akhauriyash/Code-Regression huggingface dataset:
#include<cstdio> 
#include<cstring> 
const int MAX_E=20005,MAX_V=205,INF=1e7; 
struct edge{ 
    int to,cap,rev,next; 
}g[2*MAX_E]; 
int k=0,h[MAX_V],level[MAX_V],iter[MAX_V],head=0,tail=0,q[MAX_V],n,m,S,T;
char map[105][105]; 
void add(int u,int v,int cap){ 
    g[++k].next=h[u]; h[u]=k; 
    g[k].to=v; g[k].cap=cap; g[k].rev=k+1; 
    g[++k].next=h[v]; h[v]=k; 
    g[k].to=u; g[k].cap=0; g[k].rev=k-1; 
} 
void bfs(int s){ 
    head=tail=0; 
    q[tail++]=s; level[s]=1; 
    while(head!=tail){ 
        int u=q[head]; 
        for(int i=h[u];i;i=g[i].next){ 
            if(!level[g[i].to]&&g[i].cap){ 
                level[g[i].to]=level[u]+1; 
                q[tail++]=g[i].to; 
            } 
        } 
        head++; 
    } 
} 
int dfs(int u,int t,int f){ 
    if(u==t) return f; 
    for(int &i=iter[u];i;i=g[i].next){ 
        if(level[g[i].to]==level[u]+1&&g[i].cap){ 
            int d=dfs(g[i].to,t,f<g[i].cap?f:g[i].cap); 
            if(d){ 
                g[i].cap-=d; 
                g[g[i].rev].cap+=d; 
                return d; 
            } 
        } 
    } 
    return 0; 
} 
int max_flow(int s,int t){ 
    int flow=0; 
    for(;;){ 
        for(int i=1;i<=m+n+2;++i) iter[i]=h[i]; 
        memset(level,0,sizeof(level)); 
        bfs(s); 
        if(level[t]==0) return flow; 
        int d=dfs(s,t,INF); 
        while(d>0){ 
            flow+=d; 
            d=dfs(s,t,INF); 
        } 
    } 
} 
int main(){
	scanf("%d%d",&n,&m);
	S=n+m+1,T=n+m+2;
	for(int i=1;i<=n;++i) scanf("%s",map[i]+1);
    for(int i=1;i<=n;++i)
        for(int j=1;j<=m;++j){
            if(map[i][j]!='.') add(i,j+n,1),add(j+n,i,1);
            if(map[i][j]=='S') add(S,i,INF),add(S,j+n,INF);
            else if(map[i][j]=='T') add(i,T,INF),add(j+n,T,INF);
        }
    int ans=max_flow(S,T);
    if(ans>=INF) puts("-1");
    else printf("%d\n",ans);
}

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

# 各整数がいくつあるかのリスト
L = [0]*N
for i in A:
    L[i-1] += 1

# 全体から選んだ場合の数を求める
# 各整数で２つ選ぶ組み合わせの合計
SumAll = 0
for i in range(N):
    x = L[i]
    if x >= 2:
        SumAll += int((x * (x-1))/2)

# k番目がない場合の数
# kが影響する分のもとの場合の数を引いて、ｋを抜いたあとの場合の数を足す
for k in range(N):
    i = A[k] - 1
    Sub = 0
    x = L[i]
    if x >= 2:
        Sub += int((x * (x-1)/2))
    if x >= 3:
        Sub -= int((x-1)*(x-2)/2)
    print(SumAll - Sub)


Measured memory_bytes: 84944
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for(int &i: h) cin >> i;

    vector<int> dp(n + 1000, INT_MAX);
    dp[0] = 0;

    for(int i = 0; i < n; i++)
    {
        // dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i - 2] -h[i]));
        for(int j = 1; j <= k; j++)
        {
            dp[i + j] = min(dp[i] + abs(h[i] - h[i + j]), dp[i + j]);
        }
    }

    cout << dp[n - 1];
    return 0;
}

Measured memory_bytes: 1024
n, A, B, C = map(int, input().split())
l = [int(input()) for i in range(n)]


def dfs(cur, a, b, c):
    if cur == n:
        return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else 10**9
    ret0 = dfs(cur + 1, a, b, c)
    ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
    ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
    ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
    return min(ret0, ret1, ret2, ret3)

print(dfs(0, 0, 0, 0))

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main{

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        
        // input
        String input = scan.next();
        char[] inputChar = input.toCharArray();

        // search
        int countZero = 0;
        int countOne = 0;
        for(int i = 0; i < inputChar.length; i++){
            if(inputChar[i] == '0'){
                countZero++;
            } else {
                countOne++;
            }
        }
        
        // answer
        System.out.println(Math.min(countZero, countOne) * 2);

    }
}

Measured memory_bytes: 27604
#include<iostream>
#include<cstdio>
using namespace std;
long long a,b,c,d,e,f,g;
inline long long max(long long a,long long b){
	return a>b?a:b;
}
int main() {
	scanf("%lld%lld%lld%lld%lld%lld%lld",&a,&b,&c,&d,&e,&f,&g);
	printf("%lld\n",b+max(a/2*2+d/2*2+e/2*2+3*(a%2&&d%2&&e%2),3*(a>0&&d>0&&e>0)+(a-1)/2*2+(d-1)/2*2+(e-1)/2*2));
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cmath>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <numeric>

using namespace std;

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

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

const int Maxn = 2010;

const ll INF = (ll)1e16;

int n;
ll x;
ll a[Maxn], minv[Maxn];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> x;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    fill(minv, minv + n, INF);
    ll ans = INF;
    for (int k = 0; k < n; ++k) {
        ll cost = k * x;
        for (int i = 0; i < n; ++i) {
            minv[i] = min(minv[i], a[(i - k + n) % n]);
            cost += minv[i];
        }
        ans = min(ans, cost);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
    int h[n], dp[n];
    for (int i = 0; i < n; i++)
    {
    	cin >> h[i];
    }

    dp[0] = 0;

    for (int i = 1; i < n; i++) {
        dp[i] = INT_MAX;

        for (int j = 1; j <= k; j++) {
            if (i - j >= 0)
            {
                dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]));    
            }
        }
    }
    cout << dp[n-1] << "\n";

    return 0;
}

Measured memory_bytes: 1024
//压行课次
#include<bits/stdc++.h>
using namespace std;
int read(){int sss=0,fff=1;char ccc;ccc=getchar();while(ccc<'0'||ccc>'9'){if(ccc=='-')fff=-1;ccc=getchar();}while(ccc>='0'&&ccc<='9')sss=(sss<<1)+(sss<<3)+(ccc^'0'),ccc=getchar();return sss*fff;}
int main()
{
//	freopen("123.in","r",stdin);
//	freopen("123.out","w",stdout);
	int a=read(),b=read();
	if(a>=10||b>=10) printf("-1\n");
	else printf("%d\n",a*b);
	return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

cnt, su, r = 0, 0, 0
for l in range(n):
    while r < n and su + a[r] == su ^ a[r]:
        su += a[r]
        r += 1
    cnt += r - l
    if l == r:
        r += 1
    else:
        su -= a[l]
print(cnt)


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

char b;

int main(){
    cin >> b;
    switch (b){
        case 'A': cout << 'T'; break;
        case 'T': cout << 'A'; break;
        case 'C': cout << 'G'; break;
        case 'G': cout << 'C'; break;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define endl "\n"

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
    oreno_initializer() {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }
} oreno_initializer;



string s;
int a, b, c, d;

signed main() {
    while (1) {
        cin >> s;
        if (s=="#") break;
        cin >> a >> b >> c >> d;
        a--, b--, c--, d--;
        string m[11];

        int h = count(all(s), '/') + 1;
        int hn = 0;
        rep(id,s.size()) {
            if (s[id]=='/') hn++;
            else if (s[id]=='b') m[hn].push_back('#');
            else rep(j,s[id]-'0') m[hn].push_back('.');
        }
        int w = m[0].size();

        m[a][b] = '.', m[c][d] = '#';
        int cnt = 0;
        string res;
        rep(i,h) rep(j,w) {
            if (m[i][j]=='.') cnt++;
            else {
                if (cnt) res.push_back('0'+cnt), cnt = 0;
                res.push_back('b');
            }
            if (j==w-1) {
                if (cnt) res.push_back('0'+cnt), cnt = 0;
                res += "/";
            }
        }
        res.pop_back();
        cout << res << endl;
    }
}



Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef vector<int> vec;

int dp[105][4][2];

int main(){
  string s; cin>>s;
  int n=s.size();
  int K; cin>>K;
  dp[0][0][0]=1;
  
  rep(i,n)rep(j,4)rep(k,2){
    int nd=s[i]-'0';
    rep(d,10){
      int ni=i+1,nj=j,nk=k;
      if(d!=0)nj++;
      if(nj>K)continue;
      if(k==0){
        if(d>nd)continue;
        if(d<nd)nk=1;
      }
      dp[ni][nj][nk]+=dp[i][j][k];
    }
  }
  cout<< dp[n][K][0]+dp[n][K][1]<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	long long n, i, j, k, ans, curr, m, x, xx, xxx, ss, r;
	cin >> n >> k;
	vector<long long> p(n + 1), c(n + 1);
	vector<bool> used(n + 1, false);
	for (i = 1; i <= n; i++) cin >> p[i];
	for (i = 1; i <= n; i++) cin >> c[i];

	ans = -1LL << 61;
	for (i = 1; i <= n; i++) {
		if (used[i]) continue;

		vector<long long> v;
		curr = i;
		do {
			v.push_back(c[curr]);
			used[curr] = true;
			curr = p[curr];
		} while (curr != i);
		
		m = v.size();
		vector<long long> s(m + 1);
		s[0] = 0;
		for (j = 0; j < m; j++) s[j + 1] = s[j] + v[j];
		ss = s[m];

		for (j = 0; j < m; j++) {
			x = 0;
			for (r = 1; (r <= k) && (r <= m); r++) {
				x += v[(j + r - 1) % m];
				ans = max(ans, x);
				xx = (k - r) / m;
				ans = max(ans, x + xx * ss);
			}
		}

	}

	cout << ans << "\n";



	return 0;
}


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

#define M 1000000007
#define pb emplace_back
#define f first
#define s second
#define rep(i, st, ed) for(ll i=st; i<ed; ++i)
#define repn(i, st, ed) for(ll i=st; i<=ed; ++i)
#define repb(i, ed, st) for(ll i=ed; i>=st; --i)
#define all(v) v.begin(),v.end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define PI acosl(-1.0)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vec;
typedef vector<pll> vecp;
typedef map<ll, ll> mpll;


const int N = 1e5 + 10;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << to_string(H) << endl;
  debug_out(T...);
}
#define LOCAL 3
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:" << endl, debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif


void solve()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	if(n%2 == 1)
	{
		cout<<"No"<<endl;
		return;
	}
	int j = n / 2;

	rep(i,0,n/2)
	{
		if(s[i] != s[j+i])
		{
			cout<<"No"<<endl;
			return;
		}
	}
	cout<<"Yes"<<endl;
}


int main()
{
	ll Tests = 1;
    //cin>>Tests;
    while(Tests--)
    {
    	solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;cin >> n;int a[20],b[20],c[20];
  for (int i=0; i<n; i++) cin >> a[i];
  for (int i=0; i<n; i++) cin >> b[i];
  for (int i=0; i<n-1; i++) cin >> c[i];
  int s = 0;
  for (int i=0; i<n; i++) s += b[a[i]-1];
  for (int i=0; i<n-1; i++){
    if(a[i+1] == a[i]+1){
      s += c[a[i]-1];
    }
  }
  cout << s;
}

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

int dp[2222][2222];
int R[2222][2222];
int S,N,M;
const int INF = (1000000009);

bool update(int &a,int b){
  if( a > b ) { a = b; return true; }
  return false;
}

int solvek(){
  fill( dp[0],dp[M+1], INF );
  dp[0][0] = 0;
  for(int i=1;i<=M;i++){
    int kid = 0;
    for(int j=1;j<=N;j++){
      while( kid < j && update( dp[i][j], dp[i-1][kid] + R[j][kid] ) ) kid++;      
      kid--;
      cout << kid << " " ;
    }
    cout << endl;
    for(int j=0;dp[i][j]!=0;j++)
      dp[i][j] = 0;    
  }
  return dp[M][N];
}

int solve(){
  fill( dp[0],dp[M+1], INF );
  dp[0][0] = 0;
  for(int i=1;i<=M;i++){
    int minik=0;
    for(int j=1;j<=N;j++){
      for(int kid=minik;kid<N;kid++){
        if( update( dp[i][j], dp[i-1][kid] + R[j][kid] ) ){
          minik = max( minik, kid );
        }        
      }
    }
    for(int j=0;dp[i][j]!=0;j++)
      dp[i][j] = 0;    
  }
  return dp[M][N];
}

int main(){
  cin >> S >> N >> M;
  int X[2222],Y[2222];
  for(int i=0;i<S;i++) cin >> X[i];
  
  for(int i=0;i<N;i++){
    int t,p; cin >> t >> p; p--;
    Y[i] = t-X[p];
  }

  sort( Y,Y+N );

  for(int i=0;i<N;i++){
    int sum = 0;
    //cout << " y " << Y[i] << endl;
    for(int j=i;j>-1;j--){
      sum += Y[i] - Y[j];
      R[i+1][j] = sum;
      //cout << "[ " << j << ", " << i+1 << " ) = " << R[i+1][j] << endl;
    }
  }

  cout << solve() << endl;
  
}

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

int descending_compare(const void *a, const void *b){
    if (*(long long*)a > *(long long*)b){
        return -1;
    }else if (*(long long*)a == *(long long*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}


int lower_bound(int *a, int n, int key){
    int left, mid, right;
    left = 0, right = n;
    mid = (left + right)/2;
    while ((left+1 != mid || mid+1 != right) && mid != left){
        if (key > a[mid]){
            left = mid;
        }else{
            right = mid+1;
        }
        mid = (left + right)/2;
    }
    if (a[left] >= key)return left;
    if (a[mid] >= key)return mid;
    if (a[right] >= key)return right;
    return n;
}

//greatest common divisor
unsigned long gcd(unsigned long x, unsigned long y){
    if (y == 0){ 
        return x;
    }else if (x > y){
        return gcd(y, x % y);
    }else{
        return gcd(x, y % x);
    }
}

unsigned long lcm(unsigned long x, unsigned long y){
    unsigned long g = gcd(x, y);
    return x*y/g;

}



long long factorial(int x){
    long long rtn = 1;
    int i;
    for (i = x; i > 1; i--){
        rtn = (rtn*i);
    }
    return rtn;
}

/*
int struct_ascending_compare(const void *p, const void *q) {
return ((struct_name*)p)->member_name - ((struct_name*)q)->member_name;
}*/

/*unsigned long long pascal[100][100] = {0};
void make_pascal(void){
    for (int i = 0; i < 100; i++){
        pascal[i][0] = 1;
    }
    pascal[1][1] = 1;
    for (int i = 2; i < 100; i++){
        for (int j = 1; j < 100; j++){
           pascal[i][j] = (pascal[i-1][j-1]+pascal[i-1][j]);
        }
    }
}*/
long long mod = 1000000007;
long long fact[200005];
long long inv[200005];

long long mod_pow(long long x, long long n){
    long long res = 1;
    for(int i = 0;i < 60; i++){
        if(n >> i & 1) res = res * x % mod;
        x = x * x % mod;
    }
    return res;
}



int main(void){
    fact[1] = 1;
    inv[0] = 1;
    for (long long i = 2; i < 200005; i++){
        fact[i] = (fact[i-1] * i) % mod; 
    }
    for (int i = 1; i < 200005; i++){
        inv[i] = mod_pow(fact[i], mod-2);
    }
    int h, w, a, b;
    scanf("%d %d %d %d", &h, &w, &a, &b);
    int y = h-a;
    int x = b+1;
    long long ans = 0;

    while (x <= w && 1 <= y){
        long long cmb_a = fact[(x-1)+(y-1)] * inv[x-1] % mod * inv[y-1] % mod;
        long long cmb_b = fact[(w-x)+(h-y)] * inv[w-x] % mod * inv[h-y] % mod;
        long long cmb = cmb_a * cmb_b % mod;
        ans += cmb;
        ans %= mod;
        x++;
        y--;
    }
    printf("%lld\n", ans);

}

Measured memory_bytes: 3328
#include<stdio.h>

int A[1000000],n;

int Search(int key){
  int left=0;
  int right = n;
  int mid;

  while(left < right){
    mid = (left + right)/2;
    if(key == A[mid]) return 1;
    if(key > A[mid]) left = mid + 1;
    else if(key < A[mid]) right = mid;
  }
  return 0;
}

int main( ){
  int i,j,k;
  int sum = 0;

  scanf("%d",&n);
  for(i=0;i < n; i ++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&j);
  for(i=0; i < j; i++){
    scanf("%d",&k);
    if(Search(k)) sum++;
  }

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

  return 0;
}



Measured memory_bytes: 2092
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
	int a,b;
	cin >> a >> b;
	int n1,n2,n3;
	n1=a+b;
	n2=a-b;
	n3=a*b;
	int max1;
	if(n1>n2)
		max1=n1;
	else
		max1=n2;
	if(n3>max1)
		max1=n3;
	cout << max1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef signed long long int ll;

int INFp=1000000007;
const string minusinf ="-";
const int mininf = -1;
int cost[10]={0,
    2
    ,
    5
    ,
    5
    ,
    4
    ,
    5
    ,
    6
    ,
    3
    ,
    7
    ,
    6
};
void chmax(string &a,string b){
    if(a == minusinf) a=b;
    else if(a.size()<b.size()) a=b;
    else if(a.size()==b.size()){
        if(a<b) a=b;
    }
}
int main(){
    int n,m;
    int a[15];
    cin>>n>>m;
    for(int i=0;i<m;i++) cin>>a[i];
    
    sort(a,a+n,greater<int>());
    
    int dp[11050];//i本使うときの最大桁数
    for(int i=0;i<10500;i++) dp[i]=-1;
    dp[0]=0;
    
    for(int i=0;i<10010;i++){
        if(dp[i]>=0){
            for(int j=0;j<m;j++){
                dp[i+cost[a[j]]]=max(dp[i+cost[a[j]]],dp[i]+1);
            }
        }
    }
    
    
    int costcount=n;
    
    int ans[dp[n]+100];
    for(int i=1;i<=dp[n];i++){
        for(int j=0;j<m;j++){
            if(costcount-cost[a[j]]>=0){
                if(dp[costcount-cost[a[j]]]==dp[costcount]-1){
                    ans[i]=a[j];
                    costcount-=cost[a[j]];
                    break;
                }
            }
        }
    }
    for(int i=1;i<=dp[n];i++){
        cout<<ans[i];
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  lol a[n + 5], sum = 0, nasu = 0;
  rep(i, n){
    cin >> a[i];
    if(a[i] % 2 == 1){
      sum ++;
    }
    if(a[i] % 4 == 0){
      nasu ++;
    }
  }
  if(n % 2 == 0){
    if(sum <= nasu){
      cout << "Yes\n";
    } else {
      cout << "No\n";
    }
  } else {
    if(sum - 1 <= nasu){
      cout << "Yes\n";
    } else {
      cout << "No\n";
    }
  }
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INFINITO 1000000000
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )


bool comp( tuple<string, int, int> a, tuple<string, int, int> b ) {
    if ( get<0>(a) == get<0>(b) ) return get<1>(a) > get<1>(b);
    return get<0>(a) < get<0>(b);
}


int main() {

    int n;
    cin >> n;
    vector<tuple<string, int, int>> rests(n);

    fo(i, n) {
        string s;
        int p;
        cin >> s >> p;
        rests[i] = make_tuple(s, p, i + 1);
    }

    sort(all(rests), comp);
    for ( auto t : rests ) cout << get<2>(t) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    int n,i,l,f;
    char s[10000];
    scanf("%d\n",&n);
    gets(s);
    l=strlen(s);
    for(i=0;i<l;i++){
        f=s[i]+n;
        if(f<=90){
            s[i]=f;
        }
        else{
            s[i]=f-26;
        }
    }
    printf("%s",s);
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] h = new int[n];
		int[] dp = new int[n];

		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
			dp[i] = Integer.MAX_VALUE;
		}

		dp[0] = 0;

		for (int i = 1; i < n; i++) {
			dp[i] = Math.min(dp[i], dp[i - 1] + (Math.abs(h[i] - h[i - 1])));
			for (int j = 2; j <= k; j++) {
				if (i - j >= 0) {
					dp[i] = Math.min(dp[i], dp[i - j] + (Math.abs(h[i] - h[i - j])));
				}
			}
		}
		System.out.println(dp[n - 1]);
		sc.close();

	}
}


Measured memory_bytes: 64916
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    long long sum=0,ans=0;
    cin >> N;
    vector<long long> A(N);
    for(int i=0;i<N;i++){
        cin >> A.at(i);
        sum += A.at(i);
    }

    for(int i=0;i<N;i++){
        sum -= A.at(i);
        ans += A.at(i)*(sum%(1000000000+7));
        ans = ans%(1000000000+7);
    }
    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 4772
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    a, b = MAP()
    print(1 + ceil((b-a) / (a-1)))

if  __name__=='__main__':
    main()


Measured memory_bytes: 5136
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static boolean solve() {
		int n = in.nextInt();
		if (n == 0) return false;

		int[] cnt = new int[26];
		boolean f = false;
		for (int i=0; i<n; i++) {
			int p = in.next().charAt(0) - 'A';
			cnt[p]++;
			int[] tmp = Arrays.copyOfRange(cnt, 0, 26);
			Arrays.sort(tmp);
			if (!f && tmp[24] + n-i-1 < tmp[25]) {
				int idx = -1;
				for (int j=0; j<26; j++) {
					if (tmp[25] == cnt[j]) idx = j;
				}
				out.println((char)(idx+'A')+" "+(i+1));
				f = true;
			}
		}

		if (!f) out.println("TIE");

		return true;
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		while(solve());
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

Measured memory_bytes: 51004
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;


int main() {

   int n,temp;
   vector<int> v;
   
   cin>>n;
   
   for(int i=0;i<n;i++){
       cin>>temp;
       v.push_back(temp);
   }
   
   long long sum=0;
   for(int i=0;i<v.size();i++){
       for(int j=i+1;j<v.size();j++){
         sum+=v[i]*v[j];
       }
   }

    cout<<sum;
    return 0;
   
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
	
	static class Cake{
		int s, w, d;
		Cake(int tw, int td){
			w=tw;
			d=td;
			s=w*d;
		}
	}
	
    public static void main(String[] args) {
        try(Scanner sc = new Scanner(System.in)){
            
        	while(sc.hasNext()) {
        		int n=sc.nextInt();
        		int w=sc.nextInt();
        		int d=sc.nextInt();
        		if(n+w+d==0) break;
        		
        		ArrayList<Cake> list=new ArrayList<Cake>();
        		Cake cake=new Cake(w, d);
        		
        		list.add(cake);
        		
        		for(int i=0; i<n; i++) {
        			int p=sc.nextInt();
        			int s=sc.nextInt();
        			Cake cut1, cut2;
        			
        			cake=list.remove(p-1);
        			int cutplace= s%(cake.w + cake.d);
        			
        			if(cutplace > cake.w) {
        				cut1 = new Cake(cake.w, cutplace-cake.w);
        				cut2 = new Cake(cake.w, cake.d - cut1.d);
        			}
        			else {
        				cut1 = new Cake(cutplace, cake.d);
        				cut2 = new Cake(cake.w - cutplace, cake.d);
        			}
        			if(cut1.s < cut2.s) {
        				list.add(cut1);
        				list.add(cut2);
        			}
        			else {
        				list.add(cut2);
        				list.add(cut1);
        			}
        		}
        		int size=list.size();
        		int[] s=new int[size];
        		
        		for(int i=0; i<size; i++) {
        			s[i]=list.get(i).s;
        		}
        		Arrays.sort(s);
        		
        		for(int i=0; i<size; i++) {
        			if(i!=0) System.out.print(" ");
        			System.out.print(s[i]);
        		}
        		System.out.println();
        		
        	}
        	
        	
        	
        }
    }
}



Measured memory_bytes: 44476
#include<bits/stdc++.h>
#define ll long long
#define ull long long
#define mod 1000000007
using namespace std;
ll binpow(ll x,ll y)/* (x^y)%p in O(log y) */{ll res=1;while (y > 0){if(y&1)res=(res*x);y = y>>1;x=(x*x);}return res;}
ll binpowmod(ll x,ll y,ll p)/* (x^y)%p in O(log y) */{ll res=1;x=x%p;while (y > 0){if(y&1)res=(res*x)%p;y = y>>1;x=(x*x)%p;}return res;}
ll mod_inverse(ll n,ll p)/* Returns n^(-1) mod p */{return binpowmod(n,p-2,p);}
ll gcd(ll x,ll y)
{
	if(y==0)
		return x;
	return gcd(y,x%y);
}
bool comp(int x,int y)
{
	return x>y;
}
bool isPowerOfTwo (ll x)  
{  
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));  
}

void swap(int &a,int &b)
{
	a=a+b;
	b=a-b;
	a=a-b;
}

ll cost=1000000000000000;
void solve2(ll n,ll m,ll x,vector<ll> c,vector< vector<ll> > a,ll i,vector<ll> lvl,ll cc)
{
	if(i==n){
		int flag=1;
		for(ll j=0;j<m;j++)
		{
			if(lvl[j]<x) flag=0;
		}
		// check
		if(flag==1)
			cost=min(cost,cc);
		return;
	}
	for(ll j=0;j<m;j++)
	{
		lvl[j]+=a[i][j];
	}
	solve2(n,m,x,c,a,i+1,lvl,cc+c[i]);
	for(ll j=0;j<m;j++)
	{
		lvl[j]-=a[i][j];
	}
	solve2(n,m,x,c,a,i+1,lvl,cc);
}
void solve()
{
	ll n,m,x,i,j;
	cin>>n>>m>>x;
	vector<ll> c(n);
	vector<ll> lvl(m,0);
	vector< vector<ll> > a(n,vector<ll>(m,0));
	for(i=0;i<n;i++)
	{
		cin>>c[i];
		for(j=0;j<m;j++)
			cin>>a[i][j];
	}
	solve2(n,m,x,c,a,0,lvl,0);
	if(cost!=1000000000000000)
		cout<<cost;
	else
		cout<<-1;

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	solve();

}


Measured memory_bytes: 3680
def main():
    N, M = (int(i) for i in input().split())
    SC = [[int(i) for i in input().split()] for j in range(M)]
    for i in range(1000):
        S = str(i)
        if len(S) != N:
            continue
        for s, c in SC:
            if S[s-1] != str(c):
                break
        else:
            return print(S)
    print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
import java.io.*;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        FastScanner in = new FastScanner();
        int n = in.nextInt();
        int k = in.nextInt();
        int cur = 1;
        for (int i = 0; i < n; i++) {
            if (cur < k) {
                cur = cur * 2;
            } else cur += k;
        }
        System.out.println(cur);
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }

        int nextInt() {
            return Integer.parseInt(nextToken());
        }

        long nextLong() {
            return Long.parseLong(nextToken());
        }

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}


Measured memory_bytes: 21332
import java.util.Scanner;

class MathUtil {
	public static void swap(int[] obj, int a, int b) {
		int tmp = obj[a];
		obj[a] = obj[b];
		obj[b] = tmp;
	}
}

class Dice {
	int N=6;
	int ten[] = new int[N+1];

	public Dice(int[] tenkaizu) {
		for(int i=1;i<=N;i++) {
			this.ten[i] = tenkaizu[i-1];
		}
	}

	public int showDice(int number) {
		return ten[number];
	}

	public void printDice() {
	    for(int i=1;i<=N;i++) {
            System.out.print(ten[i] + "\t");
        }
        System.out.println("");
    }

	public void rotate(String meirei) {
		switch (meirei) {
			case "N":
				rotate(1, 2, 6, 5);
				break;
			case "S":
				rotate(5,6, 2, 1);
				break;
			case "E":
				rotate(4, 6, 3, 1);
				break;
			case "W":
				rotate(1, 3, 6, 4);
				break;
		}
	}

	public void rotate(int a, int b, int c, int d) {
		MathUtil.swap(ten, a, b);
		MathUtil.swap(ten, b, c);
		MathUtil.swap(ten, c, d);
	}

	public void rotate(int a, int b, int c) {
		MathUtil.swap(ten, a, b);
		MathUtil.swap(ten, b, c);
	}

	/**
	 * ????????????????????¢??????d?????????
	 * @param d
	 */
	public void topTo(int d) {
		for(int i=0;i<4;i++) {
			rotate("W");
			if(showDice(1) == d) break;
		}
		for(int i=0;i<4;i++) {
			rotate("N");
			if(showDice(1) == d) break;
		}
	}

	public int findRight(int frontD) {
		int[] pos = {4,2,3,5};
		for(int i=0;i<4;i++) {
			if(ten[pos[i]] == frontD) {
				return ten[pos[(i+1)%4]];
			}
		}
		return -1;
	}
}

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String[] men_str = in.nextLine().split(" ");
		int[] men_int = new int[6];
		for (int i = 0; i < 6; i++) {
			men_int[i] = Integer.parseInt(men_str[i]);
		}
		Dice dice = new Dice(men_int);

		int q = in.nextInt();
		for (int i = 0; i < q; i++) {
			int top = in.nextInt();
			int front = in.nextInt();
			dice.topTo(top);
			int ans = dice.findRight(front);
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 26020
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		int x = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if(Math.abs(x-a) > Math.abs(x-b)) {
			System.out.println("B");
		}else {
			System.out.println("A");
		}
		
	}

}


Measured memory_bytes: 22996
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int n; cin>>n;
    vector<T> xl(n);
    for(int i=0; i<n; i++){
        int x, l; cin>>x>>l;
        xl[i] = T(x + l, x, l);
    }

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

    int ans = 1;
    int tail = get<0>(xl[0]);
    for(int i=1; i<n; i++){
        int x = get<1>(xl[i]), l = get<2>(xl[i]);
        int head = x - l;

        if(tail <= head){
            tail = x + l;
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1408
import std.conv, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex, std.typecons;
import core.bitop, core.thread;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) throw new EOFException; tokens = readln.split; } auto token = tokens[0]; tokens.popFront; return token; }
int readInt() { return readToken().to!int; }
long readLong() { return readToken().to!long; }
real readReal() { return readToken().to!real; }

void chmin(T)(ref T t, in T f) { if (t > f) t = f; }
void chmax(T)(ref T t, in T f) { if (t < f) t = f; }

int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = cast(int)(as.length); for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }
int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a < val)); }
int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a <= val)); }


int N, K;
int[] A;

void main() {
  try {
    for (; ; ) {
      N = readInt();
      K = readInt();
      A = new int[N];
      foreach (i; 0 .. N) {
        A[i] = readInt();
      }
      auto dp = new bool[K + 1];
      foreach (x; 0 .. K + 1) {
        foreach (i; 0 .. N) {
          if (x >= A[i] && !dp[x - A[i]]) {
            dp[x] = true;
          }
        }
      }
      writeln(dp[K] ? "First" : "Second");
    }
  } catch (EOFException e) {
  }
}


Measured memory_bytes: 380
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

int main() {
	int n,x=0;
	string w;
	cin>>n;
	w=to_string(n);
	for(int i=0;i<w.size();i++){
		x+=stoi(w.substr(i,1));
	}
	if(n%x==0){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <tuple>
#include <bitset>
#include <utility>
#include <climits>
#include <iomanip>

#define push emplace_back
#define each(i, x) for (auto i=0; i < x; i++)
using ull = unsigned long long;
constexpr auto mod = 1000000007;
constexpr auto INF = ULLONG_MAX;

using namespace std;
template <typename T> inline void dump(const T& x) { cout << "[" << x << "]" << endl; }
template <typename T> inline void dump(const vector<T>& x) { for (const auto v : x) { cout << v << " "; } cout << endl; }
template <typename T> inline void sort_asc(vector<T>& x) { std::sort(x.begin(), x.end()); }
template <typename T> inline void sort_desc(vector<T>& x) { std::sort(x.begin(), x.end(), greater<T>()); }
template <typename T> inline T max_value(vector<T>& x) { return *max_element(x.begin(), x.end()); }
template <typename T> inline T min_value(vector<T>& x) { return *min_element(x.begin(), x.end()); }
template <typename T> inline T sum_value(vector<T>& x) { return accumulate(x.begin(), x.end(), 0ULL); }

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

  string s;
  cin >> s;

  ull result = 0;
  char current = 0x00;
  for (ull i=0; i < s.size(); i++) {
    if (current != s[i]) {
      result++;
      current = s[i];
    }
  }

  cout << result << endl;

  return 0;
}


Measured memory_bytes: 512
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	iv, _ := strconv.Atoi(scanString())
	return iv
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n, m := scanInt(), scanInt()
	xs := make([]int, n)
	for i := range xs {
		xs[i] = -1
	}

	to := 1
	for i := 1; i < n; i++ {
		to *= 10
	}
	from := to*10 - 1
	if n == 1 {
		to = 0
	}

	xm := make(map[int]string)
	for i := 0; i < m; i++ {
		s, c := scanInt(), scanString()
		if v, ok := xm[s]; ok && v != c {
			fmt.Println(-1)
			return
		}
		xm[s] = c
	}

	for i := to; i <= from; i++ {
		str := strconv.Itoa(i)
		found := true
		for s, c := range xm {
			if string(str[s-1]) != c {
				found = false
				continue
			}
		}
		if found {
			fmt.Println(i)
			return
		}
	}
	fmt.Println(-1)
}


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

void exchange(char a, char b, string& S) {
  int n = S.length();
  for (int i = 0; i < n; ++i) {
    if (S[i] == a) {
      S[i] = b;
    } else if (S[i] == b) {
      S[i] = a;
    }
  }
}

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

  for (int i = 0; i < S.length(); ++i) {
    char a = S[i];
    char b = T[i];
    if (a != b) {
      // 操作済みの部分列と同じ文字だったら失敗
      for (int j=0; j<i; ++j) {
        if (S[j] == a || S[j] == b) {
          cout << "No" << endl;
          return 0;
        }
      }
      // そうでなければ操作実行
      exchange(a,b,S);
    }
  }

  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 776
#include <algorithm>
#include <vector>
#include <numeric>
#include <iostream>
using namespace std;
int main() {
    int n, x; cin >> n >> x;
    long long b[n], l[n], u[n];
    for (int i = 0; i < n; i++) cin >> b[i] >> l[i] >> u[i];
    vector<int> v(n);
    iota(v.begin(), v.end(), 0);
    sort(v.begin(), v.end(),
         [&](int i, int j) {
             return (u[i] - l[i]) * b[i] - u[i] * x < (u[j] - l[j]) * b[j] - u[j] * x;
         });
    long long sum = 0;
    for (int i = 0; i < n; i++) sum -= l[i] * b[i];
    long long s[n+1];
    s[0] = sum;
    for (int i = 0; i < n; i++) {
        int j = v[i];
        s[i+1] = s[i] + u[j] * (x - b[j]) + l[j] * b[j];
    }
    // cerr << sum << endl;
    long long ans = 1LL<<60;
    for (int i = 0; i < n; i++) {
        int j = v[i];
        long long add = 1LL<<60;
        if (s[i] >= 0) {
            int k = lower_bound(s, s+i, - l[j]*b[j] - u[j] * (x - b[j])) - s;
            if (s[k] + l[j] * b[j] >= 0) {
                add = (- s[k] + l[j] - 1) / l[j];
            } else {
                long long amt = -(l[j] * b[j] + s[k]);
                add = b[j] + (amt + u[j] - 1) / u[j];
            }
            ans = min(ans, (long long)x * k + max(add, 0LL));
        } else {
            int k = lower_bound(s, s+n, 0) - s;
            long long t = s[k] - l[j] * b[j] - u[j] * (x - b[j]);
            if (t + l[j] * b[j] >= 0) {
                add = (-t + l[j] - 1) / l[j];
            } else {
                long long amt = -(l[j] * b[j] + t);
                add = b[j] + (amt + u[j] - 1) / u[j];
            }
            ans = min(ans, (long long)x * (k-1) + add);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3712
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace At
{
    class Program
    {
        static void Main(string[] args)
        {
            var c = Read();
            switch (c)
            {
                case "a":
                case "i":
                case "u":
                case "e":
                case "o":
                    WriteLine("vowel");
                    break;
                default:
                    WriteLine("consonant");
                    break;

            }
        }
       

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        //最大公約数
        public static int Gcd(int a, int b)
        {
            if (a < b)
            {
                return Gcd(b, a);
            }
            while (b != 0)
            {
                var reminder = a % b;
                a = b;
                b = reminder;
            }
            return a;
        }

        //最小公倍数
        public static int Lcm(int a, int b)
        {
            return a * b / Gcd(a, b);
        }

    }
}


Measured memory_bytes: 11092
#include<stdio.h>
int main()
{
	int w, h, x, y, r;
	scanf("%d %d %d %d %d", &w, &h, &x, &y, &r);
	if((x+r<=w && x-r>=0) && (y+r<=h && y-r>=0))
	{
		printf("Yes\n");	
	}
	else
	{
		printf("No\n");
	}
	
}


Measured memory_bytes: 2144
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<int> vec;

void solve(){
	int n; cin >> n;
	set<int> st;
	rep(i, n) {
		int a; cin >> a;
		if (st.count(a)) {
			st.erase(a);
		}
		else {
			st.insert(a);
		}
	}
	cout << st.size() << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(6);
	//init();
	solve();
	stop
		return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define ll long long 
#define clr(c) memset(c,0,sizeof(c))
#define inf 0x7fffffff
const int mod=1e9+7;
const int M=4e5+5;
const int N=2e5+10;
using namespace std;
inline ll read()
{
	ll sum=0,b=1;char c=getchar();
	while(!isdigit(c)){if(c=='-') b=-1; c=getchar();}
	while(isdigit(c)){sum=sum*10+c-'0';c=getchar();}
	return b*sum;
}
ll t,n,m,k;
ll a,b,c;
ll ans;
int main()
{
	ll A,B;
  	A=read();
  	B=read();
  
  	ll yard;
  	
   	yard=(A*B)-(A+B-1);
  	cout<<yard;
  
  
	
	return 0;
}  

Measured memory_bytes: 256