akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;


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

    ll k;
    cin >> k;

    if(k<10){
        cout << k << endl;
        return 0;
    }

    queue<ll> q;
    rep1(i, 10) q.push(i);

    ll cnt = 9;
    bool b_flg = false;
    while(!q.empty()){
        ll current = q.front();
        ll v = q.front() % 10;
        q.pop();
        
        rep(i, 3){
            ll nv = v+i-1;
            if(nv<0 || nv>=10) continue;

            q.push(current*10 + nv);
            ++cnt;

            if(cnt==k){
                cout << current*10 + nv << endl;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 768
import math
n = int(input())
x = list(map(float,input().split()))
y = list(map(float,input().split()))
for p in [1.0,2.0,3.0]:
    s = 0
    for i in range(n):
        s += abs(x[i]-y[i])**p
    print(pow(s,1.0/p))
print(max([abs(x[i]-y[i]) for i in range(n)]))

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

class Main{

	public static void main(String[] args) {
        FastScanner in = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int n = in.nextInt();
        int a[] = new int[n];
        a[0] = in.nextInt();
        int prev = a[0];
        long ans = 0;
        for(int i=1;i<n;i++)
        {
        	a[i] = in.nextInt();
        	prev = Math.max(prev, a[i]);
        	ans += Math.max(0, prev-a[i]);
        }
        out.println(ans);
        out.flush();
	}
	
	static class FastScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		
		String next() {
			while(!st.hasMoreTokens())
				try {
					st = new StringTokenizer(br.readLine());
				}catch(IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		
		long nextLong() {
			return Long.parseLong(next());
		}
		
		int[] readArray(int n) {
			int a[] = new int[n];
			for(int i=0;i<n;i++) a[i] = nextInt();
			return a;
		}
		
		long[] readArray(int n,long x) {
			long a[] = new long[n];
			for(int i=0;i<n;i++) a[i] = nextLong();
			return a;
		}
		
	}
}











Measured memory_bytes: 54548
#include <iostream>
#include<cmath>
using namespace std;
int main(){
    int d,n;
    cin>>d>>n;
    
    if(n==100)n++;
    
    if(d>0){
        int base=pow(100,d);
    cout<<base*n<<endl;
    }else{
        cout<<n<<endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 256
# coding=utf-8


def calc_cost():
    global M
    for diff in range(0, n):
        for i in range(1, n-diff+1):
            j = i + diff
            if diff == 0:
                M[i][j] = 0
            elif diff == 1:
                M[i][j] = p[i-1] * p[i] * p[j]
            else:
                M[i][j] = calc_min(i, j)
            ### debugger ###
            #for row in M:
            #    print(*row)
    return M[1][n]

def calc_min(i, j):
    global M, p
    min_cost = float("inf")
    for k in range(i, j):
        cost = M[i][k] + M[k+1][j] + (p[i-1] * p[k] * p[j])
        #print("i, j, k, cost:", i, j, k, cost)
        if cost < min_cost:
            min_cost = cost
    return min_cost

n = int(input())
M = [["-" for _ in range(n+1)] for _ in range(n+1)]
r_list = []
c_list = []
p = []
for _ in range(n):
    r, c = map(int, input().split())
    r_list.append(r)
    c_list.append(c)

p.append(r_list[0])
for c in c_list:
    p.append(c)

total_cost = calc_cost()
print(total_cost)

Measured memory_bytes: 7752
#include<bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.141592653589793238462643383279502884L
#define make_unique(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define Sort(vec) sort(vec.begin(),vec.end())
#define RSort(vec) sort(vec.rbegin(),vec.rend())
#define endl "\n"
#define tr1(i) cout<<i<<endl;
#define tr2(i,j) cout<<i<<" "<<j<<endl;
#define tr3(i,j,k) cout<<i<<" "<<j<<" "<<k<<endl;
#define vvi vector<vector<int> > 
#define vvl vector<vector<ll> >
#define all(st) st.begin(),st.end()
#define vpl vector<pair<ll,ll> >
#define vpi vector<pair<int,int> >
#define pi pair<int,int>
#define pl pair<ll,ll>
#define al vector<list<int> >
#define vs vector<string>
#define vi vector<int>
#define vb vector<bool>
#define vl vector<ll>
#define vc vector<char>
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repit(st) for(auto it=st.begin();it!=st.end();it++)
#define ull unsigned long long int
#define eb emplace_back
#define pb push_back
#define ll long long int
#define minf -(1e18)
#define inf 1e18
#define f first
#define se second
#define mod 1000000007
#define mx 500001
using namespace std;
ll mi(ll n,ll m){ll pw=n%m;ll ex=m-2;ll ans=1;while(ex){if(ex&1) ans = ans*pw%m;pw = pw*pw%m;ex>>=1;}return ans%mod;}
ll pw(ll a,ll n){ll pw=a%mod;ll ex=n;ll ans=1;while(ex){if(ex&1) ans = ans*pw%mod;pw = pw*pw%mod;ex>>=1;}return ans%mod;}
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }
void show(ll x){cout<<x<<" ";}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
ll Abs(ll x){return x>0?x:(-x);}
ll Ceil(ll a,ll b){return a/b+(a%b!=0);}
#define bs binary_search
#define lb lower_bound
#define mkp make_pair
//#define d double
void solve(){
	const int mxm = 12900;
	int n,mm,x;
	cin>>n>>mm;
	vvi m(n,vi(mm));
	rep(i,0,n) rep(j,0,mm) cin>>m[i][j];
	rep(i,0,n) rep(j,0,mm) cin>>x,m[i][j]=Abs(m[i][j]-x);
	bool can[n][mm][mxm+1];
	memset(can,false,sizeof(can));
	can[0][0][m[0][0]]=true;
	for(int i=1;i<n;i++){
		for(int v=0;v<=mxm;v++){
			can[i][0][v]|=can[i-1][0][Abs(v-m[i][0])];
			if(v+m[i][0]<=mxm) can[i][0][v]|=can[i-1][0][v+m[i][0]];
		}
	}
	for(int j=1;j<mm;j++){
		for(int v=0;v<=mxm;v++){
			can[0][j][v]|=can[0][j-1][Abs(v-m[0][j])];
			if(v+m[0][j]<=mxm) can[0][j][v]|=can[0][j-1][v+m[0][j]];
		}
	}
	for(int i=1;i<n;i++){
		for(int j=1;j<mm;j++){
			for(int v=0;v<=mxm;v++){
				can[i][j][v]|=can[i-1][j][Abs(v-m[i][j])];
				if(v+m[i][j]<=mxm) can[i][j][v]|=can[i-1][j][v+m[i][j]];
				can[i][j][v]|=can[i][j-1][Abs(v-m[i][j])];
				if(v+m[i][j]<=mxm) can[i][j][v]|=can[i][j-1][v+m[i][j]];
			}
		}
	}
	int ans;
	for(int i=0;i<=mxm;i++){
		if(can[n-1][mm-1][i]){
			ans=i;
			break;
		}
	}
	cout<<ans;
}
int32_t main(){
FIO;
int t=1;
//cin>>t;
while(t--){
	solve();
}
}

Measured memory_bytes: 80896
#include<bits/stdc++.h>
using namespace std;
#define INF "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
 
string chmin( string a, string b){
  if(a.size() != b.size()) return (a.size() < b.size() ? a : b);
  return (a < b ? a : b);
}
 
int main(){
  string dp1[10][10],dp2[10][1 << 10];
  int n;
  vector< string > str;
 
  while( cin >> n, n){
    fill_n( *dp1, 10 * 10, INF);
    fill_n( *dp2, 10 * 1 << 10, INF);
    str.resize(n);
    for(int i = 0; i < n; i++){
      cin >> str[i];
    }
    unsigned bit = 0u;
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        if(i == j || (bit >> i) & 1 || (bit >> j) & 1) continue;
        if(str[i].find(str[j]) != string::npos) bit |= 1 << j;
      }
    }
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        dp1[i][j] = str[j];
      }
    }

   
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        if(i == j || (bit >> j) & 1) continue;
        for(int k = 0; k < str[i].size(); k++){
          if(str[i].substr(k) == str[j].substr(0, str[i].substr(k).size())){
            dp1[i][j] = str[j].substr(str[i].substr(k).size());
            break;
          }
        }
      }
    }
    for(int i = 0; i < n; i++){
      dp2[i][bit|(1 << i)] = str[i];
    }
    for(int i = 0; i < 1 << n; i++){
      for(int j = 0; j < n; j++){
        if(dp2[j][i|bit] == INF) continue;
        for(int k = 0; k < n; k++){
          if(j == k || ((i|bit) >> k) & 1) continue; //mumumu??
          dp2[k][i|bit|(1 << k)] = chmin( dp2[k][i|bit|(1 << k)], dp2[j][i|bit] + dp1[j][k]);
        }
      }
    }
    string ret = INF;
    for(int i = 0; i < n; i++){
      ret = chmin( ret, dp2[i][(1 << n) - 1]);
    }
   
    cout << ret << endl;
  }
}

Measured memory_bytes: 3004
#include <iostream>
#include <string>

int main() {
  int N;

  std::cin >> N;

  std::string S1, S2;
  S1.reserve(N);
  S2.reserve(N);

  for (int i=0; i<N; i++) {
    char c;
    std::cin >> c;

    if (i==0 || S1.back() != c) {
      S1.push_back(c);
    }
  }

  for (int i=0; i<N; i++) {
    char c;
    std::cin >> c;

    if (i==0 || S2.back() != c) {
      S2.push_back(c);
    }
  }

  std::cerr << S1 << std::endl;
  std::cerr << S2 << std::endl;

  long long ans = S1[0] == S2[0] ? 3 : 6;

  for (int i=1; i<S1.size(); i++) {
    if (S1[i-1] == S2[i-1]) {
      ans *= 2;
    } else {
      if (S1[i] != S2[i]) {
        ans *= 3;
      }
    }
    ans %= 1000000007;
  }

  std::cout << ans << std::endl;

  return 0;
}


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

using namespace std;
typedef long long ll;
const int N = 1e5 + 10, M = 2e5 + 10;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-6;

int n, m, t;
unordered_map<int, int> mp;

int main()
{
    int flag = 1;
    cin >> n;
    while (n--)
    {
        int x;
        scanf("%d", &x);
        if(mp.count(x))
            flag = 0;
        else
        {
            mp[x] = 1;
        }
        
    }
    if(flag)
        puts("YES");
    else
    {
        puts("NO");
    }
    
    
    return 0;
}


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

int main(void) {

    int n;
    string s[2];
    cin >> n >> s[0] >> s[1];

    string ans;
    for (int i = 0; i < n * 2; i++) {
        ans += s[i%2][i/2];
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

const int mod = 1e9+7;

int k, n;
int memo[5005][5005];

int dp(int pos, int len){
	if(pos == k){
		if(len == n){
			return 1;
		}else{
			return 0;
		}
	}else{
		int &ret = memo[pos][len];
		if(ret == -1){
			ret = 0;
			ret = (dp(pos+1, max(0, len-1)))%mod + (2*dp(pos+1, len+1))%mod;
			ret%= mod;
		}
		return ret;
	}
}

int powMod(int x, int y){
	if(y == 0) return 1;
	else if(y == 1) return x;
	else{
		long long ret = powMod(x, y/2);
		ret = (ret*ret)%mod;
		if(y%2) ret = (ret*x)%mod;
		return ret;
	}
}

int main(){
	memset(memo, -1, sizeof memo);
	n = 0;
	scanf("%d", &k);
	getchar();
	while(getchar() != '\n') n++;

	long long ans = dp(0, 0);
	int tmp = powMod(2, mod-2);
	tmp = powMod(tmp, n);
	ans = (ans*tmp)%mod;
	printf("%lld\n", ans);

}

Measured memory_bytes: 98304
def main():
  num = int(input())

  tmp = [input() for i in range(num)]

  tmp2 = {}
  for t in tmp:
    if len(tmp2) == 0:
      tmp2[t] = 1
    else:
      if t in tmp2:
        tmp2[t] += 1
      else:
        tmp2[t] = 1

  _tmp2 = sorted(tmp2.items(), key=lambda x:x[1])
  tmp3 = sorted(tmp2.items())
  for t in tmp3:
    if _tmp2[-1][1] == t[1]:
      print(t[0])

main()

Measured memory_bytes: 60044
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = int64_t;

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; }
const int INF = 1001001001;
const ll INFL = (1LL<<60);
const double eps = (1e-9);

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

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

  int n;
  cin >> n;

  vector<ll> a(n);
  vector<int> one(60, 0);

  rep(i, n) {
    cin >> a[i];
    rep(j, 60) if ((a[i] >> j) & 1) one[j]++;
  }

  mint ans(0);

  rep(i, n-1) {
    rep(j, 60) if ((a[i] >> j) & 1) one[j]--;  // 自分の分は引く

    rep(j, 60) {
      if (a[i] >> j & 1) {
        ans += ((n - i - 1) - one[j]) * ((ll(1) << j) % mod);
      } else {
        ans += one[j] * ((ll(1) << j) % mod);
      }
    }
  }

  cout << ans.x << endl;

  return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>
#include <string>
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;

int main(void){
    int h,w;
    cin >> h >> w;
    char pic[h][w];
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin >> pic[i][j];
        }
    }
    for(int i=0; i<h*2; i++){
        for(int j=0; j<w; j++){
            cout << pic[i/2][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;

int main(){

    int n; cin >> n;

    long long a[n], b[n];
    for(int i=0; i<n; i++){
        cin >> a[i] >> b[i];
    }

    long long mod[n];
    for(int i=0; i<n; i++){
        mod[i] = a[i] % b[i];
    }

    long long res = 0;
    for(int i=n-1; i>=0; i--){
        res += ( b[i] - (mod[i] + res) % b[i] ) % b[i];
    }

    cout << res << endl;



    return 0;
}

Measured memory_bytes: 2560
r, c = map(int, input().split())
mat = [[0 for _ in range(c+1)] for _ in range(r+1)]
for i in range(r):
    x = list(map(int, input().split()))
    for j in range(c):
        mat[i][j] = x[j]

for i in range(r):
    for j in range(c):
        mat[i][c] += mat[i][j]

for j in range(c+1):
    for i in range(r):
        mat[r][j] += mat[i][j]

for i in range(r+1):
    for j in range(c):
        print(mat[i][j], end=' ')
    print(mat[i][c])


Measured memory_bytes: 6212
N = int(input())
AB = 0
B_ = 0
_A = 0
B_A = 0
for i in range(N):
    s = input()
    AB += s.count('AB')
    if s[0]=='B':
        B_ += 1
    if s[-1]=='A':
        _A += 1
    if s[0]=='B' and s[-1]=='A':
        B_A += 1
if B_==_A==B_A:
    if B_A==0:
        print(AB)
    else:
        print(AB+B_A-1)
else:
    print(AB+min(B_,_A))


Measured memory_bytes: 44136
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

string S;

inline bool ok2(string T)
{
	bool used[26];

	for (int i = 0; i < 26; i++) used[i] = false;

	for (int i = 0; i < S.size(); i++)
	{
		if (!used[T[i] - 97] && T[i] != 'a')
		{
			used[T[i] - 97] = true; T[i]--;
		}
	}

	return S == T;
}

int main()
{
	while (true)
	{
		cin >> S;

		if (S == "#") break;

		vector<string> lists;

		for (int i = 0; i < (1 << S.size()); i++)
		{
			string T = S; bool ok = true;

			for (int j = 0; j < S.size(); j++)
			{
				if (i & (1 << j))
				{
					if (S[j] == 'z')
					{
						ok = false; break;
					}

					T[j]++;
				}
			}

			if (ok)
			{
				if (ok2(T))
				{
					lists.push_back(T);
				}
			}
		}

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

		printf("%u\n", lists.size());

		if (lists.size() < 10)
		{
			for (int i = 0; i < lists.size(); i++)
			{
				printf("%s\n", lists[i].c_str());
			}
		}
		else
		{
			for (int i = 0; i < 5; i++)
			{
				printf("%s\n", lists[i].c_str());
			}

			for (int i = lists.size() - 5; i < lists.size(); i++)
			{
				printf("%s\n", lists[i].c_str());
			}
		}
	}

	return 0;
}

Measured memory_bytes: 4304
#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define RFOR(i,k,n) for (int (i)=(n)-1; (i)>=(k); --(i))
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(v) v.begin(), v.end()
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
using namespace std;

int main() {
  int x, a, b;
  cin >> x >> a >> b;
  cout << ((abs(x - a) < abs(x - b)) ? 'A' : 'B') << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
s = list(input())
t= list(input())

if len(s)<len(t):
    print('UNRESTORABLE')
    sys.exit()

ans_list = []

for i in range(len(s)-len(t)+1)[::-1]:
    flag=True
    for j in range(len(t)):
        if s[i+j]=="?" or s[i+j]==t[j]:
            continue
        else:
            flag=False
            break
    if flag:
        ans = "".join(s[:i]+t+s[i+len(t):]).replace("?","a")
        ans_list.append(ans)
    else:
        continue
if len(ans_list)==0:
    print('UNRESTORABLE')
else:
    print(min(ans_list))

Measured memory_bytes: 38384
from scipy.special import comb
n, p = map(int, input().split())
A = list(map(int, input().split()))
cnt_o = len([a for a in A if a%2 == 1])
cnt_e = n - cnt_o
sum_comb_o = 0  # 奇数からとる組み合わせの和
for i in range(n+1):
    if p == 0 and i%2 == 0:
        sum_comb_o += comb(cnt_o, i, exact=True)
    elif p == 1 and i%2 == 1:
        sum_comb_o += comb(cnt_o, i, exact=True)
print(2**cnt_e * sum_comb_o)

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

//Just do bitDP
int main(){

	int n;
	while(cin>>n,n){
		long long t[20][20];
		for(int i=0;i<n;i++){
			for(int j=0;j<n+1;j++) cin>>t[i][j];
		}

		vector<long long> dp(1LL<<n,5000000000000000LL);
		dp[0]=0;

		for(long long bit=0;bit<(1LL<<n);bit++){
			
			// iテ」ツつ津ヲツ板サテァツ閉・
			for(int i=0;i<n;i++){
				if(bit&(1<<i)) continue;

				long long cost=t[i][0];
				for(int j=0;j<n;j++){
					if(bit&(1<<j)) cost=min(cost,t[i][j+1]);
				}

				dp[bit|(1LL<<i)]=min(dp[bit|(1LL<<i)],dp[bit]+cost);

			}
		}

		cout<<dp[(1LL<<n)-1LL]<<endl;
	}

	return 0;
}

Measured memory_bytes: 3572
a=Array.new()
loop do
   x=gets.to_s
   if x.to_i==0 then break end
   total=0
   for i in 0..x.length-1 do
       total=total+x[i].to_i
   end
   a.push(total)
end

a.each do |e|
  puts e
end

Measured memory_bytes: 8696
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1000000
using namespace std;
int main()
{
    int N, K, M;
    while (cin >> N >> K >> M)
    {
        if (N == 0 && K == 0 && N == 0)
            break;
        queue<int> que;
        rep(i, N) que.push(i + 1);
        rep(i, M - 1)
        {
            int tmp = que.front();
            que.pop();
            que.push(tmp);
        }
        que.pop();
        int pos = 1;
        while (que.size() != 1)
        {
            if (pos == K)
            {
                //cout << que.front() << endl;
                pos = 1;
                que.pop();
            }
            else
            {
                int tmp = que.front();
                que.pop();
                que.push(tmp);
                pos++;
            }
            //pos++;
        }
        cout << que.front() << endl;
    }
}




Measured memory_bytes: 3056
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
lint ami[10];
lint dp[110][10];
int main()
{
	lint mo=1000000007;
	ami[0]=ami[1]=1;
	REP(i,2,10) ami[i]=(ami[i-1]+ami[i-2])%mo;
	memset(dp,0,sizeof(dp));dp[0][0]=1;
	int h,w,K;
	cin>>h>>w>>K;
	rep(i,h) rep(j,w) rep(k,w){
		if(abs(j-k)>1) continue;
		if(j==k){
			dp[i+1][k]+=(dp[i][j]*ami[j])%mo*ami[w-1-j];
			dp[i+1][k]%=mo;
		}
		if(j+1==k){
			dp[i+1][k]+=(dp[i][j]*ami[j])%mo*ami[w-2-j];
			dp[i+1][k]%=mo;
		}
		if(j-1==k){
			dp[i+1][k]+=(dp[i][j]*ami[j-1])%mo*ami[w-1-j];
			dp[i+1][k]%=mo;
		}
	}
	cout<<(dp[h][K-1])%mo<<endl;
}


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

int main() {
  int H,W;
  cin >> H >> W;
  
  //1行目をつくる
  for (int i=0;i<W+2;i++){
    cout << '#';
  }
  cout << endl;
  
  //2行目以降をつくる
  vector<char> A(W);
  for (int h=0;h<H;h++){
    cout << '#';
   for (int j=0;j<W;j++){
     cin >> A.at(j);
   }
    for(int j=0;j<W;j++){
      cout << A.at(j);
    }
    cout << '#' << endl;
  }
  
  //最終行をつくる
  for (int i=0;i<W+2;i++){
    cout << '#';
  }
  cout << endl;
}


Measured memory_bytes: 256
S = input()
dp = [[1, 0, 0, 0] for _ in range(len(S))]
if S[0] == 'A':
    dp[0][1] = 1
if S[0] == '?':
    dp[0][1] = 1
    dp[0][0] *= 3

for i, v in enumerate(S):
    if i == 0:
        continue
    if v == '?':
        dp[i][0] = dp[i-1][0] * 3 % 1000000007
        dp[i][1] = (dp[i-1][1] * 3 + dp[i-1][0]) % 1000000007
        dp[i][2] = (dp[i-1][2] * 3 + dp[i-1][1]) % 1000000007
        dp[i][3] = (dp[i-1][3] * 3 + dp[i-1][2]) % 1000000007
        continue

    dp[i][0] = dp[i-1][0]
    dp[i][1] = dp[i-1][1]
    dp[i][2] = dp[i-1][2]
    dp[i][3] = dp[i-1][3]
    if v == 'A':
        dp[i][1] += dp[i-1][0]
        dp[i][1] %= 1000000007
    if v == 'B':
        dp[i][2] += dp[i-1][1]
        dp[i][2] %= 1000000007
    if v == 'C':
        dp[i][3] += dp[i-1][2]
        dp[i][3] %= 1000000007

print(dp[-1][3])

Measured memory_bytes: 27592
#include <iostream>

using namespace std;

int main()
{
  int n, p, sum, max;
	cin >> n;

	cin >> max;
	sum = max;

	for (int i = 1; i < n; ++i)
	{
		cin >> p;
		sum += p;
		max = (p > max) ? p : max;
	}

	sum -= max / 2;

	cout << sum;
  
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextUint64(scanner)

	// 0: 同一 1: 繰り上がりをすると同一 2:未満確定
	var dp [65][3]int64

	dp[0][0] = 1
	mod := int64(1e9 + 7)

	for i := 0; i <= 63; i++ {
		bit := (n >> uint(63-i)) & 1
		if bit == 1 {
			// 0 0
			dp[i+1][1] += dp[i][0]
			dp[i+1][2] += dp[i][1]
			dp[i+1][2] += dp[i][2]
			// 1 0
			dp[i+1][0] += dp[i][0]
			dp[i+1][2] += dp[i][1]
			dp[i+1][2] += dp[i][2]
			// 1 1
			dp[i+1][1] += dp[i][1]
			dp[i+1][2] += dp[i][2]
		} else {
			// 0 0
			dp[i+1][0] += dp[i][0]
			dp[i+1][2] += dp[i][1]
			dp[i+1][2] += dp[i][2]
			// 1 0
			dp[i+1][1] += dp[i][1]
			dp[i+1][2] += dp[i][2]
			// 1 1
			dp[i+1][0] += dp[i][1]
			dp[i+1][2] += dp[i][2]
		}
		for ii := 0; ii < 3; ii++ {
			dp[i+1][ii] %= mod
		}
	}

	ans := (dp[64][0] + dp[64][1] + dp[64][2]) % mod
	fmt.Fprintln(writer, ans)
	writer.Flush()
}


Measured memory_bytes: 640
using System;
using System.Linq;
using System.Collections.Generic;
class ProgramC
    {
        static void Main(string[] args)
        {
            
            string input = Console.ReadLine();
            int n = int.Parse(input);
            
            var a_array = new List<int>();
            for(int i = 0; i < n;i ++)
            {
                string input_a = Console.ReadLine();
                int a = int.Parse(input_a);
                a_array.Add(a);
            }
            int max = a_array.Max();
            int max_i = a_array.IndexOf(max);
            
            for(int i = 0; i < n;i ++)
            {
                if(max_i != i)
                    Console.WriteLine(max);
                else
                {
                    a_array.RemoveAt(max_i);
                    Console.WriteLine(a_array.Max());
                }
            }

        }
    }

Measured memory_bytes: 20308
#include <bits/stdc++.h>
using namespace std;
map<int,int> Mp;
int n,a,m,b,ok;
int main()
{
    ok=1;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a);
        Mp[a]++;
    }
    scanf("%d",&m);
    for(int i=1;i<=m;i++){
        scanf("%d",&b);
        if(Mp[b]){
            Mp[b]--;
        }
        else{
            ok=0;
        }
    }
    if(ok)
        printf("YES");
    else
        printf("NO");
    return 0;
}


Measured memory_bytes: 9600
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

s = STR()
l = len(s)
a = 'keyence'
flag = False
for i in range(l - 6): #消し始め
    for j in range(l - i + 1): #消す文字数
        if s[:j] + s[i+j:] == a:
            print('YES')
            exit()
print('NO')

Measured memory_bytes: 60140
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int m, d, ans = 0; cin >> m >> d;
	for(int i = 10; i <= d; i++){
		if(i / 10 > 1 && i % 10 > 1){
			int p = (i / 10) * (i % 10);
			if(p <= m) ans++;
		}
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
    string s,r[100];
    int n,ans=0;
    cin>>s>>n;
    for(int i=0;i<n;i++){
        cin>>r[i];
        r[i]+=r[i];
        bool ok=false;
        for(int j=0;j<r[i].size()/2;j++)
            if(r[i].substr(j,s.size())==s)
                ok=true;
        if(ok)
            ans++;
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 3176
# 真ん中を通れば必ず二分できてこれが最大値だが、自分自身が真ん中の座標の場合は自分自信を通るどんな直線も二分できる
w, h, x, y = map(int, input().split())
ans1 = (w * h) / 2.0
ans2 = 1 if w / 2 == x and h / 2 == y else 0
print(ans1, ans2)


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

int main(){
  double a, b, x;
  cin >> a >> b >> x;
  x /= a;
  double max_water = a*b;
  double air = max_water - x;
  double ans = 0;
  if(air == x){
    ans = 45;
  }
  else if(air < x){
    ans = atan(2*air/(a*a)) * (180.0 / M_PI);
  }
  else{
    double y = atan(2*x/(b*b)) * (180.0 / M_PI);
    ans = 90.0 - y;
  }
  cout << setprecision(20) << ans << endl;
}

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

int main(){

  int n,k;
  cin >> n >> k;

  vector<int> p(n);
  for(int i=0;i<n;i++) cin >> p[i];

  sort(p.begin(),p.end());
  int ans = 0;
  for(int i=0;i<k;i++){
    ans+=p[i];
  }

  cout << ans << endl;
}

Measured memory_bytes: 3576
import java.util.Scanner;


public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
//			System.out.println(f(10));
//			System.out.println(f(40));
			
			long n = sc.nextLong();
			
			if ( n % 2 == 1) {
				System.out.println(0);
				return;
			}
			
			long ans = 0;
//			for(long i = 2 ; i <= n ; i+=2 ) {
//				//TLE
//				count += countZero(i);
//			}
//			
//			System.out.println(count);
			
//			int len = String.valueOf(n).length();
			
//			System.out.println(len);
			
//			//10のみを考えるのはよくない
//			long upper = 0;
//			for(int i = len - 1 ; i > 0 ; i-- ) {
//				long div = (long)Math.pow(10, i);
//				
//				long currentCount = (n / div);
//				System.out.println(currentCount );
//				ans += currentCount;
//			}
			
			long div = 10;
			while( n / div > 0 ) {
				ans += n / div;
				div *= 5;
			}
			
			System.out.println(ans);
		}
	}
	
	public static long countZero(long n) {
		
		long count = 0;
		
		while(n > 0 && n % 10 == 0) {
			count++;
			n = n / 10;
		}
		
		return count;
	}
	
	public static long f(long n) {
		if ( n < 2) {
			return 1;
		}
		return n * f(n-2);
	}

}

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

const int maxh = 100;
const int maxn = 100000;

int a[maxn];
int grid[maxh][maxh];

int main() {
    int h, w;
    cin>>h>>w;
    int n;
    cin>>n;
    int cur = 0;
    for (int i = 1; i <= n; ++i) {
        cin>>a[i];
    }
    for (int i = 1; i <= n; ++i) {
        while (a[i]--) {
            int r = cur / w;
            int c = cur % w;
            if (r % 2 == 1)
                c = w - 1 - c;
            grid[r][c] = i;
            cur ++;            
        }
    }
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j)
            cout<<grid[i][j]<<" ";
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;

int main()
{
	char c = ' ';
	bool f = true;
	while(scanf("%c", &c) != EOF)
	{
		if(f) cout<<c;
		f = not f;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <string>
#include <unordered_map>
#include <queue>
#include <set>
using namespace std;


int main(){
    int n;
    cin >> n;
    vector<int> a(n + 1), b(n + 1);
    for (int i = 1; i <= n; i++)
        cin >> a[i];

    int sum = 0;
    for (int i = n; i >= 1; i--){
        int count=0;
        for (int j = 0; j * i <= n; j++){
            count += b[j * i];
            count %= 2;
        }
        if (a[i] != count){
            b[i] = 1;
            sum++;
        }
        else b[i] = 0;
    }
    cout << sum << endl;
    for (int i = 1; i <= n; i++){
        if (b[i]) cout << i << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 2432
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let w: usize = iterator.next().unwrap().parse().unwrap();
    let h: usize = iterator.next().unwrap().parse().unwrap();
    let x: usize = iterator.next().unwrap().parse().unwrap();
    let y: usize = iterator.next().unwrap().parse().unwrap();

    return format!(
        "{:.6} {}",
        w as f64 * h as f64 / 2.0,
        if x * 2 == w && y * 2 == h { "1" } else { "0" }
    );
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n,k;
	int s=1;
	scanf("%d%d",&n,&k);
	while(n--)
	{
		if(s<k)
		{
			s*=2;
		}
		else
		{
			s+=k;
		} 
	}
	printf("%d",s);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef long long LL;
typedef vector<LL> VEC;
typedef vector<VEC> VVEC;
typedef  pair<LL,LL> P;


const LL INF=1<<30;
const LL MOD=1000000007;




int main(){

        int N;
        cin>>N;
        vector<int> X(N);
            
        vector<int> Y(N);

		int sec[]={0, 1, 2, 3, 4, 5, 6, 7};
        for(int i=0;i<N;++i){
            cin>>X[i]>>Y[i];
        }

		double ans=0;
		do
		{
			for (int i=0;i<N-1;++i)
			{
				ans+=sqrt((double)((X[sec[i]]-X[sec[i+1]])*(X[sec[i]]-X[sec[i+1]])+(Y[sec[i]]-Y[sec[i+1]])*(Y[sec[i]]-Y[sec[i+1]])));
			}

		} while (next_permutation(sec, sec+N));


		long ret =1;
		while (N>=1)
		{
			ret*=N;
			N--;
		}



		cout<<setprecision(7)<<(double)ans/(double)ret;

       

}

int f(int n)
{
	int ret=1;
	while (n>=1)
	{
		ret=n;
		n--;
	}
	return ret;
}

Measured memory_bytes: 256
import sys
N, M = map(int,input().split())
A = []
B = []
for _ in range(N):
    A.append(input())
for _ in range(M):
    B.append(input())
for i in range(N - M + 1):
    for j in range(N - M + 1):
        flag = 1
        for h in range(M):
            if A[h+i][j:j+M] != B[h]:
                flag = 0
        if flag:
            print('Yes')
            sys.exit()
print('No')

Measured memory_bytes: 3064
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fr first
#define sc second
using namespace std;
typedef long long ll;
const long long llnrm=LLONG_MAX;
const int nrm=INT_MAX;
const int nrn=INT_MIN;
const int nmax=1e5+5;
const int mod=1e9+7;
const int lim=1e8;
int n,a,b,ans;
string s;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    //freopen("solution.in","r",stdin);
	//freopen("solution.out","w",stdout);o
	cin>>n>>a>>b;
	if(n==2) rc("Borys");
	if(abs(a-b)%2!=0) rc("Borys"); else rc("Alice");
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,k,q;
cin>>n>>k>>q;
vector<int>a(n,k-q);
while(q--){
    int num;
    cin>>num;
    a[num-1]++;
}
for(int x:a){
    if(x<=0)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}
    return 0 ;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <chrono>
#include <random>

using namespace std;

typedef signed long long ll;
typedef vector<int> vec;
const int TP = 26;

ll compute_score(int D, vector<int>& C, vector<vector<int>>& S, vector<int>& sol) {
    vector<int> last(TP, 0);
    ll score = 0;
    for (int i = 0; i < D; i++) {
        int j = sol[i];
        last[j] = i + 1;
        int tmp = 0;
        for (int k = 0; k < TP; k++)
            tmp -= C[k] * (i + 1 - last[k]);
        score += S[i][j] + tmp;
    }
    return score;
}

void compute_greedy_with_pen(int D, vector<int>& C, vector<vector<int>>& S, vector<int>* sol, double gamma) {
    vector<int> last(TP, 0);
    for (int i = 0; i < D; i++) {
        vector<double> scores(TP, 0.0);
        for (int k = 0; k < TP; k++) {
            scores[k] = S[i][k] + gamma * (i + 1 - last[k]) * C[k];
        }
        auto itp = std::max_element(scores.begin(), scores.end());
        int di = itp - scores.begin();
        last[di] = i + 1;
        (*sol)[i] = di;
    }
}

int main() {
    int D; cin >> D;
    vector<int> C(TP, 0);
    for (int i = 0; i < TP; i++) cin >> C[i];
    vector<vector<int>> S(D, vector<int>(TP, 0));
    for (int i = 0; i < D; i++)
        for (int j = 0; j < TP; j++)
            cin >> S[i][j];

    // greedy解の周辺を探索
    auto start = std::chrono::system_clock::now();
    vector<int> sol(D, 0);
    vector<int> sol_best(D, 0);
    double gamma = 1.0;
    double dg = 5.0;
    compute_greedy_with_pen(D, C, S, &sol, gamma);
    gamma += dg;
    for (int k = 0; k < D; k++) { sol_best[k] = sol[k]; }
    ll score_best = compute_score(D, C, S, sol);
    while (true) {
        compute_greedy_with_pen(D, C, S, &sol, gamma);
        ll score = compute_score(D, C, S, sol);
        if (score > score_best) {
            for (int k = 0; k < D; k++) { sol_best[k] = sol[k]; }
            score_best = score;
        }
        auto end = std::chrono::system_clock::now();
        double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
        if (elapsed >= 500)
            break;
        gamma += dg;
    }

    // 残りローカルサーチ
    std::random_device r;
    std::default_random_engine e1(r());
    std::uniform_int_distribution<int> ud1(0, D);
    std::uniform_int_distribution<int> ud2(0, TP);
    while (true) {
        // ランダムに1日選択
        int di = ud1(e1);
        int gi = ud2(e1);

        vector<int> nsol(D, 0);
        for (int k = 0; k < D; k++) { nsol[k] = sol_best[k]; }
        nsol[di] = gi;
        ll score = compute_score(D, C, S, nsol);
        if (score > score_best) {
            for (int k = 0; k < D; k++) { sol_best[k] = nsol[k]; }
            score_best = score;
        }

        auto end = std::chrono::system_clock::now();
        double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
        if (elapsed >= 1950) {
            for (auto v : sol_best) { cout << (v  + 1) << endl; }
            exit(0);
            break;
        }
    }
}

Measured memory_bytes: 3692
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;
typedef tuple<ll, ll, ll> tuplll;

const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;
const int MOD = 1000000007;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }



int main()
{
	string s, t;
	cin >> s >> t;
	const int ns = SZ(s), nt = SZ(t);

	vvi dp(ns + 1, vi(nt + 1, 0));

	REP(i, ns)
		REP(j, nt)
	{
		if (s[i] == t[j]) chmax(dp[i + 1][j + 1], dp[i][j] + 1);
		chmax(dp[i + 1][j + 1], dp[i][j + 1]);
		chmax(dp[i + 1][j + 1], dp[i + 1][j]);
	}

	int i = ns, j = nt;
	string res = "";
	while (i > 0 && j > 0)
	{
		if (dp[i][j] == dp[i - 1][j])
			--i;
		else if (dp[i][j] == dp[i][j - 1])
			--j;
		else // if (dp[i][j] == dp[i - 1][j - 1])
		{
			--i; --j; res.PB(s[i]);
		}
	}

	reverse(ALL(res));
	cout << res << endl;
}


Measured memory_bytes: 35584
use std::io::{BufRead, Write};
use std::io;
use std::cmp;

fn solve<R: BufRead, W: Write>(mut input: R, mut output: W) {
    let mut buf = String::new();
    input.read_line(&mut buf).unwrap();
    let n: usize = buf.trim_right().parse().unwrap();
    let csf: Vec<(usize, usize, usize)> = (0..n - 1).map(|_| {
        buf.clear();
        input.read_line(&mut buf).unwrap();
        let mut split = buf.split_whitespace();
        (split.next().unwrap().parse().unwrap(), split.next().unwrap().parse().unwrap(), split.next().unwrap().parse().unwrap())
    }).collect();
    for i in 0..n {
        writeln!(output, "{}", csf[i..].iter().fold(0, |time, x| cmp::max((time + x.2 - 1) / x.2 * x.2, x.1) + x.0)).unwrap();
    }
}

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();
    solve(stdin.lock(), stdout.lock());
}

#[cfg(test)]
mod tests {
    fn test(input: &str, output: &str) {
        let mut v: Vec<u8> = Vec::new();
        ::solve(input.as_bytes(), &mut v);
        assert_eq!(String::from_utf8(v).unwrap(), output);
    }

    #[test]
    fn case1() {
        test(
            "3
6 5 1
1 10 1
",
            "12
11
0
",
        );
    }

    #[test]
    fn case2() {
        test(
            "4
12 24 6
52 16 4
99 2 2
",
            "187
167
101
0
",
        );
    }

    #[test]
    fn case3() {
        test(
            "4
12 13 1
44 17 17
66 4096 64
",
            "4162
4162
4162
0
",
        );
    }
}

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

int main( void ) {
    int a, b;
    cin >> a >> b;
    if( a > b )
        cout << "a > b" << endl;
    else if( a == b )
        cout << "a == b" << endl;
    else
        cout << "a < b" << endl;
}



Measured memory_bytes: 3080
#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<set>
#include<map>

using namespace std;


///////////////////ダイクストラで使うクラス//////////////////
class E{
	public:
	int dir,cost,limit;
	E(int dir,int cost,int limit):dir(dir),cost(cost),limit(limit){}
};

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

////////////////////////////main/////////////////////////
int main(){
	
	while(1){
		/////////////入力/////////////////////////////////
		int n,m,start,goal;
		vector<E> edge[33];
		
		cin>>n>>m; if(n==0)break;
		cin>>start>>goal;
		
		for(int i=0;i<m;i++){
			int a,b,c,d;
			cin>>a>>b>>c>>d;
			edge[a].push_back(E(b,c,d));
			edge[b].push_back(E(a,c,d));
		}
		
		///////////ダイクストラ本体//////////////////////
		priority_queue<T> que;
		que.push(T(start,0,0,0)); //初期位置設定
		
		int visit[33][33][33]={0};
		while(1){
			if(que.empty())break; //異常終了
			
			T u = que.top();
			que.pop();
			
			if(visit[u.pos][u.bef][u.speed]==1)continue; //一度訪れた状態の場合は弾く
			visit[u.pos][u.bef][u.speed]=1;
			
			if(u.pos==goal && u.speed==1){ //終了判定
				printf("%lf\n",u.val);
				goto A;
			}
			
			for(int i=0;i<edge[u.pos].size();i++){ //状態遷移
				E e = edge[u.pos][i];
				if(e.dir == u.bef)continue; //Uターン禁止の制約で弾く
				
				//-1:減速 0:等速 1:加速
				for(int j=-1;j<=1;j++){
					
					int next = u.speed + j;
					if(next > e.limit || next <= 0)continue; //速度の制約で弾く
					
					que.push( T(e.dir, u.pos, u.val + double(e.cost)/next, next) );
				}
			}
		}
		
		printf("unreachable\n");
		A:;
	}
}

Measured memory_bytes: 21428
//Mayank
#include "bits/stdc++.h"

#define ll long long
#define rep(i, a, b) for(ll i = (a); i < (b); i++)
#define sz(x) ((ll) (x).size())
#define all(x) (x).begin(), (x).end()
#define pii pair<ll, ll>
#define vi vector<ll>
using namespace std;
const ll N = 1e5+1;
const ll MOD = 1e9+7;

ll d(pii &a, pii &b){
    return abs(a.first-b.first) + abs(a.second-b.second);
}

void solve(){
    ll n;
    cin>>n;
    vector<pii> e(n);
    rep(i, 0, n)cin>>e[i].first>>e[i].second;
    sort(all(e));
    ll hy=0, ly = 0;
    ll hx=0, lx = 0;
    rep(i, 0, n){
        if(e[i].second+e[i].first>e[hy].second+e[hy].first)hy=i;
        if(e[i].second+e[i].first<e[ly].second+e[ly].first)ly=i;
        if(e[i].second-e[i].first>e[hx].second-e[hx].first)hx=i;
        if(e[i].second-e[i].first<e[lx].second-e[lx].first)lx=i;
    }
    ll d1 = d(e[hy], e[ly]);
    ll d2 = d(e[hx], e[lx]);
    ll ans = max(d1, d2);
    cout<<ans;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll T=1;
    // cin>>T;
    rep(test, 1, T+1){
        // cout<<"Case #"<<test<<": ";
        solve();
    }
    return 0 ;
}

Measured memory_bytes: 6356
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<iomanip>

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

#define debug(x) cout<<(#x)<<"="<<(x)<<", ";
#define debug1(x) debug(x) cout<<'\n';
#define debug2(x1, x2) debug(x1) debug(x2) cout<<'\n';
#define debug3(x1, x2, x3) debug(x1) debug(x2) debug(x3) cout<<'\n';
#define debug4(x1, x2, x3, x4) debug(x1) debug(x2) debug(x3) debug(x4) cout<<'\n';
#define debug5(x1, x2, x3, x4, x5) debug(x1) debug(x2) debug(x3) debug(x4) debug(x5) cout<<'\n';

#define fcout cout<<fixed<<setprecision(15)
#define repp(i,j,k) for(int i=j; i<k; ++i)
#define rep(i,j) repp(i,0,j)
#define rrep(i,j,k) for(int i=j; i>=k; --i)
#define all(x) (x).begin(), (x).end()
#define sort(x) sort(x.begin(), x.end())
#define lb(x,val) lower_bound(x.begin(), x.end(), val)
#define ub(x,val) upper_bound(x.begin(), x.end(), val)
#define pb(x) emplace_back(x);

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef tuple<int, int, lli> tiil;

//const lli M=998244353ll;
const lli M=1000000007ll;
const double D=1.0;

int main(){
fast_io
int a,b; cin>>a>>b;
if(a+b<10) cout<<(a+b);
else cout<<"error";
 return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>

using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	a += b;
	if (a >= 10) {
		cout << "error" << endl;
	}
	else {
		cout << a << endl;
	}
	return 0;
}



Measured memory_bytes: 256