akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<string>

using namespace std;


	int a[100900];
	int dp[100900];

int main(){

	

	int n , k; cin >> n >> k;
	
	for(int i = 0 ; i < n; i++) cin >> a[i];
	sort(a,a+n);
	
	
	for(int i = 0; i < a[0]; i++) dp[i] = -1;
	for(int i = a[0]; i <= k; i++){
		
		for(int j = 0; j < n; j++){
			if(i - a[j] < 0) continue;
			if(dp[i - a[j]] == -1) dp[i] = 1;
		}
		
		if(dp[i] == 0) dp[i] = -1;
		
	}
	
	if(dp[k] == 1) cout << "First";
	else cout << "Second";
	




	return 0;
}


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

#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);++i)

#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")

#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")

int main(void){
  int N,K,ans=0;
  cin >> N >> K;
  vector <int> p(N);
  rep(i,N){cin >> p.at(i);}
  sort(p.begin(),p.end());
  rep(i,K){ans+=p.at(i);}
  cout << ans <<endl;
  return 0;
  
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <numeric>
#include <iomanip>
using namespace std;
    
#define int long long
#define pb push_back
#define ub upper_bound
#define lb upper_bound
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
    
using ll = long long;
const ll INF = LLONG_MAX - 100;
ll mod = 1e9 + 7;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;
    
class fact {
public:
    int fmod = 1e9+7;
    vector<int> fac, inv;
    fact (int n, int Mod = 1e9+7) {
        fmod = Mod;
        fac = vector<int>(n,0);
        inv = vector<int>(n,0);
        fac[0] = 1; for (int i = 1; i < n; i++) fac[i] = fac[i-1] * i % fmod;
        for (int i = 0;i < n;i++) inv[i] = fact::POW(fac[i],fmod-2);
    }
    ll nCr(ll n, ll r) {return (fac[n] * inv[r] % fmod) * inv[n-r] % fmod;}
    ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%fmod;}a = a * a%fmod; b >>= 1;}return c;}
};
    
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;}
void EMP(int x) {cout<<"!!!"<<x<<"!!!"<<endl;}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return a * b / GCD(a, b);}
ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%mod;}a = a * a%mod; b >>= 1;}return c;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}
bool isSqrt(ll a) {return pow(sqrt(a),2) == a ? 1 : 0;}
void YesNo(bool a) {if (a) cout << "Yes"; else cout << "No"; cout << endl;}
void yesno(bool a) {if (a) cout << "yes"; else cout << "no"; cout << endl;}
void YESNO(bool a) {if (a) cout << "YES"; else cout << "NO"; cout << endl;}
int poorpow(int b, int a) {
    int tmp = 1;
    REP (i,a) {
        tmp *= b;
    }
    return tmp;
}


bool solve() {
    int H,W,h,w; cin >> H >> W >> h >> w;
    cout << (H-h) * (W-w) << endl;
}

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


Measured memory_bytes: 256
N, A, B = map(int, input().split())
ans = 0
for i in range(1, N+1):
    sum = 0
    sum += i % 10
    if i >= 10:
        sum += (i // 10) % 10
    if i >= 100:
        sum += (i // 100) % 10
    if i >= 1000:
        sum += (i // 1000) % 10
    if i >= 10000:
        sum += (i // 10000) % 10
    if sum >= A and sum <= B:
        ans += i
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstring>
#include <set>
using namespace std;

const int SIZE = 102;
const int OFFSET = 50;
const int dir[ 4 ][ 2 ] = { { 0, -1 }, { 1, 0 }, { 0, 1 }, { -1, 0 } };

int main()
{
	int n, m;

	while( cin >> n >> m && ( n || m ) ){
		int map[ SIZE ][ SIZE ];
		memset( map, 0, sizeof(map) );
		int sx, sy;
		for( int i = 1; i < m + 1; ++i ){
			for( int j = 1; j < n + 1; ++j ){
				char c;
				cin >> c;
				if( c == '&' ){
					sx = j;
					sy = i;
					c = OFFSET + 1;
				}
				map[ i ][ j ] = c;
			}
		}
		set< pair< int, int > > q;
		q.insert( make_pair( sx, sy ) );

		int count = OFFSET;
		bool end = false;
		while( !end ){
			set< pair< int, int > > nextq;
			++count;
			while( !q.empty() ){
				pair< int, int > p = *(q.begin());
				q.erase( q.begin() );
				char a = count % 2 ? '.' : '#';
				char b = count % 2 ? '#' : '.';

				for( int i = 0; i < 4; ++i ){
					int x = p.first + dir[ i ][ 0 ];
					int y = p.second + dir[ i ][ 1 ];
					char c = map[ y ][ x ];
					if( c == 0 ){
						end = true;
						break;
					}
					if( c == a ){
						map[ y ][ x ] = count;
						q.insert( make_pair( x, y ) );
					}
					if( c == b ){
						map[ y ][ x ] = count + 1;
						nextq.insert( make_pair( x, y ) );
					}
				}
				if( end ) break;
			}
			if( end ) break;
			q = nextq;
		}
		cout << ( count - OFFSET ) / 2 << endl;
	}

	return 0;
}

Measured memory_bytes: 1472
#include<bits/stdc++.h>
using namespace std;
#define maxn 5020
#define rep(i,l,r) for(register int i = l ; i <= r ; i++)
#define repd(i,r,l) for(register int i = r ; i >= l ; i--)
#define rvc(i,S) for(register int i = 0 ; i < (int)S.size() ; i++)
#define rvcd(i,S) for(register int i = ((int)S.size()) - 1 ; i >= 0 ; i--)
#define fore(i,x)for (register int i = head[x] ; i ; i = e[i].next)
#define pb push_back
#define prev prev_
#define stack stack_
#define mp make_pair
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define lowbit(x) (x&(-x))
typedef long long ll;
typedef pair<int,int> pr;

const ll mod = 1e9 + 7;
struct node{
	int next,to;
}e[maxn * 2];
int head[maxn],cnt,sz[maxn];
ll g[maxn],f[maxn][maxn],sum[maxn];
int n;

inline void adde(int x,int y){
	e[++cnt].to = y;
	e[cnt].next = head[x];
	head[x] = cnt;
}
void dfs(int x,int fa){
	f[x][1] = 1 , sz[x] = 1;
	fore(i,x){
		if ( e[i].to == fa ) continue;
		dfs(e[i].to,x);
		sz[x] += sz[e[i].to];
		repd(j,sz[x],1){
			f[x][j] = f[x][j] * (-sum[e[i].to] + mod) % mod;
			rep(k,max(1,j - sz[x] + sz[e[i].to]),min(sz[e[i].to],j - 1)){ //两部分都只能恰好for到sz，否则会被链卡成n^3
				f[x][j] = (f[x][j] + f[x][j - k] * f[e[i].to][k]) % mod;
			}
		}
	}
	rep(i,1,sz[x]) sum[x] = (sum[x] + f[x][i] * g[i]) % mod;
}
int main(){
	scanf("%d",&n);
	rep(i,1,n - 1){
		int x,y;
		scanf("%d %d",&x,&y);
		adde(x,y) , adde(y,x);
	}
	g[0] = 1;
	rep(i,1,n) if ( i % 2 == 0 ) g[i] = g[i - 2] * (i - 1) % mod;
	dfs(1,0);
	cout<<sum[1]<<endl;
}



Measured memory_bytes: 196352
// while( !(succeed == try()) );

#include "bits/stdc++.h"
using namespace std;

// Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha


#define int long long int
#define loop(i,s,e) for(int i=s; i<e; i++)
#define endl '\n'
#define vii vector<int>
#define pii pair<int, int>
#define ff first
#define ss second
#define N 100001
#define pb push_back
#define INF LLONG_MAX
#define inf INT_MAX
#define M (int)(1e9+7)

void INP();

#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define rtn                                       if(0)return;
template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { rtn cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{     rtn 
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

// Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha


void alpha()
{	
	int n, k;
	cin>>n>>k;

	int ans = 0;

	loop(i,k,n+2)
	{
		int t= i;
		t--;

		int min_sum = t*(t+1)/2;
		int max_sum = n*(n+1)/2 - (n-i)*(n-i+1)/2;

		// bug(min_sum, max_sum);

		ans += max_sum - min_sum + 1;
		ans %= M;
	}

	cout<<ans<<endl;
}

int32_t main(){

	ios_base:: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	// INP();
    int t=1;
	//cin>>t;

  	while(t--) alpha();

	return 0;

}






















inline void INP()
{
      #ifndef ONLINE_JUDGE
          freopen("input.txt",  "r",  stdin);
          freopen("output.txt", "w", stdout);
      #endif
}
 
 

Measured memory_bytes: 3652
import java.util.*;

public class Main {
	public Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	public Main() {
		new aoj1130().doIt();
	}
	class aoj1130{
		boolean map[][];
		int x[] = {-1,1,0,0};
		int y[] = {0,0,-1,1};
		int H,W;
		int cnt = 0;
		
		void dfs(int h,int w){
			if(map[h][w]){
				cnt++;
				map[h][w] = false;
			}
			for(int i = 0;i < 4;i++){
				if(h + y[i] < H && w + x[i] < W && h + y[i] >= 0 && w + x[i] >= 0){
					if(map[h + y[i]][w + x[i]] == true){
						dfs(h+y[i],w+x[i]);
					}
				}
			}
		}
		
		void doIt() {
			while (true) {
				W = sc.nextInt();
				H = sc.nextInt();
				if(H + W == 0)break;
				map = new boolean[H][W];
				int sh = 0,sw = 0;
				for(int h = 0;h < H;h++){
					String str = sc.next();
					char ctr[] = str.toCharArray();
					for(int w = 0;w < W;w++){
						if(ctr[w] == '.') map[h][w] = true;
						else if(ctr[w] == '@'){
							map[h][w] = true;
							sh = h;
							sw = w;
						}
					}
				}
				dfs(sh,sw);
				System.out.println(cnt);
				cnt = 0;
			}
		}
	}
}

Measured memory_bytes: 27212
//
// Created by yamunaku on 2019/12/29.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main(){
    // CFS;
    int n, q;
    cin >> n >> q;
    vi a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));
    rep(t, q){
        int l, r;
        cin >> l >> r;
        cout << upper_bound(all(a), r) - a.begin() - (lower_bound(all(a), l) - a.begin()) << endl;
    }
    return 0;
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

int32_t main(){
	set<int> s;
	int a;
	cin >> a;
	s.insert(a);
	cin >> a;
	s.insert(a);
	cin >> a;
	s.insert(a);
	if(s.size() == 2)
		cout << "Yes";
	else
		cout << "No";

	return 0;
}



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

int n;

int main(){
	bool bisa = 1;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		if(x%2==1) continue;
		if(x%3==0 || x%5==0) continue;
		printf("DENIED\n");
		return 0;
	}
	printf("APPROVED");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int N, M;
int Q;
int l, r;
int p, q;
int sum[505][505];

int main()
{
    scanf("%d %d %d", &N, &M, &Q);
    
    for (int i = 0; i < M; i++) {
        scanf("%d %d", &l, &r);

        sum[l][r]++;
    }

    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
        }
    }

    for (int i = 0; i < Q; i++) {
        scanf("%d %d", &p, &q);

        printf("%d\n", sum[q][q] - sum[q][p - 1] - sum[p - 1][q] + sum[p - 1][p - 1]);
    }

    return 0;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        sc.close();

        // 主処理
        for (int i = 0; i < k; i++) {
            if (b <= a) {
                b *= 2;
            } else if (c <= b) {
                c *= 2;
            } else {
                break;
            }
        }
        boolean judge = a < b && b < c;
        String result = judge ? "Yes" : "No";

        // 出力
        System.out.println(result);
    }
}


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

int main() {
	long long A, B, ans;
	string str="",num;
	cin >> A >> str;

	num.push_back(str.at(0));
	num.push_back(str.at(2));
	num.push_back(str.at(3));

	B = stod(num);
	ans = A*B /100;

	cout << ans << endl;
}


Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;

int main(){
    double a,b,c;
    scanf("%lf%lf%lf",&a,&b,&c);
    c=c*pi/180;
    double s=a*b*sin(c)/2,l=a+b+sqrt(a*a+b*b-2*a*b*cos(c)),h=b*sin(c);
    printf("%lf %lf %lf\n",s,l,h);
}


Measured memory_bytes: 3444
#include "bits/stdc++.h"
using namespace std;
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
int main() {
	int n;
	int m;
	cin >> n;
	cin >> m;
	int s[100020] = {};
	int c[100020] = {};
	c[1] = 1;
	for (int i = 1; i <= n; i++) {
		s[i] = 1;
	}
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		s[a]--;
		s[b]++;
		if (c[a] == 1) {
			c[b] = 1;
		}
		if (s[a] == 0) {
			c[a] = 0;
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (c[i] == 1) {
			ans++;
		}
	}
	cout << ans;
}

Measured memory_bytes: 1024
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define eps 1e-10
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

int c1[maxn],c2[maxn],a[maxn];
vector <int> v1,v2;

inline bool cmp1(int a,int b){return c1[a]>c1[b];}
inline bool cmp2(int a,int b){return c2[a]>c2[b];}

int main()
{
	int n=read();
	for(int i=1;i<=n;i++) a[i]=read();
	for(int i=1;i<=n;i+=2)
	{
		if(c1[a[i]]==0) v1.push_back(a[i]);
		c1[a[i]]++;
	}
	for(int i=2;i<=n;i+=2)
	{
		if(c2[a[i]]==0) v2.push_back(a[i]);
		c2[a[i]]++;
	}
	sort(v1.begin(),v1.end(),cmp1); sort(v2.begin(),v2.end(),cmp2);
	if(v1[0]!=v2[0]) cout<<n-c1[v1[0]]-c2[v2[0]]<<endl;
	else cout<<n-max(c1[v1[0]]+c2[v2[1]],c1[v1[1]]+c2[v2[0]])<<endl;
	return 0;
}

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

#define len(x)  (int((x).size()))
#define append push_back
#define pp make_pair
#define ff(a, b)    for (int a = 0; a < int(b); ++a)
#define kk(n)    ff(k, n)
#define xx(n)    ff(x, n)
#define yy(n)    ff(y, n)
#define ii(n)    ff(i, n)
#define fff(a, b, c) for (int a = int(b); a < int(c); ++a)
#define kkk(a, b) fff(k, a, b)
#define xxx(a, b) fff(x, a, b)
#define yyy(a, b) fff(y, a, b)
#define iii(a, b) fff(i, a, b)
#define bb begin()
#define ee end()
#define uu first
#define vv second
#define all(x)  (x).bb, (x).ee
#define ite(v)   decltype((v).bb)
#define fe(i, v) for(ite(v) i = (v).bb; i != (v).ee; ++i)
#define err(...)    { fprintf(stderr, __VA_ARGS__); fflush(stderr); }
#define zz(array, byte)   memset(array, byte, sizeof(array));

using LL = long long;
using DD = long double;
using pii = pair<int, int>;


const LL  INFLL  = 0x7f7f7f7f7f7f7f7fLL;
const int INFint = 0x7f7f7f7f;  //Works with memset(..).
   



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

int main() {
    //ios_base::sync_with_stdio(false);     cin.tie(NULL);
    //cout << '\n';     //Avoid flushing with endl.
    cout.precision(16);


    int H, W, K;
    cin >> H >> W >> K;

    vector<vector<int> > building(W, vector<int>(H, -1));
    vector<pii> q;
    ii (H) {
        string line;
        cin >> line;
        xx (W) {
            if ('S' == line[x]) {
                q.append(pp(x, i));
                building[x][i] = 0;
            } else if ('.' == line[x]) {
                building[x][i] = -10;
            }
        }
    }

    int rr = INFint;
    ff (qstart, len(q)) {
        pii here = q[qstart];
        if (0 == here.uu || 0 == here.vv
        || here.uu == W-1 || here.vv == H-1) {
            cout << "1\n";
            return 0;
        }
        int dist = building[here.uu][here.vv];
        if (dist > K)
            break;
        rr = min(rr, here.uu);
        rr = min(rr, here.vv);
        rr = min(rr, W-1-here.uu);
        rr = min(rr, H-1-here.vv);
        ii (4) {
            pii nei(here.uu + dx[i],
                    here.vv + dy[i]);
            if (-10 != building[nei.uu][nei.vv])
                continue;
            building[nei.uu][nei.vv] = dist+1;
            q.append(nei);
        }
    }

    cout << 1 + (rr + K-1) / K << "\n";
    

    return 0;
}



Measured memory_bytes: 3460
n = int(input())
a = list(map(int,input().split()))
m = 1000
ka = 0
for i in range(n-1):
    if a[i+1] > a[i]:
        #print(m,"m",a[i],ka)
        ka += m // a[i]
        #print(ka,"ka")
        m = m % a[i]
    else:
        if ka > 0:
            m += ka * a[i]
            ka = 0
    if i == n-2:
        if ka > 0:
            #print("t",ka,m)
            m += ka * a[i+1]
    #print(m,ka,i)
print(m)

Measured memory_bytes: 61716
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
const int maxn=(int)1e6+5;
int n,m;
vector<int> E[maxn];
int vis[maxn];
int flag=1;
int curvis[maxn];
void dfs(int x){
    if(flag==0)return;
    if(vis[x]||curvis[x])return;
    curvis[x]=1;
    vis[x]=1;
    for(auto t:E[x]){
        if(curvis[t]){flag=0;return;}
        dfs(t);
    }
    curvis[x]=0;
}
int main(){
   // ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n>>m;           
    rep(i,1,m){
        int x,y;
        scanf("%d%d",&x,&y);
        E[x].push_back(y);
    }
    
    rep(i,0,n-1){
        if(flag==0)break;
        if(!vis[i])dfs(i);
    }
    cout<<!(flag)<<endl;
}
/*
10 0

3 3
0 1
0 2
1 2

3 3
0 1
1 2
2 0
 */


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

using namespace std;

int main() {
	int n;

	cin >> n;

	if (n < 1200)
		cout << "ABC";
	else if (n < 2800)
		cout << "ARC";
	else
		cout << "AGC";

	return 0;
}

Measured memory_bytes: 256
'''input
3 5
1 2 1
2 3 0
'''
# connected components
from sys import stdin, setrecursionlimit
from bisect import bisect_left
import sys, threading
from collections import defaultdict
sys.setrecursionlimit(10 ** 5 + 1)

def dfs(node, distance, graph, visited, cur):
    visited[node] = True
    distance[node] = cur
    for i in graph[node]:
        if i not in visited:
            dfs(i, distance, graph, visited, cur + 1)


# main start
n, T, A = list(map(int, stdin.readline().split()))
graph = defaultdict(list)
for _ in range(n - 1):
    u, v = list(map(int, stdin.readline().split()))
    graph[u].append(v)
    graph[v].append(u)

T_traverse = [0] * (n + 1)
A_traverse = [0] * (n + 1)
visited = dict()
dfs(T, T_traverse, graph, visited, 0)
visited = dict()
dfs(A, A_traverse, graph, visited, 0)
# print(T_traverse)
# print(A_traverse)
ans = 0
for i in range(1, n + 1):
    if T_traverse[i] <= A_traverse[i]:
        diff = A_traverse[i] - T_traverse[i]
        if diff % 2 == 0:
            for adj in graph[i]:
                if A_traverse[adj] > A_traverse[i] - 1:
                    ans = max(ans, A_traverse[i])
                    break
            else:
                ans = max(ans, A_traverse[i] - 2)
        else:
            ans = max(ans, A_traverse[i] - 1)
print(ans)


Measured memory_bytes: 118544
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  set<ll> s;
  ll t, n; std::cin >> n;
  re(i, n){
    std::cin >> t;
    if(s.find(t)!=s.end()) s.erase(t);
    else s.insert(t);
  }
  std::cout << s.size() << '\n';
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) cout<<(ans?"Yes":"No")<<endl
#define YN(ans) cout<<(ans?"YES":"NO")<<endl
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int main(){
    map<char,int> orimap;
    set<char> oriset;
    int n;
    in(n);
    string s;
    rep(i,n){
        cin>>s;
        map<char,int> map1;
        if(i==0){
            rep(j,s.length()){
                if(oriset.count(s[j])){
                    orimap[s[j]]++;
                }else{
                    oriset.insert(s[j]);
                    orimap[s[j]]=1;
                }
            }
        }else{
            rep(j,s.length()){
                if(map1.count(s[j])){
                    map1[s[j]]++;
                }else{
                    map1[s[j]]=1;
                }
            }
            for(auto value:oriset){
                if(map1.count(value)){
                    orimap[value]=min(orimap[value],map1[value]);
                }else{
                    orimap[value]=0;
                }
            }
        }
    }
    for(auto value:oriset){
        rep(i,orimap[value]){
            printf("%c",value);
        }
    }
    printf("\n");
}

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

int main(){
    ll n,ans;
    int k[] = {1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51};
    cin >> n;
    cout << k[n-1];
    return 0;
}


Measured memory_bytes: 256
#include <iostream> 
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair
#define MAX 1000001
ll prime[MAX];
#define FAST           ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007

ll rec(vector<vector<ll> >& dp,vector<ll>& arr,int n,int i,int k,int w)
{
  ll ans=0;
  if(i>=n)
    return 0;

  if(dp[i][k]!=-1)
    return dp[i][k];


  if(k!=0)
  ans=max(rec(dp,arr,n,i+1,w,w),arr[i]+rec(dp,arr,n,i+1,k-1,w));
  else
  ans=max(rec(dp,arr,n,i+1,k,w),rec(dp,arr,n,i+1,w,w));

  return dp[i][k]=ans;

}

//ll t[400008];
// void build(vector<ll>& a, int v, int tl, int tr) {
//     if (tl == tr) {
//         t[v] = a[tl];
//     } else {
//         int tm = (tl + tr) / 2;
//         build(a, v*2, tl, tm);
//         build(a, v*2+1, tm+1, tr);
//         t[v] = max(t[v*2] ,t[v*2+1]);
//     }
// }

// ll maxi(int v, int tl, int tr, int l, int r) {
//     if (l > r) 
//         return 0;
//     if (l == tl && r == tr) {
//         return t[v];
//     }
//     int tm = (tl + tr) / 2;
//     return max(maxi(v*2, tl, tm, l, min(r, tm)) ,maxi(v*2+1, tm+1, tr, max(l, tm+1), r));
// }



// void update(int v, int tl, int tr, int pos, ll new_val) {
//     if (tl == tr) {
//         t[v] = new_val;
//     } else {
//         int tm = (tl + tr) / 2;
//         if (pos <= tm)
//             update(v*2, tl, tm, pos, new_val);
//         else
//             update(v*2+1, tm+1, tr, pos, new_val);
//         t[v] = max(t[v*2] ,t[v*2+1]);
//     }
// }


int main() { 

  int n,x,t,ans;
  cin>>n>>x>>t;
  if(n%x==0)
    ans=(n/x)*t;
  else
    ans=(n/x+1)*t;

  cout<<ans;


return 0;
}


Measured memory_bytes: 3644
// Problem : A - Air Conditioner
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define mk make_pair
#define fast                    \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define rep(i, a, b) for (ll i = a; i < b; i++)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define sz(x) (int)x.size()
#define mem(a, val) memset(a, val, sizeof(a))
#define deci(x) cout << fixed << setprecision(x);
#define bitcount(x) __builtin_popcountll(x)

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

const long long int mod = 1e9 + 7;
const long double EPS = 1e-12;
const int N = 1e5 + 20;

void solve() {
  ll tem;
  cin >> tem;
  if (tem >= 30) {
    cout << "Yes";
  } else
    cout << "No";
}
int main() {
  fast;
  ll t;
  t = 1;

  // cin>>t;

  while (t--) {
    solve();
  }

  return 0;
}


Measured memory_bytes: 3648
def gcd(a, b)
  a, b = b, a if b > a

  while (c = a % b) != 0
    a, b = b, c
  end
  b
end

def lcm(a, b)
  a * b / gcd(a, b)
end

while line = gets
  a, b = line.split.map(&:to_i)
  gcd = gcd(a, b)
  lcm = lcm(a, b)
  puts "#{gcd} #{lcm}"
end

Measured memory_bytes: 8660
#include <cstdio>
#include <stdio.h>
#include <string>
using namespace std;

int main() {
    int N, A;
    scanf("%d %d", &N, &A);

    N = N % 500;
    if(N <= A) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }

    return 0;
}

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

int sw=0;

void bubbleSort(int A[],int N){
  bool flag=1;
  int i=0;
 
  while(flag){
    flag=0;
    for(int j=N-1;j>i;j--){
      if(A[j]<A[j-1]){
	swap(A[j],A[j-1]);
	flag=1;
	sw++;
      }
    }
    i++;
  }
}


int main(){
  int N,A[100];
  
  cin>>N;
  for(int i=0;i<N;i++)cin>>A[i];
  bubbleSort(A,N);
  for(int i=0;i<N;i++){
    if(i!=0) cout<<" ";
    cout<<A[i];
  }
  cout<<endl;
  cout<<sw<<endl;
  return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef vector<int> vi;
const int inf = 1e9+7;
const int INF = 1e18+7;
int mod = 1e9+7;

int a[100], dp[100][3000][100], n, m;
signed main(){
	scanf("%lld%lld", &n, &m);
	rrep(i,n)scanf("%lld", &a[i]);
	
	rep(i,n)dp[i][0][0] = 1;
	rrep(i,n){
		rep(j,3000){
			rrep(k,n){
				dp[i][j][k] += dp[i-1][j][k];
				if(j >= a[i])dp[i][j][k] += dp[i-1][j-a[i]][k-1];
			}
		}
	}
	
	int ans = 0;
	rrep(i,3000){
		if(i*m >= 3000)break;
		ans += dp[n][i*m][i];
	}
	printf("%lld\n", ans);
	return 0;
}




Measured memory_bytes: 119168
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

typedef unsigned long long ULLONG;
typedef long long LLONG;

template <class _T> static _T tp_abs(const _T& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void getint(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}
static void getstring(char* buff) {
	if (scanf(" %s", buff) < 0) {
		printf("getstr error!\n");
	}
}
static const long long MOD_NUM = 1000000007LL;
template <class _T> static _T tp_pow(_T base, int exp)
{
	_T ans = 1;

	for (int i = 0; i < exp; i++) {
		ans *= base;
	}
	return ans;
}

static void D_task();

int main()
{
	D_task();
	fflush(stdout);
	return 0;
}

template <class _T> void tp_getPrimes(_T targ, std::map<_T, _T>& primes)
{
	_T target = targ;
	_T i = 2;
	while ((i * i) <= target) {
		if ((target % i) == 0) {
			target /= i;
			primes[i]++;
		}
		else {
			i++;
		}
	}
	if (target > 1) {
		primes[target]++;
	}
}

static void D_task()
{
	LLONG N;
	getint(N);

	LLONG val = N;
	int ans = 0;
	std::map<LLONG, LLONG> used;
	while (val > 1) {
		std::map<LLONG, LLONG> primes;
		tp_getPrimes<LLONG>(val, primes);

		LLONG z = 0;
		for (auto pr = primes.begin(); pr != primes.end(); pr++) {
			LLONG mul = 1;
			while (mul <= pr->second) {
				LLONG div = tp_pow<LLONG>(pr->first, mul);

				if (used.find(div) == used.end()) {
					used[div]++;
					ans++;
					z = div;
					break;
				}
				mul++;
			}
			if (z > 0) {
				break;
			}
		}
		if (z == 0) break;
		val /= z;
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 3796
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
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)*}
    };
}

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)*}
    };
}

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")
    };
}

fn main() {
    input!(
        s : String,
    );
//    let str : String = "".to_string();
    let mut chs = s.chars();
    let mut rev = s.chars().rev();

    let len = (s.len()/2) as u32;
    let mut ans = 0;
    for _ in 0..len{
        if chs.next() != rev.next(){
            ans += 1;
        }
    }
    println!("{}",ans);
}

Measured memory_bytes: 4352
#pragma G++ optimize(3)
#include<iostream>
#include<cstdio>
#define re register
using namespace std;
int t[100000+10];
inline int read()
{
	re int n=0,ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9')
		{
			n=(n<<3)+(n<<1)+ch-'0';
			ch=getchar();
		}
	return n;
}
void write(int n)
{
	if(n>=10)write(n/10);
	putchar(n%10+'0');
}
int main()
{
	re int s=0,N,M;
	N=read();
	for(re int i=1;i<=N;++i)
		{
			t[i]=read();
			s+=t[i];
		}
	M=read();
	re int p,x;
	for(re int i=1;i<=M;++i)
		{
			p=read();
			x=read();
			write(s+x-t[p]);
			putchar('\n');
		}
	return 0;
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

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


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

	int n;
	cin>>n;
	vector<int> s(n);
	REP(i,n) cin>>s[i];
	vector<int> v;
	sort(ALL(s));
	REP(i,min(n,10)) {
		REP(j,min(n,10)) {
			if(i==j) continue;
			string t=to_string(s[i])+to_string(s[j]);
			v.pb(stoi(t));
		}
	}
	sort(ALL(v));
	cout<<v[2]<<endl;

	return 0;
}





Measured memory_bytes: 3316
#include <bits/stdc++.h>
#include <sstream>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

const double pi = 3.14159265359;
const ll INF = 1e12;
const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5;
/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl

String to integer:
stringstream dark(s);
int x = 0; dark >> x;
*/

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}


int n; string s, t;

void solve()
{
    cin >> n >> s >> t;
    for (int i=0; i<n; i++) cout << s[i] << t[i];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    for (int i=1; i<=t; i++)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ll long long
#define lson l,mid,p<<1
#define rson mid+1,r,p<<1|1
#define pii pair<int,int>
using namespace std;
const int inf=1e9+10;
const int mod=1e9+7;
const int maxn=1e5+10;
int a,b,c;
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	cin>>a>>b>>c;
	if((a==b&&a==c)||(a!=b&&a!=c&&b!=c)){
		puts("No");
	}else puts("Yes");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0; i<n ; ++i)
#define lpx(i,x,n) for(int i=x; i<n ; ++i)
#define all(v) v.begin() , v.end()
#define sz(v) (int(v.size()))
typedef unsigned long long ul;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;
typedef pair<char, int> pci;
typedef vector<pii> vp;
typedef vector<pci> vpc;
typedef pair<int,pii> piii;

int OO = 2e9;
const double eps = 1e-9 ;
const int N = 500000;
int mx = -1e9 , mn = 1e9 ;
int arr[N],arr2[N] ;

int dcmp(double x, double y)
{
    return fabs(x - y) <= eps ? 0 : x > y ? -1 : 1;
}



int main()
{
    int a, b= 0; cin>> a;
    lp(i,a){
        cin >> arr[i];
        arr2[i] = arr[i];
    }
    sort(arr,arr+a);
    lp(i,a){
        if(arr[i] != arr2[i])++b;
    }
    cout << (b > 2 ? "NO": "YES" ) << endl;



    return 0;
}
























Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

char upper(char c){
	return c-0x20;
}

char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

int main() {
    ll a,b,c,k;cin>>a>>b>>c>>k;
    cout << (k%2? b-a: a-b) << endl;
}



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

using namespace std;

typedef pair< int, int > P;

int main() {
	int n;

	while( true ) {
		cin >> n;
		if( !n ) {
			break;
		}
		vector< P > book(n);

		for(int i = 0; i < n; i++) {
			cin >> book[i].first >> book[i].second;
		}

		sort(book.begin(), book.end(), greater< P >());

		int ans = 0;
		if(book.size() == 1) {
			ans = book[0].first * 2 + book[0].second;
		} else {
			int total = 0;
			for(int i = 1; i < book.size(); i++) {
				total += book[i].first;
			}

			if(book[0].first > total) {
				int a = book[0].first - total;

				vector< int > b(a + 1, 0);
				vector< int > write(n - 1);
				b[0] = 1;

				for(int i = 1; i < book.size(); i++) {
					write[i - 1] = book[i].second;
				}

				for(int i = 0; i < write.size(); i++){
					for(int j = b.size() - 1; j >= 0; j--) {
						if(b[j]) {
							if(j + write[i] < b.size()) {
								b[j + write[i]] = 1;
							}
						}
					}
				}

				int s = a;


				for(int i = b.size() - 1; i >= 0; i--) {
					if(b[i]) {
						s -= i;
						break;
					}
				}


				
				for(int i = 0; i < book.size(); i++) {
					ans += book[i].first + book[i].second;
				}
				ans += s;

			} else {
				for(int i = 0; i < book.size(); i++) {
					ans += book[i].first + book[i].second;
				}
			}
		}

		cout << ans << endl;
	}
}

Measured memory_bytes: 1212
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <bitset>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <string>

const int MAX_N = 12;
int N, M;
int k[MAX_N];
int s[MAX_N][MAX_N];
int p[MAX_N];

bool is_all(std::bitset<MAX_N> bs) {
    for (int i = 1; i <= M; i++) {
        int num = 0;
        for (int j = 1; j <= k[i]; j++) {
            if (bs.test(s[i][j] - 1)) {
                num++;
            }
        }
        if (num % 2 != p[i]) {
            return false;
        }
    }
    return true;
}

int main(int argc, char **argv) {
    std::cin >> N >> M;

    for (int i = 1; i <= M; i++) {
        std::cin >> k[i];
        for (int j = 1; j <= k[i]; j++) {
            std::cin >> s[i][j];
        }
    }

    for (int i = 1; i <= M; i++) {
        std::cin >> p[i];
    }

    long long ret = 0;
    for (int i = 0; i < (1 << N); i++) {
        std::bitset<MAX_N> bs(i);
        if (is_all(bs)) {
            ret++;
        }
    }

    std::cout << ret << std::endl;

    return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N, M;
    cin >> N >> M;
    // vector<P> S(N);
    vector<ll> ac(N, 0), wa(N, 0);
    rep(i, M){
        ll p; string S;
        cin >> p >> S;
        p--;
        if (S == "AC"){
            ac.at(p) += 1;
        } else {
            if (ac.at(p) == 0){
                wa.at(p) += 1;
            }
        }
    }
    ll n_correct = 0;
    ll n_fail = 0;
    rep(i, N){
        if (ac.at(i) > 0){
            n_correct += 1;
            n_fail += wa.at(i);
        }
    }
    cout << n_correct << " " << n_fail << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 1792
# include <algorithm>
# include <cassert>
# include <cctype>
# include <cstdio>
# include <cstdlib>
# include <cstring>
# include <cmath>
# include <iostream>
# include <map>
# include <queue>
# include <set>
# include <sstream>
# include <stack>
# include <string>
# include <vector>
# include <iomanip>
 
# define rep(i, n) for (int i = 0; i < (int)(n); i++)
# define irep(i, n) for (int i = int(n) - 1; i >= 0; i--)
# define FOR(i, m, n) for (int i = int(m); i < (int)(n); i++)
 
using namespace std;
 
template <typename T>
void show_all(T t) {
  rep (i, t.size()) {
    rep (j, t[0].size()) {
      cout << t[i][j];
    }
    cout << endl;
  }
}
 
int main() {
 
  int N;
  long long T;
  cin >> N >> T;
 
  vector<long long> t(N);
  vector<long long> a(N);
 
  rep (i, N) cin >> t[i];
 
  long long l = 0;
  long long ans = 0;
  // cout << next_start << endl;
 
  rep (i, N-1) {
    if (l + T > t[i+1]) {
      ans += t[i+1] - l;
    } else {
      ans += T;
    }

    l = t[i+1];
  } 
 
  ans += T;
 
  cout << ans << endl;
}


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

#define rep(i,n) for(signed i=0;i<n;++i)
#define int long long
#define str string
#define debg(a) cout<<#a<<":"<<a<<endl;
#define vint vector<signed>
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define yn(a) cout<<((a)?"Yes":"No")<<endl;
#define YN(a) cout<<((a)?"YES":"NO")<<endl;

signed main(){
  int h,w;
  cin>>h>>w;
  str s[h];
  rep(i,h)cin>>s[i];
  int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
  rep(i,h){
    rep(j,w){
      bool tf=false;
      //debg(s[i][j]);
      rep(pos,4){
        if(s[i][j]=='.'){tf=true;break;}
        if(i+dy[pos]==-1||i+dy[pos]==h)continue;
        if(j+dx[pos]==-1||j+dx[pos]==w)continue;
        //debg(s[i+dy[pos]][j+dx[pos]]);
        if(s[i][j]=='#'){
          if(s[i+dy[pos]][j+dx[pos]]=='#'){
            tf=true;
          }
        }
      }
      cout<<endl;
      if(!tf){cout<<"No"<<endl;return 0;}
    }
  }
  
  cout<<"Yes"<<endl;
  return 0;
}


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

int main()
{
 int n;
  vector<double> v;
  cin >> n;
  for (int i = 0;i < n;i++)
  {
    double tmp;
    cin >> tmp;
    v.push_back(tmp);
  }
  
  double ans = 0;
  for (int i = 0;i < n;i++)
  ans += 1/v[i];
  
  cout << 1/ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
using namespace std;
// using namespace _gnu_pbds;
#define vb __int128
#define ll long long
#define ld long double
#define full(a) a.begin(),a.end()
#define fr(i,a,b) for(ll i = a ; i < b ; i++)
#define stoink stack<ll>
#define quu queue<ll>
#define quee queue<pair<ll,ll>>
#define vec vector <ll>
#define vecd vector<ld>
#define vg vector<vector<ll> >
#define eg vector<pair<ll,ll>>
#define vgw vector<vector<pair<ll,ll> > >
#define pa pair<ll,ll>
#define pb push_back
#define ff first
#define ss second
#define pre 0.00000000000000000001
#define inf 100000000
#define mod 998244353
#define endl '\n'
    // gp_hash_table<ll, int,chash> dist;
// using namespace __gnu_pbds;
// ll power(ll x,ll exp)
// {ll res=1;while(exp>0){if(exp%2==1)res=((res%mod)*(x%mod)%mod);
// 	x=((x%mod)*(x%mod)%mod);exp=exp>>1;}return res;}
struct chash {
    const int RANDOM = (long long)(make_unique<char>().get()) ^ chrono::high_resolution_clock::now().time_since_epoch().count();
    static unsigned long long hash_f(unsigned long long x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    static unsigned hash_combine(unsigned a, unsigned b) { return a * 31 + b; }
    int operator()(int x) const { return hash_f(x)^RANDOM; }
};
struct block{
    ll w,s,val;
    void read(){ 
        cin >> w >> s >> val;
    }
    bool operator < (const block& b) const {
        return w + s < b.w + b.s;
    }
};
int main()
{	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
    cin >> n;
    vector<block> arr(n);
    ll maxi = 2e5 + 5;
    fr(i,0,n) {
        arr[i].read();
    }
    sort(full(arr));
    vec dp(maxi + 1,0);
    for(auto i : arr) {
        for(int j = i.s ; j >= 0 ; j--) {
            dp[j + i.w] = max(dp[j + i.w],dp[j] + i.val);
        }
    }
    ll answer = 0;
    fr(i,0,maxi) {
        answer = max(answer,dp[i]);
    }
    cout << answer;
    return 0;
}	

Measured memory_bytes: 4808
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N, cnt = 0; cin >> N;
  while (N >= 10) {
    if (N%10 < 9)
      N -= 10;
    N /= 10;
    cnt += 9;
  }
  cnt += N;
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256