akhauriyash/Code-Regression huggingface dataset:
#include <bitset>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

const int N=2e5+5;

int h,c,n,x,y;
vector<int> p[N];
#define pb(a) push_back(a)

bitset<N> f;

int main() {
	scanf("%d%d",&h,&c);
	scanf("%d",&n);
	fo(i,1,n) {
		scanf("%d%d",&x,&y);
		if (x==2&&y==1) {puts("1");return 0;}
		p[x].pb(y);
	}
	f[1]=1;
	fo(i,2,h) {
		f|=f<<1;
		for(int j=0;j<p[i].size();j++) f[p[i][j]]=0;
		for(int j=0;j<p[i+1].size();j++) 
			if (f[p[i+1][j]]) {
				printf("%d\n",i);
				return 0;
			}
	}
	printf("%d\n",h);
	return 0;
}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

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 int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int M;
    cin >> M;
    vec<ll> d(M), c(M);
    rep(i,M){
        cin >> d[i] >> c[i];
    }
    ll sumdc = 0;
    ll sumc = 0;
    ll ans = 0;
    rep(i,M){
        sumdc += d[i] * c[i];
        sumc += c[i];
    }
    ans = sumc - 1  + (sumdc - 1)/9;
    cout << ans << endl;
}

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

using namespace std;

int n;

int ap[30001];

int cmmdc(int a, int b)
{
    while(b != 0)
    {
        int r = a % b;
        a = b;
        b = r;
    }

    return a;
}

int stk[20001];

int rez = 0;

void verif()
{
    int i;
    int sum = 0;
    int cm = stk[1];
    for(i = 1; i <= n; i ++)
    {
        sum += stk[i];
        cm = cmmdc(cm, stk[i]);
    }

    if(cm != 1)
        return;

    for(i = 1; i <= n; i ++)
    {
        if(cmmdc(stk[i], sum - stk[i]) == 1)
            return;
    }

//    cout << "FOUND\n";

    for(i = 1; i <= n; i ++)
        cout << stk[i] << " ";
    cout << "\n";

    rez ++;

    exit(0);

    //if(rez == 2)
    //    exit(0);
}

void bkt(int k)
{
    if(k == n + 1)
    {
        verif();

        return;
    }

    int i;
    for(i = max(2, stk[k - 1] + 1); i <= 30000; i ++)
    {
        int c = i;
        int ok2=0,ok3=0;
        while(c % 2 == 0)
            c /= 2,ok2=1;
        while(c % 3 == 0)
            c /= 3,ok3=1;

        if(ok2 || ok3)
        if(ap[i] == 0)
        {
            ap[i] = 1;
            stk[k] = i;
            bkt(k + 1);
            ap[i] = 0;
        }
    }
}

int main()
{
    cin >> n;

    bkt(1);
    return 0;
}


Measured memory_bytes: 1536
program sum_of_product_of_pairs
  implicit none
  integer(8), parameter :: m = 1000000007
  integer :: n, i
  integer(8) :: a(200000) = 0, s = 0, x = 0
  read(*,*) n
  read(*,*) a(1:n)
  s = a(n)
  do i = n - 1, 1, -1
    x = mod(x + s * a(i), m)
    s = s + a(i)
    if (s >= m) s = s - m
  end do
  write(*,'(i0)') x
end program sum_of_product_of_pairs

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

int main() {
  int N;
  double x;
  string u;
  double sum = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> x;
    cin >> u;
    if (u == "JPY") {
      sum += x;
    } else {
      sum += 380000.0 * x;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<int> v;
int n,c,k,a,cnt=0,start,kk=0;
int main(){
	scanf("%d%d%d",&n,&c,&k);
	for(int i=1;i<=n;i++){
		scanf("%d",&a);
		v.push_back(a);
	}
	sort(v.begin(),v.end());
	for(int i=0;i<v.size();i++){
		if(i==0){
			start=v[0];
			++cnt;
			++kk;
			continue;
		}
		++kk;
		if(kk>c||v[i]>start+k){
			start=v[i];
			++cnt;
			kk=1;
		}
	}
	printf("%d",cnt);
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define llu long long unsigned
int main()
{
    int t,a,b,x,y,z,n,mx,mn,tmp;
    ///scanf("%d",&t);
   ///for(int i=0;i<t;i++){
        int cnt=0,ans=0;
        string s="";
        vector<int>vc;
        map<int,int>mp;
        map<char,int>mc;
        scanf("%d",&x);
        char ch,ch2;
        if(x%1000==0) puts("0");
        else printf("%d\n",1000-x%1000);


    ///}

    return 0;
}






Measured memory_bytes: 3780
# ITP1_6_B_0001

all = Array.new
mark = [ "S" , "H" , "C" , "D" ]
i1 = 1
sample = Array.new
i2 = 0
i3 = 0

mark.each do
	13.times do
		all << [ mark[i3] , i1.to_s ]
		i1 += 1
	end
	i1 = 1
	i3 += 1
end

n = gets.to_i

n.times do
	sample << gets.split.map(&:to_s)
end

outdata = all - sample

outdata.each do
	puts outdata[i2].join(" ")
	i2 += 1
end

Measured memory_bytes: 6112
#include <iostream>
#include <algorithm>

int main()
{
  int a, b, c, d;
  std::cin >> a >> b >> c >> d;
  int firstPoint = std::min(b, d);
    int secondPoint = std::max(a, c);
    
    std::cout << std::max(0, firstPoint - secondPoint);
}

Measured memory_bytes: 256
s = input()
t = input()
ls = len(s)
lt = len(t)
ans = "z"*(ls+1)

for i in range(ls-lt+1):
    for j in range(lt):
        if s[i+j] != t[j] and s[i+j] != "?":
            break
    else:
        tmp = (s[:i]+t+s[i+lt:]).replace("?","a")
        if ans > tmp:
            ans = tmp
else:
    if ans == "z"*(ls+1):
        ans = "UNRESTORABLE"

print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
int main()
{
	int a,b,i,s;
	char c[10],d[10];

	scanf("%d%d",&a,&b);
	for(i=0;i<b;i++)
		c[i]=a;
	for(i=0;i<a;i++)
		d[i]=b;
	s=strcmp(c,d);
	if(s<=0)
		for(i=0;i<b;i++)
			printf("%d",a);
	else
		for(i=0;i<a;i++)
			printf("%d",b);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

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


vector<ll> inv,fact,invfact;
void Mod_build(int n=201010){
	fact.resize(n+1);
	inv.resize(n+1);
	invfact.resize(n+1);
	fact[0]=inv[0]=invfact[0]=1;
	inv[1]=1;
	for(ll i=0;i<n;i++){
		fact[i+1]=fact[i]*(i+1)%mod;
		if(i>0)inv[i+1]=mod-inv[mod%(i+1)]*(mod/(i+1))%mod;
		invfact[i+1]=invfact[i]*inv[i+1]%mod;
	}
}
ll perm(int n,int k){
	if(n<0||k<0||k>n)return 0;
	return fact[n]*invfact[n-k]%mod;
}
ll comb(int n,int k){
	if(n<0||k<0||k>n)return 0;
	return (fact[n]*invfact[n-k]%mod)*invfact[k]%mod;
}
ll powmod(ll n,ll k){
	k%=mod-1;
	if(k<0)k+=mod-1;
	ll ret=1;
	while(k){
		if(k&1)ret=ret*n%mod;
		n=n*n%mod;
		k>>=1;
	}
	return ret;
}


ll modinv(ll a) {
    ll m=mod;
    ll b = m, u = 1, v = 0;
    while (b) {
        ll 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 n;
vector<int> E[201010];
vector<double> dp1(201010,0);
vector<double> dp2(201010);
VI size1(201010,0);
VI size2(201010);
vector<double> ans(201010);

void dfs1(int cu, int pa = -1) {
  for(int to:E[cu]) {
    if (to != pa) {
      dfs1(to,cu);
      dp1[cu]+=dp1[to];
	    size1[cu]++;
    }
  }
  if(size1[cu]) {
    dp1[cu]/=size1[cu];
    dp1[cu]+=1.0;
  }
}

void dfs2(int cu, int pa = -1) {
  if(pa==-1) {
    dp2[cu]=0;
    ans[cu]=dp1[cu];
  } 
  else ans[cu]=(dp1[cu]*size1[cu]+dp2[cu])/(size1[cu]+1);
  for(int to:E[cu]){
    if(to==pa) continue; 
    if(pa!=-1){ 
      dp2[to]=ans[cu]*(size1[cu]+1)-(dp1[to]+1);
      dp2[to]/=size1[cu]; 
    }
    else {
      dp2[to]=ans[cu]*size1[cu]-(dp1[to]+1);
      if(size1[cu]-1) dp2[to]/=(size1[cu]-1);
    }
    dp2[to]+=1;
    dfs2(to,cu);
  }
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int i,j;
	cin>>n;
	Mod_build();
	for(i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		a--; b--;
		E[a].pb(b);
		E[b].pb(a);
	}
	dfs1(0);
  dfs2(0);
  for(i=0;i<n;i++){
    //cout<<dp1[i]<<" "<<dp2[i]<<endl;
  }
	for(i=0;i<n;i++) cout<<fixed<<setprecision(12)<<ans[i]<<endl;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn  = 1e5+5;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);

#define pb push_back
#define endl '\n'
#define dokme(x) return(cout << x , 0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ms(x , y) memset(x , y , sizeof x);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

int n;
int mxval[520][maxn];
int w[(1 << 18)+5] , v[(1 << 18)+5];
int q;
int w2[20];
int v2[20];

void solve(int x){
    int pos = x;
    int cnt = 0;
    while(x!=0){
        w2[cnt] = w[x];
        v2[cnt++] = v[x];
        x/=2;
    }
    for(int i = 0 ; i < (1 << cnt) ; i ++){
        int sum = 0;
        int val = 0;
        for(int j = 0 ; j < cnt ; j ++){
            if(i&(1 << j))
                sum+=w2[j] , val+=v2[j];
        }
        if(sum <= 100000)
            mxval[pos][sum] = max(mxval[pos][sum] , val);
    }
    for(int i = 1 ; i < maxn ; i ++)
        mxval[pos][i] = max(mxval[pos][i] , mxval[pos][i-1]);
}

void prep(){
    for(int i = 1 ; i <= min(n,510) ; i ++){
        solve(i);
    }
}

void solve(int x , int l){
    int mx = 0;
    int cnt = 0;
    while(x>510){
        w2[cnt] = w[x];
        v2[cnt++] = v[x];
        x/=2;
    }
    for(int i = 0 ; i < (1 << cnt) ; i ++){
        int sum = 0;
        int val = 0;
        for(int j = 0 ; j < cnt ; j ++){
            if(i&(1 << j))
                sum+=w2[j] , val+=v2[j];
        }
        if(sum <= l)mx = max(mx , val);
        if(l >= sum)mx = max(mx , val + mxval[x][l - sum]);
    }
    cout << mx << endl;
}

int main(){
    migmig
    cin >> n;
    for(int i = 1 ; i <= n ; i ++)
        cin >> v[i] >> w[i];
    prep();
    cin >> q;
    while(q -- ){
        int x , l;
        cin >> x >> l;
        if(x <= 510){
            cout << mxval[x][l] << endl;
            continue;
        }
        solve(x , l);
    }
    return(0);
}

Measured memory_bytes: 204940
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <list>
#include <queue>
#include <vector>
using namespace std;

const long MAX=100000;

vector<int> G[MAX];
list<int> ou;
bool V[MAX];
int N;
int indeg[MAX];

void bfs(int s){
	queue<int> que;
	que.push(s);
	V[s]=true; //?¨???????
	
	while( !que.empty() ){
		int u=que.front();
		que.pop();
		ou.push_back(u); //????????¨????????????????????????
		
		for(int i=0; i<G[u].size(); ++i){
			int v=G[u][i]; //u?????????????????????????????????????????????
			indeg[v]--; //????¬???°???????????????
			
			if(indeg[v]==0 && !V[v]){
				V[v]=true;
				que.push(v);	
			}
		}
	}		
}

//topological sort
void tsort(){
	for(int i=0; i<N; ++i) indeg[i]=0;
	
	for(int i=0; i<N; ++i){
		for(int j=0; j<G[i].size(); ++j){
			int k=G[i][j];
			indeg[k]++;
		}
	}
	
	for(int i=0; i<N; ++i){
		if(indeg[i]==0 && !V[i]) bfs(i);	
	}
	
	for(list<int>::iterator it=ou.begin(); it!=ou.end(); ++it){
		cout << *it << endl;	
	}
}

int main(){
	long M;
	scanf(" %d %ld", &N, &M);
	
	for(int i=0; i<N; ++i) V[i]=false;
	
	for(long i=0; i<M; ++i){
		int s, t;
		scanf(" %d %d", &s, &t);
		G[s].push_back(t); //??????????????????		
	}	
	
	tsort();
}

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def build_grid(H, W, intv, _type, space=True, padding=False):
    # 入力がスペース区切りかどうか
    if space:
        _input = lambda: input().split()
    else:
        _input = lambda: input()
    _list = lambda: list(map(_type, _input()))
    # 余白の有無
    if padding:
        offset = 1
    else:
        offset = 0
    grid = list2d(H+offset*2, W+offset*2, intv)
    for i in range(offset, H+offset):
        row = _list()
        for j in range(offset, W+offset):
            grid[i][j] = row[j-offset]
    return grid

H, W = MAP()
grid = build_grid(H, W, '*', str, space=0, padding=1)

dp = list2d(H+2, W+2, INF)
if grid[1][1] == '.':
    dp[1][1] = 0
else:
    dp[1][1] = 1
for i in range(H+1):
    for j in range(W+1):
        if grid[i][j] == grid[i][j+1]:
            dp[i][j+1] = min(dp[i][j+1], dp[i][j])
        else:
            dp[i][j+1] = min(dp[i][j+1], dp[i][j] + 1)  
        if grid[i][j] == grid[i+1][j]:  
            dp[i+1][j] = min(dp[i+1][j], dp[i][j])
        else:
            dp[i+1][j] = min(dp[i+1][j], dp[i][j] + 1)
ans = ceil(dp[H][W], 2)
print(ans)


Measured memory_bytes: 43376
#include <iostream>
#include <queue>

using namespace std;

#define fi first
#define se second

typedef long long int ll;

const ll maxn = 1e3 + 10;
const int Move[4][2] = {-1,0,1,0,0,1,0,-1};
char mp[maxn][maxn];
int step[maxn][maxn];
bool vis[maxn][maxn];
int n,m;

bool check(int x,int y) {
    if(x < 0 || y < 0|| x >= n || y >= m || vis[x][y] || mp[x][y] == '#') return false;
    return true;
}

int BFS() {
    queue<pair<int ,int> > q;
    q.push(make_pair(0,0));
    step[0][0] = 1;
    vis[0][0] = true;
    while (!q.empty()) {
        pair<int ,int> t = q.front();
        q.pop();
        for(int i = 0;i < 4;i++) {
            int tox = t.fi + Move[i][0];
            int toy = t.se + Move[i][1];
            if(tox == n - 1 && toy == m - 1) return step[t.fi][t.se] + 1;
            if(check(tox,toy)) {
                vis[tox][toy] = true;
                step[tox][toy] = step[t.fi][t.se] + 1;
                q.push(make_pair(tox,toy));
            }
        }
    }
    return -1;
}


int main(){
    cin>>n>>m;
    int cnt = 0;
    for(int i = 0;i < n;i++)
        for(int j = 0;j < m;j++) {
            cin>>mp[i][j];
            if(mp[i][j] == '#') cnt++;
        }
    int res = BFS();
    if(res == -1) {
        cout<<"-1"<<endl;
    } else {
        cout<<n*m - res - cnt<<endl;
    }
    return 0;
}


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

const long long INF=1e15;

struct edge{
    int to,cost;
};

vector<long long> dp(100100,-1);
vector<edge> g[100100];

void solve(int u,int pa=-1){
    for(auto e:g[u]){
        int v=e.to; int c=e.cost;
        if(v==pa) continue;
        if(dp[v]!=-1) continue;
        dp[v]=dp[u]+c;
        solve(v,u);
    }
}

int main(){
    int N; cin >> N;
    for(int i=0;i<N-1;i++){
        int a,b,c; cin >> a >> b >> c;
        a--;b--;
        g[a].push_back({b,c});
        g[b].push_back({a,c});
    }
    int Q,K; cin >> Q >> K;
    K--;
    dp[K]=0;
    solve(K);
    /*
    for(int i=0;i<N;i++){
        cout << dp[i] << " ";
    }
    */
    for(int i=0;i<Q;i++){
        int x,y; cin >> x >> y; x--;y--;
        cout << dp[x]+dp[y] << endl;
    }
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1e09+7;



#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vi vector<int>

int main(){

  int n;
  cin>>n;
  
  vi p(n);
  vi q(n);
  
  rep(i,n){
    int tmp;
    cin>>tmp;
    p.at(i)=tmp;
  }
  
  rep(i,n){
    int tmp;
    cin>>tmp;
    q.at(i)=tmp;
  }
  
  vi vec(n);
  rep(i,n){
    vec.at(i)=i+1;
  }
  
  
  int count=0;
  int a,b;
  
  do{
    count++;
    if (p==vec){
      a=count;
    }
    if (q==vec){
      b=count;
    }
  }while(next_permutation(vec.begin(),vec.end()));
  
  cout<<abs(a-b)<<endl;
  
      
  
  

  
  
  
}



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

using namespace std;


const int INF = 1e9;

int N, A, B, C;
vector<int> l;

int dfs(int i, int a, int b, int c) {
    if (i == N) {
        if (a == 0 || b == 0 || c == 0) return INF;
        return abs(A - a) + abs(B - b) + abs(C - c);
    }

    // not use
    int res = dfs(i+1, a, b, c);
    // A
    res = min(res, dfs(i+1, a + l[i], b, c) + (a == 0 ? 0: 10));
    // B
    res = min(res, dfs(i+1, a, b + l[i], c) + (b == 0 ? 0: 10));
    // C
    res = min(res, dfs(i+1, a, b, c + l[i]) + (c == 0 ? 0: 10));

    return res;
}


void solve() {
    cin >> N >> A >> B >> C;
    l.resize(N);
    for (int i = 0; i < N; i++) cin >> l[i];

    cout << dfs(0, 0, 0, 0) << endl;
}


int main() {
    solve();
    return 0;
}

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

int main(){
	int n, mochi;
	cin >> n;
	vector<int> d(n);
	mochi = n;
	for(int i = 0; i < n; i++)
		cin >> d.at(i);
	sort(d.begin(), d.end());
	for(int i = 1; i < n; i++){
		if(d.at(i-1) == d.at(i)){
			mochi--;
		}
	}
	cout << mochi << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,r,c,i,j,k=0;
    cin>>r>>c;
    int ar[r][c];
    int cn[r*c][4];
    for(i=0;i<r;i++)
    {
        for(j=0;j<c;j++)
        {
            cin>>ar[i][j];
        }
    }
     for(i=0;i<r;i++)
    {
        for(j=0;j<c-1;j++)
        {
            if(ar[i][j]%2!=0)
            {
                k++;
                ar[i][j+1]=ar[i][j+1]+1;
                ar[i][j]=ar[i][j]-1;
             cn[k-1][0]=i;
              cn[k-1][1]=j;
               cn[k-1][2]=i;
                cn[k-1][3]=j+1;


            }
           // cout<<ar[i][j]<<" ";
        }
        //cout<<ar[i][c-1];
        //cout<<endl;
    }
    for(j=c-1;j<c;j++)
    {
        for(i=0;i<r-1;i++)
        {
            if(ar[i][j]%2!=0)
            {
                k++;
                ar[i+1][j]=ar[i+1][j]+1;
                ar[i][j]=ar[i][j]-1;
             cn[k-1][0]=i;
              cn[k-1][1]=j;
               cn[k-1][2]=i+1;
                cn[k-1][3]=j;


            }
        }
    }
     /*for(i=0;i<r;i++)
    {
        for(j=0;j<c;j++)
        {
            cout<<ar[i][j]<<" ";
        }
        cout<<endl;
    }*/
    cout<<k<<endl;
    for(i=0;i<k;i++)
    {
        for(j=0;j<4;j++)
        {
            if(j!=3)cout<<cn[i][j]+1<<" ";
          else
            cout<<cn[i][j]+1<<endl;
        }
        //cout<<endl;
    }


}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
typedef long long lnt;
template <class T> inline void read(T &x) {
	x = 0; int c = getchar(), f = 1;
	for (; !isdigit(c); c = getchar()) if (c == 45) f = -1;
	for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-'0');
}
int n, m, w[105], v[105]; lnt f[100005];
int main() {
	read(n), read(m);
	for (int i = 1; i <= n; i++)
		read(w[i]), read(v[i]);
	for (int i = 1; i <= n; i++)
		for (int j = m; j >= w[i]; j--)
			f[j] = max(f[j], f[j-w[i]]+v[i]);
	lnt mx = 0;
	for (int i = 0; i <= m; i++)
		mx = max(mx, f[i]);
	return printf("%lld\n", mx), 0;
}


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

int main(){
  string S;
  cin >> S;
  int monf = S.at(5) -'0';
  int monr = S.at(6) -'0';
  if(monf*10+monr<=4) cout << "Heisei" << endl;
  else cout << "TBD" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAX_V 1000
#define INF 1<<29
using namespace std;
struct edge{int to,cap,rev,re;};
vector<edge>G[MAX_V];
int level[MAX_V];
int iter[MAX_V];
void add_edge(int from,int to,int cap,int re){
  G[from].push_back((edge){to,cap,(int)G[to].size(),re});
  G[to].push_back((edge){from,0,(int)G[from].size()-1,-1});
}
void bfs(int s){
  memset(level,-1,sizeof(level));
  queue<int>q;
  level[s]=0;
  q.push(s);
  while(!q.empty()){
    int v=q.front();q.pop();
    for(int i=0;i<G[v].size();i++){
      edge &e=G[v][i];
      if(e.cap>0&&level[e.to]<0){
        level[e.to]=level[v]+1;
        q.push(e.to);
      }
    }
  }
}
int dfs(int v,int t,int f){
  if(v==t)return f;
  for(int &i=iter[v];i<G[v].size();i++){
    edge &e=G[v][i];
    if(e.cap>0&&level[v]<level[e.to]){
      int d=dfs(e.to,t,min(f,e.cap));
      if(d>0){
        e.cap-=d;
        G[e.to][e.rev].cap+=d;
        return d;
      }
    }
  }
  return 0;
}
int max_flow(int s,int t){
  int flow=0;
  while(1){
    bfs(s);
    if(level[t]<0)return flow;
    memset(iter,0,sizeof(iter));
    int f;
    while((f=dfs(s,t,INF))>0){
      flow+=f;
    }
  }
}
int main(){
  int n,m,c=1,s,t;
  cin>>n>>m;
  while(m--){
    int a,b;
    cin>>a>>b;
    a--,b--;
    add_edge(a,b,1,-1);
    add_edge(b,a,1,c++);
  }
  cin>>s>>t;s--,t--;
  cout<<max_flow(s,t)<<endl;
  vector<int>ans;
  for(int i=0;i<1000;i++){
    for(int j=0;j<G[i].size();j++){
      if(G[i][j].re!=-1&&G[i][j].cap==0)ans.push_back(G[i][j].re);
    }
  }
  cout<<ans.size()<<endl;
  sort(ans.begin(),ans.end());
  for(int i=0;i<ans.size();i++){
    cout<<ans[i]<<endl;
  }
}

Measured memory_bytes: 3284
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>

int min(int a,int b){
    if(a>b){
        return b;
    }else{
        return a;
    }
}

int max(int a,int b){
    if(a>b){
        return a;
    }else{
        return b;
    }
}

int main(void){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    int m = min(min(a,b),c);
    int M = max(max(a,b),c);
    int mid = a+b+c-m-M;
    printf("%d\n",M*10 + mid + m);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
const int MOD=(int)1e9+7;
using namespace std;
int main(){
    int n,tmp,ans=0;
    cin>>n;
    REP(i,n){
        int tmp;
        cin>>tmp;
        ans+=tmp-1;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	static final Scanner	s	=new Scanner(System.in);

	public static void main(String args[]){
		input();
		solve();
	}

	private static void input(){
	}

	private static void solve(){
		long n=s.nextInt(),res=1;
		for(int i=1;i<=n;i++) {
			res*=i;
			res%=1000000007;
		}
		System.out.println(res);
	}
}


Measured memory_bytes: 20692
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;

public class Main {

	static BufferedReader reader;
	final static boolean MODE_DEBUG = false;
	//static field here
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		reader = new BufferedReader(new InputStreamReader(System.in));
		//code here
		int[] NM = readLineInt();
		int r = NM[0];
		int D = NM[1];
		int x = NM[2];
		int ans = x;
		for(int i=2001;i<=2010;i++) {
			ans = ans*r-D;
			print(ans);
		}
		
	}
	
	//functions here
	//note that all methods should be STATIC


	private static <T> int arraySearch(T needle, T[] heystack) {
		for(int i=0;i<heystack.length;i++) {
			if(needle.equals(heystack[i])) {
				return i;
			}
		}
		return -1;
	}
	private static int[] sort(int[] base) {
		int[] copy = array_copy(base);
		Arrays.sort(copy);
		return copy;
	}
	private static int[] array_copy(int[] base) {
		int[] copy = new int[base.length];
		for(int i=0;i<base.length;i++) {
			copy[i] = base[i];
		}
		return copy;
	}
	private static int[] asArray(ArrayList<Integer> ints) {
		int[] intlist = new int[ints.size()];
		for(int i=0;i<intlist.length;i++) {
			intlist[i] = ints.get(i);
		}
		return intlist;
	}
	private static String[] readLine(){
		try{
			return reader.readLine().split(" ");
		}catch(Exception e){
			e.printStackTrace();
			return new String[]{e.getMessage()};
		}
	}
	private static int[] readLineInt(){
		try{
			String[] s = readLine();
			int[] ints = new int[s.length];
			for(int i=0;i<ints.length;i++) {
				ints[i] = Integer.parseInt(s[i]);
			}
			return ints;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	private static byte[] readLineByte(){
		try{
			String[] s = readLine();
			byte[] bytes = new byte[s.length];
			for(int i=0;i<bytes.length;i++) {
				bytes[i] = Byte.parseByte(s[i]);
			}
			return bytes;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	private static char[] readLineChar(){
		try{
			String[] s = readLine();
			char[] chars = new char[s.length];
			for(int i=0;i<chars.length;i++) {
				chars[i] = (char)Integer.parseInt(s[i]);
			}
			return chars;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	private static void print(Object o){
		System.out.println(o);
	}
	private static void print(){
		System.out.println();
	}
	private static void printd(Object o){
		if(MODE_DEBUG)System.err.println(o);
	}
	private static void printd(){
		if(MODE_DEBUG)System.err.println();
	}
}


Measured memory_bytes: 20948
#include<bits/stdc++.h>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
typedef std::vector<int> vi;
typedef std::vector<std::vector<int>> vvi;
typedef std::vector<long long> vl;
typedef std::vector<std::vector<long long>> vvl;
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
 
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;
}


ll gcd(ll n, ll m) {
    ll tmp;
    while (m!=0) {
        tmp = n % m;
        n = m;
        m = tmp;
    }
    return n;
}
 
ll lcm(ll n, ll m) {
    return abs(n) / gcd(n, m)*abs(m);//gl=xy
}

using namespace std;

void solve()
{
  string s;
  cin >> s;
  if(s=="ABC"){
    cout << "ARC";
  }
  else
    cout << "ABC";
}

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



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

int main()
{
    int n;

    while(cin>>n)
    {
        int a,b;
        cin>>a>>b;

        if(n==1)
            cout<<"Hello World"<<endl;
        else
            cout<<a+b<<endl;
    }

    return 0;
}


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

#define trav(a, A) for (auto & a : A)
#define f first
#define s second

typedef long long ll;

const ll MOD = 1e+9+7;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const ll MAXN = 1e+5+7;

struct DSU{
    vector<int> p, sz;
    DSU(int n){
        p = sz = vector<int>(n,1);
        for (int i = 0; i < n; ++i) p[i] = i;
    }
    int get(int a){
        return p[a] = (p[a] == a ? a : get(p[a]));
    }
    void join(int a, int b){
        a = get(a);
        b = get(b);
        if (a == b) return;
        if (sz[a] > sz[b]) swap(a, b);
        p[a] = b;
        sz[b] += sz[a];
    }
};

void solve(){
    int n, m;
    cin >> n >> m;
    DSU d(n);
    int ans = 0;
    while(m--){
        int a, b;
        cin >> a >> b;
        a--, b--;
        d.join(a, b);
    }
    for (int i = 0; i<  n; ++i){
        ans = max(ans, d.sz[d.get(i)]);
    }
    cout << ans << '\n';
}

int main ()
{
	ios_base::sync_with_stdio (0);
	cin.tie (0);
	ll i, j, n;
	int t = 1; //cin >> t;
	while(t--) solve();
	return 0;
}



Measured memory_bytes: 4752
def main():
    n=int(input())
    X=list(map(int,input().split()))
    m=sum(X)/n
    if 2*(m//1-m)+1<0:
      m=int(m//1+1)
    else:
      m=int(m//1)
    ans=0
    for i in range(n):
        ans+=(X[i]-m)**2
    print(ans)   
if __name__=='__main__':
    main()

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

#define sf(n) scanf("%d",&n)
#define sfl(n) scanf("%lld",&n)
#define sfd(n) scanf("%lf",&n)
#define sfc(n) scanf(" %c",&n)
#define endll pf("\n")
#define pf printf
#define pi acos(-1.0)
#define eps 1e-10
#define mem(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define xx first
#define yy second
#define pii pair<int,int >
#define pll pair<ll int,ll int >
#define ll long long
#define MP make_pair
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define cnd tree[idx]
#define lnd tree[idx<<1]
#define rnd tree[(idx<<1)+1]
#define lndp (idx<<1),(b),((b+e)>>1)
#define rndp ((idx<<1)+1),(((b+e)>>1)+1),(e)
#define inf 1999999999
#define MX 100005
#define mod 1000000007
#define var int i,j,k,l,m,n,z=0,c=0,x,y,t,r,mid
//int dx[8]={0,0,1,1,-1,-1,1,-1};
//int dy[8]={1,-1,1,-1,1,-1,0,0};
//int dx[4]={1,-1,0,0};
//int dy[4]={0,0,1,-1};

ll int bigmod(ll int x,ll int y,ll int m)
{
    if(y==0)return 1;
    ll n=bigmod(x,y/2,m);
    n=(n*n)%m;
    if(y & 1)n=((n%m)*(x%m))%m;
    return n;
}

void subset(int n)
{
    int i,j,sz=(1<<n);
    for(i=1;i<sz;i++)
    {
        for(j=0;j<n;j++)
        {
            if((1<<j)&i)
            {
                //cout<<j<<" ";
            }
        }
        //endll;
    }
}


int main()
{
    var;
    cin>>n>>m>>k;
    if(m>k)swap(m,k);
    z=max(k-(n+m),0);
    //if(z<=n)cout<<0<<endl;
     cout<<z<<endl;
}


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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int x,y;
    cin>>x>>y;
    bool flag=false;
    for (int i=0;i<=x;i++)
        if(2*i+4*(x-i)==y)
            flag=true;
    if(flag) cout<<"Yes\n";
    else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

template<typename T>
struct BinaryIndexedTree{
    vector<T> data;
    int sz;

    BinaryIndexedTree(int n){
        sz = n + 1;
        data.assign(sz, 0);
    }

    void add(int i, T x){
        ++i;
        while(i < sz){
            data[i] += x;
            i += i & -i;
        }
    }

    // [0, i] の区間和
    T sum(int i){
        T res = 0;
        ++i;
        while(i > 0){
            res += data[i];
            i -= i & -i;
        }
        return res;
    }

    T sum(int l, int r){
        return sum(r - 1) - sum(l - 1);
    }

    // val 以上を満たす 0-indexed の位置を返す
    int lower_bound(T val){
        // if(val <= 0)    return -1;
        int res = 0;
        int n = 1;
        while(n < sz)   n <<= 1;
        for(int k = n >> 1; k > 0; k >>= 1){
            if(res + k < sz && data[res + k] < val){
                val -= data[res + k];
                res += k;
            }
        }
        return res;     // 1-indexed であれば、res + 1 を返す
    }
};

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

    int n, m, q;
    cin >> n >> m >> q;
    vector<tuple<int, int, int>> table;
    for(int i = 0; i < m; ++i){
        int l, r;
        cin >> l >> r;
        table.emplace_back(l, q, r);
    }
    for(int i = 0; i < q; ++i){
        int l, r;
        cin >> l >> r;
        table.emplace_back(l, i, r);
    }
    // 列車とクエリを左端昇順ソート (左端が同じものはクエリが先にくるようにする。)
    // こうすることで、クエリの区間に対して左端がはみ出たものを考慮せずに済む。
    sort(table.begin(), table.end());

    BinaryIndexedTree<int> bit(n + 1);
    for(auto tup : table){
        if(get<1>(tup) < q) continue;
        // 列車の右端の位置について加算
        bit.add(get<2>(tup), 1);
    }
    vector<int> ans(q);
    for(auto tup : table){
        int i = get<1>(tup);
        // 列車であれば、以降は利用しないので減算しておく。
        if(i == q)  bit.add(get<2>(tup), -1);
        // クエリであれば、[l, r] に含まれる列車の個数を取得する。
        else{
            int l = get<0>(tup), r = get<2>(tup);
            ans[i] = bit.sum(l, r + 1);
        }
    }
    for(int x : ans)    cout << x << '\n';
}

Measured memory_bytes: 9524
#import sys
MOD = 10 ** 9 + 7
#input = sys.stdin.readline
import math

import itertools

#import bisect

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default


def main():
#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]
    n=int(input())
    nn=n//2
    a=nn//5 #base
    b = [a//(10**i) for i in range(1,18)]
    c = [a//(5**i) for i in range(1,50)]
    count=0
#    for i in b:
 #       if i!=0:
  #          count+=i
    for i in c:
        if i!=0:
            count+=i
 #   print(b,c)
    if n%2==0:
        print(count+a)
    else:
        print(0)




if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
str = STDIN.gets
num = str.chomp.to_i
ans = []
while (num != 0)
	a = 0
	b = 0
	for i in 1..num do
		str = STDIN.gets
		cards = str.split(" ")
		card_a = cards[0].to_i
		card_b = cards[1].to_i
		
		if card_a == card_b then
			a += card_a
			b += card_b
		elsif card_a > card_b then
			a += card_a + card_b
		else
			b += card_a + card_b
		end
	end
	ansstr = a.to_s + " " + b.to_s
	ans.push(ansstr)
	str = STDIN.gets
	num = str.chomp.to_i
end

for out in ans do
	print out ,"\n"
end

Measured memory_bytes: 6096
x,n=list(map(int,input().split(' ')))

if n == 0:
    print (x)
else:
    p=list(map(int,input().split(' ')))

    chk_x = False
    pmax = 0
    pmin = 101
    for pr in p:
        if pmax < pr:
            pmax = pr
        if pmin > pr:
            pmin = pr
        if pr == x:
            chk_x = True

    all_i = list(range(0,102))
    target_i = list(set(all_i)^set(p))

    minsub = abs(target_i[0] - x) + 1
    ans = -1
    for i in target_i:
        if abs(i-x) < minsub:
            minsub = abs(i-x)
            ans = i
    if not chk_x:
        print(x)
    else:
        print (ans)

Measured memory_bytes: 62032
#include<bits/stdc++.h>
using namespace std;
int dp[8001][16001];
int a[8001];
int main(){
	string s;
	int x,y;
	cin>>s>>x>>y;
	int k=0;
	int w=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='T'){
			k++;
			a[k]=w;
			w=0;
		}
		else{
			w++;
		}
	}
	k++;
	a[k]=w;
	//for(int i=1;i<=k;i++)cout<<a[i]<<endl;
	dp[1][a[1]+8000]=1;
	for(int i=3;i<=k;i+=2){
		for(int j=0;j<=16000;j++){
			if(j+a[i]<=16000)
				dp[i][j]=dp[i-2][j+a[i]];
			if(j-a[i]>=0)
				dp[i][j]=dp[i][j]||dp[i-2][j-a[i]];
		}
	}
	dp[0][8000]=1;
	for(int i=2;i<=k;i+=2){
		for(int j=0;j<=16000;j++){
			if(j+a[i]<=16000)
			dp[i][j]=dp[i-2][j+a[i]];
			if(j-a[i]>=0)
			dp[i][j]=dp[i][j]||dp[i-2][j-a[i]];
		}
	}
	int ans;
	if(k%2==0){ 
		ans=dp[k][y+8000]&&dp[k-1][x+8000];
	}
	else{
		ans=dp[k][x+8000]&&dp[k-1][y+8000];
	}
	cout<<(ans==0?"No":"Yes");
	return 0;
}

Measured memory_bytes: 497792
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define boost ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define pii pair<ll,ll>
const int sz=1e5+5;
ll n,ans=0;
ll a[sz],b[sz],c[sz];
int main()
{
    boost;
    cin>>n;
    for(int i=0;i<n;i++)
    cin>>a[i];
    for(int i=0;i<n;i++)
    cin>>b[i];
    for(int i=0;i<n;i++)
    cin>>c[i];
    sort(a,a+n),sort(b,b+n),sort(c,c+n);
    for(int i=0;i<n;i++)
    {
        int x=b[i];
        int p=lower_bound(a,a+n,x)-a;
        int q=n-(upper_bound(c,c+n,x)-c);
        ans+=1LL*p*q;
    }
   cout<<ans<<endl;
}

Measured memory_bytes: 2560
A,B,C,K = map(int,input().split())
ans=0
if A<K:
    ans+=A
    K-=A
else:
    ans+=K
    K=0
if B<K:
    K-=B
else:
    K=0
if C<K:
    ans-=C
    K-=C
else:
    ans-=K
    K=0
print(ans)

Measured memory_bytes: 9196
x,y,z,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

ab=[]

for aa in a:
    for bb in b:
        ab.append(aa+bb)

ab.sort(reverse=True)

abk=ab[:k]

ans=[]

for item in abk:
    for cc in c:
        ans.append(item+cc)

ans.sort(reverse=True)

for item in ans[:k]:
    print(item)


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

int n, c1, c2, mx, c[100005];
int main()
{
    int i, t;
    cin >> n;
    for (i = 0; i < n; i++) {
        scanf("%d", &t);
        c[t]++;
        mx = max(mx, t);
    }
    for (i = 0; i <= mx; i++) {
        while (c[i] > 2) c[i] -= 2;
    }
    for (i = 0; i <= mx; i++) {
        if (c[i] == 2) c2++;
        if (c[i] > 0) c1++;
    }
    cout << c1 - c2 % 2 << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <cmath>
#include <set>
#include <queue>
#include <map>
#include <cstdio>
#include <cstring>
#include <string>
#include <stack>
#include <algorithm>
#include <limits.h>
#include <bits/stdc++.h>
#define fw(x) freopen("x.txt","w",stdout)
#define For(i,a,b,c) for(int i = a;i < b;i+=c)
#define REP(i,n) for(int i = 0;i < n;++i)
#define REP1(i,n) for(int i = 1; i<=n;i++)
#define mem(a,s) memset(a,s,sizeof a)
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL)
#define pf printf
#define sc scanf
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()
#define vii vector<int>
#define vll vector<ll>
#define vss vector<string>
#define debug(x)  cout<<#x"="<<(x)<<endl
#define pb push_back


using namespace std;


// moves

//int dx[]= {0,0,1,-1};/*4 side move*/
//int dy[]= {-1,1,0,0};/*4 side move*/
//int dx[]= {1,1,0,-1,-1,-1,0,1};/*8 side move*/
//int dy[]= {0,1,1,1,0,-1,-1,-1};/*8 side move*/
//int dx[]={1,1,2,2,-1,-1,-2,-2};/*knight move*/
//int dy[]={2,-2,1,-1,2,-2,1,-1};/*knight move*/


//big_mod

//ll bigmod(ll a,ll b,ll m)
//{if(b == 0) return 1%m;ll x = bigmod(a,b/2,m);x = (x * x) % m;if(b % 2 == 1) x = (x * a)% m;return x;}
//ll BigMod(ll B,ll P,ll M){ ll R=1%M; while(P>0) {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;} /// (B^P)%M

//ll getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1ll;}
//ll setBit1(ll num, int idx) {return num or (1ll<<idx);}
//ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
//ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}

const int mod = 1000000007;
const int N= 2005;

bitset<N*N>bi;


int main()
{
    
    int n; cin >> n;
    int sum = 0,x;
    bi[0] = 1;
    for(int i=1;i<=n;i++)
    {
        cin >> x; sum+=x;
        bi = bi|(bi<<x);
    }
    for(int i = (sum+1)>>1; ; i++)
    {
        if(bi[i])
        {
            cout<<i<<endl;return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main(){
	fastio();
	int x,y;
	cin>>x>>y;
	for(int i=0;i<=x;i++){
		if(i*2+(x-i)*4==y){
			cout<<"Yes";
			return 0;
		}
	}	
	cout<<"No";
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
    #define ll long long
    #define sz(a) int((a).size())
    #define fr(i,n) for(int i=0;i<n;i++) 
    #define rf(i,n) for(int i=1;i<=n;i++)
    #define jdb(i,v) for(__typeof(v.begin())i=v.begin(); i!=v.end();i++)
    #define present(c,a) (find(all(c),a) != c.end())
    #define spresent(c,a) (c.find(a)!=c.end())
    #define no(s,c) s.count(c)  
    #define pb push_back 
    #define eb emplace_back
    #define mp make_pair
    #define all(c) (c).begin(),(c).end()
    #define MAX INT_MAX 
    using namespace std;
    #define f first
    #define s second
    int M = 1000000007;
    bool x[1000001],y[1000001];
    int main() 
    { 
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        int n;
        cin>>n;
        map<int,int>map;
        int i=1;
        map[n]++;
        while(n>0)
        {
            if(n&1)
            {
                n=3*n+1;
                map[n]++;
                i++;
                if(map[n]>1)
                    {
                        cout<<i<<endl;
                        return 0;
                    }    
            }    
            else
                {
                    n=n/2;
                    map[n]++;
                    i++;
                    if(map[n]>1)
                    {
                        cout<<i<<endl;
                        return 0;
                    }    
                }        
        }
        return 0; 
    }

Measured memory_bytes: 256
#include <stdio.h>

int main () {
    int mo;
    int da;
    int sum = 0;
    int i;
    int array [13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    while (1) {
        scanf("%d %d",&mo, &da);
        sum = 0;
        if (mo == 0 && da == 0) {
            break;
        }
        for (i = 1; i < mo; i++) {
            sum += array[i];
        }
        sum += da;
        if (sum % 7 == 0) {
            printf("Wednesday\n");
        }
        else if (sum % 7 == 1) {
            printf("Thursday\n");
        }
        else if (sum % 7 == 2) {
            printf("Friday\n");
        }
        else if (sum % 7 == 3) {
            printf("Saturday\n");
        }
        else if (sum % 7 == 4) {
            printf("Sunday\n");
        }
        else if (sum % 7 == 5) {
            printf("Monday\n");
        }
        else if (sum % 7 == 6) {
            printf("Tuesday\n");
        }
    }
    return 0;
}

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


int main() {
    string S, ans;
    cin >> S;
    int S_a = stoi(S.substr(0,2));
    int S_b = stoi(S.substr(2,2));
    if (S_a >= 1 && S_a <= 12) {
        ans = "MM";
    }
    else {
        ans = "YY";
    }
    if (S_b >= 1 && S_b <= 12) {
        ans += "MM";
    }
    else {
        ans += "YY";
    }
    if (ans == "MMMM"){
        cout << "AMBIGUOUS" << endl;
    }
    else if (ans == "YYYY"){
        cout << "NA" << endl;
    }
    else {
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
const int SIZE=200001;
//int arr[SIZE]={};
//ここまでテンプレ
int main(){
	int N;
	cin>>N;
	char a[55],b[55];
	int c[55]={};
	cin>>a;
	cin>>b;
	for(int i=0,j=0;j<N;i++,j++){
		if(a[j]==b[j]){
			c[i]=1;
		}
		else{
			c[i]=2;
			j++;
		}
	}
	ll ans=3;
	for(int i=1;c[i]!=0;i++){
		if(c[i]==1 && c[i-1]==1){
			ans=ans*2%MOD;
		}
		else if(c[i]==1 && c[i-1]==2){

		}
		else if(c[i]==2 && c[i-1]==1){
			ans=ans*2%MOD;
		}
		else if(c[i]==2 && c[i-1]==2){
			ans=ans*3%MOD;
		}
	}
	if(c[0]==2)
		ans=ans*2%MOD;
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
import numpy as np

N,K = list(map(int,input().rstrip().split()))
S = list(input())
if S[0] == '0':
    zero_start = True
else:
    zero_start = False

N_normalized = [0,0,0] if zero_start else [0,0]
tmp = '0' if zero_start else '1'
cnt = 0
for i in range(len(S)):
    if tmp == S[i]:
        cnt += 1
        if i == len(S)-1:
            N_normalized.append(cnt)
    else:
        N_normalized.append(cnt)
        cnt = 1
        tmp = S[i]
        if i == len(S)-1:
            N_normalized.append(1)
N_normalized.append(0)
N_normalized.append(0)
N_normalized.append(0)

tmp = sum(N_normalized[0:K*2+1])
ans = tmp

if len(N_normalized)>K*2+1:
    for i in range(2, len(N_normalized)-(K*2+1), 2):
        tmp = tmp-N_normalized[i-1]-N_normalized[i-2]+N_normalized[i+K*2-1]+N_normalized[i+K*2]
        if ans < tmp:
            ans = tmp
else:
    ans = sum(N_normalized)

print(ans)

Measured memory_bytes: 14436