akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;

public class Main
{
	public static void main(String[] args)
	{
		int[] h = new int[300];
		int[] w = new int[300];
		Scanner sc = new Scanner(System.in);
		int count=0,i=0,j=0,k=0;
		while(true)
		{
			h[count] = sc.nextInt();
			w[count] = sc.nextInt();
			if((h[count]==0)&&(w[count]==0))break;
			count++;
		}
		for(i=0;i<count;i++)
		{
			for(j=0;j<h[i];j++)
			{
				for(k=0;k<w[i];k++)
				{
					System.out.printf("#");
				}
				System.out.printf("\n");
			}
			System.out.printf("\n");
		}
	}
}

Measured memory_bytes: 61676
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int n,m,x;
    cin >> n >> m >> x;
    vector<int> a(10000);
    int costr=0;
    int costl=0;
    for(int i=0;i<m;i++){
        int x;
        cin >> x;
        a[x]=1;
    }
    for(int i=x-1;i>=0;i--){
        costl+=a[i];
    }
    for(int i=x+1;i<=n;i++){
        costr+=a[i];
    }
    cout << min(costl,costr) << endl;
}

Measured memory_bytes: 256
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
    #include<numeric>
    #include<array>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
    #define chmin(a, b) a = min(a, b)
    #define chmax(a, b) a = max(a, b)
    #define Vl vector<ll>
     
    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
     
const ll MOD = 1e9 + 7;
const ll ZER = 0;

int main(){
   string s;
   cin >> s;
   ll n = s.size();
   
   ll res = 0, sum = 0;
   rep(i, n)res += (s[i] - '0');
   rep(i, n){
       sum += (s[i] - '0');
       if(s[i] != '0'){
           chmax(res, sum + (n - i - 1) * 9 - 1);
       }
   }
   cout << res << endl;
}


Measured memory_bytes: 3600
module AOJ_Volume0096;

import std.stdio,std.string,std.conv;

int main()
{
	int k[4001];
	foreach(i;0..4001)
	{
		k[i] = i+1;
	}

	string s;
	while((s = readln.chomp).length != 0)
	{
		int n = s.to!int;
		int count = 0;
		foreach(a;0..1001)
		{
			foreach(b;0..1001)
			{
				if(a + b <= n)
				{
					int m = n - a - b;
					if(m <= 1000)
					{
						count += k[m];
					}
					else if(m <= 2000)
					{
						count += k[2000 - m];
					}
				}
			}
		}

		count.writeln;
	}
	return 0;
}

Measured memory_bytes: 1064
//参考：https://qiita.com/DaikiSuyama/items/9dba963ba74396b9b7fd
//インクルード(アルファベット順)
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define FIR first    //pairの一つ目の要素
#define SEC second   //pairの二つ目の要素

enum Trend
{
    discend = -1,
    equal = 0,
    ascend = 1,
};

ll break_point(vector<ll> a)
{
    if (SIZE(a) < 3)
        return SIZE(a);

    Trend t;
    if (a[1] > a[0])
        t = Trend::ascend;
    else if (a[1] < a[0])
        t = Trend::discend;
    else
        t = Trend::equal;

    ll i;
    for (i = 2; i < SIZE(a); i++)
    {
        if (t == Trend::ascend && a[i] < a[i - 1])
            return i;

        if (t == Trend::discend && a[i] > a[i - 1])
            return i;

        if (t == Trend::equal && a[i] > a[i - 1])
            t = Trend::ascend;

        if (t == Trend::equal && a[i] < a[i - 1])
            t = Trend::discend;
    }

    return i + 1;
}

signed main()
{
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll N;
    cin >> N;

    if (N < 3)
    {
        cout << 1 << endl;
        return 0;
    }

    vector<ll> A(N);
    REP(i, N)
    cin >> A[i];

    ll index = 0, ans = 0;
    while (index < N)
    {
        index = index + break_point(vector<ll>(A.begin() + index, A.end()));
        ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4464
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
ld a[101][2]={0};
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i][0]>>a[i][1];
    }
    ld mx=0;
    for(ll j=0;j<(ll)1e6;j++){
    ld theta= ((j*M_PI)/1e+6);
    ld xp=0,xn=0,yp=0,yn=0;
    for(int i=0;i<n;i++){
        ld x=a[i][0];
        ld y=a[i][1];
        ld xx=sin(theta)*y+cos(theta)*x;
        ld yy=-1*sin(theta)*x+cos(theta)*y;
        if(xx>=0){xp+=xx; yp+=yy;}
        if(xx<=0){xn+=xx; yn+=yy;}
        }
     ld temp=max(sqrt(xn*xn+yn*yn),sqrt(xp*xp+yp*yp));
     mx=max(mx,temp);
    }
    cout<<fixed<<setprecision(11)<<mx;
    return 0;
}

Measured memory_bytes: 512
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println(sort(sc.next()).equals("abc")?"Yes":"No");

    }

    static String sort(String input){
        String output="";
        char[] chars=new char[input.length()];
        for(int i=0;i<chars.length;i++){
            chars[i]=input.charAt(i);
        }
        Arrays.sort(chars);
        for(int i=0;i<chars.length;i++){
            output+=chars[i];
        }
        return output;
    }
}

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

int main () {
  int line[3] ;
  for(int i = 0 ; i < 3 ; i++ ) cin >> line[i] ;
  if(line[2] == line[1] && line[1] == line[0] ) cout << "Yes" << endl ;
  else cout << "No" << endl ;
}

Measured memory_bytes: 256
import math

N, D = list(map(int, input().split()))
x = [input().split() for l in range(N)]
count = 0
for i in range(N):
    for j in range(i+1,N):
        norm = 0
        for k in range(D):
            diff = abs(int(x[i][k]) - int(x[j][k]))
            norm += diff * diff
        
        bool1 = False
        for k in range(1, norm+1):
            if k*k == norm:
                bool1 = True
        
        if bool1:
            count += 1

print(count)
        

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  i64 m = 1;

  vector<i64> vs(N + 1);
  vector<int> as(N + 1);

  i64 inf = INT64_MAX >> 3;

  // 全部子が2つであると仮定して、頂点数を増やしていく
  F0R(i, N + 1) {
    int a;
    cin >> a;
    as[i] = a;

    vs[i] = m;
    m = (m - a) * 2;
    if (m > inf) m = inf;
    //debug(m);
  }
  //Print(vs);

  i64 sum = 0;

  if (m < 0) {
    cout << -1;
    return 0;
  }

  // 頂点数のあまり
  m /= 2;
  //debug(m);

  if (m > 0) {
    vs.back() = as.back();
  }
  RF0(i, N) {
    if (vs[i] > vs[i + 1] + as[i]) {
      vs[i] = vs[i + 1] + as[i];
    }
  }
  //Print(vs);

  F0R(i, N + 1) {
    sum += vs[i];
    if (vs[i] <= 0) {
      sum = -1;
      break;
    }
  }
  if (sum == 0) sum = -1;
  if (vs[0] != 1) sum = -1;

  cout << sum << newl;
}
#endif


Measured memory_bytes: 4516
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1000000000
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repX(i, n ,x) for (int i = x; i < (int)(n); i++)
#define repM(i, n) for (int i = n; i > 0; i--)

int main() {
    string S;
    cin >> S;
    string week[] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
    rep(i,7){
        if(S==week[i]){
            if(i!=0){
                cout << 7-i << endl;
            }else{
                cout << "7" << endl;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define int long long
using namespace std;
using P=pair<int,int>;
using Graph=vector<vector<int>>;
using ll=long long;

//map<pair<int,int>,int> dp;
vector<int> dp(10e5+1);
int solve(vector<int> value,vector<int> weight,int v,int l){
    map<pair<int,int>,int> dp;
    
    int i=0;
    while(v!=0){
        for(int w=0;w<=l;w++){
            if(w>=weight[v-1]) dp[mp(i+1,w-weight[v-1])]=max(dp[mp(i,w-weight[v-1])]+value[v-1],dp[mp(i,w)]);
            else dp[mp(i+1,w)]=dp[mp(i,w)];
        }
        v/=2;
        i++;
    }

    return dp[mp(i,l)];
}

signed main(){ 
    int x,n; cin>>x>>n;

    set<int> p;
    for(int i=0;i<n;i++){
        int pi; cin>>pi;
        p.insert(pi);
    }

    if(n==0){
        string s;
        getline(cin,s);
        cout<<x<<endl;
        return 0;
    }

    for(int i=0;i<100;i++){
        if(p.count(x-i)==false){
            cout<<x-i<<endl;
            return 0;
        }
        if(p.count(x+i)==false){
            cout<<x+i<<endl;
            return 0;
        }
    }


}  

Measured memory_bytes: 10988
import math

short, long, hour, minute = map(int, input().split())
time = hour * 60 + minute
s_angle = math.pi * (time / 720) * 2
l_angle = math.pi * (minute / 60) * 2
l_x = long * math.cos(l_angle)
l_y = long * math.sin(l_angle)
s_x = short * math.cos(s_angle)
s_y = short * math.sin(s_angle)
r_long = math.sqrt((l_x - s_x) ** 2 + (l_y - s_y) ** 2)
print(r_long)

Measured memory_bytes: 9524
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
using namespace std;

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

    if((a + b) % 2 == 1) {
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }

    cout << (a + b) / 2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
int main()
{	
	int N,K;
	string S;
	cin>>N>>K>>S;
	int mass=0;
	vector<int> massset;
	for(int i=0; i<N; i++)
	{
		if(mass==0)
		{
			if(S[i]=='0')
			{
				mass=-1*1;
			}
			else
			{
				mass=1;
			}
		}
		else if(mass<0 && S[i]=='1')
		{
			massset.push_back(mass);
			mass=1;
		}
		else if(mass>0 && S[i]=='0')
		{
			massset.push_back(mass);
			mass=-1*1;
		}
		else if(mass>0 && S[i]=='1')
		{
			mass++;
		}
		else if(mass <0 && S[i]=='0')
		{
			mass--;
		}
		
		if(i==N-1)
		{
			massset.push_back(mass);
		}
	}
	int mssize=massset.size();
	int mininum=0;
	for(int i=0; i<mssize; i++)
	{
		if(massset[i]<0)
		{
			mininum++;
		}
	}
	vector<int> subconsum;
	int nextstart=0;
	int firstsum=0;
	int last=0;
	bool isfastpossible=false;
	int numofm=0;
    for(int i=0; i<mssize; i++)
    {
      if(massset[i]<0)
      {
        numofm++;
      }
    }
	//calculate subconsum 0
	if(numofm<=K)
	{
		cout<<N<<endl;
	}
	else
	{
		int fc=0;
	for(int i=0; i<mssize; i++)
	{
		firstsum+=abs(massset[i]);
		if(fc==1 && massset[i]>0)
		{
			nextstart=i;
		}
		if(massset[i]<0)
		{
			fc++;
		}
		if(fc==K && massset[i]>0)
		{
			last=i;
			break;
		}
	}
	subconsum.push_back(firstsum);
	int checker=0;
	while(subconsum.size()<mininum-K+1)
	{
		int newsum=subconsum.back();
		int mcount=0;
		for(int j=nextstart-1; j>=0; j--)
		{
			newsum-=abs(massset[j]);
			if(massset[j]<0)
			{
				mcount++;
			}
			if(mcount==1 && massset[j]>0)
			{
				break;
			}
		}
		mcount=0;
		nextstart+=2;
		for(int j=last+1; j<mssize; j++)
		{
			newsum+=abs(massset[j]);
			if(massset[j]<0)
			{
				mcount++;
			}
			if(mcount==1 && massset[j]>0)
			{
				last=j;
				break;
			}
		}
		subconsum.push_back(newsum);
	}
	
	sort(subconsum.begin(),subconsum.end());
	cout<<subconsum.back()<<endl;
	}
}

Measured memory_bytes: 1272
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1<<29)
#define EPS 1e-10
#define MOD 1000000007

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int N,T,L,B;
int l[128],b[128];
double dp[128][128];


int main(){
  while(cin >> N >> T >> L >> B && N+T+L+B){
    memset(l,0,sizeof(l));
    memset(b,0,sizeof(b));
    rep(i,L){
      int x; cin >> x;
      l[x] = 1;
    }
    rep(i,B){
      int x; cin >> x;
      b[x] = 1;
    }
    memset(dp,0,sizeof(dp));
    dp[0][0] = 1.0;
    rep(i,T){
      for(int cur=0;cur<N;cur++){
	for(int j=1;j<=6;j++){
	  int tar = cur+j;
	  if(tar > N) tar = 2*N-tar;
	  if(b[tar]) tar = 0;
	  if(l[tar]){
	    dp[i+2][tar] += dp[i][cur]/6.0;
	  }else{
	    dp[i+1][tar] += dp[i][cur]/6.0;
	  }
	}
      }
    }

    double res = 0;
    rep(i,T+1) res += dp[i][N];
    cout << fixed << setprecision(12) << res << endl;
  }
  return 0;
}

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

int main() {
  
  ll N, M;
  cin>>N>>M;
  vector<ll> A(N), B(N), I(N);
  for(ll i = 0; i < N; i++){
    cin>>A[i]>>B[i];
    I[i] = i;
  }
  sort(I.begin(), I.end(), [&](ll l, ll r){ return A[l] < A[r]; });
  ll sum = 0;
  for(ll i = 0; i < N; i++){
    ll j = I[i];
    if(M > B[j]){
      M -= B[j];
      sum += A[j] * B[j];
    }else{
      sum += A[j] * M;
      break;
    }
  }
  cout<<sum<<endl;
  
}


Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
class TOPO{//out is tsort's return.
	public:
	vvi G;
	vi out;
	vector<bool>V;
	vi indeg;
	int n;
	TOPO(int size){
		n=size;
		G=vvi(n);
		out=vi(0);
		V=vector<bool>(n);
		indeg=vi(n);
	}
	void add_edge(int s,int t){
		G[s].pb(t);
	}
	void bfs(int s){
		queue<int>q;
		q.push(s);
		V[s]=true;
		while(!q.empty()){
			int u=q.front();q.pop();
			out.pb(u);
			rep(i,G[u].size()){
				int v=G[u][i];
				indeg[v]--;
				if(indeg[v]==0&&!V[v]){
					V[v]=true;
					q.push(v);
				}
			}
		}
	}
	void tsort(){
		rep(i,n)indeg[i]=0;
		rep(i,n)rep(j,G[i].size()){
			int v=G[i][j];
			indeg[v]++;
		}
		rep(i,n)if(indeg[i]==0&&!V[i])bfs(i);
		rep(i,n)cout<<out[i]+1<<endl;
	}
};
int main(){
	int n,m;
	cin>>n>>m;
	TOPO tp(n);
	while(m--){
		int a,b;
		cin>>a>>b;
		a--;b--;
		tp.add_edge(a,b);
	}
	tp.tsort();
}
 
 

Measured memory_bytes: 1224
import java.io.*;
import java.util.*;

public class Main {
    static PrintWriter out = new PrintWriter(System.out);
    static Scanner sc = new Scanner(System.in);
    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    long[] res;
    ArrayList<Integer>[] tree;
    public static void main(String[] args) throws IOException {
        Main main = new Main();
//        main.solve();
        out.println(main.solve());
        out.flush();
    }
    long solve(){
        long x = sc.nextLong();
        long cur = 100;
        for(int i=1;i<=500000;i++){
            cur += cur/100;
            if(cur>=x) return i;
        }
        return 0;
    }
}



Measured memory_bytes: 35904
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <stack>
#include <vector>
#include <random>
#include <set>
#include <map>
#include <queue>
#include <bitset>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)

int main(){
	ll n,a,b;
	cin >> n >> a >> b;
	n %= 12;
	FOR(i,1,n+1){
		if(i&1){
			a = a-b;
		}else{
			b = a+b;
		}
	}
	cout << a << " " << b << endl;
}



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

#define int long long
#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define mp make_pair
#define mt make_tuple
#define DESYNC                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define all(x) x.begin(), x.end()
#define EPS 1e-9
#define INF 1e18
#define ROOT 1
#define M 1000000007
#define curtime chrono::steady_clock::now().time_since_epoch().count
#define rep(i, beg, n, s) for (int i = beg; i < n; i += s)
const double PI = acos(-1);

using namespace std;

inline int mod(int n, int m) {
  int ret = n % m;
  if (ret < 0) ret += m;
  return ret;
}

int gcd(int a, int b) {
  if (a == 0)
    return b;
  else
    return gcd(b % a, a);
}
void solution() {
  int x, n;
  cin >> x >> n;
  int best = 1000000000;
  int ans = 10000000;
  set<int> s;
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    s.insert(k);
  }
  for (int i = x - 100; i <= x + 100; i++) {
    if (abs(x - i) < best || (abs(x - i) == best && ans > i)) {
      if (s.count(i)) continue;
      ans = i;
      best = abs(x - i);
    }
  }
  cout << ans << endl;
}

int32_t main() {
  DESYNC;
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  int t = 1;
#ifdef MULTIPLE_TEST_CASE
  cin >> t;
#endif
  while (t--) solution();
}


Measured memory_bytes: 3660
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true) {
        	int H = sc.nextInt();
        	int W = sc.nextInt();
        	if(H == 0 && W == 0) {
        		break;
        	}else {
        		for(int i = 0;i < H;i++) {
            		for(int j = 0;j < W;j++) {
            			if(i == 0 | i == H -1 | j == 0 | j == W - 1) {
            				System.out.print("#");
            			}else {
            				System.out.print(".");
            			}

            		}
            		System.out.println();
            	}
        		System.out.println();
        	}

        }
    }
}


Measured memory_bytes: 35376
input_d1 = int(input()) 
input_d2 = list(input().split())

c = sorted(input_d2)
c.append('0')
e = {'0':0}
g = [0]
s = 0

for i in range(0,input_d1):
    if c[i] == c[i+1]:
        pass
    else:
        g.append(i+1)
        e[c[i]] = i + 1 - g[s]
        s += 1

e.pop('0')
d = {}
f = sum(map(lambda x:x*(x-1)/2 , e.values()))

for i in e.keys():
    d[i] = 1 - e[i] + f


for i in input_d2:
    print(int(d[i]))

Measured memory_bytes: 45404
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aryssoncf
 */



// Taken from: https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/templateShort.cpp

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<ull> vul;
typedef vector<ll> vl;
typedef vector<pi> vpi;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i,0,a)
#define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i, a) ROF(i,0,a)
#define trav(a, x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

#define mp make_pair
#define pb push_back
#define f first
#define s second

const int MOD = 1e9 + 7; // 998244353; // = (119<<23)+1
const int MX = 2e5 + 5;

template<class T>
bool ckmin(T &a, const T &b) {
    return a > b ? a = b, 1 : 0;
}

template<class T>
bool ckmax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

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


//
// Created by aryssoncf on 28/10/2019.
//

#include <type_traits>


#include <iterator>
#include <utility>

template<typename T>
constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) {
    return true;
}

constexpr bool hasBegin(...) {
    return false;
}

template<typename T>
using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>;


#ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP
#define JHELPER_EXAMPLE_PROJECT_IO_HPP

#endif //JHELPER_EXAMPLE_PROJECT_IO_HPP

template<typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
    for (T &element: vec) {
        is >> element;
    }
    return is;
}

template<typename T, typename U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    is >> p.first;
    is >> p.second;
    return is;
}

template<class X, class Y>
std::ostream &operator<<(std::ostream &os, std::pair<X, Y> const &p) {
    return os << p.first << " " << p.second;
}

template<class Ch, class Tr, class Container>
std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, Container const &x) {
    bool first = true;
    for (auto &y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}

using namespace std;

/*
PROG:
LANG: C++
*/

class ANextAlphabet {
public:
    void solve(std::istream &in, std::ostream &out) {
        char c;
        in >> c;
        char res = c + 1;
        out << res << "\n";
    }

    void setup() {}
};


int main() {
    std::ios_base::sync_with_stdio(false);
    ANextAlphabet solver;
    solver.setup();
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
    solver.solve(in, out);
    return 0;
}


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

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    const ll mod=1000000007;
    int n;
    cin >> n;
    vector<ll> a(n+1,0);
    ll s=0;
    for(int i=1;i<=n;i++)
    {
        cin >> a[i];
        s=(s+a[i])%mod;
    }
    ll res=0;
    for(int i=1;i<=n;i++)
    {
        s=(s-a[i]+mod)%mod;
        res=(res+a[i]*s)%mod;
    }
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 4780
#include <stdio.h>
#define N 2000000
#define I 10000
int a[N+1],b[N+1],c[N+1];
main(){
  
  int n,i,j,k;
 
  scanf("%d",&n);
 
  
  for(i=0; i<n; i++){
    scanf("%d",&a[i+1]);
    if(a[i]<a[i+1])
      k=a[i];
  }
  
  for(i=0; i<n; i++)
    c[i]=0;
  
  
  for(i=0; i<n; i++)
    c[a[i+1]]++;
 
  
  for(i=0; i<N; i++)
    c[i+1]=c[i+1]+c[i];
  
  
  for(i=n; i>0; i--){
    b[c[a[i]]]=a[i];
    c[a[i]]--;
  }
  
  
  for(i=0; i<n-1; i++)
    printf("%d ",b[i+1]);
  printf("%d\n",b[n]);
  

  return 0;
}

Measured memory_bytes: 24036
let rec for_fold a b v f = if a >= b then v else for_fold (a+1) b (f v a) f
let s = Scanf.scanf "%s" (fun x -> x)
let n = String.length s
let solve k1 k2 = begin
  if s.[n-1] = '1' then k1 () else
  let ok = for_fold 0 (n-1) true (fun b i -> b && s.[i] = s.[n-2-i]) in
  if s.[0] = '0' || not ok then k1 () else
  let rec constr acc r i =
    if i-1 > n/2 then begin
      for_fold i (n+1) acc (fun acc j -> (r,j)::acc)
      |> List.rev
    end else
      if s.[i-2] = '1' then constr ((r,i)::acc) i (i+1)
      else constr ((r,i)::acc) r (i+1)
  in
  constr [] 1 2 |> k2
end
let () =
  solve (fun () -> print_endline "-1")
        (List.iter (fun (a,b) -> Printf.printf "%d %d\n" a b))


Measured memory_bytes: 11264
nn = gets.to_i
# 各選手の最近の試合配列
r_ar = []
aa =
  nn.times.map do
    arr = gets.split.map(&:to_i)
    r_ar << arr.shift
    arr
  end

day = 0

pop_ar = (0..(r_ar.size-1)).to_a
while r_ar.compact.size > 0 do
  ans_ar=[]
  pop_ar.sort.each do |i|
    # 次の試合予定ないならスキップ
    next if r_ar[i].nil?
    # 試合する
    if i+1 ==r_ar[r_ar[i]-1]
      ans_ar<<i<<r_ar[i]-1
    end
  end
  # 循環してるならできない
  if ans_ar.size==0
    puts -1
    exit
  end
  # 重複してるものは除く
  pop_ar = ans_ar.uniq

  #puts pop_ar.to_s#d
  # 試合した人は次の試合予定を入れる
  pop_ar.each do |n_i|
    r_ar[n_i] = aa[n_i].shift
  end

  # 1日経過
  day+=1
end
puts day


Measured memory_bytes: 45432
var N = 0;
var humans = [];

function parse(stdin){
    var lines = stdin.split("\n");
    for(i = 0; i < lines.length; i++){
        var line = lines[i];
        if (i === 0) N = parseInt(line);
        else {
            var input = line.split(" ");
            if (input.length === 1) humans.push([]);
            else humans[humans.length - 1].push(input.map(x => parseInt(x)))
        }
    }
}

function createHonests(num) {
    var creating = [];
    var binary = num.toString(2).split('');
    while (creating.length !== N) {
        binary.length ? creating.unshift(parseInt(binary.pop())) : creating.unshift(0)
    }
    return creating
}

function main() {
    var patterns = Math.pow(2, N);

    for (i = patterns - 1; i >= 0; i--) {

        // 正直者の組み合わせを仮定
        var honests = createHonests(i);

        // 仮定が矛盾したか否か
        var isCont = false;

        for (j = 0; j < humans.length; j++) {
            // 嘘つきの証言は無視
            if (honests[j] === 0) continue;

            // 正直者の証言をチェック
            var words = humans[j];
            for (k = 0; k < words.length; k++) {
                var word = words[k];
                var isHonest = honests[word[0] - 1]
                // 仮定と矛盾したらbreak
                if (isHonest !== word[1]) {
                    isCont = true;
                    break;
                }
            }
        }
        // breakしなかったら矛盾してないので最大数
        if (!isCont) {
            return honests.reduce((acc, val) => acc += val, 0);
        }
    }

    return 0;
}

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

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

int main() {
    int n;
    cin >> n;
    int x;
    vector<int> ans(n);
    rep(i,n-1) {
        cin >> x;
        ans[x-1]++;
    }
    rep(i,n) cout << ans[i] << endl;
    return 0;
}

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

int main(void)
{
    ll n, m;
    cin >> n >> m;
    string str(n, ' ');
    bool error = false;
    for (int i = 0; i < m; i++)
    {
        ll s;
        char c;
        cin >> s >> c;
        s = s - 1;
        if (str[s] != ' ' && c != str[s])
        {
            error = true;
        }
        str[s] = c;
    }
    ll ans;
    if ((n != 1 && str[0] == '0') || error)
    {
        ans = -1;
    }
    else
    {
        replace_if(
            begin(str), end(str), [](char ch) { return ch == ' '; }, '0');
        ans = stoi(str);
        if (n != 1 && pow(10, n - 1) > ans)
        {
            str[0] = '1';
            ans = stoi(str);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

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

   while(1){
      c-=b;
      if(c<=0){printf("Yes\n");return 0;}
      a-=d;
      if(a<=0){printf("No\n");return 0;}
   }
   return 0;
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

struct UnionFind{
    std::vector<int> parent, rank, cnt, wi;

    UnionFind(int n) : parent(n), rank(n, 0), cnt(n, 1), wi(n, 0) {
        std::iota(parent.begin(), parent.end(), 0);
    }

    int find(int v){
        if(v == parent[v]){return v;}
        return parent[v] = find(parent[v]);
    }

    bool same(int v, int w){
        return find(v) == find(w);
    }

    void unite(int v, int w){
        v = find(v);
        w = find(w);

        if(v == w){return;}

        if(rank[v] > rank[w]){
            parent[w] = v;
            cnt[v] += cnt[w];
            wi[v] += wi[w];
        }else{
            parent[v] = w;
            cnt[w] += cnt[v];
            wi[w] += wi[v];
            if(rank[v] == rank[w]){rank[w] += 1;}
        }
    }

    int count(int v){
        return cnt[find(v)];
    }

    int width(int v){
        return wi[find(v)];
    }
};

UnionFind uf(100100);
int N;
std::vector<P> ps;
std::vector<int> ys;

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

    std::cin >> N;

    for(int i=0;i<N;++i){
        int x, y;
        std::cin >> x >> y;

        ps.emplace_back(x, y);
        ys.emplace_back(y);
    }

    std::sort(ys.begin(), ys.end());
    ys.erase(std::unique(ys.begin(), ys.end()), ys.end());
    
    for(int i=0;i<N;++i){
        snd(ps[i]) = std::lower_bound(ys.begin(), ys.end(), snd(ps[i])) - ys.begin();
    }

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

    for(int i=0,j=1;i<N;){
        while(j < N && fst(ps[j]) == fst(ps[i])){
            uf.unite(snd(ps[j]), snd(ps[i]));
            j += 1;
        }

        uf.wi[uf.find(snd(ps[i]))] += 1;

        i = j;
        j += 1;
    }

    ll res = 0;

    for(int i=0;i<ys.size();++i){
        if(i == uf.find(i)){
            // std::cout << ys[i] << ", " << uf.count(i) << ", " << uf.width(i) << std::endl;
            res += 1ll * uf.count(i) * uf.width(i);
        }
    }

    res -= N;

    std::cout << res << std::endl;
}


Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
const int MOD = 1e9+7;
int ans=0;
int main(){
  int n,m;
  cin >> n >> m;
  vector<int> s(n),t(m);
  for(int i=0;i<n;i++) cin >> s[i];
  for(int i=0;i<m;i++) cin >> t[i];
  vector<vector<int>> dp(n+1,vector<int> (m+1,0));
  dp[0][0]=1;
  for(int i=0;i<n;i++){
    int cnt = 0;
    for(int j=0;j<m;j++){
      cnt = (cnt + dp[i][j]) % MOD;
      dp[i+1][j] = (dp[i+1][j] + dp[i][j]) % MOD; 
      if(s[i]==t[j]) dp[i+1][j+1] = (dp[i+1][j+1] + cnt) % MOD;
    }
    dp[i+1][m] = (dp[i+1][m] + dp[i][m])%MOD;
  }
  for(int j=0;j<m+1;j++) ans = (ans + dp[n][j])%MOD;
  cout << ans << endl;
}


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

int main() {
  string s; cin >> s;
  //奇数が全てRUDのいずれか
  //偶数が全てLUDのいずれか
  bool ans = true;
  rep(i, s.size()) {
    if (i%2 == 0) {
      if (s[i] == 'L') ans = false;
    }
    if (i%2 == 1) {
      if (s[i] == 'R') ans = false;
    }
  }
  if (ans) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 768
import itertools

def getint(): return int(input())
def getints(): return list(map(int, input().split()))

n=getint()
a=getints()
inf = 1 << 60

cache=[[-inf] * 2 for _ in range(n)]

def solve(pos, minus):
    if pos == n - 1:
        return -a[pos] if minus else a[pos]
    res = cache[pos][minus]
    if res > -inf:
        return res
    now = a[pos] if minus == 0 else -a[pos]
    res1 =  now + solve(pos + 1, 0)
    res2 = -now + solve(pos + 1, 1)
    res  = max(res1, res2)
    cache[pos][minus] = res
    return res

for i in range(n-1,-1,-1):
    solve(i, 0)
    solve(i, 1)

res = solve(0, 0)
print(res)

Measured memory_bytes: 25632
def aaa(n):
    if n==1:
        a=[3,5,7]
    else:
        a=[]
        b=aaa(n-1)
        for i in b:
            a.append(i*10+3)
            a.append(i*10+5)
            a.append(i*10+7)
    return a

N=int(input())
n=N
S=0
i=0
while n>0:
    n=n//10
    i+=1
n=i
for j in range(n):
    a=aaa(j+1)
    for i in range(len(a)):
        if a[i]<N+1:
            p=0
            q=0
            r=0
            while a[i]>0:
                if a[i]%10==3:
                    p=1
                if a[i]%10==5:
                    q=1
                if a[i]%10==7:
                    r=1
                a[i]=a[i]//10
            if p*q*r==1:
                S+=1

        
print(S)


Measured memory_bytes: 4084
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
const int MOD = ((int)1e9)+7;
const int INF = (int)(1e9)+(int)(1e7);
const ll INFL = (ll)(1e18)+INF;
const double EPS = 1e-8;
using namespace std;
int main()
{
    int N;
    cin >> N;
    map<string,int>m;
    int mx=0;
    rep(i,N){
        string S;
        cin >> S;
        m[S]++;
        mx=max(mx,m[S]);
    }
    vector<string>ans;
    for(auto s:m){
        if(s.second==mx)ans.push_back(s.first);
    }
    sort(ans.begin(),ans.end());
    rep(i,ans.size()){
        cout << ans[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 26868
arr = []
while true
    arr[0] = gets.chomp
    break if arr[0] == "0"
    arr[1] = gets.chomp
    arr[2] = gets.chomp

    result = "NA"
    [[[0, 0], [0, 1], [0, 2]], [[1, 0], [1, 1], [1, 2]], [[2, 0], [2, 1], [2, 2]],
     [[0, 0], [1, 0], [2, 0]], [[0, 1], [1, 1], [2, 1]], [[0, 2], [1, 2], [2, 2]],
     [[0, 0], [1, 1], [2, 2]], [[0, 2], [1, 1], [2, 0]]].each{|a, b, c|
        if arr[a[0]][a[1]] == arr[b[0]][b[1]] && arr[a[0]][a[1]] == arr[c[0]][c[1]] && arr[a[0]][a[1]] != "+"
            result = arr[a[0]][a[1]]
            break
        end
    }
    puts result
end



Measured memory_bytes: 6844
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;
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; }

typedef unsigned int uint;
typedef long long llong;
typedef unsigned long long ullong;
typedef long double ldouble;

typedef vector<llong> vecllong;
typedef vector<vecllong> vvecllong;

const llong MOD = 1e9 + 7;
const llong INF = 1e17;

#define FOR(i, n) for (llong i = 0; i < n; i++)
#define FORS(i, a, b) for (llong i = a; i < b; i++)
#define FORR(i, n) for (llong i = n; i > 0; i++)

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

    llong N;
    cin >> N;
    vecllong P(N, 0);
    FOR(i, N){
        cin >> P[i];
    }

    vecllong pToI(N + 1, -1);
    FOR(i, N) {
        pToI[P[i]] = i + 1;
    }

    llong ans = 0;
    multiset<llong> S;
    S.insert(0);
    S.insert(0);
    S.insert(N + 1);
    S.insert(N + 1);
    for(llong i = N; i > 0; i--) {
        S.insert(pToI[i]);
        auto mid = S.find(pToI[i]);

        llong L1 = *(prev(mid));
        llong L2 = *(prev(prev(mid)));
        llong R1 = *(next(mid));
        llong R2 = *(next(next(mid)));

        ans += i * (L1 - L2) * (R1 - *mid);
        ans += i * (R2 - R1) * (*mid - L1);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6528
def binarySearch left, right, arr, val
	mid = left + (right - left) / 2
	return true if arr[mid] == val

	if arr[mid] > val
		right = mid - 1
	else
		left = mid + 1
	end

	return false if left > right
	binarySearch(left, right, arr, val)
end

n = gets.to_i
s  = gets.chomp.split.map(&:to_i)
q = gets.to_i
t  = gets.chomp.split.map(&:to_i)

c = 0
t.each{|val| c += 1 if binarySearch(0, n - 1, s, val)}
puts c

Measured memory_bytes: 18172
import java.util.Scanner;
import java.util.Comparator;
import java.util.PriorityQueue;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        PriorityQueue<Integer> P = new PriorityQueue<>(Comparator.reverseOrder());
        P.add(sc.nextInt());
        P.add(sc.nextInt());
        P.add(sc.nextInt());
        System.out.println(P.poll()*10 +P.poll() + P.poll());
        sc.close();
    }
}

Measured memory_bytes: 23764
input()
a = [0] * (100000 + 1)

for i in map(int, input().split()):
    a[i] += 1
    if a[i] == 3:
        a[i] >>= 1

c = [0, a.count(1), a.count(2)]

ans = 0
ans += (c[2] >> 1) << 1
ans += c[1]

print(ans)




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

#define rep(i, a, b) for(int i = (a); i < int(b); ++i)
#define rrep(i, a, b) for(int i = (a) - 1; i >= int(b); --i)
#define trav(it, v) for(auto &it : (v))
#define all(v) (v).begin(), (v).end()
#define what_is(x) cerr << #x << " is " << x << endl;
#define sz(x) (int)(x).size()

typedef double fl;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;

int main(){
	ios::sync_with_stdio(0);
	int N, K;
	cin >> N >> K;
	int maxA = 0;
	int g = 0;
	rep(i,0,N){
		int A;
		cin >> A;
		if(!g)
			g = A;
		else
			g = __gcd(g, A);
		maxA = max(maxA, A);
	}
	if(K%g || K > maxA){
		cout << "IMPOSSIBLE" << endl;
	}
	else{
		cout << "POSSIBLE" << endl;
	}
}

Measured memory_bytes: 764
# Problem: https://atcoder.jp/contests/agc027/tasks/agc027_a
# Python 2nd Try

import sys
# from collections import defaultdict
# import heapq,copy
# from collections import deque


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LI(): return list(map(int, sys.stdin.readline().split()))


def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solver(haveManyPiaceOFCandy, AI):
    result = 0
    AI.sort()
    for j in range(len(AI)):
        haveManyPiaceOFCandy = haveManyPiaceOFCandy - AI[j]
        if haveManyPiaceOFCandy < 0:
            return result
        else:
            result = result + 1
    # algorithm
    if 0 < haveManyPiaceOFCandy:
        result = result - 1
    return result


if __name__ == "__main__":
    _, X = MI()
    AI = LI()
    print("{}".format(solver(X, AI)))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define LL long long
#define clr(x,i) memset(x,i,sizeof(x))
using namespace std;
const int N=57;
int c[3],ans;
int main()
{
	cin>>c[0]>>c[1]>>c[2];
	sort(c,c+3);
	int v1=c[2]-c[1];
	c[0]+=v1; c[1]+=v1;
	int v2=(c[2]-c[0])/2;
	if(v2*2+c[0]<c[2])
	  v2+=2;
	ans=v1+v2;
	printf("%d\n",ans); 
	return 0;
}

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

int main(){
    int X;
    cin >> X;
    bool ans = false;
    rep(i, 1010){
        if(i*100 <= X && X <= i*105) ans = true;
    }
    cout << ans << endl;
}   

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main()
{
    char a[4];
    scanf("%s", a);
    if ((a[0] == a[1] && a[1] == a[2]) || (a[1] == a[2] && a[2] == a[3]))
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define MAX 1000001
  
int ru[MAX],cu[MAX];
int rv[MAX],cv[MAX];
int a[MAX],b[MAX],c,d;
int e[MAX],f[MAX],g,h;
  
int main(){
  int N,u,v,m,in;
  cin >> N >> u >> v >> m;
  for(int i = 0 ; i < MAX ; i++){
    ru[i] = cu[i] = rv[i] = cv[i] = -1;
    a[i] = b[i] = N;
    e[i] = f[i] = N;
  }
  c = d = g = h = N;
  for(int i = 0 ; i < N ; i++){
    for(int j = 0 ; j < N ; j++){
      cin >> in;
      ru[in] = i;
      cu[in] = j;
    }
  }
  for(int i = 0 ; i < N ; i++){
    for(int j = 0 ; j < N ; j++){
      cin >> in;
      rv[in] = i;
      cv[in] = j;
    }
  }
   
  bool usagi = false,neko = false;
  int x;
  while(m--){
    cin >> x;
    if(N == 1){
      if(ru[x] != -1){
        u--;
      }
      if(rv[x] != -1){
        v--;
      }
      if(u == 0){ usagi = true; }
      if(v == 0){ neko = true; }
      if(usagi || neko){ break; }
      continue;
    }
    if(ru[x] != -1){
      a[ru[x]]--;
      b[cu[x]]--;
      if(ru[x] == cu[x]){
        if( N/2 == ru[x] && (N & 1)){
          c--;
          d--;
        }else{
          c--;
        }
        if(c == 0){ c = -1; u--; }
        if(d == 0){ d = -1; u--; }
      } else if(ru[x]+cu[x] == N-1){
        d--;
        if(d == 0){ d = -1; u--; }
      }
      if(a[ru[x]] == 0){ ru[x] = -1; u--; }
      if(b[cu[x]] == 0){ cu[x] = -1; u--; }
    }
  
    if(rv[x] != -1){
      e[rv[x]]--;
      f[cv[x]]--;
      if(rv[x] == cv[x]){
        if(N/2 == rv[x] && (N&1)){
          g--;
          h--;
        }else{
          g--;
        }
        if(g == 0){ g = -1; v--; }
        if(h == 0){ h = -1; v--; }
      } else if(rv[x]+cv[x] == N-1){
        h--;
        if(h == 0){ h = -1; v--; }
      }
      if(e[rv[x]] == 0){ rv[x] = -1; v--; }
      if(f[cv[x]] == 0){ cv[x] = -1; v--; }
    }
    if(u <= 0){ usagi = true; }
    if(v <= 0){ neko = true; }
    if(usagi || neko){
      break;
    }
  }
  while( cin >> x ){}
  if((usagi && neko) || (!usagi && !neko)){
    cout << "DRAW" << endl;
  }else if(usagi){
    cout << "USAGI" << endl;
  }else{
    cout << "NEKO" << endl;
  }
  return 0;
}

Measured memory_bytes: 32408
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int A, B;
  cin >> A >> B;
  cout << (A > 9 || B > 9 ? -1 : A * B) << '\n';
  return 0;
}


Measured memory_bytes: 3588
#include "bits/stdc++.h"
using namespace std;

const int INF = 1e9 + 5;

const int MAX = 1000005;
int main(){

	int n,w,a,b	;
	long long dp[MAX];
	
	memset(dp,-1,sizeof(dp));
	
	scanf("%d%d",&n,&w);
	
	vector<pair<int,int>> v;
	
	for(int i=0;i<n;i++){
		scanf("%d%d",&a,&b);
		
		v.push_back(pair<int,int>(a,b));
	}
	
	
	for(int i=0;i<n;i++){
		for(int j=w;j>=0;j--){
			if(dp[j]!=-1){
				if(v[i].first+j>w) continue; 
				dp[v[i].first+j] = max(dp[v[i].first+j],dp[j]+v[i].second);
			}else{ 
				if(j==v[i].first) dp[j] = v[i].second;
			}
		}
	}
	long long ans=0;
	for(int j=w;j>=0;j--){
		ans = max(dp[j],ans);
	}
	
	printf("%lld\n",ans);
	
	return 0;
}


Measured memory_bytes: 8064
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;

const double PI = acos(-1);
typedef long long ll;
#define int ll
#define fori(n) for(int i=0; i<int(n); i++)

#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cind(d) double d; cin>>d;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a, n) vd a(n); fori(n) { cin>>a[i]; }


typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;

void solve() {
    cini(n);
    cini(k);
    int x=n;
    do {
        n=x;
        if(abs(n-k)<=k)
            x=abs(n-k);
        else {
            x=min(n%k, k%n);
        }
    } while(x<n && n>0);
    cout<<min(n,x)<<endl;
}

signed main() {
    cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
        solve();
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using   namespace   std;
int a[20];
int main()
{
    int i,j,k,n,s;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    sort(a,a+n);
    s=0;
    for(i=0;i<n-1;i++)
        s=s+a[i];
    s=s+a[n-1]/2;
    printf("%d\n",s);
    return  0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  int j=n-1;
  int ans=0;
  rep(i,n){
    if(s[i]=='W'){
      while(s[j]=='W'){
        j--;
      }
      if(i>=j)break;
      swap(s[i],s[j]);
      ans++;
    }
  }
  cout<<ans<<endl;
  return(0);
}

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

int main(){
    // 制約見て！！！デカかったらlong longにすること！
    int N,K;
    cin>>N>>K;
    int number = 1;
        int number2 ;
    rep(i,N){
        number2 = number*2;
        if(number2-number < K){
            number = number2;
        }else{
            number+=K;
        }
    }
    cout<<number<<endl;
}

Measured memory_bytes: 3632
#include <algorithm>  // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>     // bitset
#include <cctype>     // isupper, islower, isdigit, toupper, tolower
#include <cstdint>    // int64_t, int*_t
#include <cstdio>     // printf
#include <deque>      // deque
#include <iomanip>    // fixed, setprecision
#include <iostream>   // cout, endl, cin
#include <map>        // map
#include <queue>      // queue, priority_queue
#include <set>        // set
#include <stack>      // stack
#include <string>     // string, to_string, stoi
#include <tuple>      // tuple, make_tuple
#include <unordered_map>  // unordered_map
#include <unordered_set>  // unordered_set
#include <utility>        // pair, make_pair
#include <vector>         // vector
using namespace std;

int main() {
  int64_t X;
  bool prime;
  cin >> X;

  while (true) {
    prime = true;
    if (X != 2 && X % 2 == 0) {
      prime = false;
    } else {
      for (int i = 3; i < sqrt(X); i += 2) {
        if (X % i == 0) {
          prime = false;
          break;
        }
      }
    }

    if (prime) break;

    X += 1;
  }
  cout << X << endl;
}


Measured memory_bytes: 3188
eval'A=#'+`tr ' ' ,`
c=[0]*-~t=10**6
A.map{c[_1]+=1}
print A.reduce(:gcd)>1?:not:(2..t).any?{|i|(1..t/i).sum{c[_1*i]}>1}?:setwise: :pairwise," coprime"

Measured memory_bytes: 139328
/*
  最大公約数
  2018/03/23
*/

#include<stdio.h>

int main(void)
{
  unsigned x,y;
  unsigned d;/*ｘ÷ｙのあまり*/

  fscanf(stdin,"%d %d",&x,&y);
  d = x%y;
  while(d != 0){
    d = x%y;
    x = y;
    y = d;
  }
  fprintf(stdout,"%d\n",x);
  return 0;
}


Measured memory_bytes: 2096