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

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

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

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

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

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

int main() {
	LL n; cin >> n;
	VS s(n); REP(i, n)cin >> s[i];
	REP(i, n)SORT(s[i]);
	SORT(s);
	LL tmpsum = 0,tmpcount=0;
	LL sum = 0;
	REP(i, n-1) {
		tmpcount = 0;
		for (int j = i + 1; j<n&&s[i]==s[j]; j++) {
			tmpcount++;
          i++;
		}
		sum += tmpcount * (tmpcount + 1) / 2;
	}
	COUT(sum);
}

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

Measured memory_bytes: 7296
#include<iostream>
#include<queue>
#include<set>

#define INV (-1)
#define MAX 128
#define MAX_ENEMY 10
#define MAX_STORE 21

using namespace std;

const int even_di[] = {-1,-1,0,0,1,1};
const int even_dj[] = {0,1,-1,1,0,1};
const int odd_di[] = {-1,-1,0,0,1,1};
const int odd_dj[] = {-1,0,-1,1,-1,0};
const int infty = 1 << 26;

class Area{
 public:
  int store;
  int dist[MAX_STORE];
  bool valid;
  Area():store(INV),valid(false){
    for(int i = 0; i < MAX_STORE; ++i){
      dist[i] = infty;
    }
  }
};

class Map{
 public:
  int n,m;
  Area T[MAX][MAX];
  Map(){}
  Map(int n, int m):n(n),m(m){
    for(int i = 1; i < n+1; ++i){
      for(int j = 1; j < m+1; ++j){
	T[i][j].valid = true;
	for(int k = 0; k < MAX_STORE; ++k){
	  T[i][j].dist[k] = infty;
	}
      }
    }
  }
  int occupied(int store){
    int ret = 0;
    for(int i = 1; i < n + 1; ++i){
      for(int j = 1; j < m + 1; ++j){
	int minimum = infty;
	int id = -1;
	int cnt = 0;
	for(int k = 0; k < MAX_STORE; ++k){
	  if( k >= MAX_ENEMY && k != store ) continue;
	  minimum = min( minimum, T[i][j].dist[k] ); 
	}
	for(int k = 0; k < MAX_STORE; ++k){
	  if( k >= MAX_ENEMY && k != store ) continue;
	  if( minimum == T[i][j].dist[k] ){
	    ++cnt;
	    id = k;
	  }
	}
	if( cnt == 1 && id == store ){
	  ++ret;
	}
      }
    }
    return ret;
  }
};

class State
{
public:
  int i,j;
  int cost;
  State():i(0),j(0),cost(infty){}
  State(int i, int j, int cost):i(i),j(j),cost(cost){}
};
  
void store_bfs( int i, int j, int store, Map &M )
{
  queue< State > qpi;
  set<pair<int,int> > vis;
  qpi.push( State(i,j,0) );

  vis.insert(make_pair(i,j));
  while(!qpi.empty()){
    State now = qpi.front();
    qpi.pop();

    M.T[now.i][now.j].dist[store] = now.cost;
    
    for(int i = 0; i < sizeof(even_di)/sizeof(*even_di); ++i){
      int ti = now.i + ( now.i%2==0 ? even_di[i] : odd_di[i] );
      int tj = now.j + ( now.i%2==0 ? even_dj[i] : odd_dj[i] );
      
      if( !M.T[ti][tj].valid ) continue;
      if( vis.find( make_pair( ti, tj ) ) != vis.end() ) continue;
      
      vis.insert( make_pair( ti, tj ) );
      qpi.push( State(ti,tj,now.cost+1) );
    }
  }
}

int main()
{
  while(true){
    int m,n;
    int ans = 0;
    cin >> m;
    if( m == 0 ) break;
    cin >> n;
    if( n == 0 ) break;
    int st;
    Map M(n,m);
    
    cin >> st;
    for(int i = 0; i < st; ++i){
      int y,x;
      cin >> x >> y;
      //++x;++y;
      M.T[y][x].store = i;
      store_bfs( y, x, i, M );
    }
    
    int cands;
    cin >> cands;
    for(int i = 0; i < cands; ++i){
      int y,x;
      cin >> x >> y;
      //++x;++y;
      M.T[y][x].store = MAX_ENEMY + i;
      store_bfs( y, x, MAX_ENEMY+i, M );
    }
    

    /*
    for(int i = 0; i < n+2; ++i){
      for(int j = 0; j < m+2; ++j){
	cout << "(" << j << " , " << i << ") = ";
	for(int k = 0; k < MAX_STORE; ++k){
	  cout << M.T[i][j].dist[k] << ' ';
	}
	cout << endl;
      }
      cout << "--------" << endl;
    }
    */
    

    for(int i = 0; i < cands; ++i){
      ans = max( ans, M.occupied( MAX_ENEMY + i ) );
    }

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

}

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

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

signed main() {
  string s;
  cin >> s;

  int fir = (int)toInt(s.substr(0, 2));
  int sec = (int)toInt(s.substr(2, 2));

  if (fir == 0 && sec == 0) {
    cout << "NA" << endl;
    return 0;
  }

  if (fir == 0) {
    if (sec <= 12) {
      cout << "YYMM" << endl;
    } else {
      cout << "NA" << endl;
    }
    return 0;
  }

  if (sec == 0) {
    if (fir <= 12) {
      cout << "MMYY" << endl;
    } else {
      cout << "NA" << endl;
    }
    return 0;
  }

  if (fir >= 13) {
    if (sec <= 12) {
      cout << "YYMM" << endl;
    } else {
      cout << "NA" << endl;
    }
    return 0;
  }

  if (sec >= 13) {
    if (fir <= 12) {
      cout << "MMYY" << endl;
    } else {
      cout << "NA" << endl;
    }
    return 0;
  }

  cout << "AMBIGUOUS" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
#define mod 1e9
int a[100005],n,vis[100005],i;
int32_t main() {
	cin>>n;
	for(i=0;i<n;i++){cin>>a[i];
	a[i]--;
	}

	int ans=0,f=0;
	i=0;
	while(i!=1)
	{
		vis[i]=1;
		ans++;
		i=a[i];
		if(vis[i]==1)
			break;
	}
	if(i==1)
		cout<<ans;
	else cout<<-1;
	
	
}
						

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n;
	cin>>n;
	vector<int> p(n);
	for(auto &x : p){
		cin>>x;
	}
	int cur = n + 1, ans = 0;
	for(auto x : p){
		if(x < cur){
			cur = x; ans++;
		}
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
  char s[101],p[101];
  int i,j,sn=0,pn=0,t;
  scanf("%s %s",s,p);
  while(s[sn] != '\0') sn++;
  while(p[pn] != '\0') pn++;
  for(i=0;i<sn;i++){
    t=1;
    for(j=0;j<pn;j++)
      if(s[(i+j)%sn] != p[j]) t=0;
    if(t) break;
  }
  if( t )
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}
  
      



Measured memory_bytes: 2108
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>
#include<list>


using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;



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

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

	int maxT = t[0] + k;
	int cntV = 0;
	int cntB = 0;
	for (int i = 0; i < n; i++) {
		
		if (t[i] > maxT) {
			
			maxT = t[i] + k;
			cntV = 1;
			cntB++;
			continue;
		}

		cntV++;
		if (cntV > c) {
			maxT = t[i] + k;
			cntV = 1;
			cntB++;
			
		}
		
	}
	if (cntV > 0) {
		cntB++;
	}

	cout << cntB << endl;
}



Measured memory_bytes: 640
#coding:utf-8
from __future__ import division,print_function
try:
    input = raw_input
    range = xrange
except NameError:
    pass
# 上記のコードはPython2とPython3の違いを一部吸収するためのもの


# N * Mの表をつくる.すべての要素はvにする。
def make_matrix(N,M,v):
    # return [[v for i in range(M)] for j in range(N)]とも書ける。
    ret = []
    for i in range(N):
        l = []
        for j in range(M):
            l.append(v)
        ret.append(l)
    return ret


# gは行列(二次元配列)
def solve(n,m,g):
    # current_max[i][j] = 直前がjの場合のi日目の最大成長度
    current_max = make_matrix(m,n,-1)
    # 最初は何をあげても1.0のまま
    for i in range(n):
        current_max[0][i] = 1.0
    for i in range(1,m):
        # jは次にあげるもの
        for j in range(n):
            # 前に何をあげてたか
            for k in range(n):
                current_max[i][j] = max(current_max[i][j],
                                        current_max[i-1][k]*g[k][j])
    ret = max(current_max[m-1])
    ret = round(ret,3)
    print("%.2f" % ret)

def main():
    while True:
        # 受けとった文字列をintに変換する(リストの内包表記)
        n,m = [int(i) for i in input().split(" ")]
        if n == 0 and m == 0:
            return
        g = []
        for i in range(n):
            g.append([float(x) for x in input().split(" ")])

        solve(n,m,g)
main()

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

int i,j,k,m;
main()
{
    int c=0;
    int k,s;cin>>k>>s;
    for(i=0;i<=k;i++)
    {
        for(j=0;j<=k;j++)
        {
            int f=i+j;
            if((s-f)>=0&&(s-f)<=k) c++;
        }
    }
    cout<<c<<endl;
}


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

int main() {
	int n,k,d,x;
	cin>>n>>k;
	set<int> s;
	for(int i=1;i<=k;i++) {
		cin>>d;
		while(d--) {
			cin>>x;
			s.insert(x);
		}
	}
	//int co
	cout<<n-s.size()<<endl;
	return 0;
}


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

int gcd(int x,int y) {
    return ((x % y) ? gcd(y,x % y) : y);
}

int main(){
    ll sum = 0;
    int k;
    cin >> k;
    for(int i = 1; i <= k; i++) {
        for(int j = 1; j <= k; j++) {
            for(int t = 1; t <= k; t++) {
                sum += gcd(gcd(i,j),t);
            }
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 3680
/************************************
/ AUTHOR : YATHARTH GOSWAMI         /  
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define PI 3.14159265359

using namespace std;

/*ll powMod(ll a, ll y)
{
    ll ans = 1;
    
    while (y > 0) 
    { 
        if (y & 1) 
            ans = (ans*a) % MOD; 
  
        y = y>>1;
        a = (a*a) % MOD; 
    } 
    return ans;
}*/

/*ll modInv(ll a)
{
    return powMod(a, MOD-2);	
}*/

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    vector <ll> v(n);
    for (ll &x : v) cin >> x;
    ll maxx = 0, ans = 0;
    for (int i = 0; i < n; i++) {
        maxx = max(v[i], maxx);
        ans += (maxx-v[i]);
    }
    cout << ans << endl;
    return 0;
}




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

int main(){
    long long L, R;
    // vector<int> vp;
    // int vp[12][12];

    cin >> L >> R;
    // for (int j=0; j<N; j++){
    //     for (int i=0; i<D; i++){
    //         cin >> vp[j][i];
    //     }
    // }

    long long res = 2020;
    long long mod2019;

    for (long long i=L; i<=R-1; i++){
        for (long long j=i+1; j<=R; j++){
            // mod2019 = (i * j) % 2019;   // TLE
            mod2019 = ((i % 2019) * (j % 2019)) % 2019;
            
            if (mod2019 < res)
                res = mod2019;
            
            if (res == 0)
                break;
        }
        if (res == 0)
            break;
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

public class Main{
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
  
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        long ans = 0;
        
        ans = b / a;
        if (ans > c) {
            ans = c;
        }
        System.out.println(ans);
    }

}

Measured memory_bytes: 23124
#include <stdio.h>
long long min(long long a,long long b){return a<b?a:b;}
int main(void){
    long long a,b,c,ans;
    scanf("%lld%lld%lld",&a,&b,&c);
    ans=b;
    ans+=min(b,c);
    c-=min(b,c);
    if (c>0){
        ans+=min(a,c);
        c-=a;
    }
    if (c>0){
        ans++;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define ll long long
#define pb push_back
#define F first
#define S second
#define ld long double
#define rep(i,n) for (int i =0;i < (n); ++i)
#define vi vector<ll>
#define all(v) (v).begin(),(v).end()
const int inf = 1e9 + 10;

void solve() {
	ll x; cin >> x;
	for (ll i = -118; i < 119; i++) {
		for (ll j = -119; j < 118; j++) {
			if ((pow(i, 5) - pow(j, 5)) == x) {
				cout << i << " " << j;
				return;
			}
		}
	}
}

int main() {

	FASTIO;

#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	cout << fixed << setprecision(25);
	int t = 1;
	//cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 4096
var main = (input: string) => {
    const s: number = parseInt(input);

    let ans: number = distribution(s) % 1000000007;
    ans = (ans + 1000000007) % 1000000007;
    console.log(ans);
}

var memorizedDistribution = {};
function distribution(s: number) {
    if (s === 1 || s === 2) {
        return 0;
    } else if (s === 3) {
        return 1;
    }

    if (memorizedDistribution[s]) {
        return memorizedDistribution[s];
    } else {
        let d = (distribution(s - 1) + distribution(s - 3)) % 1000000007;
        memorizedDistribution[s] = d;
        return d;
    }
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29856
//url:
//problem name: Brick Break

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

char tolower(char c) {
  return (c + 0x20);
}

int main() {
    int N,K; cin >> N >> K;
    string S; cin >> S;
    S[K-1] = tolower(S[K-1]);
    cout << S << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    
    int i=0,count=0,m,n,j;
    scanf("%d",&m);
    int S[m];
    for(i=0;i<m;i++) scanf("%d",&S[i]);
    scanf("%d",&n);
    int T[n];
    for(i=0;i<n;i++) scanf("%d",&T[i]);
    
    for(j=0;j<n;j++){
        i=0;
    while (S[i] != T[j]){
        i++;
        if(i == m) break;
    }
    if (S[i] == T[j]) count++;
    }
    printf("%d\n",count);
    return 0;
}


Measured memory_bytes: 2076
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#include<deque>
#define rep(i,rept)	for(int i = 0; i<(ll)rept;++i)
typedef long long ll;
using namespace std;

//最終日

int main() {

	int n = 0;
	int dp[100010] = {}; //大きめにとる(10万はnの最大数)
	cin >> n;
	dp[0] = 0;//必ず0で初期化すること

	for (int i = 1; i <= 100000; i++) {
		dp[i] = 1145141919; //minをとるので大きな数で初期化する
	}

	int pow;

	//dp[i] →　i円を引き出すのに少なくともdp[i]回の操作が必要
	for (int i = 1; i <= 100000; i++) {
		pow = 1;
		while (pow <= i) {
			dp[i] = min(dp[i], dp[i - pow] + 1);//どんどんちいさい数に塗り替える
			pow *= 6;
		}
	    pow = 1;
		while (pow <= i) {
			dp[i] = min(dp[i], dp[i - pow] + 1);//どんどんちいさい数に塗り替える
			pow *= 9;
		}
	}

	cout << dp[n] << endl;

	return 0;
}

Measured memory_bytes: 640
n = gets.to_s.to_i

h = Array.new(n, 0)
ans = 0
d = $<.read.split.map{|t|t.to_i}.each_with_index do |e, i|
  ans      += h[i - e] if i - e >= 0
  h[i + e] += 1        if i + e < n
end

puts ans

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

using namespace std;

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

  int N; cin>>N;
  string S; cin>>S;

  auto alph_size = 'z' - 'a' + 1;

  for (char& c : S) {
	c -= 'A';
	c += N;
	c %= alph_size;
	c += 'A';
  }
  cout << S << endl;

  return 0;
}


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

#define int long long

typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;

#define endl '\n'
#define fi first
#define se second
#define all(v) v.begin(), v.end()

#define print(x)    cout << #x << " : " << x << endl;
#define darr(a,n)   for(int i=0; i<n; i++) cout << a[i] <<' '; cout<< '\n';
#define fast        ios_base::sync_with_stdio (false); cin.tie (nullptr);
#define dvec(vct)   for(auto i : vct) cout << i << " "; cout << endl;

const int maxn = 1e6;
const int mod = 1e9 + 7;
// const int mod = 998244353;


/*****************************************************************************/



void solve() {
    int n, m; cin >> n >> m;
    int ans = 0;
    ans += (n < 2) ? 0 : (n * (n-1))/2;
    ans += (m < 2) ? 0 : (m * (m-1))/2;
    cout << ans << endl;
}



/*****************************************************************************/



int32_t main() {
    fast;

    auto start = chrono::steady_clock::now();
    solve();

    auto end = chrono::steady_clock::now();
    auto diff = end - start;

}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[200010],b[200010];
int main()
{
	int n,i,j;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		b[i]=a[i];
	}
	sort(b+1,b+1+n);
	for(i=1;i<=n;i++)
	{
		if(a[i]!=b[n])printf("%d\n",b[n]);
		else printf("%d\n",b[n-1]);  
	}    
}

Measured memory_bytes: 3072
parseInt(x) = parse(BigInt, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n = readline() |> parseInt
	if n==2
		println(-1)
	elseif n==3
		println("aa.")
		println("..a")
		println("..a")
	else
		x = n%4+4
		for ii in 1:div(n-4,4)*4
			for jj in 1:n
				if div(jj-1,4)==div(ii-1,4)
					i = ii%4
					j = jj%4
					if (i,j)==(1,1)||(i,j)==(1,2)||(i,j)==(3,3)||(i,j)==(3,0)
						print("a")
					elseif (i,j)==(1,3)||(i,j)==(2,3)||(i,j)==(3,1)||(i,j)==(0,1)
						print("b")
					elseif (i,j)==(1,0)||(i,j)==(2,0)||(i,j)==(3,2)||(i,j)==(0,2)
						print("c")
					else
						print("d")
					end
				else
					print(".")
				end
			end
			println("")
		end
		for i in 1:x
			for j in 1:div(n-4,4)*4
				print(".")
			end
			if x==4
				if i==1
					print("aabc")
				elseif i==2
					print("ddbc")
				elseif i==3
					print("bcaa")
				else
					print("bcdd")
				end
			elseif x==5
				if i==1
					print("aabba")
				elseif i==2
					print("bcc.a")
				elseif i==3
					print("b..cb")
				elseif i==4
					print("a..cb")
				else
					print("abbaa")
				end
			elseif x==6
				if i==1
					print("aabc..")
				elseif i==2
					print("ddbc..")
				elseif i==3
					print("..aabc")
				elseif i==4
					print("..ddbc")
				elseif i==5
					print("bc..aa")
				else
					print("bc..dd")
				end
			elseif x==7
				if i==1
					print("aabbcc.")
				elseif i==2
					print("dd.dd.a")
				elseif i==3
					print("..d..da")
				elseif i==4
					print("..d..db")
				elseif i==5
					print("dd.dd.b")
				elseif i==6
					print("..d..dc")
				else
					print("..d..dc")
				end
			end
			println("")
		end
	end
end

main()

Measured memory_bytes: 181152
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AizuQueue solver = new AizuQueue();
        solver.solve(1, in, out);
        out.close();
    }

    static class AizuQueue {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            final int n = in.nextInt();
            final int q = in.nextInt();

			Queue queue = new Queue();
            for (int i = 0; i < n; i++) {
                final String id = in.next();
                final int t = in.nextInt();

                queue.enqueue(new Pair(id, t));
            }

            long curr = 0L;
            while (!queue.isEmpty()) {
                Pair p = queue.dequeue();

                if (p.t > q) {
                    curr += q;
                    p.t -= q;
                    queue.enqueue(p);
                } else {
                    curr += p.t;
                    out.printf("%s %d\n", p.id, curr);
                }
            }
        }

        static class Queue {
            private Node head;
            private Node tail;

            public Queue() {
                head = tail = null;
            }

            public void enqueue(final Pair p) {
                Node n = new Node(p, null, null);

                if (head == null) {
                    head = tail = n;
                } else {
                    tail.next = n;
                    n.prev = tail;
                    tail = n;
                }
            }

            public Pair dequeue() {
                if (head == null) {
                    throw new IllegalStateException("empty queue");
                }

                final Pair p = head.key;
                head = head.next;

                if (head == null) {
                    tail = null;
                }

                return p;
            }

            public boolean isEmpty() {
                return head == null;
            }

            static class Node {
				Pair key;
                Node next;
                Node prev;

                public Node(final Pair key, final Node prev, final Node next) {
                    this.key = key;
                    this.prev = prev;
                    this.next = next;
                }

            }

        }

        static class Pair {
            String id;
            int t;

            public Pair(final String id, final int t) {
                this.id = id;
                this.t = t;
            }

        }

    }
}




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



// 最大公約数を求める
// 計算量O(logn)
template<class T>
T gcd(T a, T b){
    if(b == 0) return a;
    return gcd(b, a%b);
}

// 最小公倍数を求める
// 計算量O(logn)
template<class T>
T lcm(T a, T b){
    return a/gcd(a,b)*b;
}

// 素数判定
// 計算量O(√n)
template<class T>
bool isPrime(T n){
    if(n < 2) return false;
    for(long long i = 2; i*i <= n; ++i) if(n % i == 0) return false;
    return true;
}

// 素数列挙
// nまでの素数をEratosthenesの篩で列挙する
// 計算量O(nloglogn)
template<class T>
vector<T> prime_list(T n){
    vector<T> ret;
    vector<T> isPrime(n+1,1);
    isPrime[0] = isPrime[1] = 0;
    for(long long i = 2; i <= n; ++i){
        if(isPrime[i] == 0) continue;
        ret.push_back(i);
        for(long long j = i*i; j <= n; j += i) isPrime[j] = 0;
    }
    return ret;
    // return isPrime;  // 状況によってはこっちを返す
}

// 素因数分解
// nを素因数分解してmapに記録
// 計算量O(√nlogn),必要ならmapではなくvectorにすると計算量を落とせる
template<class T>
map<T,int> prime_factor(T n){
    map<T,int> ret;
    if(n <= 0){
        cout << "Prime_factor Error" << "\n";
        return ret;
    }
    for(long long i = 2; i*i <= n; ++i){
        while(n%i== 0){
            ++ret[i];
            n /= i;
        }
    }
    if(n != 1) ret[n]++;
    return ret;
}


// 関数名：pow
// 概要：modつき指数関数
// 第一引数a：指数の底
// 第二引数b：指数
// 第三引数mod：法となる値
// 戻り値：a^b(m mod)
// 計算量O(log b)
template<class T>
T pow(T a, int b){
    if(b == 0) return 1;
    if(b%2){
        T ret = pow(a,(b-1)/2); 
        return ret*ret*a;
    }else{
        T ret = pow(a,b/2);
        return ret*ret;
    }
}

template<class T>
T pow(long long a, long long b, T mod){
    if(b == 0) return 1;
    if(b % 2 == 0){
        T d = pow(a,b/2,mod);
        return (d*d)%mod;
    }else return a%mod*pow(a,b-1,mod)%mod;
}


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

    const ll MOD = 1e9 + 7;
    ll n,k; cin >> n >> k;
    ll ans = 0LL;
    for(ll i = k; i <= n+1; ++i){
        ans += ((n*i%MOD - i*(i-1)+MOD)%MOD + 1 + MOD)%MOD;
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3612
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <array>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(void) {

	int n;
	std::string S;
	std::array<int, 'z' - 'a'+1> C;
	C.fill(INT16_MAX);

	std::cin >> n;
	
	for (int i = 0; i < n; i++) {
		std::cin >> S;
		std::array<int, 'z' - 'a'+1> Sc;
		Sc.fill(0);
		for (auto& c : S) {
			Sc[(int)(c - 'a')] ++;
		}
		for (int j = 0; j < C.size(); j++) {
			C[j] = std::min(C[j], Sc[j]);
		}
	}
	
	
	for (int i = 0; i < C.size(); i++ ) {
		for (int j = 0; j < C[i]; j++) {
			std::cout << (char)('a' + i);
		}
	}
	std::cout << std::endl;


	return 0;
}

Measured memory_bytes: 256
//----------------------------------------------------------------------
#include <bits/stdc++.h>
#include <iterator>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
//----------------------------------------------------------------------

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    string s;
    cin >> s;

    sort(s.begin(), s.end());
    cout << ( (s[0] == s[1] && s[2] == s[3] && s[1] != s[2]) ? "Yes" : "No" )<< endl;
    return 0;
}


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

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
#define all(v) (v).begin(), (v).end()
#define sz(v) (int) (v).size()

int main(int argc, char* argv[]) {
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  vector<int> dp(n);
  for (int i = 1; i < n; i++) {
    dp[i] = dp[i - 1] + abs(a[i] - a[i - 1]);
    if (i - 2 >= 0)
      dp[i] = min(dp[i], dp[i - 2] + abs(a[i] - a[i - 2]));
  }   
  cout << dp[n - 1] << '\n';
  return 0;
}

Measured memory_bytes: 3944
from bisect import bisect_left

a = [int(input()) for _ in range(int(input()))]
LIS = [a[0]]

for i, x in enumerate(a):
    if LIS[-1] < x:
        LIS.append(x)
    else:
        LIS[bisect_left(LIS, x)] = x

print(len(LIS))




Measured memory_bytes: 10356
#include <algorithm>
#include<iostream>
#include<stdio.h>
#include <algorithm>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<string>
#define rep(i,n) for(int i=0; i<(int)n; i++)//n回繰り返す
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
    string s; cin >> s;
    int N = s.size();
    int n = (N - 1) / 2;
    int m = (N + 3) / 2;
    bool a = true, b = true, c = true;
    rep(i, n) {
        if (s[i] == s[N - 1 - i]) {
            a = true;
        }
        else {
            a = false;
            break;
        }
    }
    rep(i, n / 2) {
        if (s[i] == s[n - 1 - i]) {
            b = true;
        }
        else {
            b = false;
            break;
        }


    }
    rep(i, (N - m) / 2) {
        if (s[m - 1 + i] == s[N - 1 - i]) {
            c = true;
        }
        else {
            c = false;
            break;
        }

    }
    if (a == true && b == true && c == true) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>

char s[20];
int szS;

int main()
{
	scanf("%s", s);
	szS = strlen(s);
	
	int minDiff = -1;
	
	int curDiff;
	for (int i = 0 ; i < szS - 2 ; i++)
	{
		int limit = i + 3;
		int num = 0;
		for (int j = i ; j < limit ; j++)
			num = num * 10 + s[j] - '0';
			
		if (num > 753)
			curDiff = num - 753;
		else
			curDiff = 753 - num;
			
		if (minDiff == -1 || curDiff < minDiff)
			minDiff = curDiff;
	}
	
	
	
	printf("%d\n", minDiff);
	
		
	return 0;
}

Measured memory_bytes: 128
def dfs(s, t, links):
    visited = set()
    q = [(s, 0)]
    while q:
        v, used = q.pop()
        if v == t:
            return used
        visited.add(v)
        for lb, u in links[v]:
            if u in visited:
                continue
            q.append((u, used | lb))


def bitcount32(n):
    n = ((n >> 1) & 0x5555555555555555) + (n & 0x5555555555555555)
    n = ((n >> 2) & 0x3333333333333333) + (n & 0x3333333333333333)
    n = ((n >> 4) & 0x0f0f0f0f0f0f0f0f) + (n & 0x0f0f0f0f0f0f0f0f)
    n = ((n >> 8) & 0x00ff00ff00ff00ff) + (n & 0x00ff00ff00ff00ff)
    n = ((n >> 16) & 0x0000ffff0000ffff) + (n & 0x0000ffff0000ffff)
    n = ((n >> 32) & 0x00000000ffffffff) + (n & 0x00000000ffffffff)
    return n


n = int(input())
links = [set() for _ in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    lb = 1 << i
    links[a].add((lb, b))
    links[b].add((lb, a))
conditions = []
m = int(input())
for i in range(m):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    conditions.append(dfs(u, v, links))

ans = 0
for i in range(1 << m):
    cnd_cnt = bitcount32(i)
    bit = 0
    k = i
    while k:
        b = k & -k
        j = b.bit_length() - 1
        bit |= conditions[j]
        k ^= b
    free_link_cnt = n - 1 - bitcount32(bit)
    val = 2 ** free_link_cnt
    if cnd_cnt % 2:
        ans -= val
    else:
        ans += val
print(ans)


Measured memory_bytes: 42344
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <stack>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
struct SEAT
{
    int first;
    int end;
};
int main(void)
{
    int N;
    cin >> N;
    SEAT *x;
    x = new SEAT[N];
    for (int i = 0; i < N; i++)
    {
        cin >> x[i].first >> x[i].end;
    }
    int sum = 0;
    for (int i = 0; i < N; i++)
    {
        sum += (x[i].end - x[i].first + 1);
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextInt()
    val b = sc.nextInt()
    println(problem152b(a, b))
}

fun problem152b(a: Int, b: Int): String {
    var aStr = ""
    for (i in 0 until b) {
        aStr += a.toString()
    }
    var bStr = ""
    for (i in 0 until a) {
        bStr += b.toString()
    }
    return if (aStr > bStr) bStr else aStr
}

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

int main() {
    int k,n;
    cin >>k>>n;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
    }
    vector<int> kyori(n);
    int kyori_max=0;
    rep(i,n-1){
        int b = a[i+1]-a[i];
        kyori_max=max(kyori_max,b);
    }
    kyori_max=max(kyori_max,k-(a[n-1]-a[0]));
    cout << k-kyori_max << endl;
}

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

int main(){
	int n, a, b, c, d;
	scanf("%d %d %d %d %d",&n,&a,&b,&c,&d);
	for (int i = 0; i <= n - 1; i++){
		if (b - a <= 1LL * i * d - 1LL * (n - i - 1) * c && b - a >= 1LL * i * c - 1LL * (n - i - 1) * d){
			printf("YES\n");
			return 0;
		}
	}
	printf("NO\n");
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

using namespace std;

#define int long long
#define deb(x) cout << #x << " " << x << endl;
#define pb push_back
#define pp pop_back
#define F first
#define S second
#define all(x) x.begin(),x.end()

#define MOD 1000000007
#define MAX 50000

typedef long long ll;
typedef long double ld;
const int N = 1e5 + 10;
const long double Pie = acos(-1);

signed main() 
{
	int n;
	cin >> n;
	
	int a[n], b[n], c[n];
	for (int i = 0; i < n; i++)
	{
		cin >> a[i] >> b[i] >> c[i];
	}
	
	int dp[n][3];
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];
	 
	for (int i = 1; i < n; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			dp[i][j] = 0;
		}
	}
	
	for (int i = 1; i < n; i++)
	{
		dp[i][0] = max(dp[i - 1][1] +a[i], dp[i - 1][2] + a[i]);
		dp[i][1] = max(dp[i - 1][0] +b[i], dp[i - 1][2] + b[i]);
		dp[i][2] = max(dp[i - 1][0] +c[i], dp[i - 1][1] + c[i]);
	}
	
	cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));

	return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
string alphabet = "abcdefghijklmnopqrstuvwxyz";
string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main(){
  int a , b;
  cin >> a >> b;
  cout << (a - 1) * (b - 1) << endl;
}


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

template<typename T> T In() { T v; cin >> v; return v; }

#define P(s) cout<<s<<endl

int main() {
    auto s1 = In<string>();
    auto s2 = In<string>();
    auto s3 = In<string>();
    P("A" << s2[0] << "C");
    return 0;
}

Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //d
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  for (auto& x : p) {
    cin >> x;
    x--;
  }
  vector<long long> c(n);
  for (auto& x : c) cin >> x;
  long long ans = -(1LL << 60);
  for (int i = 0; i < n; i++) {
    vector<bool> vis(n);
    vector<int> path;
    int cur = p[i];
    while (!vis[cur]) {
      path.push_back(cur);
      vis[cur] = true;
      cur = p[cur];
    }
    long long score = 0;
    long long kk = k;
    for (int j = 0; j < (int) path.size() && kk > 0; j++, kk--) {
      score += c[path[j]];
      ans = max(ans, score);
    }
    long long cycle = score;
    long long ccc = 1LL * (kk / (int) path.size());
    long long cc = max(0LL, ccc - 3);
    score += cc * cycle;
    kk -= cc * path.size();
    ans = max(ans, score);
    for (int j = 0; kk > 0; j++, kk--) {
      score += c[path[j % (int) path.size()]];
      ans = max(ans, score);
    }
    ans = max(ans, score);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3696
/*input
cupofcoffee
cupofhottea
*/
 
 
 
#include <bits/stdc++.h>
using namespace std;
 
 
 
#define int long long int
#define rep(i,n) \
    for(int i = 0; i < n; i++)
#define rep2(i, a, b) \
    for(int i = a; i < b; i++)
#define all(c) \
    c.begin(), c.end()
#define init(arr, num) \
    memset(arr, num, sizeof(arr))
#define fast\
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inputFile \
    freopen("input.txt", "r", stdin); 
#define outputFile \
    freopen("output.txt", "w", stdout);
#define modM 1000000007
#define PI 3.1415926535897932
#define F first
#define S second  
#define pb push_back  
#define INF 3e18
#ifdef gaviria
#define TRACE
#endif
#ifdef TRACE
#define trace(...) _f(#VA_ARGS, __VA_ARGS_)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std::endl;
 
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define trace(...)
#endif
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair< ll, ll > ii;
typedef unordered_set<int> usi;
 


ll n,i,j,k,m,x;



void solve()
{
    string a,b;
    cin>>a>>b;
int c=0;
    for(i=0;i<a.size();i++)
    {
        if(a[i]!=b[i])
            c++;
    }
    cout<<c;
}


 
 
 
signed main()
{
 
    // inputFile;
    // outputFile;
    fast;
    int T = 1;
    // cin >> T;
    // ll h=T;
    while(T--){
 
        solve();
        cout<<endl;
 
     
        
        
 
    }
    
    
    return 0;
 
}

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

int main()
{
    int N, R;
    cin >> N >> R;
    if (10 <= N)
    {
        cout << R << endl;
    }
    else
    {
        cout << R + 100 * (10 - N) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
  int a,b;
  char su,sut,k;
  while(1){
    scanf("%d%c%c%c%d",&a,&su,&k,&su,&b);
    if(k=='?')break;
    if(k=='+')printf("%d\n",a+b);
    else if(k=='-')printf("%d\n",a-b);
    else if(k=='*')printf("%d\n",a*b);
    else if(k=='/')printf("%d\n",a/b);
  }
  return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int lli;
typedef long double ld;
const int oo = 1e9;

int n;
const int nx = 1e5+5;
int ac[nx][3];
int dp[3][nx];
int go(int a, int i)
{
	if(i==n) return 0;
	if(dp[a][i] != -1) return dp[a][i];
	int& ans = dp[a][i];
	if(a==0)
	{
		ans=max(ans, go(1, i+1)+ac[i][0]);
		ans=max(ans, go(2, i+1)+ac[i][0]);
	}
	if(a==1)
	{
		ans=max(ans, go(0, i+1)+ac[i][1]);
		ans=max(ans, go(2, i+1)+ac[i][1]);
	}
	if(a==2)
	{
		ans=max(ans, go(0, i+1)+ac[i][2]);
		ans=max(ans, go(1, i+1)+ac[i][2]);
	}
	
	return ans;
	
}
int main()
{
    cin>>n;
    for(int i=0; i<n; i++) cin>>ac[i][0]>>ac[i][1]>>ac[i][2];
    memset(dp, -1, sizeof dp);
    cout<<max(go(0,0), max(go(1,0),go(2,0)))<<"\n";
    return 0;
}
	

Measured memory_bytes: 7296
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const ll LINF = 1e18;
const double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	bool b = true;
	REP(i, N) {
		int a;
		cin >> a;
		if (a % 2 == 1)b = false;
	}
	if (b) {
		cout << "second" << endl;
	}
	else {
		cout << "first" << endl;
	}
	PAU;
	return 0;
}


Measured memory_bytes: 504
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


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

  vector<int> p(N);
  REP(i, N) cin >> p[i];

  sort(ALL(p));
  p.emplace_back(INF);

  int num = 0;

  int ans = 0;
  int MIN = X;
  REP(i, 200){
    if(p[num] == i){
      num++;
      continue;
    }

    if(MIN > abs(X-i)){
      MIN = abs(X-i);
      ans = i;
    }
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 3640
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> ipair;
typedef tuple<int, int, int> ituple;

// const int INF = INT_MAX;
const ll INF = LLONG_MAX;
// const int MOD = ((int)1e9 + 7);
// const ld EPS = (1e-10);
#define PI acosl(-1)
#define MAX_N (100000 + 2)

void exec(){
  int n, w;
  ll dp[MAX_N][2];
  int weight, value;
  int now = 0, prev;
  cin >> n >> w;

  for (int i = 0; i < MAX_N; i++){
    dp[i][now] = INF;
  }

  dp[0][now] = 0;

  for (int i = 0; i < n; i++){
    cin >> weight >> value;
    prev = now;
    now = 1 - now;
    for (int j = 0; j < MAX_N; j++){
      dp[j][now] = dp[j][prev];
    }
    for (int j = 0; j < MAX_N; j++){
      if (j - value >= 0 && dp[j-value][prev] != INF){
        dp[j][now] = min(dp[j][now], dp[j - value][prev] + weight);
      }
    }
  }

  ll ans = 0;
  for (int i = 0; i < MAX_N; i++){
    if (dp[i][now] <= w){
      ans = i;
    }
  }

  cout << ans << endl;

}

void solve(){
  int t = 1;
  // scanf("%d", &t);
  for (int i = 0; i < t; i++){
    exec();
  }
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
int N;
int check=0;

long long int Min(long long int a, long long int b){
 if(a<=b)return a;
 else return b;
}

long long int Abs(long long int a){
  if(a>0)return a; 
  else return a*-1;
}

int main(void){
 int n,k;
 int x;
 int a;
 long long int ans=300000000000;
 vector<int> A;
 vector<int> B;
 

 cin>>n>>k;

 for(int i=0; i<n; i++){
  cin>>a;
  if(a<0)A.push_back(Abs(a));  
  else B.push_back(a);
 }
 
 sort(A.begin(),A.end());
 sort(B.begin(),B.end());
 
 if(A.size()>=k)ans=Min(ans,A[k-1]);
 if(B.size()>=k)ans=Min(ans,B[k-1]);
 //for(int i=0; i<A.size();i++)std::cout<<A[i]<<std::endl;

 for(int i=0; i<A.size(); i++){
  long long int sum=30000000000;
  if(k-1-(i+1)<B.size())sum=(long long int)A[i]*2+B[k-1-(i+1)];
  ans=Min(ans,sum);
  if(k-1-(i+1)<B.size())sum=A[i]+(long long int) B[k-1-(i+1)]*2;
  ans=Min(ans,sum);
 }
 std::cout<<ans<<std::endl;
}

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

#define stirng string
#define vvi vector<vector<int>>
#define vi vector<int>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

const int inf = 1e9 + 7;

int main() {
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	if(abs(a-c) <= d){
		cout << "Yes" << endl;
	}
	else if(abs(b-a) <= d && abs(b-c) <= d){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);


//Inputdata
static const int D = 365;
vector<int> c(D);
int s[D][26];
ll ans[D];
int last[26];  //コンテストが最後に行われた日
vector<int> t(D);

int checkScore(int d, int t){
 int score = 0;
 score += s[d][t];
 //last[t] = d;
 REP(i,26){
   score -= c[i] * (d - last[i]);
 }
 return score;
}

void input(){
  //input data
  int _;
  cin >> _;

  REP(i,26) cin >> c[i];
  REP(d,D){
    REP(i,26){
      int x;
      cin >> x;
      s[d][i] = x;
    }
  }

}

void initial(){
  REP(i,26) last[i] = -1;
  REP(d, D) ans[d] = 0;
  REP(d, D) t[d] = 1;
  //ans = 0;
}




int main(){
  input();

  initial();


  //cout << endl << "==ans==" << endl;

  // REP(d,D){
  //   int t;
  //   int score;
  //   cin >> t;
  //   --t;
  //   score = checkScore(d,t);
  //   cout << score << endl;
  // }


  int MX_score = 0;
  int MX_i = 0;

  //maxscore
  REP(d,D){
    MX_score = 0;
    REP(i,26){
      int score = 0;
      ans[d] = 0;
      score = checkScore(d, i);
      if(score > MX_score){
        MX_score = max(MX_score, score);
        t[d] = i + 1;
        MX_i = i;
      }
      //last[i] = 0;
    }
    ans[d] = MX_score;
    last[MX_i] = d;
    //cout << d   << " "<< MX_score << endl;
  }

  REP(d,D) cout << t[d] <<  endl;

  //ll sum = 0;

  // REP(d,D){
  //   cout << ans[d] << endl;
  //   sum += ans[d];
  // }
  //cout << sum << endl;

  return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <list>

int main() {
  int n, q;
  std::cin >> n >> q;
  std::list<int> l[n];
  for (int i = 0; i < q; ++i) {
    int c, t;
    std::cin >> c >> t;
    switch (c) {
    case 0:
      int x;
      std::cin >> x;
      l[t].push_back(x);
      break;
    case 1:
      for (auto it = l[t].begin(); it != l[t].end(); ++it) {
        if (it != l[t].begin())
          std::cout << " ";
        std::cout << *it;
      }
      std::cout << std::endl;
      break;
    case 2:
      int s;
      std::cin >> s;
      std::swap(s, t);
      l[t].splice(l[t].end(), std::move(l[s]));
      break;
    }
  }
}



Measured memory_bytes: 18636