akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define f(i,n) for(int i=0; i<n; ++i)
#define fi(i,st,n) for(int i=st; i<=n; ++i)
#define veci vector<int>
#define vecp vector<pair<int,int> >
#define vecl vector<ll>
int prime[100000+10];

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

ll power(ll a, ll n, ll mod) {
	if(n < 0 or a < 0 or mod <= 0) return 0;
	if(mod == 1) return 0;
	ll res = 1;
	while(n > 0) {
		if(n&1) {
			res = (res*a)%mod;
		}
		a = (a*a)%mod;
		n = n/2;
	}
	return res;
}

ll sum(int arr[], int n) {
	ll res = 0;
	f(i,n) {
		res += arr[i];
	}
	return res;
}

void seive() {
	prime[1] = 0;
	for(int i=2; i<=100000; i++) {
		prime[i] = 1;
	}
	for(ll i=2; i<=100000; i++) {
		if(prime[i]) {
			for(ll j=i*i; j<=100000; j+=i) {
				prime[j] = 0;
			}
		}
	}
}

ll cal(ll n) {
	ll c = 0;
	if(n == 0) return 0;
	ll temp = n;
	while(n > 0) {
		if(n%2) c++;
		n /= 2;
	}
//	cout<<c<<" ";
	return 1 + cal(temp%c);
}

int main(){
//	ios_base::sync_with_stdio(false);
//	cin.tie(NULL);
//	cout.tie(NULL);
	int t = 1;
//	cin>>t;
	while(t--){
		int n;
		cin>>n;
		string s;
		cin>>s;
		ll c = 0;
		f(i,n) {
			if(s[i] == '1') c++;
		}
		reverse(s.begin(), s.end());
//		cout<<"-1 ";
		int ans1 = 0, ans2 = 0;
		for(ll i=0; i<n; i++) {
			if(s[i] == '1') {
				ans1 += power(2,i,c+1);
				ans2 += power(2,i,c-1);
				ans1 %= (c+1);
				if(c != 1)
				ans2 %= (c-1);
			}
		}
//		cout<<"-2 ";
		for(int i=n-1; i>=0; i--) {
			if(s[i] == '0') {
				ll temp = (ans1+power(2,i,c+1))%(c+1);
				cout<<1+cal(temp)<<"\n";
			} 
			else {
				if(c != 1) {
					ll temp = (ans2 - power(2,i,c-1) + (c-1))%(c-1);
					cout<<1+cal(temp)<<"\n";
				}
				else {
					cout<<"0\n";
				}
			}
		}
 	}
 	return 0;
}


Measured memory_bytes: 3752
#include "bits/stdc++.h"
using namespace std;

int a[100010];
int A, B;
int n;

long long ceiling(long long a, long long b) {
	if(a % b == 0) return a / b;
	else return (a / b) + 1; 
}

bool good(long long x) {
	long long cnt = 0;
	for(int i = 1; i <= n; i++) {
		long long h = a[i] - x * B;
		if(h <= 0) continue;
		cnt += ceiling(h, A - B);
	}
	return cnt <= x;
}

long long search(long long b, long long e) {
	if(b == e) {
		return b;
	}
	long long m = (b + e) >> 1;
	if(good(m)) return search(b, m);
	else return search(m + 1, e);
}

int main(int argc, char const *argv[])
{
	scanf("%d %d %d", &n, &A, &B);

	long long sum = 0;
	for(int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		sum += a[i];
	}
	printf("%lld\n", search(0, ceiling(sum, B)) );
	return 0;
}

Measured memory_bytes: 640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Kenji
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC108A solver = new ABC108A();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC108A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int K = in.nextInt();
            int ans = 0;
            for (int i = 1; i <= K - 1; i++) {
                for (int j = i + 1; j <= K; j++) {
                    if ((i + j) % 2 == 1) {
                        ans++;
                    }
                }
            }
            out.println(ans);
        }

    }
}



Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
using P=pair<int,int>;
typedef unsigned long long ull;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const ll INF=1e18;
const ll MOD=1e9+7;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  int n,t;
  cin >> n >> t;
  vector<ll>a(n);
  rep(i,n) cin >> a[i];
  ll m=2e9;
  map<ll,ll>mp;
  rep(i,n){
    m=min(m,a[i]);
    mp[a[i]-m]++;
  }
  ll ans=0;
  ll val=0;
  for(auto p:mp){
    if(val<p.first)ans=p.second;
  }
  cout << ans << endl;
}


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

using namespace std;
typedef long long ll;

int main() {
    int ans;
    string S;
	cin >> S;
    if (S=="SUN") ans = 7;
    else if (S=="MON") ans = 6;
    else if (S=="TUE") ans = 5;
    else if (S=="WED") ans = 4;
    else if (S=="THU") ans = 3;
    else if (S=="FRI") ans = 2;
    else if (S=="SAT") ans = 1;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<cstdlib>
#include<queue>
#include<utility> //pair
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

typedef long long ll;
typedef vector<vector<int>> Graph;

int main() {
	//入力;
	int N, M;
	cin >> N >> M;
	Graph G(N);
	REP(i, M) {
		int a, b;
		cin >> a >> b;
		G[a - 1].push_back(b - 1);
		G[b - 1].push_back(a - 1);
	}

	//順列用のベクトル;
	vector<int> P;
	REP(i, N-1) P.push_back(i+1);

	//答え;
	ll ans = 0;

	//全順列探索;
	do {
		int startv, nextv;
		startv = 0;
		bool check1;
		bool check2 =true;

		REP(i, N - 1) {
			nextv = P[i];
			
			check1 = false;
			for (auto& x : G[startv]) { //始点からいける頂点の中にnextvが存在するか
				if (x == nextv) check1 = true;
			}

			if (!check1) { //ダメな場合はそこで探索終了;
				check2 = false;
				break;
			}

			startv = P[i];
		}

		if (check2) ++ans;
	} while (next_permutation(P.begin(), P.end()));

	cout << ans << endl;


	//小数点以下の桁数表示;
	//cout << fixed << setprecision(15);

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int t = Integer.parseInt(sc.next());

        System.out.println((t / a) * b);
    }
}


Measured memory_bytes: 21844
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vvvvll = vector<vector<vector<vector<ll>>>>;
using pl4 = pair<ll,ll>;
using str = string;
using vpl4 = vector<pair<ll,ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x) ll (x);cin >>(x);
#define stin(x) str (x);cin >>(x);
#define vllin(x,n) vll (x)(n);FOR(i,0,n-1){cin >>(x)[i];}
#define vllin2(a,b,n) vll (a)(n);vll (b)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];}
#define vllin3(a,b,c,n) vll (a)(n);vll (b)(n);vll (c)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];}
#define vlling(x,n) (x).assign(n,0);FOR(i,0,n-1){cin >>(x)[i];}
#define vlling2(a,b,n) (a).assign(n,0);(b).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];}
#define vlling3(a,b,c,n) (a).assign(n,0);(b).assign(n,0);(c).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];}
#define vpl4in(x,n) vpl4 (x)((n),mp(0,0));FOR(i,0,n-1){cin >>x[i].fi>>x[i].se;}
#define FOR(i,a,b) for(ll i = a ; i <= b ; i++)
#define rFOR(i,b,a) for(ll i = a; i >= b ; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout<<(x);
#define sal(x) cout<<(x)<<endl;
#define says(x) cout<<(x)<<(' ');
#define sas cout<<(' ');
#define sayR(x) cout<<fixed<<setprecision(10)<<(x);
#define salR(x) cout<<fixed<<setprecision(10)<<(x)<<endl;
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Imp(a) cout <<((a)?"Possible":"Impossible")<<endl;
#define IMP(a) cout <<((a)?"POSSIBLE":"IMPOSSIBLE")<<endl;
#define pow(a,b) ll(pow(a,b))

ll MOD=998244353;

signed main(){
        llin(n);
        llin(k);
        sal(n-k+1)
}

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

int main(){
  string A;
  cin >> A;
  
  int len = A.length();
  int mismuch = 0;
  
  for(int i = 0; i < len/2 ; i++){
    if(A[i] != A[len - i -1])
      ++mismuch;
  }
  cout << mismuch << endl;
  
}

Measured memory_bytes: 256
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.Vector.Unboxed as U
import Control.Monad

primesTo :: Int -> [Int]
primesTo n = [p | p <- [2..n], primes U.! p]
  where primes = U.create $ do
          isPrime <- UM.replicate (n + 1) True
          UM.unsafeWrite isPrime 0 False
          UM.unsafeWrite isPrime 1 False
          forM_ [2..n] $ \i -> do
            isP <- UM.unsafeRead isPrime i
            when isP $ forM_ [2 * i, 3 * i .. n] $ \j -> do
              UM.unsafeWrite isPrime j False
          return isPrime

mod5is1 :: [Int]
mod5is1 = [p | p <- primesTo 55555, p `mod` 5 == 1]

main :: IO ()
main = readLn >>= putStrLn . unwords . map show . flip take mod5is1


Measured memory_bytes: 1020
#include <stdio.h>
int main(void) {
	int line,i,p,m,a,b;
	scanf("%d",&line);
	for(i=0,m=10000000000,p=0;i<line;i++){
		scanf("%d %d",&a,&b);
		if(m>b)m=b,p=a;
		}
	if(m!=0)for(i=m;i>0;i--)p++;
	printf("%d",p);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> vi; 
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
const int mod = 1e9+7;
const int maxn = 2e5+10;
const int inf = 0x3f3f3f3f;
bool vis[11],f=false;
int a[100],len;
int ans[maxn];
vi used;
void dfs(int now,bool ok) {
    if(f) return ;
    if(now==len) {
        f=true;
        return ;
    }
    if(ok) {
        ans[now]=used[0];
        dfs(now+1,ok);
    }
    else {
        for(int x:used) {
            if(x==a[now]) {
                ans[now]=x;
                dfs(now+1,false);
            }
            if(x>a[now]) {
                ans[now]=x;
                dfs(now+1,true);
                break;
            }
        }
    }
}
int main()
{
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int n,k;
    cin>>n>>k;
    while(n) {
       a[len++]=n%10;
       n/=10;
    }
    reverse(a,a+len);
    rep(i,1,k) {
        int x;
        cin>>x;
        vis[x]=true;
    }
    rep(i,0,9) {
        if(!vis[i]) used.pb(i);
    }
    dfs(0,false);
    if(f) {
        rep(i,0,len-1) cout<<ans[i];
        cout<<'\n';
    }
    else {
        if(used[0]==0) cout<<used[1];
        else cout<<used[0];
        rep(i,0,len-1) cout<<used[0];
        cout<<'\n';
    }
    return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define N 100000 + 5
char s[N];
int len;
int main(){
    scanf("%s", s + 1);
    len = strlen(s + 1);
    if(s[1] == s[len]){
        if(len & 1) puts("Second");
        else puts("First");
    }
    else{
        if(len & 1) puts("First");
        else puts("Second");
    }
    return 0;
}

Measured memory_bytes: 3864
package main

import (
	"fmt"
)

func getNextContest(s string) string {
	if s == "ABC" {
		return "ARC"
	} else if s == "ARC" {
		return "ABC"
	}
	return ""
}

func main() {
	var s string
	fmt.Scan(&s)

	fmt.Println(getNextContest(s))
}


Measured memory_bytes: 1752
import sys
readline = sys.stdin.readline
import fractions

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def main():
    A, B, C, D = map(int, readline().rstrip().split())
    CD = lcm_base(C, D)
    ans = B - (B//C + B//D - B//CD)
    ans -= ((A-1) - ((A-1)//C + (A-1)//D - (A-1)//CD))
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 5052
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,s,f) for(int i=s;i<f;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}
map<int, int> factaring(int x) {
	map<int, int>ans;
	int now = 2;
	while (now * now <= x) {
		if (x % now == 0) {
			x /= now;
			ans[now]++;
		}
		else now++;
	}
	if (x != 1) ans[x]++;
	return ans;
}
int comb(int n, int k) {
	k = min(k, n - k);
	int x = 1, y = 1;
	rep(i, k) {
		y *= i + 1;
		y %= MOD;
	}
	for (int i = n - k + 1; i <= n; i++) {
		x *= i;
		x %= MOD;
	}
	return x * modinv(y, MOD) % MOD;
}

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

	int h, w;
	cin >> h >> w;
	char c[105][105];
	rep(i, h) {
		rep(j, w) {
			cin >> c[i][j];
		}
	}
	int d[105][105];
	bool v[105][105];
	rep(i, h) {
		rep(j, w) {
			d[i][j] = INF;
			v[i][j] = false;
		}
	}
	if (c[0][0] == '#') d[0][0] = 1;
	else d[0][0] = 0;
	queue<P>que;
	que.push({ 0,0 });
	while (!que.empty()) {
		P now = que.front(); que.pop();
		if (v[now.first][now.second]) continue;
		v[now.first][now.second] = true;
		rep(i, 2) {
			int ny, nx;
			if (i == 0) {
				ny = now.first + 1;
				nx = now.second;
			}
			else {
				ny = now.first;
				nx = now.second + 1;
			}
			if (ny < h && nx < w) {
				if (c[now.first][now.second] == '.' && c[ny][nx] == '#') {
					d[ny][nx] = min(d[ny][nx], d[now.first][now.second] + 1);
					que.push({ ny,nx });
				}
				else {
					d[ny][nx] = min(d[ny][nx], d[now.first][now.second]);
					que.push({ ny,nx });
				}
			}
		}
	}
	
	cout << d[h - 1][w - 1] << endl;
	
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    map<int, bool> hash;
    int ans = 0;
    REP(i, n){
        int a;
        cin >> a;
        if(hash.count(a) > 0){
            hash.erase(a);
            ans--;
        }else{
            hash.insert(make_pair(a, true));
            ans++;
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 4992
# -*- coding: utf-8 -*-

from collections import deque
import sys

COMMAND = ("insert", "delete", "deleteFirst", "deleteLast")

if __name__ == "__main__":
    n = int(sys.stdin.readline())
    ans = deque()
    inp = sys.stdin.readlines()
    for i in range(n):
        com = inp[i].split()
        if com[0] == COMMAND[0]:
            ans.appendleft(com[1])
        elif com[0] == COMMAND[1]:
            if com[1] in ans:
                ans.remove(com[1])
        elif com[0] == COMMAND[2]:
            ans.popleft()
        elif com[0] == COMMAND[3]:
            ans.pop()
    print(" ".join(ans))

Measured memory_bytes: 214316
def get(i1, j1, i2, j2):
  if i1 > i2 or j1 > j2 or i1 < 0 or j1 < 0 or i2 < 0 or j2 < 0:
    return 0
  elif i1 > 0 and j1 > 0:
    return l[i2][j2] - l[i1-1][j2] - l[i2][j1-1] + l[i1-1][j1-1]
  elif i1 <= 0 < j1:
    return l[i2][j2] - l[i2][j1-1]
  elif j1 <= 0 < i1:
    return l[i2][j2] - l[i1 - 1][j2]
  else:
    return l[i2][j2]

N, K = map(int, input().split())
K2 = 2*K
R = []
l=[[0] * K2 for _ in range(K2)]

for i in range(N):
  xi, yi, ci = input().split()
  if ci == "W":
    yi = int(yi) + K
  xi, yi = int(xi), int(yi)
  l[xi%K2][yi%K2]+=1

for y in range(K2):
  for x in range(1,K2):
    l[x][y] += l[x-1][y]
for y in range(1,K2):
  for x in range(K2):
    l[x][y] += l[x][y-1]

ans = 0
for i in range(K):
  for j in range(K):
    tmp = 0
    tmp += get(0, 0, i-1, j-1)
    tmp += get(0, j+K, i-1, K2-1)
    tmp += get(i+K, j+K, K2-1, K2-1)
    tmp += get(i+K, 0, K2-1, j-1)
    tmp += get(i, j, i+K-1, j+K-1)

    ans = max(ans, tmp, N-tmp)
print(ans)


Measured memory_bytes: 81628
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <iostream>
#include <map>
#include <functional>
#include <cstdlib>
#include <numeric>
#include <queue>
#include <complex>
#include <sstream>
#include <stack>

using namespace std;

#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> Point;

typedef map<int, pair<int, long long> > mipill;

int main()
{
	int n;
	while(scanf("%d", &n), n){
		vi colums(n, 0);
		rep(i, n){
			int row = 0;
			rep(j, n){
				int a;
				scanf("%d", &a);
				printf("%5d", a);
				row += a;
				colums[j] += a;
			}
			printf("%5d\n", row);
		}

		int sum = 0;
		rep(i, n){
			printf("%5d", colums[i]);
			sum += colums[i];
		}
		printf("%5d\n", sum);
	}

	return 0;
}

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

int main(int argc, char const *argv[]) {
    ll n;
	cin >> n;
	vector<int> a(n+1, 0), d(n);
	ll sum = 0;
	rep(i,n){
		cin >> a[i];
		sum += a[i];
	}
	rep(i,n-1){
		d[i] = a[i+1] - a[i];
	}
	d[n-1] = a[0] - a[n-1];
	ll cnt = n*(n+1)/2;
	if(sum%cnt != 0){
		cout << "NO" << endl;
		return 0;
	}
	ll k = sum / cnt;
	rep(i,n){
		if(d[i] > k || (k-d[i])%n != 0){
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
    return 0;
}


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

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            bool cf = false;
            bool f = true;
            if (str[0] == 'A' && char.IsLower(str[1]) && char.IsLower(str.Last()))
            {
                foreach (char c in str.Substring(2,str.Length - 3))
                {
                    if (c == 'C')
                    {
                        if (!cf)
                            cf = true;
                        else
                        {
                            f = false;
                            break;
                        }
                    }
                    else if (char.IsUpper(c))
                    {
                        f = false;
                        break;
                    }
                }
            }

            if (cf && f)
            {
                Console.WriteLine("AC");
            }
            else
            {
                Console.WriteLine("WA");
            }
#if DEBUG
            Console.ReadKey();
#endif
        }
    }
}


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


int n, k;
int a[100100];
int dp[100100];

int main() {
  cin >> n >> k;
  rep(i,n) cin >> a[i];
  memset(dp,0,sizeof(dp));
  for(int i = 1; i <= k; i++) {
    rep(j,n) {
      if(i<a[j]) continue;
      if(dp[i-a[j]]==0) dp[i] = 1;
    }
  }

  if(dp[k]==1) cout << "First";
  else cout << "Second";
  cout << endl;
  return 0;
}

Measured memory_bytes: 4016
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a<=c && c<=b) cout << "Yes" << endl;
    else cout << "No" << endl; 
}

Measured memory_bytes: 768
#C
#各ペアについてみていき、一つでもｌ以上⇔Possible

n,l = [int(i) for i in input().split()]
a   = [int(i) for i in input().split()]

maxsum=0
maxind = 0
for i in range(n-1):
    s = a[i]+a[i+1]
    if s > maxsum:
        maxsum = s
        maxind = i+1

if maxsum<l:
    print("Impossible")
else:
    print("Possible")
    for i in range(1,maxind):
        print(i)
    for i in range(n-1,maxind,-1):
        print(i)
    print(maxind)

Measured memory_bytes: 14060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
  class Program
  {
    static void Main(string[] args)
    {
      string input1 = Console.ReadLine();
      string[] input2 = Console.ReadLine().Split(" ".ToCharArray());
      
      int[] valueList = new int[input2.Length];
      for(int i = 0; i < input2.Length; i++)
      {
        valueList[i] = int.Parse(input2[i]);
      }
      
      int result = 0;
      while((valueList = DivHalf(valueList)) != null)
      {
        result++;
      }
      
      Console.WriteLine(result);
    }
    
    static int[] DivHalf(int[] valueList)
    {
      int[] result = new int[valueList.Length];
      
      for(int i = 0; i < valueList.Length; i++)
      {
         if(0 < valueList[i] && valueList[i] % 2 == 0)
         {
            result[i] = valueList[i] / 2;
         }
         else
         {
            result = null;
            break;
         }
      }
      
      return result;
    }
  }
}



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

template<typename T, typename U>
using pv=vector<pair<T,U>>;
template<typename T>
using pque=priority_queue<T>;
template<typename T>
using lpque=priority_queue<T,vector<T>,greater<T>>;

using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using ilpair=pair<int,ll>;
using lipair=pair<ll,int>;
using intvec=vector<int>;
using llvec=vector<ll>;
using intq=queue<int>;
using llq=queue<ll>;
using intmat=vector<intvec>;
using llmat=vector<llvec>;

#define PI 3.141592653589793
#define INTINF ((1<<30)-1)
#define LLINF ((1LL<<62)-1)
#define MPRIME 1000000007
#define MPRIME9 998244353
#define MMPRIME ((1ll<<61)-1)

#define len length()
#define pushb push_back
#define fi first
#define se second

#define setpr fixed<<setprecision(15)
#define all(name) name.begin(),name.end()
#define rall(name) name.rbegin(),name.rend()
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

template<class T>
inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template<class T>
inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

template<class T>
inline void init(T& v) {
	for(auto &a: v) cin>>a;
}
template<class T, class U>
inline void init(vector<pair<T,U>>& v) {
	for(auto &a: v) cin>>a.first>>a.second;
}
template<class T, class N>
inline void init(T& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a;
}
template<class T, class U, class N>
inline void init(vector<pair<T,U>>& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a.first>>a.second;
}

inline void out() {
	cout<<endl;
}
template<class T, class... U>
inline void out(T a, U... alist) {
	cout<<a<<" ";
	out(forward<U>(alist)...);
}

template<class N>
void resiz(N n) {
	//empty
}
template<class N, class T, class... U>
void resiz(N n, T&& hd, U&&... tl) {
	hd.resize(n);
	resiz(n,forward<U>(tl)...);
}

bool isout(int h, int w, int H, int W) {
	return ( h<0 || h>=H || w<0 || w>=W );
}

ll binpow(ll a, ll ex, ll p) {
	ll result=1;
	while(ex>0) {
		if(ex&1) result=result*a%p;
		ex>>=1;
		a=a*a%p;
	}
	return result;
}


string S,T;
int ans=INTINF;

void input() {
	cin>>S>>T;
}

void solve() {
	for(int i=0; i<=S.len-T.len; i++) {
		int tmp=0;
		for(int j=0; j<T.len; j++) {
			if(S[i+j]!=T[j]) tmp++;
		}
		chmin(ans,tmp);
	}
	cout<<ans<<endl;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(15);
	int t=1;
	while(t) {
		input();
		solve();
		t--;
	}
}


Measured memory_bytes: 3656
def find(A):
    N=len(A)
    dic={}
    for i in range(len(A)):
        if A[i] in dic:
            dic[A[i]]+=1
        else:
            dic[A[i]]=1
            
    if len(dic)>3:
        return False
    
    if len(dic)==1:
        if 0 in dic:
            return True
        else:
            return False
    
    if len(dic)==2:
        if N%3!=0:
            return False
        temp=[]
        for x in dic:
            temp+=[dic[x]]
        n=N//3
        temp=sorted(temp)
        if (temp[0],temp[1])!=(n,2*n):
            return False
        
        if 0 not in dic:
            return False
        
        n1=dic[0]
        if n1==n:
            return True
        return False
    
    if len(dic)>3:
        return False
    
    if len(dic)==3 and N%3!=0:
        return False
    
    temp=[dic[x] for x in dic]
    if temp[0]!=temp[1] or temp[1]!=temp[2] or temp[2]!=temp[0]:
        return False
    
    a,b,c=[x for x in dic]
    if a^b==c or b^a==c or c^b==a:
        return True
    return False
    
input()
A=list(map(int,input().strip().split(' ')))
if find(A):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 57008
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long int ll;
int main(){
  ll a,b,c,k;
  cin>> a>> b>> c>>k;
  if(k%2==0){
    cout << a-b<<endl;
  }
  else{
    cout << b-a<<endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#pragma GCC optimize ("O3")

inline static int gl(void){
    int x = 0;
    for(;;){
        unsigned int c = getchar_unlocked() - 48;
        if(c < 10){
            x = x*10 + c;
        }else{
            break;
        }
    }
    return x;
}

inline static void pl(unsigned int s){
    char str[9];
    int pos=9;
    if(s==0){
        putchar_unlocked('0');
        return;
    }
    do{
        pos--;
        str[pos]=s%10+48;
        s/=10;
    }while(s!=0);
    for(; pos<9; pos++){
        putchar_unlocked(str[pos]);
    }
}

//char a[501];
//unsigned short out[1000000];

int main(void){
    char* a = (char*)calloc(501,1);
    unsigned short* out = (unsigned short*)calloc(100000000,2);
    const int h=gl(), w=gl();
    int pos=0;
    char haveCoin = 0;
    short old_y, old_x;
    for(int i=1; i<=h; i++){
        for(int j=1; j<=w; j++){
            int t = getchar_unlocked() - 48;
            getchar_unlocked();
            a[j] = t;
        }
        if(i%2==1){
            for(int j=1; j<=w; j++){
                if(haveCoin){
                    out[4*pos+0]=old_y;
                    out[4*pos+1]=old_x;
                    out[4*pos+2]=i;
                    out[4*pos+3]=j;
                    pos++;
                }
                haveCoin ^= a[j]&1;
                old_y = i;
                old_x = j;
            }
        }else{
            for(int j=w; j>0; j--){
                if(haveCoin){
                    out[4*pos+0]=old_y;
                    out[4*pos+1]=old_x;
                    out[4*pos+2]=i;
                    out[4*pos+3]=j;
                    pos++;
                }
                haveCoin ^= a[j]&1;
                old_y = i;
                old_x = j;
            }
        }
    }
    pl(pos); putchar_unlocked('\n');
    for(int i=0; i<pos; i++){
        pl(out[4*i+0]); putchar_unlocked(' ');
        pl(out[4*i+1]); putchar_unlocked(' ');
        pl(out[4*i+2]); putchar_unlocked(' ');
        pl(out[4*i+3]); putchar_unlocked('\n');
    }
    return 0;
}


Measured memory_bytes: 4864
#include <iostream>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
using namespace std;

int main()
{
  int W,a,b;
  cin>>W>>a>>b;
  cout<< max(max(b-a-W,0),max(a-b-W,0))  <<endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    K, T = map(int, input().split())
    a = list(map(int, input().split()))
    print(max(0,2*max(a) - K - 1))  

if __name__ == "__main__":
    main()


Measured memory_bytes: 3316
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		//		new Main().solveA();
		new Main().solveB();
		// new Main().solveC();
		// new Main().solveD();
	}

	private void solveA() {
		Scanner scanner = null;
		int lineAB = 0;
		int lineBC = 0;
		int lineCA = 0;

		try {
			scanner = new Scanner(System.in);
			lineAB = scanner.nextInt();
			lineBC = scanner.nextInt();
			lineCA = scanner.nextInt();

			if (lineCA <= (lineAB + lineBC)) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveB() {
		Scanner scanner = null;
		int n = 0;
		int m = 0;

		try {
			scanner = new Scanner(System.in);
			n = scanner.nextInt();

			Map<String, Integer> nArray = new HashMap<String, Integer>();
			for (int i = 0; i < n; i++) {
				String key = scanner.next();
				if (!nArray.containsKey(key)) {
					nArray.put(key, 1);
				} else {
					int count = nArray.get(key);
					nArray.put(key, ++count);
				}
			}

			m = scanner.nextInt();

			for (int i = 0; i < m; i++) {
				String key = scanner.next();
				if (nArray.containsKey(key)) {
					int count = nArray.get(key);
					nArray.put(key, --count);
				}
			}

			int maxCount = 0;
			for (Iterator<Integer> iterator = nArray.values().iterator(); iterator.hasNext();) {
				maxCount = Math.max(maxCount, iterator.next());
			}

			System.out.println(maxCount);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveB2() {
		Scanner scanner = null;
		int n = 0;
		int m = 0;

		try {
			scanner = new Scanner(System.in);
			n = scanner.nextInt();

			String[] nArray = new String[n];
			for (int i = 0; i < nArray.length; i++) {
				nArray[i] = scanner.next();
			}

			m = scanner.nextInt();

			String[] mArray = new String[m];
			for (int i = 0; i < mArray.length; i++) {
				mArray[i] = scanner.next();
			}

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveC() {
		Scanner scanner = null;
		int lineAB = 0;
		int lineBC = 0;
		int lineCA = 0;

		try {
			scanner = new Scanner(System.in);
			lineAB = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveD() {
		Scanner scanner = null;
		int lineAB = 0;
		int lineBC = 0;
		int lineCA = 0;

		try {
			scanner = new Scanner(System.in);
			lineAB = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

Measured memory_bytes: 23252
#include <iostream>
#include <vector>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
typedef long long int ll;
using namespace std;
vvi G = vv(100001, 0, 0, int);
vector<int> p(100001, -1);
int dfs(int now){
  if(p[now]!=-1) return p[now];
  int ret = 0;
  for(int i=0;i<G[now].size();i++) ret = max(ret, dfs(G[now][i])+1);
  return p[now] = ret;
}
int main(int argc, char const *argv[]) {
  int N, M, a, b, ans = 0;
  scanf("%d %d", &N, &M);
  for(int i=0;i<M;i++) scanf("%d %d", &a, &b),G[a].push_back(b);
  for(int i=1;i<=N;i++) if(p[i]==-1) ans = max(ans, dfs(i));
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 8192
N=input()
L=[int(N[i]) for i in range(len(N))]

P=0
OT=0

for i in range(len(L)-1):
    if 0 <= L[i] <= 3:
        P += L[i] + OT
        OT = 0

    elif L[i] == 4:
        if OT == 1 and L[i+1]>=5:
            P += 5
        else:
            P += OT+L[i]
            OT = 0

    elif L[i] == 5:
        if OT == 1:
            P += 4

        else:
            if L[i+1] >= 5:
                P += 1 + 4
                OT = 1
            else:
                P += 5

    else:
        if OT == 1:
            P += 9-L[i]
            OT = 1
        else:
            P += 10 - L[i]
            OT = 1

Pone = 0
if OT==0:
    Pone = min(L[-1],11-L[-1])
elif OT==1 and L[-1]<=4:
    Pone = 1+L[-1]
else:
    Pone = 10-L[-1]

print(P+Pone)

Measured memory_bytes: 116388
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <queue>
#include <cmath>
#include <cstring>
using namespace std;

void init();
void solve();
int main(){
try { 

#ifndef CUSTOM_MAIN
#ifdef MULTIPLE_TEST_CASES_WITH_T

int T; scanf("%d",&T); while(T--) {init(); solve();}

#else
#ifdef MULTIPLE_TEST_CASES_WITHOUT_T

while(1) {try{init(); } catch(bool t){return 0;} solve(); }

#else

init(); solve();

#endif
#endif
#endif

} catch (const char* s) { return 0; }
    return 0;
}

#ifdef ENABLE_LL
#define int long long
#endif

#ifdef ENABLE_LL
#define I "%lld"
#define II "%lld%lld"
#define III "%lld%lld%lld"
#define IIII "%lld%lld%lld%lld"
#define IN "%lld\n"
#define IIN "%lld%lld\n"
#define IIIN "%lld%lld%lld\n"
#define IIIIN "%lld%lld%lld%lld\n"
#else
#define I "%d"
#define II "%d%d"
#define III "%d%d%d"
#define IIII "%d%d%d%d"
#define IN "%d\n"
#define IIN "%d%d\n"
#define IIIN "%d%d%d\n"
#define IIIIN "%d%d%d%d\n"
#endif

#ifdef __LOCALE__
#define see(a) std::cout << #a << "=" << a << std::endl
#define ses(a) std::cout << #a << "=" << a << " " 
#else
#define see(a) //std::cout << #a << "=" << a << std::endl
#define ses(a)
#endif
#define repe(a,b) for (int a=0;a<(int)b.size();a++)
#define rep(i,n) for (int i=0;i<n;i++)
#define repa(i,n) for (int i=1;i<=n;i++)
#define repi(i,a,b) for (int i=a;i<=b;i++) 
#define repb(i,a,b) for (int i=a;i>=b;i--)
typedef pair < int , int > pr; typedef pair < pr  , int > prr;
#define L first
#define R second
template <class T> inline bool checkMin(T& a , T b) { return (a > b ? a=b,1 : 0); }
template <class T> inline bool checkMax(T& a , T b) { return (a < b ? a=b,1 : 0); }
class Scanner{ private: istream& ist;public: Scanner(istream& in):ist(in){} string next(){ string r; ist >> r; return r; } string nextLine(){ string r; getline(ist,r); return r; } int nextInt(){ int r; ist >> r; return r; } double nextDouble(){ double r; ist >> r; return r; } char nextChar(){ char r; ist>>r; return r;} }; Scanner sc(cin);
void ALERT(bool judgememt, const char* phrase) { if (judgememt) { puts(phrase); throw "ALERT"; } }
bool alert(bool judgememt, const char* phrase) { if (judgememt) puts(phrase); return judgememt; }

const int N = 100005;
int a[N];

void init() {
     
}

void solve() {
    repa (i,100) repa (j,100) repa (k,100) a[i*i+j*j+k*k+i*j+j*k+k*i]++;
    repa (i,sc.nextInt()) printf(IN,a[i]); 
}



Measured memory_bytes: 3956
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
using namespace std;
using ll = long long;

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

  if(n == 0){
    cout << 0 << endl;
    return 0;
  }
  
  string ans = "";

  for(ll i=31; i>=0; i--){
    ll t = (ll)pow(-2, i);
    if(t > 0){
      if(-(t-1)/3*2 <= n-t && n-t <= (t-1)/3){
        n -= t;
        ans = ans + "1";
      }
      else{
        ans = ans + "0";
      }
    }
    else{
      if((-t) / 3 * (-1) <= n-t && n-t <= (-t) / 3  * 2 + 1){
        n -= t;
        ans = ans + "1";
      }
      else{
        ans = ans + "0";
      }
    }
  }
  
  int cnt = 0;
  for(int i=0; i<ans.length(); i++){
    if(ans[i] == '1'){
      cnt = i;
      break;
    }
  }
  cout << ans.substr(cnt, ans.length()-cnt) << endl;

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define siz(v) (ll)(v).size()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, x, n) for (ll i = x; i < (ll)(n); i++)
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1};

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

    ll n, ans = 0;
    cin >> n;

    vector<ll> a(n), b(n);
    rep(i, n) cin >> a[i];

    rep(i, n) cin >> b[i];

    priority_queue<ll> q;
    for(int i=0;i < n;i++)
    {
        if (b[(i + 1) % n] < b[i] && b[i] > b[(i - 1 + n) % n])
        {
            q.push(i);
        }
    }
    

    while(!q.empty())
    {
        ll ind=q.top();
        q.pop();

        if (b[ind] <= a[ind])
            continue;

        ll ng = 0, ok = INF,fr=b[(ind + 1) % n],ba=b[(ind - 1 + n) % n];
        while (abs(ng - ok) > 1)
        {
            ll mid = (ok + ng) / 2, B = b.at(ind) - (mid) * (fr + ba);

            if (B>a[ind] && (fr < B && B > ba))
            {
                ng = mid;
            }
            else
            {
                ok = mid;
            }
        }

        b.at(ind) -= ok * (fr+ba);

        if (b[ind] < a[ind])
            break;

        ans += ok;

        ind+=n-1;
        ind%=n;
        if (b[(ind + 1) % n] < b[ind] && b[ind] > b[(ind - 1 + n) % n])
        {
            q.push(ind);
        }

        ind+=2;
        ind%=n;
        if (b[(ind + 1) % n] < b[ind] && b[ind] > b[(ind - 1 + n) % n])
        {
            q.push(ind);
        }
        
    }

    for (int i = 0; i < n; i++)
    {
        if (a[i] != b[i])
        {
            cout << -1 << endl;
            return 0;
        }

    }

    cout << ans << endl;
}

Measured memory_bytes: 4600
import java.util.*;

// ABC 73-D
// http://abc073.contest.atcoder.jp/tasks/abc073_d

public class Main {

	static int N;
	static int M;
	static int R;
	
	static int answer = Integer.MAX_VALUE;
	static int[][] map;
	
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		N = in.nextInt();
		M = in.nextInt();
		R = in.nextInt();
		
		int[] cities = new int[R];
		for (int i = 0; i < R; i++) {
			cities[i] = in.nextInt() - 1;
		}
		
		map = new int[N][N];
		for (int i = 0; i < N; i++) {
			Arrays.fill(map[i], 100000 * (N - 1) + 1);
		}
		
		for (int i = 0; i < M; i++) {
			int s = in.nextInt() - 1;
			int g = in.nextInt() - 1;
			int d = in.nextInt();
			
			map[s][g] = d;
			map[g][s] = d;
		}
		
		for (int k = 0; k < N; k++) {
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < N; j++) {
					map[i][j] = Math.min(map[i][j], map[i][k] + map[k][j]);
				}
			}
		}
		
//		for (int i = 0; i < N; i++) {
//			for (int j = 0; j < N; j++) {
//				System.out.printf("%d ", map[i][j]);
//			}
//			System.out.println();
//		}
		
		solve(0, cities, new int[R], new int[R]);
		System.out.println(answer);
	}
	
	public static void solve(int index, int[] cities, int[] used, int[] path) {
		if (index == R) {
//			for (int i = 0; i < R; i++) {
//				System.out.printf("%d ", path[i]);
//			}
//			System.out.println();
			answer = Math.min(answer, distance(path));
		} else {
			for (int i = 0; i < R; i++) {
				if (used[i] == 0) {
					path[index] = cities[i];
					used[i] = 1;
					solve(index + 1, cities, used, path);
					used[i] = 0;
				}
			}
		}
	}
	
	public static int distance(int[] path) {
		int d = 0;
		for (int i = 0; i < R - 1; i++) {
			d += map[path[i]][path[i + 1]];
		}
		return d;
	}
}


Measured memory_bytes: 46124
#include <bits/stdc++.h>
#define fi first
#define se second
#define debug(x) cerr<<#x<<" = "<<(x)<<endl
#define rep(i,s,t) for(int i=(s),_t=(t);i<_t;++i)
using namespace std;
typedef pair<int,int> pii;


const int N=(int)1e5+5;

int R,C,tot;
pii dat[N<<1];

inline bool on_boundary(int x,int y)
{
	return !x||x==R||!y||y==C;
}

void trans(int id,int x,int y)
{
	if(!y)dat[tot++]=pii(x,id);
	else if(x==R)dat[tot++]=pii(x+y,id);
	else if(y==C)dat[tot++]=pii(R+C+(R-x),id);
	else dat[tot++]=pii(R+R+C+(C-y),id);
}

int main()
{
	int n;
	cin>>R>>C>>n;
	for(int x1,y1,x2,y2;n--;)
	{
		scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		if(on_boundary(x1,y1)&&on_boundary(x2,y2))
		{
			trans(n,x1,y1);
			trans(n,x2,y2);
		}
	}
	sort(dat,dat+tot);
	static int stk[N<<1];
	int tp=0;
	rep(i,0,tot)
	{
		if(tp&&stk[tp-1]==dat[i].se)--tp;
		else stk[tp++]=dat[i].se;
	}
	puts(!tp?"YES":"NO");
	return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin>>s>>t;
  int a,b;
  cin>>a>>b;
  string u;
  cin>>u;
  if(s==u){
    a-=1;
  }
  else{
    b-=1;
  }
  cout<<a<<" "<<b<<endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n; cin >> n;
	while( n-- ){
		int temp; cin >> temp;
		if( temp%2 == 1 ){
			cout << "first" << endl;
			return 0;
		}
	}
	cout << "second" << endl;
	return 0;
}

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

#define tt template<typename T> ostream& operator <<(ostream& os, const
#define tuv template<typename U, typename V> ostream& operator<<(ostream& os, const
tt vector<T>& v)            { os << "["; for(auto & x : v) os << " " << x; os << " ]"; return os; }
tt vector<vector<T> >& m)   { for(auto & x : m) { for(auto & y : x) os << y << " "; os << "\n"; } return os; }
tt set<T>& s)               { os << "{"; for(auto & x : s) os << " " << x; os << " }"; return os; }
tt unordered_set<T>& s)     { os << "{"; for(auto & x : s) os << " " << x; os << " }"; return os; }
tt queue<T>& q)             { queue<T> q2(q); while(!q2.empty()) { os << q2.front() << " "; q2.pop(); } return os; }
tt stack<T>& s)             { stack<T> s2(s); while(!s2.empty()) { os << s2.top() << " "; s2.pop(); } return os; }
tuv pair<U,V>& p)           { os << "(" << p.first << "," << p.second << ")"; return os; }
tuv map<U,V>& m)            { os << "{ "; for(auto & x : m) os << x.first << ":" << x.second << " "; os << "}"; return os; }
tuv unordered_map<U,V>& um) { os << "{ "; for(auto & x : um) os << x.first << ":" << x.second << " "; os << "}"; return os; }


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

    int x, y, z;
    std::cin >> x >> y >> z;

    std::cout << z << " " << x << " " << y << std::endl;


    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

// change!!!!!!!!!!!!
#define MAX_N 100000

int uf_par[MAX_N];
int uf_rank[MAX_N];

void uf_init( int n ) {
    for ( int i = 0; i < n; i++ ) {
        uf_par[i] = i;
        uf_rank[i] = 0;
    }
}

int uf_find( int x ) {
    if ( uf_par[x] == x ) { return x; }
    else { return uf_par[x] = uf_find(uf_par[x]); }
}

void uf_unite( int x, int y ) {
    x = uf_find( x );
    y = uf_find( y );
    if ( x == y ) { return; }
    
    if ( uf_rank[x] < uf_rank[y] ) {
        uf_par[x] = y;
    }
    else {
        uf_par[y] = x;
        if ( uf_rank[x] == uf_rank[y] ) { uf_rank[x]++; }
    }
    
}

bool uf_same( int x, int y ) {
    return uf_find(x) == uf_find(y);
}

int main() {

    int N,M;
    cin >> N >> M;
    vector<int> A(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> A[i];
    }
    uf_init(N);
    for ( int i = 0; i < M; i++ ) {
        int a,b;
        cin >> a >> b;
        a--; b--;
        uf_unite(a,b);
    }
    int ans = 0;
    for ( int i = 0; i < N; i++ ) {
        if ( uf_same( i, A[i]-1 ) ) { ans++; }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    ll n,k,a,cnta[200000]={},nowk=0,cntb=0;
    cin>>n>>k;
    rep(i,n){
        cin>>a;
        a--;
        if(cnta[a]==0) nowk++;
        cnta[a]++;
    }
    sort(cnta,cnta+200000);
    rep(i,200000){
        if(nowk<=k) break;
        if(cnta[i]==0) continue;
        nowk--;
        cntb+=cnta[i];
    }
    cout<<cntb<<endl;
    return 0;
}

Measured memory_bytes: 1792
#ifdef _MSC_VER
#include "stdc++.h"
#endif
#ifdef __GNUC__
#include<bits/stdc++.h>
#endif
using namespace std;

using ll = long long;

//constant
const double EPS = 1e-10;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// vector
//template<typename T> vector<vector<T>> vv(ll H, ll W, T v) { return vector<vector<T>> vec(H, vector<T>(W, v)); }

// view vector
template<typename T> void view(T e) { cout << e << endl; }
template<typename T> void view(const vector<T>& v) { for (const auto& e : v) { cout << e << " "; } cout << endl; }
template<typename T> void view(const vector<vector<T> >& vv) { for (const auto& v : vv) { view(v); } }

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




// ***************************************

vector<ll> calc_K(ll N){
    vector<ll> res;
    for (ll k = 1; k * k <= N; k++){
        if (N % k != 0) continue;
        res.push_back(k);
        ll j = N / k;
        if (j != k) res.push_back(j);
    }

    sort(ALL(res));

    return res;
}


int main(){

    ll N;
    cin >> N;

    const auto& vec1 = calc_K(N - 1);
    const auto& vec2 = calc_K(N);

    ll ans = vec1.size() - 1;

    for(auto& K: vec2){
        if (K == 1) continue;
        ll NN = N;

        while (NN % K == 0) NN /= K;
        if (NN % K == 1) ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384