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

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define fst first
#define sc second
#define snd second
#define sz(X) (int)(X).size()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define fornr(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define forab(i, a, b) for(int i = int(a); i < int(b); i++)
#define forabr(i, a, b) for(int i = int(b)-1; i >= int(a); i--)
#define all(X) X.begin(), X.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ld;
typedef vector<int> vi;

const int N = 310;
const ll INF = 1e18;
ll dp[N][N][N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    n++;
    vector<ll> a(n + 1);
    forab(i, 1, n) cin >> a[i];
    forn(i, N) forn(j, N) forn(l, N) dp[i][j][l] = INF;
    dp[1][0][0] = 0;
    forab(i, 1, n) {
        forn(j, k + 1) {
            forn(l, i) {
                dp[i + 1][j][i] = min(dp[i + 1][j][i], dp[i][j][l] + max(a[i] - a[l], 0ll));
                if (j < k) {
                    dp[i + 1][j + 1][l] = min(dp[i + 1][j + 1][l], dp[i][j][l]);
                }
            }
        }
    }
    ll ans = INF;
    forn(j, k + 1) forn(l, n) ans = min(ans, dp[n][j][l]);
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 232960
n = int(input())
s = input()

max = 0
for k in range(n):
    alpha = ""
    for i in range(k):
        for j in range(k, n):
            if s[i] == s[j]:
                if alpha.find(s[i]) < 0:
                    alpha += s[i]
    if len(alpha) > max:
        max = len(alpha)
print(max)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define REP(i, k, n) for(long long i=(long long)(k); i<(long long)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define PQ(T) priority_queue<T>
#define PQS(T) priority_queue<T, vector<T>, greater<T> >
#define deci cout << fixed << setprecision(15);
typedef long long ll;
const ll inf = 1020304050607080910;
const int INF = 2000000000;
const ll mod = 998244353;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T> bool chmin(T&x,T y){if(x>y){x=y;return true;}return false;}
template<class T> bool chmax(T&x,T y){if(x<y){x=y;return true;}return false;}
ll gcd(ll x,ll y){if(x>y)swap(x, y);while(x!=0){y%=x;swap(x, y);}return y;}
ll mpow(ll x,ll r){if(r==0)return 1;if(r%2==1){return x*mpow(x,r-1)%mod;}else{ll aa=mpow(x,r/2);return aa*aa%mod;}}

int main(){
	ll N; cin >> N;
	ll c = 0;
	for(int i=1; i<=N; i++){
		c = c + (N-1)/i;
	}
	cout << c << endl;
	return 0;
}


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

int MOD=1000000007LL;
bool used[55][55][55][55];
int dp[55][55][55][55];

struct st{
  int n[4];
  st(){}
  st(int *a){
    for(int i=0;i<4;i++) n[i]=a[i];
  }
  st(int a0,int a1,int a2,int a3){
    n[0]=a0;n[1]=a1;n[2]=a2;n[3]=a3;
  }
};

signed main(){
  int n[4],m;
  for(int i=0;i<4;i++) cin>>n[i];
  cin>>m;
  cin.ignore();
  string s[m];
  for(int i=0;i<m;i++) getline(cin,s[i]);
  string key[m];
  vector<string> v[m];
  for(int i=0,j=0;i<m;i++,j=0){
    while(isalpha(s[i][j])) key[i]+=s[i][j++];
    j++;
    while(j<(int)s[i].size()){
      while(j<(int)s[i].size()&&s[i][j]==' ') j++;
      if(s[i][j]=='['){
	string t;
	j++;
	while(s[i][j]!=']') t+=s[i][j++];
	j++;
	v[i].push_back(t);
      }else{
	string t;
	while(j<(int)s[i].size()&&isalpha(s[i][j])) t+=s[i][j++];
	v[i].push_back(t);
      }
    }
  }
  map<string,int> ms;
  for(int i=0;i<m;i++) ms[key[i]]=i;
  
  int sum=0;
  for(int i=0;i<4;i++) sum+=n[i];
  //cout<<sum<<endl;
  
  int sz[m];
  
  for(int i=m-1;i>=0;i--){
    sz[i]=v[i].size();
    for(int j=0;j<(int)v[i].size();j++){
      if(islower(v[i][j][0])){
	int t=ms[v[i][j]];
	sz[i]+=sz[t]-1;
	if(sz[t]<=sum){
	  v[i].erase(v[i].begin()+j);
	  for(int k=0;k<sz[t];k++){
	    //cout<<v[t][k]<<endl;
	    v[i].insert(v[i].begin()+j+k,v[t][k]);
	  }
	}
      }
    }
    sz[i]=v[i].size();
  }

  /*//
  for(int i=0;i<m;i++){
    cout<<key[i]<<":";
    for(int j=0;j<sz[i];j++) cout<<" "<<v[i][j];
    cout<<endl;
  }
  //*/

  int ans=0;
  map<char,int> mc;
  mc['A']=0;
  mc['T']=1;
  mc['G']=2;
  mc['C']=3;
  
  for(int i=0;i<m;i++){
    //cout<<i<<"+"<<sz[i]<<endl;
    if(sz[i]!=sum) continue;
    memset(used,0,sizeof(used));
    memset(dp,0,sizeof(dp));
    queue<st> q;
    q.push(st(0,0,0,0));
    dp[0][0][0][0]=1;
    while(!q.empty()){
      st p=q.front();q.pop();
      int a[4],x=0;
      for(int j=0;j<4;j++) a[j]=p.n[j],x+=p.n[j];
      if(x==sum) break;
      //cout<<i<<"-"<<x<<":";
      //for(int j=0;j<4;j++) cout<<" "<<a[j];cout<<endl;
      for(int j=0;j<(int)v[i][x].size();j++){
	//cout<<j<<endl;
	int b[4];
	for(int k=0;k<4;k++) b[k]=a[k];
	if(b[mc[v[i][x][j]]]==n[mc[v[i][x][j]]]) continue;
	b[mc[v[i][x][j]]]++;
	(dp[b[0]][b[1]][b[2]][b[3]]+=dp[a[0]][a[1]][a[2]][a[3]])%=MOD;
	if(used[b[0]][b[1]][b[2]][b[3]]) continue;
	q.push(st(b));
	used[b[0]][b[1]][b[2]][b[3]]=1;
      }
    }
    (ans+=dp[n[0]][n[1]][n[2]][n[3]])%=MOD;
  }
  
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 86052
def solve(x):
    res = 0
    res += (x // 500) * 1000
    x = x % 500
    res += (x // 5) * 5
    return res


def main():
    x = int(input())
    res = solve(x)
    print(res)


def test():
    assert solve(1024) == 2020
    assert solve(0) == 0
    assert solve(1000000000) == 2000000000


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 2940
def solve():
    import sys
    input = sys.stdin.readline

    class FenwickTree:
        def __init__(self, size):
            self.size = size
            self.array = [0]*size
    
        def add(self, index, value):
            while index < self.size:
                self.array[index] += value
                index += index&(-index)
    
        def sum(self, index):
            answer = 0
            while index > 0:
                answer += self.array[index]
                index -= index&(-index)
            return answer
    
        def rangesum(self, start, end):
            return self.sum(end)-self.sum(start-1)


    N, Q = map(int, input().split())
    *c, = map(int, input().split())
    tree = FenwickTree(N+1)
    m = [tuple(map(int, input().split()))+(i,) for i in range(Q)]
    m.sort(key=lambda x:x[1])

    right = 0
    pos = [-1] * (N+1)
    ans = [-1] * (Q)

    for l, r, idx in m:
        for i in range(right, r):
            x = pos[c[i]]
            if x != -1:
                tree.add(x, -1)
            pos[c[i]] = i+1
            tree.add(i+1, 1)
        ans[idx] = tree.rangesum(l, r)
        right = r
    for i in ans:
        print(i)


solve()


Measured memory_bytes: 237256
#include<cstdio>
using namespace std;
#define N 22
int dp[1<<N][N],n,k,v[N],nt[N][2],ct,le,lg[1<<N];
char s[1<<N];
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=0;i<=n;i++)
	{
		scanf("%s",s);
		for(int j=0;j<1<<i;j++)
		dp[j|(1<<i)][0]=s[j]=='1';
	}
	for(int i=2;i<1<<n+1;i++)lg[i]=lg[i>>1]+1;
	for(int j=(1<<n+1)-1;j>=0;j--)
	{
		int le=lg[j];
		for(int k=1;k<=le;k++)v[k]=(bool)(j&(1<<k-1));
		nt[le][0]=nt[le][1]=-1;
		for(int k=le-1;k>=0;k--)
		{
			nt[k][0]=nt[k+1][0];nt[k][1]=nt[k+1][1];
			nt[k][v[k+1]]=k+1;
		}
		for(int k=0;k<=le;k++)
		if(dp[j][k])
		{
			dp[j&((1<<k)-1)][k+1]=dp[j&((1<<k)-1)][k+1]+dp[j][k];
			if(nt[k][0]!=-1)dp[(j&((1<<k)-1))|(j>>(nt[k][0]-1)<<k)][k+1]=dp[(j&((1<<k)-1))|(j>>(nt[k][0]-1)<<k)][k+1]+dp[j][k];
			if(nt[k][1]!=-1)dp[(j&((1<<k)-1))|(j>>(nt[k][1]-1)<<k)][k+1]=dp[(j&((1<<k)-1))|(j>>(nt[k][1]-1)<<k)][k+1]+dp[j][k];
		}
	}
	for(int l=n;l>=1;l--)
	for(int j=0;j<1<<l;j++)
	if(dp[j][l+1]>=k)
	{
		for(int i=l;i>=1;i--)printf("%d",(bool)(j&(1<<i-1)));
		return 0;
	}
}//orzzyw

Measured memory_bytes: 193792
#include<iostream>
using namespace std;
long long raika(int n){
    long long box[100];
    box[0]=2; 
    box[1]=1;
    if (n>=2){
        for (int i=2;i<=n;i++){
            box[i]=box[i-1]+box[i-2];
        }
    }
return box[n];
    
}
int main(){
    int a;
    cin>>a;
    cout<<raika(a)<<endl;
}

Measured memory_bytes: 256
//Om Sree Sai Ram
#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
using namespace std;
vector<int> dp;



int main() 
{

  
 int n,W;
 cin>>n>>W;
 vector<long long> dp(W+1);
 //dp[i] represents maximum value obtained with exactly i amount of weight
 //j means weight already there in the knapsack
 dp[0] = 0;
 for(int i=0;i<n;i++)
 {
  int weight,value;
  cin>>weight>>value;
  for(int j=W-weight;j>=0;j--)
  {
    dp[j+weight] = max(dp[j+weight],dp[j]+value); 
  }
 }
 cout<<*max_element(dp.begin(),dp.end())<<endl;
}


Measured memory_bytes: 1024
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <iomanip>
#include <bitset>

using namespace std;

typedef long long ll;

mt19937 rnd(228);

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
    int n, a, b;
    cin >> n >> a >> b;
    if (a * (ll) b < n || a + b > n + 1)
    {
        cout << -1 << '\n';
        return 0;
    }
    bool rev = false;
    if (b < a)
    {
        swap(b, a);
        rev = true;
    }
    int l = 0, r = n + 1;
    while (l < r - 1)
    {
        int m = (l + r) / 2;
        int ret = (n - m) / b + bool((n - m) % b);
        if (ret + m <= a)
        {
            l = m;
        }
        else
        {
            r = m;
        }
    }
    int x = l;
    n -= x;
    int init_n = n + x;
    vector <int> arr;
    vector <int> kek;
    for (int i = n; i < init_n; i++)
    {
        kek.push_back(i);
    }
    for (int i = 0; i < n; i += b)
    {
        int en = min(n - 1, i + b - 1);
        for (int j = en; j >= i; j--)
        {
            arr.push_back(j);
        }
    }
    if (!kek.empty()) for (int x : kek) arr.push_back(x);
    kek.clear();
    if (rev) reverse(arr.begin(), arr.end());
    for (int v : arr)
    {
        cout << v + 1 << ' ';
    }
    cout << '\n';
}


Measured memory_bytes: 4080
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int INF = 2e6;
ll MOD = 1e9 + 7;

int main(){
    vector<int> a(3);
    rep(i,3) cin >> a[i];
    sort(a.begin(),a.end());

    int b, c; 
    b = a[2] - a[0]; c = a[2] - a[1];
   
    if((b - c) % 2 == 0){
        cout << c + (b - c) / 2 << endl;
        return 0;
    }

    cout << c + (b - c) / 2 + 2 << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    long long r,d,x[100];
    cin>>r>>d>>x[0];
    for(int i=1;i<=10;i++)
    {
        x[i]=x[i-1]*r-d;
        cout<<x[i]<<endl;
    }
    return 0;
}

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

int main()
{
    int n, ce, cw;
    string s;
    cin >> n >> s;
    ce = cw = 0;
    for(auto c: s){
        if(c == 'E') ce++;
    }
    cw = n-ce;
    int leftw[n+1] = {};
    int righte[n+1] = {};
    leftw[0] = 0;
    for(int i = 0; i<n; i++){
        if(s[i] == 'E'){
            leftw[i] = i==0? 0: leftw[i-1];
            righte[i] = ce-(i+1-leftw[i]) +1;
        }else{
            leftw[i] = i==0? 1: leftw[i-1] +1;
            righte[i] = ce-(i+1-leftw[i]);
        }
        // cout << i <<s[i] <<  " :" << leftw[i] << " ," << righte[i]<< endl;
    }
    int ans = 1e9;
    for(int i =0; i<n; i++){
        ans = min(ans, leftw[i] + righte[i]);
    }
    cout << ans-1 << endl;
    return 0;
}

Measured memory_bytes: 2948
#ABC124 B
N = int(input())
H = list(map(int, input().split()))
ans = 1
for i in range(N):
    if i==0:
        pass
    else:        
        i_bool = True
        for j in range(1,i+1):
            if H[j-1] > H[i]:
                i_bool = False
        if i_bool:
            ans+=1
print(ans)                    

Measured memory_bytes: 3060
import numpy as np
from collections import defaultdict
from itertools import combinations

# s = input()
N, D = map(int, input().split())

X = []
for n in range(N):
  x = list(map(int, input().split()))
  X.append(x)

res = 0
for i, j in combinations(range(N),2):
  dist = 0
  for d in range(D):
    delta = X[i][d] - X[j][d]
    dist += delta**2

  if np.sqrt(dist) == int(np.sqrt(dist)):
    res += 1

print(res)


Measured memory_bytes: 13664
#include <bits/stdc++.h>
using namespace std;
using i64=int_fast64_t;
using pii=pair<int,int>;
#define fir first
#define sec second
#define all(v) begin(v),end(v)

struct UnionFind {
    vector<int> par,siz;
    vector<bool> cyc;
    int root_cnt;
 
    UnionFind(int n) : root_cnt(n) { init(n); }
 
    void init(int n) {
        par.resize(n);
        siz.assign(n,1);
        cyc.assign(n,false);
        for(int i = 0; i < n; ++i) par[i] = i;
    }
 
    int find(int x) {
        if(par[x] == x) return x;
        int r = find(par[x]);
        return par[x] = r;
    }
 
    int size(int x) { return siz[find(x)]; }

    bool is_cyclic(int x) { return cyc[find(x)]; }
 
    bool is_same(int x, int y) { return find(x) == find(y); }
 
    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        if(x == y) {
            cyc[x] = true;
            return false;
        }
        if(siz[x] < siz[y]) swap(x,y);
        siz[x] += siz[y];
        par[y] = x;
        --root_cnt;
        cyc[x] = cyc[x] || cyc[y];
        return true;
    }
};


int n,m;

int solve() {
    int ans=0;
    int h[252];
    bool exi[252]={};
    vector<pii> g[251];
    for(int i=0; i<n; ++i) {
        cin>>h[i];
    }
    for(int i=0; i<m; ++i) {
        int a,b,c;
        cin>>a>>b>>c;
        a--,b--;
        g[a].emplace_back(b,c);
        g[b].emplace_back(a,c);
    }

    vector<pii> vrt;
    for(int i=0; i<n; ++i) vrt.emplace_back(h[i],i);
    sort(all(vrt),greater<pii>());

    vector<int> clck(h,h+n);
    clck.emplace_back(0);
    sort(all(clck));

    int las=1e7;
    UnionFind uff(n);
    
    for(int i=0,j=0; i<n; i=j) {
        while(j<n && vrt[i].fir==vrt[j].fir) {
            int v=vrt[j].sec;
            exi[v]=true;
            for(auto &e:g[v]) {
                if(exi[e.fir]) {
                    uff.unite(v,e.fir);
                }
            }
            ++j;
        }
        if(uff.root_cnt!=n-j+1) {
            las=vrt[i].fir;
        }
    }
    
    vector<tuple<int,int,int>> edg;
    UnionFind uf(n);
    fill(all(exi),false);
    for(int i=0, j=0; i<n; i=j) {
        while(j<n && vrt[j].fir==vrt[i].fir) {
            int v=vrt[j].sec;
            exi[v]=true;
            for(pii &e:g[v]) {
                if(exi[e.fir]) {
                    edg.emplace_back(e.sec,e.fir,v);
                }
            }
            ++j;
        }
        if(las>vrt[i].fir) {
            sort(all(edg));
            for(auto &e:edg) {
                int u,v,c; tie(c,u,v)=e;
                if(uf.unite(u,v)) {
                    ans+=c;
                }
            }
            edg.clear();
        }
    }
    return ans;
}

signed main() {
    //freopen("stderr.txt","wt",stderr);
    while(cin>>n>>m,n) {
        cout<<solve()<<endl;
    }
}


Measured memory_bytes: 3972
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
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;}
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

int H,W,N;
int S[10010];
int grid[110][110];

int main() {
    scanf("%d%d%d",&H,&W,&N);
    REP(i,N) scanf("%d",&S[i]);
    vector<int> num;
    REP(i,N){
        REP(j,S[i]){
            num.push_back(i+1);
        }
    }

    REP(i,H){
        REP(j,W){
            if(i&1) cout << num[i*W + W-j-1] << " ";
            else cout << num[i*W + j] << " ";
        }
        cout << endl;
    }

    return 0;
}

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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
#define db(x) cerr << #x << " = " << (x) << ", ";
#define endln cerr << "\n";
#define chkpt cerr << "-----\n";

void solve() {
    int a, b, c; cin >> a >> b >> c;
    FOR(it, 0, 100000) {
        if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1) {
            cout << it << "\n";
            return;
        }
        int x = a + b >> 1, y = b + c >> 1, z = c + a >> 1;
        a = x, b = y, c = z;
    }
    cout << -1 << "\n";
}

int main() {
    int JUDGE_ONLINE = 1;
    if (fopen("in.txt", "r")) {
        JUDGE_ONLINE = 0;
        assert(freopen("in.txt", "r", stdin));
        //assert(freopen("out.txt", "w", stdout));
    }
    else {
        ios_base::sync_with_stdio(0), cin.tie(0);
    }
    solve();
    if (!JUDGE_ONLINE) {
        //cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e9
#define N 510
#define MAX_V N
using namespace std;
typedef map<int,int> M;
M g[N];
bool used[MAX_V];      //DFS??§?????§??????????????????????????°

int dfs(int v,int t,int f){
  if(v == t)return f;
  used[v]=true;
  
  for(M::iterator it=g[v].begin();it!=g[v].end() ;it++){
    int to=it->first;
    int &cap=it->second;
    if(!used[to] && cap > 0){
      int d = dfs(to ,t , min(f,cap));
      if(d > 0){
	cap -= d;
	g[to][v]+=d;
	return d;
      }
    }
  }
  return 0;
}

int max_flow(int s,int t){
  int flow = 0;
  for(;;){
    memset(used,0,sizeof(used));
    int f = dfs(s, t, INF);
    if(f == 0)return flow;
    flow += f;
  }
}

bool check(int s,int t){
  memset(used,0,sizeof(used));
  return dfs(s,t,1);
}

int main(){
  int n,m,q;
  cin>>n>>m>>q;
  for(int i=0,a,b;i<m;i++){
    cin>>a>>b;a--,b--;
    g[a][b]=g[b][a]=1;
  }
  
  int flow=max_flow(0,n-1);
  while(q--){
    int op,a,b;
    cin>>op>>a>>b;a--,b--;
    if(op==1) g[a][b]=g[b][a]=1,flow+=max_flow(0,n-1);
    if(op==2){
      if(!g[a][b]||!g[b][a]){
	if(!g[b][a])swap(a,b);
	if(!check(a,b))flow--,check(a,0),check(n-1,b);
      }
      g[a][b]=g[b][a]=0;
    }
    cout <<flow<<endl;
  }
  
  return 0;
}

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

using namespace std;

int main(void){
//string S;
int N;
int flag = 0;
cin >> N;
vector<int> a(N);

for(int i = 0; i < N; i++){
  cin >> a[i];
}

/*for(int i = 0; i < 2; i++){
  cin >> N[i];
}*/

sort(a.begin(), a.end());

int prea = a[0];
for(int i=1; i < a.size(); i++){
  if(prea == a[i]) flag = 1;
  prea = a[i];
}
if(flag == 0){
  cout << "YES" << endl;
}else{
  cout << "NO" << endl;
}

return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N; string S;
int R = 1, G = 2, B = 4;
int RGB = 7;
int cnt[8];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> S;
	fore(c, S) {
		if (c == 'R') c = R;
		else if (c == 'G') c = G;
		else c = B;
	}

	int r = 0, g = 0, b = 0;
	ll ans = 0;
	rep(j, 0, N) {
		rep(k, j + 1, N) {
			if (S[j] == S[k]) continue;

			int Si = RGB - S[j] - S[k];
			ans += cnt[Si];

			int i = j - (k - j);
			if (0 <= i) {
				int msk = S[i] | S[j] | S[k];
				if (msk == RGB) ans--;
			}
		}

		cnt[S[j]]++;
	}
	cout << ans << endl;
}







Measured memory_bytes: 3604
n=int(input())
X=[]
Y=[]
#P=np.ndarray((0,2))
for i in range(n):
    x,y = map(int,input().split())
    X.append(x+y)
    Y.append(x-y)

    
ans = max(max(X)-min(X),max(Y)-min(Y))

print(ans)
    

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

int main() {
    int N, G = 0;

    cin >> N;
    vector<int> Val(N);
    vector<int> Cos(N);

    for (int i = 0; i < N; i++){
        cin >> Val[i];
    }

    for (int i = 0; i < N; i++){
        cin >> Cos[i];

        if (Val[i] > Cos[i]){
            G = G + Val[i] - Cos[i];
        }
    }

    cout << G << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define mp(a, b) make_pair(a, b)
const int maxn = 2e5 + 10; 
int main()
{
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(max(a * c, b * d), max(a * d, b * c)) << endl;
	return 0;
}

Measured memory_bytes: 3628
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		Map<String,String> map = new HashMap<String,String>();
		map.put("A", "T");
		map.put("T", "A");
		map.put("C", "G");
		map.put("G", "C");

		System.out.println(map.get(sc.next()));


	}

}

Measured memory_bytes: 22612
/* Your prologue will be the story. */
/* Copyright by HenryLi */
#include<iostream>
#include<algorithm>
#include<queue>
#include<string>
#include<map>
#include<vector>
#include<set>
#include<sstream>
#include<stack>
#include<ctime>
#include<cmath>
#include<cctype>
#include<climits>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<iomanip>
#include<bitset>
#include<complex>
using namespace std;
template <class _T> inline void read(_T &_x) {
	int _t; bool _flag=false;
	while((_t=getchar())!='-'&&(_t<'0'||_t>'9')) ;
	if(_t=='-') _flag=true,_t=getchar(); _x=_t-'0';
	while((_t=getchar())>='0'&&_t<='9') _x=_x*10+_t-'0';
	if(_flag) _x=-_x;
}
typedef long long LL;
const int maxn = 200010;
int n, a[maxn];
set<int> s;
int main() {
	//freopen("C.in","r",stdin);
	//freopen("C.out","w",stdout);
	read(n);
	for (int i = 1; i <= n; ++i) {
		read(a[i]);
		if (a[i] >= i || a[i] - a[i - 1] > 1) {
			puts("-1");
			return 0;
		}
	}
	LL ans = 0;
	for (int i = n; i >= 1; --i) {
		if (s.find(a[i] - i) != s.end()) continue;
		s.insert(a[i] - i);
		ans += a[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 10368
px = ((0,0,-1,1), (-1,-1,1,1), (0,0,-2,2))
py = ((-1,1,0,0), (-1,1,-1,1), (-2,2,0,0))

p = [[0]*14 for i in range(14)]

while True:
    try:
        x,y,s = map(int,raw_input().split(','))
        x += 2
        y += 2
        p[x][y] += 1
        for i in range(s):
            for j in range(4):
                p[x+px[i][j]][y+py[i][j]] += 1
    except EOFError:
        break
p = [a[2:-2] for a in p[2:-2]]
print sum([a.count(0) for a in p])
print max([max(a) for a in p])

Measured memory_bytes: 4280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
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; }
const long long INF = 1LL << 60;
long long dp[100010];
long long h[100010];

int main()
{
    int n, a; cin >> n;
    map<ll, ll> ma;
    Rep(i, 1, n + 1)
    {
        cin >> a;
        ma[a]++;
    }

    ll ans = 0;
    for (auto x : ma)
    {
        if (x.second % 2 != 0)
            ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6528
#include<iostream>
#include<vector>
#define ll unsigned long long
using namespace std;

int main(){
    ll X, i=0;
    ll m = 100;
    cin >> X;
    // cout << X;
    while(m < X){
        m = m * 1.01;
        i++;
    }
    cout << i << endl;
}

Measured memory_bytes: 3544
#include <iostream>
#include<string>
#include<cmath>
#include<ciso646>
#include<cstring>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<math.h>

using ll = long long;
int M = 100100100;
using namespace std;
int main()
{
	
	int n, k;
	int sum = 0;
	cin >> n >> k;
	vector<int> aa(n);
	for (int i = 0;i < n;i++)
		cin >> aa[i];

	sort(aa.begin(), aa.end());
	for (int i = 0;i < k;i++)
		sum += aa[i];
	cout << sum;


	
	
}

Measured memory_bytes: 3628
n = int(input())
A = [int(input()) for i in range(n)]

minv = A[0]
maxv = A[1] - A[0]
for j in range(1, n):
    if maxv < A[j] - minv:
        maxv = A[j] - minv
    if minv > A[j]:
        minv = A[j]
print(maxv)


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

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

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>
T GCD(T a, T b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}
template<class T>
T LCM(T a, T b) {
	return a / GCD(a, b) * b;
}
template<class T>
inline T round_int(T a, T b) {return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

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

	vi a(n);
	rep(i, n) cin >> a[i];

	int now = 0, cnt = 0;
	rep(i, n + 1) {
		int next = a[now];
		
		if (next == 2) {
			cout << i + 1 << endl;
			return 0;
		}
		next--;
		now = next;
	}
	cout << -1 << endl;
}

Measured memory_bytes: 640
import scala.io.StdIn.readInt

object Main extends App {
  println {
    Iterator.continually(readInt).takeWhile(_ != -1).map { w =>
                val w3 = if(w>30) w-30 else 0
      val w2 = if(w>20) w - w3 -20 else 0
      val w1 = if(w>10) w - w3 - w2 - 10 else 0
      4280 - (1150 + w1*125 + w2*140 + w3*160)
    }.mkString("\n")
  }
}

Measured memory_bytes: 44016
N = int(input())
A = list(map(int,input().split()))

def argsort(seq):
    return sorted(range(len(seq)), key=seq.__getitem__)

# Aを昇順arg sort
ans = argsort(A)

# すべてに1を足す
ans = [x+1 for x in ans]

print(*ans)

Measured memory_bytes: 14928
#include <iostream>

using namespace std;

int main() {
    int a, b; cin >> a >> b;
    int total{1}, cnt{0};
    while (total < b) {
        cnt++;
        // extend to a new power strip by adding a and subtract 1
        total = total + a - 1;
    }
    
    cout << cnt << endl;
}

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

int c[33], s[444][33];
int sco(int t, const vector<int> &v) {
    int r = 0, l = 0, d = v.size();
    for(int i = 0; i < d; i++)
        if(v[i] == t)
            r += s[i][t] - c[t] * (i + 1 - l) * (i - l) / 2, l = i + 1;
    r -= c[t] * (d + 1 - l) * (d - l) / 2;
    return r;
}
int main() {
    auto ti = clock();
    int d;
    cin >> d;
    for(int i = 0; i < 26; i++)
        cin >> c[i];
    for(int i = 0; i < d; i++)
        for(int j = 0; j < 26; j++)
            cin >> s[i][j];
    vector<int> ss, tt;
    int M = -1e9;
    for(int a = 10; a < 16; a++) {
        for(int b = 0; b < 4; b++) {
            for(int z = 5; z < 16; z++) {
                int r = 0, l[33] = {};
                ss.clear();
                for(int i = 0; i < d; i++) {
                    auto m = 0.;
                    int t = 0;
                    for(int j = 0; j < 26; j++) {
                        double p = s[i][j];
                        p += c[j] * (i + 1 - l[j]) * .4 * a;
                        for(int k = 1; k < z; k++)
                            if(i + k < d)
                                p -= s[i + k][j] * (z - k) * .05 / z * b;
                        if(p > m)
                            m = p, t = j;
                    }
                    ss.push_back(t);
                    r -= c[t] * (i + 1 - l[t]) * (i - l[t]) / 2;
                    l[t] = i + 1;
                    r += s[i][t];
                }
                for(int j = 0; j < 26; j++)
                    r -= c[j] * (d + 1 - l[j]) * (d - l[j]) / 2;
                if(r > M)
                    M = r, tt.swap(ss);
            }
        }
    }
    random_device rd;
    mt19937 mt(rd());
    uniform_int_distribution<> rc(0, 25), r0(0, d - 1), r2(1, 6);
    uniform_real_distribution<> ru(0, 1);
    int cnt = 0;
    for(;;) {
        auto T = (clock() - ti + 0.) / CLOCKS_PER_SEC;
        if(T > 1.9)
            break;
        auto U = pow(2e3, 1 - T / 1.9) * pow(6e2, T / 1.9);
        for(int cn = 0; cn < 100; cn++, cnt++) {
            auto uu = tt;
            int di;
            if(rc(mt) < 12) {
                int x0 = r0(mt), xc = rc(mt);
                uu[x0] = xc;
                di = sco(tt[x0], uu) + sco(xc, uu) - sco(tt[x0], tt) -
                     sco(xc, tt);
            } else {
                int x2 = r2(mt);
                uniform_int_distribution<> r1(0, d - 1 - x2);
                int x1 = r1(mt);
                x2 += x1;
                swap(uu[x1], uu[x2]);
                di = sco(tt[x1], uu) + sco(tt[x2], uu) - sco(tt[x1], tt) -
                     sco(tt[x2], tt);
            }
            if(ru(mt) <= exp(di / U))
                tt.swap(uu);
        }
    }
    M = 0;
    for(int j = 0; j < 26; j++)
        M += sco(j, tt);
    for(int i : tt)
        cout << i + 1 << '\n';
    cerr << M << endl;
    cerr << cnt << endl;
    return 0;
}


Measured memory_bytes: 4324
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define debug(x) cerr << #x " = " << (x) << endl;
#define P(x) cerr << #x << endl;    
typedef long long ll;
#define int long long
const int mod = 1000000007;


int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << fixed << setprecision(9);
    
    
    int n;
    cin >> n;
    
    vector<int> a(n + 1);
    vector<int> b(n + 1);
    vector<int> c(n);
    
    for(int i = 1; i <= n; ++ i)
    {
        cin >> a[i];
    }
    for(int i = 1; i <= n; ++ i)
    {
        cin >> b[i];
    }
    for(int i = 1; i <= n - 1; ++ i)
    {
        cin >> c[i];
    }
    int sum = 0;
    vector<int> vec;
    for(int i = 1; i <= n; ++ i)
    {
        sum += b[a[i]];
        vec.push_back(a[i]);
    }
    
    for(int i = 0; i < vec.size() - 1; ++ i)
    {
        if(vec[i + 1] == vec[i] + 1)
            sum += c[vec[i]];
    }
    
    cout << sum << endl;
    
    return 0;
}






Measured memory_bytes: 256
// AtCoder ABC135: A - Harmony
// 2019.8.26 bal4u

#include <stdio.h>
 
int main()
{
	int a, b;
	
	scanf("%d%d", &a, &b);
	if ((a+b) & 1) puts("IMPOSSIBLE");
	else printf("%d\n", (a+b)>>1);
	return 0;
}

Measured memory_bytes: 128
N = int(input())
S = [0] + [s for s in input()]
W_nums = [0 for _ in range(N+2)]
E_nums = [0 for _ in range(N+2)]

for idx in range(1, N+1):
  if S[idx] == 'W': W_nums[idx]  = W_nums[idx-1] + 1
  else: W_nums[idx]  = W_nums[idx-1]

for idx in range(N, 0, -1):
  if S[idx] == 'E': E_nums[idx]  = E_nums[idx+1] + 1
  else: E_nums[idx]  = E_nums[idx+1]

print(min([W_nums[i-1] + E_nums[i+1] for i in range(1,N+1)]))

Measured memory_bytes: 98916
#include <stdio.h>

int main() {
    int n, max = -1000000, min = 1000000;
    long int sum = 0;
    scanf("%d", &n);
    int num[n];
    for (int i=0; i<n; i++) {
        scanf("%d", &num[i]);
        if (num[i] > max) {max = num[i];}
        if (num[i] < min) {min = num[i];}
        sum += num[i];
    }
    printf("%d %d %ld\n", min, max, sum);
    return 0;
}



Measured memory_bytes: 2112
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int ll;
int main(){
int n,t,a;
cin >> n;
cin >> t>>a;
int h;
double k[n];
for(int i=0;i<n;i++) {
  cin >>h;
  k[i]=(double)(t-h*0.006);
  k[i]=k[i]-a;
  if(k[i]<0) k[i]=-k[i];
}
double ans=k[0];
int sum=0;
for(int i=1;i<n;i++){
  if(k[i]<ans) {
    ans=k[i];
    sum=i;
  }
}
cout <<sum+1<<endl;
}


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

int main() {
    int n;
    cin>>n;
    if(n==1){
        cout << "Hello World" << endl;
    }else{
        int a,b;
        cin>>a>>b;
        cout << a+b << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,a,cnt=0;
    set<int>st;
    cin>>n;
    while(cin>>a)
        if(a<3200)
            st.insert(a/400);
        else
            cnt++;
    cout<<max(1,int(st.size()))<<' '<<st.size()+cnt<<endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

const int MAX = 1e5;
int A[MAX + 1], B[MAX + 1];

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int a, b, m;
    cin >> a >> b >> m;
    int minA = 1e9;
    for (int j = 1; j <= a; ++j) {
        cin >> A[j];
        minA = min(minA, A[j]);
    }

    int minB = 1e9;
    for (int j = 1; j <= b; ++j) {
        cin >> B[j];
        minB = min(minB, B[j]);
    }

    int ans = minA + minB;
    int x, y, z;
    for (int i = 1; i <= m; ++i) {
        cin >> x >> y >> z;
        ans = min(ans, A[x] + B[y] - z);
    }

    cout << ans;


    return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_H 1010
#define MAX_W MAX_H

ll H, W;
vector<string> A;

ll dp[MAX_H][MAX_W];

// A[i][j] にいるときのパターン数
ll dfs(ll i = 0, ll j = 0) {
    if(i == H-1 && j == W-1) { return 1; }

    ll& ret = dp[i][j];
    if(~ret) { return ret; }
    ret = 0;

    // 下へ行く
    if(i != H-1 && A[i+1][j] == '.') {
        ret += dfs(i+1, j);
        ret %= MOD;
    }
    // 右へ行く
    if(j != W-1 && A[i][j+1] == '.') {
        ret += dfs(i, j+1);
        ret %= MOD;
    }

    return ret;
}

signed main()
{
    cin >> H >> W;
    A.assign(H, "");
    REP(i, H) { cin >> A[i]; }
    MINUS(dp);
    printf("%lld\n", dfs());
    return 0;
}


Measured memory_bytes: 9344
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

vector<ll>path[10101];
ll ans[10101];

int main(){
    ll N;
    cin >> N;
    ll sum = 0, mx = 0;
    for(ll i = 1; i < N; i++){
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        path[a].push_back(b);
        path[b].push_back(a);
    }
    vector<ll>v(N);
    for(ll i = 0; i < N; i++){
        cin >> v[i];
        sum += v[i];
        mx = max(mx, v[i]);
    }
    sort(v.begin(), v.end(), greater<ll>());
    queue<ll>Q;
    Q.push(0);
    for(int cnt = 0; !Q.empty();){
        ll idx = Q.front();
        Q.pop();
        ans[idx] = v[cnt];
        cnt++;
        for(ll i = 0; i < path[idx].size(); i++){
            ll nxt = path[idx][i];
            if(ans[nxt])continue;
            Q.push(nxt);
        }
    }
    cout << sum - mx << endl;
    for(ll i = 0; i < N; i++){
        cout << ans[i];
        if(i+1==N)cout << endl;
        else cout << " ";
    }
    return 0;
}


Measured memory_bytes: 1152
if __name__ == '__main__':
    n = int(input())
    arr = []
    for i in range(1, n + 1):
        inp = input().split(' ')
        arr.append({'n': int(i), 's': inp[0], 'p': int(inp[1])})
    _sorted = sorted(arr, key = lambda x: (x['s'], -x['p']))
    for item in _sorted:
        print(item['n'])


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main() {
    int h,w,a,b;
    cin>>h>>w>>a>>b;
    int ans[h][w];
    rep(i,b){
        rep(j,a){
            ans[i][j]=0;
        }
        for(int j=a;j<w;j++){
            ans[i][j]=1;
        }
    }
    for(int i=b;i<h;i++){
        rep(j,a){
            ans[i][j]=1;
        }
        for(int j=a;j<w;j++){
            ans[i][j]=0;
        }
    }

    rep(i,h){
        rep(j,w){
            cout<<ans[i][j];
        }
        cout<<endl;
    }
}



Measured memory_bytes: 5120
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int64 INF = 1LL << 60;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

const int N = 2e5 + 10;
int64 a[N];
int64 dp[N][3];
bool visit[N][3];
int n;

int64 solve(int pos, int rem) {
  if (pos >= n) return rem == 2 ? -INF : 0;
  int64& ret = dp[pos][rem];
  if (visit[pos][rem]) return ret;
  visit[pos][rem] = true;
  ret = -(1LL << 60);
  for (int i = 0; i <= rem && pos + i < n; ++i) {
    ret = max(ret, a[pos + i] + solve(pos + i + 2, rem - i));
  }
  // trace(pos, rem, ret);
  return ret;
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%lld", &a[i]);
  }
  memset(visit, 0, sizeof(visit));
  int64 ret = solve(0, n % 2 + 1);
  printf("%lld\n", ret);
  return 0;
}


Measured memory_bytes: 20004
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  int N;
  cin >> N;
  vector<int> a(N);
  REP(i, N)
  cin >> a[i];
  ll ans = 0;
  REP(i, N)
  ans += 1ll * (a[i] - 1);
  cout << ans << endl;
  return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> count(N,0);
  
  for (int x=1;x<sqrt(N);x++){
    for (int y=x;y<sqrt(N);y++){
      for (int z=y;z<sqrt(N);z++){
        for (int i=0;i<N;i++)
          if ( (pow(x+y+z,2)-(x*y+y*z+z*x))==i+1 )
            if (x==y && y==z)
              count.at(i)+=1;
        	else if (x==y || y==z)
              count.at(i)+=3;
        	else
              count.at(i)+=6;
      }
    }
  }
  for (int i=0;i<N;i++)
    cout << count.at(i) << endl;
}

Measured memory_bytes: 3760
#include <iostream>  // cin,cout
#include <stdio.h>   // printf,scanf (standard input/output)
#include <cmath>     // abs(x),pow(x,2)
#include <string>
#include <string.h>  // strlen, strcmp
#include <algorithm> // min,max, sort(v.begin(),v.end())
#include <vector>
#include <time.h>
using namespace std;

long long result = 0;
long long H[50], P[50];

int Func(int N, long long X){
    if (N==0) {
        if (X==0) return 0;
        else if (X==1) {
            result += 1;
            return 0;
        }
    }
    else {
        if (X==1) return 0;
        if (2<=X and X<=H[N-1]+1) Func(N-1, X-1);
        if (X==H[N-1]+2) {
            result += P[N-1] + 1;
            return 0;
        }
        if (H[N-1]+2<X and X<=2*H[N-1]+2) {
            result += P[N-1] + 1;
            Func(N-1, X-H[N-1]-2);
        }
        if (X==2*H[N-1]+3) {
            result += 2*P[N-1] + 1;
            return 0;
        }
    }
}

int main(){
    int N;
    long long X;
    
    cin >> N;
    cin >> X;
    
    H[0] = 1;
    P[0] = 1;
    for (int i=1;i<N;i++) {
        H[i] = 2*H[i-1]+3;
        P[i] = 2*P[i-1]+1;
    }
    
    Func(N, X);
    cout << result << endl;
    
    return 0;
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define PB push_back
#define MP make_pair
#define SORT(c) sort((c).begin(),(c).end())
#define COUT(x) cout<<x<<endl

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

//constant
//--------------------------------------------
const double PI = acos(-1.0);
const LL MOD = 1e9 + 7;
const ULL INF= 1e18;
const int dx[]{ 1,-1,0,0 }, dy[]{ 0,0,1,-1 };

//function
//--------------------------------------------
LL gcd(LL, LL);
bool isEven(LL);
void coutY();
void coutN();

int main() {
	LL a, b, c; cin >> a >> b;
	COUT(max({ a + b,a - b,a * b }));
}

LL gcd(LL a, LL b) {
	if (a == 0 || b == 0)return 0;
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	else gcd(b, a % b);
}
bool isEven(LL a) {
	return !((bool)(a % 2));
}
void coutY() {
	cout << "Yes" << endl;
	return;
}
void coutN() {
	cout << "No" << endl;
	return;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
int n,cons=1000000007,t;
signed main(){
	//cin>>t;while(t--){
	cin>>n;
	int ans1=1,ans8=1,ans9=1;
	for(int i=1;i<=n;i++){
		ans1=(ans1*10)%cons;
		ans8=(ans8*8)%cons;ans9=(ans9*9)%cons;
	}
	ans9=(ans9*2)%cons;
	ans1=(ans1-ans9+ans8+cons)%cons;
	cout<<ans1<<endl;
} 

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b && b==c)
        cout<<"No"<<endl;
    else if(a!=b && b!=c && c!=a)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;
}


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

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    rep(i,h){
        rep(j,2) cout << s[i] << endl;
    }
    return 0;
}

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

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

  int n; cin >> n;
  map<int, int> mp1, mp2;
  for (int i = 0; i < n; i++) {
	int v; cin >> v;
	(i % 2 == 0 ? mp1[v]++ : mp2[v]++);
  }
  int a = 0, b = 0, c = 0, d = 0;
  int mx1 = 0, mx2 = 0;
  for (int i = 1; i <= 100000; i++) {
	if (mp1[i] >= a) {
	  b = a;
	  a = mp1[i];
	  mx1 = i;
	}
	if (mp2[100000 - i] >= c) {
	  d = c;
	  c = mp2[100000 - i];
	  mx2 = 100000 - i;
	}
  }
  if (mx1 != mx2) cout << n - a - c << endl;
  else {
	cout << min(n - a - d, n - b - c) << endl;
  }
  return 0;
}



Measured memory_bytes: 9984