akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<int,int>;
using Graph=vector<vector<int>>;
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();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int N;
deque<int> A[1010];
int step[1010];
int M;
int main() {
	
	cin>>N;
	REP(i,N) {
		REP(j,N-1) {
            int x;
			cin>>x;
			A[i].push_back(x-1);
		}
	}
	M=N*(N-1)/2;
	
	queue<int> Q;
	REP(i,N) Q.push(i);
	
	int num=0;
	while(Q.size()) {
		queue<int> Q2;
		
		while(Q.size()) {
			int i=Q.front();
			Q.pop();
			if(step[i]<=num && A[i].size() && A[A[i].front()].front()==i && step[A[i].front()]<=num) {
				step[i]=step[A[i].front()]=num+1;
				Q2.push(i);
				Q2.push(A[i].front());
				A[A[i].front()].pop_front();
				A[i].pop_front();
				M--;
			}
		}
		num++;
		if(M==0) break;
		swap(Q,Q2);
	}
	
	if(M) cout<<-1<<endl;
	else cout<<num<<endl;
}

Measured memory_bytes: 7976
#include<cstdio>
#include<algorithm>
int w[101000];
long long s;
using namespace std;
int n;
int main(){
    int i, t = 0;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d",&w[i]);
    }
    sort(w+1,w+n+1);
    for(i=1;i<n;i++){
        s+=w[i];
        if(s*2<w[i+1])t=i;
    }
    printf("%d\n",n-t);
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,e) for(int i = (s); i < (e); i++)
#define FOE(i,s,e) for(int i = (s); i <= (e); i++)
#define FOD(i,s,e) for(int i = (s); i >= (e); i--)
#define ll long long
#define pb push_back
#define mp make_pair

int n, m, x, y, z, k, w;

int main ()
{
	scanf("%d %d", &x, &y);
	
	k = y;
	while (k > 0) k /= 10, w++;
	
	z = 1;
	FOR(i, 0, w) z *= 10;
	
	x = x * z + y;
	
	FOE(i, 0, 1000) if (i * i == x) { printf("Yes\n"); return 0; }
	printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#pragma region
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define repc(i, m, n) for (int i = m; i < n; i++)
#define reprc(i, m, n) for (int i = m; i > n; i--)
#define all(v) v.begin(), v.end()
#define INF 1e9
#define EPS 1e-10
using namespace std;
typedef long long ll;
#pragma endregion

struct Point { double x, y;};

double th = M_PI * 60.0 / 180.0;

int koch(int d, Point p1, Point p2){
    if(d == 0){
        return 0;
    }

    Point s,t,u;

    s.x = (2.0 * p1.x + 1.0 * p2.x) / 3.0;
    s.y = (2.0 * p1.y + 1.0 * p2.y) / 3.0;
    t.x = (1.0 * p1.x + 2.0 * p2.x) / 3.0;
    t.y = (1.0 * p1.y + 2.0 * p2.y) / 3.0;
    u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
    u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

    koch(d - 1, p1, s);
    printf("%.8f %.8f\n", s.x, s.y);
    koch(d - 1, s, u);
    printf("%.8f %.8f\n", u.x, u.y);
    koch(d - 1, u, t);
    printf("%.8f %.8f\n", t.x, t.y);
    koch(d - 1, t, p2);
}

int main()
{
    int n;
    Point f,e;
    f.x = 0.0;
    f.y = 0.0;
    e.x = 100.0;
    e.y = 0.0;
    cin >> n;

    printf("%.8f %.8f\n", f.x, f.y);
    koch(n, f, e);
    printf("%.8f %.8f\n", e.x, e.y);
}


Measured memory_bytes: 3404
// Sea the world.

#include <cmath>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>
#include <bitset>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

using namespace std;

// SELF TEMPLATE CODE BGEIN

#define SZ(x) ((int)((x).size()))
#define OUT(x) printf(#x" %d\n", x)
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repf(i,a,b) for (int i = (a); i <= (b); ++i)
#define repd(i,a,b) for (int i = (a); i >= (b); --i)
#define repcase int t, Case = 1; for (scanf ("%d", &t); t; --t)

typedef long long int64;
typedef pair<int, int> pii;

int sgn(double x) { return (x > 1e-8) - (x < -1e-8); }
int count_bit(int x) { return x == 0? 0 : count_bit(x >> 1) + (x & 1); }

template<class T> inline void to_min(T &a, const T b) { if (b < a) a = b; }
template<class T> inline void to_max(T &a, const T b) { if (b > a) a = b; }

// SELF TEMPLATE CODE END

void solve(int n, int a, int b, const string& s) {
  int qualified = 0;
  int b_cnt = 0;
  rep (i, n) {
    if (s[i] == 'a' && qualified < a + b) {
      puts("Yes");
      ++qualified;
    } else if (s[i] == 'b') {
      if (qualified < a + b && b_cnt < b) {
        puts("Yes");
        ++qualified;
      } else {
        puts("No");
      }
      ++b_cnt;
    } else {
      puts("No");
    }
  }
}

int main() {
  ios::sync_with_stdio(false);

  int n, a, b;
  string s;
  while (cin >> n >> a >> b >> s) {
    solve(n, a, b, s);
  }
  return 0;
}


Measured memory_bytes: 848
Q=int(input())
score=[list(map(int,input().split())) for _ in range(Q)]
import math
for i in range(Q):
    max_num=int(math.sqrt(score[i][0]*score[i][1]))

    if score[i][0]==score[i][1]:
        print(2*max_num-2)
    elif score[i][0]*score[i][1]==max_num**2:
        print(2*max_num-3)
    elif score[i][0]*score[i][1]>max_num*(max_num+1):
        print(2*max_num-1)
    else:
        print(2*max_num-2)


Measured memory_bytes: 3064
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main () {
	ll n;cin>>n;
	map<ll,ll>m;
	vector<ll>a; 
    while (n % 2 == 0)  
    {  
        if (m[2]==0) {a.push_back(2);}
		m[2]++;  
        n = n/2;  
    }  
    for (ll i = 3; i <= sqrt(n); i = i + 2)  
    {  
        // While i divides n, print i and divide n  
        while (n % i == 0)  
        {  
            if (m[i]==0) {a.push_back(i);}
			m[i]++;  
            n = n/i;  
        }  
    }  
  
    // This condition is to handle the case when n  
    // is a prime number greater than 2  
    if (n > 2)  
        if (m[n]==0) {a.push_back(n);m[n]++;} 
		ll k,k1,p,sum=0;  
  for (ll i=0;i<a.size();i++) {
	  k=m[a[i]];
	  //cout<<k<<endl;
	  k1=sqrt(1+8*k);
	  p=(k1-1)/2 ;
	 /* if (k1*k1!=(1+8*k)) {
		  p--;
	  }*/
	  //cout<<sum<<endl;
     sum+=p;
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 3724
#ifdef DEBUG
#include "../utils.cpp"
#endif
#include <bits/stdc++.h>
/*
Problem
 
Category
DP
 
URL:
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_A&lang=ja

考察:


Date: 2020/04/18
*/
 

using namespace std;
using ll = int64_t;
#define int int64_t

 
/* ==== declarations ====== */
// functions
void solve();
void getInput();
 
// global variables
int n;
vector<int> dp;

/* ======================== */
int fib(int k) {
    if (dp[k] == 0) dp[k] = fib(k-1) + fib (k-2);
    return dp[k];
}

void getInput() {
    cin>>n;
    dp = vector<int>(n+1, 0);
    dp[0] = 1; dp[1] = 1;
}
 
 
void solve() {
    cout<<fib(n)<<endl;
}
 
 
 
signed main(){
    getInput();
    solve();
    return 0;
}




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

const int H = 20;
const long long mod = 1000000007ll;

template <class T>
void read(T &x) {
	int sgn = 1;
	char ch;
	x = 0;
	for (ch = getchar(); (ch < '0' || ch > '9') && ch != '-'; ch = getchar()) ;
	if (ch == '-') ch = getchar(), sgn = -1;
	for (; '0' <= ch && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
	x *= sgn;
}
template <class T>
void write(T x) {
	if (x < 0) putchar('-'), write(-x);
	else if (x < 10) putchar(x + '0');
	else write(x / 10), putchar(x % 10 + '0');
}

int h, perm[1 << H];
long long tmp[1 << H], ans = 0ll;

void add(int pos, long long val) {
	for (int i = pos; i; i >>= 1) {
		val = val * i % mod;
		tmp[i] = (tmp[i] + val) % mod; 
	}
}
void del(int pos) {
	for (int i = pos; i; i >>= 1) tmp[i] = 0ll;
}
void update(int pos, long long val) {
	for (int i = pos; i; i >>= 1) {
		val = val * i % mod;
		if (i > 1) ans = (ans + 1ll * tmp[i ^ 1] * val % mod * (i >> 1)) % mod;
	} 
}
void dfs1(int u, long long mul) {
	if ((u << 1 | 1) < (1 << h)) {
		dfs1(u << 1, mul * u % mod);
		dfs1(u << 1 | 1, mul * u % mod);
	} else add(perm[u], mul * u % mod);
}
void dfs2(int u, long long mul) {
	if ((u << 1 | 1) < (1 << h)) {
		dfs2(u << 1, mul * u % mod);
		dfs2(u << 1 | 1, mul * u % mod);
	} else update(perm[u], mul * u % mod); 
}
void dfs3(int u) {
	if ((u << 1 | 1) < (1 << h)) dfs3(u << 1), dfs3(u << 1 | 1);
	else del(perm[u]);
}

void dfs(int u) {
	if ((u << 1) < (1 << h)) dfs(u << 1);
	if ((u << 1 | 1) < (1 << h)) dfs(u << 1 | 1);
	if ((u << 1 | 1) << (1 << h)) {
		dfs1(u << 1, u);
		dfs2(u << 1 | 1, 1);
		dfs3(u << 1);
	} 
}
int main() {
	read(h);
	for (int i = (1 << (h - 1)); i < (1 << h); i++) read(perm[i]), perm[i] += (1 << (h - 1)) - 1;
	for (int i = 0; i < (1 << h); i++) tmp[i] = 0;
	dfs(1);
	write(ans), putchar('\n');
	return 0;
}

Measured memory_bytes: 6204
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);

		// 文字列の入力
		while (true) {
			// String型で入力
			String strInput = scanner.nextLine();

			// "0"で終了
			if (("0").equals(strInput)) {
				break;
			}

			int intSum = 0;
			// 桁数分ループ処理
			for (int intLength = 0; intLength < strInput.length(); intLength++ ) {
				// 型変換を行って１文字ずつ合計値に加算
				char charNum = strInput.charAt(intLength);
				String strNum = String.valueOf(charNum);
				int intNum = Integer.parseInt(strNum);
				intSum += intNum;
			}
			System.out.println(intSum);
		}

	}

}



Measured memory_bytes: 27056
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)

#define INF 1000000000

typedef pair<int,int> pii;

class T{
	public:
	int now,val;
	T(int now,int val):now(now),val(val){}
	bool operator<(const T& a)const{
		return val>a.val;
	}
};

const int M = 3001;
vector<pii> e[M];

int main(){
	
	int n,m,k;
	cin>>n>>m>>k;
	
	
	rep(i,m){
		int a,b,c;
		cin>>a>>b>>c;
		
		e[a].push_back(pii(b,c));
		e[b].push_back(pii(a,c));
	}
	
	int st[M];
	rep(i,k)cin>>st[i];
	
	
	priority_queue<T> que;
	rep(i,k){
		que.push(T(st[i],0));
	}
	
	int visit[M];
	rep(i,M)visit[i]=INF;
	
	while(1){
		if(que.empty())break;
		
		T u = que.top();
		que.pop();
		
		if(visit[u.now] != INF)continue;
		visit[u.now] = u.val;
		
		rep(i,e[u.now].size()){
			pii edge = e[u.now][i];
			que.push(T(edge.first, u.val+edge.second));
		}
	}
	
	int ans = 0;
	
	rep(i,M){
		rep(j,e[i].size()){
			pii edge = e[i][j];
			int L = visit[i] + visit[edge.first] + edge.second + 1;
			
			ans = max(ans, L/2);
		}
	}
	
	printf("%d\n",ans);
}

Measured memory_bytes: 6004
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to;
	ld cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
bool suf(ld a, ld b, ld c, ld d) {
	if (b <= c || d <= a) return 0;
	return 1;
}//[a,b),[c,d)
ll fact(ll x, ll k) {//最大値、個数
	ll sum = 1;
	for (int i = 0; i < k; i++)
		sum *= (x--);
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%p;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}
#define int long long
const long long inf = 4523372036854775807;
const int iinf = 1500000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
int h, w, d, q;
int a[300][300];
int b[90001][60];
H c[90001];
signed main() {
	cin >> h >> w >> d;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> a[i][j];
			c[a[i][j]] = H{ i,j };
		}
	}
	for (int i = 1; i+d <= h*w; i++) {
		b[i][0] = abs(c[i].x - c[i + d].x) + abs(c[i].y - c[i + d].y);
	}
	for (int i = 1; d*pow(2, i) <= h*w; i++) {
		int k = d*pow(2, i);
		for (int j = 1; j + k <= h*w; j++) {
			b[j][i] = b[j][i - 1] + b[j + k / 2][i - 1];
		}
	}
	cin >> q;
	for (int i = 0; i < q; i++) {
		int x, y;
		cin >> x >> y;
		y -= x;
		y /= d;
		int sum = 0, r = 0;
		while (y > 0) {
			if (y & 1) {
				sum += b[x][r];
				y ^= 1;
				x += d*pow(2, r);
			}
			y >>= 1;
			r++;
		}
		cout << sum << endl;
	}
	getchar(); getchar();
}

Measured memory_bytes: 45688
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
#define STEP 0.0005
// sort(a.begin(), a.end(), std::greater<int>());

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

int main()
{
    int n;
    cin >> n;
    vector<int> a;
    long long int sum = 0;
    rep(i, n)
    {
        int temp;
        cin >> temp;
        a.push_back(temp);
    }
    rep(i, n - 1)
    {
        sum += abs(a[i] - a[i + 1]);
    }
    sum += abs(a[0]);
    sum += abs(a[a.size() - 1]);
    cout << sum - abs(a[0]) - abs(a[0] - a[1]) + abs(a[1]) << endl;
    REP(i, 1, n - 1)
    {
        cout << sum - abs(a[i] - a[i + 1]) - abs(a[i] - a[i - 1]) + abs(a[i - 1] - a[i + 1]) << endl;
    }
    cout << sum - abs(a[a.size() - 2] - a[a.size() - 1]) - abs(a[a.size() - 1]) + abs(a[a.size() - 2]) << endl;
    return 0;
}


Measured memory_bytes: 1784
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int main() {

	ll x,y;
	cin>>x>>y;

	if(x%y==0){
		cout<<"-1"<<endl;
	}else{
		cout<<x<<endl;
	}

	return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <cmath>
#include <ios>
#include <ctype.h>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <set>
#include <queue>
#include <unordered_map>
#include <functional>
#include <bitset>
#include <list>
#include <deque>
#include <time.h>
#include <random>
#include <iomanip>
#include <fstream>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define RREP(i,a,b) for (int i = a; i > (b); --i)
#define all(x) (x).begin(),(x).end()
const long long INF = 1000000007;
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
int solve(){
  string s;
  cin>>s;
  if(s == "keyence"){
    cout << "YES" << endl;
    return 0;
  }
  int n = s.size();
  bool can = false;
  rep(i,n)REP(j,i,n){
    string tmp;
    rep(k,n){
      if(i <= k && k <= j)continue;
      else tmp.push_back(s[k]);
    }
    if(tmp == "keyence")can = true;
  }
  cout << (can ? "YES" : "NO") << endl;
  return 0;
}
int main(){
  ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16);
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <locale>
#include <iomanip>

#define nl '\n'

using namespace std;

int n, l, t, d = 201, a;

int main(){

    cin >> n >> l;

    vector<int> v;

    for(int i = 0; i < n; i++){
        v.push_back(i+l);
    }

    for(int i = 0; i < v.size(); i++){
        if(abs(0-v[i]) < d){
            d = abs(0-v[i]);
            a = i;
        }
    }

    for(int i = 0; i < v.size(); i++){
        if(i == a){
            continue;
        }
        t = t + v[i];
    }

    cout << t;



}

//g++ -std=c++14 comp.cpp -o b; ./b.exe

//Comment

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

typedef long long ll;

int main(){
    ll N;
    cin >> N;
    vector<ll> cp(5);
    ll min_cp = 1000000000000000;
    for(int i = 0; i < 5; i++)
        cin >> cp[i];

    for(int i = 0; i < 5; i++)
        min_cp = min(min_cp, cp[i]);
    
    ll ans = (N + min_cp - 1) / min_cp;

    cout << ans + 4 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <list>
#include <map>
#include <cmath>
#include <string>
#include <cstdio>
#include <vector>
 
using namespace std;

typedef long long ll;
typedef long double ld;
#define L(ID) ((ID*2)+1)
#define R(ID) ((ID*2)+2)
#define M(L,R) ((L+R)/2)
#define forr(start,end) for(int i = start; i < end; i++)
#define gap ' '
 
const int MAXN = 100+5;
int weights[MAXN], value[MAXN];

int largest(int a, int b){
	return (a<b)?b:a;
}



int main() {	
	string s,t,k;
	cin >> s >> t >> k;
	s[0]-=32, t[0]-=32,  k[0]-=32;
	cout << s[0]<< t[0] << k[0] << endl;



    return 0;
}	

Measured memory_bytes: 256
#include<iostream>
using namespace std;
long long n,a[100],b[100],c[100];
long long gcd1;
long long gcd(long long a,long long b){
	if(b==0){return a;}
	return gcd(b,a%b);
}
int main(){
	while(true){
		cin>>n;
		if(n==0){break;}
		gcd1=1;
		for(int i=0;i<n;i++){
			cin>>a[i]>>b[i];
			long long GCD2=gcd(a[i],b[i]);
			a[i]/=GCD2;b[i]/=GCD2;
			long long GCD=gcd(gcd1,a[i]);
			gcd1=gcd1*a[i]/GCD;
		}
		for(int i=0;i<n;i++){
			c[i]=gcd1*b[i]/a[i];
		}
		long long gcd2=c[0];
		for(int i=1;i<n;i++){
			gcd2=gcd(gcd2,c[i]);
		}
		for(int i=0;i<n;i++){
			cout<<c[i]/gcd2<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1156
#include <iostream>
using namespace std;
int main(void){
    int n;
    long int a;
    scanf("%d\n",&n);
    long int sum=0; 
    long int min=1000000000;
    int cou=0;
    for(int i=0;i<n;i++){
        scanf("%ld",&a);
        if(a<0){sum-=a;cou++;}
        else sum+=a;
        if(abs(a)<min)min=abs(a);
    }
    if(cou%2==1)sum-=2*min;
    printf("%ld\n",sum);
    return 0;
}


Measured memory_bytes: 256
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
s = input()
t = input()
s = s[:-1]
t = t[:-1]

dup = 0
for i in range(N):
    if s[N-i-1:] == t[:i+1]:
        dup = i+1
print(2*N-dup)


Measured memory_bytes: 3060
def main():
    k = int(input())
    if k <= 9:
        print(k)
        exit()
    count = 9
    l = [i for i in range(1,10)]
    while True:
        ins_l = []
        for x in l:
            y = x % 10
            if y != 0:
                z = x * 10 + y - 1
                ins_l.append(z)
                count += 1
                if count == k:
                    print(z)
                    exit()

            z = x * 10 + y
            ins_l.append(z)
            count += 1
            if count == k:
                print(z)
                exit()

            if y != 9:
                z = x * 10 + y + 1
                ins_l.append(z)
                count += 1
                if count == k:
                    print(z)
                    exit()
        l = ins_l

if __name__ == "__main__":
    main()


Measured memory_bytes: 6308
#include<iostream>

using namespace std;

int main(){
	int x,y;
	while(1){
		cin>> x>> y;
		if(x==0 && y==0)break;
		if(x<y){
			cout<< x<< " "<< y<<endl;
		}
		else{
			cout<< y<< " "<< x<<endl;
		}
		
	}
	
	return 0;
}

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

int main(){
    int n,m;
    cin >> n >> m;
    int a[m], b[m];
    for(int i = 0; i < m; i++){
        cin >> a[i] >> b[i];
    }
    bool c[n] = {},d[n] = {};
    for(int i = 0; i < m; i++){
        if(a[i] == 1){
            c[b[i]-1] = 1;
        }
    }
    for(int i = 0; i < m; i++){
        if(b[i] == n){
            d[a[i]-1] = 1;
        }
    }

    for(int i = 0; i < n; i++){
        if(c[i] == 1 && d[i] == 1){
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;

    return 0;
}

Measured memory_bytes: 2176
#include <iostream>

using namespace std;
int main(){
	int i,n,k;
	cin >> n >> k;
	if(n==1){
		if(k==0){
			cout << 0 << " " << 0 << " " << 1 << " " << 1 << endl;
		}else{
			cout << -1 << endl;
		}
	}else{
		if(k==0){
			for(i=0;i<(1<<n);i++){
				cout << i << " " << i << " " ;
			}
			return 0;
		}
		if((1<<n)<=k){
			cout << -1 << endl;
		}else{
			cout << 0 << " " << k << " " << 0 << " ";
			for(i=(1<<n) - 1;i>=1;i--){
				if(i==k) continue;
				cout << i << " ";
			}
			cout << k << " ";
			for(i=1;i<=(1<<n) - 1;i++){
				if(i==k) continue;
				cout << i << " ";
			}
			cout << endl;
		}
	}
}

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

/* typedef */
/* long系 */
typedef long long ll;   // long long
typedef long double ld; // long double
/* vector系 */
typedef vector<int> vi;                    // intのvector
typedef vector<double> vd;                 // doubleのvector
typedef vector<ll> vll;                    // llのvector
typedef vector<ld> vld;                    // ldのvector
typedef vector<pair<int, int>> vi_i;       // i_iのvector
typedef vector<pair<double, double>> vd_d; // d_dのvector
typedef vector<pair<ll, ll>> vl_l;         // l_lのvector
typedef vector<pair<ld, ld>> vld_ld;       // ld_ldのvector
typedef vector<string> vs;                 // stringのvector
/* pair系 */
typedef pair<int, int> i_i;       // int同士のpair
typedef pair<double, double> d_d; // double同士のpair
typedef pair<ll, ll> l_l;         // ll同士のpair
typedef pair<ld, ld> ld_ld;       // ld同士のpair

/* define */
#define all(v) v.begin(), v.end() // コンテナ全体
#define PI (acos(-1))             // 円周率pi

/* main */
void Main(void)
{
    int a, h, m, s;
    cin >> a;
    h = a / 3600;
    m = (a - h * 3600) / 60;
    s = a - h * 3600 - m * 60;
    cout << h << ":" << m << ":" << s << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();

    return 0;
}



Measured memory_bytes: 3172
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 200010;
const int MAXM = 100010;
const int MAXK = 510;
const int MAXQ = 200010;

int res;
int n, k, a[MAXN];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> k;
    FOR(i,1,n) cin >> a[i];
    int l = 0, r = 0;
    FOR(i,1,n) {
        int p = a[i] + k;
        r = max(r, p);
        if (i == n || r < a[i+1]) {
            res += r-l;
            if (i < n) l = r = a[i+1];
        }
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 1024
N, M = list(map(int, input().split()))
H = list(map(int, input().split()))
arr = [[] for i in range(N)]
ans = 0
#print(arr)
for i in range(M):
    a, b = list(map(int, input().split()))
    arr[a-1].append(b-1)
    arr[b-1].append(a-1)

for i in range(N):
    if arr[i] == []:
        ans += 1
    else:
        if all(H[i] > H[arr[i][j]] for j in range(len(arr[i]))):
            ans += 1

print(ans)


Measured memory_bytes: 29404
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){
    ll x,k,d;
    cin>>x>>k>>d;
    if(x<0)x*=-1;
    if(x>d) {
        ll xd = x / d;
        if (xd >= k) {
            cout << x - k * d << endl;
            return 0;
        } else {

            ll xdk = x % d;
            xd = k -x / d;
            if(xd%2==0){
                cout<<xdk<<endl;
            }else{
                cout<<d-xdk<<endl;
            }

        }
    }else{
        if(k%2==0){
            cout<<x<<endl;
        }else{
            cout<<d-x<<endl;
        }
    }







    return 0;
}


Measured memory_bytes: 3568
def countA(A):
    global cnt
    if len(A)==1:
        cnt += A[0]
    else:
        amin = min(A)
        A = [A[i]-amin for i in range(len(A))]
        cnt += amin
        while A:
            if A[0]==0:
                A.pop(0)
            elif A[-1]==0:
                A.pop()
            else:break
        B = []
        for i in range(1,len(A)):
            if A[i]==0 and A[i-1]==0:
                B.append(i)
        C = []
        for i in range(len(A)):
            if i not in B:
                C.append(A[i])
        C0 = []
        for i in range(len(C)):
            if C[i]==0:
                C0.append(i)
        if len(C0)==0 and len(C)>0:
            countA(C)
        else:
            cur = 0
            for c in C0:
                countA(C[cur:c])
                cur = c+1
            if cur<len(C):
                countA(C[cur:])
            
N = int(input())
H = list(map(int,input().split()))
cnt = 0
countA(H)
print(cnt)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<pli,pii> plii;
#define mkp make_pair
#define fi first
#define se second
int n;
ll dis[53][21][2];
char c[53][23];
int len[53],C[53];
priority_queue<plii,vector<plii>,greater<plii> >pq;
void add(ll a,int t,int x,int y){
	pq.push(mkp(mkp(a,t),mkp(x,y)));
} 
char cur[104];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)scanf("%s",c[i]+1),len[i]=strlen(c[i]+1),cin>>C[i];
	for(int i=0;i<53;i++)for(int j=0;j<21;j++)for(int k=0;k<2;k++)dis[i][j][k]=1e18;
	ll ans=1e18;
	for(int i=1;i<=n;i++){
		dis[i][1][0]=dis[i][len[i]][1]=C[i];
		add(C[i],i,1,0),add(C[i],i,len[i],1);
		bool ok=0;
		for(int j=1,k=len[i];j<k;j++,k--)if(c[i][j]!=c[i][k])ok=1;
		if(!ok)ans=min(ans,0ll+C[i]);
	}
	while(!pq.empty()){
		plii u=pq.top();pq.pop();
		ll w=u.fi.fi;int x=u.fi.se,a=u.se.fi,b=u.se.se;
		if(w>dis[x][a][b]||w>=ans)continue;
		if(b==0){
			for(int i=1;i<=n;i++){
				int cnt=0;
				for(int j=a;j<=len[x];j++)cur[++cnt]=c[x][j];
				for(int j=1;j<=len[i];j++)cur[++cnt]=c[i][j];
				bool ok=0;
				for(int j=1,k=cnt;j<k;j++,k--)if(cur[j]!=cur[k])ok=1;
				if(!ok)ans=min(ans,w+C[i]);
			}
			for(int i=1;i<=n;i++){
				bool ok=0;
				for(int j=a,k=len[i];j<=len[x]&&k>=1;j++,k--)if(c[x][j]!=c[i][k])ok=1;
				if(ok)continue;
				ll val=w+C[i];
				int lt=len[x]-a+1,AB=abs(lt-len[i]);
				if(lt<len[i]&&dis[i][AB][1]>val)dis[i][AB][1]=val,add(val,i,AB,1);
				if(lt>len[i]&&dis[x][len[x]-AB+1][0]>val)dis[x][len[x]-AB+1][0]=val,add(val,x,len[x]-AB+1,0);
			}
		}else{
			for(int i=1;i<=n;i++){
				int cnt=0;
				for(int j=1;j<=len[i];j++)cur[++cnt]=c[i][j];
				for(int j=1;j<=a;j++)cur[++cnt]=c[x][j];
				bool ok=0;
				for(int j=1,k=cnt;j<k;j++,k--)if(cur[j]!=cur[k])ok=1;
				if(!ok)ans=min(ans,w+C[i]);
			}
			for(int i=1;i<=n;i++){
				bool ok=0;
				for(int j=a,k=1;j>=1&&k<=len[i];j--,k++)if(c[x][j]!=c[i][k])ok=1;
				if(ok)continue;
				ll val=w+C[i];
				int AB=abs(a-len[i]);
				if(a<len[i]&&dis[i][len[i]-AB+1][0]>val)dis[i][len[i]-AB+1][0]=val,add(val,i,len[i]-AB+1,0);
				if(a>len[i]&&dis[x][AB][1]>val)dis[x][AB][1]=val,add(val,x,AB,1);
			}
		}
	}
	if(ans==1e18)puts("-1");
	else cout<<ans;
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int i,j;

int main(){
    /*int n,q;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++) cin>>a[i];
    cin>>q;
    int b[q],c[q];
	ll s[q]={0};
    for(i=0;i<q;i++) cin>>b[i]>>c[i];
    for(i=0;i<q;i++){
    	for(j=0;j<n;j++){
    		if(a[j]==b[i])a[j]=c[i];
    		s[i]+=a[j];
		}
		cout<<s[i]<<endl;
	}*/
	int n,q;
    cin>>n;
    int a[n];
    map<ll,ll> mp;
	ll s=0;
    for(i=0;i<n;i++){
    	cin>>a[i];
    	mp[a[i]]++;
    	s+=a[i];
	}
    cin>>q;
    int b[q],c[q];
    for(i=0;i<q;i++) cin>>b[i]>>c[i];
    for(i=0;i<q;i++){
    	    s+=mp[b[i]]*(c[i]-b[i]);
		mp[c[i]]+=mp[b[i]];
		mp[b[i]]=0;
		cout<<s<<endl;
	}
	return 0;
}

Measured memory_bytes: 10556
import Control.Monad
import Control.Applicative
import Data.List

main :: IO ()
main = do
    [a, b] <- fmap read . words <$> getLine :: IO [Int]
    case (a + b, a * b) of
        (15, _) -> putStrLn "+"
        (_, 15) -> putStrLn "*"
        _       -> putStrLn "x"

Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);++i)
#define rep(i,n) REP(i, 0, n)
typedef pair<int, int> pint;

int H, W;
struct Edge { int num, to; Edge(int n, int t) : num(n), to(t) {}};
vector<vector<Edge>> edges;
bool bfs(int broken_edge, vector<int>& dist, const vector<vector<Edge>>& edges) {
    dist[(H - 1) * W + W - 1] = 0;
    queue<int> que; que.push((H - 1) * W + W - 1);
    while(!que.empty()) {
        int cur = que.front(); que.pop();
        for(const Edge& e : edges[cur]) {
            if(e.num == broken_edge || dist[e.to] != INF) continue;
            dist[e.to] = dist[cur] + 1;
            que.push(e.to);
        }
    }
    return dist[0] == INF;
}

int solve(const vector<vector<int>>& wdist, const vector<vector<Edge>>& edges) {
    vector<int> dist(H * W, INF);
    priority_queue<pint, vector<pint>, greater<pint>> que;
    dist[(H - 1) * W + W - 1] = 0; que.emplace(0, (H - 1) * W + W - 1);
    auto upd = [](int& a, int b) { return a > b ? (a = b, true) : false;};
    while(!que.empty()) {
        int cos, node;
        tie(cos, node) = que.top(); que.pop();
        if(dist[node] < cos) continue;
        for(const Edge& e : edges[node]) {
            int ncos = max(cos + 1, wdist[e.num][e.to]);
            if(upd(dist[e.to], ncos)) que.emplace(ncos, e.to);
        }
    }
    return dist[0];
}
int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    while(cin >> H >> W && H) {
        int t_, edgenum = 0;
        vector<vector<Edge>> edges(H * W);
        rep(i, H) {
            rep(j, W - 1) {
                cin >> t_;
                if(t_ == 0) {
                    edges[i * W + j].emplace_back(edgenum, i * W + j + 1);
                    edges[i * W + j + 1].emplace_back(edgenum, i * W + j);
                    ++edgenum;
                }
            }
            if(i == H - 1) continue;
            rep(j, W) {
                cin >> t_;
                if(t_ == 0) {
                    edges[i * W + j].emplace_back(edgenum, (i + 1) * W + j);
                    edges[(i + 1) * W + j].emplace_back(edgenum, i * W + j);
                    ++edgenum;
                }
            }
        }
        vector<vector<int>> wdist(edgenum, vector<int>(H * W, INF));
        rep(i, edgenum) if(bfs(i, wdist[i], edges)) goto fail;
        cout << solve(wdist, edges) << endl;
        continue;
      fail:
        cout << "-1" << endl;
    }
    return 0;
}

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

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {

		var inputArray = retreiveLongArray();
			var inputCount = 2;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			long N = inputArray[0];
			long M = inputArray[1];

			var inputInfo = new List<long[]>();

			for (int i = 0; i < M; i++) {
				var inp = retreiveLongArray();
				inputInfo.Add(inp);
			}

			var kosuDic = new Dictionary<long, long>();
			var whitePossible = new Dictionary<long, bool>();

			//dictionaryの初期値セット
			for (int i = 1; i <= N; i++) {
				if (i == 1) {
					whitePossible.Add(i, true);
				}
				else {
					whitePossible.Add(i, false);
				}

				kosuDic.Add(i, 1);
			}


			for (int i = 0; i < M; i++) {

				var inp = inputInfo[i];
				var x = inp[0];
				var y = inp[1];

				kosuDic[x]--;
				kosuDic[y]++;

				if (whitePossible[x]) {
					whitePossible[y] = true;
				}
				if (kosuDic[x]==0) {
					whitePossible[x] = false;
				}
			}


			//答えの出力
			var ans = whitePossible.Where(x =>x.Value).Count();
			Console.WriteLine(ans);

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}
	}
}


Measured memory_bytes: 37428
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair <INT, INT> II;
typedef vector <II> VII;

template<class T> ostream& operator << ( ostream& os, vector<T> v ) {
    for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i ) {
        os << *it_i << ", ";
    }
    return os;
}


int solve( int n ) {
    int res = 0;
    while ( n > 1 ) {
        res ++;
        n = ( n % 2 == 0 ? n / 2 : n * 3 + 1 );
    }
    return res;
}

int main() {
    int n;
    while ( cin >> n && n ) cout << solve( n ) << endl;
    return 0;
}

Measured memory_bytes: 0
def main():
    S = input()
    k = int(input())

    array = []
    for i in range(len(S)):
        for j in range(i+1,len(S)+1):
            if j-i <= k:
                array.append(S[i:j])
    array = list(set(array))
    array.sort()
    print(array[k-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 40304
x, n = list(map(int, input().split()))
if n > 0:
    p = list(map(int, input().split()))
else:
    p = []
w = 0
ans = 0
while True:
    if (x - w) not in p:
        ans = x - w
        break
    if (x + w) not in p:
        ans = x + w
        break
    w += 1
print(ans)

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    if (K < A) {
        cout << K << '\n';
        return 0;
    }
    K -= A;
    if (K < B) {
        cout << A << '\n';
        return 0;
    }
    K -= B;
    cout << A - K << '\n';
    return 0;
}

Measured memory_bytes: 3612
// AOJ 0541: Walk
// 2017.10.28 bal4u@uu

#include <stdio.h>
#include <string.h>

char map[1002][1002];
int dp[1002][1002];

char buf[3002], *p;
int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int main()
{
	int h, w, n, r, c;

	while (fgets(p=buf, 32, stdin) && *buf != '0') {
		h = getint(), p++, w = getint(), p++, n = getint();
		for (r = 0; r < h; r++) {
			fgets(p=buf, 3000, stdin);
			for (c = 0; c < w; c++) {
				map[r][c] = *p++ & 1, p++;
			}
		}
   
		memset(dp, 0, sizeof(dp));
	    dp[0][0] = n - 1;
		for (r = 0; r < h; r++) for (c = 0; c < w; c++) {
			if (r+1 < h) dp[r+1][c] += (dp[r][c] - map[r][c]+1) / 2;
			if (c+1 < w) dp[r][c+1] += (dp[r][c] + map[r][c]) / 2;
		}

		r = c = 0;
	    while (r < h && c < w) {
	      if ((dp[r][c] + map[r][c]) & 1) c++;
	      else r++;
		}
		printf("%d %d\n", r+1, c+1);
	}
	return 0;
}

Measured memory_bytes: 6540
n, a, b = map(int, input().split())
ans = 0


def sum_digit(i):
    s = str(i)
    l = list(map(int, list(s)))
    return sum(l)


for i in range(n + 1):
    if a <= sum_digit(i) and b >= sum_digit(i):                                                                   
        ans += i

print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int a,b;
int main(){
  int n;
  cin >> n;
  string s;int ans[30];
  for(int i=0;i<30;i++) ans[i]=1e8;
  for(int i=0;i<n;i++){
    cin >> s;
    int c[30]={0};
    for(int j=0;j<s.size();j++){
            c[s[j]-'a']++;
    }
    for(int j=0;j<26;j++){
      ans[j]=min(ans[j],c[j]);
    }
  }
  char ch='a';
for(int i=0;i<26;i++){
  for(int j=0;j<ans[i];j++){
    cout << ch;
  }
  ch++;
}
cout <<endl;
  }


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

using namespace std;

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

#define int ll


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

	vector<int> r;
	vector<int> g;
	vector<int> b;
	for(int i=0;i<n;i++){
		if(s[i]=='R') r.push_back(i);
		if(s[i]=='G') g.push_back(i);
		if(s[i]=='B') b.push_back(i);
	}

	int ans = 0;
	for(int i=0;i<r.size();i++){
		for(int j=0;j<g.size();j++){
			int ii = r[i];
			int jj = g[j];
			
			ans += b.size();
			if(binary_search(b.begin(),b.end(), 2*jj-ii)) ans--;
			if(binary_search(b.begin(),b.end(), 2*ii-jj)) ans--;
			if((ii+jj)%2==0 && binary_search(b.begin(),b.end(), (ii+jj)/2)) ans--;
			
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int n;
	cin >> n;
	
	for (int i = 0; i < n; i++) {
		char s;
		cin >> s;
		if (s == 'Y') {
			cout << "Four" << endl;
			return 0;
		}
	}
	cout << "Three" << endl;
	return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
// 10min
int main(void){
  int n;
  int a, b;
  int ans = 0;
  
  scanf("%d%d%d", &n, &a, &b);
  ans = n*a;
  if(ans > b){
    ans = b;
  }
  
  printf("%d\n", ans);

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1ll << 60;
const int MOD = 1e9;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define itn int
#define asn ans
bool dbg = false;

int H, W, h, w;
int ans[500][500];

itn SUM;
void solve() {
    if (H % h == 0 && W % w == 0) {
        No();
        return;
    }

    FOR(i, 0, H) {
        FOR(j, 0, W) {
            if (i % h == 0 && j % w == 0) {
                ans[i][j] = MOD - 1;
            } else if (i % h == h - 1 && j % w == w - 1) {
                ans[i][j] = -MOD;
            }
            SUM += ans[i][j];
        }
    }
    if (SUM <= 0) {
        No();
        return;
    } else {
        Yes();
        FOR(H) {
            FOR(j, W)
            cout << ans[i][j] << " ";
            cout << endl;
        }
    }
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> H >> W >> h >> w;


    solve();
    return 0;
}


Measured memory_bytes: 4864
#include <iostream>
#include<math.h>
#include<list>
#include <algorithm>
#include<vector>
#include<math.h>
#include<map>
using namespace std;
using ll = long long;
using vll = vector<long long>;

#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(long i=s;i<e;i++)
#define repeq(i,s,e) for(long i=s;i<=e;i++)


int main() {
	ll k, x,min,max;

	in(k);
	in(x);

	min = x - k + 1;
	if (min < -1000000) {
		min = -1000000;
	}

	max = x + k - 1;
	if (max > 1000000) {
		max = 1000000;
	}

	repeq(i, min, max) {
		if (i == max) {
			outn(i);
		}
		else {
			outs(i);
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

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

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int a,b,c;
	cin >> a >> b >> c;
	if((a == b && b != c) ||(a == c && c != b) || (b == c && a != c)){
		cout << "Yes" << '\n';
	}
	else{
		cout << "No" << '\n';
	}
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = 0
for i in range(n):
    differences = v[i] - c[i]
    if 0 < differences:
        ans += differences
    else:
        continue
print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT false

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T> void DEBUG(string str, T e){if(DEBUG_OUT == false)return;std::cout <<str<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


int COUNT_SAME_ALPHABET(string str1, string str2)
{
  set<char> st1,st2;
  for (int i = 0; i < str1.size(); i++)
  {
    st1.insert(str1[i]);
  }
  for (int i = 0; i < str2.size(); i++)
  {
    st2.insert(str2[i]);
  }
  int res = 0;
  auto itr = st2.begin();
  for (int i = 0; i < st2.size(); i++)
  {
    auto find = st1.insert(*itr);
    itr++;
    if(find.second == false){
      res++;
          }

  }
  DEBUG(str1); DEBUG(str2); DEBUG(res);
  return res;
}
//CODE
void solve(void)
{
  int N;
  cin>>N;
  string str;
  cin>>str;
  int ANS = 0;
  for (int i = 0; i < str.size()-1; i++)
  {
    string A = str.substr(0,i+1);
    string B = str.substr(i+1,(int)str.size()-1-i);
    chmax(ANS,COUNT_SAME_ALPHABET(A,B));
  }
  cout<<ANS<<endl;

  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  

 
  return 0;
}

Measured memory_bytes: 256