akhauriyash/Code-Regression huggingface dataset:
N, W = map(int, input().split())
dp = [[0]*100100 for _ in range(110)]

for i in range(N):
    weight, value = map(int, input().split())
    for sum_w in range(W+1):
        if sum_w - weight >= 0:
            dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w - weight] + value)

        dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w])

print(dp[N][W])

Measured memory_bytes: 159900
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<vector<vector<int>>> v3int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef vector<vector<vector<ll>>> v3ll;
typedef list<int> liint;
typedef pair<int, int> pint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, int>> vpll_int;
typedef vector<pair<int, ll>> vpint_ll;
typedef set<pair<int, int>> spint;
typedef set<pair<ll, int>> spll;
typedef unordered_map<int, unordered_set<int>> Graph;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string S;
    cin >> S;
    if (S[S.size() - 1] == 's') {
        cout << S + "es" << endl;
    }
    else {
        cout << S + "s" << endl;
    }
    return 0;
}

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

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	vector <int> a(n);
	for (int &i : a) cin >> i;
	sort(a.begin(), a.end());
	int min_cost = 0;
	for (int i=0; i<k; ++i) min_cost += a[i];
	cout << min_cost << '\n';
}


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

const long long INF = 1LL << 60;

int n;
int k;
long long h[100100];
long long dp[100100];

int main() {
  cin >> n >> k;
  for (int i = 0; i < n; ++i) cin >> h[i];
  for (int i = 0; i < n; ++i) dp[i] = INF;

  dp[0] = 0;

  for (int i = 1; i < n; ++i) {
    for (int j = 1; j <= k; ++j) {
      if (j <= i) {
        long rep = dp[i - j] + abs(h[i] - h[i - j]);

        if (rep < dp[i]) {
          dp[i] = rep;
        }
      }
    }
  }

  cout << dp[n - 1] << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+6;
int main()
{
	int a[maxn];
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a+1,a+n+1);
	if(n%2!=0)
	{
		printf("0\n");
	}
	else
	{
		if(a[n/2]==a[(n/2)+1])
		{
			printf("0\n");
		}
		else
		{
			printf("%d\n",a[n/2+1]-a[n/2]);
		}
	}
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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 long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;
int H, W;
int dh[2] = {1, 0};
int dw[2] = {0, 1};
deque<i_i> deq;
string field[105];
ll dist[105][105];

int main() {
    cin >> H >> W;
    for(int h = 0; h < H; h++) {
        cin >> field[h];
    }
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            dist[i][j] = 1e9;
        }
    }
    dist[0][0] = 0;
    if(field[0][0] == '#') dist[0][0] = 1;
    deq.push_back({0, 0});
    while(!deq.empty()) {
        auto now = deq.front();
        deq.pop_front();
        int nowh = now.first;
        int noww = now.second;
        for(int k = 0; k < 2; k++) {
            int newh = now.first + dh[k];
            int neww = now.second + dw[k];
            if(newh >= H) continue;
            if(neww >= W) continue;
            ll cost = dist[now.first][now.second];
            if(field[nowh][noww] != field[newh][neww]) cost++;
            if(chmin(dist[newh][neww], cost)) {
                if(field[nowh][noww] != field[newh][neww]) {
                    deq.push_back({newh, neww});
                } else {
                    deq.push_front({newh, neww});
                }
            }
        }
    }
    int ans = dist[H-1][W-1];
    if(ans & 1) ans++;
    cout << ans / 2 << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h> 
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define Rep(i,s,t) for(long long i=s;i<t;i++)
#define all(x) x.begin(),x.end()
#define _GLIBCXX_DEBUG
typedef long long ll;
using namespace std;
int main(){
  int r;
  cin>>r;
  cout<<3*r*r<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int n;
	cin >> n;
	int num = n;

	int sum = 0;
	while (n) {
		sum += n % 10;
		n /= 10;
	}

	if (num % sum == 0) {
		cout << "Yes" << '\n';
	} else {
		cout << "No" << '\n';
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define maxn 100005
using namespace std;

int par[maxn], res[maxn], sz[maxn], in[maxn];

int rep(int x){
    if(par[x] == x) return x;
    return par[x] = rep(par[x]);
}

void join(int x, int y){
    x = rep(x);
    y = rep(y);
    if(x != y){
        par[x] = y;
        sz[y] += sz[x];
    }
}

int main() {

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

    for(int i=1;i<=n;i++){
        par[i] = i;
        sz[i] = 1;
    }
    while(m--){
        int x, y;
        cin >> x >> y;
        join(x, y);
        in[x] ++;
        in[y] ++;
    }
    for(int i=1;i<=n;i++){
        res[i] = sz[rep(i)] - 1 - in[i];
    }
    while(k--){
        int x, y;
        cin >> x >> y;
        if(rep(x) == rep(y)){
            res[x] --;
            res[y] --;
        }
    }

    for(int i=1;i<=n;i++){
        if(i-1) cout << " ";
        cout << res[i] ;
    }
    cout << endl;


    return 0;
}



Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <algorithm>

int main(int argc, char *argv[]){
    int A,B;
    std::cin >> A >> B;
    std::vector<int>vector({A+B,A-B,A*B});
    std::cout << *std::max_element(vector.begin(),vector.end()) << std::endl;
    return 0;
}


Measured memory_bytes: 256
N=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
ans=0
r=0
for i in range(N):
  if q[i]+r>p[i]:
    ans+=p[i]
    r=min(q[i]+r-p[i],q[i])
  else:
    ans+=q[i]+r
    r=0
ans+=min(p[N],r)
print(ans)


Measured memory_bytes: 18624
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int x = stdIn.nextInt();
		int a = stdIn.nextInt();
		int b = stdIn.nextInt();
		
		if(b >= a+x+1) {
			System.out.println("dangerous");
		}else {
			if(b > a) {
				System.out.println("safe");
			}else {
				System.out.println("delicious");
			}
		}
		
	}

}


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

using namespace std;

int main()
{
    int N; cin >> N;
    int x = N, d = 0;
    while (x)
    {
        d += x % 10;
        x /= 10;
    }
    if (N % d == 0) cout << "Yes\n";
    else cout << "No\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int main()
{
  int N;
  int a[2][100];
  int dp[3][110];
  cin >> N;

  rep(i,2) {
    rep(j,N) {
      cin >> a[i][j];
    }
  }

  rep(i,3) {
    rep(j,110) {
      dp[i][j]=0;
    }
  }

  dp[0][0] = a[0][0];

  FOR(i,1,2){
    FOR(j,1,N) {
      if(i==0) dp[i][j] = dp[i][j-1] + a[i-1][j-1];
      else dp[i][j] = max(dp[i][j-1] + a[i-1][j-1], dp[i-1][j] + a[i-1][j-1]);
    }
  }

  cout << dp[2][N] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll n,k;
    cin>>n>>k;
    bool a0[n];
    rep(0,i,n)a0[i]=false;
    rep(0,i,k){
        ll d;
        cin>>d;
        rep(0,j,d){
            ll a;
            cin>>a;
            a0[a-1]=true;
        }
    }
    ll ans=0;
    rep(0,i,n)if(!a0[i])++ans;
    cout<<ans;
}

Measured memory_bytes: 3632
import numpy as np
n = int(input())

AB = []

for i in range(n):
    AB.append(list(map(int, input().split())))
AB = sorted(AB)
AB = sorted(AB, key = lambda x: x[1])
AB = np.array(AB)

X = np.cumsum(AB.T[0])
Y = AB.T[1]

Z = Y - X

ans = 'Yes'

for i in Z:
    if i < 0:
        ans = 'No'
        break

print(ans)


Measured memory_bytes: 65132
#include<cstdio>
#include<cstring>
char s[10001];
int main()
{
	int n;
	scanf("%d",&n);
	scanf("%s",s+1);
	int len=strlen(s+1);
	for(int i=1;i<=len;i++){
		int x=s[i]-'A';
		x=(x+n)%26;
		s[i]=x+'A';
	}
	printf("%s",s+1);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <cmath>

using namespace std;

int main(int argc, char *argv[]) {
  int n, pm, pe, pj;
  while (cin >> n, n) {
    for (int i = 0; i < n; i++) {
      cin >> pm >> pe >> pj;
      if (pm == 100 || pe == 100 || pj == 100)
        cout << 'A' << endl;
      else if ((pm + pe) / 2 >= 90)
        cout << 'A' << endl;
      else if ((pm + pe + pj) / 3 >= 80)
        cout << 'A' << endl;
      else if ((pm + pe + pj) / 3 >= 70)
        cout << 'B' << endl;
      else if (((pm + pe + pj) / 3 >= 50) &&
               (pm >= 80 || pe >= 80))
        cout << 'B' << endl;
      else
        cout << 'C' << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1152
import sys
import math
import collections

def set_debug(debug_mode=False):
    if debug_mode:
        fin = open('input.txt', 'r')
        sys.stdin = fin


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


if __name__ == '__main__':
    # set_debug(True)

    # t = int(input())
    t = 1

    for ti in range(1, t + 1):
        n = int(input())
        print(n + n * n + n * n * n)



Measured memory_bytes: 9372
#include <bits/stdc++.h>
#define intt long long
using namespace std;
const int maxx = 1e5+5;
int i , j ;
int a[maxx];
map <int,int> mp;
int main ()
{
    int n,m , cnt = 0;
    cin >> n>> m;
    intt res =0 , ans = 0 ;
    mp[0] =1;
    for ( i =1  ; i <= n;  i++ )
    {
        cin >> a[i];
        res += a[i];
        ans += mp[res%m];
        mp[res%m]++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3584
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
int main(){
	int a[5],mini=100000;
	for(int i=0;i<5;++i){
	scanf("%d",&a[i]);
	}
	for(int i=0;i<3;++i){
		if(mini>a[i]){
			mini=a[i];
		}
	}
	printf("%d\n",mini+std::min(a[3],a[4])-50);
	return 0;
}

Measured memory_bytes: 3212
from collections import defaultdict
import bisect

d=defaultdict(list)

s=input()
t=input()

ns=len(s)
nt=len(t)

for i in range(ns):
  d[s[i]].append(i)

for k,v in d.items():
  d[k].append(ns)
#print(d)

ans=0
cnt=-1

for i in range(nt):
  tt=d[t[i]]
#  print(t[i],tt,ans,cnt)
  if tt==[]:
    print(-1)
    exit(0)
  else:
    a=bisect.bisect_right(tt,cnt)
#    print("ind",a)
    if tt[a]==ns:
      ans+=ns+tt[0]-cnt
      cnt=tt[0]
    else:
      ans+=tt[a]-cnt
      cnt=tt[a]
      
print(ans)
      

Measured memory_bytes: 7916
// "header" {{{
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <tuple>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int> 
#define int long long
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1000000007;

inline double sqrt( const double &x) 
{
	double         xHalf = 0.5 * x;
	int64_t  tmp   = 0x5FE6EB50C7B537AAl - ( *(int64_t*)&x >> 1);
	double         xRes  = * (double*)&tmp;

	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	return xRes * x;
}
// }}}
int N,W;
vector<int> w,v;
vector<vector<int> > mem;

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N >> W;
	w.resize(N+1);
	v.resize(N+1);
	mem.resize(N+1,vector<int>(W+1));
	reps(i,N){
		cin >> w[i] >> v[i];
	}
	reps(i,N){
		reps(j,W){
			if(w[i] <= j) mem[i][j] = max(mem[i-1][j-w[i]] + v[i],mem[i-1][j]);
			else mem[i][j] = mem[i-1][j];
		}
	}
	cout << mem[N][W] << '\n';
	return 0;	
}


Measured memory_bytes: 80256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

//解説参考.
int main(){
	int n;
	cin>>n;
	
	vector<vector<pii > > g(n);
	REP(i,n-1){
		int u,v,w;
		cin>>u>>v>>w;
		u--, v--;
		g[u].emplace_back(v,w);
		g[v].emplace_back(u,w);
	}
	
	vi ans(n,-1);
	ans[0]=0;
	queue<int> que;
	que.push(0);
	while(!que.empty()){
		int v=que.front();
		que.pop();
		REP(i,g[v].size()){
			int u,w;
			tie(u,w)=g[v][i];
			if(ans[u]==-1){
				ans[u]=(ans[v]+w)%2;
				que.push(u);
			}
		}
	}
	
	for(auto elem:ans) cout<<elem<<endl;
}

Measured memory_bytes: 6912
#include <iostream>
#include <string>
#include <map>
using namespace std;
string z(int i){string s="";if(i>25){s+='a'+i/25;i%=25;}s+='a'+i;return s;}
int main(){
	string s;
	map<string,int>m;
	int i=0;
	cout<<"?shiritori"<<endl<<flush;
	for(;i<50;i++){
		cin>>s;
		if(s[0]!='i'||m[s]){cout<<"!OUT"<<endl;return 0;}
		m[s]=1;cout<<string("?")+s[s.size()-1]<<z(i)<<'i'<<endl<<flush;
	}
}

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

using namespace std;

#define REP(i,n) for(int i=0;(i)<(int)(n);(i)++)

int main() {
  int N;
  cin >> N;
  vector<int> a, b;

  int skip = (N % 2 == 1) ? N - 1 : N;

  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) if (i < j) {
      if (j == skip) continue;
      a.emplace_back(i);
      b.emplace_back(j);
    }
    skip--;
  }

  cout << a.size() << endl;
  REP(i,a.size()) {
    cout << a[i] << ' ' << b[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(void){
	int i, j, H, W;
	while(1){
		//数値を2つ入力
		scanf("%d %d", &H, &W);
		//数値が2とも0なら終了
		if(H == 0 && W == 0){
			break;
		}
		//チェック柄の四角形表示
		for(i = 0; i < H; i++){
			for(j = 0; j < W; j++){
				if((i % 2) == 0){
					if(j == (W - 1) && (j % 2) == 0){
						printf("#\n");
					}else if((j % 2) == 0){
						printf("#");
					}else if(j == (W - 1) && (j % 2) == 1){
						printf(".\n");
					}else{
						printf(".");
					}
				}else{
					if(j == (W - 1) && (j % 2) == 0){
						printf(".\n");
					}else if((j % 2) == 0){
						printf(".");
					}else if(j == (W - 1) && (j % 2) == 1){
						printf("#\n");
					}else{
						printf("#");
					}
				}
			}
		}
		printf("\n");
	}
	return 0;
}

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

typedef std::pair <int, int> pr;
const int N = 300054, INF = 0x3f3f3f3f;

int n, X, Y;
int x[N], y[N], l[N], u[N];
int que[N];
pr p[N];

inline void up(int &x, const int y) {x < y ? x = y : 0;}
inline void down(int &x, const int y) {x > y ? x = y : 0;}
inline int max(const int x, const int y) {return x < y ? y : x;}

int partition(int L, int R) {
	#define val(_) (u[_] - x[_])
	if (L + 1 == R) return 0;
	int i, j, h = 0, t = 0, M = (L + R) / 2, inf = 0, sup = Y, left = INF, ret = 0;
	for (i = M; i < R; ++i) l[i] = inf, u[i] = sup, y[i] * 2 <= Y ? up(inf, y[i]) : down(sup, y[i]);
	inf = 0, sup = Y;
	for (i = M - 1; i >= L; --i) l[i] = inf, u[i] = sup, y[i] * 2 <= Y ? up(inf, y[i]) : down(sup, y[i]);
	for (i = M, j = M - 1; i < R; ++i) {
		for (; j >= L && l[j] <= l[i]; que[t++] = j--)
			for (; h < t && val(que[t - 1]) <= val(j); --t);
		for (; h < t && u[ que[h] ] >= u[i]; ++h) down(left, x[ que[h] ]);
		up(ret, (u[i] - left) + (x[i] - l[i]));
		if (h != t) up(ret, val(que[h]) + (x[i] - l[i]));
	}
	return up(ret, partition(L, M)), up(ret, partition(M, R)), ret;
}

int main() {
	int i, ans;
	scanf("%d%d%d", &X, &Y, &n), ans = 1 + max(X, Y);
	for	(i = 0; i < n; ++i) scanf("%d%d", &p[i].first, &p[i].second);

	x[n + 1] = X, std::sort(p, p + n);
	for (i = 1; i <= n; ++i) std::tie(x[i], y[i]) = p[i - 1];
	up(ans, partition(0, n + 2));

	std::reverse(x + 1, x + (n + 1)), std::reverse(y + 1, y + (n + 1));
	for (i = 1; i <= n; ++i) x[i] = X - x[i];
	up(ans, partition(0, n + 2));
	
	for (std::swap(X, Y), i = 0; i < n; ++i) std::swap(p[i].first, p[i].second);

	x[n + 1] = X, std::sort(p, p + n);
	for (i = 1; i <= n; ++i) std::tie(x[i], y[i]) = p[i - 1];
	up(ans, partition(0, n + 2));

	std::reverse(x + 1, x + (n + 1)), std::reverse(y + 1, y + (n + 1));
	for (i = 1; i <= n; ++i) x[i] = X - x[i];
	up(ans, partition(0, n + 2));

	printf("%d\n", 2 * ans);
	return 0;
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    string s; cin >> s;

    string t; t = s;
    reverse(t.begin(), t.end());

    int sum = 0;

    for (int i = 0; i < s.length(); ++i) {
        if (s[i] != t[i]) ++sum;
    }

    cout << sum / 2 << endl;
}

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

using namespace std;

const int OO = 1e9;
const double EPS = 1e-9;

#define ndl cout << '\n'
#define sz(v) int(v.size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define present(a, x) (a.find(x) != a.end())
#ifdef LOCAL
#define db(...) ({cout << "> Line " << __LINE__  \
		<< ": "; _db(#__VA_ARGS__, __VA_ARGS__);})
#define RNG() rng()
#else
#define db(...) true
#define RNG() true
#endif

template<class T>
void _db(const char *dbStr, T e) {
	cout << dbStr << " = " << e << endl;
}
template<class T, class... L>
void _db(const char *dbStr, T e, L... r) {
  while(*dbStr != ',') cout << *dbStr++;
  cout << " = " << e << ','; _db(dbStr + 1, r...);
}
template<class S, class T>
ostream& operator<<(ostream& o, const map<S, T>& v) {
	o << "["; int i = 0;
	for (const pair<S, T>& pr : v) o << (!i++ ? "" : ", ") << "{"
	<< pr.fs << " : " << pr.sc << "}"; return o << "]";
}
template<template <class, class...> class S, class T, class... L>
ostream& operator<<(ostream& o, const S<T, L...>& v) {
	o << "["; int i = 0;
	for (const auto& e : v) o << (!i++ ? "" : ", ") << e;
	return o << "]";
}
template<class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& pr) {
	return o << "(" << pr.fs << ", " << pr.sc << ")";
}
ostream& operator<<(ostream& o, const string& s) {
	for (const char& c : s) o << c;
	return o;
}

template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = VV<V<T>>;
using ll = long long;
using pii = pair<int, int>;
using vi = V<int>;
using vii = V<pii>;
using vvi = VV<int>;
using mii = map<int, int>;
using umii = unordered_map<int, int>;
using si = set<int>;
using usi = unordered_set<int>;


const int MX = 205;

int N;
bool adj[MX][MX], bad;
int vis[MX];
vi L, R;

void dfs(int u, int clr) {
	vis[u] = clr;
	if (clr == 1)
		L.pb(u);
	if (clr == 2)
		R.pb(u);
	for (int v = 1; v <= N; ++v) {
		if (adj[u][v]) {
			if (!vis[v])
				dfs(v, 3 - clr);
			else {
				if (vis[v] == vis[u])
					bad = true;
			}
		}
	}
}



int main() {
	#ifdef LOCAL
	auto stTime = clock();
//	freopen("in.txt", "r", stdin);
	mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
	#endif
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin.tie(0);

	cin >> N;

	for (int i = 1; i <= N; ++i) {
		for (int j = 1; j <= N; ++j) {
			char c;
			cin >> c;
			adj[i][j] = c - '0';
		}
	}

	dfs(1, 1);

	if (bad) {
		cout << "-1\n";
		return 0;
	}

	db(L, R);

	int ans = 2;

	for (int u = 1; u <= N; ++u) {
		memset(vis, 0, sizeof(vis));
		si s;
		s.insert(u);
		vis[u] = 1;
		int curr = 1;
		while (true) {
			si t;
			for (auto& v : s)
				for (int w = 1; w <= N; ++w)
					if (!vis[w] && adj[v][w])
						t.insert(w), vis[w] = curr + 1;
			if (t.empty())
				break;
			++curr;
			s = t;
		}
		ans = max(ans, curr);
	}


	cout << ans << '\n';


	#ifdef LOCAL
	cout << "\n\n\nExecution time: " <<
		(clock() - stTime) * 1e3 / CLOCKS_PER_SEC << " ms" << endl;
	#endif
    return 0;
}


Measured memory_bytes: 384
# -*- coding: utf-8 -*-
import collections
# factrize
def factorize(target_number):
    factor_list = []
    while target_number % 2 == 0:
        factor_list.append(2)
        target_number //= 2
    factor = 3
    while factor * factor <= target_number:
        while target_number % factor == 0:
            target_number //= factor
            factor_list.append(factor)
        factor += 2
    if target_number > 1:
        factor_list.append(target_number)
    return factor_list

N = int(input())

fact_list = factorize(N)

fact_counter_dict = collections.Counter(fact_list)
ans = 0
for fact, freq in fact_counter_dict.items():
    freq_copy = freq
    for i in range(1, freq + 1):
        freq_copy -= i
        if freq_copy < 0:
            break
        ans += 1
print(ans)

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

using ll = long long;

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

  vector<int> h(N);
  vector<int> cost(N+1);
  for(int i = 0; i<N; i++){
    cin >> h.at(i);
  }
  cost.at(1) = cost.at(0) +abs(h.at(0) - h.at(1));
  for(int i=2; i<N; i++){
    cost.at(i) = min(cost.at(i-1) + abs(h.at(i) - h.at(i-1)), cost.at(i-2) + abs(h.at(i) - h.at(i-2)));
  }
  cout << cost.at(N-1) << endl;

  return 0;

}

Measured memory_bytes: 4052
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iomanip>
#include <fstream>
#include <stdint.h>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
using namespace std;

constexpr int INF       = 1000000000;/* 1e+9a */
constexpr int MODULO    = 1000000007;

#define REP(i,f,n) for(int i=(f); i < (n); ++i)
#define PER(i,f,n) for(int i=(n-1); i >= f; --i)


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

int64_t gcd(int a, int b)
{
	return b == 0 ? a : gcd(b, a % b);
}

signed main()
{
    ios::sync_with_stdio(false);
	int64_t a, b;
	while(cin >> a)
	{
		cin >> b;
		int64_t gc = gcd(max(a,b),min(a,b));
		cout << gc << ' ' << a * b / gc << endl;
	}

}

Measured memory_bytes: 3108
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

class Myon{
    static void Main(string[] args){
        var myon = new Myon();
    }

    public Myon(){
        int[] time = new int[5];
        for(int i = 0;i < 5;i ++){
            time[i] = int.Parse(Console.ReadLine());
        }
        
        int[] amari = new int[5];
        for(int i = 0;i < 5;i ++){
            amari[i] = time[i]%10;
        }
        int timeProg = 0;
        int Min = 10;
        for(int i = 0;i < 5;i ++){
            if(amari[i] == 0){timeProg += time[i];continue;}
            else if(amari[i] < Min)Min = amari[i];
            timeProg += time[i] - amari[i] + 10;
        }
      
        timeProg -= 10 - Min;
        Console.WriteLine(timeProg);
    }
}

Measured memory_bytes: 13140
#include<iostream>
#include<stdio.h>
#include<string>
#include <algorithm>

using namespace std;

int main() {
	string str;

	cin >> str;

	// 長さを取得
	size_t size = str.length();

	string front = str.substr(0, size / 2);
	string back = str.substr(size / 2);
	reverse(back.begin(), back.end());

	int cnt = 0;
	for (int i = 0; i < size / 2; ++i){
		if (front[i] != back[i]) {
			cnt++;
		}
	}

	printf("%i\n", cnt);

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#define int long long
using namespace std;
const long long linf = (1LL<<60);
 
signed main() {
  int L, R; cin >> L >> R;
  if(R-L >= 2019) {
    cout << 0 << endl;
    return 0;
  }
  int ans = linf;
  for(int i = L; i <= R; ++i) {
    for(int j = i+1; j <= R; ++j) {
      ans = min(ans, i*j%2019);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
while gets do
  a, b, c, d, e, f = $_.split(/\s/).map(&:to_f)

  z = b*d - a*e
  x = (b*f - c*e)/z
  y = (c*d - a*f)/z

  x = 0.0 if x == 0
  y = 0.0 if y == 0

  puts sprintf("%.3f\s%.3f", x.round(3), y.round(3))
end

Measured memory_bytes: 6184
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N,D;
  cin >> N >> D;
  int w=2*D+1;
  if(N%w!=0)cout << N/w+1 << endl;
  else cout << N/w << endl;
  return 0;
    

}


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

int main() {
  int n;
  float v, cv = 0;
  vector<float> values;
  cin >> n;
  REP(i, n) {
    cin >> v;
    values.push_back(v);
  }
  sort(values.begin(), values.end());
  cv = values[0];
  for (int i = 1; i < n; i++) {
    cv = (cv + values[i]) / 2.0;
  }

  cout << cv << endl;
  return 0;
}

Measured memory_bytes: 256
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
import scala.io.StdIn._
object Main extends App {
  loop()
  @tailrec def loop(count: Int = 1): Unit = {
    val Array(n, w) = readLine.trim.split(' ').map(_.toInt)
    if (n == 0 && w == 0) return
    val memo = Array.fill(n){-1}
    val words = Array.tabulate(n){_ ⇒ readLine.trim.toInt}
    println(s"Case $count: ${solve(words, 0)(memo, w)}")
    loop(count + 1)
  }
  def solve(words: Array[Int], current: Int)(implicit memo: Array[Int], width: Int): Int = {
    if (current == words.length) 0
    else if (memo(current) >= 0) memo(current)
    else {
      var length = 0
      memo(current) = Int.MaxValue
      for (i ← current until words.length) {
        length += words(i)
        val temp = if (i != words.length - 1) solve(words, i + 1) + math.abs(width - length) else math.max(0, length - width)
        if (memo(current) > temp) memo(current) = temp
      }
      memo(current)
    }
  }
}


Measured memory_bytes: 54364
#include<iostream>
#include<fstream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<ctime>
#include<random>
#include<queue>
#include<algorithm>
#define ll long long
using namespace std;

int k,n;
int t[120000];
ll d[120000];
ll ans=0;
struct node
{
    ll d;
    int t,next;
};
node e[120000];
int loc[120000];
int top=1;
int maxIdx[120000];
priority_queue<ll> q1;
priority_queue<ll> q2;
ll s1[120000];
int t1;
int t2;
ll sum1[120000];
ll sum2[120000];
ll s2[120000];

bool cmp(ll a,ll b)
{
    return a>b;
}

int main()
{
    cin>>n>>k;
    for (int i=1; i<=n; ++i)
    {
        int t;
        ll d;
        scanf("%d %lld",&t,&d);

        e[top].t=t;
        e[top].d=d;
        e[top].next=loc[t];
        loc[t]=top;
        if (d>e[maxIdx[t]].d)
        {
            maxIdx[t]=top;
        }
        top++;
    }
    for (int i=1; i<top; ++i)
        if (i==maxIdx[e[i].t])
        {
            s1[t1++]=e[i].d;
        }else
        {
            s2[t2++]=e[i].d;
        }
    sort(s2,s2+t2,cmp);
    sort(s1,s1+t1,cmp);
    for (int i=0; i<t1; ++i)
    {
        s1[i]=s1[i]+2*i+1;
    }
    for (int i=1; i<=t1; ++i)
        sum1[i]=sum1[i-1]+s1[i-1];
    for (int i=1; i<=t2; ++i)
        sum2[i]=sum2[i-1]+s2[i-1];
   // for(int i=0; i<t1; ++i)
   // {
   //     cout<<s1[i]<<' ';
   // }
   // cout<<endl;
   // for(int i=0; i<t2; ++i)
   //     cout<<s2[i]<<' ';
   // cout<<endl;
    for (int i=0; i<=k; ++i)
    {
        if (i>=0 && k-i>=0)
            ans=max(ans,sum1[i]+sum2[k-i]);
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 5888
import sys
N = int(input())

L = []
for i in range(N):
  t,x,y = map(int,input().split())
  L.append([t,x,y])

t = 0
x = 0
y = 0
for i in range(N):
  dt = L[i][0]-t
  nx = L[i][1]
  ny = L[i][2]
  dif = abs(x-nx)+abs(ny-y)
  #print(dif,dt)
  if dif > dt or (dif-dt)%2 == 1:
    print("No")
    sys.exit()
  t += dt
  x = nx
  y = ny
print("Yes")

Measured memory_bytes: 19572
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#define max(a, b)	(((a) > (b)) ? (a) : (b))		/* ２個の値の最大値 */
#define min(a, b)	(((a) < (b)) ? (a) : (b))		/* ２個の値の最小値 */
#define ENTER		printf("\n")					/* 改行プリント */
/********************************************************************************************************************************/
/* main *************************************************************************************************************************/
/********************************************************************************************************************************/
int DEBUG = 0;										/* デバッグプリント 提出時は0 */

/* int型配列から最大値サーチ */
int max4x(int *a, int count) {
	int ret = *a;
	for (int i=0; i<count; i++) {
		if (*(a+i) > ret) ret = *(a+i);
	}
	return ret;
}

/* int型配列から最小値サーチ */
int min4x(int *a, int count) {
	int ret = *a;
	for (int i=0; i<count; i++) {
		if (*(a+i) < ret) ret = *(a+i);
	}
	return ret;
}

int main()
{
	int		n,i,j;
	long long ans=0;
	int		a[10000];

	scanf("%d", &n);
	for(i=0;i<n;i++) {
		scanf("%d", &a[i]);
		ans += a[i];
	}

	i = min4x(a,n);
	j = max4x(a,n);
	printf("%d %d %lld\n",i,j,ans);

	return 0;
}



Measured memory_bytes: 2108
a,b,c,d = map(int, input().split())
check = True
turn = 1
while check:
  if turn%2 != 0:
    c = c-b
    if c<=0:
      check = False
      print("Yes")
  else:
    a = a-d
    if a<=0:
      check = False
      print("No")
  turn = turn+1

Measured memory_bytes: 9144
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, C;
    cin >> A >> B >> C;
    cout << B + min(A + B + 1, C) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=3e5+7;
int s[maxn];
template<class T>
void read(T &res)
{
    res = 0;
    char c = getchar();
    T f = 1;
    while(c < '0' || c > '9')
    {
        if(c == '-') f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9')
    {
        res = res * 10 + c - '0';
        c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x)
{
    if(x < 0)
    {
        putchar('-');
        x = -x;
    }
    if(x >= 10)
    {
        out(x / 10);
    }
    putchar('0' + x % 10);
}
int n,k,num;
void init()
{
    for(int i=1;i<=k;i++) s[i]=(n+1)/2;
}
int main()
{

    read(n);
    read(k);
    if(n&1){
          init();
          num=k;
          for(int i=1;i<=k/2;i++){
            if(s[num]==1) num--;
            else{
                s[num]--;
                for(int j=num+1;j<=k;j++)
                    s[j]=n;
                num=k;
            }
          }
          for(int i=1;i<=num;i++){
            printf("%d ",s[i]);
          }
    }
    else{
        out(n/2);
        printf(" ");
        for(int i=2;i<=k;i++){
            printf("%d ",n);
        }

    }
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    int R[N],maxv = 0, min = 1000000000;
    int ans = -1000000000;

    for(int i = 0; i < N; i++){
        cin >> R[i];
         
        
        if(i != 0){
            ans = max(ans,R[i]-min);
        }
        if(R[i] < min){
            min = R[i];
        }
    
    }

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




Measured memory_bytes: 3880
N, M = map(int,input().split())
P=list(map(int,input().split()))

Group=[i for i in range(N+1)]


Swap=[None]*M
for i in range(M):
    Swap[i]=sorted(map(int,input().split()))

def find(x):
    while Group[x] != x:
        x=Group[x]
    return x

for i in range(M):
    if find(Swap[i][1]) != find(Swap[i][0]):
        Group[find(Swap[i][1])]=min(find(Swap[i][1]),find(Swap[i][0]))
        Group[find(Swap[i][0])]=min(find(Swap[i][1]),find(Swap[i][0]))
        Group[Swap[i][1]]=min(find(Swap[i][1]),find(Swap[i][0]))
        Group[Swap[i][1]]=min(find(Swap[i][1]),find(Swap[i][0]))

count=0

for i in range(N):
    if find(P[i])==find(i+1):
        count+=1


print(count)


Measured memory_bytes: 82156
#include <bits/stdc++.h>
#define int long long
#define range(i,x,y) i=(x);i<(y);i++
#define rep(i,n) for(int i=0,i##_len=n;i<i##_len;i++)
#define all(x) begin(x),end(x)
#define lim(x,r,l) (r<=x&&x<l)
typedef long long ll;
typedef long double ld;
using namespace std;

int c = -1;
string s;


/*
<eq> = <expr> '='
<expr> = <expr2> (('+'|'-') <expr2>)*
<expr2> = <expr3> (('*'|'/') <expr3>)*
<expr3> = <number> | '(' <expr> ')'
<number> = ['0' - '9']+
*/

char seek(){
  assert(c < s.size());
  return s[c];
}
char next(){
  assert(c < s.size());
  char res = s[c];
  c++;
  return res;
}
int number(){
  int res = 0;
  while(isdigit(seek())){
    res *= 10;
    res += next() - '0';
  }
 return res;
}
int expr();

int expr3(){
  char p = seek();
  if(p == '('){
    next();
    int res = expr();
    assert(next() == ')');
    return res;
  }
  return number();
}
int expr2(){
  int res = expr3();
  while(true){
    char op = seek();
    if(op == '*'){
      next();
      int other = expr3();
      res *= other;
    }else if(op == '/'){
      next();
      int other = expr3();
      res /= other;
    }else{
      return res;
    }
  }
}
int expr(){
  int res = expr2();
  while(true){
    char op = seek();
    if(op == '+'){
      next();
      int other = expr2();
      res += other;
    }else if(op == '-'){
      next();
      int other = expr2();
      res -= other;
    }else{
      return res;
    }
  }
}

int eq(){
  int e = expr();
  char eqa = next();
  assert(eqa == '=');
  return e;
}
int solve(string str){
  c = 0;
  s = str;
  return eq();
}
signed main(){
  int n; cin >> n;
  rep(i,n){
    string str; cin >> str;
    cout << solve(str) << endl;
  }
}

Measured memory_bytes: 3156
use proconio::input;

fn is_palindlome(s: Vec<char>) -> bool {
    let mut ret = true;
    for i in 0..s.len()/2 {
        if s[i] != s[s.len()-i-1] {
            ret = false;
            break;
        } else {
            continue;
        }
    }
    ret
}

fn main() {
    input! {
        s: String
    };
    let s: Vec<char> = s.chars().collect();
    println!("{}", 
     if is_palindlome(s[..s.len()/2].to_vec())
     && is_palindlome(s[(s.len()+1)/2..].to_vec())
     && is_palindlome(s) {"Yes"}
     else {"No"}
    );
}


Measured memory_bytes: 2192
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 60;

int helper(int i, int j, int h, int w, vector<string>& data) {
  vvl dist(h, vl(w, -1));
  dist[i][j] = 0;
  queue<pll> que;
  que.push({i, j});
  vector<int> di = {1, 0, -1, 0};
  vector<int> dj = {0, 1, 0, -1};
  while (!que.empty()) {
    auto p = que.front();
    que.pop();
    int ci = p.first, cj = p.second;
    rep(k, 4) {
      int ni = ci + di[k], nj = cj + dj[k];
      if (ni < 0 || h <= ni || nj < 0 || w <= nj) continue;
      if (data[ni][nj] == '#') continue;
      if (dist[ni][nj] == -1 || dist[ni][nj] > dist[ci][cj] + 1) {
        dist[ni][nj] = dist[ci][cj] + 1;
        que.push({ni, nj});
      }
    }
  }
  ll ret = 0;
  rep(ci, h) rep(cj, w) if (dist[ci][cj] >= 0) ret = max(ret, dist[ci][cj]);
  return ret;
}

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

  ll h, w;
  cin >> h >> w;
  vector<string> data(h);
  rep(i, h) cin >> data[i];

  int ans = 0;
  rep(i, h) {
    rep(j, w) {
      if (data[i][j] == '#') continue;
      ans = max(ans, helper(i, j, h, w, data));
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
k = []
s = []
for i in range(m):
    x = tuple(map(int,input().split()))
    k.append(x[0])
    s.append(x[1:])
p = list(map(int,input().split()))
ans = 0
for i in range(1<<n):
    flag = [0] * m
    for j,sj in enumerate(s):
        cnt = 0
        for l in sj:
            if i >> (l-1) & 1:
                cnt += 1
        if cnt % 2 == p[j]:
            flag[j] = 1
    if all(flag):
        ans+=1
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repA(i,a,n) for(int i=a;i<n;i++)
#define trav(a,x)for(auto &a: x)
#define fll(a) memset(a,-1,sizeof(a));
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define itr(it,x) for(auto it=x.begin();it!=x.end();it++)
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
typedef vector<int>vi;
typedef map<int,int>ma;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
void fopen()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);   
}
 
int main()
{
 // fopen();
  ll h,w;
  cin>>h>>w;
  if(h==1 || w==1)
  {
    cout<<1<<endl;
    return 0;
  }
  ll p=(h*w);
  ll q=p/2,r=p%2;
  cout<<q+r;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main(){
  int n;
  cin >> n;
  int ans;
  rep(i,n){
    ans +=  i+1;}
  cout << ans << endl;
  return 0;
}

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

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

  map<string, int> cnt;

  for (int i = 0; i < N; i++) {
    string a;
    cin >> a;
    cnt[a]++;
  }

  int m = 0;
  for (auto itr = cnt.begin(); itr != cnt.end(); ++itr) {
    m = max(m, itr->second);
  }
  for (auto itr = cnt.begin(); itr != cnt.end(); ++itr) {
    if (itr->second == m) {
      cout << itr->first << endl;
    }
  }
}


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

using namespace std;

int main() {
    while (true) {
        int n, m;
        cin >> n >> m;
        if (n == 0 && m == 0) return 0;
        vector<int> vec[n];
        vector<bool> fri(n);
        for (int i = 0; i < m; ++i) {
            int a, b;
            cin >> a >> b;
            --a;
            --b;
            vec[a].push_back(b);
            vec[b].push_back(a);
        }
        for (int s : vec[0]) {
            fri[s] = true;
            for (int t : vec[s]) {
                fri[t] = true;
            }
        }
        int ans = 0;
        for (int i = 1; i < n; ++i) {
            if (fri[i]) ++ans;
        }
        cout << ans << '\n';
    }
}


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

using namespace std;

typedef long long int LL;
typedef LL ll;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef stringstream strs;

#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define ER(a) cout << #a << ' ' << a << endl
#define LB(a,n,x) (lower_bound(a,(a)+(n),x)-(a))

const ll M=3e5+5,LG=26,SM=600,inf=1e9+1;
ll mod=95542721;

ll n,x;

ll calc(ll a,ll b)
{
    if (a<b) return calc(b,a);
    if (a%b==0)
    {
        return 2*a-b;
    }  
    return 2*(a/b)*b+calc(b,a%b);
}

int main()
{
	ios::sync_with_stdio(0);
    cin >> n >> x;
    cout << calc(x,n-x)+n;	
}

Measured memory_bytes: 256
from itertools import combinations as comb

N, K = map(int, input().split())
a = list(map(int, input().split()))
ans = 10**17

for i in comb([n for n in range(1, N)], K-1):
    tmpa = a[:]
    tmp = 0
    for j in range(K-1):
        pre = max(tmpa[:i[j]])
        if tmpa[i[j]] <= pre:
            tmp += pre+1-tmpa[i[j]]
            tmpa[i[j]] = pre+1
    
    if tmp < ans:
        ans = tmp

print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
    int a,b,c;
    int d=0;
    scanf("%d%d%d",&a,&b,&c);
    for (a;a<=b;a++){
        if (c%a==0){
                d++;

        }

    }
    printf("%d\n",d);
    return 0;
}



Measured memory_bytes: 2120
import java.util.Scanner;

//6/1コンテスト

public class Main {
	public static void main(String[]args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String[] fruit = a.split("");
		int win=0;
		int lose=0;

		for(int i= 0;fruit.length>i;i++) {
			if (fruit[i].equals("o")) {
				win++;
			}
			else if (fruit[i].equals("x")) {
				lose++;
			}
		}

		if(win>=8)
			System.out.println("YES");
		else if (lose>=8)
			System.out.println("NO");
		else
			System.out.println("YES");
	}

}


Measured memory_bytes: 22996
#include <stdio.h>

int main(void){
  int i,x;
  for(i=1;i<=10000;i++){
      scanf("%d",&x);
      if(x==0){
          i=10000;
      }else{
          printf("Case %d: %d\n",i,x);
      }
  }
  return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<int>H(n);
	for (int i = 1;i <= n;++i) {
		cin >> H[i];
	}
	int max = 0;
	int ans = 0;
	for (int i = 1;i <= n;++i) {
		if (max <= H[i]) {
			ans++;
			max = H[i];
		}
	}
	cout << ans << endl;
}


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

int  main()
{
	int H,W; cin >> H >> W;
	int h,w; cin >> h >> w;
	int t = (H-h) * (W-w);
	cout << t << endl;
	return (0);
}

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

int main(){
  ll A,B,K;
  cin >> A >> B >> K;
  rep(i,K){
    if(i%2==0){
      if(A%2==1) A--;
      A/=2;
      B+=A;
    }
    else{
      if(B%2==1) B--;
      B/=2;
      A+=B;
    }
  }
  cout << A << " " << B;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;

#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////

#define N 10
ll n;
ll a[N][N];
ll w[N];
ll l[N];
ll ans=0;
void init(){
    memset(a,0,sizeof(a));
    memset(w,0,sizeof(w));
    memset(l,0,sizeof(l));
    ans=0;
}
#define win 1
#define lose 2

bool dfs(ll p){
    if(p==n*n){
        bool flag=true;
        rep(i,0,n-1){
            if(w[i]*2+1!=n)flag=false;
            if(l[i]*2+1!=n)flag=false;
        }
        if(flag)ans++;
        return 0;
    }
    ll x=p/n,y=p%n;
    if(x==y||a[x][y]!=0){
        dfs(p+1);return 0;
    }
    if(w[x]*2+1<n&&l[y]*2+1<n){
        w[x]++;
        l[y]++;
        a[x][y]=1;
        a[y][x]=2;
        dfs(p+1);
        w[x]--;
        l[y]--;
        a[y][x]=a[x][y]=0;
    }
    if(l[x]*2+1<n&&w[y]*2+1<n){
        w[y]++;
        l[x]++;
        a[x][y]=2;
        a[y][x]=1;
        dfs(p+1);
        w[y]--;
        l[x]--;
        a[x][y]=a[y][x]=0;
    }
    
    return 0;
}

int main(){fastio
    while(1){
        cin>>n;
        if(n==0)return 0;
        init();
        ll m;cin>>m;
        while(m--){
            ll x,y;cin>>x>>y;
            x--;y--;
            a[x][y]=win;
            a[y][x]=lose;
            w[x]++;
            l[y]++;
        }
        dfs(0);
        cout<<ans<<endl;
    }
    return 0;
}



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

typedef long long ll;

int main()
{
    int K;
    int A, B;
    cin >> K >> A >> B;
    for (int i = A; i <= B; ++i)
    {
        if (i % K == 0)
        {
            cout << "OK" << endl;
            return 0;
        }
    }

    cout << "NG" << endl;
}


Measured memory_bytes: 3640
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int trainA = sc.nextInt();
    int trainB = sc.nextInt();
    int busA = sc.nextInt();
    int busB = sc.nextInt();
    System.out.println(Math.min(trainA, trainB) + Math.min(busA, busB));
  }
}

Measured memory_bytes: 22100
#include <stdio.h>
int main(void){
	int m, f, r;
	while(1){
		scanf("%d %d %d", &m, &f, &r);
		if(m == -1 && f == -1 && r == -1)break;
		else if(m == -1 || f == -1 || m+f < 30){
			printf("F\n");
		}else if(m+f >= 30 && m+f < 50 && r < 50){
			printf("D\n");
		}else if(m+f >= 30 && m+f < 50 && r >= 50){
			printf("C\n");
		}else if(m+f >= 50 && m+f < 65){
			printf("C\n");
		}else if(m+f >= 65 && m+f < 80){
			printf("B\n");
		}else{
			printf("A\n");
		}
	}
	
	return 0;
}

Measured memory_bytes: 584
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
ll n,a,b;
cin>>n>>a>>b;
ll sum=n/(a+b)*a;
cout<<sum+min(a,n%(a+b))<<endl;
}


Measured memory_bytes: 256
"""
Sの文字列、最初が何かに依存しそう
"""


S = input()
K = int(input())

if S[0] == "1":
    len_one = 0
    flag = 0
    for s in S:
        if s == "1" and flag == 0:
            len_one += 1
        elif flag == 0:
            save_num = s
            flag = 1
        else:
            flag = 1
    if K <= len_one:
        ans = 1
    else:
        ans = int(save_num)

else:
    ans = int(S[0])

print(ans)

Measured memory_bytes: 3064