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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N=in();
	auto A=vecin(N);
	int M=in();
	auto B=vecin(M);
	vector<int> C;
	set_intersection(ALL(A),ALL(B),back_inserter(C));
	
	for(auto& x:C){
		out(x);
	}
	return 0;
}


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

int main() {
  int x;
  int y;
  int a = -1;
  int b = -1;
  int c = -1;
  // a + b + c = x;
  // 1000*a + 5000*b + 10000*c =y;
  // 4000b + 9000*c = y-1000*x;
  cin >> x >> y;
  for(int i=0; i<=x; i++) {
    if(y - 1000*x - 4000*i >= 0 && (y - 1000*x - 4000*i) % 9000 == 0) {
      if (x - i - (y - 1000*x - 4000*i) / 9000 >= 0) {
        b = i;
        c = (y - 1000*x - 4000*i) / 9000;
        a = x - b - c;
        break;
      }
    }
  }
  cout << c << ' ' << b << ' ' << a << endl;
}

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

int main(){
  string s, t;
  cin >> s >> t;

  int start = -1;
  for(int i = 0; i < s.size() - t.size() + 1; ++i){
    bool tmp_flg = true;
    for(int j = 0; j < t.size(); ++j){
      if(s[i + j] == t[j])continue;
      else if(s[i + j] != '?')tmp_flg = false;
    }
    if(tmp_flg){
      start = i;
    }
  }

  string key = "";
  if(start != -1){
    for(int i = 0; i < s.size(); ++i){
      if(i == start){
        key += t;
        i += t.size() - 1; 
      }
      else if(s[i] != '?')key += s[i];
      else key += 'a';
    }

    cout << key << endl;
  }
  else cout << "UNRESTORABLE" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
long long int n , a[1000010] ;
int main()
{
    int i ;
    scanf("%lld",&n) ;
    for( i = 1 ; i <= n ; i ++ )
    {
        scanf("%lld",&a[i]) ;
    }
    if( a[n] != 2 )
    {
        puts("-1") ;
        return 0 ;
    }
    long long int low = 2 , high = 3 ;
    for( i = n - 1 ; i >= 1 ; i -- )
    {
        long long int x;
        x = ( low / a[i] ) * a[i] ;
        if( low % a[i] )
            x += a[i] ;
        long long int x1;
        x1 = ( high / a[i] ) * a[i] ;

        if( x > high || x1 < low )
        {
            puts("-1") ;
            return 0 ;
        }
        low = x , high = x1 + a[i] - 1 ;
    }
    printf("%lld %lld\n",low,high) ;
    return 0 ;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define null NULL
#define mp make_pair
#define pb(a) push_back(a)
#define sz(a) ((int)(a).size())
#define all(a) a.begin() , a.end()
#define fi first
#define se second
#define relaxMin(a , b) (a) = min((a),(b))
#define relaxMax(a , b) (a) = max((a),(b))
#define SQR(a) ((a)*(a))
#define PI 3.14159265358979323846
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

const int MAX = 2E5 + 10;

int h, w, n;
int sr, sc;
char a[MAX], b[MAX];

vi a_lr, b_lr;
vi a_ud, b_ud;

bool CanPush(int len, int s, const vi& a, const vi& b){
  int lo, hi;

  if(a[n - 1] == 0) lo = 1, hi = len;
  if(a[n - 1] == -1) lo = 2, hi = len;
  if(a[n - 1] == +1) lo = 1, hi = len - 1;
  if(lo > hi) return true;

  for(int i = n - 2;i >= 0;--i){
    if(b[i] == -1) hi = min(hi + 1, len);
    if(b[i] == +1) lo = max(lo - 1, 1);
    if(a[i] == -1) lo = lo + 1;
    if(a[i] == +1) hi = hi - 1;
    if(lo > hi) return true;
  }

  if(lo <= s && s <= hi) return false;
  return true;
}

int main(){
  scanf("%d%d%d", &h, &w, &n);
  scanf("%d%d", &sr, &sc);
  scanf("%s", a);
  scanf("%s", b);

  a_lr.resize(n, 0);
  b_lr.resize(n, 0);
  a_ud.resize(n, 0);
  b_ud.resize(n, 0);

  for(int i = 0;i < n;++i){
    if(a[i] == 'L') a_lr[i] = -1;
    if(a[i] == 'R') a_lr[i] = +1;
    if(a[i] == 'U') a_ud[i] = -1;
    if(a[i] == 'D') a_ud[i] = +1;

    if(b[i] == 'L') b_lr[i] = -1;
    if(b[i] == 'R') b_lr[i] = +1;
    if(b[i] == 'U') b_ud[i] = -1;
    if(b[i] == 'D') b_ud[i] = +1;
  }

  if(CanPush(h, sr, a_ud, b_ud) ||
     CanPush(w, sc, a_lr, b_lr)){
    printf("NO\n");
  } else {
    printf("YES\n");
  }

  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define ppb pop_back
#define INF 1e18
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using namespace std;
int main(int argc, char *argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);

    int n,m;cin>>n>>m;
    int correct = 0;
    int sum_wrong = 0;

    bool *flags = new bool[n];
    for(int i = 0;i<n;i++)flags[i]=false;
    int *wrongs = new int[n];
    for(int i  = 0;i<n;i++)wrongs[i]=0;

    for (int i = 0; i < m; i++)
    {
        int x;
        string s;
        cin >> x >> s;
        if (flags[x - 1])
            continue;
        else if (s == "AC")
        {
            correct++;
            flags[x - 1] = true;
        }
        else
        {
            wrongs[x-1]++;
        }
    }
    for(int i =0;i<n;i++)if(flags[i])sum_wrong+=wrongs[i];
    cout << correct << " " << sum_wrong << endl;
    return 0;
}

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

//define gcd and lcm (using 64bit)
ll gcd(ll a,ll b){
    if (a < b) {
        //^はxor(bitwise operator)。以下三行でswap(a,b)を行っている。
        a ^= b;
        b ^= a;
        a ^= b;
    }
    //only when b==0,this program finds that b means false and returns a.
    return b ? gcd(b, a % b) : a;
}

ll lcm(ll a,ll b){
    return a * b / gcd(a, b);
}


int main() {
    int r;
    cin>>r;
    cout<<(r*r*3)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>

#include <iomanip>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define FIND(x, target) find(x.begin(),x.end(),target)
#define pb(x) push_back(x)
#define pob(x) pop_back(x)
#define output(x) cout<<x<<endl
#define ERASE(x, n) x.erase(x.begin()+n)
// #define int long long
// #define P pair<int, int>
// queue: first in first out
// stack: first in last out
typedef long long ll;

const long long int MOD = 1e9+7;
const ll INF = 1e17;
const ll NUM = 1e5+1;
// ll dp[100005][13];
ll dp[10005];

ll Query[NUM];

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

signed main(void) {
  ll H, W;
  cin >> H >> W;
  if (H == 1 || W == 1) {
    cout << 1 << endl;
  } else {
    cout << (H*W+1)/2 << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef string str;
int main(){
  int ans,i;
  str S,T;
  cin>>S;cin>>T;
  ans=0;
  for(i=0;i<3;++i){
    if(S[i]==T[i]){
      ans+=1;
    }
  }
  cout<<ans<<endl;
}

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

using ll = long long int;
using ull = unsigned long long int;
using P = pair<ll, ll>;
using P3 = pair<P,int>;
using PP = pair<P, P>;
constexpr ll INF = 1LL << 60;
constexpr ll MOD = ll(1e9)+7;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};
constexpr int di8[] = {0, 1, 1, 1, 0, -1, -1, -1};
constexpr int dj8[] = {1, 1, 0, -1, -1, -1, 0, 1};
constexpr double EPS = 1e-9;


int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    ll ans1 = 0, ans2 = 0;
    ll s = 0;
    for(int i=0;i<n;i++){
        s += a[i];
        if(i%2){
            if(s <= 0){
                ans1 += abs(s)+1;
                s = 1;
            }
        }else{
            if(s >= 0){
                ans1 += abs(s)+1;
                s = -1;
            }
        }
    }
    s = 0;
    for(int i=0;i<n;i++){
        s += a[i];
        if(i%2){
            if(s >= 0){
                ans2 += abs(s)+1;
                s = -1;
            }
        }else{
            if(s <= 0){
                ans2 += abs(s)+1;
                s = 1;
            }
        }
    }
    cout << min(ans1,ans2) << endl;
    return 0;
}


Measured memory_bytes: 4028
#include<stdio.h>
char a[21][21];
int c;
void dfs(int y,int x){
  c++;
  a[y][x]=0;
  if(y!=0)
    if(a[y-1][x]=='.')
      dfs(y-1,x);
  if(y!=20)
    if(a[y+1][x]=='.')
      dfs(y+1,x);
  if(x!=0)
    if(a[y][x-1]=='.')
      dfs(y,x-1);
  if(x!=20)
    if(a[y][x+1]=='.')
      dfs(y,x+1);
}
int main(){
  int w,h,i,j;
  char b[21];
  while(1){
    scanf("%d%d",&w,&h);
    if(w==0&&h==0)break;
    for(i=0;i<21;i++){
      for(j=0;j<21;j++){
	a[i][j]=0;
      }
    }
    for(i=0;i<h;i++){
	scanf("%s",b);
	for(j=0;b[j]!='\0';j++){
	  a[i][j]=b[j];
	}
    }
    c=0;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	if(a[i][j]=='@')dfs(i,j);
      }
    }
    printf("%d\n",c);

   
  }
  return 0;
}

Measured memory_bytes: 1048
#include <iostream>
using namespace std;
typedef long long ll;
int main()
{
	ll n,sum=0;
	cin >> n;
	for (ll i = 1;i <= n;i++)
	{
		if (i % 3 != 0 && i % 5 != 0) sum += i;
	}
	cout << sum;
	return 0;
}

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

N, = map(int, input().split())

ac = 0
wa = 0
tle = 0
re = 0
for _ in range(N):
    s, = map(str, input().split())
    if s=='AC':
        ac += 1
    elif s=='WA':
        wa += 1
    elif s=='TLE':
        tle += 1
    elif s=='RE':
        re += 1

print("AC x {}".format(ac))
print("WA x {}".format(wa))
print("TLE x {}".format(tle))
print("RE x {}".format(re))


Measured memory_bytes: 9136
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T, class U> inline bool chmax(T& a,U b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class U> inline bool chmin(T& a,U b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &e : a) cin >> e;
    
    long long ans = 0;
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        if (mp.count(a[i])) ans += mp[a[i]];
        mp[a[i]]++;
    }
    
    for (int i = 0; i < n; i++) {
        cout << ans - (mp[a[i]] - 1) << '\n';
    }
    return 0;
}

Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
int n, m, p = 998244353;
char a[100020];
char b[100020];
char c[100020];
char d[100020];
long long v[500020];
long long u[500020];
long long ans;
int a1, b1, c1, d1;
int f[100020];
int g[100020];
long long C(int n, int m) {
	if (n == -1 && m == -1) {
		return 1;
	}
	if (m < 0) {
		return 0;
	}
	return u[n] * v[m] % p * v[n - m] % p;
}
int main() {
	scanf("%d%d", &n, &m);
	scanf("%s%s%s%s", a, b, c, d);
	v[1] = 1;
	for (int i = 2; i <= 500010; i++) {
		v[i] = v[p % i] * (p - p / i) % p;
	}
	v[0] = u[0] = u[1] = 1;
	for (int i = 2; i <= 500010; i++) {
		v[i] = v[i] * v[i - 1] % p;
		u[i] = u[i - 1] * i % p;
	}
	a1 = b1 = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] == '1') {
			a1++;
		}
		if (b[i] == '1') {
			b1++;
		}
	}
	c1 = d1 = 0;
	for (int i = 0; i < m; i++) {
		if (c[i] == '1') {
			c1++;
		}
		if (d[i] == '1') {
			d1++;
		}
	}
	if (a1 == 0 && b1 == 0 && c1 == 0 && d1 == 0) {
		printf("1\n");
		return 0;
	}



	c1 = d1 = 0;
	for (int i = 0; i < m; i++) {
		if (i == 0) {
			f[i] = 0;
		} else {
			f[i] = f[i - 1];
		}
		if (c[i] == '1' || d[i] == '1') {
//			cerr << "?" << C(c1 + d1 + a1 - 1, a1 - 1) << ' ' << a1 << ' ' << b1 << ' ' << c1 << ' ' << d1 << endl;
			f[i] = (f[i] + C(c1 + d1 + a1 - 1, a1 - 1)) % p;
			if (c[i] == '1' && d[i] == '1') {
				f[i] = f[i] * 2 % p;
			}
		}
		if (c[i] == '1') {
			c1++;
		}
		if (d[i] == '1') {
			d1++;
		}
	}
	c1 = d1 = 0;
	for (int i = m - 1; i >= 0; i--) {
		if (c[i] == '1' || d[i] == '1') {
			ans = (ans + f[i] * C(c1 + d1 + b1 - 1, b1 - 1)) % p;
		}
		if (c[i] == '1') {
			c1++;
		}
		if (d[i] == '1') {
			d1++;
		}
	}




	c1 = d1 = 0;
	for (int i = 0; i < m; i++) {
		if (c[i] == '1') {
			c1++;
		}
		if (d[i] == '1') {
			d1++;
		}
	}
	a1 = b1 = 0;
	for (int i = 0; i < n; i++) {
		if (i == 0) {
			f[i] = 0;
		} else {
			f[i] = f[i - 1];
		}
		if (a[i] == '1' || b[i] == '1') {
//			cerr << "?" << C(a1 + b1 + c1 - 1, c1 - 1) << ' ' << a1 << ' ' << b1 << ' ' << c1 << ' ' << d1 << endl;
			f[i] = (f[i] + C(a1 + b1 + c1 - 1, c1 - 1)) % p;
			if (a[i] == '1' && b[i] == '1') {
				f[i] = f[i] * 2 % p;
			}
		}
		if (a[i] == '1') {
			a1++;
		}
		if (b[i] == '1') {
			b1++;
		}
	}
	a1 = b1 = 0;
	for (int i = n - 1; i >= 0; i--) {
		if (a[i] == '1' || b[i] == '1') {
			ans = (ans + f[i] * C(a1 + b1 + d1 - 1, d1 - 1)) % p;
		}
		if (a[i] == '1') {
			a1++;
		}
		if (b[i] == '1') {
			b1++;
		}
	}


	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 8960
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX=1e5+10;
int A[MAX];
int main ()
{
    int n;cin >> n;
    int mx = -1;
    for(int i=0;i<n;i++){
        cin >> A[i];
        mx = max(mx,A[i]);
    }
    int mn = 1e9+10,b=-1;
    for(int i=0;i<n;i++){
        if(A[i]==mx)continue;
        int x = mx - A[i];
        int y = mx - x;
        if(x<y)swap(x,y);
        if(x-y<mn){
            mn = x-y;
            b = A[i];
        }
    }
    cout<<mx<<" "<<b;
    return 0;
}


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

int main () {
  int N, A, B;
  cin >> N >> A >> B;
  
  if (N * A < B) {
    cout << N * A << endl;
  }
  
  if ( N * A > B) {
     cout << B << endl;
  }
  if ( N * A == B) {
     cout << B << endl;
  }
}


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll a, b;
  cin >> a >> b;
  
  if(a <= b)
    cout << a << "\n";
  else
    cout << a-1 << "\n";

}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

vector<ll> pw2(51,1); vector<ll> pw10(19,1);
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll myceil(ll x,ll y){if(x<=y) return 1;else if(x%y==0) return x/y;else return x/y+1;}

//a,b x
int main(){
	ll N,C; cin>>N>>C;
	vector<vector<ll>> D(C+1,vector<ll>(C+1));
	rep1(i,C)rep1(j,C) cin>>D[i][j];
	vector<vector<ll>> c(N+1,vector<ll>(N+1));
	rep1(i,N)rep1(j,N) cin>>c[i][j];

	//あまり0~2のマスすべて色(1~N)にするコスト
	ll cost[3][501];
	rep(i,3)rep1(j,C){
		//あまりiをj色に染める
		ll tmpcost=0;
		rep1(h,N)rep1(w,N){
			if((h+w)%3==i) tmpcost+=D[c[h][w]][j];
		}
		cost[i][j]=tmpcost;
	}

	ll ans=1000000000000000;
	rep1(c0,C)rep1(c1,C)rep1(c2,C){
		if(c0!=c1 && c1!=c2 && c0!=c2){
			ans=min(ans,cost[0][c0]+cost[1][c1]+cost[2][c2]);
		}
	}
	cout<<ans;
}

Measured memory_bytes: 2304
#TODO
def dfs(word, idx):
    if len(word)==n:
        print(word)
        return
    for j in range(idx):
        dfs(word+chr(j+mx), idx)
    dfs(word+chr(idx+mx), idx+1)

n = int(input())
mx = ord('a')
dfs("", 0)

Measured memory_bytes: 9060
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main(){
    int n,x;
    cin>>n>>x;
    vector<int> m(n);
    for(int i=0;i<n;i++){
        cin>>m[i];
    }
    sort(m.begin(),m.end());
    int sum=0;
    for(int i=0;i<n;i++){
        sum+=m[i];
    }
    int def=x-sum;
    int cnt=n+def/m.front();
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>

#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())

#define fs first
#define sc second
		 
using namespace std;
		 
typedef long long ll;
typedef pair<ll, ll> P;

		 
int main(){
	int H, W;
	cin >> H >> W;

	int grid[H+1][W+1];
	for(int i = 1; i <= H; ++i){
		for (int j = 1; j <= W; j++){
			cin >> grid[i][j];
		} // j
	} // i

	int state = 0;
	vector< vector<int> > ops;
	for(int i = 1; i <= H; ++i){
		state = 0;
		for (int j = 1; j <= W-1; j++){
			if(state == 0){
				if(grid[i][j] % 2 == 1){
					state = 1;
					grid[i][j]--;
					grid[i][j+1]++;
					vector<int> tmp = {i, j, i, j+1};
					ops.emplace_back(tmp);
				}
			} else {
				if(grid[i][j] % 2 == 0){
					state = 0;
				} else {
					grid[i][j]--;
					grid[i][j+1]++;          
					vector<int> tmp = {i, j, i, j+1};
					ops.emplace_back(tmp);
				}
			}	
		} // j
	} // i

	state = 0;
	for (int i = 1; i <= H-1; i++){
		if(state == 0){
			if(grid[i][W] % 2 == 1){
				state = 1;
				grid[i][W]--;
				grid[i+1][W]++;
				vector<int> tmp = {i, W, i+1, W};
				ops.emplace_back(tmp);
			}
		} else {
			if(grid[i][W] % 2 == 0){
				state = 0;
			} else {
				grid[i][W]--;
				grid[i+1][W]++;          
				vector<int> tmp = {i, W, i+1, W};
				ops.emplace_back(tmp);
			}
		}
	}
	
	cout << ops.size() << endl;
	for (size_t i = 0; i < ops.size(); i++){
		cout << ops[i][0] << " ";
		cout << ops[i][1] << " ";
		cout << ops[i][2] << " ";
		cout << ops[i][3] << endl;
	}

	return 0;
}


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

int main() {
	int m1, d1, m2, d2;
	cin >> m1 >> d1 >> m2 >> d2;

	if(m1 + 1 == m2) cout << 1 << endl;
	else cout << 0 << endl;

 	return 0;
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

int main(void){
	string S,T;
	cin >> S >> T;
	int ans = 0;
	for(int i=0;i<S.size();i++){
		if(S[i] == T[i]) ans ++ ;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
ans = [0]*4
ls = ['AC','WA','TLE','RE']
for i in range(n):
    s = input()
    if s == 'AC':
        ans[0]+=1
    elif s == 'WA':
        ans[1]+=1
    elif s == 'TLE':
        ans[2]+=1
    elif s == 'RE':
        ans[3]+=1

for i in range(4):
    print(ls[i]+' x '+str(ans[i]))



Measured memory_bytes: 69928
import sys
input = sys.stdin.readline

sys.setrecursionlimit(1000000)

def main(): 

    N=int(input())
    to=[[] for _ in range(N+1)]
    ans=[0]*(N+1)

    for i in range(N-1):
        u,v,w=map(int,input().split())
        to[u].append([v,w])
        to[v].append([u,w])
    
    def dfs(chil, par):
        for v,l in to[chil]:
            if v == par: continue
            if (ans[chil] == 1 and l%2==0) or (ans[chil] == 0 and l%2==1):
                ans[v]=1
            dfs(v,chil)
    
    #ans[1] = 1
    dfs(1,-1)
    for i in ans[1:]:
        print(i)
if __name__ == "__main__":
    main()
    

Measured memory_bytes: 94556
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fst . fromJust . BS.readInt

readIntList = map readInt . BS.words

getIntList = readIntList <$> BS.getLine

main = do
  [n, m] <- getIntList
  putStrLn $ if m == n then "Yes" else "No"


Measured memory_bytes: 3772
#include<cstdio>
#include<cstring>
char a[10010];
bool c, f;
int main() {
	scanf("%s", a);
	for(int i=0; i<strlen(a); i++) {
		if(a[i]=='C') c=true;
		if(a[i]=='F'&&c==true) f=true;
	}
	if(f==true) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define pp pair<int,int>
#define Pi acos(-1)
#define pq priority_queue
#define mz 1000000007

using namespace std;

int num[100005];

int main()
{
    int n,ans=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&num[i]);
    for(int i=1;i<=n;i++)
    {
        if(num[i]==i)
        {
            num[i+1]=i;
            ans++;
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>

typedef long long ll;
typedef std::vector< int > VI;

const double EPS = 1e-10;
const double PI  = acos(-1);
const ll     INF = 1 << 30;

int main(int argc, char* argv[])
{
  int n, a, b;
  int all_sum = 0;
  std::cin >> n >> a >> b;

  for (int i = 1; i <= n; i++) {
    int x = i;
    int sum = 0;
    while(x >= 10) {
      sum += x % 10;
      x /= 10;
    }
    sum += x;
    if (sum >= a && sum <= b) {
      all_sum  += i;
    }
  }

  std::cout << all_sum << std::endl;

  return 0;
}


Measured memory_bytes: 256
/*
 * atcoder/abc112_2nd/c.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

int N;
vector<ll> X, Y, H;

void solve() {
  cin >> N;
  ll x, y, h;
  loop(n,0,N) {
    cin >> x >> y >> h;
    if (h > 0) X.push_back(x), Y.push_back(y), H.push_back(h);
  }
  N = H.size();
  if (N == 1) {
    cout << X[0] << " " << Y[0] << " " << H[0] << endl;
    return;
  }

  loop(cx,0,101) loop(cy,0,101) {
    bool isCenter = true;
    ll h = -1;
    loop(n,0,N) {
      ll h2 = H[n] + abs(cx - X[n]) + abs(cy - Y[n]);
      isCenter &= h < 0 ? true : h2 == h;
      h = h2;
    }
    if (isCenter) {
      cout << cx << " " << cy << " " << h << endl;
      return;
    }
  }
}
int main() {
  // cout.precision(15);
  // cout << fixed << double

  solve();

  return 0;
}


Measured memory_bytes: 256
a,b,c,d=map(int,raw_input().split())
if a%d==0:
	p=a/d
else:
	p=a/d + 1

if c%b==0:
	q=c/b
else:
	q=c/b + 1

if q<=p:
	print "Yes"

else:
	print "No"

Measured memory_bytes: 64080
#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int a,b,c;
    scanf("%d %d %d", &a, &b ,&c);
    if(a < b && b < c){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}



Measured memory_bytes: 2044
use proconio::input;

fn main() {
    input! {
        n: usize,
        m: usize,
        x: i64,
    }

    let mut c = vec![];
    let mut a = vec![];
    for _ in 0..n {
        input! {
            ci: i64,
            ai: [i64; m],
        }
        c.push(ci);
        a.push(ai);
    }

    let inf = std::i64::MAX;
    let mut min = inf;
    for bits in 0..(1 << n) {
        let mut s = vec![0; m];
        let mut cost = 0;
        for i in 0..n {
            if (bits >> i) & 1 > 0 {
                cost += c[i];
                for j in 0..m {
                    s[j] += a[i][j];
                }
            }
        }
        if s.iter().all(|si| *si >= x) {
            min = std::cmp::min(min, cost);
        }
        // eprintln!("{:b}", bits);
        // dbg!(s, cost);
    }

    if min == inf {
        println!("-1");
    } else {
        println!("{}", min);
    }
}


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

using namespace std;

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

  int c[3] = {0};
  int p;
  for (int i = 0; i < n; i++) {
    cin >> p;
    if (p <= a)
      c[0]++;
    else if (a < p && p <= b)
      c[1]++;
    else
      c[2]++;
  }
  const int ans = min({c[0], c[1], c[2]});
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
/**
*
* Author: Mouhanad
* Lang: GNU C++14
*
**/
#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define ii pair < int , int >
#define LS pair < ll , string >
typedef long long ll;
const int inf = 1<<30;
const int N =100100;
int n , m ;
int vis[N] , color[N] , cnt[2];
vector < int > adj[N];
void dfs ( int u , int c ){

  vis[u] = 1 ;
  color[u]=  c ;
  cnt[c]++;
  for ( auto v : adj[u])
    if ( !vis[v])
    dfs(v,1-c);
}
int main ( ){
 scanf("%d %d",&n,&m);
 int x , y ;
 for ( int i = 1 ; i <= m ;i++ ) {
    scanf("%d %d",&x,&y);
    adj[x].push_back(y);
    adj[y].push_back(x);
 }
 dfs(1,0);
 bool bipartite = true ;
 for ( int u = 1; u <= n ;u++ ){
    for ( auto v : adj[u] )
        if ( color[v] == color[u] ) bipartite = false ;
 }
 if ( !bipartite ) {
  printf("%lld",1LL*n*(n-1)/2LL-m);
 }
 else printf("%lld",1LL*cnt[0]*cnt[1]-m);

return 0 ;
}


Measured memory_bytes: 6912
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

ull dp[50003];

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N,P;
  cin >> N >> P;
  int pct = 0;
  vector<int> a(N);
  REP(i,N) cin >> a[i];
  dp[0] = 1;
  REP(i,N){
    for(int j = 5000;j>=a[i];j--){
      if(dp[j - a[i]]) dp[j] += dp[j - a[i]];
    }
  }
  ull ans = 0;
  REP(i,5003){
    if(i % 2 == P) ans += dp[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<list>
#include<functional>
#define _USE_MATH_DEFINES

#include<math.h>
#include<map>

#define SENTINEL 1000000001

#define min(a,b) ((a)>(b)?(b):(a))
#define max(a,b) ((a)>(b)?(a):(b))

#define INF 200000000

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;

struct OwnEdge
{
	int s, t, c;
	OwnEdge(int s,int t,int c):s(s),t(t),c(c){}
	OwnEdge():s(-1),t(-1),c(-1){}
	bool operator<(const OwnEdge& e)const
	{
		return c < e.c;
	}
	bool operator>(const OwnEdge& e)const
	{
		return c > e.c;
	}
};

ll MCA(vector<OwnEdge>& edges, int V, int r)
{
	vector<pii> mins(V, pii(INF, -1));
	for (auto& e : edges)
	{
		mins[e.t] = min(mins[e.t], pii(e.c, e.s));
	}
	mins[r] = pii(-1, -1);

	vector<int> group(V, 0);
	vector<bool> isCycle(V, false);
	int counter = 0;

	vector<bool> checked(V, false);
	for (int i = 0; i < V; i++)
	{
		if (checked[i])
		{
			continue;
		}
		vector<int> chain;
		int cursor = i;
		while (cursor != -1 && !checked[cursor])
		{
			checked[cursor] = true;
			chain.push_back(cursor);
			cursor = mins[cursor].second;
		}
		if (cursor != -1)
		{
			bool inCycle = false;
			for (auto& n : chain)
			{
				group[n] = counter;
				if (n == cursor)
				{
					inCycle = true;
					isCycle[counter] = true;
				}
				if (!inCycle)counter++;
			}
			if (inCycle)counter++;
		}
		else
		{
			for (auto& n : chain)
			{
				group[n] = counter;
				counter++;
			}
		}
	}

	if (counter == V)
	{
		ll sum = 1;
		for (int i = 0; i < V;i++)
		{
			sum += mins[i].first;
		}
		return sum;
	}

	ll res = 0;
	for (int i = 0; i < V; i++)
	{
		if (i != r&&isCycle[group[i]])
		{
			res += mins[i].first;
		}
	}

	vector<OwnEdge> newEdge;
	for (auto& e : edges)
	{
		int to = e.t;
		int gfrom = group[e.s];
		int gto = group[e.t];

		if (gfrom == gto)
		{
			continue;
		}
		else if (isCycle[gto])
		{
			newEdge.push_back(OwnEdge(gfrom, gto, e.c - mins[to].first));
		}
		else
		{
			newEdge.push_back(OwnEdge(gfrom, gto, e.c));
		}
	}

	return res + MCA(newEdge, counter, group[r]);
}

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

	vector<OwnEdge> edges;

	int V, E,r;
	scanf("%d %d %d", &V, &E, &r);

	for (int i = 0; i < E; i++)
	{
		int s, t, d;
		scanf("%d %d %d", &s, &t, &d);

		edges.push_back(OwnEdge(s, t, d));
	}

	printf("%d\n", MCA(edges, V, r));

	return 0;
}


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

int main(){
  int n; cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }int i=0;
  long long ans=0;
  while(i!=n){
    ans++;
    int base=a[i];
    i++;
    bool flag=true;
    while(i!=n){
      if(base==a[i]){
        i++;
      }else if(base<a[i]){
        flag=true;
        break;
      }else{
        flag=false;
        break;
      }
    }if(i==n) break;
    base=a[i]; i++;
    if(flag){
      while(i!=n){
        if(base<=a[i]){
          base=a[i]; i++;
        }else break;
      }
    }else{
      while(i!=n){
        if(base>=a[i]){
          base=a[i]; i++;
        }else break;
      }
    }
  }cout<<ans<<endl;
}

Measured memory_bytes: 640
N = int(input())

c = [[0]* 10 for i in range(10)]

for i in range(1, N+1):
    s = str(i)
    c[int(s[0])][int(s[-1])] += 1

ans = 0
for i in range(10):
    for j in range(10):
        ans += c[i][j] * c[j][i]

print(ans)

Measured memory_bytes: 3060
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) (a).begin(), (a).end()
#define AALL(a, n) (a), ((a) + (n))
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define MODNUM (static_cast<int>(1e9 + 7))
#define MOD(x) ((x) % MODNUM)

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

const int INF = 2e9;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

template <typename T>
int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T>
T square(T x) {
	return x * x;
}

inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

int main() {
	int a[3];
	scanf("%d %d %d", &a[0], &a[1], &a[2]);
	puts(a[0] + a[1] + a[2] > 21 ? "bust" : "win");
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();

        long attacks = 0;
        long level = 1;
        while (h != 0) {
            h = h/2;
            attacks += level;
            level *= 2;
        }
        System.out.println(attacks);
    }
}

Measured memory_bytes: 21844
from itertools import accumulate
n,w=map(int, input().split())
items = {}
for _ in range(n):
    u,v = map(int, input().split())
    if u not in items:
        items[u] = []
    items[u].append(v)
cost = 0
acc = []
minkey = min(items.keys())
for i in range(4):
    if minkey + i in items:
        items[minkey + i].sort(reverse=True)
        acc.append([0] + list(accumulate(items[minkey + i])))
    else:
        acc.append([0])

ans = 0
for i in range(len(acc[0])):
    a = (i) * minkey
    if w < a:
        continue
    for j in range(len(acc[1])):
        b = (j) * (minkey+1)
        if w < a + b:
            continue
        for k in range(len(acc[2])):
            c = (k) * (minkey+2)
            if w < a + b + c:
                continue
            for l in range(len(acc[3])):
                d = (l) * (minkey+3)
                if w < a + b + c + d:
                    continue
                cost = acc[0][i] + acc[1][j] + acc[2][k] + acc[3][l]
                if cost > ans :
                    ans = cost

print(ans)


Measured memory_bytes: 41200
package main

import "fmt"

type dice struct {
	top, bottom, right, left, up, down int
}

func move(d *dice, dir byte) {
	now := d.top
	switch dir {
	case 'N':
		d.top = d.down
		d.down = d.bottom
		d.bottom = d.up
		d.up = now
	case 'S':
		d.top = d.up
		d.up = d.bottom
		d.bottom = d.down
		d.down = now
	case 'W':
		d.top = d.right
		d.right = d.bottom
		d.bottom = d.left
		d.left = now
	case 'E':
		d.top = d.left
		d.left = d.bottom
		d.bottom = d.right
		d.right = now
	}
}

func roll(d *dice) {
	// tob-bottomを軸にして右回転する
	now := d.up
	d.up = d.right
	d.right = d.down
	d.down = d.left
	d.left = now
}

func check(d1 *dice, d2 *dice) bool {
	return d1.top == d2.top && d1.bottom == d2.bottom &&
		d1.up == d2.up && d1.down == d2.down &&
		d1.left == d2.left && d1.right == d2.right
}

func fullcheck(d0 *dice, d1 *dice) bool {
	found := false
	// d1を転がしてd0と上面を一致させる。一致させられなければその時点で終わり
	ops := "NNNNEEEE"
	for i := 0; i < len(ops); i++ {
		// fmt.Printf("DBG0 - i %d - d0 %v, d1 %v\n", i, *d0, *d1)
		if d0.top == d1.top { // 上面は一致した
			d1c := *d1 // snapshot
			for j := 0; j < 4; j++ {
				// fmt.Printf(" DBG1 - j %d - d0 %v, d1 %v\n", j, *d0, d1c)
				if check(d0, &d1c) {
					found = true
					break
				} else {
					roll(&d1c)
				}
			}
			if found {
				break
			}
		}
		if found {
			break
		}
		move(d1, ops[i])
	}
	return found
}

func main() {
	d := make([]dice, 2)
	for i := 0; i < len(d); i++ {
		fmt.Scan(&d[i].top, &d[i].down, &d[i].right, &d[i].left, &d[i].up, &d[i].bottom)
	}
	for i := 1; i < len(d); i++ {
		if !fullcheck(&d[0], &d[i]) {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}



Measured memory_bytes: 1160
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5+5;
const long long MOD = 1e9+7;
long long fact[MAXN];

int main(){
    int n,m;
    cin>>n>>m;
    if(abs(m-n)>1){
        cout<<0<<endl;
        return 0;
    }
    fact[0] = 1;
    for(int i=1;i<=max(n,m);i++){
        fact[i] = fact[i-1]*i;
        fact[i]%=MOD;
    }
    if(m==n){
        cout<<(2*(fact[n]*fact[m])%MOD)%MOD;
        return 0;
    }
    cout<<(fact[n]*fact[m])%MOD<<endl;
}


Measured memory_bytes: 1024
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

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

	ll n;
	string s;
	cin >> n >> s;
	ll r = 0, g = 0, b = 0;
	for (ll i = 0; i < n; i++) {
		if (s[i] == 'R') r++;
		else if (s[i] == 'G') g++;
		else b++;
	}
	ll ans = r * g * b;
	for (ll i = 0; i < n - 2; i++) {
		for (ll j = i + 1; j < n - 1; j++) {
			ll k = 2 * j - i;
			if (k < n) {
				if (s[i] != s[j] && s[j] != s[k] && s[k] != s[i]) ans--;
			}
		}
	}
	cout << ans << endl;
}

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

string s;

int main(void)
{
    cin>>s;
    int len = s.length();
    long long res = 0;
    for(int i=len-1;i>=0;--i){
        if(s[i] < '5') res += s[i]-'0';
        else if(s[i] == '5'){
            if(i == 0) res += s[i]-'0' ;
            else if(s[i-1] < '5') res += s[i]-'0';
            else{
                res += 10-int(s[i]-'0');
                int k = i-1;
                while(k>=0 && s[k] == '9'){
                    s[k] = '0';
                    --k;
                }
                if(k == -1) res += 1;
                else s[k] += 1;
            }
        }
        else {
            res += 10-int(s[i]-'0');
            if(i == 0) res += 1;
            else if(s[i-1] < '9') s[i-1] += 1;
            else {
                int k = i-1;
                while(k>=0 && s[k] == '9'){
                    s[k] = '0';
                    --k;
                }
                if(k == -1) res += 1;
                else s[k] += 1;
            }
        }
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 1412
#include<stdio.h>

int main(){
  int c;
  scanf("%d", &c);

  if(c%10 == 1) c += 8;
  else c -= 8;
  
  if(c/10%10 == 1) c += 80;
  else c -= 80;

  if(c/100%10 == 1) c += 800;
  else c -= 800;

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

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
//const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

struct point{
    int v, w;
    vector<ll> dp; 
    int um;
};

int main() {
    int x, n ;cin >> x >> n;
    vector<int> ar(301,0);
    rep(i,n){
        int a; cin >> a;
        ar[a+100]++;
    }
    if (ar[x+100] == 0) {cout << x << endl; return 0;}
    repp(i,101,1){
        if (ar[x+100-i] == 0){
            cout << x-i << endl;
            return 0;
        }
        if (ar[x+100+i] == 0){
            cout << x + i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define MOD 1000000007
typedef long long ll;
const char sp = ' ';



using namespace std;


int main(void){
    ll N, K, count=0;
    cin>>N>>K;
    reps(i, K, N+2){
        count+=(N-i+1)*i+1;
        count%=MOD;
        //cout<<count<<endl;
    }
    cout<<count<<endl;
    return 0;
}


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



int main(){
  int a;
  cin >> a;
  char b[a];
  for(int i = 0;i < a;i++){
    cin >> b[i];
  }
  int d;
  cin >> d;
  char c = b[d-1];
  string answer = "";
  for(int i = 0;i < a;i++){
    if(b[i] != c){
      b[i] = '*';
    }
    answer += b[i];
  }
  cout << answer << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <atcoder/all>
#define ll long long int
#define MOD 1000000007
#define P pair<ll,ll>
#define INF 1000000000000000000

//using namespace atcoder;
using namespace std;

int main(void){
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if (a*b > c*d)
    cout << a*b << endl;
  else
    cout << c*d << endl;

  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;
const int N_MAX = pow(10,5);

struct DUnionFind {
  vector<int> par, d;

  DUnionFind(int N) : par(N), d(N) { 
    rep(i, N) { par[i] = i; d[i] = 0; } 
  }

  int root(int x) { 
    if (par[x]== x) return x;
    else {
      int tmp_root = root(par[x]);
      d[x] += d[par[x]];
      return par[x] = tmp_root;
    }
  }

  void unite(int x, int y, int dd) {
    // if (dd<=0) { swap(x, y); dd*=-1; }
    int rx = root(x);
    int ry = root(y);
    if (rx==ry) return;
    d[ry] = dd + dist(x) - dist(y);
    par[ry] = rx;
  }

  bool same(int x, int y) { return root(x) == root(y); }

  int dist(int x) { root(x); return d[x]; }

  int diff(int x, int y) { if (same(x, y)) return dist(y) - dist(x); }

};

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

  DUnionFind tree(N);
  string result = "Yes";
  rep(i, M) {
    ll L, R, D; cin >> L >> R >> D;
    L--; R--;
    if (tree.same(L,R)) { if (tree.diff(L,R)!=D) { result = "No"; break; } }
    else tree.unite(L, R, D);
  }

  cout << result << endl;
  // rep(i,N) cout << i << ": " << tree.root(i) << " " << tree.dist(i) << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
#define EPS 1e-9
using namespace std;

typedef pair<int,int> P;
typedef pair<double,P> P2;

double d[50][1<<10];
bool v[50][1<<10];

int main(){
  int n,m,p,a,b;
  int x,y,z;
  int t[10];
  vector<P> g[50];

  while(cin >> n >> m >> p >> a >> b, n||m||p||a||b){
    for(int i=0;i<n;i++)cin >> t[i];

    for(int i=0;i<=m;i++)g[i].clear();
    for(int i=0;i<p;i++){
      cin >> x >> y >> z;
      g[x].push_back(P(y,z));
      g[y].push_back(P(x,z));
    }
      
    for(int i=0;i<=m;i++)
      for(int j=0;j<(1<<n);j++){
	d[i][j] = 10000.0;
	v[i][j] = false;
      }
    d[a][0] = 0.0;

    priority_queue<P2,vector<P2>,greater<P2> > q;
    q.push(P2(0.0,P(a,0)));

    double ans = 10000.0;
    while(!q.empty()){
      P2 p = q.top(); q.pop();
      double dis = p.first;
      int c = p.second.first, ti = p.second.second;

      if(v[c][ti])continue;
      v[c][ti] = true;
      if(c==b){ans = dis; break;}

      for(int i=0;i<(int)g[c].size();i++){
	int nc = g[c][i].first;
	for(int j=0;j<n;j++){
	  if( (ti>>j) & 1 )continue;
	  int nt = ti+(1<<j);
	  
	  double nd = dis + (double)g[c][i].second/t[j];
	  
	  if(d[nc][nt] > nd && !v[nc][nt]){
	    d[nc][nt] = nd;
	    q.push(P2(nd,P(nc,nt)));
	  }
	}
      }
    }

    if(ans+EPS>10000.0)printf("Impossible\n");
    else printf("%.5lf\n",ans);
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
ll mod=1000000007;

int main() {
  ll n;cin >>n;
  vector<ll> v;
  while(n>0){
    ll r = n%10;
    n/=10;
    v.push_back(r);
  }
  ll out=0;
  bool allnine =true;
  if(v.size()>1){
    for(int i=0;i<v.size();++i){
      if(i==v.size() -1){
        out += v[i] - 1;
        if (allnine)out += 1;
      } else {
        if(allnine && v[i] != 9) allnine =false;
        out += 9;
      }
    }
  } else {
    out += v[0];
  }
  cout << out << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
int n;
int c[500],s[500],f[500];
int main(){
	cin >> n;
	REP(i,n - 1) {
		cin >> c[i] >> s[i] >> f[i];
	}

	REP(i,n) {
		int t = s[i];
		FOR(j,i,n - 1) {
			if(t % f[j])
				t += (f[j] - t % f[j]);
			if(t < s[j])  
				t = s[j];
			t += c[j];
		} 
		cout << t << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int t = sc.nextInt();

    int m = (int)((t+0.5)/a);
    System.out.println(b*m);
  }
}


Measured memory_bytes: 22228
object Main {
  def main(args: Array[String]): Unit = {
    val factors     = io.StdIn.readLine.split(" ").map{_.toInt}
    val item_values = io.StdIn.readLine.split(" ").map{_.toInt}.sorted
    var sum         = 0

    ( 0 until factors(1) ).foreach { i =>
      sum += item_values(i)
    }

    println( sum )
  }
}

Measured memory_bytes: 54756
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<deque>
using namespace std;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
static const ll maxLL = (ll)1 << 62;
const int mod=1000000007;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};
int dyy[]={0,-1,0,1};
int dxx[]={-1,0,1,0};

#define int ll

signed main(){
    int n,t;
    cin>>n>>t;
    int a[200200];
    int s=0,cnt=0;
    rep(i,0,n){
        cin>>a[i];
        if(a[i]>s){
            cnt+=a[i]-s;
        }
        s=a[i]+t;
    }
    cout<<s-cnt<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
	string S[3] = {"GREATER", "EQUAL", "LESS"};
	string A, B;
	cin >> A >> B;

	int a = A.size();
	int b = B.size();

	if(a>b){
		cout << S[0] <<endl;
	}else if(a<b){
		cout << S[2] <<endl;
	}else{
		if(A<B){
			cout << S[2] <<endl;
		}else if(A>B){
			cout << S[0] <<endl;
		}else{
			cout << S[1] <<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
void main()
{
    long[] tmp = rdRow;
    long n = tmp[0], a = tmp[1], b = tmp[2];

    long l = b - 1;
    long r = n - a;
    long div = (b - a) / 2;
    long rem = (b - a) % 2;

    if (rem)
    {
        long s = b - a;
        long t = s / 2 + a;

        long u = n - b;
        long v = (n - a - u) / 2 + u + 1;

        min(l, r, t, v).writeln;
    }
    else
    {
        min(l, r, div).writeln;
    }
}

T rdElem(T = long)()
{
    //import std.stdio : readln;
    //import std.string : chomp;
    //import std.conv : to;

    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;

dchar[] rdDchar()
{
    //import std.conv : to;

    return rdStr.to!(dchar[]);
}

T[] rdRow(T = long)()
{
    //import std.stdio : readln;
    //import std.array : split;
    //import std.conv : to;

    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    //import std.range : iota;
    //import std.algorithm : map;
    //import std.array : array;

    return iota(col).map!(x => rdElem).array;
}

T[][] rdMat(T = long)(long col)
{
    //import std.range : iota;
    //import std.algorithm : map;
    //import std.array : array;

    return iota(col).map!(x => rdRow).array;
}

void wrMat(T = long)(T[][] mat)
{
    //import std.stdio : write, writeln;

    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256