akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

int N;
string S[222];

vector<int> Adj[222];

int color[222];

int ans=0;

int assign(int K, int col) {

	color[K] = col;
	if (ans == -1) { return -1; }

	for (auto y : Adj[K]) {
		if (color[y] == -1) {
			assign(y, (col + 1) % 2);
		}
		else {
			if (color[y] != (col + 1) % 2) { ans = -1;  break; }
		}
	}

}


int dis[222];
int INF = 9999;
int used[222];

void INIT(void) {
	for (int i = 1; i <= N; i++) { dis[i] = INF; used[i] = 0; }
}

queue<int> Q;

void BFS(int K, int d) {

	Q.push(K); used[K] = 1; dis[K] = 0;

	while (Q.size() > 0) {
		int y = Q.front(); Q.pop();
		for (auto h : Adj[y]) {
			if (used[h] == 0) { used[h] = 1; dis[h] = dis[y] + 1;  Q.push(h); }
		}
	}

}

int main(void) {

	cin >> N;

	for (int i = 1; i <= N; i++) {
		cin >> S[i];
		S[i] = "$" + S[i];
	}


	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			if (S[i][j] == '1') { Adj[i].push_back(j); }
		}
	}

	for (int i = 1; i <= N; i++) { color[i] = -1; }
	assign(1, 1);
	if (ans == -1) { cout << -1 << endl; return 0; }


	
	for (int i = 1; i <= N; i++) {
		INIT();
		BFS(i, 0);
		for (int j = 1; j <= N; j++) {
			ans = max(ans, dis[j]+1);
		}
		/*for (int j = 1; j <= N; j++) {
			cout << "dis[" << j << "]= " << dis[j] << endl;
		}
		cout << ans << endl;*/
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include <string> 
#include <vector>  
#include<math.h>
#include <algorithm>
#include<iomanip>
#define INF 1000000000
#define LM 55555
using namespace::std;


long long mc,pc,p[100001],m[100001],n, bc, now, C, H, W, X[100000],K, Y, ans, r, l, numcon, N, M;
string S,s,a[101],b[101],c[101];
bool h,k[101];
int main() {
	cin >> N;
	ans = 0;
	for (int i = 105; i <= N; i+=2) {
		now = 0;
		for (int j = 1; j <= i; j++) {
			if (i%j == 0)now++;
		}
		if (now == 8) {
			ans++;
		}
	}

	cout <<ans << endl;

	return 0;

}




Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;

#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>

#define rep(i,n)         for(int i=(int)0; i<(int)n; i++)
#define REP(i,m,n)       for(int i=(int)m; i<(int)n; i++)
#define arr(var, n)      vecll var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define prt(var)         cout << var << endl
#define prtd(n, var)     cout << fixed << setprecision(n) << var << endl
#define prt2(var1, var2) cout << var1 << " " << var2 << endl
#define prseq(var, n)    rep(i,n){cout << var[i] << " ";} cout << endl
#define prseql(var, n)   rep(i,n){cout << var[i] << " " << endl;}

//----------------------------------------------------------------

int main(void) {
  int n;
  cin >> n;

  vector<string> s(n);
  rep(i,n){
    string tmp;
    cin >> tmp;
    sort(all(tmp));
    s[i] = tmp;
  }

  sort(all(s));

  ll num=1;
  ll ans=0;
  rep(i,n-1){
    if(s[i]==s[i+1]){
      num++;
    } else {
      ans += num*(num-1)/2;
      num=1;
    }
  }
  ans += num*(num-1)/2;

  prt(ans);
}


Measured memory_bytes: 5760
#include<iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include <assert.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include <iomanip>
#include<map>
#include <random>
#include<type_traits>
#include<stack>
#include <sstream> 
#include <limits>
#include <numeric>
#include<string.h>
#include<set>
#include <climits>
using namespace std;
typedef unsigned long long ull;
#define ll long long int
static const double PI = 3.141592653589793;
const ll INF = 100000000000000;
ll mod = 1000000007;
//typedef vector<int> V;
//typedef vector<V> VV;
//typedef vector<VV> VVV;

int board[2005][2005];
string check[2005];

int main() {
	ll h, w;
	cin >> h >> w;
	for (int i = 0; i < h; i++) {
		cin >> check[i];
	}

	for (int i = 0; i < h; i++) {
		int s = 0, t = 0,c=0;
		while (s < w) {
			if (t >= w) {
				for (int j = s; j < t; j++) {
					board[i][j] += c;
				}
				break;
			}
			if (check[i][t] == '#') {
				for (int j = s; j < t; j++) {
					board[i][j] += c;
				}
				c = 0;
				s = t + 1;
			}
			else {
				c++;
			}
			t++;
		}
	}
	for (int i = 0; i < w; i++) {
		int s = 0, t = 0, c = 0;
		while (s < h) {
			if (t >= h) {
				for (int j = s; j < t; j++) {
					board[j][i] += c;
				}
				break;
			}
			if (check[t][i] == '#') {
				for (int j = s; j < t; j++) {
					board[j][i] += c;
				}
				c = 0;
				s = t + 1;
			}
			else {
				c++;
			}
			t++;
		}
	}
	int y = 1;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			y = max(y, board[i][j]);
		}
	}
	cout <<  y - 1 << endl;
}


Measured memory_bytes: 19968
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
using namespace std;

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

typedef long long ll;

int A, N;
string ans;

int main() {
  cin >> N >> A;

  if (N%500 <= A) {
    ans = "Yes";
  } else {
    ans = "No";
  }

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


Measured memory_bytes: 256
a,b,c,x,y = map(int, input().split())

ans = 0

if x<y:
    xy = x
    y -= x
    if b < 2*c:
        ans += b*y
    else:
        ans += 2*c*y

else:
    xy = y
    x -= y
    if a < 2*c:
        ans += a*x
    else:
        ans += 2*c*x

if a+b<2*c:
    ans += xy*(a+b)
else:
    ans += xy*(2*c)

print (ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, maxs = 0;
    string s;
    cin >> n;

    map<string, int> s_count;
    for(int i = 0; i < n; i++){
        cin >> s;
        s_count[s] += 1;
    }

    for (pair<string, int> p : s_count) {
        maxs = max(p.second, maxs);
    }

    for (pair<string, int> p : s_count) {
        if(p.second == maxs) cout << p.first << endl; 
    }

}

Measured memory_bytes: 25216
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <sstream>
#include <set>
#include <tuple>
#include <algorithm>
#include <memory>
#include <numeric>
#include <queue>
#include <functional>
#include <cmath>
#include <cstring>
#include <map>

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

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

	ll N;

	cin >> N;

	vector<ll> a(N);
	vector<ll> b(N);
	vector<ll> c(N);
	for (ll i = 0; i < N; ++i) cin >> a[i] >> b[i] >> c[i];

	vector<vector<ll>> dp(N, vector<ll>(3, numeric_limits<ll>::min()));
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];

	for (ll i = 1; i < N; ++i)
	{
		chmax(dp[i][0], dp[i - 1][1] + a[i]);
		chmax(dp[i][0], dp[i - 1][2] + a[i]);
		chmax(dp[i][1], dp[i - 1][0] + b[i]);
		chmax(dp[i][1], dp[i - 1][2] + b[i]);
		chmax(dp[i][2], dp[i - 1][0] + c[i]);
		chmax(dp[i][2], dp[i - 1][1] + c[i]);
	}

	cout << *max_element(dp[N - 1].begin(), dp[N - 1].end()) << endl;
	//system("pause");
}


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

using namespace std;

int main() {
   int n;
   cin >> n;
   int h[n];

   int t,a;
   cin >> t >> a;

    int ave[n];
    int min=10E5;
    int min_n = 0;
    for(int i=0;i<n;i++){
       cin >> h[i];
       ave[i] = t*1000 - h[i]*6 - a*1000;
       if(ave[i]<0)ave[i] = -ave[i];
       if(ave[i] < min)min = ave[i],min_n = i;
    }

   
   cout << min_n+1 << endl;
    return 0;
}


Measured memory_bytes: 256
import sys

p = []
path = [ 0 for i in range(10**5+1)]
def main():

    sys.setrecursionlimit(1000000)

    N = int(input())

    e = [ [] for i in range(N)]
    for i in range(N-1):
        a,b = map(int,input().split())
        a-=1
        b-=1
        e[a].append(b)
        e[b].append(a)

    col = [ -1 for i in range(N)]
    col[0] = 0
    
    def dfs(n,c):
        global p
        if n == N - 1:
            p = path
        path[c] = n
        for v in e[n]:
            if col[v] == -1:
                col[v] = c + 1
                dfs(v,c+1)
                if p:
                    return
    dfs(0,0)

    t = col[N-1] + 1
    if t % 2 ==0:
        sn = p[t//2]
    else:
        sn = p[t//2+1]


    colfn = [ -1 for i in range(N)]
    colfn[0] = 0
    def dfs2(n,c):

        for v in e[n]:
            if v == sn:
                continue
            elif colfn[v] == -1:
                colfn[v] = c + 1
                dfs2(v,c+1)

    dfs2(0,0)

    fennec = -1
    for i in range(N):
        if colfn[i] != -1:
            fennec += 1

    snuke = N - fennec - 2
    if fennec > snuke:
        print("Fennec")
    else:
        print("Snuke")



if __name__ == '__main__':
    main()



Measured memory_bytes: 137108
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;string S;cin>>N>>S;
  for(int i=0;i<S.size();i++){
    if(char(S.at(i)+N)<='Z')cout<<char(S.at(i)+N);
    else cout<<char(S.at(i)+N-26);
  }
  cout<<endl;
}

Measured memory_bytes: 256
# coding: utf-8
W, H, N = map(int, input().split())
grid = [[0, W], [0, H]]
for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        if grid[0][0] < x:
            grid[0][0] = x
    elif a == 2:
        if grid[0][1] > x:
            grid[0][1] = x
    elif a == 3:
        if grid[1][0] < y:
            grid[1][0] = y
    else:
        if grid[1][1] > y:
            grid[1][1] = y
ans = (grid[0][1] - grid[0][0]) * (grid[1][1] - grid[1][0])
if grid[0][0] > grid[0][1] or grid[1][0] > grid[1][1]:
    ans = 0
print(ans)


Measured memory_bytes: 3064
import sys

n, m = map(int, input().split(" "))
ab = [[int(m) for m in input().split(" ")] for i in range(m)]

roads_count = [0 for i in range(n)]
for a_i, b_i in ab:
    if a_i != b_i:
        roads_count[a_i-1] += 1
        roads_count[b_i-1] += 1
[print(num) for num in roads_count]

Measured memory_bytes: 3060
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

a,b,c,d = na()
a-=1

def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
def lcm(a, b):
	return a * b // gcd (a, b)

e = lcm(c,d)

ac = a//c
bc = b//c
ad = a//d
bd = b//d

acd = a//e
bcd = b//e

loo = (bc+bd-bcd) - (ac+ad-acd)

print(b-a-loo)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
using namespace std;
 

int main(){
    int r,d,x; cin >> r >> d >> x;
    rep(i,10){
        x=r*x-d;
        cout << x << endl;
    }
return 0;
}


Measured memory_bytes: 256
/*
If you want to shine like a sun, first burn like a sun.
*/

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define vpi vector<ppi>
#define vpl vector<ppl>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf 9000000000000000000
#define minf -inf
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
#define MAXN 2000005
#define test1(x) cout << #x " = " << x << endl;
#define test2(x,y) cout << #x " = " << x << " " << #y " = " << y << endl;
const ll infinity = 9e18;


#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int



bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
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 fact[MAXN];

void factorial()
{
    fact[0] = 1;

    for(ll i = 1; i < MAXN; i++)
    {
        fact[i] = (i*(fact[i-1]))%mod;
    }
}

ll ncr(ll n,ll r)
{
	ll x1 = power(fact[r],mod-2,mod);
	ll y1 = power(fact[n-r],mod-2,mod);
	return (((fact[n]*x1)%mod)*y1)%mod;
}

int main()
{
    fast
    factorial();
/*
    #ifndef ONLINE_JUDGE
        freopen("input.txt",  "r",  stdin);
        freopen("output.txt", "w", stdout);
    #endif
//*/

        
	ll r1,c1,r2,c2;
	cin>>r1>>c1>>r2>>c2;

	ll ans = (mod + (ncr(r2+c2+2,c2+1)-ncr(r1+c2+1,c2+1)-ncr(r2+c1+1,c1)+ncr(r1+c1,c1))%mod)%mod;

	cout<<ans;



    return 0;
}	

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

int main(){
    int k, s;
    cin >> k >> s;
    int ans = 0;
    for(int x = 0; x <= k; x++){
        for(int y = 0; y<= k; y++){
            if(s-x-y >= 0 && s-x-y <= k) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int main()
{
	int n;
	cin >> n;
	string s;
	REP(i, n)
	{
		char c; cin >> c;
		s += c;
	}
	REP(i, 1111111)
	{
		string t = to_string(i);
		if (s.find(t) == string::npos)
		{
			cout << i << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 3276
N, M, C = gets.chomp.split.map(&:to_i)
B = gets.chomp.split.map(&:to_i)
A = N.times.map{gets.chomp.split.map(&:to_i)}

p A.inject(0) {|sum, a|
    sum = (0...M).inject(0){|res, i| res += a[i] * B[i]} + C > 0 ? sum + 1 : sum
}

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

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    vector<pair<pair<string, int>, int> > p(n);
    REP(i,n){
        cin>>p[i].first.first>>p[i].first.second;
        p[i].second = i+1;
    }
    
    int ans = 1;
    REP(i,n){
        REP(j,n){
            if(p[j].first.first<p[ans-1].first.first) ans = p[j].second;
            else if(p[j].first.first==p[ans-1].first.first && p[j].first.second>p[ans-1].first.second) ans = p[j].second;
        }
        print(p[ans-1].second);
        p[ans-1].first.first = "zzzzzzzzzz";
        p[ans-1].first.second = -1;
        ans = 1;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){
  long long int N, A, B;
  cin >> N >> A >> B;

  long long int sum = 0;
  long long int count = N/(A+B);
  sum = count*A;
  N %= (A+B);
  
  if(N < A)
    sum += N;
  else
    sum += A;
    
  cout << sum << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <algorithm>
#include <ctime>
#include <vector>
#include <set>
#include <queue>
using namespace std;

#define PI 3.14159265358979323846264338327950L

int res;

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

    int A, B;
    int socket = 1;
    cin >> A >> B;
    int cnt = 0;
    while (socket < B)
    {
        socket += A-1;
        cnt++;
        //cout << socket << endl;
    }
    cout << cnt << endl;
    return 0;
}

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

long long ans = 1, n;
map<int, int> mp;

int main() {
  cin >> n;
  for(int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    ++mp[x];
  }
  for(auto it = mp.begin(); it != mp.end(); ++it) {
    if(it->first != 0 && it->second != 2) {
      cout << 0 << endl;
      return 0;
    }
    ans *= it->second;
    ans %= 1000000007;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3200
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,m = readInts()
def yaku(m):
    ans = []
    i = 1
    while i*i <= m:
        if m % i == 0:
            j = m // i
            ans.append(i)
            if j != i:
                ans.append(j)
        i += 1
    ans = sorted(ans)
    return ans
ya = yaku(m)
#print(ya)
ans = -1
for a in ya:
    if a * n <= m:
        ans = a
    else:
        break
print(ans)


Measured memory_bytes: 10356
import collections

N = int(input())
cnt_dic = collections.defaultdict(int)

for _ in range(N):
  s = input()
  cnt_dic[s] += 1

max_v = max(cnt_dic.values())

ans_lis = [k for k, v in cnt_dic.items() if v == max_v]

for s in sorted(ans_lis):
  print(s)


Measured memory_bytes: 149588
#include <bits/stdc++.h>
using namespace std;
inline int read() 
{   
	int x=0,f=1;char c=getchar();  
	while(c<'0' || c>'9'){if(c=='-')f=-1;c=getchar();}   
	while(c>='0' && c<='9'){x=x*10+c-'0';c=getchar();}   
	return x*f; 
}     
int n,a,b,c,d;
string str;
int main() 
{ 
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>str;
		if(str=="AC")
			a++;
		else if(str=="WA")
			b++;
		else if(str=="TLE")
			c++;
		else if(str=="RE")
			d++;
	}
	cout<<"AC x "<<a<<endl;
	cout<<"WA x "<<b<<endl;
	cout<<"TLE x "<<c<<endl;
	cout<<"RE x "<<d<<endl;
	return 0;
} 

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;


int main(){
    int a,b ;
    cin >> a >> b ;
    if (a < b)
    {
        for (size_t i = 0; i < b; i++)
        {
            cout << a ;
        }
        
    }else
    {
        for (size_t i = 0; i < a; i++)
        {
            cout << b ;
        }
        
    }
    cout << endl ;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int k;
  cin >> k;
  vector<ll> lunlun{1,2,3,4,5,6,7,8,9};
  while(true){
    if(lunlun.size() >= k){
      cout << lunlun[k - 1] << endl;
      return 0;
    }
    k -= lunlun.size();
    vector<ll> old;
    for(ll i : lunlun){
      for(int j = -1; j <= 1; j++){
        int num = i % 10 + j;
        if(num > 9 || num < 0) continue;
        old.push_back(i * 10 + num);
      }
    }
    swap(old, lunlun);
  }
}

Measured memory_bytes: 1712
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int TEN(int n) {return (n==0)?1:10*TEN(n-1);}

int main() {
    string s;
    cin >> s;
    int n = (int)s.size();
    if (n == 2) {
        if (s[0] == s[1]) {
            printf("1 2\n");
        } else {
            printf("-1 -1\n");
        }
        return 0;
    }
    for (int i = 0; i < n-2; i++) {
        if (s[i] == s[i+1] or s[i+1] == s[i+2] or s[i+2] == s[i]) {
            printf("%d %d\n", i+1, i+3);
            return 0;
        }
    }
    printf("-1 -1\n");
    return 0;
}

Measured memory_bytes: 512
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys


def input():
    return sys.stdin.readline()


def resolve():
    k, x = map(int, input().split())

    sum_money = k * 500

    if sum_money >= x:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    resolve()



Measured memory_bytes: 38384
#include<bits/stdc++.h>                                                                    
using namespace std;
int main()
{
  int N;
  cin >> N;
  vector<int> T(N);
  for(int i=0; i<N; i++){
    cin >> T.at(i);
  }
  int M;
  cin >> M;
  vector<int> P(M);
  vector<int> X(M);
  for(int i=0; i<M; i++){
    cin >> P.at(i) >> X.at(i);
  }
  vector<int> sum(M);
  for(int i=0; i<M; i++){
    for(int j=0; j<N; j++){
      if(P.at(i)==j+1)
        sum.at(i)+=X.at(i);
      else
        sum.at(i)+=T.at(j);
    }
  }
  for(int i=0; i<M; i++)
    cout << sum.at(i) << endl;
}


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

using namespace std;

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

    if (a + b >= k) {
        cout << min(a, k) << endl;
    } else {
        cout << 2 * a + b - k << endl;
    }
}


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

int countFreq(string &pat, string &txt)
{
    int M = pat.length();
    int N = txt.length();
    int res = 0;
    for (int i = 0; i <= N - M; i++)
    {
        int j;
        for (j = 0; j < M; j++)
            if (txt[i+j] != pat[j])
                break;

        if (j == M)
        {
           res++;
           j = 0;
        }
    }
    return res;
}

int main()
{
    int n;
    cin >>n;
   string txt ;
   cin>>txt;
   string pat = "ABC";
   cout << countFreq(pat, txt);
   return 0;
}


Measured memory_bytes: 256
import numpy as np

l = []

for _ in range(3):
    a = [int(x) for x in input().split()]
    l.append(a)

l = np.array(l)

def check(m):
    a = []
    for i in range(3):
        b,c = m[i,0] - m[i,1], m[i,1] - m[i,2]
        a.append((b,c))
    if a[0] != a[1] or a[1] != a[2]:
        return False
    else:
        return True

if check(l) and check(np.transpose(l)):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 21812
import numpy as np

_,*_t=[list(map(int,i.split())) for i in open(0)]
n=_[0]
m=_[1]
x=_[2]
table=np.array(_t)
value=9000000


def boolAchieve(nums):
  for i in range(1,m+1):
    if nums[i]<x:
      return False
  return True


tmp=np.sum(table,axis=0)
if not boolAchieve(tmp):
  print(-1)
  exit()


for i in range(1,2 ** n):
  selects=[bool((i >> j) & 1) for j in range(n)]
  picks=np.sum(table[selects,:],axis=0)
  if not boolAchieve(picks):
    continue
  value=min(value,picks[0])

  
print(value)

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

using namespace std;

typedef long long int lli;

lli dp[100001][101];
lli wt[101], val[101];

lli max_val(lli w, lli i) {
	if(i==0) return 0;
	
	if(!dp[w][i-1]) dp[w][i-1] = max_val(w, i-1);
//	cout << dp[w][i-1] << " weight " << w << " concerning " << i-1 << endl;
	
	if(w < wt[i]) return dp[w][i-1];
	
	lli t1, t2;
	
	if(!dp[w-wt[i]][i-1]) dp[w-wt[i]][i-1] = max_val(w-wt[i], i-1);
	
//	cout << dp[w][i-1] << " weight " << w-wt[i] << " concerning " << i-1 << endl;
	t1 = val[i] + dp[w-wt[i]][i-1];
	
	t2 = dp[w][i-1];
	return max(t1, t2);
}

int main() {
	int n, w;
	cin >> n >> w;
	for(int i=1; i<=n; i++) cin >> wt[i] >> val[i];

	cout << max_val(w, n) << endl;	
}

Measured memory_bytes: 78848
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n;

int main(){
	cin>>n;
	while(1){
		if(n/100==n/10%10&&n/100==n%10) break;
		n++;
	}
	cout<<n<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define MAX_E 500000
#define MAX_V 100000
#define INF 1010001000

typedef struct edge{
    int from, to, cost;
}edge;

edge es[MAX_E];
int d[MAX_V];
int v, e;

int main(void)
{
    int i, j, r, fl;
    scanf("%d%d%d", &v, &e, &r);

    for (i = 0; i < v; i++) {
        d[i] = INF;
    }

    for (i = 0; i < e; i++) {
        scanf("%d %d %d", &es[i].from, &es[i].to, &es[i].cost);
    }
    d[r] = 0;
    for (j = 0; j < v; j++) {
        fl = 1;
        for (i = 0; i < e; i++) {
            if (d[es[i].from] != INF &&
                    d[es[i].to] > d[es[i].from] + es[i].cost) {
                d[es[i].to] = d[es[i].from] + es[i].cost;
                fl = 0;
            }
        }
        if (fl) {
            break;
        } else if (j == v-1) {
            puts("NEGATIVE CYCLE");
            return 0;
        }
    }
    for (i = 0; i < v; i++) {
        if (d[i] == INF) {
            puts("INF");
        } else {
            printf("%d\n", d[i]);
        }
    }
    return 0;
}

Measured memory_bytes: 632
import math
n = input()
n = int(n)
summ=0
count = 0
if(n%2==1): print("0")
else:
    while(n/5>0):
        if(count==0): 
            n=str(n)
            n=n[0:len(n)-1]
            if(len(n)==0): break
            else: n=int(n) 
            count+=1
        else:
            n = n*2
            n=str(n)
            n=n[0:len(n)-1]
            if(len(n)==0): break
            else: n=int(n)            
        #print("n="+str(n))
        summ+=n
    print(summ)
#12499999999999996
#1000000000000000000
#100000000000000010
# 99999999999999990

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#define numarr 40
using namespace std;

int main() {
	int A[numarr][numarr], K[numarr], N, M, i, j, numlike[numarr], ans = 0;
	cin >> N >> M;
	for (i = 1; i <= M; i++)
	{
		numlike[i] = 0;
	}
	for (i = 1; i <= N; i++)
	{
		cin >> K[i];
		for (j = 1; j <= K[i]; j++)
		{
			cin >> A[i][j];
			numlike[A[i][j]]++;
		}
	}
	for (i = 1; i <= M; i++)
	{
		if (numlike[i] == N)
			ans++;
	}

		cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
LL a,b,x;
LL MOD=1e9+7;
int main(){
	cin>>a>>b>>x;
	if(x<a){
		cout<<x%MOD<<endl;
	}else{
		x-=a;
		LL ans=0;
		LL now=x/(a-b);
		ans+=(now%MOD)*(a%MOD);
		ans%=MOD;
		//cout<<ans<<endl;
		x=x%(a-b);
		x+=a;
		//cout<<x<<endl;
		while(x>=a){
			x-=a;
			x+=b;
			ans+=a;
		}
		ans+=x;
		ans%=MOD;
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 3108
N,M=map(int, input().split())
sc = [tuple(map(int, input().split())) for _ in range(M)]

for n in range(10**(N-1) if N>1 else 0,10**N):
    S = str(n)
    for s,c in sc:
        if S[s-1] != str(c): break
    else:
        print(n)
        exit()

print(-1)

Measured memory_bytes: 38384
x = int(input())
a = round(x**0.5) + 1
import sys

if x == 2:
    print(2)
    sys.exit()
for i in range(x, 2*x+1):
    flag = 0
    for j in range(2,a+1):
        if i % j == 0:
            flag = 1 
            break
    if flag == 0:
        print(x)
        sys.exit()
    x += 1

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;

int main(){
    int n[2];
    cin >> n[0] >> n[1];
    lli ans = 1;
    for(int d=0; d<2; d++){
        lli sum = 0;
        for(int i=0; i<n[d]; i++){
            lli a;
            cin >> a;
            sum += a;
        }
        ans *= sum;
    }
    cout << ans << endl;
    return 0;
}



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

int main() {
	string S, ACGT = "ACGT";
	int N, key = 0, sum = 0, length = 0;

	cin >> S;

	N = S.size();

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 4; j++) {
			if (S[i] == ACGT[j]) {
				sum += 1;
				key = 1;
			}
		}

		if (length < sum) {
			length = sum;
		}

		if (key == 0) { sum = 0; }

		key = 0;
	}

	cout << length;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 5999999999999999999
#define ALL(n) n.begin(),n.end()
#define ABS(a,b) max(a,b) - min(a,b)

int main(){
	int a[26] = {},n[26] = {},ans = INF;
	string s;
	cin >> s;
	REP(i,s.size()){
		REP(j,26){
			if(j == s[i] - 'a') {
				a[j] = max(a[j],n[j]);
				n[j] = 0;
			}else n[j]++;
		}
	}
	REP(j,26) a[j] = max(a[j],n[j]);
	REP(i,26) ans = min(ans,a[i]);
	cout << ans << endl;
}


Measured memory_bytes: 256
A, B, C = input().split()

print(max(
    int(A+B) + int(C),
    int(B+A) + int(C),
    int(B+C) + int(A),
    int(C+B) + int(A),
    int(A+C) + int(B),
    int(C+A) + int(B)
))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) (long long)((a).size())
const double pi = 3.14159265358979323846;

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    
    ll n,i,j;
    cin>>n;
    vector<ll> a(n);
    ll p = 1;
    for(i=0;i<n;i++) 
    {
        cin>>a[i];
        if(a[i]==0) {cout<<0;return 0;}  
    }
    for(i=0;i<n;i++)
    {
        if(a[i]>((ll)1e18)/p) {cout<<-1;return 0;}
        p*=a[i];
        // cout<<i<<"->"<<p<<"\n";
    }
    cout<<p;
}

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

int main() {
    string s1, s2;
    int n;
    cin >> n >> s1 >> s2;
    rep(i,n) {
        cout << s1[i];
        cout << s2[i];
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define array_input int n;cin>>n;int a[n+1],i;for(i=1;i<=n;i++){cin>>a[i];}
#define array_output for(i=1;i<=n;i++){cout<<a[i]<<" ";}cout<<endl;
#define INF 2147483647
#define long_INF 18446744073709551615
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long double ld;
const double pi=acos(-1);
const double eps=1e-6;

void read(int &x)
{
    x=0;
	char c=getchar();
    while(c<'0' || c>'9')c=getchar();
    while(c>='0' && c<='9')
	{
        x=x*10+c-'0';
        c=getchar();
    }
}

void write(int x)
{
    if(x==0)
	{
		putchar(48);
		return;
	}
    int len=0,dg[20];
    while(x>0)
	{
		dg[++len]=x%10;
		x/=10;
	}
    for(int i=len;i>=1;i--)
	{
		putchar(dg[i]+48);
	}
}

int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int ans;
	ans=0;
	if (a<b)
	{
		ans+=a;
	}
	else
	{
		ans+=b;
	}
	if (c<d)
	{
		ans+=c;
	}
	else
	{
		ans+=d;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
S1 = input()
S2 = input()

def prepare(s1,s2,n):
    result = []
    i = 0
    while i < n:
        if s1[i] == s2[i]:
            result.append(1)
            i += 1
        else:
            result.append(0)
            i += 2

    return result



def calculate(arr):
    ans = 1
    for index in range(len(arr)):
        if index == 0:
            if arr[index] == 0:
                ans = 6
            else:
                ans = 3
            continue
        #xo
        if (arr[index - 1] == 1) and (arr[index] == 0):
            ans *= 2

        #xx
        if (arr[index - 1] == 1) and (arr[index] == 1):
            ans *= 2

        #oo
        if (arr[index - 1] == 0) and (arr[index] == 0):
            ans *= 3

        #ox
        if (arr[index - 1] == 0) and (arr[index] == 1):
            ans *= 1

    print(ans % 1000000007)



arr = prepare(S1,S2,N)
calculate(arr)

Measured memory_bytes: 9232
#include <iostream>
#include <string>
#include <vector>
#include <map>

using namespace std;

int main(void){
    // Your code here!
    while(true){
        int N;
        cin >> N;
        if(N == 0){
            break;
        }
        vector<int> income;
        int ans = 0;
        int average = 0;
        for(int i=0;i<N;i++){
            int value;
            cin >> value;
            income.push_back(value);
            average += value;
        }
        average /= N;
        for(int i=0;i<N;i++){
            if(average >= income[i]){
                ans++;
            }
        }
        cout<< ans<<endl;
    }
    return 0;
}



Measured memory_bytes: 3260
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define rn(i,n) for(int i=1;i<=n;i++)

int main(){
  int n;
  cin>>n;
  if(n%2==0)cout<<(double)1/2<<endl;
  else{
    cout<<(double)((int)n-n/2)/n<<endl;
  }


  return 0;
}


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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using pii = pair<int, int>;
using vi = vector<int>;
using lint = long long;

const int inf = 1001001001;
const lint linf = 1001001001001001001ll;
const double eps = 1e-9;
const int mod = 1e9 + 7;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};

template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; } return a > b; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; } return a < b; }
template<typename T> inline void print(const T &x, string s = "\n") { cout << x << s; }
template<typename T> inline void print(const vector<T> &v, string s = " ")
{ if (!v.size()) puts(""); rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : s); }
inline bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; }
inline lint in() { lint x; std::cin>>x; return x; }

signed main()
{
  int n = in();
  vector<lint> a;

  rep(i, n) a.pb(in());

  lint ans = 0;
  while (true) {
    bool f = true;
    rep(i, n) if (a[i] >= n) f = false;
    if (f) break;

    lint cnt = 0;
    rep(i, n) {
      cnt += max(0ll, a[i]) / n;
    }
    rep(i, n) {
      lint d = max(0ll, a[i]) / n;
      a[i] = a[i] - d * n + (cnt - d);
    }

    ans += cnt;
  }

  print(ans);
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int N, R, R2;
	scanf("%d %d", &N, &R);
	if(N>=10){
		R2=R;
		printf("%d", R2);
	} else {
		R2=R+100*(10-N);
		printf("%d", R2);
	}
	return 0;
}

Measured memory_bytes: 2128
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long int;
using ull = unsigned long long int;
using P = pair<ll, ll>;
using P3 = pair<double,P>;
using PP = pair<P ,P>;
constexpr ll MOD = ll(1e9+7);
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e6) + 5;
constexpr double EPS = 1e-8;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int main(){
    ll n;
    cin >> n;
    vector<P> ls;
    for(int i=0;i<n;i++){
        ll x, l;
        cin >> x >> l;
        ls.push_back(P(x+l,x-l));
    }
    SORT(ls);
    ll ans = 0, r = -LLINF;
    for(int i=0;i<n;i++){
        if(ls[i].second >= r){
            ans++;
            r = ls[i].first;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2420
open System;

[<EntryPoint>]
let main argv =
    ignore( System.Console.ReadLine() )
    let res = seq { while true do yield System.Console.ReadLine() }
                |> Seq.takeWhile( (<>) null )
                |> Seq.map (fun x -> x + "\n" + x)
                |> Seq.reduce (fun a b -> a + "\n" + b)
    printfn "%s" res
    0


Measured memory_bytes: 8276
N = input()
A_list = list(map(int,input().split()))
flag = True
count = 0
while flag:
    for n in range(len(A_list)):
        if A_list[n] % 2 != 0:
            flag = False
            break
        A_list[n] /= 2
    if flag == True:
        count += 1
print(count)

Measured memory_bytes: 39152
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.TreeMap;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		TreeMap<Integer, Integer[]> trade = new TreeMap<Integer, Integer[]>();

		boolean lastMonth = false;
		int customer = 0;

		while ((line = br.readLine()) != null) {
			if (line.isEmpty()) {
				lastMonth = true;
				continue;
			} else {
				customer = Integer.parseInt(line.split(",")[0]);
			}
			
			if (!lastMonth) {
				if (trade.containsKey(customer)) {
					trade.get(customer)[0]++;
				} else {
					trade.put(customer, new Integer[2]);
					trade.get(customer)[0] = 1;
					trade.get(customer)[1] = 0;
				}
			} else {
				if (trade.containsKey(customer)) {
					trade.get(customer)[1]++;
				}
			}
		}
		for (Integer k : trade.keySet()) {
			if (trade.get(k)[1] > 0)
				System.out.println(k + " "
						+ (trade.get(k)[0] + trade.get(k)[1]));
		}
	}
}

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

struct card { char suit, value; };

void bubble(struct card a[],int n) {
	for (int i = 0; i < n; i++) {
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j].value < a[j-1].value) {
				card t = a[j]; a[j] = a[j - 1]; a[j - 1] = t;
			}
		}
	}
}

void selection(struct card a[], int n){
	for (int i = 0; i < n; i++) {
		int minj = i;
		for (int j = i; j < n; j++) {
			if (a[j].value < a[minj].value) {
				minj = j;
			}
		}
		card t = a[i]; a[i] = a[minj]; a[minj] = t;
	}
}

void print(struct card a[], int n) {
	for (int i = 0; i < n; i++) {
		if (i > 0 && i<=n-1) cout << " ";
		cout << a[i].suit << a[i].value;
	}
	cout << endl;
}

bool isStable(struct card a[], struct card b[], int n) {
	for (int i = 0; i < n; i++) {
		if (a[i].suit != b[i].suit) {
			return false;
		}
	}
	return true;
}

int main() {
	card c1[100], c2[100];
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> c1[i].suit >> c1[i].value;
	}
	for (int i = 0; i < n; i++) c2[i] = c1[i];

	bubble(c1, n);
	selection(c2, n);

	print(c1,n);
	cout << "Stable" << endl;

	print(c2, n);
	if (isStable(c1, c2, n)) {
		cout << "Stable" << endl;
	}
	else {
		cout << "Not stable" << endl;
	}

	return 0;
}

Measured memory_bytes: 3104
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use text_io::*;

fn main() {
    const U_INF: usize = 1 << 50;
    const I_INF: isize = 1 << 50;

    let n: usize = read!();
    let m: usize = read!();
    let mut vertexes = vec![vec![]; n];
    for _ in 0..m {
        let x: usize = read!();
        let y: usize = read!();
        vertexes[y - 1].push(x - 1);
    }

    let mut dp = vec![None; n];

    println!("{}", (0..n).map(|i| memo(i, &vertexes, &mut dp)).max().unwrap() - 1);
}

fn memo(i: usize, vertexes: &Vec<Vec<usize>>, dp: &mut Vec<Option<usize>>) -> usize {
    match dp[i] {
        Some(n) => n,
        None => {
            let bs = vertexes[i].iter().map(|&j| memo(j, vertexes, dp));
            let ans = bs.max().unwrap_or(0) + 1;
            dp[i] = Some(ans);
            ans
        }
    }
}


Measured memory_bytes: 16408
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n, x;
        while(true){
            n = scan.nextInt();
            x = scan.nextInt();
            if(n == 0 && x == 0) break;
            System.out.println(calcCombi(n, x));
        }
    }
    public static int calcCombi(int n, int x){
        if(x < 6) return 0;
        int i, j, k;
        int count = 0;
        for(i = 1; i <= n; i++){
            for(j = i + 1; j <= n; j++){
                for(k = j + 1; k <= n; k++){
                    if(i + j + k == x) count++;
                }
            }
        }
        return count;
    }
}


Measured memory_bytes: 26600
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<cmath>
using namespace std;
int main()
{
    long long n,m;
    scanf("%lld",&n);
    for(long long i = 1; i*i <= n; i++)
        m = i * i;
    printf("%lld\n",m);
}

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

int main(){

    int n; cin >> n;
    vector<vector<int> > a(n, vector<int> (30, 0));
    for(int i = 0; i < n; i++){
        string s; cin >> s;
        for(int j = 0; j < s.size(); j++){
            a[i][(int)(s[j] - 'a')]++;
        }
    }

    vector<char> ans;

    for(int i = 0; i < 26; i++){
        int num = 1000;
        for(int j = 0; j < n; j++){
            num = min(num, a[j][i]);
        }

        //cout << num << endl;
        for(int j = 0; j < num; j++) ans.push_back(i + (int)'a');
    }

    for(int i = 0; i < ans.size(); i++){
        cout << ans[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
from bisect import bisect_left

s = input()
t = input()

len_s = len(s)
indices = defaultdict(list)
for i in range(len_s):
    indices[s[i]].append(i + 1)

letters_s = set(indices.keys())
letters_t = set(t)
if letters_t <= letters_s:
    cycles = 0
    cur = 0
    for ti in t:
        index = bisect_left(indices[ti], cur + 1)
        if index == len(indices[ti]):
            cycles += 1
            cur = indices[ti][0]
        else:
            cur = indices[ti][index]
    ans = len_s * cycles + cur
else:
    ans = -1
print(ans)


Measured memory_bytes: 7916
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()


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

const int Z = 10000;
bool dpx[Z];
bool dpy[Z];
bool tmp[Z];

int main(){
    dpx[0] = dpy[0] = true;
    string s;
    int x, y;
    cin >> s >> x >> y;
    const int len = s.size();
    int z = 0;
    while(z < len && s[z] != 'T'){
        z++;
    }
    x -= z;
    if(abs(x) > 8000){cout << "No" << endl; return 0;}
    if(s[z] == 'T')z++;
    int cnt = 0;
    s += "T";
    int t = 0;              //0のときx, 1のときy
    for(; z <= len; z++){
        if(s[z] == 'T'){
            t ^= 1;
            fill(tmp, tmp + Z, false);

            rep(i, Z){
                if(t){
                    if(!dpy[i])continue;
                    tmp[i + cnt] = tmp[abs(i - cnt)] = true;
                }
                else {
                    if(!dpx[i])continue;
                    tmp[i + cnt] = tmp[abs(i - cnt)] = true;
                }
            }
            cnt = 0;
            swap(tmp, t ? dpy : dpx);
        }
        else cnt++;
    }
    if(dpx[abs(x)] && dpy[abs(y)])cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		long n, a, i, sum, max, min;
		
		Scanner scan = new Scanner(System.in);
		
		n = scan.nextInt();
		a = scan.nextInt();
		max = a;
		min = a;
		sum = a;
		
		for(i = 1; i < n; i++) {
			a = scan.nextInt();
			sum += a;
			if(a > max) max = a;
			if(a < min) min = a;
		}
		
		System.out.printf("%d ", min);
		System.out.printf("%d ", max);
		System.out.printf("%d\n", sum);
		
	}

}


Measured memory_bytes: 43196
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<map>
#include<iomanip>
#include<limits>
#include<queue>
#include<set>
#include<cstdio>
#include<climits>
#include<cstring>

using namespace std;

int main(){


	int N = 100000;

	int A,B,C,X,Y;
	cin >> A >>B >>C >> X >> Y;

	int ans = INT_MAX;
	for(int i = 0;i <=N;i++){
		int a = 0;
        a = i*2*C + max(0,X-i)*A + max(0,Y-i)*B;
        ans = min(ans,a);
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 0
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
using namespace std;

int n,W,ans;
int dp[111][111111];
int w[1111],v[1111];
signed main(){
	cin>>n>>W;
	rep(i,n)cin>>w[i]>>v[i];
	rep(j,W+1){
		rep(i,n){
			dp[i+1][j]=max(dp[i][j],dp[i+1][j]);
			if(j>=w[i])dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]);
			
		}
	}
	cout<<dp[n][W]<<endl;
}

Measured memory_bytes: 87296