akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h> //library
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //for-loop (from 0)
#define reps(i,n) for(int i = 1; i <= (int)(n); i++) //for-loop (from 1)
#define all(x) (x).begin(),(x).end() //start-to-end iteration, mainly in upper_bound, lower_bound
#define SZ(x) ((int)(x).size()) //unsigned to signed

using namespace std;
using ll = long long; //long long
ll M = 1000000000 + 7;
const ll INF = 1LL << 60;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; } //compare a,b and replace by greater
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; } //compare a,b and replace by smaller
ll qp(int a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; } //power
ll qp(int a, ll b, ll Mod = M) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%Mod; a = 1ll * a*a%Mod; } while (b >>= 1); return ans; } //power(mod)
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; } //gcd
int dx[4] = { 1,0,-1,0 }; //path
int dy[4] = { 0,1,0,-1 }; //path
ll RS(ll N, ll P, ll Mod = M) { if (P == 0)return 1; else if (P % 2 == 0) { ll sq = RS(N, P / 2, Mod); return sq*sq%Mod; } else { return N*RS(N, P - 1, Mod) % Mod; } } //power(mod)(repeat-square,fast)
ll nPr(ll n, ll r, ll Mod = M) { ll ans = 1; rep(i, r) { ans = ans * (n - i) % Mod; } return ans; } //permutation
ll nCr(ll n, ll r) { ll bunbo = 1; ll bunshi = 1; rep(i, r) { bunbo = bunbo * (i + 1); bunshi = bunshi * (n - i); } return bunshi / bunbo; } //combination

int main(void) {
  ll N; cin >> N;
  vector<ll> A(N); vector<ll> B(N+1,0);
  rep(i,N){
    cin >> A[i];
    B[A[i]]++;
  }
  vector<ll> nCr_arr(N+1,0);
  vector<ll> nCrmi1_arr(N+1,0);
  reps(i,N){
    if (B[i] <= 1){
      nCr_arr[i] = 0;
      nCrmi1_arr[i] = 0;
    }
    if (B[i] == 2){
      nCr_arr[i] = nCr(B[i],2);
      nCrmi1_arr[i] = 0;
    }
    else{
      nCr_arr[i] = nCr(B[i],2);
      nCrmi1_arr[i] = nCr(B[i]-1,2);
    }
  }
  ll res_orig = 0;
  reps(i,N){
    res_orig += nCr_arr[i];
  }

  rep(i,N){
    cout << res_orig - nCr_arr[A[i]] + nCrmi1_arr[A[i]] << "\n";
  }
  return 0;
}


Measured memory_bytes: 8832
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    int n,k;
    long long s=4000000000000000000;
    vector<pair<int,int>> p(50);
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>p[i].first>>p[i].second;
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            long long a=min(p[i].first,p[j].first),b=max(p[i].first,p[j].first);
            for(int m=0;m<n;m++){
                for(int l=0;l<n;l++){
                    long long t=0,c=min(p[m].second,p[l].second),d=max(p[m].second,p[l].second);
                    long long u=(b-a)*(d-c);
                    for(int h=0;h<n;h++){
                        long long x=p[h].first,y=p[h].second;
                        if(x>=a&&x<=b&&y>=c&&y<=d)t++;
                    }
                    if(t>=k)s=min(s,u);
                }
            }
        }
    }
    cout<<s<<endl;
    
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	const char* kugyu = "You are an idiot!";
	char S[1024];
	if (scanf("%1023s", S) != 1) return 1;
	switch (S[0]) {
		case 'S': kugyu = "Cloudy"; break;
		case 'C': kugyu = "Rainy"; break;
		case 'R': kugyu = "Sunny"; break;
	}
	puts(kugyu);
	return 0;
}


Measured memory_bytes: 128
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,k,s=0;
    cin>>n;
    k=n;
    while(k>0){
        s+=k%10;
        k/=10;
    }
    cout<<((n%s)?"No":"Yes");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n+1;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int n,k;
  cin >>n>>k;
  vector<int> l(n);
  rep(i,n) cin >>l[i];
  sort(l);
  reverse(l);
  int ans = 0;
  rep(i,k) ans += l[i];
  cout << ans << endl;
}

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

using namespace std;
using ull = unsigned long long;
using ll = long long;

int main()
{
	int count = 0;
	int n;
	cin >> n;
	for (int a = 1; a < n; a++)
	{
		int max_b = n / a + 1;
		for (int b = 1; b < max_b; b++)
		{
			if (int c = n - a * b; c > 0)
			{
				count++;
			}
		}
	}
	cout << count << endl;
}

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

int main(){
  int x, ans;
  cin >> x;
  ans = x / 500 * 1000;
  x %= 500;
  ans += (x / 5) * 5;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define print(A,n) for(ll i=0;i<n;++i)cout<<A[i]<<' ';cout<<endl;
#define take(A,n) for(ll i=0;i<n;++i)cin>>A[i];
//    for(auto& it : m)
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);}
//  priority_queue<ll int> pq;
//  priority_queue <ll int, vector<ll int>, greater<ll int> > pq;
//  vector<ll int> v;
//  vector< pair<ll int,ll int> > v;
//  set<ll int>::iterator it=s.begin();
//  unordered_map<  pair<ll int,ll int>, ll int> mp;

 

ll int power(ll int x, ll int y, ll int p)  
{  
    ll int res = 1;     // Initialize result  
  
    x = x % p; // Update x if it is more than or  
                // equal to p 
   
    if (x == 0) return 0; // In case x is divisible by p; 
  
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}  

void computeLPSArray(string pat, int M, int* lps) 
{ 
    // length of the previous longest prefix suffix 
    int len = 0; 
  
    lps[0] = 0; // lps[0] is always 0 
  
    // the loop calculates lps[i] for i = 1 to M-1 
    int i = 1; 
    while (i < M) { 
        if (pat[i] == pat[len]) { 
            len++; 
            lps[i] = len; 
            i++; 
        } 
        else // (pat[i] != pat[len]) 
        { 
            // This is tricky. Consider the example. 
            // AAACAAAA and i = 7. The idea is similar 
            // to search step. 
            if (len != 0) { 
                len = lps[len - 1]; 
  
                // Also, note that we do not increment 
                // i here 
            } 
            else // if (len == 0) 
            { 
                lps[i] = 0; 
                i++; 
            } 
        } 
    } 
}


int main()
{
  fastio();

 
ll int T;
T=1;
while(T--)
{	
	ll int i;
string s;
cin>>s;
for(i=0;i<s.size();i++)
	if(s[i]=='?')s[i]='D';
cout<<s<<endl;

}
    return 0;
}


Measured memory_bytes: 3748
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T>
bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll N; cin>>N;
    vector<ll> ans(N);
    ll ct=0;
    ll sum=0;
    ll buf=-1;
    if(N%2==0){
        ans[ct++]=2;
        sum+=2;
    }
    reps(i,3,27500){
        if(i%2==0){
            if(ct==N-2) continue;
            if(buf==-1){
                buf=i;
            }
            else{
                ans[ct++]=buf;
                sum+=buf;
                ans[ct++]=i;
                sum+=i;
                buf=-1;
            }
        }
        else if(i%3==0 or i%5==0 or i%7==0 or i%11==0){
            ans[ct++]=i;
            sum+=i;
        }
        if(ct==N-1) break;
        if(i==27499) assert(0);
    }
    repr(i,30000,1){
        if(i%2==0 or i%3==0 or i%5==0 or i%7==0 or i%11==0){
            if((sum+i)%2310==0){
                ans[N-1]=i; break;
            }
        }
    }
    rep(i,N){
        cout<< ans[i] <<" ";
    }
    cout<<"\n";
}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 512
#include<iostream>

using namespace std;

int main(){
  int k,s,c=0,z;
  cin>>k>>s;
  for(int i=0;i<=k;i++){
    for(int j=0;j<=k;j++){
      z=s-i-j;
      if(z>=0 && z<=k) c++;
    }
  }
  cout<<c<<endl;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using namespace std;
using ll=long long;

ll convert(char c){
	if(isdigit(c))
		return c - '0';
	else
		return c -'A'+10;
}

const int prime[11]={2,3,5,7,11,13,17,19,23,29,31};

int main(void){
	ll n;
	string m;
	while(cin >> n >> m,n){
		ll num[11]={0};		
		ll mten=0LL;

		for(auto &d:m) mten=n*mten+convert(d);
		rep(i,11){
			ll cur=prime[i];
			while(1){
				num[i]+=mten/cur;
				if(cur>mten/prime[i]) break;
				cur*=prime[i];
			}
		}
		ll ans=-1LL;
		rep(i,11){
			ll cur=n,coef=0LL;
			while(cur%prime[i]==0) cur/=prime[i],coef++;  
			if(coef==0) continue;
			if(ans==-1)
				ans=num[i]/coef;
			else
				chmin(ans,num[i]/coef);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3048
X, Y, Z, K = map(int,input().split())
A = sorted(list(map(int, input().split())),reverse=True)
B = sorted(list(map(int, input().split())),reverse=True)
C = sorted(list(map(int, input().split())),reverse=True)

ans = []

for i in range(X):
    for j in range(Y):
        if (i+1)*(j+1) > K:
            break
        for t in range(Z):
            if (i+1)*(j+1)*(t+1) > K:
                break
            ans.append(A[i]+B[j]+C[t])
ans.sort(reverse=True)

for l in range(K):
    print(ans[l])

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

using namespace std;

#define INF 999999999
#define REP(i,n) for(int i=0; i<(int)(n); i++)

int dp[10][10][2][2];

int main(){
	int i, j, k, l;
	int ans;
	string in;
	int di[2][2] = {{1,0},{0,1}};
	//cout << in.max_size();
	while(1){
		cin >> in;
		if(in[0]=='#') break;
		REP(a,10)REP(b,10)REP(c,2)REP(d,2)dp[a][b][c][d]=INF;
		dp[5][5][0][0] = 0;
		dp[5][5][1][0] = 0;
		REP(e,in.size()){
			/*
			for(i=1;i<=9;i++){
				for(j=1;j<=9;j++){
					if(dp[i][j][0][0]==INF) cout << "-1 ";
					else cout << dp[i][j][0][0] << " ";
				}
				cout << endl;
			}
			cout << endl;
			for(i=1;i<=9;i++){
				for(j=1;j<=9;j++){
					if(dp[i][j][1][0]==INF) cout << "-1 ";
					else cout << dp[i][j][1][0] << " ";
				}
				cout << endl;
			}
			cout << endl;
			*/
			int s = in[e] - '0';
			for(i=1;i<=9;i++)for(j=1;j<=9;j++)REP(c,2){
				if(dp[i][j][c][0]!=INF){
					if(i==s)
					dp[s][j][0][1] = min(dp[s][j][0][1],dp[i][j][c][0]+di[c][0]);
					if(j==s)
					dp[i][s][1][1] = min(dp[i][s][1][1],dp[i][j][c][0]+di[c][1]);
					if(i==5)
					dp[i][s][1][1] = min(dp[i][s][1][1],dp[i][j][c][0]+di[c][1]);
					if(j==5)
					dp[s][j][0][1] = min(dp[s][j][0][1],dp[i][j][c][0]+di[c][0]);
					if(i!=s&&i!=5&&(i-1)%3<=(s-1)%3)
					dp[i][s][1][1] = min(dp[i][s][1][1],dp[i][j][c][0]+di[c][1]);
					if(j!=s&&j!=5&&(s-1)%3<=(j-1)%3)
					dp[s][j][0][1] = min(dp[s][j][0][1],dp[i][j][c][0]+di[c][0]);
				}
			}
			REP(a,10)REP(b,10)REP(c,2){
				dp[a][b][c][0]=dp[a][b][c][1];
				dp[a][b][c][1]=INF;
			}
		}
		ans = INF;
		for(i=1;i<=9;i++)for(j=1;j<=9;j++)REP(c,2){
			if(dp[i][j][c][0] < ans)ans = dp[i][j][c][0];
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1316
#include<bits/stdc++.h>
using namespace std;
const int N=500010;
int a[N];
int res;
int tr[N];
int ans[N];
int n;
int lowbit(int x)
{
	return x&-x;
}
void add(int x,int d)
{
	for(int i=x;i<=n;i+=lowbit(i))
	tr[i]+=d;
}
int query(int x)
{
	int res=0;
	for(int i=x;i;i-=lowbit(i))
		res+=tr[i];
		return res;
}
struct node{
	int l;
	int r;
	int id;
	bool operator < (const node&W)const
	{
			return 	r<W.r;
	}
}q[N];
int c[N],b[N];
int pos[N];
int m;
void solve()
{
	int cur=0;
	int res=0;
	for(int i=1;i<=q[0].r;i++)
	{
		if(pos[a[i]])
		{
			add(pos[a[i]],-1);
			add(i,1);
			pos[a[i]]=i;
		}
		else
		{
			pos[a[i]]=i;
			add(i,1);
		}
	}
	cur=q[0].r+1;
	ans[q[0].id]=query(q[0].r)-query(q[0].l-1);
	for(int i=1;i<m;i++)
	{
		for(int j=cur;j<=q[i].r;j++)
		{
			if(pos[a[j]])
			{
				add(pos[a[j]],-1);
				pos[a[j]]=j;
				add(j,1);
			}
			else
			{
				pos[a[j]]=j;
				add(j,1);
			}	
		}
		cur=q[i].r+1;
		ans[q[i].id]=query(q[i].r)-query(q[i].l-1);
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	cin>>a[i];
	for(int i=0;i<m;i++)
	{
		scanf("%d%d",&q[i].l,&q[i].r);
		q[i].id=i;
	 } 
	 sort(q,q+m);
	 solve();
	for(int i=0;i<m;i++)
	printf("%d\n",ans[i]);
	return 0; 
 } 

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

using namespace std;

const int INF = 1 << 30;

struct Data
{
  int small, big;
};

int N, K;
int value[100000];
vector< int > tree[100000];
bool c[100000];
int small[100000], big[100000];

void color(int idx, bool now, int par = -1)
{
  if(~value[idx] && value[idx] % 2 != now) {
    puts("No");
    exit(0);
  }
  c[idx] = now;
  for(int to : tree[idx]) {
    if(to == par) continue;
    color(to, now ^ 1, idx);
  }
}

int main()
{
  cin >> N;
  for(int i = 0; i < N - 1; i++) {
    int A, B;
    cin >> A >> B;
    tree[--A].push_back(--B);
    tree[B].push_back(A);
  }
  cin >> K;
  memset(value, -1, sizeof(value));
  for(int i = 0; i < K; i++) {
    int V, P;
    cin >> V >> P;
    value[--V] = P;
  }
  queue< int > que;
  fill_n(small, 100000, -INF);
  fill_n(big, 100000, INF);

  bool first = false;
  for(int i = 0; i < N; i++) {
    if(~value[i]) {
      que.push(i);
      small[i] = big[i] = value[i];
      if(!first++) color(i, value[i] & 1);
    }
  }

  while(!que.empty()) {
    int p = que.front();
    que.pop();
    for(int to : tree[p]) {
      if(small[to] < small[p] - 1 || big[to] > big[p] + 1) {
        small[to] = max(small[to], small[p] - 1);
        big[to] = min(big[to], big[p] + 1);
        que.push(to);
      }
    }
  }


  for(int i = 0; i < N; i++) {
    if(small[i] > big[i]) {
      puts("No");
      exit(0);
    } else if(small[i] == big[i]) {
      que.push(i);
    }
  }

  while(!que.empty()) {
    int p = que.front();
    que.pop();
    for(int to : tree[p]) {
      if(small[to] != big[to]) {
        if(small[to] <= small[p] - 1 && small[p] - 1 <= small[to]) {
          que.push(to);
          small[to] = big[to] = small[p] - 1;
        } else if(small[to] <= small[p] + 1 <= small[p] - 1 <= small[to]) {
          que.push(to);
          small[to] = big[to] = small[p] + 1;
        } else {
          puts("No");
          exit(0);
        }
      }
    }
  }

  puts("Yes");
  for(int i = 0; i < N; i++) {
    printf("%d\n", small[i]);
  }


}


Measured memory_bytes: 12416
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cmath>     // pow
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>   // setprecision
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;

// long long gcd(long long a, long long b) { return b != 0 ? gcd(b, a % b) : a;
// }

// int binary_search(int key) {
//     int ng = -1;
//     int ok = (int)a.size();
//     while(abs(ok - ng) > 1) {
//         int mid = (ok + ng) / 2;
//         if(isOK(mid, key))
//             ok = mid;
//         else
//             ng = mid;
//     }
//     return ok;
// }

// cout << fixed << setprecision(10);
// vector<vector<int>> vec(H, vector<int>(W))    // int H*W
// int MOD = 1000000007;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int sum = a + b + c;
    if(sum >= 22){
        cout << "bust" << endl;
    }else{
        cout << "win" << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Main main = new Main();
    main.solve();
    main.show();
  }

  int n;
  Deque<Integer> a = new ArrayDeque<Integer>();
  Deque<Integer> b = new ArrayDeque<Integer>();
  Deque<Integer> c = new ArrayDeque<Integer>();
  int ans;
  int turn = 0;
  boolean win = false;

  public Main() {
    Scanner sc = new Scanner(System.in);
    try {
      read(sc, a);
      read(sc, b);
      read(sc, c);
    } finally {
      sc.close();
    }
  }

  private static void read(Scanner sc, Deque<Integer> a) {
    String s = sc.next();
    int n = s.length();
    for (int i = 0; i < n; i++) {
      if (s.charAt(i) == 'a' ) a.addLast(0);
      if (s.charAt(i) == 'b' ) a.addLast(1);
      if (s.charAt(i) == 'c' ) a.addLast(2);
    }
  }
  
  void solve() {
    while (!win) {
      play();
    }
  }

  void play() {
    if (turn == 0) play_a();
    if (turn == 1) play_b();
    if (turn == 2) play_c();
  }

  void play_a() {
    if (a.size() == 0) {
      win = true;
      ans = 0;
      return;
    }
    turn = a.pollFirst();
  }
  
  void play_b() {
    if (b.size() == 0) {
      win = true;
      ans = 1;
      return;
    }
    turn = b.pollFirst();
  }

  void play_c() {
    if (c.size() == 0) {
      win = true;
      ans = 2;
      return;
    }
    turn = c.pollFirst();
  }

  void show() {
    if (ans == 0) System.out.println("A");
    if (ans == 1) System.out.println("B");
    if (ans == 2) System.out.println("C");
  }
}


Measured memory_bytes: 35544
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 100010
#define LL long long
LL a[MAXN];
int Adj[MAXN],V[MAXN*2],nxt[MAXN*2],c,du[MAXN],n;
void AddEdge(int u,int v)
{
	c++;V[c]=v,nxt[c]=Adj[u];Adj[u]=c;
}
LL s[MAXN];
void dfs(int u,int p)
{
	if(du[u]==1)
	{
		s[u]=a[u];
		return;
	}
	LL sum=0;
	for(int i=Adj[u];i;i=nxt[i])
		if(V[i]!=p)
		{
			dfs(V[i],u);
			sum+=s[V[i]];
		}
	if(sum<a[u]||sum>a[u]*2)
	{
		printf("NO\n");
		exit(0);
	}
	if(sum==a[u])
	{
		s[u]=sum;
		return;
	}
	s[u]=2*a[u]-sum;
	LL left=sum-a[u],ls=0,al=0;
	for(int i=Adj[u];i&&left;i=nxt[i])
		if(V[i]!=p)
		{
			LL k=s[V[i]];
			LL del=min(min(k,ls),left);
			k-=del,left-=del,ls-=del;
			if(k>1&&al&&left)
			{
				LL p=k/2;
				LL ed=min(min(p,al),left);
				left-=ed;
				k-=ed*2;
				al+=ed;
			}
			ls+=k;
			al+=del;
		}
	if(left)
	{
		printf("NO\n");
		exit(0);
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	int u,v;
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&u,&v);
		du[u]++,du[v]++;
		AddEdge(u,v);
		AddEdge(v,u);
	}
	if(n==2)
	{
		if(a[1]==a[2])
			printf("YES\n");
		else printf("NO\n");
		return 0;
	}
	int rt=1;
	for(int i=1;i<=n;i++)
		if(du[i]>1)
		{
			rt=i;
			break;
		}
	dfs(rt,0);
	if(s[rt]) printf("NO\n");
	else printf("YES\n");
}

Measured memory_bytes: 8064
#include <stdio.h>

int gcd(int x, int y) {
	if (x % y == 0) return y;

    return gcd(y, x % y);
}

int main( ) {
	int x, y, ans, buff, max, i;

	scanf("%d %d", &x, &y);

	if (x < y) {
		buff = x;
		x = y;
		y = buff;
	}

	printf("%d\n", gcd(x, y));

	return 0;
}

Measured memory_bytes: 592
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int t_life = sc.nextInt();
        int t_attack = sc.nextInt();
        int a_life = sc.nextInt();
        int a_attack = sc.nextInt();

        int ans1 = a_life % t_attack == 0 ? a_life / t_attack : (a_life / t_attack) + 1;
        int ans2 = t_life % a_attack == 0 ? t_life / a_attack : (t_life / a_attack) + 1;

        if (ans1 <= ans2) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35776
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010;
int dx[5]={0,1,0,-1,0};
int dy[5]={1,0,-1,0,0};
int main(){
    int a,b,c,d,e,f;cin>>a>>b>>c>>d>>e>>f;
    int s=0;
    s+=a;
    s+=b*5;
    s+=c*10;
    s+=d*50;
    s+=e*100;
    s+=f*500;
    if(s>=1000){
        cout<<1<<endl;
    }else{
        cout<<0<<endl;
    }
}


Measured memory_bytes: 3108
import sys
input = sys.stdin.readline

H,N = map(int, input().split())
table = []
dp = [10**9]*(H+1)
dp[0] = 0

for i in range(N):
    a,b = map(int, input().split())
    table.append((a,b))

for i in range(1,H+1):
#    print(dp)
    for j in range(N):
        a,b = table[j]
        if i<a:
            dp[i] = min(dp[i],b)
        else:
            dp[i] = min(dp[i],dp[i-a]+b)
print(dp[-1])

Measured memory_bytes: 41836
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in))) {

			int in = Integer.parseInt(br.readLine());

			int k = in/2;

			 System.out.println(in%2==0?k*k
					 :k*(k+1));
		}
	}
}

Measured memory_bytes: 25360
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int main() {
	int n, s[200] = {}, result = 0,lamp=1,in,ax,h,w;
	string str[106];
	cin >> h>>w;
	for (int i = 1; i <= h; i++) {
		cin >> str[i];
	}
	cout << endl;
	for (int i = 1; i <= h; i++) {
		cout<< str[i] << endl;
      	cout<< str[i] << endl;
	}

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n,k;
  cin>>n>>k;
  int count=0;
  int d,a;
  vector<bool> fg(n,false);
  rep(i,k){
    cin>>d;
    rep(j,d){
      cin>>a;
      fg[a-1]=true;
    }
  }
  rep(i,n){
    if(!fg[i]){
      count++;
    }
  }
  cout<<count<<'\n';
  return(0);
}


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

int main() {                                                                                                                                                                int W, H, x, y, r;                                                                                                                                                        cin >> W >> H >> x >> y >> r;                                                                                                                                           
                                                                                                                                                                            if (0 <= x - r && x + r <= W && 0 <= y - r && y + r <= H) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;                                                                                                                                                               } 

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

signed main() {
  int N;
  cin >> N;

  vector<int> t(N);
  vector<int> x(N);
  vector<int> y(N);
  for( int i = 0; i < N; i++ ){
    cin >> t.at(i) >> x.at(i) >> y.at(i);
  }

  //今いる場所
  int bax = 0;
  int bay = 0;
  int time = 0;
  for( int i = 0;  i < N; i++ ){
    if( abs( x.at(i)-bax ) + abs( y.at(i)-bay ) <= (t.at(i)-time) && (abs( x.at(i)-bax ) + abs( y.at(i)-bay ))%2 == (t.at(i) - time)%2 ){
      bax = x.at(i);
      bay = y.at(i);
      time = t.at(i);
    }else{
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


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

using namespace std;

int main(void)
{

    //freopen("C:\\Users\\Administrator\\Desktop\\debug.in", "r", stdin);

    int cc,dd,ee;
    int tmp = 0;

    cin >> cc >> dd >> ee;

    for(int i = cc; i <= dd; i++)
    {
        if(ee % i == 0)
            tmp++;
    }

    cout << tmp << endl;

   return 0;
}



Measured memory_bytes: 3124
from bisect import bisect_left, bisect_right  # return index

def search(t, i):
    ix = bisect_right(t, i)
    if t[ix-1] != i:
        return False
    return True

n = int(input())
s = list(set(list(map(int, input().split()))))
q = int(input())
t = sorted(list(set(list(map(int, input().split())))))

ans = 0
for i in s:
    ans += search(t, i)

print(ans)


Measured memory_bytes: 16748
#include <bits/stdc++.h>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(0), cin.tie(0)
#define ppb push_back
#define rep(i, a, b) for(int i = a; i < b; i++)
#define mem(i) memset((i), (-1), (sizeof(i)))
#define all(i) (i).begin(), (i).end()
#define endl '\n'
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;

int n, l;
int flavor;

int main()
{
	fastio;
	cin >> n >> l;
	flavor = n * (n + 1) / 2 + l * n - n;
	int x = l, y = l + n - 1;
	if (x > 0) flavor -= x;
	else if (y < 0) flavor -= y;

	cout << flavor << endl;
}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int N, dpc[210][210], dpn[210][210];
vector<int> G[210];

vector<int> merge(vector<int> A, vector<int> B, int cur, int nxt) {
    vector<int> res((int)A.size() + (int)B.size() - 1);
    dpc[0][0] = 1;
    for(size_t i=0; i<A.size(); i++) {
        for(size_t j=0; j<B.size(); j++) {
            for(size_t k=0; k<=j; k++) {
                {
                    (dpc[j+1][k  ] += dpc[j][k]) %= MOD; // 被らせず置く
                    (dpn[j+1][k+1] += dpc[j][k]) %= MOD; // 被らせて進む
                    (dpn[j  ][k  ] += dpc[j][k]) %= MOD; // そのまま進む
                }

                // マージ (i 個の要素 A と j 個の要素 B を k 個被りで)
                (res[i+j-k] += A[i] * B[j] % MOD * dpc[j][k] % MOD) %= MOD;
            }
        }
        fill(dpc[0], dpc[B.size() + 2], 0);
        swap(dpc, dpn);
    }
    fill(dpc[0], dpc[B.size() + 2], 0);
    return res;
}

void dump_vec(vector<int> res) {
    for(size_t i=0; i<res.size(); i++) {
        fprintf(stderr, "%lld%c", res[i], " \n"[i+1 == res.size()]);
    }
}

vector<int> solve(int cur) {
    vector<int> res(1, 1);
    for(auto to : G[cur]) {
        auto vec = solve(to);
        res = merge(res, vec, cur, to);
    }
    res.insert(res.begin(), 0LL);
    // dump_vec(res);
    return res;
}

signed main() {
    cin >> N;
    vector<int> deg(N);
    for(int i=0; i<N-1; i++) {
        int u, v; cin >> u >> v;
        G[u].push_back(v);
        deg[v]++;
    }

    int ans = 1;
    for(int i=0; i<N; i++) {
        if(deg[i] == 0) {
            int sum = 0;
            auto res = solve(i);
            for(auto e : res) (sum += e) %= MOD;
            (ans *= sum) %= MOD;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3868
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl;
// *min_element(c + l, c + r) *max_element(c + l, c + r)
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// struct Edge {
//   int to, id;
//   Edge(int to, int id): to(to), id(id) {}
// };

vector<ll> a;

ll dp[3010][3010][2];

ll rec(int l, int r, int ord) {
  if(dp[l][r][ord] != -1) return dp[l][r][ord];
  if(ord == 0) {
    if(l == r) return dp[l][r][ord] = a[l];
    return dp[l][r][ord] = max(a[l] + rec(l + 1, r, 1), a[r] + rec(l, r - 1, 1));
  } else {
    if(l == r) return dp[l][r][ord] = -a[l];
    return dp[l][r][ord] = min(rec(l + 1, r, 0) - a[l], rec(l, r - 1, 0) - a[r]);
  }
}

int main() {
  int N; cin >> N;
  a = vector<ll>(N);
  rep(i, N) cin >> a[i];
  rep(i, N + 1) {
    rep(j, N + 1) {
      rep(k, 2) dp[i][j][k] = -1;
    } 
  }
  ll ans = rec(0, N - 1, 0);
  cout << ans << endl;
}

Measured memory_bytes: 145000
S = input()

import collections as col
cc = col.Counter(S)

mi = 10000000000000000
ma = -1000
for k,v in cc.items():
  mi = min(mi,v)
  ma = max(ma,v)
if ( len(cc.keys())<3 ):
  mi = 0
 
if (ma-mi<=1):
  print ("YES")
else:
  print ("NO")
  

Measured memory_bytes: 39280
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <numeric>
#include <algorithm>
#include <utility>


using std::cout;
using std::cin;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;


ll gcd(ll a, ll b) {
    while (b != 0) {
        auto tmp = a;
        a = b;
        b = tmp % a;
    }
    return a;
}

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

int isPrime(int a) {
    for (int i = 2; i * i <= a; ++i) {
        if (a % i == 0) {
            return 0;
        }
    }
    return 1;
}

string add(string line) {
    int balance = 0;
    for (auto s : line) {
        if (s == ')') {
            --balance;
        } else {
            ++balance;
        }
        if (balance < 0) {
            return add("(" + line);
        }
    }
    string en;
    for (int i = 0; i < balance; ++i) {
        en += ")";
    }
    return line + en;
}



void oneCase () {
    int n;
    cin  >> n;
    string line;
    cin >> line;
    cout << add(line) << "\n";

}




int main() {
    int t = 1;
//    cin >> t;
    while (t > 0) {
        oneCase();
        --t;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b,c,x;
int num=0;
int main()
{
	scanf("%d%d%d%d",&a,&b,&c,&x);
	for(int i=0;i<=a;i++)
	for(int j=0;j<=b;j++)
	for(int k=0;k<=c;k++){
		if(i*500+j*100+k*50==x){
		num++;
		}
	} 
	printf("%d",num);
	return 0;
}

Measured memory_bytes: 256
/*
	************	************    ************	***      ***	************	***               ***
	************	************    ************	****     ***	************	 ***             ***
	***      ***	***      ***    ***      ***	*****    ***	***      ***	  ***           ***
	***      ***	***      ***    ***      ***	******   ***	***      ***	   ***         ***
	************	************    ************	*** ***  ***	************	    ***       ***
	************	************    ************	***  *** ***	************	     ***     ***
	***				***   ***       ***      ***	***   ******	***      ***	      ***   ***
	***				***    ***      ***      ***	***    *****	***      ***	       *** ***
	***				***     ***     ***      ***	***     ****	***      ***	        *****
	***				***      ***    ***      ***	***      ***	***      ***	         ***
*/

#define named(blockname) goto blockname; \
                         blockname##_skip: if (0) \
                         blockname:

#define break(blockname) goto blockname##_skip
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define readarr(a,n) for (int i=0; i<n; i++) {cin>>a[i];}
#define printarr(a,n) for (int i=0; i<n; i++) {cout<<a[i]<<' ';}
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define vint vector <int>
#define pb push_back
#define pf push_front
#define endl "\n"

signed main() {
	
	fast ;
	
	ll q ;
	// cin >> q ;
	q = 1 ;
	while(q--)
	{
		ll n ;
		cin >> n ;
		ll a[n] ;
		readarr(a,n) ;
		ll dp[n] ;
		dp[0] = 0 ;
		dp[1] = abs(a[1]-a[0]) ;
		for (ll i = 2; i < n; i++)
		{
			dp[i] = min(dp[i-1]+abs(a[i]-a[i-1]), dp[i-2]+abs(a[i]-a[i-2])) ;
		}
		cout << dp[n-1] ;
	}
	
	return 0;
}

Measured memory_bytes: 1024
//#define TIMER_
#include <bits/stdc++.h>
using namespace std;
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define ALL(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using ll = long long;
using ull = unsigned long long;

int A[13][13];

int main() {
  fastio;
  int R, C, X;
  cin >> R >> C >> X;
  vector<int> cost(R);
  for (int r = 0; r < R; r++) {
    cin >> cost[r];
    for (int c = 0; c < C; c++) {
      cin >> A[r][c];
    }
  }

  for (int c = 0; c < C; c++) {
    ull row = 0;
    for (int r = 0; r < R; r++) {
      row += A[r][c];
    }
    if (row < X) {
      cout << -1 << endl;
      return 0;
    }
  }
  
  ull mini = 1e5 * 13;
  for (int m = 1; m < (1 << R); m++) {
    vector<int> rowsum(R,0);
    ull res = 0;
    for (int r = 0; r < R; r++) {
      if (m & (1 << r)) {
        res += cost[r];
        for (int c = 0; c < C; c++) {
          rowsum[c] += A[r][c];
        }
      }
    }
    bool valid = true;
    for (int c = 0; c < C; c++) {
      if (rowsum[c] < X) {
        valid = false;
        break;
      }
    }
    if (valid) {
      mini = min(mini, res);
    }
  }
  cout << mini << '\n';
  
  #ifdef TIMER_
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  #endif
}


Measured memory_bytes: 3656
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	uint[] GU => Strs.Select(uint.Parse).ToArray();
	decimal[] GD => Strs.Select(decimal.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; }
	static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; }
	static ulong One(int k) => 1ul << k;
	static ulong All(int k) => One(k) - 1;
	static bool Has(ulong s, int k) => (s & One(k)) != 0;
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var I = G;
		int a = I[0], b = I[1], c = I[2], d = I[3];
		WriteLine(Abs(a - c) <= d || (Abs(a - b) <= d && Abs(b - c) <= d) ? "Yes" : "No");
	}
}


Measured memory_bytes: 13268
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {

    input!{
       s:chars,
    }

    let mut ans = 0;
    for w in s  {
        if w == '-'{
            ans -= 1;
        }else{
            ans += 1;
        }
    }

    println!("{}", ans);

}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
int main(){
    int n;cin>>n;
    ll m=0,a=0,r=0,c=0,h=0;
    rep(i,n){
        string s;cin>>s;
        if(s[0]=='M')m++;
        if(s[0]=='A')a++;
        if(s[0]=='R')r++;
        if(s[0]=='C')c++;
        if(s[0]=='H')h++;
    }
    cout<<m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+
    a*r*c+a*r*h+a*c*h+r*c*h<<endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(true){
            int target = sc.nextInt();
            int sheet = sc.nextInt();
            if(target==0 && sheet==0) break;

            int n = 0;
            while(sheet>Math.pow(10,n+1)) n++;
            n++;

            int[] list = new int[n];
            int sheet2 = sheet;
            for(int i=n-1; i>=0; i--){
                list[i] = sheet2%10;
                sheet2 /= 10;
            }

            int max = -1;
            String parts = "";
            for(int mask=1; mask<1<<n; mask+=2){
                int sum = 0;
                int num = -1;
                String tmp = "";
                for(int j=0; j<n; j++){
                    if((mask&(1<<j))>0){
                        if(num!=-1){
                            sum += num;
                            tmp += String.valueOf(num) + " ";
                        }
                        num = list[j];
                    }else{
                        num *= 10;
                        num += list[j];
                    }
                }
                sum += num;
                tmp += String.valueOf(num);

                if(sum==max) parts = "";
                if(sum>max && sum<=target){
                    max = sum;
                    parts = tmp;
                }

            }

            if(max==-1) System.out.println("error");
            else if(parts.equals("")) System.out.println("rejected");
            else System.out.println(max+" "+parts);     
        }
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 23316
#include <bits/stdc++.h>
using namespace std;
 
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))
 
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
 
typedef long long LL;
typedef pair<int, int> PII;
 
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = (LL)INF * INF;

const int MAX = 1 << 9;

int a[MAX][MAX];

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	FOR(i, 0, n)
		FOR(j, 0, n)
			cin >> a[i][j];
	LL ans = 0;
	FOR(i, 0, n)
		FOR(j, i + 1, n)
		{
			bool was = false;
			FOR(k, 0, n)
			{
				if(k == i || k == j)
					continue;
				if(a[i][j] > a[i][k] + a[k][j])
				{
					cout << -1;
					return 0;
				}
				else if(a[i][j] == a[i][k] + a[k][j])
					was = true;
			}
			if(!was)
				ans += a[i][j];
		}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
void solve(){
	ll x,y,z;
	cin>>x>>y>>z;
	swap(x,y);
	swap(x,z);
	cout<<x<<" "<<y<<" "<<z;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll qc=1;
	for(ll i=1;i<=qc;i++)
	solve();
}


Measured memory_bytes: 768
n, k = map(int, input().split())
a = list(map(int, input().split()))

ans1 = 0
for i in range(n):
    for j in range(i+1, n):
        if a[i] > a[j]:
            ans1 += 1

ans2 = 0
for i in a:
    for j in a:
        if i > j:
            ans2 += 1

ans = k * ans1 + k * (k-1) // 2 * ans2
ans %= 10 ** 9 + 7

print(ans)


Measured memory_bytes: 3188
n = int(input())
datasets = [0]*n
#datasets[k] == [x1k,y1k,x2k,y2k,x3k,y3k]
for i in range(0,n):
  datasets[i] = list(map(float,input().split()))

for data in datasets:
  x1p2=(data[0]+data[2])
  x1m2=(data[0]-data[2])
  x1p3=(data[0]+data[4])
  x1m3=(data[0]-data[4])
  y1p2=(data[1]+data[3])
  y1m2=(data[1]-data[3])
  y1p3=(data[1]+data[5])
  y1m3=(data[1]-data[5])
  x=(x1p2*x1m2*y1m3+y1p2*y1m2*y1m3-x1p3*x1m3*y1m2-y1p3*y1m3*y1m2)/(2*(x1m2*y1m3-x1m3*y1m2))
  y=(y1p2*y1m2*x1m3+x1p2*x1m2*x1m3-y1p3*y1m3*x1m2-x1p3*x1m3*x1m2)/(2*(y1m2*x1m3-y1m3*x1m2))
  r=((x-data[0])**2+(y-data[1])**2)**(1/2)
  if x == 0.000:
    x=0
  if y == 0.000:
    y=0
  print("{0:.3f} {1:.3f} {2:.3f}".format(x,y,r))

Measured memory_bytes: 7716
#include <bits/stdc++.h>
using namespace std;
struct thing {
    int w, c;
};
int main ()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<thing> t(n+20);
    int m = 10001;
    for (int i = 1; i <= n; ++i)
    {
        cin >> t[i].c;
        t[i].w = 1;
    }
    vector<int> weight(10001, -1);
    weight[0] = 0;
    int mx = 0;
    for(int i=1; i <= n; ++i)
        for(int j=m-t[i].c; j >= 0; --j)
            if(weight[j] != -1){
                weight[j + t[i].c] = max(weight[j + t[i].c], weight[j] + t[i].c);
                if (weight[j + t[i].c] % 10 != 0){
                    mx = max(mx,weight[j+t[i].c]);
                }
            }
    cout << mx;
}


Measured memory_bytes: 256
#include <stdio.h>
int bubbleSort(int *,int);

int main(){
  int A[100],N;
  int i,count;

  scanf("%d",&N);
  for(i=0; i<N; i++){
    scanf("%d",&A[i]);
  }
  count = bubbleSort(A,N);
  for(i=0; i<N-1; i++){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[i]);
  printf("%d\n",count);
return 0;
}

int bubbleSort(int *A,int N){
  int j,temp,flag=1,count=0;
  while(flag){
    flag = 0;
    for(j=N-1; j>=1; j--){
      if(A[j]<A[j-1]){
	temp = A[j];
	A[j] = A[j-1];
	A[j-1] = temp;
	flag = 1;
	count++;
      }
    }
  }
  return count;
}

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

int main()
{
    int x,y,z,i,j,k;
    int a,b;
    cin>>x>>y;
    if(2*x<=y && 4*x>=y && (y-2*x)%2==0 && (4*x-y)%2==0)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pub push_back
#define pob pop_back
#define loops(i, s, n) for (int i = s; i < n; i++)
#define loop(i, n) for (int i = 0; i < n; i++)
#define loopr(i, s, e) for (int i = s; i >= e; i--)
#define eps 1e-9
#define loopitr(mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define pii pair<int, int>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int, int>>
#define even_set 0xAAAAAAAA ... 1010101010
#define odd_set 0x55555555 ... 01010101
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define vall(v) v.begin(), v.end()
#define mkp make_pair
#define ret return
#define cont continue
#define nl endl
#define ff first
#define ss second
#define cnt_bits __builtin_popcount
#define test  \
    int T;    \
    cin >> T; \
    while (T)
#define arrinit        \
    int n;             \
    cin >> n;          \
    int arr[n];        \
    loop(i, n)         \
    {                  \
        cin >> arr[i]; \
    }
#define init(arr, n, val)       \
    for (int i = 0; i < n; i++) \
        arr[i] = val;
const int mod = 1000000007;

bool arr[21][21];
int dp[(1<<21)];
int n;

int find(int mask){
    int i = cnt_bits(mask);
    if(i == n){
        ret 1;
    }

    if(dp[mask] != -1)
       ret dp[mask];
    int r = 0;
    loop(j, n){
        if(((mask>>j) & 1)  || arr[i][j] == 0 )  cont;

        (r += find(mask|(1<<j)))%=mod;
    }

    ret dp[mask] = r;
}

int main()
{
    fastio;
    
    cin>>n;
    loop(i, n)
      loop(j, n)
         cin>>arr[i][j];

    loop(i, (1<<n)){
        dp[i] = -1;
    }

    cout<<find(0)<<endl;
}

Measured memory_bytes: 11828
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int D,N;
  cin >> D >> N;
  int a = 1, res = 1;
  for(int i = 0; i < D; ++i) a *= 100;
  if(N == 100) res  = a*N + a;
  else res = a*N;
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int n,i,ans=0,now=0;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++){
        if(now<a[i]){
            ans+=a[i]-now;
            now=a[i];
        }
        else now = a[i];
    }
    printf("%d",ans);
}

Measured memory_bytes: 128