akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
using ll=long long;
using P=pair<ll,ll>;
using PP=tuple<ll,ll,ll>;
using S=multiset<ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
void decimal(int x){cout<<fixed<<setprecision(x);}
ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*POW(a,b-1)%mod;ll k=POW(a,b/2);return k*k%mod;}
vi calc(ll x){vi res;while(x>0){res.eb(x%10);x/=10;}reverse(all(res));return res;}

void solve() {
  ll n,k;
  cin>>n>>k;
  ll ans=0;
  REP(i,k,n+2){
    ans=(ans+i*(n-i+1)+1)%mod;
  }
  out(ans);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}


Measured memory_bytes: 3640
#include<iostream>
#include<string>
using namespace std;

int main(){
  int A[6], v, a[6], max_a, max_i = 0;
  for ( int i = 0 ; i < 5; i++){
    cin >> A[i];
    if (A[i] < 10) a[i] = to_string(A[i])[0] - '0';
    else if ( A[i] < 100 ) a[i] = to_string(A[i])[1] - '0';
    else a[i] = to_string(A[i])[2] - '0';
    if (a[i] < a[max_i] && a[i] > 0 ) max_i = i;
  }

  int sum = 0;
  for ( int i = 0; i < 5; i++){
    if ( i == max_i || a[i] == 0 ) sum += A[i];
    else {
      sum += ( A[i] + 10 - a[i] );
    }
  }

  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;

int main()
{
	int n, a[100], A = 0, B = 0;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}

	sort(a,a+n, greater<int>());
	for (int i = 0; i < n; i++)
	{
		if (i % 2 == 0) A += a[i];
		else B += a[i];
	}
	cout << abs(A - B) << endl;

	fflush(stdin);
	getchar();
	fflush (stdin);
	getchar();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
void solve() {
	int n;
	cin >> n;
	set<string> s;
	rep(i, 0, n) {
		string t;
		cin >> t;
		s.insert(t);
	}
	cout << sz(s);
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int T_ = 1;
	//cin >> T_;
	for (int i = 0; i < T_; i++)solve();
	return 0;
}






Measured memory_bytes: 19216
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		String s = scanner.next();

		System.out.println(s.charAt(0) + String.valueOf(s.length() - 2) + s.charAt(s.length() - 1));

	}
}


Measured memory_bytes: 23252
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		long a=sc.nextLong();
		long b=sc.nextLong();
		long k=sc.nextLong();
		long h=a;
		a=Math.max(a-k, 0);
		if(a<k) {
			b=Math.max(0, b-(k-h));
		}
		System.out.println(a+" "+b);

	}

}


Measured memory_bytes: 22868
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <cmath>
#include <iomanip>
 
 
int main()
{
    std::ios::sync_with_stdio(false);
    long long int n, k; std::cin >> n >> k;
    long long int ans = 0;
    std::vector<int> h(n);
    for(long long int i=0; i<n; i++) std::cin >> h[i];
    std::sort(h.begin(), h.end(), std::greater<long long int>());

    for(long long int i=0; i<n; i++)
    {
        if(i<k) h[i] = 0;
        ans += h[i];
    }
    
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;

class Program
{

    static bool Prime (int max)
    {
        bool jud = true;

        for (int i = 2; i <= Math.Floor(Math.Sqrt(max)); i++)
        {
            if (max % i == 0)
            {
                jud = false;
                break;
            }
        }
        return jud;
    }

    static void Main(string[] args)
    {

        int n = int.Parse(Console.ReadLine());
        int max;
        int count = 0;

        for (int i = 0; i < n; i++)
        {
            max = int.Parse(Console.ReadLine());

            if (Prime(max))
            {
                count++;

            }
        }

        Console.WriteLine(count);       

    }
}


Measured memory_bytes: 15944
#include<iostream>
#include<stdio.h>
#define MAX_N 10001

using namespace std;

int data[MAX_N];

int main(){
  int a,b;
  cin >> a >> b;
  int d,r;double f;
  d = a / b;
  r = a % b;
  f = (double)a / b;;
  printf("%d %d %lf\n",d,r,f);
  return 0;
}


Measured memory_bytes: 3220
n,d=map(int,input().split())
x=[list(map(int, input().split())) for i in range(n)]
count=0
ans=0
for i in range(n):
    for z in range(i+1,n):
        for c in range(d):
            ans+=(x[i][c]-x[z][c])**2
        if (ans**0.5)%1==0:
            count+=1
        ans=0
print(count)

Measured memory_bytes: 9392
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

ll myco(ll n, ll k) {
  ll a = 0, b = 0;
  /*for(ll i = 0; i < k; i++) {
    a += i;
    b += n - i;
  }*/
 b = (2 * n - k + 1) * k / 2;
  a = k * (k - 1) / 2;
  return (b - a + 1);
}

int main() {
  ll n, k; cin >> n >> k;
  ll z = 0;
  for(ll i = k; i <= n + 1; i++) {
    z += myco(n, i);
    z %= 1000000007;
  }
  cout << z << endl;
}


Measured memory_bytes: 3596
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

N, M = map(int,input().split())
UFT = UnionFind(N)

for _ in range(M):
    A, B = map(int,input().split())
    UFT.union(A-1, B-1)

ans = 0
for i in range(N):
    ans = max(ans, UFT.size(i))
print(ans)

Measured memory_bytes: 14536
n, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [float("inf")] * 110000
dp[0] = 0

for i in range(n - 1):
    for k in range(1, K + 1):
        if i + k >= n:
            break
        dp[i + k] = min(dp[i + k], dp[i] + abs(h[i + k] - h[i]))

print(dp[n - 1])

Measured memory_bytes: 85144
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i >= n; --i)
typedef long long ll;
#define mod 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

template<class T>
ll part(const T& s, int l, int r){return s[r] - s[l];};

int main() {
  int N, K;
  string S;
  cin >> N >> K >> S;
  if(N <= K) {
    cout << N << endl;
    return 0;
  }
  int cnt = 1;
  vector<int> A;
  rep(i, 0, 3) A.push_back(0);
  if(S[0] == '0') A.push_back(0);
  rep(i, 1, N) {
    if(S[i] == S[i-1]) {
      cnt++;
    } else {
      A.push_back(cnt);
      cnt = 1;
    }
  }
  if(cnt) A.push_back(cnt);
  rep(i, 0, 3) A.push_back(0);
  vector<ll> sum(A.size() + 1);
  for(int i = 0; i < A.size(); i++) sum[i+1] = sum[i] + A[i];
  ll mx = 0;
  K = 2 * K + 1;
  if(sum.size() <= K) {
    cout << N << endl;
    return 0;
  }
  rep(i, 0, A.size() - K + 1) {
    int e = i + K;
    if(e > sum.size()) e = sum.size();
    ll a = part(sum, i, e);
    if(i%2 == 0) {
      continue;
    }
    mx = max(mx,a);
  }
  if(S == "0") mx = 1;
  cout << mx << endl;
  return 0;
}


Measured memory_bytes: 1656
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int(i)=0;i<(n);i++)

int main(){
  int n,m;cin>>n>>m;
  bool f=0;
  vector<int> a,x(n+1,0);
  REP(i,m){
    int s,t;cin>>s>>t;
    if(s==1) a.push_back(t);
    else if(t==1) a.push_back(s);
    if(s==n) x.at(t)++;
    else if(t==n) x.at(s)++;
  }
  for(auto itr=a.begin();itr!=a.end();++itr){
    if(x.at(*itr)) f=1;
  }
  cout<<(f?"POSSIBLE":"IMPOSSIBLE");
}

Measured memory_bytes: 1660
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

vector<int> get_prime(int n) {
    if(n <= 1) return vector<int>{};
    vector<bool> is_composite(n);
    vector<int> prime;
    for (int i = 2; i <= n; ++i) {
        if(!is_composite[i]) prime.push_back(i);
        for (auto &&j : prime) {
            if(i*j > n) continue;
            is_composite[i*j] = true;
            if(i % j == 0) break;
        }
    }
    return prime;
}



int main() {
    int n;
    cin >> n;
    vector<int> v(n+1);
    for (int i = 0; i <= n; ++i) {
        scanf("%d", &v[i]);
    }
    auto primes = get_prime(32000);
    vector<int> can;
    int M = abs(v.front());
    for (auto &&prime : primes) {
        if(prime <= n || M % prime == 0){
            can.emplace_back(prime);
            while(M % prime == 0) M /= prime;
        }
    }
    if(M != 1) can.emplace_back(M);
    vector<int> ans;
    for (auto &&p : can) {
        auto u = v;
        int valid = 1;
        for (int i = 0; i <= n; ++i) {
            if(i+p-1 < n) u[i+p-1] += u[i];
            else if((u[i]%p+p)%p != 0) valid = 0;
        }
        if(valid) ans.emplace_back(p);
    }
    for (auto &&p : ans) {
        printf("%d\n", p);
    }
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;

int main()
{
  int64_t a, b, c;
  cin >> a >> b >> c;
  
  long double a_ld, b_ld, c_ld;
  a_ld = (long double)a;
  b_ld = (long double)b;
  c_ld = (long double)c;
  
  if (2 * sqrt(a_ld * b_ld) < c - a - b) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main() {
    int N, A, B; cin >> N >> A >> B;
    string S; cin >> S;
    int pass = 0;
    int kai = 0;
    for (int i = 0; i < N; ++i) {
        if (S[i] == 'a') {
            if (pass < A + B) {
                cout << "Yes" << endl;
                ++pass;
            }
            else cout << "No" << endl;
        }
        else if (S[i] == 'b') {
            if (pass < A + B && kai < B) {
                cout << "Yes" << endl;
                ++pass;
            }
            else cout << "No" << endl;
            ++kai;
        }
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#include <new>
#include <typeinfo>

typedef  long long ll;
#define mop 1000000007
#define mop2 998244353

using namespace std;

int main() {
	ll MAXV = ll(1e18);
	ll n;
	cin >> n;
	ll ans = 1;
	bool over18 = false;
	for (ll i = 0; i < n; i++) {
		ll tmp;
		cin >> tmp;
		if (ans == 0) {
			break;
		}
		if (over18) {
			if (tmp == 0) {
				ans = 0;
				over18 = false;
				break;
			}
		}
		else {
			if (MAXV / tmp < ans) {
				over18 = true;
			}
			ans *= tmp;
		}
	}
	if (over18) {
		cout << -1 << endl;
	}
	else {
		cout << ans << endl;
	}
}

Measured memory_bytes: 3616
line = gets.split(' ').map(&:to_i)

N = line[0]
K = line[1]
Mod = 10 ** 9 + 7

ans = N - K + 1

for i in 1..K do
  puts ans % Mod
  ans = ans * (K-i) * (N-K-i+1) / ((i+1) * i)
end

Measured memory_bytes: 2172
//#include <bits/stdc++.h>
#include<iostream>
#include<stdio.h>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;


int main(void) {
	int n, k;
	long long int count = 0;
	int p;

	cin >> n >> k;

	FOR(i, 1, n) {
		if (k >= i) {
			continue;
		}
		else {
			p = n / i;
			count += p * (i - k);
			if (p*i < n) {
				if (k == 0) {
					count += n - (p*i + 1) + 1;
				}
				else {
					if (n - (p*i + k) + 1 >= 0) {
						count += n - (p*i + k) + 1;
					}
					
				}
			}
			
			
			//cout << i << " " << count << endl;
		}
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

typedef unsigned long long ll;

int main(int argc, char const *argv[])
{
    int N;
    cin >> N;

    vector<string> S(N);
    for (int i = 0; i < N; i++)
    {
        cin >> S[i];
    }
    auto it = find(S.begin(), S.end(), "Y");
    if (it != S.end())
    {
        cout << "Four" << endl;
    }
    else
    {
        cout << "Three" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> a(h);
  for (int i = 0; i < h; i++)
    cin >> a[i];
  for (int i = 0; i < h; i++) {
    if (a[i] != string(w, '.')) {
      swap(a[0], a[i]);
      break;
    }
  }
  int ans[h][w] = {}, num = 1;
  for (int i = 0; i < h; i++) {
    if (a[i] == string(w, '.')) {
      for (int j = 0; j < w; j++) {
        ans[i][j] = ans[i-1][j];
      }
    }
    else {
      int count = 0;
      for (int j = 0; j < w; j++) {
        if (a[i][j] == '#') {
          count++;
          if (count > 1) num++;
        }
        ans[i][j] = num;
      }
      num++;
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cout << ans[i][j];
      if (j != w-1) cout << ' ';
    }
    cout << endl;
  }
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define rev(i,s,e) for(i64 (i) = (s);(i) --> (e);)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

int main() {
  i64 N;
  cin >> N;
  string S;
  cin >> S;
  i64 ans = 0;
  for(i64 i = 0;i + 3 <= N;i++) {
    if(S.substr(i, 3) == "ABC") ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int n,a[101];
int main()
{
int maxn=-2000000000,minn=2000000000;
scanf("%d",&n);for(int i=1;i<=n;++i) {scanf("%d",&a[i]);if(maxn<a[i]) maxn=a[i];if(minn>a[i]) minn=a[i];}
printf("%d\n",maxn-minn);
return 0;
}

Measured memory_bytes: 128
package main

import (
  "fmt"
)

func strongness(x int) int {return (x + 11) % 13}

func main() {
  var a, b int; fmt.Scan(&a, &b)
  a, b = strongness(a), strongness(b)
  var ans string
  if a > b {
    ans = "Alice"
  } else if a < b {
    ans = "Bob"
  } else {
    ans = "Draw"
  }
  fmt.Println(ans)
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;  
#define pb push_back
#define F first
#define S second
#define ppp pair<ll,pair<ll,ll>>
#define pp pair<ll,ll>
#define all(x) (x).begin(),(x).end()
#define pi 3.14159265358
#define MOD 998244353



int main()
{

    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout); 
    // freopen("error.txt", "w", stderr); 
    // #endif
    
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);

     
   	 ll n,m,i,j,k,l;

   	 cin>>n>>m;

   	 ll a[n];
   	  ll tot=0;
   	 for(i=0;i<n;i++)
   	 	{
   	 		cin>>a[i];
   	 		tot+=a[i];
   	 	}

   	 sort(a,a+n,greater<>());


   	 for(i=0;i<m;i++)
   	 {
   	 	if(a[i]*4*m<tot)
   	 	{
   	 		break;
   	 	}
   	 }
   	 if(i==m)
   	 {
   	 	cout<<"Yes"<<endl;
   	 }
   	 else
   	 	cout<<"No"<<endl;

}



Measured memory_bytes: 256
import bisect
A, B, Q = map(int, input().split())
INF = 10 ** 13
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]
for q in range(Q):
    x = int(input())
    b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    res = INF
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            res = min(res, d1, d2)
    print(res)

Measured memory_bytes: 78296
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
typedef long long ll;
typedef multiset<ll> S;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll,vector<ll>,greater<ll>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
bool chmin(auto &a,auto b){if(a>b){a=b;return true;}return false;}
bool chmax(auto &a,auto b){if(a<b){a=b;return true;}return false;}
int main(){
    int n;cin>>n;
    cout<<(n-1)/2<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main() {

  int A,B;
  char op;
  
  cin >> A >> op >> B;
  
  if(op == '+'){
  
    cout << A+B << endl;
    
  }else{
  
    cout << A-B << endl;
  
  }
  
  return 0;
  
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
using namespace std;
int main(){
  long long int ans,a,b,c,x,y;
  scanf("%lld %lld %lld %lld %lld\n",&a,&b,&c,&x,&y);
  if(a+b<c*2){
    printf("%lld\n",a*x+b*y);
  }
  else{
    if(x<y){
      ans=y*c*2;
      if(ans>x*c*2+(y-x)*b){
        ans=x*c*2+(y-x)*b;
      }
    printf("%lld\n",ans);
    }
    else{
      ans=x*c*2;
      if(ans>y*c*2+(x-y)*a){
        ans=y*c*2+(x-y)*a;
      }
    printf("%lld\n",ans);
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;

// #define long long long 

template <typename T> void read_stdin(const size_t size, vector<T>& array)
{
   T value;
   for (size_t i(0); i < size; ++i) {
      cin >> value;
      array.push_back(value);
   }
}

template <typename T> void output_stdout(const vector<T>& array)
{
   for (const auto& value : array) {
      cout << value << endl;
   }
}

int main() {
   // vector<long> inputA;
   // vector<long> outputA;
   size_t N;
   string inputA;
   int outputB(0);

   // read
   {
      cin >> N;
      cin >> inputA;
   }

   // process
   {
      const string key("ABC");
      int pos(inputA.find(key));
      while (pos != string::npos) {
         ++outputB;
         inputA = inputA.substr(pos + 3);
         pos = inputA.find(key);
      }
   }

   // output
   {
      cout << outputB << endl;
   }
   
   return 0;
}


Measured memory_bytes: 256
#include <cctype>
#include <cstdio>
#include <cstring>

char S[100][16]; int N, H, Q, R, T[100], P[100];

int main()
{
    scanf("%d %d", &N, &H);
    
    for(int i = 0; i < N; i++)
    {
        scanf("%s %d", S[i], &T[i]);
    }
    
    char F[2];
    
    for(int i = 0; i < N; i++)
    {
        int ptr = 0;
        
        while(ptr != strlen(S[i]))
        {
            printf("? %s\n", S[i]); fflush(stdout);
            
            scanf("%s", F); R++;
            
            if(tolower(S[i][ptr]) == tolower(F[0]))
            {
                S[i][ptr] = '_'; ptr++; Q++;
            }
            else
            {
                P[i]++;
                
                if(P[i] > T[i])
                {
                    H--; break;
                }
            }
        }
        
        if(H == 0)
        {
            printf("! Game Over\n"); return 0;
        }
    }
    
    int r = Q * 1000 / R;
    
    printf("! Game Clear %d.%d\n", r / 10, r % 10);
    
    return 0;
}

Measured memory_bytes: 3372
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    for(int i = 0;i < n;i++){
        cin >> s[i];
        sort(s[i].begin(),s[i].end());
    }

    ll ans = 0;
    ll count = 1;
    sort(s.begin(),s.end());
    string s_tmp = s[0];
    for(int i = 1;i < n;i++){
        if(s[i] == s[i-1]) count ++;
        else{
            ans += count*(count - 1)/2;
            count = 1;
            //s_tmp = s[i];
        }
    }
    ans += count*(count - 1)/2;
    cout << ans << endl;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<ll> A(N);
    for(int i=0; i<N; i++) cin >> A[i];

    sort(A.begin(), A.end(), greater<ll>());

    ll ans = A.front();
    for(int i=1, cnt=2; cnt<N; i++)
    {
        if(cnt != N-1)
        {
            ans += A[i] * 2;
            cnt+=2;
        }
        else
        {
            ans += A[i];
            cnt++;
        }
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 4764
#define PRIM_NODE_MAX 100
#define INF 1e9
int prim(int n,int cost[][PRIM_NODE_MAX]){
	int determined[PRIM_NODE_MAX]={0};
	int undeterminednodes=n;
	int mincost[PRIM_NODE_MAX],currminnode,minnode,minnodecost,totalcost=0;
	int i;
	
	// initialize mincost
	for(i=0;i<n;i++){
		mincost[i]=INF;
	}
	// determine node 0
	currminnode=0;
	minnodecost=0;

	for(;undeterminednodes--;){
		// the node is determined
		determined[currminnode]=1;
		totalcost+=minnodecost;

		minnodecost=INF;
		for(i=0;i<n;i++){
			if(!determined[i]){
				// update mincost around the currminnode
				if(cost[currminnode][i]<mincost[i])
					mincost[i]=cost[currminnode][i];
				// select the nearest undetermined node
				if(mincost[i]<minnodecost){
					minnode=i;
					minnodecost=mincost[i];
				}
			}
		}
		currminnode=minnode;
	}
	return totalcost;
}
s,d,C[100][100];
main(){
	int i,j,v;
	for(;scanf("%d%d",&s,&d)*s;){
		memset(C,0,sizeof(C));
		for(j=0;j<s;j++){
			for(i=0;i<d;i++){
				scanf("%d",&v);
				C[j][s+i]=C[s+i][j]=v?v:INF;
			}
		}
		for(j=0;j<d-1;j++){
			for(i=0;i<d-j-1;i++){
				scanf("%d",&v);
				C[s+j][s+j+1+i]=C[s+j+1+i][s+j]=v?v:INF;
			}
		}
		printf("%d\n",prim(s+d,C));
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;cin>>n;int count=0;
for(int i=1;i<=n;i++){
int c=0;
     for(int j=1;j<=i;j++){
         if(i%j==0)c++;
     }
 
if(c==8&&i%2!=0)count++;
}
cout<<count;
}

Measured memory_bytes: 256
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <math.h>
using namespace std;


int main() {
   string n;
 
   cin >> n;
  
  int ans =0;
  for(int i= 0;i<4;i++){
    int sum = 0;
    
    for(int k= 0;k<4;k++){
      
      if(n[i]==n[k]){
        
        sum=sum+1;
       
      }
    
    
      
    }
      if(sum==2){
        
        ans=ans+1;
        
      }
  }
  
if(ans==4){
  cout << "Yes"<<endl;
}else{
  cout << "No"<<endl;
}
   
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
	string s;
	cin >> s;
	
	if(s[0] == 'S') {
		cout << "Cloudy" << endl;
	}else if(s[0] == 'C') {
		cout << "Rainy" << endl;
	}else {
		cout << "Sunny" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll max(ll a,ll b)
{
    return a>b?a:b;
}
ll min(ll a,ll b)
{
    return a<b?a:b;
}
ll n;
vector<ll> arr;
int main()
{
    cin>>n;
    arr.resize(n);
    for(ll i=0;i<n;i++)
    cin>>arr[i];
    if(n==1)
    cout<<arr[0];
    else
    {
        //dp[i][j] means -> max that a player score if we consider values from index i to j (inclusive)
        vector<vector<ll> > dp(n,vector<ll> (n,0));
        for(ll i=0;i<n;i++)
        {
            dp[i][i]=arr[i];
            if(i==n-1)
            continue;
            dp[i][i+1]=max(arr[i],arr[i+1]);
        }
        for(ll i=n-3;i>=0;i--)
        {
            for(ll j=i+2;j<n;j++)
            {
            dp[i][j]=max(arr[i]+min(dp[i+2][j],dp[i+1][j-1]),arr[j]+min(dp[i][j-2],dp[i+1][j-1]));
            }
        }
        /*for(ll i=0;i<n;i++)
        {
        for(ll j=0;j<n;j++)
        cout<<dp[i][j]<<" ";
        cout<<"\n";
        }*/
        ll a = min(dp[1][n-1],dp[0][n-2]);
        cout<<(dp[0][n-1]-a);
    }
    return 0;
}

Measured memory_bytes: 70784
#include<bits/stdc++.h>
using namespace std;

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using ull = unsigned long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
using vs = vector<string>;
using vvs = vector<vs>;
using vc = vector<char>;
using vvc = vector<vc>;
using ii = pair<int,int>;
using vii = vector<ii>;
using vvii = vector<vii>;
using dd = pair<double, double>;
using vdd = vector<dd>;
using vvdd = vector<vdd>;
using Mii = map<int,int>;
using vMii = vector<Mii>;
using Si = set<int>;
using vSi = vector<Si>;
using vvSi = vector<vSi>;

#define fi first
#define se second
#define INF 1e9 + 5
#define mod(a,m) (a%m+m)%m
#define PB push_back
#define MP make_pair

int main(){
//	cout.setf(ios::fixed);
//	cout.precision(4);
	int a;
	string s;
	while (cin >> a >> s) {
		cout << (a < 3200? "red" : s) << '\n';
	}
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
const LL MOD = 1000000007LL;
double dp[17][1 << 16];
double win[16][16];
int m, n;
double solve(int r, int c) {
	if (r == n) return 1;
	if (dp[r][c] != -1) return dp[r][c];
	double ret = 0;
	for (int i = 0; i < m; i++) {
		if (c&(1 << i)) continue;
		double t = 1;
		double sum = 0;
		for (int j = r; j < n; j++) {
			sum += t*(1 - win[i][j])*solve(j, c | (1 << i));
			t *= win[i][j];
		}
		sum += t;
		ret = max(ret, sum);
	}
	return dp[r][c] = ret;
}
int main() {
	cin >> m >> n;
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < n; j++) cin >> win[i][j];
	}
	for (int i = 0; i < n; i++) for (int j = 0; j < (1 << m); j++) dp[i][j] = -1;
	printf("%.15lf\n", solve(0, 0));
}


Measured memory_bytes: 11480
#include <bits/stdc++.h>

using namespace std;

int main() {
  std::ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<tuple<string, int, int>> a;
  for (int i = 0; i < n; i++) {
    string s;
    int v;
    cin >> s >> v;
    a.emplace_back(s, -v, i);
  }
  sort(a.begin(), a.end());
  vector<int> ans(n);
  for (int i = 0; i < n; i++) {
    cout << get<2>(a[i]) + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	// he, his, hat は全て't'より若い文字コードを持つ
	private static final int[] PATTEN_THE_ = { 0, -12, -15 };
	private static final int[] PATTEN_THIS = { 0, -12, -11, -1 };
	private static final int[] PATTEN_THAT = { 0, -12, -19, 0 };

	private static enum WORD {
		THE_, THIS, THAT, OTHER
	}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		Scanner sc;
		ArrayList<String> words;

		while ((line = br.readLine()) != null) {
			sc = new Scanner(line);
			words = new ArrayList<String>();
			while (sc.hasNext()) {
				words.add(sc.next());
			}
			for (String word : words) {
				String check = word.replace(".", "");
				WORD pattern = WORD.OTHER;
				int shift;
				if (check.length() == 3) {
					pattern = checkPattern(check, PATTEN_THE_);
				} else if (check.length() == 4) {
					pattern = checkPattern(check, PATTEN_THIS);
					if (pattern != WORD.THIS)
						pattern = checkPattern(check, PATTEN_THAT);
				}
				if (pattern == WORD.THE_ || pattern == WORD.THIS
						|| pattern == WORD.THAT) {
					shift = getNumberOfShift(word.charAt(0));
					System.out.println(decode(line, shift));
					break;
				}
			}
		}
	}

	public static WORD checkPattern(String word, int[] pattern) {

		WORD result = WORD.OTHER;

		boolean isMatch = false;

		int first = word.charAt(0);
		for (int i = 1; i < word.length(); i++) {
			int target = (int) word.charAt(i);
			if (target > first)
				target -= 26;
			if (target - first == pattern[i]) {
				isMatch = true;
			} else {
				isMatch = false;
				break;
			}
		}
		if (isMatch) {
			if (pattern == PATTEN_THE_)
				result = WORD.THE_;
			if (pattern == PATTEN_THIS)
				result = WORD.THIS;
			if (pattern == PATTEN_THAT)
				result = WORD.THAT;
		}
		return result;
	}

	public static int getNumberOfShift(char charOft) {
		int result;
		result = (int) charOft - (int) 't';
		return result;
	}

	public static String decode(String line, int shift) {
		char[] c = line.toCharArray();
		for (int i = 0; i < c.length; i++) {
			if (c[i] >= 'a' && c[i] <= 'z') {
				c[i] = (char) (c[i] - shift);
				if (c[i] < 'a')
					c[i] = (char) (c[i] + 26);
				if (c[i] > 'z')
					c[i] = (char) (c[i] - 26);
			}
		}
		return String.valueOf(c);

		// StringBuilder sb = new StringBuilder();
		// for (int i = 0; i < line.length(); i++) {
		// char ch = line.charAt(i);
		// if (ch >= 'a' && ch <= 'z') {
		// ch = (char) ((int) ch - shift);
		// if (ch < 'a')
		// ch = (char) ((int) ch + 26);
		// if (ch > 'z')
		// ch = (char) ((int) ch - 26);
		// }
		// sb.append(ch);
		// }
		// return sb.toString();
	}
}

Measured memory_bytes: 17248
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;

typedef tree<
ll,
null_type,
less<ll>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
// ordered_set X;
// *X.find_by_order(i) = ith largest element (counting from zero)
// X.order_of_key(k) = number of items in X < k (strict lt)

ll dsum(ll n) {
    ll ans = 0;
    while (n > 0) {
        ans += n % 10;
        n /= 10;
    }
    return ans;
}

int main(){
    string s;
    cin >> s;

    int N = s.size();

    vi digits(N);
    for (int i=0;i<N;i++) {
        digits[i] = s[i] - '0';
    }

    reverse(digits.begin(), digits.end());
    while (digits.size() < 10) digits.push_back(0);
    digits.push_back(0);
    digits.push_back(0);

    // multiply N by 9
    int carry = 0;
    for (int i=0;i<N+2;i++) {
        digits[i] = 9*digits[i] + carry;
        carry = digits[i]/10;
        digits[i] -= 10*carry;
    }

    // for (int d : digits) cout << d;
    // cout << endl;

    ll pref = 0; // first 9 digits
    ll tpow = 1;
    for (int i=0;i<9;i++) {
        pref += tpow*digits[i];
        tpow *= 10;
    }

    for (int i=0;i<9;i++) digits[i] = 0;

    vi suffp1(digits.begin(), digits.end());
    suffp1[9]++;
    for (int i=9;i<N+2;i++) {
        if (suffp1[i] == 10) {
            suffp1[i] = 0;
            suffp1[i+1]++;
        }
    }

    // cout << pref << endl;
    // for (int d : digits) cout << d;
    // cout << endl;
    // for (int d : suffp1) cout << d;
    // cout << endl;

    ll suff_sum = 0;
    ll suffp1_sum = 0;

    for (int d : digits) suff_sum += d;
    for (int d : suffp1) suffp1_sum += d;

    ll shift = 1000000000 - pref;

    ll best = 1000000000;

    ll S = suff_sum;
    while (dsum(pref+S) + suff_sum > S) {
        // cout << (pref + S) << " " << suff_sum << " " << S << endl;
        S++;
    }

    best = min(S, best);

    S = max(suffp1_sum - shift, (ll)0);
    while (dsum(S) + suffp1_sum > S + shift) S++;

    best = min(S+shift, best);

    cout << (best+8)/9 << endl;

    return 0;
}


Measured memory_bytes: 6660
n = int(input())
li_a = list(map(int, input().split()))

li_aw = [0] + li_a + [0]

# 全ルートを回るコスト
total_cost = 0
for i in range(1, len(li_aw)):
    total_cost += abs(li_aw[i - 1] - li_aw[i])

for i in range(n):
    # li_aw上の取りやめポイントindex
    delete_index = i + 1
    delete_cost = abs(li_aw[delete_index - 1] - li_aw[delete_index]) + abs(li_aw[delete_index] - li_aw[delete_index + 1])
    add_cost = abs(li_aw[delete_index - 1] - li_aw[delete_index + 1])
    print(total_cost - delete_cost + add_cost)




Measured memory_bytes: 14048
#include <stdio.h>

#define fd(type, fn)	type fn(P a, P b
#define ifd(type, fn)	inline fd(type, fn)

typedef double frac;

typedef struct { frac x, y; } Point, P;

ifd(frac, cross))	{ return (a.x * b.y - a.y * b.x);  }
ifd(frac, dot))		{ return (a.x * b.x + a.y * b.y);  }
ifd(P, plus))		{ return (P){a.x + b.x, a.y + b.y};}
ifd(P, minus))		{ return (P){a.x - b.x, a.y - b.y};}
ifd(frac, norm)) 	{ return (a.x * a.x + a.y * a.y);  }

fd(int, ccw), P c){
	b = minus(b, a), c = minus(c, a);
	if (cross(b, c) > 0) return +1;			// ccw
	if (cross(b, c) < 0) return -1;			// cw
	if (dot(b, c) < 0)	 return +2;			// c-a-b
	if (norm(b, b) < norm(c, c)) return -2;	// a-b-c
	return 0;
}
fd(int, in_tri), P c, P p){ return (ccw(a, b, p) == ccw(b, c, p) && ccw(b, c, p) == ccw(c, a, p)); }

int input_p(P *p) { return scanf("%lf,%lf,", &p->x, &p->y); }

int main(void)
{
	P ps[4];

	while (~input_p(ps)){
		int i;

		for (i = 1; i < 4; i++) input_p(ps + i);
		for (i = 0; i < 4; i++) {
			if (in_tri(ps[i], ps[(i + 1) % 4], ps[(i + 3) % 4], ps[(i + 2) % 4])){
				puts("NO");
				break;
			}
		}
		if (i == 4) puts("YES");
	}

	return (0);
}

Measured memory_bytes: 608
#include <bits/stdc++.h>
using namespace std;

int main() {
  double a, b, h, m;
  double ans;
  cin >> a >> b >> h >> m;
  
  double a_x, a_y, b_x, b_y;
  double s_a, s_b;
  
  s_a = h / 12. * 360. + m / 60. / 12. * 360;
  s_b = m / 60. * 360.;
  a_x = a * sin(s_a * M_PI / 180.);
  a_y = a * cos(s_a * M_PI / 180.);
  b_x = b * sin(s_b * M_PI / 180.);
  b_y = b * cos(s_b * M_PI / 180.);
  
  ans = sqrt(pow(a_x-b_x, 2.0) + pow(a_y-b_y, 2.0));
  
  cout <<fixed << setprecision(20) << ans << endl;
    
}


Measured memory_bytes: 4168
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

int L;

int main()
{
    cin >> L;
    L--;
    int d;
    REP(i, 20) if ((L + 1) >> i & 1) d = i;

    vector<vector<int>> ans;
    REP(i, d)
    {
        ans.push_back(vector<int>{i + 1, i + 2, 1 << (d - i - 1)});
        ans.push_back(vector<int>{i + 1, i + 2, 0});
    }

    int now = (1 << d) - 1;

    REP(i, d)
    {
        if ((L - now) >> i & 1)
        {
            ans.push_back(vector<int>{1, d - i + 1, now + 1});
            now += 1 << i;
        }
    }
    cout << d + 1 << " " << ans.size() << endl;
    for (auto v : ans)
    {
        cout << v[0] << " " << v[1] << " " << v[2] << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;

int main(){
double d;
cin >> d;

double mx = 0;
double p = floor(d);
double q = sqrt(d*d-p*p);
if(q<=1.0){
mx = d*sqrt(2.0);
mx = max(mx, p+1.0);
}else{
mx = d*sqrt(2.0);
}
cout.precision(10);
cout << mx << endl;
return 0;
}


Measured memory_bytes: 3276
#include <bits/stdc++.h>
using namespace std;

int main() {
  int s123, s1, s2, s3;
  cin >>s123;
  s1 = s123 / 100;
  s2 = (s123 - s1*100) /10;
  s3 = s123 - s1*100 - s2*10;
  cout << s1+s2+s3;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  ll d = LLONG_MAX;
  if (a % 2 == 0) {
    d = 0;
  } else {
    ll blue = a / 2 * b * c;
    ll red = a * b * c - blue;
    d = abs(blue - red);
  }

  ll e = LLONG_MAX;
  if (b % 2 == 0) {
    e = 0;
  } else {
    ll blue = a * (b / 2) * c;
    ll red = a * b * c - blue;
    e = abs(blue - red);
  }

  ll f = LLONG_MAX;
  if (b % 2 == 0) {
    f = 0;
  } else {
    ll blue = a * b * (c / 2);
    ll red = a * b * c - blue;
    f = abs(blue - red);
  }


  cout << min({d, e, f}) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

int func(int x)
{
    if(x%2==0)
    {
        return x/2;
    }
    else
    {
        return 3*x+1;
    }
}
int main()
{
    int a,b;
    cin>>a>>b;
    string s;
    cin>>s;
    char p[s.size()];
    for(int i=0;i<s.size();i++)
    {
        p[i]=s[i];
    }
    bool flag = true;
    for(int i=0;i<s.size();i++)
    {
        if(i==a)
        {
            if(p[i]!='-')
            {
                flag = false;
            }
        }
        else
        {
            if(p[i]=='-')
            {
                flag = false;
            }
        }
    }
    if(a+b+1!=s.size())
    {
        flag = false;
    }

    if(flag)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <algorithm>

using namespace std;

int w, h;
int board[32][32];
int dist[32][32][4];
int cost[4];
int ans;

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

inline bool isGoal(int x, int y) 
{
    return (x == w - 1 && y == h - 1);
}

inline bool isInside(int x, int y)
{
    return (x >= 0 && y >= 0 && x < w && y < h);
}

int dfs(int x, int y, int d, int c, int minValue) {
    if (isGoal(x, y))
        return c;

    dist[y][x][d] = c;
    for (int cmd = 0; cmd < 4; cmd++) {
        int newd = (d + cmd) % 4;
        int newc = cost[cmd] + c;
        
        if (cmd == board[y][x])
            newc = c;
        
        int newx = x + dx[newd];
        int newy = y + dy[newd];

        if (newc < minValue && isInside(newx, newy) &&
            dist[newy][newx][newd] > newc) 
            minValue = dfs(newx, newy, newd, newc, minValue);
    }
    
    return minValue;
}

int main()
{
    while (cin >> w >> h, w || h) {
        // Input
        for (int y = 0; y < h; y++)
            for (int x = 0; x < w; x++) {
                cin >> board[y][x];
                for (int d = 0; d < 4; d++)
                    dist[y][x][d] = INT_MAX;
            }
        for (int i = 0; i < 4; i++)
            cin >> cost[i];

        // solve
        cout << dfs(0, 0, 0, 0, INT_MAX) << endl;
    }

    return 0;
}

Measured memory_bytes: 1276
//
//  main.cpp
//  HelloWorld
//
//  Created by purple on 2020/04/13.
//  Copyright © 2020 Purple. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <cmath>

using namespace std;

int main(int argc, const char * argv[]) {


    int a,b,c;

    cin >> a >> b >> c;
    
    int cnt=0;
    
    for(int i=a; i<=b; i++){
        if(c%i==0)
            cnt++;
    }
        
    cout << cnt << endl;
    
    return 0;
    
}



Measured memory_bytes: 3120
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

int main() {
	ll a, b, k;
	cin >> a >> b >> k;

	if (a >= k) {
		cout << a-k << " " << b << endl;
	}
	else if (a + b >= k)
	{
		cout << 0 << " " << b-(k-a) << endl;
	}
	else
	{
		cout << 0 << " " << 0 << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<62;
const LL INF=1<<17;


bool f(long n){
    cout << "? " << n << endl;
    char c;cin >> c;
    //if((n<=stol(p)&&to_string(n)<=p)||(n>stol(p)&&to_string(n)>p)) c='Y';
    //else c='N';
    //cout << " " << c << endl;
    return c=='Y'?true:false;
}

int main(){
    //string p;cin >> p;
    long k=1;
    int s;
    long n=0;
    for (int i = 0; i <= 8; i++) {
        if(!f(k*10)){
            s=i;
            int l=0,r=10;
            while(abs(r-l)>1){
                int m=(l+r)/2;
                if(f(k*m*10)){
                    r=m;
                }
                else{
                    l=m;
                }
            }
            n=k*l;
            break;
        }
        if(i==8){
            k=1;
            for (long a = 2; a < 10000000000l; a=a*10+2) {
                if(f(a)){
                    cout << "! " << k << endl;
                    return 0;
                }
                k*=10;
            }
            return 0;
        }
        k*=10;
    }
    k/=10;
    for (int i = 0; i < s; i++) {
        int l=0,r=10;
        while(abs(r-l)>1){
            int m=(l+r)/2;
            if(f((n+k*m)*10)){
                r=m;
            }
            else{
                l=m;
            }
        }
        n+=l*k;
        k/=10;
    }
    cout << "! " << n+1 << endl;
    return 0;
}




Measured memory_bytes: 596
#include <iostream>
#include <algorithm>
#include <vector>
#include <bitset>

using namespace std;

int n;
string s;

int main()
{
    cin >> n >> s;
    int ans = 0;
    for (int i = 0; i < 1000; i++)
    {
        int c[3] = {i / 100, (i / 10) % 10, i % 10};
        int cur = 0;
        for (int j = 0; j < n; j++)
        {
            if (s[j] == '0' + c[cur])
            {
                cur++;
            }
            if (cur == 3)
            {
                break;
            }
        }
        if (cur == 3)
        {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi              first
#define se              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define endl			"\n"
void fast()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int n;
vector<vector<int> > points;
vector<vector<int> > dp;
int solve(int index, int activity)
{
	if (index == n)
		return 0;

	if (dp[index][activity] != -1)
		return dp[index][activity];
	int ans = points[index][activity];
	if (activity == 0)
		ans += max(solve(index + 1, 1), solve(index + 1, 2));
	else if (activity == 1)
		ans += max(solve(index + 1, 0), solve(index + 1, 2));
	else if (activity == 2)
		ans += max(solve(index + 1, 0), solve(index + 1, 1));
	return dp[index][activity] = ans;
}
int32_t main()
{
	fast();
	cin >> n;
	points.resize(n, vector<int> (3));
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < 3; j++)
			cin >> points[i][j];
	}
	dp.resize(n, vector<int> (3, -1));
	cout << max(solve(0, 0), max(solve(0, 1), solve(0, 2)));
	return 0;
}


Measured memory_bytes: 18756
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    int c=1/(a+b);
    System.out.println(((a%3==0)||(b%3==0)||((a+b)%3==0))?"Possible":"Impossible");
  }
}


Measured memory_bytes: 23380
#include <bits/stdc++.h>
using namespace std;

#define MAXN 200*1000+5

vector<int> g[MAXN];
int ans[MAXN], add[MAXN];


void dfs(int u, int p = -1) {
	ans[u] += add[u];
	for(int v : g[u]) {
		if(v != p) {
			add[v] += add[u];
			dfs(v, u);
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n, q;
	cin >> n >> q;
	for(int i = 0; i < n-1; i++) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	
	for(int i = 0; i < q; i++) {
		int u, x;
		cin >> u >> x;
		u--;
		add[u] += x;
	}
	
	dfs(0);
	for(int i = 0; i < n; i++) {
		cout << ans[i] << " \n"[i==n-1];
	}
	
}


Measured memory_bytes: 24320
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#include <queue>
#define MOD (long long)1000000007
#define INF (long long)998244353
using namespace std;

int main(void){
    int h1,m1,h2,m2,k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int time1=h1*60+m1;
    int time2=h2*60+m2;
    int def=time2-time1;
    cout << def-k << endl;
    return 0;
}

Measured memory_bytes: 3596
using System;
using System.Collections.Generic;
using System.Text;

namespace ABC0613
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] inp = Console.ReadLine().Split(' ');

            int ans = 0;
            for(int i=0;i<5;i++)
            {
                int hoge = int.Parse(inp[i]);
                if (hoge == 0)
                {
                    ans = i;
                    break;
                }
            }
            Console.WriteLine((ans+1).ToString());
        }
    }
}


Measured memory_bytes: 27392
#include <iostream>
#include <string>
using namespace std;

int main()
{
  string s;
  cin >> s;

  int l = s.length();
  int count_x = 0;
  int b = 0, e = l - 1;
  while (b <= e)
  {
    if (s[b] != s[e])
    {
      if (b != e && s[e] == 'x')
      {
        count_x++;
        e--;
        continue;
      }
      if (s[b] == 'x')
      {
        count_x++;
        b++;
        continue;
      }
      cout << -1;
      return 0;
    }

    b++, e--;
  }

  cout << count_x;
  return 0;
}


Measured memory_bytes: 512