akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

int main(){
  int n, m;
  cin >> n >> m;
  int max = 1, min = 0;
  for(int i = 0; i < n; i++){
    max *= 10;
  }
  if(n == 2)
    min = 10;
  else if(n == 3)
    min = 100;
  
  string ans = "-1";
  vector<pair<int, char>> vec(m);
  for(int i = 0; i < m; i++){
    int s; cin >> s;
    s--;
    char c; cin >> c;
    vec[i] = make_pair(s,c);
  }
  
  for(int i = min; i < max; i++){
    bool check = true;
    string num = to_string(i);
    for(int j = 0; j < m; j++){
      if(num[vec[j].first] != vec[j].second){
        check = false;
        break;
      }
    }
    if(check){
      ans = num;
      break;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
use std::io::{ self, Write };
use std::str::FromStr;
use std::cmp::{ min, max };
use std::collections::{ BinaryHeap, VecDeque };

macro_rules! trace {
    ($var:expr) => ({
        let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($var), $var);
    })
}
macro_rules! swap { ($a:expr, $b:expr) => ({ let t = $b; $b = $a; $a = t; }) }

fn main() {
    let mut sc = Scanner::new();
    let mut n = 0;
    let mut m = 0;
    for c in sc.cin::<String>().chars() {
        if c == 'S' {
            n += 1;
        } else {
            if n > 0 {
                n -= 1;
            } else {
                m += 1;
            }
        }
    }
    assert!(n == m);
    println!("{}", n + m);
}

#[allow(dead_code)]
struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn reserve(&mut self) {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        self.reserve();
        match self.buffer.pop_front().unwrap().parse::<T>() {
            Ok(a) => a,
            Err(_) => panic!("parse err")
        }
    }
    fn get_char(&mut self) -> char {
        self.reserve();
        let head = self.buffer[0].chars().nth(0).unwrap();
        let tail = String::from( &self.buffer[0][1..] );
        if tail.len()>0 { self.buffer[0]=tail } else { self.buffer.pop_front(); }
        head
    }
}

Measured memory_bytes: 1020
#include <stdio.h>
#define MAX 100005
#define NIL -1

typedef struct Node {
  int p;
  int l;
  int r;
}N;

N T[MAX];
int D[MAX],H[MAX];


int setHeight(int u){
  int h1=0,h2=0;
  if(T[u].l!=NIL)h1=setHeight(T[u].l)+1;
  if(T[u].r!=NIL)h2=setHeight(T[u].r)+1;
  return H[u]=(h1>h2?h1:h2);
}


void setDepth(int u,int p){
  if(u==NIL)return;
  D[u]=p;
  setDepth(T[u].r,p+1);
  setDepth(T[u].l,p+1);
}

int getSibling(int u){
  if(T[u].p==NIL)return NIL;
  if(T[T[u].p].l!=u&&T[T[u].p].l!=NIL)
    return T[T[u].p].l;
  if(T[T[u].p].r!=u&&T[T[u].p].r!=NIL)
    return T[T[u].p].r;
  return NIL;
}




int main(){
  int i,j,n,v,l,r,root=0,deg=0;
  
  scanf("%d",&n);
  for(i=0;i<n;i++)
    T[i].p=NIL;
  
  for(i=0;i<n;i++){
    scanf("%d%d%d",&v,&l,&r);
    
    T[v].l=l;
    T[v].r=r;
    if(l!=NIL)T[l].p=v;
    if(r!=NIL)T[r].p=v;
     
  }
  for(i=0;i<n;i++)
    if(T[i].p==NIL)root=i;

  setDepth(root,0);
  setHeight(root);

  for(i=0;i<n;i++){
    printf("node %d: parent = %d, sibling = %d, ",i,T[i].p,getSibling(i));
    if(T[i].l!=NIL)deg++;
    if(T[i].r!=NIL)deg++;
    
    printf("degree = %d, depth = %d, height = %d, ",deg,D[i],H[i]);    
    
    if(T[i].p==NIL)printf("root");
    else if(T[i].l==NIL&&T[i].r==NIL)printf("leaf");
    else printf("internal node");

    printf("\n");    
    deg=0;
  }



    
  return 0;
}
  



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

#define STACK_SIZE 100
void push(int );
int pop(void );

int stack[STACK_SIZE];
int top = 0;

int main(){
  int x,y,t;
  char s[100];

  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      x = pop( );
      y = pop( );
      push(x + y);

    } else if ( s[0] == '-' ){
      x = pop( );
      y = pop( );
      push(y - x);

    } else if ( s[0] == '*' ){
      x = pop( );
      y = pop( );
      push(x * y);
       
    } else {
      t = atoi(s);
      push(t);
    }
  }
  printf("%d\n",pop()); 
  
  return 0;
}

int pop( ){
  if(top <= 0){
    top--;
    return 0;
  }
  else {
    top--;
    return stack[top + 1]; 
  }
}
 
void push(int p){
  stack[++top] = p;
}
 


 



 

Measured memory_bytes: 548
#include <bits/stdc++.h>
#define rt "\n"
#define sp " "
#define test(n) cout << "test" << n << endl;
#define fixsp(n) fixed << setprecision(n)
#define defsp(n) defaultfloat << setprecision(n)
#define kyopro ios::sync_with_stdio(false);cin.tie(NULL)
#define MOD 1000000007
#define iikae auto&
#define vector3D(K, N, M, DP) vector<vector<vector<ll>>> DP(K, vector<vector<ll>>(N, vector<ll>(M)));
#define vector4D(K, N, M, O, DP) vector<vector<vector<vector<ll>>>> DP(K, vector<vector<vector<ll>>>(N, vector<vector<ll>>(M, vector<ll>(O))));
#define zenbu(a) a.begin(), a.end()
#define rzenbu(a) a.rbegin(), a.rend()
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define rem(i, N, s) for(ll i{N}; i > s; i--)
using namespace std;using ll = long long;using ld = long double;using P = pair<ll,ll>;
template<typename T> T gcd(T a, T b){return b != 0 ? gcd(b, a % b) : a;}
template<typename T> struct UnionFind{vector<T> par;UnionFind(T n) : par(n, -1){}void init(T n){par.assign(n, -1);}T root(T x){if (par[x] < 0) return x;else return par[x] = root(par[x]);}bool issame(T x, T y){return root(x) == root(y);}bool merge(T x, T y){x = root(x); y = root(y);if(x == y) return false;if(par[x] > par[y]) swap(x, y);par[x] += par[y];par[y] = x;return true;}int size(int x) {return -par[root(x)];}};
template<typename T> ll comb(T N_, T C_) {const int NUM_=400001;static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];if (fact[0]==0) {inv[1]=fact[0]=factr[0]=1;for (int i=2;i<=NUM_;++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%MOD, factr[i]=factr[i-1]*inv[i]%MOD;}if(C_<0 || C_>N_) return 0;return factr[C_]*fact[N_]%MOD*factr[N_-C_]%MOD;}

/* ここからコード開始 */

int main(){
  kyopro;
  ll N;
  cin >> N;
  vector<ll> d(N);
  for(auto&& i : d){
    cin >> i;
  }
  if(N%2 == 0){
    sort(zenbu(d));
    cout << d.at(N/2) - d.at(N/2-1) << rt;
  }
  else{
    cout << 0 << rt;
  }
}

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

int main(void){
	int i,j,n,m,t[100],h[100],sum_t,sum_h,ans_t,ans_h;

	while(cin>>n>>m && n){
		for(i=sum_t=0;i<n;i++){cin>>t[i]; sum_t+=t[i];}
		for(i=sum_h=0;i<m;i++){cin>>h[i]; sum_h+=h[i];}
		sort(t,t+n);
		sort(h,h+m);

		for(i=j=0,ans_t=-1;i<n&&j<m;){
			if(sum_t-t[i]+h[j] == sum_h-h[j]+t[i]){
				ans_t = t[i];
				ans_h = h[j];
				break;
			}
			if(sum_t-t[i]+h[j] > sum_h-h[j]+t[i]) i++;
			else j++;
		}

		if(ans_t >= 0) cout<<ans_t<<" "<<ans_h<<endl;
		else cout<<"-1\n";
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cfloat>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )

#define ITER( c ) __typeof( (c).begin() )
#define EACH( it, c ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

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

	int h, w;
	cin >> h >> w;

	VS board( h );
	FOR( line, board )
	{
		cin >> line;
	}

	VVI dp( h, VI( w, INT_MAX ) );
	dp[0][0] = 0;

	REP( i, 0, h )
	{
		REP( j, 0, w )
		{
			i ? dp[i][j] = min( dp[i][j], dp[ i - 1 ][j] + board[i][j] - '0' ) : true ;
			j ? dp[i][j] = min( dp[i][j], dp[i][ j - 1 ] + board[i][j] - '0' ) : true ;
		}
	}

	cout << dp.back().back() << endl;

	return 0;
}

Measured memory_bytes: 1244
def m():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    edge = []
    tmp = 0
    for i in range(N):
        if A[i] == tmp:
            edge.append(tmp)
            tmp = 0
        else:
            tmp = A[i]
    if len(edge) < 2:
        return 0
    else:
        return edge[-1] * edge[-2]

print(m())

Measured memory_bytes: 15020
from itertools import permutations
N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
for i, t in enumerate(permutations(range(1, N+1))):
    if t == P:
        p = i
    if t == Q:
        q = i
print(abs(p-q))


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 300005;
int N;
int A[MAX_N];

int myPow(int k, int n)
{
  if(n <= 0) return 1;
  else return (k * myPow(k,n-1)) % MOD;
}

signed main()
{
  cin >> N;
  REP(n,N) {
    cin >> A[n];
  }

  int ans = 0;

  REP(i,61) {
    int one = 0, zero = 0;
    REP(n,N) {
      if((A[n] >> i) & 1) {
        one++;
      } else {
        zero++;
      }
    }
    int tmp = (one*zero) % MOD;
    ans += tmp * myPow(2,i);
    ans %= MOD;
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

const int MOD = int(1e9) + 7;

int n;
int c[200005], d[200005];
int pos[200005];

int main() {
    scanf("%d", &n);
    forn(i, n) {
        scanf("%d", c + i);
        if (i > 0 && c[i] == c[i - 1]) {
            --i;
            --n;
        }
    }
    forn(i, 200005) {
        pos[i] = -1;
    }
    d[0] = 1;
    forn(i, n) {
        int col = c[i];
        if (pos[col] != -1) {
            d[i + 1] = d[pos[col] + 1];
        }
        d[i + 1] = (d[i + 1] + d[i]) % MOD;
        pos[col] = i;
    }
    cout << d[n] << endl;
    return 0;
}


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

int main(){
  int n, k, d[110], a[110], x, ans=0;
  cin >> n >> k;
  for(int i=0;i<=n;i++)a[i]=0;
  for(int i=0;i<k;i++){
    cin >> d[i];
    for(int j=0;j<d[i];j++){
      cin >> x;
      a[x]=1;
    }
  }
  for(int i=1;i<=n;i++)if(a[i]==0)ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 999999999
#define MINF -999999999

int main() {
	int n, a[110000] = {}, f = 0, ans = 0;
	cin >> n;
	REP(i, n) cin >> a[i];
	sort(a, a + n, greater<int>());
	REP(i, n) {
		if (a[i] == a[i + 1]) {
			if (f == 0) {
				ans--;
				f = 1;
			}
			else {
				ans++;
				f = 0;
			}
		}
		else {
			ans++;
			f = 0;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int M;
    cin >> M;
    vector<ll> D(M), C(M);
    rep(i, 0, M) {
        cin >> D[i] >> C[i];
    }
    ll digits = 0;
    ll sum = 0;
    rep(i, 0, M) {
        digits += C[i];
        sum += D[i] * C[i];
    }
    cout << (digits - 1) + (sum - 1) / 9 << endl;
    return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define abdelrahman001 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define inFile(t) freopen((t),"r",stdin)
#define outFile(t) freopen((t),"w",stdout)
#define pb push_back
#define pf push_front
#define Pb pop_back
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define Pf pop_front
#define sz size
#define MP make_pair
#define Pc __builtin_popcount
#define pi 2*acos(0)
#define BiEdge(v,a,b) (v)[(a)].pb(b),(v)[(b)].pb((a))
#define mod 1000000007
#define point complex<ld>
#define X real()
#define Y imag()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define cross(a,b)(conj(a)*(b)).imag()
#define dot(a,b) (conj(a)*(b)).real()
#define rectangle pair<coordinate,coordinate>
#define line tuple<ll,ll,ll>
#define EPS 1e-7
#define polygon vector<point>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
int const N = 1e5+5,M = 1005;
using namespace std;
ll n,k,arr[N],memo[N];
ll solve(ll ind)
{
    if(ind == n-1)
        return 0;
    ll &ans = memo[ind];
    if(~ans)
        return ans;
    ans = 1e9;
    for(int i = 1;i<=min(n-ind,k);i++)
        ans = min(ans,solve(ind+i) + abs(arr[ind] - arr[ind+i]));
    return ans;
}
int main()
{
    abdelrahman001
    memset(memo,-1,sizeof memo);
    cin >> n >> k;
    for(int i = 0;i<n;i++)
        cin >> arr[i];
    cout << solve(0);
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)

int main() {
  string S; cin >> S;
  int K; cin >> K;
  int N = S.size();
  vector<int> num(N);
  rep(i, 0, N) num[i] = S[i] - 'a';
  rep(i, 0, N) {
    if(num[i] == 0) continue;
    int use = 26 - num[i];
    if(K >= use) {
      K -= use;
      num[i] = 0;
    }
  }
  num[N-1] = num[N-1] + K % 26;
  rep(i, 0, N) cout << char('a' + num[i]);
  cout << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using pi = pair<int,int>;
using P = pair<pi,int>;

const int N = 111;
const int INF = 191919;

int n;
int p[N];
vector<int> ch[N];

map<pi,P> dp[N];
P dfs(int v, int a, int b){
    if(dp[v].count({a,b})) return dp[v][{a,b}];

    if(ch[v].size() == 0){
        return {{1,1},p[v]};
    }

    int sz = ch[v].size();
    int res = -INF;
    int mn = N, mx = 0;

    do{
        int ta=a, tb=b;
        int tmn = 0, tmx = 0;
        rep(i,sz){
            P val = dfs(ch[v][i], -tb, -ta);
            int vv = -val.se;
            tmn += val.fi.fi;
            tmx += val.fi.se;
            if(vv >= tb){
                ta = vv;
                break;
            }
            if(vv > ta){
                ta = vv;
            }
        }

        res = max(res,ta);
        mn = min(mn, tmn);
        mx = max(mx, tmx);

    }while(next_permutation(all(ch[v])));

    // printf(" %d %d %d  ->   [%d,%d],  val = %d\n",v,a,b,mn,mx,res);

    P ret = {{mn,mx}, res};
    dp[v][{a,b}] = ret;
    return ret;
}

int main(){
    cin >>n;
    rep(i,n) cin >>p[i];
    rep(i,n){
        int k;
        cin >>k;
        while(k--){
            int t;
            cin >>t;
            --t;
            ch[i].pb(t);
        }
        sort(all(ch[i]));
    }

    pi ans = dfs(0,-INF,INF).fi;
    cout << ans.fi << " " << ans.se << endl;
    return 0;
}



Measured memory_bytes: 3820
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
typedef vector<LL> VI;
typedef vector<vector<LL> > VVI;
LL MOD = 1000000007;

VVI matrix_multi(VVI a,VVI b){
	VVI ret(a.size(),VI(b[0].size(),0));
	for(int k=0;k<a[0].size();k++)
	for(int i=0;i<a.size();i++)
	for(int j=0;j<b[0].size();j++)
	{
		ret[i][j] += a[i][k] * b[k][j] % MOD;
		ret[i][j] %= MOD;
	}
	return ret;
}

VVI matrix_pow(VVI mat, LL k) {
	int n = mat.size();
	if(k==0) {
		VVI init(n, VI(n, 0));
		for(int i=0; i<n; i++)
			init[i][i] = 1;
		return init;
	}
	VVI tmp = matrix_pow(mat, k/2);
	VVI ret = matrix_multi(tmp, tmp);
	if(k%2==1) {
		ret = matrix_multi(ret, mat);
	}
	return ret;
}

LL solve(LL cntBlack, LL H, LL yoko, LL K) {
	VVI mat(2, VI(2, 0));
	mat[0][0] = cntBlack;
	mat[0][1] = -yoko;
	mat[1][1] = H;
	mat = matrix_pow(mat, K-1);
	LL b = 1;
	if(H == 0) b = 0;
	LL ans =  mat[0][0] + b * mat[0][1];
	ans %= MOD; ans += MOD; ans %= MOD;
	return ans;
	
}


int main() {
	LL H, W, K;
	cin >> H >> W >> K;
	vector<string> field;
	int cntBlack = 0;
	for(int i=0; i<H; i++) {
		string s;
		cin  >> s;
		field.push_back(s);
		for(int j=0; j<s.size(); j++)
			if(s[j] == '#')
				cntBlack++;
	}
	
	int cntH = 0, cntW = 0;
	for(int i=0; i<H; i++) {
//		cout << field[i][0] << " " << field[i][W-1] << endl;
		if(field[i][0] == field[i][W-1] && field[i][0] == '#')
			cntH++;
	}
	for(int j=0; j<W; j++)
		if(field[0][j] == field[H-1][j] && field[0][j] == '#' )
			cntW++;
	if(cntH > 0 && cntW > 0 || K == 0) {
		cout << 1 << endl;
		return 0;
	}
	LL cntA=0, cntB=0;
	for(int i=0; i<H; i++) {
		for(int j=0; j<W; j++) {
			if(i<H-1) {
				if(field[i][j] == field[i+1][j] && field[i][j] == '#')
					cntA++;
			}
			if(j<W-1) {
				if(field[i][j] == field[i][j+1] && field[i][j] == '#')
					cntB++;
			}
		}
	}
	
	
	if(cntH == 0) {
		swap(cntW, cntH);
		swap(W, H);
		swap(cntA, cntB);
	}
//	cout << cntA << " " << cntB << endl;
//	cout << cntW << " " << cntH << endl;
	cout << solve(cntBlack, cntH, cntB, K) << endl;
	
	return 0;
}



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

int main(){
    int n;
    cin >> n;
    int a,j,ans,k=0;
    vector <int> m(55);
    rep(i,5555){
        a=10*(i+1)+1;
        j=2;
        ans=0;
        while(j*j<=a){
            if(a%j==0){
                ans=-1;
            }
            ++j;
        }
        if(ans==0){
            m[k]=a;
            if(k==54){
                break;
            }
            ++k;
        }
    }
    
    rep(i,n){
        cout << m[i] << " ";
    }
    

    return 0;
}

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

#define x first
#define y second
#define y1 Y1
#define y2 Y2
#define mp make_pair
#define pb push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> pii;

template <typename T> inline int Chkmax (T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline int Chkmin (T &a, T b) { return a > b ? a = b, 1 : 0; }

inline void proc_status()
{
	ifstream t ("/proc/self/status");
	cerr << string (istreambuf_iterator <char> (t), istreambuf_iterator <char> ()) <<endl;
}

template <typename T> T read ()
{
	T sum = 0, fl = 1; char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') fl = -1;
	for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch - '0';
	return sum * fl;
}

const int Maxn = 200 + 10, Maxm = 2e5 + 100;

int N, M, A[Maxn], Dp[Maxm];
int e, Begin[Maxm], To[Maxm * Maxn], Next[Maxm * Maxn], deg[Maxm];

inline void add_edge (int x, int y) { To[++e] = y; Next[e] = Begin[x]; Begin[x] = e; deg[y]++;}

inline void Solve ()
{
	memset(Dp, -1, sizeof Dp);
	for (int i = 0; i < A[1]; ++i) Dp[i] = 0;
	for (int i = 1; i <= N; ++i)
	{
		for (int j = 0; j <= M - A[i]; ++j)
		{
			add_edge (j, j + A[i]);
		}
	}
	queue <int> Q;
	for (int i = 0; i <= M; ++i) if (!deg[i]) Q.push(i);
	while (!Q.empty())
	{
		int x = Q.front(); Q.pop();
		for (int i = Begin[x]; i; i = Next[i])
		{
			int y = To[i];
			if (!Dp[x]) Dp[y] = 1;
			else if (Dp[x] == 1 && Dp[y] != 1) Dp[y] = 0;
			deg[y]--;
			if (!deg[y]) Q.push(y);
		}
	}
	if (Dp[M]) printf("First");
	else printf("Second");
}

inline void Input ()
{
	N = read<int>(), M = read<int>();
	for (int i = 1; i <= N; ++i) A[i] = read<int>();
}

int main()
{
#ifdef hk_cnyali
	freopen("K.in", "r", stdin);
	freopen("K.out", "w", stdout);
#endif
	Input();
	Solve();
	return 0;
}


Measured memory_bytes: 84608
#include <bits/stdc++.h>
#define MAX 1000005
using namespace std;

int n;
int a[MAX];

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++){
        scanf("%1d", &a[i]);
    }
    if(n == 1){
        cout << a[1] << endl;
        return 0;
    }
    n--;
    for(int i = 1; i <= n; i++){
        a[i] = abs(a[i+1]-a[i]);
    }
    int flag = 0;
    for(int i = 1; i <= n; i++){
        if(a[i] == 1) flag = 1;
    }
    if(!flag){
        for(int i = 1; i <= n; i++){
            a[i] >>= 1;
        }
    }
    int t = 0;
    for(int i = 1; i <= n; i++){
        t ^= (a[i]&1)*(((n-1)&(i-1)) == i-1);
    }
    if(!flag) t <<= 1;
    cout << t << endl;

    return 0;
}

Measured memory_bytes: 4096
#include <iostream>
using namespace std;
int main()
{
int a[10],i,j;
while(scanf("%1d", &a[0])!=EOF){
for(i = 1; i < 10; i++)scanf("%1d",&a[i]);
for(i = 9; i >= 0; i--)
for(j = 0; j < i; j++)
a[j]=a[j]+a[j+1]-((a[j]+a[j+1])/10)*10;
cout<<a[0]<<endl;
}
return 0;
}

Measured memory_bytes: 0
MOD = 10 ** 9 + 7
def add(a, b):
  return (a + b) % MOD
def sub(a, b):
  return (a - b) % MOD
def mul(a, b):
  return ((a % MOD) * (b % MOD)) % MOD
def div(a, b):
  return ( (a % MOD) * (power(b, MOD)) ) % MOD
def power(a, b):
  return pow(a, b, MOD)

fn = [1, 1]
for i in range(10 ** 5):
  fn1 = fn[-2] + fn[-1]
  fn.append(fn1)

n, m = map(int, input().split())
an = []
for _ in range(m):
  an.append(int(input()))
an.append(n+1)

now = 0
pattern = 1
for a in an:
  if now >= a:
    pattern = 0
    break
  steps = a - now - 1
  pattern = mul(pattern, fn[steps])
  now = a + 1

print(pattern)
  
  

Measured memory_bytes: 464184
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;

    vector<int> height(N);
    for (int i = 0 ; i < N ; i++)cin >> height[i];

    vector<int> cost(N);
    cost[0]=0;
    cost[1]=abs(height[1]-height[0]);

    for(int i=2 ; i<N ;i++){
        cost[i]=min(abs(height[i]-height[i-1])+cost[i-1],
                    abs(height[i]-height[i-2])+cost[i-2]
                    );
    }

    cout << cost[N-1] << endl;
}

Measured memory_bytes: 1024
import fractions
from functools import reduce

def main():

    N,X= map(int,input().split())
    targetList = list(map(int,input().split()))
    targetList.append(X)
    targetList.sort()
    diffList = []

    if N > 2:
        for i in range(N-1):
            diffList.append(targetList[i+1] - targetList[i])

    elif N==2:
        for i in targetList:
            diffList.append(i)
    else:
        print(abs(targetList[0]-targetList[1]))
        exit()

    print(reduce(fractions.gcd,diffList))

        
    
if __name__== "__main__":
    main() 


Measured memory_bytes: 16236
#include<bits/stdc++.h>
#define For(i,l,r) for(int i = (l),i##end = (r);i <= i##end;i++)
#define Fordown(i,r,l) for(int i = (r),i##end = (l);i >= i##end;i--)
#define debug(x) cout << #x << " = " << x << endl

using namespace std;

typedef long long ll;

template <typename T> inline bool chkmin(T &x,T y) { return y < x ? x = y,1 : 0; }
template <typename T> inline bool chkmax(T &x,T y) { return x < y ? x = y,1 : 0; }

const int INF = 0x3f3f3f3f;
const int N = 5e3 + 10,mod = 1e9 + 7,Inv2 = (mod + 1) / 2;

int dp[N][N],to[N << 1],nex[N << 1],beg[N],sz[N],cur[N],fac[N],inv[N];
int e;

inline int read() {
	int x = 0,flag = 1;
	char ch = getchar();
	while(!isdigit(ch) && ch != '-')ch = getchar();
	if(ch == '-')flag = -1,ch = getchar();
	while(isdigit(ch))x = (x << 3) + (x << 1) + (ch - '0'),ch = getchar();
	return x * flag;
}

inline void add(int x,int y) {
	to[++e] = y,nex[e] = beg[x],beg[x] = e;
}

inline int fpm(int a,int b) {
	int res = 1;
	while(b) {
		if(b & 1) res = 1ll * res * a % mod;
		a = 1ll * a * a % mod,b /= 2;
	}
	return res;
}

inline int Calc(int n) {
	return 1ll * fac[n] * inv[n / 2] % mod * fpm(Inv2,n / 2) % mod;
}

inline void Add(int &x,int y) {
	if((x += y) >= mod) x -= mod;
}

inline void dfs(int x,int fa) {
	dp[x][sz[x] = 1] = 1;
	for(int i = beg[x];i;i = nex[i]) {
		if(to[i] == fa) continue;
		dfs(to[i],x);
		For(j,0,sz[x] + sz[to[i]]) cur[j] = 0;
		For(j,0,sz[x] + sz[to[i]]) For(k,max(j - sz[x],0),min(sz[to[i]],j))
			Add(cur[j],1ll * dp[to[i]][k] * dp[x][j - k] % mod);
		For(j,0,sz[x]) for(int k = 2;k <= sz[to[i]];k += 2)
			Add(cur[j],mod - 1ll * dp[x][j] * Calc(k) % mod * dp[to[i]][k] % mod);
		sz[x] += sz[to[i]];
		For(j,0,sz[x]) dp[x][j] = cur[j];
	}
}

int main() {

	int n = read();
	For(i,1,n - 1) {
		int x = read(),y = read();
		add(x,y),add(y,x);
	}

	fac[0] = 1;
	For(i,1,n) fac[i] = 1ll * fac[i - 1] * i % mod;
	inv[n] = fpm(fac[n],mod - 2);
	Fordown(i,n,1) inv[i - 1] = 1ll * inv[i] * i % mod;

	dfs(1,0);

	int ans = 0;
	for(int i = 2;i <= n;i += 2) Add(ans,1ll * dp[1][i] * Calc(i) % mod);

	printf("%d\n",ans);

	return 0;
}

Measured memory_bytes: 97024
s = input()
flag = False
for i in range(len(s)):
  if (i + 1) % 2 != 0 and (s[i] == "R" or s[i] == "U" or s[i] == "D"):  #奇数
    flag = True
  elif (i + 1) % 2 == 0 and (s[i] == "L" or s[i] == "U" or s[i] == "D"):  #偶数
    flag = True
  else:
    flag = False
    break
if flag:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let line = read_as_vec::<i32>();
    let (a, b) = (line[0], line[1]);

    if a <= 8 && b <= 8{
        println!("Yay!");
    }else{
        println!(":(");
    }
}


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

using namespace std;

int main() {
    int n, k;

    scanf("%d%d", &n, &k);

    int ans=1;
    for (int i = 0; i < n; i++) {
        if (2*ans>ans+k){
            ans+=k;
        }
        else{
            ans*=2;
        }
    }

    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
from typing import Tuple


def answer(n: int, p: Tuple[int]) -> int:
    count = 0
    for i in range(1, n - 1):
        max_ = max(p[i - 1], p[i + 1])
        min_ = min(p[i - 1], p[i + 1])
        if min_ < p[i] < max_:
            count += 1

    return count


def main():
    n = int(input())
    p = tuple(map(int, input().split()))
    print(answer(n, p))


if __name__ == '__main__':
    main()

Measured memory_bytes: 10224
#include<bits/stdc++.h>
#include<random>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

int main() {
	init();
	
    int N; cin >> N;
    rep(i, 1, N + 1) {
        if (i + (8 * i) / 100 == N) {
            cout << i << "\n";
            return 0;
        }
    }
    cout << ":(" << "\n";

	return 0;
}

Measured memory_bytes: 256
// practice with kaiboy
import java.io.*;
import java.util.*;

public class Main extends PrintWriter {
	Main() { super(System.out); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		Main o = new Main(); o.main(); o.flush();
	}

	void main() {
		int n = sc.nextInt();
		int k = sc.nextInt();
		if (k > (n - 1) * (n - 2) / 2) {
			println(-1);
			return;
		}
		int m = n - 1 + (n - 1) * (n - 2) / 2 - k;
		println(m);
		for (int i = 1; i < n; i++)
			println(i + " " + n);
		m -= n - 1;
		for (int i = 1; i < n; i++)
			for (int j = i + 1; j < n; j++) {
				if (m-- == 0)
					return;
				println(i + " " + j);
			}
	}
}


Measured memory_bytes: 39796
#include<stdio.h>
#define MAX 2000000

void maxHeapify(int);
int extract(void);
void increaseKey(int ,int);
void insert(int);

int size, A[MAX];

int main(){

  int key;
  char com[20];

  while(1){
    scanf("%s", com);
    if ( com[0] == 'i' ){
      scanf("%d", &key);
      insert(key);
    }
    else if ( strcmp(com, "extract") == 0  ){
      printf("%d\n", extract());
    }
    else break;
  }
  
  return 0;
}

void maxHeapify(int i){
  
  int l, r, largest, t;

  l = 2*i;

  r = 2*i+1;
  if ( l <= size && A[l] > A[i] ) largest = l;
  else largest = i;
  if ( r <= size && A[r] > A[largest] ) largest = r;
  if ( largest != i ){
    t = A[i]; A[i] = A[largest]; A[largest] = t;
    maxHeapify(largest);
  }
}

int extract(void){
  
  int maxv;
  
  if ( size < 1 ) return;
  maxv = A[1];
  A[1] = A[size--];
  maxHeapify(1);

  return maxv;
}

void increaseKey(int i, int key){

  int tmp;

  if ( key < A[i] ) return;

  A[i] = key;

  while ( i > 1 && A[i/2] < A[i] ){
    tmp = A[i];
    A[i] = A[i/2];
    A[i/2] = tmp;
    i = i/2;
  }
}

void insert(int key){

  size++;
  A[size] = -1000000001;
  increaseKey(size, key);
  
}

Measured memory_bytes: 4696
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int l = (int)s.size();
    REP(i,l){
        cout << "x";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

void read();
template<typename First, typename... Rest> void read(First& first, Rest&... rest);
void write();
template<typename First, typename... Rest> void write(First first, Rest... rest);
template<typename T> void write_vec(vector<T>& v, char divider);

constexpr ll MOD = 1000000007;

ll modpow(ll n, ll r, ll mod) {
    if(r == 0) return 1;
    if(n == 0) return 0;
    if(r % 2 == 0) {
        ll tmp = modpow(n, r / 2, mod);
        return tmp * tmp % mod;
    }
    else {
        return n * modpow(n, r - 1, mod) % mod;
    }
}

ll modcomb(ll n, ll r, ll mod){
    ll u = 1;
    for(ll i = n; i > n - r; i--){
        u *= i;
        u %= mod;
    }
    ll d = 1;
    for(ll i = r; i > 0; i--){
        d *= i;
        d %= mod;
    }
    return u * modpow(d, mod - 2, mod) % mod;
}

int main(){
    ll n, a, b;
    read(n, a, b);
    ll ans = modpow(2, n, MOD);
    ans = (ans - modcomb(n, a, MOD) + MOD) % MOD;
    ans = (ans - modcomb(n, b, MOD) + MOD) % MOD;
    write(ans - 1);
    return 0;
}

//配列以外の入力を受け取る
void read(){

}
template<typename First, typename... Rest>
void read(First& first, Rest&... rest){
    cin >> first;
    read(rest...);
}
//
//配列以外を出力する
void write(){

}
template<typename First, typename... Rest>
void write(First first, Rest... rest){
    cout << first << " ";
    write(rest...);
}
//
//配列を区切って出力する
template<typename T>
void write_vec(vector<T>& v, char divider){
    for(size_t i = 0; i < v.size(); i++){
        cout << v[i] << divider;
    }
}
//

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

#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (ll i = m; i < (n); i++)

using ll = long long;
using pii = pair<int, int>;
using Vi = vector<int>;


int main() {
  int a,b;
  cin >>a>>b;
  if(a*b%2==1) cout << "Odd" << endl;
  else cout << "Even" << endl;
}

Measured memory_bytes: 3564
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define ALL(v) v.begin(), v.end()
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
	string S;
	cin >> S;

	int N = S.size();

	int ans = 0;
	int cur = 0;
	string prev, now;
	while (cur < N) {
		now += S[cur];
		if (prev != now) {
			++ans;
			prev = now;
			now = "";
		}
		++cur;
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#[allow(unused_imports)]
use itertools::Itertools;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
    input! {
        n: usize,
        mut a: [i64; n],
    }
    a.sort();
    let m = num::clamp(a.iter().filter(|&a| *a < 0).count(), 1, n - 1);
    println!(
        "{}",
        a[m..].iter().sum::<i64>() - a[..m].iter().sum::<i64>()
    );
    let mut x = a[n - 1];
    for i in 1..m {
        println!("{} {}", x, a[i]);
        x -= a[i];
    }
    let mut y = a[0];
    for i in m..n - 1 {
        println!("{} {}", y, a[i]);
        y -= a[i];
    }
    println!("{} {}", x, y);
}


Measured memory_bytes: 3836
import java.util.*;

public class Main{
 public static void main(String[] agrs){
  Scanner sc = new Scanner(System.in);
  int a = sc.nextInt();
  int b = sc.nextInt();
  if(a*b%2==0){
   System.out.println("Even");
  }else{
   System.out.println("Odd");
  }
 }
}


Measured memory_bytes: 21844
import java.io.*;

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] a=br.readLine().split(" ");
        int m=Integer.parseInt(a[0]);
        int f=Integer.parseInt(a[1]);
        int r=Integer.parseInt(a[2]);
		int k=m+f;
        while(!(m==-1&&f==-1&&r==-1)){
    		String g=null;
        	if(m==-1||f==-1||k<30){
        		g="F";
        	}else if(30<=k&&k<50){
        		if(r>=50){
        			g="C";
        		}else{
        			g="D";
        		}
        	}else if(50<=k&&k<65){
        		g="C";
        	}else if(65<=k&&k<80){
        		g="B";
        	}else{
        		g="A";
        	}
            System.out.println(g);
        	a=br.readLine().split(" ");
            m=Integer.parseInt(a[0]);
            f=Integer.parseInt(a[1]);
            r=Integer.parseInt(a[2]);
            k=m+f;
        }
	}
}

Measured memory_bytes: 24420
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
class UnionFind {
private:
	vector<ll> parents;
	vector<ll> ranks;
public:
	vector<ll> sizes;
	UnionFind(ll s): parents(s), ranks(s), sizes(s, 1) {
		for(ll i = 0; i < s; i++) parents[i] = i;
	}
	int find(ll x) {
		if(parents[x] == x) return x;
		else return parents[x] = find(parents[x]);
	}
	void unite(ll x, ll y) {
		x = find(x);
		y = find(y);
		if(x == y)return;
		if(ranks[x]<ranks[y]) {
			parents[x] = y;
			sizes[y] += sizes[x];
		} else {
			parents[y] = x;
			sizes[x] += sizes[y];
			if(ranks[x] == ranks[y]) ranks[x]++;
		}
	}
 
	bool same(ll x, ll y) {
		return find(x) == find(y);
	}
};
int main(){
    int N, M, K;
    cin >> N >> M >> K;
    UnionFind uf(N);
    vector<int> C(K), D(K);
    vector<int> J(N);
    for(int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        uf.unite(a, b);
        J[a]++;
        J[b]++;
    }
    for(int i = 0; i < K; i++) {
        cin >> C[i] >> D[i];
        C[i]--;
        D[i]--;
    }
    vector<int> ans(N);
    for(int i = 0; i < N; i++) {
        ans[i] = uf.sizes[uf.find(i)] - J[i] - 1;
    }
    for(int i = 0; i < K; i++) {
        if(uf.same(C[i], D[i])) {
            ans[C[i]]--;
            ans[D[i]]--;
        }
    }
    for(int i = 0; i < N; i++) {
        cout<<ans[i]<<" ";
    }
    cout<<endl;
    return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> vec;
  vector<pair<int, int>> backup;
  rep(i, m){
    int a, b;
    cin >> a >> b;
    vec.push_back(make_pair(a,b));
  }
  backup = vec;
  sort(all(vec));
  map<int, string> mp;
  string str = "";
  int currentCity = vec[0].first;
  int currentNum = 1;
  rep(i, 6-std::to_string(currentCity).length()) str += "0";
  str+= std::to_string(currentCity);
  rep(i, 6-std::to_string(currentNum).length()) str += "0";
  str+= std::to_string(currentNum);
  mp[vec[0].second] = str;
  for(int i=1; i<m; i++){
   	if(vec[i].first == currentCity){
      currentNum++;
      string str = "";
      rep(i, 6-std::to_string(currentCity).length()) str += "0";
  	  str+= std::to_string(currentCity);
  	  rep(i, 6-std::to_string(currentNum).length()) str += "0";
  	  str+= std::to_string(currentNum);
  	  mp[vec[i].second] = str;
    }else{
      string str = "";
      currentCity = vec[i].first;
      currentNum = 1;
      rep(i, 6-std::to_string(currentCity).length()) str += "0";
  	  str+= std::to_string(currentCity);
  	  rep(i, 6-std::to_string(currentNum).length()) str += "0";
  	  str+= std::to_string(currentNum);
  	  mp[vec[i].second] = str;
    }
  }
  rep(i, m){
    cout << mp[backup[i].second] << endl;
  }
  return 0;
}

Measured memory_bytes: 15604
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<algorithm>
using std::cout;
using std::cin;
using std::endl;

char finder(std::string sorted,char lastchar){
    for(int position=(int)sorted.size()-1;position>=0;position--){
        if(lastchar<sorted[position]){
            return sorted[position];
        }
    }
}


int main(void){
    std::string S;
    cin>>S;
    if(S.size()<26){
        bool isused[256]={};
        for(int i=0;i<(int)S.size();i++){
            isused[(int)S[i]]=true;
        }
        int target=(int)'a';
        while(isused[target]==true){
            target++;
        }
        S+=(char)target;
        cout<<S<<endl;
        return 0;
    }else{
        std::string sorted=S;
        std::sort(sorted.begin(),sorted.end(),std::greater<char>());
        if(S==sorted){
            cout<<-1<<endl;
            return 0;
        }
        
        for(int target=24;target>=0;target--){
            std::string bs;
            for(int i=target;i<=25;i++){
                bs+=S[i];
            }
            std::string as=bs;
            std::sort(as.begin(),as.end(),std::greater<char>());
            if(as!=bs){
                std::string ans;
                int k;
                for(k=0;k<=target-1;k++){
                    ans+=S[k];
                }
                ans+=finder(as,S[k]);
                cout<<ans<<endl;
                return 0;

            }
        }
        

    }

    


	
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int d = sc.nextInt();
    int ans = 1;
    for(int i=0; i<n; ++i) {
      if(2*d*i>=n-i) {
        ans = i;
        break;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 22740
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
using namespace std;

int main(){
  string s,t; cin>>s>>t;
  int a,b; cin>>a>>b;
  string u; cin>>u;
  if(u==s) cout<<(a-1)<<" "<<b<<endl;
  else cout<<a<<" "<<(b-1)<<endl;
  return 0;
}

Measured memory_bytes: 384
import sys

class Node:
    __slots__ = ['key', 'left', 'right']
    def __init__(self, key):
        self.key = key
        self.left = self.right = None

root = None

def insert(key):
    global root
    x, y = root, None
    while x != None: x, y = x.left if key < x.key else x.right, x
    if y == None: root = Node(key)
    elif key < y.key: y.left = Node(key)
    else: y.right = Node(key)

def find(target):
    result = root
    while result and target != result.key:
        result = result.left if target < result.key else result.right
    return result != None

def inorder(node):
    return inorder(node.left) + f' {node.key}' + inorder(node.right) if node else ''
def preorder(node):
    return f' {node.key}' + preorder(node.left) + preorder(node.right) if node else ''

input()
for e in sys.stdin:
    if e[0] == 'i': insert(int(e[7:]))
    elif e[0] == 'f': print(['no','yes'][find(int(e[5:]))])
    else: print(inorder(root)); print(preorder(root))


Measured memory_bytes: 55616
def sort(A):
    N=len(A)
    for i in range(N):
        for j in range(N-i-1):
            if A[j] < A[j+1]:
                temp=A[j+1]
                A[j+1]=A[j]
                A[j]=temp
    return A
A=list(map(int,input().split()))
print(" ".join(list(map(str,sort(A)))))

Measured memory_bytes: 7632
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    String org = sc.next();
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < org.length(); i++) {
      char c = org.charAt(i);
      if (i == K - 1) {
        c = (char) ('a' + (int)c - 'A');
      }
      builder.append(c);
    }
    System.out.println(builder.toString());
    //System.out.println(Arrays.toString(array));
  }
}

Measured memory_bytes: 22612
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int MAX = 1e6;

bool prime[MAX];

void is_prime(){
  fill(prime,prime+MAX,true);
  
  prime[0] = prime[1] = false;
  for(int i = 2 ; i*i < MAX ; i++)
    if(prime[i])
      for(int j = i*i ; j < MAX ; j += i)
	prime[j] = false;
}

int main(){
  int n,p;

  is_prime();

  while(true){
    cin >> n >> p;
    if(n == -1 && p == -1) break;

    vector<int> v;
    for(int i = n+1 ; i < n+500 ; i++){
      if(prime[i]) v.push_back(i);
    }

    vector<int> ans;
    for(int i = 0 ; i < (int)v.size() ; i++){
      for(int j = i ; j < (int)v.size() ; j++){
	ans.push_back(v[i]+v[j]);
      }
    }
    sort(ans.begin(),ans.end());

    cout << ans[p-1] << endl;
  }  

  return 0;
}

Measured memory_bytes: 2228
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <numeric>
#include <algorithm>
#include <iomanip>
#include <stdio.h>


int main(void){
  int n,d1,d2,count=0;
  std::cin >> n;
  for(int i=0;i<n;i++){
    std::cin >> d1 >> d2;
    if(d1==d2)count++;
    else count = 0;
    if(count==3){
      std::cout << "Yes";
      exit(0);
    }
  }
  std::cout << "No";
  return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>

using namespace std;

int main()
{
    int N, ans = 0, count;
    string s;
    bool left = false, right = false;

    cin >> N >> s;

    for (int i = 1; i < N; i++) {
        count = 0;
        for (char c = 'a'; c <= 'z'; c++) {
            left = false;
            right = false;
            for (int j = 0; j < i; j++) {
                if (s[j] == c) left = true;
            }
            for (int j = i; j < N; j++) {
                if (s[j] == c) right = true;
            }
            if (left && right) count++;
        }
        if (ans < count) ans = count;
    }
    cout << ans << endl;
}

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

int main(){
  while(1){
  int t,n;
  
  cin >> t;
  if(t<=0){
	break;
  }
  cin >> n;

  int s[n],f[n];
  int all=0;

  for(int i=0;i<n;i++){
	cin >> s[i] >> f[i];
	all+=f[i]-s[i];
  }

  if(all>=t){
	cout << "OK" << endl;
  }
  else{
	cout << t-all << endl;
  }

  }

  return 0;
}


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

using namespace std;

int main()
{
    set <int> st;

    int a, b, c;
    cin >> a >> b >> c;

    st.insert(a);
    st.insert(b);
    st.insert(c);

    cout << (st.size() == 2 ? "Yes\n" : "No\n");
    return 0;
}

Measured memory_bytes: 256