akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) {}
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool same(int x, int y) {
    return find(x) == find(y);
  }
  int find(int x) {
    if (data[x] < 0) return x;
    return data[x] = find(data[x]);
  }
  int size(int x) {
    return -data[find(x)];
  }
};

int main()
{
  int n, q;
  cin >> n >> q;

  UnionFind uf(n);

  for (int i = 0; i < q; i++) {
    int com, x, y;
    cin >> com >> x >> y;

    if (com == 1) {
      cout << uf.same(x, y) << endl;
    } else if (com == 0) {
      uf.unite(x, y);
    }
  }

  return (0);
}

Measured memory_bytes: 3136
/*input
10
*/

#include <bits/stdc++.h>

using namespace std;

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n; cin >> n;
    for (int i = 1; i <= 9; ++i) {
        if (n % i == 0 && n / i < 10) {
            cout << "Yes\n";
            return 0;
        }
    }

    cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lli long long int
#define MOD 1000000007
#define KING 1000000002
#define queen 1000002
#define fi first
#define se second
#define se second
#define lsb(i) (i & -i)
#define nl cout<<'\n'
#define TEST cout<<"TEST",nl
#define pr pair<lli,lli>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define vi vector<lli>
#define vpi vector<pr> 
#define P pair<lli,pr>
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define NA(i,s,n) for(lli i=s;i<n;i++)
using namespace std;
const int N = 2019;

long long int power(long long int x,long long int y,long long int p) 
{ 
	long long int res = 1;	 
	x = x % p; 
	while (y > 0) 
	{ 
		if (y & 1) 
			res = (res*x) % p; 
		y = y>>1; 
		x = (x*x) % p; 
	} 
	return res; 
} 

void solve(){
    string s; cin>>s;
    lli n = s.size();
    vi suff(n+1, 0), mpp(2020, 0); 
    for(lli i=n-1; i>-1; --i){
        lli cur_v = s[i]-'0';
        lli cur_p = power(10, n-1-i, N);
        suff[i] = (cur_v * cur_p) % N;
        suff[i] = (suff[i]+suff[i+1]) % N;
    }
    // NA(i,0,n) cout<<suff[i]<<' '; nl;
    mpp[0]++;
    NA(i,0,n) mpp[suff[i]]++;
    lli ans = 0;
    NA(i,0,2019){
        ans += ((mpp[i])*(mpp[i]-1) / 2);
    }
    cout<<ans;
    return;
}
int main(){
    fastIO;
    lli t = 1; 
    // cin>>t;
    NA(i,0,t) solve();
    return 0;
}

Measured memory_bytes: 5212
#include <iostream>
using namespace std;
int main(){
    int n, i, num;
    cin >> n;
    num = 0;
    for (i = 1; i <= n; i++){
        if (i % 2 == 1){
            num++;
        }
    }
    cout << (double)num / n << endl;
    return 0;
}


Measured memory_bytes: 3260
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
const ll MOD = 1000000007;

ll P[5010], C[5010], po[5010], tur[5010];
bool arr[5010];



int main() {
	ll N, K;
	cin >> N >> K;
	for (int i = 0;i < N;i++) {
		cin >> P[i];
		P[i]--;
		arr[i] = 0;
		po[i] = 0;
	}
	for (int i = 0;i < N;i++) {
		cin >> C[i];
	}
	int nv;
	ll t, cnt = 0, ans = INT32_MIN, rp, rpp, nnv, x;
	for (int i = 0;i < N;i++) {
		for (int j = 0;j < N;j++) {
			po[j] = tur[j] = 0;
			arr[j] = 0;
		}
		nv = P[i];
		t = 0;
		cnt = 0;
		while (1) {
			nv = P[nv];
			cnt += C[nv];
			t++;
			ans = max(cnt, ans);
			arr[nv] = 1;
			tur[nv] = t;
			po[nv] = cnt;
			if (arr[P[nv]])break;
			if (t == K)break;
		}
		if (t == 0) {
			ans = max(ans, cnt);
		}
		else {
			rp = t + 1 - tur[P[nv]];
			rpp = cnt + C[P[nv]] - po[P[nv]];
			if (rpp > 0) {
				if (rp <= K - t) {
					cnt += ((K - t) / rp - 1) * rpp;
					x = (K - t) % rp + rp;
					t = K - x;
				}
				nnv = nv;
				while (t != K) {
					cnt += C[nv];
					ans = max(ans, cnt);
					nv = P[nv];
					t++;
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3772
import java.util.*;
import java.io.*;

 public class Main{
// taking inputs
static BufferedReader s1;
static BufferedWriter out;
static String read() throws IOException{String line="";while(line.length()==0){line=s1.readLine();continue;}return line;}
static int int_v (String s1){return Integer.parseInt(s1);}
static long long_v(String s1){return Long.parseLong(s1);}
static int[] int_arr() throws IOException{String[] a=read().split(" ");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;}
static long[] long_arr() throws IOException{String[] a=read().split(" ");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;}
static void assign(){s1=new BufferedReader(new InputStreamReader(System.in));out=new BufferedWriter(new OutputStreamWriter(System.out));}

//......................................@uthor_Alx..............................................

   public static void main(String[] args) throws  IOException{
	        		  assign();
	        		  	int n=int_v(read());
	        		  	int[] arr=int_arr();
	        		  	Arrays.sort(arr);
	        		  	int[] f=new int[arr[n-1]+1];
	        		  	for(int x:arr){f[x]++;}
	        		  	boolean[] b=new boolean[arr[n-1]+1];
	        		    boolean[] b1=new boolean[arr[n-1]+1];
	        		    Arrays.fill(b,true);
	        		   for(int i=0;i<n;i++){
	        		   	    if(!b[arr[i]]||b1[arr[i]]) continue;
	        		   	    b1[arr[i]]=true;
	        		   		for(int j=2*arr[i];j<arr[n-1]+1;j+=arr[i]){
	        		   			b[j]=false;
	        		   		}
	        		   }
	        		   int res=0;
	        		   for(int i=0;i<n;i++){
	        		   		if(b[arr[i]]&&f[arr[i]]==1){
	        		   			res++;
	        		   		}
	        		   }
	        		  	out.write(res+"");
                      out.flush();
	        		 
	}
}
	       

Measured memory_bytes: 67008
N = int(input())
V_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))

ans = 0

for n in range(N):
  v = V_list[n]
  c = C_list[n]
  if v-c >= 0:
    ans += v-c

print(ans)

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;

int main() {
  ll h, a;
  cin >> h >> a;
  cout << (h + a - 1) / a << endl;
  return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




int main(){
  ll n; cin >> n; vl num(100003); ll ans = 0;
  
  rep(i,n){
    ll x; cin >> x; x++;
    num[x-1]++; num[x]++; num[x+1]++;
  }
  
  rep(i,100002){
    ans = max(ans,num[i]);
  }
  
  
  cout << ans << endl;
  
  
  
}

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

int main() {
    int N;
    cin >> N;
    vector<ull> A(N);
    ull A_sum = 0;
    for (int i=0; i<N; i++) {
        cin >> A[i];
        A_sum += A[i];
    }
    ull sum = 0;
    for (int i=0; i<N-1; i++) {
        A_sum = A_sum - A[i];
        ull A_sum_mod = A_sum % 1000000007;
        sum += A[i] * A_sum_mod;
        sum = sum % 1000000007;
    }
    cout << sum << endl;
}

Measured memory_bytes: 4764
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
int main(){
    int a,b;
    cin >> a >> b;
    int ans = max(2*a-1,max(a+b,2*b-1));
    cout << ans << endl;
}

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

int main(){
  int N, Y;
  cin >> N >> Y;
  
  int res10000 = -1, res5000 = -1, res1000 = -1;
  for(int a = 0; a <= N; a++){
    for(int b = 0; a +b <= N; b++){
      int c = N - a - b;
      if(a * 10000 + b * 5000 + c * 1000 == Y){
        res10000 = a;
        res5000 = b;
        res1000 = c;
      }
    }
  }
  
  cout << res10000 << " " << res5000 << " " << res1000 << endl;
}
          


Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    int k=b/a;
    if(k>=c)
    {
        printf("%d\n",c);
    }
    else printf("%d\n",k);
    return 0;
}


Measured memory_bytes: 256
h,w = map(int,input().split())
li = []
for i in range(h):
    li.append(list(input()))
#print(li)
for i in range(h):
    for j in range(w):
        if li[i][j] == "#":
            continue
        cnt = 0
        for kk in (-1,0,1):
            for ll in (-1,0,1):
                if not 0 <= i+kk < h or not 0<= j+ll < w:
                    continue
                if li[i+kk][j+ll] == "#":
                    cnt += 1
        li[i][j] = str(cnt)
for i in range(h):
    print("".join(li[i]))

Measured memory_bytes: 3188
#include <iostream>
#include <queue>
#include <map>
using namespace std;

typedef long long ll;
int N;
ll A[200010];
ll S[200010] = {0};
int main(){
	cin >> N;
	map<ll,ll> m;
	ll count = 0;
	for(int i=0;i<N;i++){
		cin >> A[i];
		S[i] = S[i-1]+A[i];
		if(S[i]==0) count++;
		m[S[i]]++;
	}
	ll ans = count;
	for(auto x:m){
		ans += (x.second-1)*x.second/2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
char a[5]= {'a','e','i','o','u'};
int main() {
	char c;
	c=getchar();
	for(int i=0; i<5; i++) {
		if(c==a[i]) {
			cout<<"vowel"<<endl;
			return 0;
		}
	}
	cout<<"consonant"<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
s = [0, 0, 0, 0]

for i in range(n):
    st = input()
    if st == 'AC':
        s[0] += 1
    elif st == 'WA':
        s[1] += 1
    elif st == 'TLE':
        s[2] += 1
    else:
        s[3] += 1

print('AC x '+str(s[0]))
print('WA x '+str(s[1]))
print('TLE x '+str(s[2]))
print('RE x '+str(s[3]))

Measured memory_bytes: 9200
H, W = map(int, input().split())
s = ['.'*(W+2)] + ['.'+input()+'.' for i in range(H)] + ['.'*(W+2)]

ans = 'Yes'
for h in range(1, H+1):
  for w in range(1, W+1):
    if s[h][w] == '#':
      if '#' not in [s[h-1][w], s[h+1][w], s[h][w-1], s[h][w+1]]:
        ans = 'No'
        break

print(ans)

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

using namespace std;

using ll=long long;
// in theoretical term, Z/M may called mobius transform/inversion on subset lattice
// O(n 2^n) Yates
#define __loop(f) \
    for (int i = 0, n = 31-__builtin_clz((int)f.size()), MSK = 1<<n; i < n; i++)\
        for (int msk = 0; msk < MSK; msk++)\
            if (msk>>i&1)

void solve() {
    int n; cin >> n;
    vector<vector<pair<int,int>>> g(n);
    for (int i = 0; i < n-1; i++) {
        int x,y;
        cin >> x >> y;
        x--;y--;
        g[x].emplace_back(y,i);
        g[y].emplace_back(x,i);
    }
    vector<int> pth;
    int T;
    function<bool(int,int)> dfs = [&](int u, int p){
        for (auto& e: g[u]) {
            int v,i;
            tie(v,i) = e;
            if (v==p) continue;
            pth.push_back(i);
            if (v == T) return true;
            if (!dfs(v, u)) pth.pop_back();
            else return true;
        }
        return false;
    };
    int m; cin >> m;
    vector<ll> cover(1<<m);
    for (int j = 0; j < m; j++) {
        int x,y;
        cin >> x >> y;
        x--;y--;
        T = y;
        pth.clear();
        dfs(x, -1);
        for (int i: pth) {
            cover[1<<j] |= 1ll<<i;
        }
    }
    __loop(cover) cover[msk] |= cover[msk^1<<i];
    const int MSK = 1<<m; 
    ll res = 0;
    for (int msk = 0; msk < MSK; msk++) {
        int c = n-1 - __builtin_popcountll(cover[msk]);
        int sign = (__builtin_popcount(msk)&1) ? -1 : 1;
        res += sign * (1ll<<c);
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 8448
#include<bits/stdc++.h>
#define ui unsigned int
#define ll long long
#define db double
#define ld long double
#define ull unsigned long long
#define ft first
#define sd second
#define pb(a) push_back(a)
#define PII std::pair<int,int>
#define PLL std::pair<ll,ll>
#define mp(a,b) std::make_pair(a,b)
#define ITR(a,b) for(auto a:b)
#define REP(a,b,c) for(register int a=(b),a##end=(c);a<=a##end;++a)
#define DEP(a,b,c) for(register int a=(b),a##end=(c);a>=a##end;--a)
const int Mod=998244353,MAXN=1<<15,MAXM=200+10;
int r,c,n,m,rev[MAXN];
ll pw[MAXN],ipw[MAXN],inv3,invn,fac[MAXN],inv[MAXN],a[MAXN],b[MAXN],f[MAXM][MAXN],cnt,ans;
template<typename T> inline void read(T &x)
{
	T data=0,w=1;
	char ch=0;
	while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
	if(ch=='-')w=-1,ch=getchar();
	while(ch>='0'&&ch<='9')data=((T)data<<3)+((T)data<<1)+(ch^'0'),ch=getchar();
	x=data*w;
}
template<typename T> inline void write(T x,char ch='\0')
{
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
	if(ch!='\0')putchar(ch);
}
template<typename T> inline bool chkmin(T &x,T y){return y<x?(x=y,true):false;}
template<typename T> inline bool chkmax(T &x,T y){return y>x?(x=y,true):false;}
template<typename T> inline T min(T x,T y){return x<y?x:y;}
template<typename T> inline T max(T x,T y){return x>y?x:y;}
inline ll qexp(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1)res=res*a%Mod;
		a=a*a%Mod;
		b>>=1;
	}
	return res;
}
inline void NTT(ll *A,int tp)
{
	REP(i,0,n-1)if(i<rev[i])std::swap(A[i],A[rev[i]]);
	for(register int l=2;l<=n;l<<=1)
	{
		ll wn=tp>0?pw[l]:ipw[l];
		for(register int i=0;i<n;i+=l)
		{
			ll w=1;
			for(register int j=0;j<(l>>1);++j)
			{
				ll A1=A[i+j],A2=1ll*A[i+j+(l>>1)]*w%Mod;
				A[i+j]=(A1+A2)%Mod,A[i+j+(l>>1)]=(A1-A2+Mod)%Mod;
				w=1ll*w*wn%Mod;
			}
		}
	}
}
inline ll C(int n,int m)
{
	if(n<m)return 0ll;
	return 1ll*fac[n]*inv[m]%Mod*inv[n-m]%Mod;
}
int main()
{
	read(r);read(c);
	m=r+r+3;
	for(n=1,cnt=0;n<m;n<<=1,++cnt);
	REP(i,0,n-1)rev[i]=(rev[i>>1]>>1)|((i&1)<<(cnt-1));
	invn=qexp(n,Mod-2);inv3=qexp(3,Mod-2);
	for(register int l=1;l<=n;l<<=1)
		pw[l]=qexp(3,(Mod-1)/l),ipw[l]=qexp(inv3,(Mod-1)/l);
	fac[0]=1;
	REP(i,1,n+2)fac[i]=1ll*fac[i-1]*i%Mod;
	inv[n+2]=qexp(fac[n+2],Mod-2);
	DEP(i,n+1,0)inv[i]=1ll*inv[i+1]*(i+1)%Mod;
	REP(i,1,r)b[i]=inv[i+2];NTT(b,1);
	f[0][0]=1;
	REP(j,1,c)
	{
		REP(i,0,r)a[i]=1ll*inv[i]*f[j-1][i]%Mod;
		REP(i,r+1,n-1)a[i]=0;
		NTT(a,1);
		REP(i,0,n-1)a[i]=1ll*a[i]*b[i]%Mod;
		NTT(a,-1);
		REP(i,0,r)f[j][i]=1ll*a[i]*invn%Mod*fac[i+2]%Mod;
		REP(i,0,r)(f[j][i]+=1ll*f[j-1][i]*(C(i+1,2)+1)%Mod)%=Mod;
	}
	REP(i,0,r)(ans+=1ll*f[c][i]*C(r,i)%Mod)%=Mod;
	write(ans,'\n');
	return 0;
}


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

using namespace std;

int main(){
    int a,b;
    cin >> a >> b;
    string c;
    if(a > b)c = ">";
    else if(a == b)c = "==";
    else c = "<";
    cout << "a " << c << " b" << endl;
    return 0;
}



Measured memory_bytes: 3164
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#define mod (1e9 + 7)
#define pb push_back
using namespace std;
typedef pair<int,int> pii;

int main(){
  int n,m;
  cin>>n>>m;

  int l,r,ll,rr;
  ll=0;rr=n;
  for(int i=0;i<m;i++){
    cin>>l>>r;
    ll=max(l,ll);
    rr=min(r,rr);
  }
  cout<<max(rr-ll+1,0)<<endl;
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
#include<algorithm>
#include<vector>
#define mod  998244353
#define int long long int
int32_t main()
{
	string str;
	cin>>str;
	int answer=0;
	int count=0;
	int j;
	int l=str.size();
	for(j=0;j<l;j++)
	{
		if(str[j]=='S')
		{
			int p;
			for(p=j;p<l&&str[p]==str[j];p++)
			     count++;
			j=p-1;
		}
		else
		{
			int p,val=0;
			for(p=j;p<l&&str[p]==str[j];p++)
			    val++;
			answer+=2*min(count,val);
			count-=val;
			if(count<0)
			    count=0;
			j=p-1;
		}
	}
	cout<<l-answer<<endl;
}


Measured memory_bytes: 640
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();// 料金所の数
        int x = sc.nextInt();// 今いる場所

        HashMap<Integer, Boolean> box = new HashMap<>();
        // 初期化
        for (int i = 0; i <= n; i++) {
            box.put(i, false);
        }

        for (int i = 0; i < m; i++) {
            int tmpShop = sc.nextInt();// 料金所の場所
            box.put(tmpShop, true);
        }

        int costRight = 0;// マスを右に移動
        for (int i = x; i <= n; i++) {
            if ((boolean)box.get(i) == true) costRight++;
        }

        int costLeft = 0;// マスを左に移動
        for (int i = x; i > 0; i--) {
            if ((boolean)box.get(i) == true) costLeft++;
        }

        System.out.println(Math.min(costLeft, costRight));
    }
}


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

int main() {
    int N, K, A[5005];
    scanf("%d %d", &N, &K);
    for (int i = 0; i < N; i++) scanf("%d", &A[i]);
    sort(A, A+N);

    int B[5005];
    for (int i = 0; i < N; i++) B[i] = 0;
    int i = N;
    int k = K;
    while (i > 0) {
        int j = 0;
        while (j < i && A[j] < k) j++;
        if (j < i) B[j] = 1;
        k -= A[j-1];
        i = j - 1;
    }

    int ans = 0;
    while (B[ans] == 0 && ans < N) ans++;

    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

#define MAX_N (400L)
#define INF (1000000000000000000L)

using namespace std;

long dpss[MAX_N + 1][MAX_N + 1];

void init(long N) {
  for (long i = 0; i <= N; i++) {
    for (long j = 0; j <= N; j++) {
      dpss[i][j] = -1;
    }
  }
}

long calc_cost(const long *as, long b, long e) {
  if (e - b <= 1) {
    return 0;
  }
  if (dpss[b][e] < 0) {
    long dp = INF;
    for (long m = b + 1; m <= e - 1; m++) {
      dp = min(dp, calc_cost(as, b, m) + calc_cost(as, m, e));
    }
    for (long i = b; i < e; i++) {
      dp += as[i];
    }
    dpss[b][e] = dp;
  }
//   printf("b = %ld, e = %ld, dpss[b][e] = %ld\n", b, e, dpss[b][e]);
  return dpss[b][e];
}

int main() {
  // read inputs
  long N, as[MAX_N];
  scanf("%ld", &N);
  for (long i = 0; i < N; i++) {
    scanf("%ld", &as[i]);
  }

  // solve dp
  init(N);
  printf("%ld\n", calc_cost(as, 0, N));
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <stdlib.h>
#include "time.h"
#include "unistd.h"
#include "string.h"
#include <math.h>
int ans=0;
int main(int argc, char* argv[]){
  long a=0,b=0,c=100000000;
  scanf("%ld",&a);
  long d[a];
  for (int i = 0; i < a; i++) {
    scanf("%ld",&d[i]);
  }
  long min=10000,max=-1;
  for (int i = 0; i < a; i++) {
    if (d[i]<min) {
      min=d[i];
    }
    if (d[i]>max) {
      max=d[i];
    }
  }
  b=max+min;
  b=b/2;
  for (int j = min; j <= max; j++) {
    for (int i = 0; i < a; i++) {
      ans += pow(d[i]-j,2);
    }
    if (ans<c) {
      c=ans;
    }
    ans=0;
  }
  printf("%ld",c);
}


Measured memory_bytes: 128
package main

import (
	"fmt"
)


func main(){
	var n int
	fmt.Scanf("%d",&n)
	m:=make(map[string]int)
	keys:=[]string{"AC","WA","TLE","RE"}
	for i:=0;i<n;i++{
		var s string
		fmt.Scanf("%s\n",&s)
		m[s]=m[s]+1
	}
	for _,s:=range keys{
		fmt.Printf("%s x %d\n", s, m[s])
	}

}


Measured memory_bytes: 6344
#include<bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define per(i,n) for(int i=n-1;i>=0;++i)
#define rep1(i,n) for(int i=1; i<=n; ++i)
#define per1(i,n) for(int i=n; i>=1; --i)
#define debug cout << "line : " << __LINE__ << " debug" << endl
#define Dcout(N) cout << setprecision(20) << N << endl
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long ll;
typedef pair<int,int> P;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//const long long INF = 1LL << 60;
//const long long mod = 1e9+7;

//------------------------------------------------------------------------

ll dp[35];
ll a[35];

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int i = 0;
  while(1){
      int n; cin >> n;
      a[i] = n;
      if(n==0) break;
      i++;
  }
  int N = i;

  rep(i,N){
      rep(k,35) dp[k] = 0;
      dp[0] = 1;
      rep(j,a[i]){
          dp[j+1] += dp[j];
          dp[j+2] += dp[j];
          dp[j+3] += dp[j];
      }
      ll tmp = (dp[a[i]]/10);
      if(tmp%365==0 && tmp!=0) cout << tmp/365 << endl;
      else cout << tmp/365 + 1 << endl;
  }


  return 0;
}



Measured memory_bytes: 3004
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Scanner;

/**
 * 0007:Debt Hellの解答
 * 
 * @author MS14A
 * @version 2015/04/15
 */
public class Main {

    /** 初期借金額：10万円 */
    private static final BigDecimal INITIAL_DEBT = new BigDecimal("100000");

    /** 利子：5% */
    private static final BigDecimal INTEREST_RATE = BigDecimal.valueOf(0.05);

    /** \1000未満の繰り上げ計算用 */
    private static final BigDecimal DIVISOR_FOR_ROUND_UP = BigDecimal.valueOf(1000);

    /**
     * n 週間後の借金の残高を出力する。<br>
     * ※n は 100 以下とする。
     * 
     * @param args
     * @throws IOException 
     */
    public static void main(String[] args) throws IOException {
        // 標準入力読み取り
        int weeks = getWeeks();

        // n週間後の借金額計算
        System.out.println(calcDebt(weeks));
    }

    /**
     * 標準入力を読み取り、"n"の値を返す。
     * 
     * @return n：入力値
     * @throws IOException 
     */
    private static int getWeeks() throws IOException {
        
        /*InputStreamReader streamReader = new InputStreamReader(System.in);
        BufferedReader bufferedReader = new BufferedReader(streamReader);
        
        int n = bufferedReader.read();
        
        bufferedReader.close();
        streamReader.close();*/
        
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        
        return n;
    }

    /**
     * n週間後の借金額を計算する。
     * 
     * @param weeks
     */
    private static BigDecimal calcDebt(int weeks) {
        BigDecimal finalDebt = INITIAL_DEBT;

        for (int i = 0; i < weeks; i++) {
            // 利子額計算。1000で割った小数部を繰り上げる。
            BigDecimal interestAmount = finalDebt.multiply(INTEREST_RATE)
                    .divide(DIVISOR_FOR_ROUND_UP, 0, BigDecimal.ROUND_UP);

            // 借金額 = 前週の借金額 + 利子額
            finalDebt = finalDebt.add(interestAmount.multiply(DIVISOR_FOR_ROUND_UP));
        }

        return finalDebt;
    }

}

Measured memory_bytes: 17236
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        int count =0;
        for(int i=0;i<n;i++){
            int tall = sc.nextInt();
            if(tall >= k){
                count++;
            }
        }
        System.out.println(count);


    }
}

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

int main() {
  int h;
  cin >> h;
  int w;
  cin >> w;
  vector<string> a(h);
  for(int i=0; i<h; i++)
    cin >> a[i];
 
  vector<bool> col(h, false);
  vector<bool> row(w, false);
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      if( a[i][j] =='#'){
        col[i] =true;
        row[j] =true;
      } 
    }
  }
  
  for(int i=0; i<h; i++){
    if(col[i]){
      for(int j=0; j<w; j++){
        if(row[j])
          cout << a[i][j];
      }
    }
    cout << endl;
  }
  return 0;
}  

Measured memory_bytes: 256
#include<iostream>

using namespace std;

void swap(int &x,int &y){
    int tmp = x;
    x = y;
    y = tmp;
}

int main(){
    int x,y;
    cin >> x >> y;
    if(x < y) swap(x,y);
    while(y != 0){
        int tmp = x;
        x = y;
        y = tmp % y;
    }
    cout << x << endl;
    return 0;
}


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

#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N;
  double tmp_a;
  double result = 0;

  cin >> N;
  REP(i, N) { 
    cin >> tmp_a; 
    result += 1 / tmp_a;
  }

  cout << setprecision(10) << 1/result << endl;

  return 0;
}


Measured memory_bytes: 256
//This Code was made by Chinese_zjc_.
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<bitset>
#include<cmath>
#include<queue>
#include<stack>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<map>
#include<set>
#include<time.h>
// #include<windows.h>
#define int long long
#define PI 3.14159265358979323
#define INF 0x3fffffffffffffff
using namespace std;
int ans;
double x,X,Y,t;
signed main()
{
    ios::sync_with_stdio(false);
    cin>>x;
    x=x*PI/180;
    X+=sin(t);Y+=cos(t);
    // cout<<t<<' '<<sin(t)<<' '<<cos(t)<<endl;
    t+=x;
    ++ans;
    while(abs(X)>0.00000005||abs(Y)>0.00000005)
    {
        X+=sin(t);Y+=cos(t);
        // cout<<t<<' '<<sin(t)<<' '<<cos(t)<<endl;
        t+=x;
        ++ans;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4072
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

signed main(void)
{
    int H, W, K;
    cin >> H >> W >> K;
    string c[H];
    for (int i = 0; i < H; i++) {
        cin >> c[i];
    }
    int ans = 0;
    for (int i = 0; i < (1<<H); i++) { //除外列(1<<H)は2^H
        for (int j = 0; j < (1<<W); j++) { //除外行
            
            int cnt = 0;
            for (int k = 0; k < H; k++) {
                if ((i & (1<<k)) != 0) continue; //列挙にkが含まれたらカウントしない
                
                for (int l = 0; l < W; l++) {
                    if ((j & (1<<l)) != 0) continue; //列挙にlが含まれたらカウントしない
                    if (c[k][l] == '#') cnt++;
                }
            }
            if (cnt == K) ans++;
        }
    }
    mes(ans);
    re0;
    
    
    
    
}

Measured memory_bytes: 3632
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        long[] b = new long[n];
        Long[] c = new Long[n];
        long bSum = 0;
        for (int i = 0; i <n ; i++) {
            a[i] = sc.nextLong();
            b[i] = sc.nextLong();
            bSum += b[i];
            c[i] = a[i] + b[i];
        }
        Arrays.sort(c, Comparator.reverseOrder());
        long ans = 0;
        for (int i = 0 ; i < n ; i++) {
            if (i % 2 == 0) {
                ans += c[i];
            }

        }
        System.out.println(ans - bSum);
    }

}

Measured memory_bytes: 96376
#include <iostream>
#include <vector>
#include <map>
using namespace std;
long long MOD = 1000000007;
int main(){
	int N;
	cin >> N;
	vector<int> C(N + 1);
	for (int i = 1; i <= N; i++){
		cin >> C[i];
	}
	map<int, int> mp;
	vector<int> prev(N + 1);
	for (int i = 1; i <= N; i++){
		prev[i] = mp[C[i]];
		mp[C[i]] = i;
	}
	vector<long long> dp(N + 1);
	dp[0] = 1;
	for (int i = 1; i <= N; i++){
		if (prev[i] == i - 1 || prev[i] == 0){
			dp[i] = dp[i - 1];
		} else {
			dp[i] = dp[i - 1] + dp[prev[i]];
			dp[i] %= MOD;
		}
	}
	cout << dp[N] << endl;
}

Measured memory_bytes: 15568
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>

#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    bool ok = true;
    for(int i = 0; i < n; ++i){
        if((i + 1) % 2 == 0){
            if(s[i] == 'R') {ok = false; break;}
        }
        if((i + 1) % 2 != 0){
            if(s[i] == 'L') {ok = false; break;}
        }
    }
    if(ok == true) cout << "Yes" << endl;
    else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
			int n = sc.nextInt();
			double result = 100000;
				for(int i = 0; n > i; i++)
				{
					result = result * 1.05;
					result = ((int)((result + 999)/1000))*1000;
				}
			System.out.println((int)result);
	}
}

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

int main() {
    ll n;
    cin >> n;

    string ans = "";

    ll hoge_a, hoge_b;
    int cnt = 1;
    for (int i = 1; i < 12; i++)
    {
        hoge_a = hoge_b;
        hoge_b += pow(26, i);
        if (hoge_a <= n && n <= hoge_b) {
            break;
        }
        cnt++;
    }
    
    for (int i = 0; i < cnt; i++)
    {
        int hoge = n % 26;
        if (hoge == 0) {
            hoge = 26;
            n -= 1;
        }
        ans += 96 + hoge;
        n /= 26;
    }
    
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4096
solve :: Int -> Int -> Int
solve n x = length [[a,b,c] | a <- [1..n], b <- [1..n], c <- [1..n], a + b + c == x, a /= b, b /= c, a /= c] `div` 6

main = do
	[n,x] <- fmap (map read . words) getLine
	if [n,x] == [0,0]
		then return ()
		else do
			putStrLn $ show $ solve n x
			main

Measured memory_bytes: 5396
#include<bits/stdc++.h>
using namespace std;
         
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define mod 1000000007  
const int N = 100001; 

// bool sortbysec(const pair<int,int> &a, const pair<int,int> &b){ 
//     return (a.second < b.second);}
 
// int fexp(int a, int b,int m){int ans = 1;while(b){if(b&1)ans=ans*a%m; b/=2;a=a*a%m;}return ans;}
// int inverse(int a, int p){return fexp(a, p-2,mod);} 

// int fac[2000001];

// int nCrModPFermat(int n, int r,int p) { 
//     if (r==0) return 1; 
//     return (fac[n]*inverse(fac[r],p)%p*inverse(fac[n-r],p)%p)%p; 
// }
 
void solve(){
	int n;cin>>n;
	int ans=n%1000;
	ans=1000-ans;
	ans=ans%1000;
	cout<<ans;

    return ;
}
         
signed main(){
        IOS;    


        int t=1;
        // cin>>t;
        // fac[0] = 1; 
        // for (int i=1 ; i<=2000001; i++) fac[i] = fac[i-1]*i%mod; 
        rep(i,0,t){
            solve();
            cout<<"\n";
        //   cout<<" * "<<t<<"\n";
        }
    //    return 0;
}

Measured memory_bytes: 3648
#include<cstdio>
#include<cstring>
using namespace std;
	int n,k;
	long long ans;
	long long a[16];
void dfs(int now,long long fee)
{
	if (fee>=ans)
		return;
	int x=0;
	int last=0;
	for (int i=1;i<=n;i++)
		if (a[i]>a[last])
		{
			x++;
			last=i;
		}
	if (x==k)
	{
		if (fee<ans) ans=fee;
		return;
	}
	last=0;
	for (int i=1;i<now;i++)
		if (a[i]>a[last])
			last=i;
	for (int i=now;i<=n;i++)
	{
		if (a[i]>a[last])
		{
			last=i;
			continue;
		}
		long long b=a[i];
		a[i]=a[last]+1;
		dfs(i+1,fee+a[last]-b+1);
		a[i]=b;
	}
}
int main()
{
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	if (n==k)
	{
		long long ans=0;
		for (int i=1;i<=n;i++)
			if (a[i]<=a[i-1])
			{
				ans+=a[i-1]-a[i]+1;
				a[i]=a[i-1]+1;
			}
		printf("%lld\n",ans);
		return 0;
	}
	ans=15000000000;
	dfs(1,0);
	printf("%lld\n",ans);
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

ll f(ll a) {
    ll res = 0;
    if (a%4==1||a%4==2) res |= 1;
    ll m = 1;
    int i = 0;
    while (1) {
        m *= 2;
        ++i;
        ll r = a / m;
        if (r==0) break;
        r %= 2;
        if (r) {
            res |= (1-a%2)<<i;
        }
    }
    return res;
}

int main(){
    ll a, b;
    cin >> a >> b;
    ll ans = f(b) ^ f(a-1);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,ans;cin>>n;
    if(n<10)ans=n;
    else if(10<=n and n<100)ans=9;
    else if(100<=n and n<1000)ans=n-99+9;
    else if(1000<=n and n<10000)ans=909;
    else if(10000<=n and n<100000)ans=n-9999+909;
    else {ans=90909;}
    cout<<ans<<endl;

}


Measured memory_bytes: 256
# encoding: utf-8
fline = gets
ary = []
ary = fline.split(" ")

if ary.include?('7')
  if ary.select{|n| n === '5'}.count === 2
    ans = 'YES'
  else
    ans = 'NO'
  end
else
  ans = 'NO'
end

puts ans

Measured memory_bytes: 1788
#include <iostream>
#include <cstdint>

#define INF (INT32_MAX/2)

using namespace std;
#define MAXN 50000
#define MAXM 20
int n,m,c[20],t[MAXM+1][MAXN+1];

int main() {
	cin >> n >> m;
	for(int i = 0;i < m;i++) cin >> c[i];
	for(int i = 0;i < MAXM+1;i++) for(int j = 1;j < MAXN+1;j++) t[i][j] = INF;
	for(int i = 1;i <= n;i++) for(int j = 1;j <= m;j++) {
		t[j][i] = min(t[j-1][i],t[j][i - c[j-1]]+1);
	}
	cout << t[m][n] << endl;
}


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

using namespace std;

int main(void) {
  int n;
  cin >> n;

  vector<int> s(n);
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    sum += s[i];
  }

  if (sum % 10 == 0) {
    sort(s.begin(), s.end());
    for (int i = 0; i < n; i++) {
      if (s[i] % 10 == 0) continue;
      cout << sum - s[i] << endl;
      return 0;
    }
    cout << 0 << endl;
  } else {
    cout << sum << endl;
  }

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    while (true) {
      int x = scanner.nextInt();
      int y = scanner.nextInt();
      if (x == 0 && y == 0) break;
      if (x < y) {
        System.out.println(x + " " + y);
      } else {
        System.out.println(y + " " + x);
      }
    }
  }
}

Measured memory_bytes: 27152
n,m,q=map(int,input().split())
A=[]
B=[]
C=[]
D=[]

for i in range(q):
  a,b,c,d=map(int,input().split())
  A.append(a)
  B.append(b)
  C.append(c)
  D.append(d)

ans=0
#print(A)
#print(B)
#print(C)
#print(D)

#mCn
def dfs(l):
  global ans # UnboundLocalError: local variable 'ans' referenced before assignment
  if len(l)==n+1:
    #print(l)
    tmp=0
    for i in range(q):
      #print(l[B[i]],l[A[i]],C[i])
      if l[B[i]]-l[A[i]]==C[i]:
        tmp+=D[i]
    ans=max(ans,tmp)
    return
  x=l[len(l)-1]
  while x<=m:
    y=l[:]
    y.append(x)
    dfs(y)
    x+=1

dfs([1])
print(ans)


Measured memory_bytes: 77420
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 06/02/20 00:02:53
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);

  int n; cin>>n;
  vector<int> graph[n];
  for (int i = 0; i < n-1; i++) {
    int a,b; cin>>a>>b; a--; b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  vector<int> dist(n);
  vector<int> path;
  auto set_dist = [&graph, &dist, n, &path](auto& f, int s, int p, int d) -> bool {
    dist[s] = d;
    bool leached = s == n-1;
    for (auto t:graph[s]) {
      if (t == p) continue;
      leached |= f(f, t, s, d+1);
    }
    if (leached)
      path.push_back(s);
    return leached;
  };
  set_dist(set_dist, 0, -1, 0);
  reverse(path.begin(), path.end());
  vector<int> color(n, -1);
  for (int i = 0; i < (path.size()+1)/2; i++) {
    color[path[i]] = 0;
  }
  for (int i = path.size()-1; i >= (path.size()+1)/2; i--) {
    color[path[i]] = 1;
  }
  auto set_color = [&color, &graph](auto& f, int s, int p, int c) -> void {
    color[s] = c;
    for (auto t:graph[s]) {
      if (t == p) continue;
      if (color[t] == -1) {
        f(f, t, s, c);
      }
    }
  };
  for (auto p:path) {
    set_color(set_color, p, -1, color[p]);
  }
  int bs = 0, ws = 0;
  for (auto c:color) {
    if (c == 0)
      bs++;
    else
      ws++;
    assert(c != -1);
  }
  cout << (bs > ws ? "Fennec" : "Snuke") << endl;

  return 0;
}


Measured memory_bytes: 10360
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    int a[n+5];
    for(int i=0;i<n;i++)
    cin>>a[i];
    sort(a,a+n);
    int ans=0;
    for(int i=0;i<k;i++)
    ans+=a[i];
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3600
// package app;

import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);

        // final String S = sc.next();
        // final int A = sc.nextInt();
        // final int A = sc.nextInt();
        // final int B = sc.nextInt();
        // final int C = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();

        // System.out.println();
        System.out.println(A * B % 2 == 0 ? "Even" : "Odd");

        // System.out.println(A <= X && A + B >= X ? "YES" : "NO");

    }
}

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

using namespace std;

// Repetitions
#define FOR(i,a,n) for(ll i = ((ll) a); i < ((ll) n); ++i)
#define FORR(i, s, g) for(ll i = ((ll)s - 1); i >= ((ll) g); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)

// Container Utils
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SORTALL(v) sort(ALL(v))
#define SZ(a) int((a).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

// For Debug
#define DMP(x)  cerr << #x << " = " << (x) << endl
#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

// Aliases
#define PB push_back
#define MP make_pair
using ll = long long;
using ld = long double;
using str = string;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vs = vector<str>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;

// Constant variables
const ld PI = (acos(-1));
const ll MOD = 1000000007;

// I/O Asynchronizing
struct __io_async{
    __io_async(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
};

#define MAX_H 500
#define MAX_W 500
int h, w;
int a[MAX_H][MAX_W];
bool is_selected[MAX_H][MAX_W];
int dx[] = { 1, 0 };
int dy[] = { 0, 1 };
queue<pair<pii, pii>> que;

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

void op() {
    REP(j, h) {
        REP(i, w) {
            if(a[j][i] % 2 == 1) {
                REP(k, 2) {
                    int ny = j + dy[k], nx = i + dx[k];
                    if(is_in_range(ny, nx)) {
                        a[j][i]--;
                        a[ny][nx]++;
                        que.push(make_pair(make_pair(j + 1, i + 1), make_pair(ny + 1, nx + 1)));
                        break;
                    }
                }
            }
        }
    }
}

int main() {
    cin >> h >> w;
    REP(j, h) {
        REP(i, w) {
            cin >> a[j][i];
        }
    }
    op();
    cout << que.size() << endl;
    while(!que.empty()) {
        int oy = que.front().first.first, ox = que.front().first.second, ny = que.front().second.first, nx = que.front().second.second;
        que.pop();
        cout << oy << " " << ox << " " << ny << " " << nx << endl;
    }
    return 0;
}


Measured memory_bytes: 5120
from math import atan, pi
a, b, x = map(int, input().split())
if x >  a*a*b-x:
    x = a*a*b-x
    rad = atan(2*x/(a*a*a))
    print(rad/pi * 180)
else:
    rad = atan(a*b*b/(2*x))
    print(rad/pi * 180)

Measured memory_bytes: 9332
#include <cstdio>
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;

int main()
{
   int n;
   cin >> n;

   vector<vector<int> > arr{{}, {}};

   int x;
   for (int i=0; i<2; i++) {
      for (int j=0; j<n; j++) {
         cin >> x;
         arr[i].push_back(x);
      }
   }

   int max = 0, tmp, sum0, sum1;
   for (int k=0; k<n; k++) {
      sum0 = accumulate(&arr[0][0], &arr[0][k+1], int(0));
      sum1 = accumulate(&arr[1][k], &arr[1][n], int(0));
      tmp = sum0 + sum1;
      if (max < tmp) {
         max = tmp;
      }
   }

   cout << max <<endl;

   return 0;
}

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

using namespace std;

int max(int a,int b)
{
	return  a > b ? a : b;
}

int main()
{
	std:ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int N,W;
	cin >> N >> W;
	
	int weight[N];
	int profit[N];
	
	for(int i=0;i<N;i++)
		cin >> weight[i] >> profit[i];
	
	unsigned long long int dp[N+1][W+1];
	for(int i=0;i<=N;i++)
		dp[i][0]=0;
	for(int i=0;i<=W;i++)
		dp[0][i]=0;
	
	for(int i=1;i<=N;i++)
	{
		for(int j=1;j<weight[i-1];j++)
			dp[i][j]=dp[i-1][j];
		
		for(int j=weight[i-1];j<=W;j++)
			dp[i][j]=max(dp[i-1][j],profit[i-1]+dp[i-1][j-weight[i-1]]);
	}
	cout<<dp[N][W];
	return 0;
}

Measured memory_bytes: 79232
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using lint = long long;

int main()
{
    lint n, q;

    scanf("%lld", &n);
    scanf("%lld", &q);

    std::vector<lint> count_direct(n);
    std::vector<lint> seen(n, 0);
    std::vector<std::vector<lint>> tree(n);

    for (lint i = 0; i < n - 1; ++i)
    {
        lint a, b;
        scanf("%lld", &a);
        scanf("%lld", &b);

        tree[a - 1].push_back(b - 1);
        tree[b - 1].push_back(a - 1);
    }

    for (lint i = 0; i < q; ++i)
    {
        lint p, x;
        scanf("%lld", &p);
        scanf("%lld", &x);

        count_direct[p - 1] += x;
    }

    lint carry = 0;

    std::deque<std::pair<lint, lint>> deq;

    std::vector<lint> ans(n, 0);

    deq.push_back(std::make_pair(0, 0));
    seen[0] = true;

    while (!deq.empty())
    {
        auto cur = deq.front();
        deq.pop_front();

        lint idx = cur.first;
        lint carry = cur.second;

        lint add = carry + count_direct[idx];
        ans[idx] = add;

        for (auto next = tree[idx].begin(); next != tree[idx].end(); next++)
        {
            if (!seen[*next])
            {
                deq.push_back(std::make_pair(*next, add));
                seen[*next] = 1;
            }
        }
    }

    for (int i = 0; i < n; ++i)
    {
        if (i != n - 1)
            std::cout << ans[i] << " ";
        else
            std::cout << ans[i];
    }

    return 0;
}


Measured memory_bytes: 22640
using System;
using System.Linq;

namespace abc060_b
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            bool find = false;
            for (int i = 1; i < x[1] * 1000 && !find; i++)
            {
                if (x[0] * i % x[1] == x[2])
                {
                    find = true;
                }
            }
            Console.WriteLine(find ? "YES" : "NO");
        }
    }
}

Measured memory_bytes: 11220