akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std ;
int main () {
  int N , K ;
  cin >> N >> K;
  int H[N] = {};
  int ans[N]={};
  for(int i = 0 ; i < N; i++) {
    cin >> H[i];
    ans[i]++;
  }
   for(int i = 0; i < K; i++){
     int a, b;
     cin >> a >> b;
     if(H[a-1]==H[b-1]){
       ans[a-1] = ans[b-1] = 0;
     }else if(H[a-1]<H[b-1]){
       ans[a-1] = 0;
     } else {
       ans[b-1] = 0;
     }
   }
  int pre =0;
  for(int i = 0 ; i < N; i++){
    if(ans[i]==1) pre++;
  }
  cout << pre << endl ;
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int dp[5][5][5][5][2];

bool solve(int* ISN, int* NKJ, bool turn = false) {
  int& ret = dp[ISN[0]][ISN[1]][NKJ[0]][NKJ[1]][turn];

  if(ret + 1) return ret;
  if(!turn && ISN[0] + ISN[1] == 0) return false;
  if( turn && NKJ[0] + NKJ[1] == 0) return false;

  ret = 0;

  rep(i, 2) rep(j, 2) {
    if(!ISN[i]) continue;
    if(!NKJ[j]) continue;
    if(!turn) {
      int tmp = NKJ[j];
      NKJ[j] += ISN[i];
      if(NKJ[j] >= 5) NKJ[j] = 0;
      ret |= !solve(ISN, NKJ, !turn);
      NKJ[j] = tmp;
    }
    else {
      int tmp = ISN[i];
      ISN[i] += NKJ[j];
      if(ISN[i] >= 5) ISN[i] = 0;
      ret |= !solve(ISN, NKJ, !turn);
      ISN[i] = tmp;
    }
  }
  return ret;
}

int main() {

  int ISN[2], NKJ[2]; cin >> ISN[0] >> ISN[1] >> NKJ[0] >> NKJ[1];
  minus(dp);
  cout << (solve(ISN, NKJ) ? "ISONO" : "NAKAJIMA") << endl;
  
  return 0;
}

Measured memory_bytes: 3076
def In(): return map(int, raw_input().split())

toll = {}
P=[6,10,12,14,27,33,7,9,12,23,30,5,8,20,27,5,17,26,12,23,10]
H=range(0,1440,60)
c=0
for i in range(0,6):
  for j in range(i+1,7):
    toll[(i,j)] = toll[(j,i)] =P[c]*50
    c += 1
D=[0, 6, 13, 18, 23, 43, 58]

while 1:
  i1 = input()-1
  if i1<0: break
  h1, m1 = In()
  i2 = input()-1
  h2, m2 = In()
  x = toll[(i1, i2)]
  if (1050<=H[h1]+m1<=1170 or 1050<=H[h2]+m2<=1170) and abs(D[i1]-D[i2])<=40:
    x = (x+50)/100*50
  print x

Measured memory_bytes: 4280
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, [ $t:tt ]) => {{
    let len = read_value!($iter, usize);
    (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  }};

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    n: i64,
    a: i64,
    b: i64,
  }
  let l = a + b;
  let cycle = n / l;
  let rem = n % l;

  puts!("{}\n", a * cycle + cmp::min(rem, a));
}


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


int main() {
  int n; cin>>n;
  vector<int> res(4,0);
  
  for(int i=0; i<n; i++){
    string si; cin>>si;
    res[0] += (si=="AC");
    res[1] += (si=="WA");
    res[2] += (si=="TLE");
    res[3] += (si=="RE");
  }
  
  cout<<"AC x "<<res[0]<<endl;
  cout<<"WA x "<<res[1]<<endl;
  cout<<"TLE x "<<res[2]<<endl;
  cout<<"RE x "<<res[3]<<endl;
}


Measured memory_bytes: 3624
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int x[5];
  for(int i = 0; i < 5; ++i) std::cin >> x[i];
  for(int i = 0; i < 5; ++i) if(x[i] == 0) fin(i+1);
  return 0;
}


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

#define REP(i, s, n) for (ll i = s; i < n; i++)
#define setarr(arr, v) for (ll i = 0; i < sizeof(arr)/sizeof(arr[0]); ++i) {arr[i] = v;}
#define pvar(x) cout << #x << " = " << x << endl;
#define mset(x, v) memset(x, v, sizeof(x));
#define fi first
#define se second
#define pb push_back
#define be() begin()
#define en() end()
#define len() length()
#define mp(x, y) make_pair(x, y)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<pll> vpll;
typedef set<ll> sll;
typedef queue<ll> qll;

template<class U, class V>
ostream& operator<<(ostream& os, const pair<U, V>& p) {os << "(" << p.first << ", " << p.second << ")";return os;}

template<class U, class V>
istream& operator>>(istream& in, pair<U, V>& p) {in >> p.first >> p.second;return in;}

namespace cp {
    template <typename T>
    T min (T first) {return first;}
    template <typename T, typename... Args>
    T min (T first, Args... args) {return std::min (first, min (args...));}

    template <typename T>
    T max (T first) {return first;}
    template <typename T, typename... Args>
    T max (T first, Args... args) {return std::max (first, max (args...));}
};

using cp::min;
using cp::max;

int main ()
{
    ll h, n; cin >> h >> n;
    ll A[n]; REP (i, 0, n) cin >> A[i];
    if (accumulate (A, A+n, 0) >= h) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}


Measured memory_bytes: 1024
/*#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include<bits/stdc++.h>
#define ll long long
#define inf 1000000005
#define mod 1000000007
#define put putchar('\n')
#define F(i,a,b) for (int i=(a);i<=(b);i++)
#define D(i,a,b) for (int i=(a);i>=(b);i--)
#define R(i,a,b) for (int i=(a);i<(b);i++)
#define go(i,t) for (int i=head[t];i;i=Next[i])
#define sqr(x) ((x)*(x))
#define re register
#define mp make_pair
#define fi first
#define se second
#define pa pair<int,int>
#define pb push_back
#define be begin()
#define en end()
#define ret return puts("-1"),0;
#define N 3055
//#define int ll
using namespace std;
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){char c=getchar();int tot=1;while ((c<'0'|| c>'9')&&c!='-') c=getchar();if (c=='-'){tot=-1;c=getchar();}
int sum=0;while (c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}return sum*tot;}
inline void wr(int x){if (x<0) {putchar('-');wr(-x);return;}if(x>=10)wr(x/10);putchar(x%10+'0');}
inline void wrn(int x){wr(x);put;}inline void wri(int x){wr(x);putchar(' ');}
inline void wrn(int x,int y){wri(x);wrn(y);}inline void wrn(int a,int b,int c){wri(a);wrn(b,c);}
int n,m,ans,a[N],q,f[N][N],x,y;
inline void add(int &x,int k){x+=k;x-=(x>=mod)?mod:0;}
int ksm(int x,int k){
	int sum=1;
	while (k){
		if (k&1) sum=(ll)sum*x%mod;
		x=(ll)x*x%mod;
		k>>=1;
	}
	return sum;
}
signed main(){
	n=read();q=read();
	F(i,1,n) a[i]=read();
	F(i,1,n){
		F(j,1,n) f[i][j]=(a[i]>a[j]);
	}
	int inv2=ksm(2,mod-2),num=ksm(2,q);
	while (q--){
		x=read();y=read();
		if (x==y) continue;
		add(f[x][y],f[y][x]);
		f[x][y]=f[y][x]=1LL*f[x][y]*inv2%mod;
		F(i,1,n){
			if (i==x||i==y) continue;
			add(f[i][x],f[i][y]);
			f[i][y]=f[i][x]=1LL*f[i][x]*inv2%mod;
			add(f[x][i],f[y][i]);
			f[y][i]=f[x][i]=1LL*f[x][i]*inv2%mod;
		}
	}
	F(i,1,n){
		F(j,i+1,n){
			add(ans,1LL*f[i][j]*num%mod);
		}
	}
	wrn(ans);
	return 0;
}

Measured memory_bytes: 36096
#include<bits/stdc++.h>
#define int long long
#define mod 1e18+10
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
int32_t main() {
	int n;
	cin>>n;
	int div=n/1.08;
	//cout<<"div is "<<div<<"\n";
	if(((int)div*1.08)==n)
	{	cout<<div;
		return 0;
	}
	div++;
	//cout<<"div is "<<div<<"\n";
	
	if(((int)(div*1.08))==n)
	{	cout<<div;
		return 0;
	}
	cout<<":(";
}	


Measured memory_bytes: 256
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

using ll=long long;
const int nax=57;
ll mod;

int n=50;

ll pot[nax][nax];

ll wyn;

int jeszrz[nax];
int jeszkol[nax];

void ff()
{
	fflush(stdout);
}

int pyt(int a, int b, int x, int y)
{
	printf("? %d %d %d %d\n", a, x, b, y);
	ff();
	int v;
	scanf("%d", &v);
	return v;
}

int los(int a, int b)
{
	return (rand()%(b-a+1))+a;
}

void szuk(int a, int b, int x, int y, int w)
{
	if (!w)
		return;
	if (!jeszrz[a])
	{
		szuk(a+1, b, x, y, w);
		return;
	}
	if (!jeszrz[b])
	{
		szuk(a, b-1, x, y, w);
		return;
	}
	if (!jeszkol[x])
	{
		szuk(a, b, x+1, y, w);
		return;
	}
	if (!jeszkol[y])
	{
		szuk(a, b, x, y-1, w);
		return;
	}
	if (w==(b-a+1)*(y-x+1))
	{
		for (int i=a; i<=b; i++)
		{
			for (int j=x; j<=y; j++)
			{
				wyn+=pot[i][j];
				jeszrz[i]--;
				jeszkol[j]--;
			}
		}
		return;
	}
	if (x==y || (a!=b && (rand()&1)))
	{
		int s=(a+b)>>1;
		//~ int s=los(a, b-1);
		int p=pyt(a, s, x, y);
		if (rand()&1)
		{
			szuk(a, s, x, y, p);
			szuk(s+1, b, x, y, w-p);
		}
		else
		{
			szuk(s+1, b, x, y, w-p);
			szuk(a, s, x, y, p);
		}
	}
	else
	{
		int s=(x+y)>>1;
		//~ int s=los(x, y-1);
		int p=pyt(a, b, x, s);
		if (rand()&1)
		{
			szuk(a, b, x, s, p);
			szuk(a, b, s+1, y, w-p);
		}
		else
		{
			szuk(a, b, s+1, y, w-p);
			szuk(a, b, x, s, p);
		}
	}
}

int main()
{
	int szit;
	scanf("%d%d%d%lld", &szit, &szit, &szit, &mod);
	ll trz=1;
	for (int i=0; i<n; i++)
	{
		for (int j=0; j<n; j++)
		{
			pot[i][j]=trz;
			trz=(trz*2)%mod;
		}
	}
	for (int i=0; i<n; i++)
	{
		jeszrz[i]=pyt(i, i, 0, n-1);
		jeszkol[i]=pyt(0, n-1, i, i);
	}
	szuk(0, n-1, 0, n-1, 250);
	printf("! %lld\n", wyn%mod);
	ff();
	return 0;
}


Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
long long f[402][402];
long long a[402];
long long sum[402];
int main()
{
	int n,i,j,k;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		sum[i]=sum[i-1]+a[i];	
	}
	for(j=1;j<=n-1;j++)	
	{
		for(i=1;i+j<=n;i++)
		{
			f[i][i+j]=std::numeric_limits<long long>::max();
			for(k=i;k<i+j;k++)
			{
				f[i][i+j]=min(f[i][i+j],f[i][k]+f[k+1][i+j]+sum[i+j]-sum[i-1]);	
			}
		}
	}
	printf("%lld",f[1][n]);
	return 0;
}

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

ll solve() {
    ll N, a;
    cin >> N;
    vector<ll> X(1e5+2);
    for ( int i = 0; i < N; i++ ) {
        cin >> a;
        X[a]++;
        X[a+1]++;
        X[a+2]++;
    }
    sort(X.begin(), X.end(),greater<>());
    return X[0];
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
ll a[300000];
ll cnt[61];
ll pw[61];
int main()
{
	int n;
	ll ans=0;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	//それぞれの桁を調べる
	fill(cnt,cnt+64,0LL);
	for(int i=0;i<n;i++)
	{
		for(ll j=0;j<61;j++)
		{
			if(a[i]&(1LL<<j))
				cnt[j]++;
		}
	}
	for(int i=0;i<61;i++)
	{
		pw[i]=(1LL<<(ll)i)%MOD;
	}
	for(int i=0;i<61;i++)
	{
		//cerr<<(1LL<<(ll)i)<<" "<<cnt[i]<<endl;
		ll tmp=pw[i]*cnt[i];
		tmp%=MOD;
		tmp*=((ll)n-cnt[i]);
		tmp%=MOD;
		ans+=tmp;
		ans%=MOD;
	}
	cout<<ans<<endl;
	return 0;
}

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

int n,s,d[12][12],b[12][12],a[12][12];
int dx[] = { 0,0,0,1,-1};
int dy[] = {-1,1,0,0, 0};

void flip(int x, int y)
{
	a[y][x] = 1;
	for(int i=0; i<5; i++)
	{
		b[y+dy[i]][x+dx[i]] = 1-b[y+dy[i]][x+dx[i]];
	}
}

void func()
{
	for(int i=0; i<1024; i++)
	{
		memset(a,0,sizeof(a));
		memcpy(b,d,sizeof(d));

		for(int y=1,x=1; x<=10; x++)
		{
			if((i>>(x-1))&1) flip(x,y);
		}

		for(int y=2; y<=10; y++)
		for(int x=1; x<=10; x++)
		{
			if(b[y-1][x]) flip(x,y);
		}

		s=0;
		for(int y=10,x=1; x<=10; x++)
		{
			s+=b[y][x];
		}

		if(s==0) return;
	}
}

int main()
{
	cin >> n;
	while(n--)
	{
		for(int y=1; y<=10; y++)
		for(int x=1; x<=10; x++)
		{
			cin >> d[y][x];
		}

		func();

		for(int y=1; y<=10; y++)
		{
			for(int x=1; x<=10; x++)
			{
				cout << a[y][x] << (x==10?"":" ");
			}
			cout << endl;
		}
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
using namespace std;
int main(){
  int N;
  string S;
  cin >> N >> S;
  for(int i = 0; i < S.size(); i++){
    S[i] = (S[i] - 'A' + N) % 26 + 'A';
  }
  cout << S << endl;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define gcd __gcd
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define twod(mat,i,j,n,m) rep(i,n){rep(j,m)in(mat[i][j]);}
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
#define pr(n) printf("%d",n)
#define out(n) printf("%d\n",n)
#define llin(a) cin >> a
#define llpr(a) cout << a << " "
#define llout(a) cout << a << endl
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
#define DEBUG(x) cout << #x << " : " << x << endl;
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define ck printf("continue\n")
#define all(vec) vec.begin(),vec.end()
#define asc(vec) sort(vec.begin(),vec.end())
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define M 1000000007
#define N 1005
typedef long long int ll;
int main()
{
    int n,m,i,j,a,b;
    in2(n,m);
    in2(a,b);
    int x=0;
    rep(i,n)
    {
        if(i==b)
            x=1-x;
        rep(j,a)
            pr(x);
        lp(j,a,m)
            pr(1-x);
        lin;
    }
}
// read the constraint properly (ll vs int)


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

int roop(vector<int> vec){
  int check = 0;
  int count = 1;
  for(int i=0; i<vec.size(); i++){
    if(vec.at(i)%2==0){
      check +=1;
    }
    else{
      return 0;
      break;
    }
  }
  if(check==vec.size()){
    for(int i=0; i<vec.size(); i++){
      vec.at(i) = vec.at(i)/2;
    }
    count += roop(vec);
  }
  return count;
}

int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  int count = 0;
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  cout << roop(vec); 
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
@SuppressWarnings("resource")
public static void main(String[] args) {
	Scanner sc =new Scanner(System.in);
	int N=sc.nextInt();
	int X= (int) (N/1.08);
	for(int i=X;;i++) {
		if(i*1.08>=N&&i*1.08<N+1) {
			System.out.println(i);
			System.exit(0);
		}else if(i*1.08>=N+1){
			System.out.println(":(");
			System.exit(0);
		}
	}

}
}

Measured memory_bytes: 23252
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,a) FOR(i,0,a)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define sz size() 
#define MP make_pair
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
 
const static ll INF = 1e18;
 
struct edge{
  ll from,to,cost,cap,rev;
  edge(ll a,ll b,ll c,ll d,ll e)
    :from(a),to(b),cost(c),cap(d),rev(e){}
};
 
//Based on Dijkstra (using potential)
struct minFlow{
  ll v;
  vector< vector<edge> > graph;
  vll d,use,h,pv,pe;
  
  minFlow(ll n):v(n){
    graph = vector< vector<edge> >(n);
    pv.resize(v); pe.resize(v);
  }
 
  void add(ll s,ll g,ll c,ll p){
    graph[s].pb(edge(s,g,c,p,graph[g].sz));
    graph[g].pb(edge(g,s,-c,0,graph[s].sz-1));
  }
 
  void cal(ll s, ll t, vll &w, vll &b, vll &x){
    ll cost = 0, flow = 0;
    x.pb(0);
 
    h = vll(v,0);
    while(1){
      priority_queue<pll ,vector<pll> ,greater<pll> > q;
      d = vll(v,INF);
      d[s] = 0; q.push(MP(0,s));
      while(q.sz){
	pll p = q.top();q.pop();
	ll u = p.second;
	if(d[u] < p.first)continue;
	rep(i,graph[u].sz){
	  edge &e = graph[u][i];
	  if(e.cap>0 && d[e.to] > d[u] + e.cost + h[u] - h[e.to]){
	    d[e.to] = d[u] + e.cost + h[u] - h[e.to];
	    pv[e.to] = u; pe[e.to] = i;
	    q.push(MP(d[e.to],e.to));
	  }
	}
      }
      if(d[t]==INF)return;
      rep(u,v)h[u] += d[u];
 
      ll f = INF;
      for(int u=t;u!=s;u=pv[u])f = min(f,graph[pv[u]][pe[u]].cap);
      flow += f;
 
      w.pb(h[t]);
      b.pb(cost);
      x.pb(flow);
 
      cost += f*h[t];
 
      for(int u=t;u!=s;u=pv[u]){
	edge &e = graph[pv[u]][pe[u]];
	e.cap -= f; graph[u][e.rev].cap += f;
      }
    }
  }
};
 
bool Less(ll u1, ll d1, ll u2, ll d2){
  // u1/d1 < u2/d2
  ll p1 = u1/d1, q1 = u1%d1, p2 = u2/d2, q2 = u2%d2;
  if(p1!=p2)return p1<p2;
  return q1*d2 < q2*d1;
}
 
int main(){
  ll n,m,s,t;
  scanf("%lld %lld %lld %lld",&n,&m,&s,&t); s--; t--;
  minFlow mf(n);
  rep(i,m){
    ll a,b,u,c;
    scanf("%lld %lld %lld %lld",&a,&b,&u,&c); a--; b--;
    mf.add(a,b,c,u);
  }
 
  vector<ll> a,b,x;
  mf.cal(s,t,a,b,x);
  ll M = x.back();  
 
  ll ansu = INF, ansd = 1;
  rep(i,b.size()){
    ll b1 = b[i], f1 = M-x[i];
    ansu = min(ansu, b1*b1 + f1*f1);
    ll b2 = b[i] + a[i]*(x[i+1]-x[i]), f2 = M - x[i+1];
    ansu = min(ansu, b2*b2 + f2*f2);
  }
 
  rep(i,b.size()){
    ll xu = M - a[i]*b[i] + a[i]*a[i]*x[i], xd = a[i]*a[i]+1;
    if(Less(xu,xd,x[i],1) || Less(x[i+1],1,xu,xd))continue;
 
    ll tmpu = (a[i]*M+b[i]-a[i]*x[i])*(a[i]*M+b[i]-a[i]*x[i]), tmpd = xd;
    if(Less(tmpu,tmpd,ansu,ansd)){
      ansu = tmpu; ansd = tmpd;
    }
  }
 
  if(a.empty()){
    ansu = 0; ansd = 1;
  }
 
  ll gcd = __gcd(ansu,ansd);
  printf("%lld/%lld\n",ansu/gcd, ansd/gcd);
}

Measured memory_bytes: 3396
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<limits>
#include<list>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0;i < (n); ++i)

int main() {
	int a;
	cin >> a;
	cout << a + pow(a, 2) + pow(a, 3) << endl;

	return 0;
}

Measured memory_bytes: 4248
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce, lru_cache  # @lru_cache(None)
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return (int(x) for x in input().split())
def LI(): return list(Is())
def TI(): return tuple(Is())
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(S())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

n = I()
AB = []
A = []
B = []
for _ in range(n):
    a, b = Is()
    A.append(a)
    B.append(b)
    AB.append((a, b))
A.sort()
B.sort()
if n % 2 == 1:
    print(B[n//2]-A[n//2]+1)
    exit()
l = (A[n//2-1]+A[n//2])/2
r = (B[n//2-1]+B[n//2])/2
print(int((r-l)*2+1))


Measured memory_bytes: 115104
N_str = input()
N = int(N_str)
ans = 0
for i in range(len(N_str)):
  cand = 0
  tmp = '9'*i + N_str[i] + '9'*(len(N_str)-i-1)
  if int(tmp) <= N:
    cand = int(tmp)
  else:
    if int(N_str[i]) >= 1:
      tmp = '9'*i + str(int(N_str[i])-1) + '9'*(len(N_str)-i-1)
    if  int(tmp) <= N:
      cand = int(tmp)
  ans = max(ans, sum([int(l) for l in str(cand)]))
print(ans)

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

using ll = long long;

#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (int)(a.size())
#define clr(a, b) memset(a, b, sizeof(a))
#define REP(i, a, b) for(int i=(int)(a); i<(int)(b); ++i)
#define REPD(i, a, b) for(int i=(int)(a)-1; i>=(int)(b); --i)

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

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

const int NX = 1e5 + 5;

int N, M;
vector<int> adj[NX];
int used[NX], p[NX];

vector<int> num;
map<int, int> pos;

void dfs(int node) {
    if(used[node])
        return;
    used[node] = 1;
    num.pb(p[node]);
    pos[node] = 1;
    for(int x: adj[node]) {
        dfs(x);
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N >> M;

    REP(i, 0, N) {
        cin >> p[i];
        --p[i];
    }

    REP(i, 0, M) {
        int x, y;
        cin >> x >> y;
        --x, --y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    int res = 0;
    REP(i, 0, N) {
        if(!used[i]) {
            pos.clear();
            num.clear();
            dfs(i);
            for(int x: num) 
                if(pos[x]) ++res;
        }
    }
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 19600
n, m = map(int, input().split())
AB = []
for i in range(n):
    a, b = map(int, input().split())
    AB.append((a, b))

AB.sort()
ans = 0
for a, b in AB:
    if b <= m:
        ans += a*b
        m -= b
    else:
        ans += a*m
        m = 0
    if m == 0:
        break
print(ans)


Measured memory_bytes: 78900
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a;
  cin>>a;
  int n[a+1],m[a+1],o[a+1];
  for(int i=0;i<a;i++)
    cin>>n[i]>>m[i]>>o[i];
  int dp[a+1][3];
  dp[0][0]=n[0];
  dp[0][1]=m[0];
  dp[0][2]=o[0];
  if(a>1)
    {
        dp[1][0]=max(n[1]+m[0],n[1]+o[0]);
        dp[1][1]=max(m[1]+n[0],m[1]+o[0]);
        dp[1][2]=max(o[1]+n[0],o[1]+m[0]);
    }
  for(int i=2;i<a;i++)
  {
    dp[i][0]=max(dp[i-1][1]+n[i],dp[i-1][2]+n[i]);
    dp[i][1]=max(dp[i-1][0]+m[i],dp[i-1][2]+m[i]);
    dp[i][2]=max(dp[i-1][0]+o[i],dp[i-1][1]+o[i]);
  }
  cout<<max(dp[a-1][0],max(dp[a-1][1],dp[a-1][2]));
}

Measured memory_bytes: 2560
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PI 3.1415926535897932384626433832795
#define endl "\n"
#define int long long
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const long long MOD = 998244353;
pair<int,int> dx[4] = {{1,0},{-1,0},{0,1},{0,-1}};
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct chash {int operator()(int x) const { return x ^ RANDOM; }};
string toString(long long x){stringstream ss;ss << x;string str = ss.str();return str;}
long long fastpow(long long x,long long k){if(!k)return 1;if(k & 1)return ((x * fastpow(x,k-1) % MOD) % MOD) % MOD;
long long ans = fastpow(x,k/2);ans %= MOD;ans *= ans;ans %= MOD;return ans;}
long long sumF(long long x){int s = 0;while(x)s += x%10,x /= 10;return s;}
bool isS(char c){return (c >= 'a' && c <= 'z');}
bool isB(char c){return (c >= 'A' && c <= 'Z');}
bool isD(char c){return (c >= '0' && c <= '9');}
bool isSqrt(long long x){ long long f = sqrt((long double)x + 0.5); return f*f == x;}
bool isCubic(long long x) {long long f = cbrt((long double)x + 0.5); return f*f*f == x;}
long long lcm(long long a,long long b){return a * (b / __gcd(a,b));}
vector<long long> divisorsVector(long long x){vector<long long> tmp;for(long long i = 1;1LL*i*i <= x;i++){if(x % i == 0){tmp.push_back(i);if(x / i != i)
tmp.push_back(x / i);}}sort(tmp.begin(),tmp.end());return tmp;}
long long countDiv(long long L,long long R,long long C){return ((R/C) - ((L-1)/C));}
int random_int(int l,int r){return uniform_int_distribution<int>(l,r)(rng);}
long long ADDMOD(long long x,long long y){return (x % MOD + y % MOD) % MOD;}
long long MULMOD(long long x,long long y){return (x % MOD * y % MOD) % MOD;}
long long DIFFMOD(long long x,long long y){return (((x % MOD - y % MOD) % MOD) + MOD) % MOD;}
long long FACMOD(long long x){if(x == 0) return 1;return (x * (FACMOD(x - 1) % MOD));}
int arr[3005];
long long dp[3005][3005];
int32_t main()
{
    IO;
    int n;
    cin >> n;
    for(int i = 1;i <= n;i++)
        cin >> arr[i];
    for(int i = n;i >= 1;i--)
    {
        for(int j = i;j <= n;j++)
        {
            if(((i-1)+(n-j)) % 2 == 0)
                dp[i][j] = max(arr[i] + dp[i+1][j],arr[j] + dp[i][j-1]);
            else
                dp[i][j] = min(-arr[i] + dp[i+1][j],-arr[j] + dp[i][j-1]);
        }
    }
    cout << dp[1][n];
    return 0;
}


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

int main() {
	int n,sum=0;
	std::cin >> n;

	std::vector<int> v(n);
	for (int& x : v) {
		std::cin >> x;
	}

	std::vector<int> c(n);
	for (int& x : c) {
		std::cin >> x;
	}

	std::vector<int> p(n);
	
	for (int i = 0; i < n; i++) {
		p[i] = v[i] - c[i];
	}

	std::sort(p.begin(), p.end());

	for (int i = 0; i < n; i++) {
		if (p[i] > 0) {
			sum += p[i];
		}
	}


	std::cout << sum << std::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);

		for (int i = 1; i < 6; i++) {
			if(sc.nextInt() == 0) {
				System.out.println(i);
				break;
			}
		}
	}

}


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


if a[n[1]-1] == "A":
    a[n[1]-1] = "a"
if a[n[1]-1] == "B":
    a[n[1]-1] = "b"
if a[n[1]-1] == "C":
    a[n[1]-1] = "c"
    
ch = ""
for i in a:
    ch += str(i)
print(ch)

Measured memory_bytes: 38256
#include <iostream>
#include <string>
#include <queue>
#include <algorithm>
#include <numeric>
#include <math.h>
using namespace std;
int n;
string s[205];
int y[205];
int solve(int i) {
	queue<int> rue;
	rue.push(i);
	int d[205];
	for (int i = 0; i < n; i++)d[i] = -1;
	d[i] = 1;
	while (!rue.empty()) {
		int r = rue.front();
		rue.pop();
		for (int j = 0; j < n; j++) {
			if (s[r][j] == '1' && d[j] == -1) {
				rue.push(j);
				d[j] = d[r] + 1;
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans = max(d[i], ans);
	}
	return ans;
}
bool solve2(int i) {
	queue<int> rue;
	rue.push(i);
	int d[205];
	for (int i = 0; i < n; i++)d[i] = -1;
	d[i] = 1;
	while (!rue.empty()) {
		int r = rue.front();
		rue.pop();
		for (int j = 0; j < n; j++) {
			if (s[r][j] == '1'&&d[j]==-1 ) {
				rue.push(j);
				d[j] = (d[r] + 1)%2;
			}
			if (s[r][j] == '1' && d[r] == d[j]) {
				return false;
			}
		}
	}
	return true;
}
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	for (int i = 0; i < n; i++) {
		int an = 0;
		for (int j = 0; j < n; j++) {
			if (s[i][j] == '1')an++;
		}
		y[i] = an;
	}
	queue<int> que;
	que.push(0);
	bool tt[205];
	for (int i = 0; i < n; i++) {
		tt[i] = false;
	}
	tt[0] = true;
	while (!que.empty()) {
		int r = que.front();
		que.pop();
		for (int i = 0; i < n; i++) {
			if (s[r][i] == '1' && tt[i] == false) {
				que.push(i);
				tt[i] = true;
			}
		}
	}
	if (!solve2(0)) {
		cout << -1;
		return 0;
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans = max(ans, solve(i));
	}
	cout << ans;
}

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

int main(){
	int a, b, c; cin >> a >> b  >> c;
	
	if(b - a == c - b) cout << "YES" << endl;
	else cout << "NO" << endl;
	
	return 0;
}


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

int main(){
  int n;
  map<int, int> mp;
  cin >> n;
  for(int i=1;i<n;i++){
    int tmp;
    cin >> tmp;
    mp[tmp]++;
  }

  for(int i=0;i<n;i++){
    cout << mp[i+1] << endl;
  }

  return 0;
}


Measured memory_bytes: 12976
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
       
        String[] list = {"a", "i", "u", "e", "o"};
      
		// 文字列の入力
		String s = sc.next();
        String ans = "consonant";
        for(String vowel : list) {
          if (vowel.equals(s)) {
            ans = "vowel";
            break;
          }
        }
    
		// 出力
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
n, k = map(int, input().split())
A = list(map(lambda x: int(x)-1, input().split()))

history = [-1]*n
cur = 0
for i in range(n):
    if history[cur] != -1:
        init_cnt = history[cur]
        loop_cnt = i - history[cur]
        break
    history[cur] = i
    cur = A[cur]

loop = k if k <= init_cnt else init_cnt+((k-init_cnt) % loop_cnt)
print(history.index(loop)+1)

Measured memory_bytes: 32188
#include<stdio.h>
#include<stdlib.h>

int gcd(int,int);
void swap(int *,int *);

int main() {
  int i,x,y,w;
  int n = 1;
  scanf("%d%d",&x,&y);

  for(i = 0; i < 9; i++) {
    n = n * 10;
  }

  if(x < 1 || x > n || y > n || y < 1) {
    exit(1);
  }

  printf("%d\n",gcd(x, y));
  return 0;
}

int gcd(int x, int y) {
  int z;
  if(x < y) {
    swap(&x, &y);
  }
  while(y > 0) {
    z = x % y;
    x = y;
    y = z;
  }
  return x;
}

void swap(int *x, int *y) {
  int data;
  data = *x;
  *x = *y;
  *y = data;
}


  



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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    ll n,m;

    Scll2(n,m);

    if( n > 1 && m > 1){
        n-=2; m-=2;
        printf ("%llu\n", n*m);
    }else{
        if( n == 1 && m == 1){
            printf ("%llu\n", 1);
        }else
        if( n == 1 ){
            printf ("%llu\n", m-2);
        }else
        if( m == 1 ){
            printf ("%llu\n", n-2);
        }
    }

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007
int main()
{
	fast;
	ll n,sum=0,sum1=0,ans=INT_MAX;
	cin>>n;
	ll arr[n];
	for(int i =0;i<n;i++)
		cin>>arr[i],sum+=arr[i];
	for(int i=0;i<n-1;i++)
	{
		sum1+=arr[i];
		if(abs(2*sum1-sum)<ans)
			ans=abs(2*sum1-sum);
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3652
import java.util.Scanner;

class Main{


	public static void main(String[] a){

		Scanner sc = new Scanner(System.in);






		while(sc.hasNext()) {
			int n = sc.nextInt();

			if(n == 0) {break;}



			int[][] data = new int[n+1][n+1];


			for(int i = 0; i < n; i++) {
				int sum = 0;
				for(int j = 0; j < n; j++) {

	 					data[i][j] = sc.nextInt();
	 					sum += data[i][j];
				}
				data[i][data.length -1] = sum;
			}

			for(int i = 0; i < n; i++) {
				int sum = 0;
				for(int j = 0; j < n; j++) {

	 					sum += data[j][i];
				}
				data[data.length -1][i] = sum;
			}

			int sum = 0;
			for(int i = 0; i < data.length; i++) {

				sum += data[data.length -1][i];
			}
			data[data.length -1][data.length -1] = sum;


			for(int i = 0; i < data.length; i++) {
				String str = "";
				for(int j = 0; j < data.length; j++) {

	 				str += String.format("%5s",data[i][j]);

				}
				System.out.println(str);
			}

		}



	}
}

Measured memory_bytes: 31912
N = int(input())
c = list(map(int, input().split(" ")))
cnt1 = c[-1]
for i in range(N-1):
  cnt1 += min(c[N-i-2],c[N-i-3])
c = c[::-1]
cnt2 = c[-1]
for i in range(N-1):
  cnt2 += min(c[N-i-2],c[N-i-3])
print(max(cnt1,cnt2))

Measured memory_bytes: 3064
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
using std::max;
using ll = long long;

ll n, m;
ll w[200005];
ll t[200005];
ll c[16], b[16];
ll ws[200005];
ll ts[200005];
ll dp[1 << 15];

int main() {
	cin >> m >> n;
	for (int i = 0; i < m; i++) {
		cin >> w[i] >> t[i];
		
		ws[i + 1] = ws[i] + w[i];
		ts[i + 1] = ts[i] + t[i];
	}
	ws[m + 1] = ts[m + 1] = 1ll << 60ll;
	
	for (int i = 0; i < n; i++) {
		cin >> c[i] >> b[i];
	}
	
	for (int i = 0; i < (1 << n); i++) {
		for (int j = 0; j < n; j++) {
			if (i & (1 << j)) continue;
			
			ll valid = dp[i];
			ll invalid = m + 1;
			ll mid;
			
			while (invalid - valid > 1) {
				mid = (invalid + valid) / 2;
				
				if (ws[mid] - ws[dp[i]] <= c[j] &&
					ts[mid] - ts[dp[i]] <= b[j]) {
					valid = mid;
				}
				else {
					invalid = mid;
				}
			}
			
			dp[i | (1 << j)] = max(valid, dp[i | (1 << j)]);
		}
	}
	
	cout << dp[(1 << n) - 1] << endl;
	
	return 0;
}



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

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

  set<int> S;
  for (int i = 1; i <= 9; i++) {
    for (int j = 1; j <= 9; j++) {
      S.insert(i * j);
    }
  }

  if (S.count(N)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#!/usr/bin/env python

from collections import deque, defaultdict
import itertools as ite
import sys
import math
from decimal import *

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N, M = map(int, raw_input().split())
s = []
c = []
for i in range(M):
    s_, c_ = map(int, raw_input().split())
    s += [s_]
    c += [c_]

for num in range(1000):
    if len(str(num)) != N:
        continue
    ls = map(int, list(str(num)))
    flag = True
    for i in range(M):
        if ls[s[i] - 1] != c[i]:
            flag = False
    if flag:
        print num
        exit()

print -1

Measured memory_bytes: 4268
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N;
	cin >> N;
	long long x = 0;
	for(int i = 0; i < N; i++) {
		int a;
		cin >> a;
		x ^= a;
	}
	cout << ((x == 0) ? "Yes\n" : "No\n");
	return 0;
}

// look at my code
// my code is amazing


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		while(true) {
			String cards = sc.next();
			if(cards.equals("-")) break;
			int shuffleNum = sc.nextInt();

			StringBuilder sb = new StringBuilder(cards);
			for(int i=0; i<shuffleNum; i++) {
				int h = sc.nextInt();
				String cutStr = sb.substring(0, h);
				sb.delete(0, h);
				sb.append(cutStr);
			}
			System.out.println(sb.toString());
		}

		sc.close();

	}

}


Measured memory_bytes: 26204
#include<bits/stdc++.h>
using namespace std;
int main(){
int k,s;
cin >> k >> s;
int df = 0;
for(int x = 0;x <= k;x++){
    for(int y = 0;y <= k && x + y <= s;y++){
            if(x + y + k >= s){
                df++;
            }
        }
    }
cout << df << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B___Count_Balls
{
    class Program
    {
        static void Main(string[] args)
        {
            var N_A_B = Console.ReadLine().Split().Select(ulong.Parse).ToArray();
            ulong N = N_A_B[0], A = N_A_B[1], B = N_A_B[2];
            ulong div = N / (A + B), mod = N % (A + B);

            Console.WriteLine((div * A) + (Math.Min(A, mod)));
        }
    }
}


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

int main(){
    int n;
    cin >> n;
    if(n/100 == 7){
        cout << "Yes";
    }else if(n%100/10 == 7){
        cout << "Yes";
    }else if (n%10 == 7)
    {
        cout << "Yes";
    }else{
        cout << "No";
    }
    
    return 0;
}

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

int main(){
    string s;
    cin>>s;
    int ans=0,j=0;
    for(int i=0;i<3;i++){
        if(s[i]=='R'){
            j++;
        }
        else{
            j=0;
        }
        ans=max(ans,j);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3588
from heapq import heapify, heappop, heappush
N,M = map(int, input().split())
AB = []
for i in range(N):
    a,b = map(int, input().split())
    if a<=M:
        AB.append((a,-b))
    else:
        N-=1
AB.sort()

Q = []
ans = 0
i = 0

for day in range(M):
    while i<N and AB[i][0] == day+1:
        heappush(Q, AB[i][1])
        i+=1
    if Q:
        ans -= heappop(Q)
print(ans)


Measured memory_bytes: 17664
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

signed main(){

	lli n,a,b;
	cin>>n>>a>>b;

	cout<<min(n*a,b)<<endl;

	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll a,b; cin>>a>>b;
    string as,bs;
    as=to_string(a);
    bs=to_string(b);
    string ass,bss;
    rep(i,b){
        ass+=as;
    }
    rep(i,a){
        bss+=bs;
    }
    cout<< ( ass<bss ? ass : bss )<<"\n";
}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18

using namespace std;

int main(void){
  ll n, k;
  cin >> k >> n;
  
  vector<ll> a(n);
  for (int i = 0; i < n; i++){
    cin >> a[i];
  }

  ll m = a[0] + k - a[n-1];
  for (int i = 0; i < n-1; i++){
    m = max(m, a[i+1] - a[i]);
  }

  cout << k - m << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll n, c, k;
  cin >> n >> c >> k;
  vector<ll> t(n);
  for(int i=0;i<n;i++)
    cin >> t[i];
  sort(t.begin(), t.end());
  ll val = t[0];
  ll ans = 1, cnt = 1;
  for(int i=1;i<n;i++) {
    cnt++;
    if(t[i] > val + k || cnt > c) {
      val = t[i];
      ans++;
      cnt = 1;
    }
  }
  cout << ans << endl;

}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rept(i,k,n) for(int i = (k); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Sort(v) sort(v.begin(),v.end(),[](int a, int b) { return a > b; })
#define Reverse(v) reverse(v.begin(),v.end())

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<long long,long long> Pll;

int main() {
    int n,x,y;
    cin>>n>>x>>y;
    x--;y--;
    vector<int> k(n,0);
    rep(i,n-1){
        rept(j,i+1,n){
            k[min(j-i,abs(x-i)+abs(y-j)+1)]++;
        }
    }
    rept(i,1,n) cout<<k[i]<<endl;
}


Measured memory_bytes: 256
n = int(input())
l = []
for i in range(1,n+1):
    s,p = input().split()
    t = [s,int(p),i]
    l.append(t)
l.sort()
def check(m,i):
    z = list(l[m:i])
    z.sort(key = lambda x: x[1] , reverse = True)
    for j in range(i-m):
        print(z[j][2])
m = 0
for i in range(1,n):
    if l[m][0] != l[i][0]:
        check(m,i)
        m = i
check(m,n)

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

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

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

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

// ------------------------------------------------------------------------------------------

const int MAX_DIGIT = 50;
int dp[100][2]; // dp[上からi桁目まで][smaller]

signed main() {
  int N, K;
  cin >> N >> K;

  vec<int> A(N);
  rep (i, N) { cin >> A[i]; }

  fill(dp[0], dp[100], -1);
  dp[0][0] = 0; // 初期条件
  for (int digit = 0; digit < MAX_DIGIT; digit++) {
    int mask = 1LL << (MAX_DIGIT - digit - 1);

    // Aでもともとdigit桁目にビットが立っている物の個数
    int num = 0;
    rep (i, N) {
      if (A[i] & mask) {
        num++;
      }
    }

    // Xのdigit桁目を0, 1にした時のコスト
    int cost0 = mask * num;
    int cost1 = mask * (N - num);

    // smaller -> smaller
    if (dp[digit][1] != -1) {
      chmax(dp[digit+1][1], dp[digit][1] + max(cost0, cost1)); // 0と1のうち大きい方
    }

    // exact -> smaller
    if (dp[digit][0] != -1) {
      if(K & mask) { // Kのdigit桁目が1だったら、Xのdigit桁目は0にする
        chmax(dp[digit+1][1], dp[digit][0] + cost0);
      }
    }

    // exact -> exact(Kにぴったり合わせる)
    if (dp[digit][0] != -1) {
      if (K & mask) {
        chmax(dp[digit+1][0], dp[digit][0] + cost1);
      } else {
        chmax(dp[digit+1][0], dp[digit][0] + cost0);
      }
    }
  }

  cout << max(dp[MAX_DIGIT][0], dp[MAX_DIGIT][1]) << endl;

  return 0;
}

Measured memory_bytes: 1024