akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i )
typedef std::pair<int,int> pint;

using namespace std;
typedef long long ll;

int main(){
    int N; cin >> N;
    string str; cin >> str;
    int length = str.length();
    int red_count = 0;
    int white_count = 0;
    int ans;
    rep (i,length){
        if (str[i] == 'R'){
            red_count++;
        }
    }
    rep (i,red_count){
        if (str[i] == 'W'){
            white_count++;
        }
    }
    ans = min(red_count,white_count);
    cout << ans << endl;
}

Measured memory_bytes: 3676
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define il inline
#define outy printf("Yes\n")
#define outn printf("No\n")
#define outf printf("First\n")
#define outs printf("Second\n")
#define FOR(a,b,c) for(int a=b;a<=c;a++)
#define FORD(a,b,c) for(int a=b;a>=c;a--)
#define FORL(a,b) for(int a=head[b];a;a=nxt[a])
#define in(a)  a=read()
#define in2(a,b)  a=read(),b=read()
#define in3(a,b,c)  a=read(),b=read(),c=read()
#define in4(a,b,c,d)  a=read(),b=read(),c=read(),d=read()
#define inl(a)  a=readl()
#define inl2(a,b)  a=readl(),b=readl()
#define inl3(a,b,c)  a=readl(),b=readl(),c=readl()
#define inl4(a,b,c,d)  a=readl(),b=readl(),c=readl(),d=readl()
#define out(a) printf("%d\n",a)
#define out2(a,b) printf("%d %d\n",a,b)
#define out3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out4(a,b,c,d) printf("%d %d %d %d\n",a,b,c,d)
#define outl(a) printf("%lld\n",a)
#define outl2(a,b) printf("%lld %lld\n",a,b)
#define outl3(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define outl4(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define clr(x,y) memset(x,y,sizeof(x))
inline int read(){
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
inline ll readl(){
    char c;ll s=0;int t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
/*------------------------------------------------------------*/
#define mod 1000000007
#define maxn 100010
#define inf 0x7fffffff
/*------------------------------------------------------------*/
int n,m;
int main(){
	char a[100];
	in2(n,m);
	int k=0,f=0;
	scanf("%s",a+1);
	FOR(i,1,n+m+1){
		if(a[i]=='-'){
			k++;
			if(!f)f=i-1;
		}
	}
	if(k==1&&f==n)outy;
	 else outn;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;
using ll = long long;

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<ll> a(n);
	for(int i = 0; i < n; ++i){
		cin >> a[i];
		a[i] *= n;
	}
	const ll sum = accumulate(a.begin(), a.end(), 0ll);
	const ll avg = sum / n;
	ll min_diff = llabs(avg - a[0]), answer = 0;
	for(int i = 1; i < n; ++i){
		const ll d = llabs(avg - a[i]);
		if(d < min_diff){
			min_diff = d;
			answer = i;
		}
	}
	cout << answer << endl;
	return 0;
}



Measured memory_bytes: 256
number = int(input())
l = number % 10
if ((l == 2) or (l == 4) or (l == 5) or (l == 7) or (l == 9)):
  print('hon')
elif ((l == 0) or (l == 1) or (l == 6) or (l == 8)):
  print('pon')
else:
  print('bon')

Measured memory_bytes: 9128
#![allow(non_snake_case)]

fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn read_vec() -> Vec<f64> {
    read_line()
        .split_whitespace()
        .map(|e| e.parse().unwrap())
        .collect()
}

fn main() {
    let N: i32 = read_line().parse().unwrap();
    let A: Vec<f64> = read_vec();
    let mut ans = 0.0;
    for a in A {
        ans += 1.0 / a;
    }
    println!("{}", 1.0 / ans);
}


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

int main() {
  int n;
  cin >> n;
  vector<int> w(n);
  for (auto idx(0); idx < n; ++idx) {
    cin >> w[idx];
  }
  auto total(0);
  for (auto idx(0); idx < n; ++idx) {
    total += w[idx];
  }
  auto subtotal(0);
  auto min_diff(100000);
  for (auto idx(0); idx < n; ++idx) {
    subtotal += w[idx];
    if (abs(total - 2*subtotal) < min_diff) {
      min_diff = abs(total - 2*subtotal);
    }
  }
  cout << min_diff<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;
  
int main()
{
  ll N, M;
  cin >> N >> M;
  vector<ll> H(N);
  REP(i, N) cin >> H[i];
  vector<P> A(M);
  REP(i,M) cin >> A[i].first >> A[i].second;
  
  set<ll> B;
  set<ll> C;
  set<ll> D;
  REP(i,M){
    C.insert(A.at(i).first);
    C.insert(A.at(i).second);
    if(H.at(A.at(i).first-1)>H.at(A.at(i).second-1)){
      if(D.count(A.at(i).first)==0){
        B.insert(A.at(i).first);
      }
      B.erase(A.at(i).second);
      D.insert(A.at(i).second);
    }else if(H.at(A.at(i).first-1)<H.at(A.at(i).second-1)){
      if(D.count(A.at(i).second)==0){
        B.insert(A.at(i).second);
      }
      B.erase(A.at(i).first);
      D.insert(A.at(i).first);
    }else if(H.at(A.at(i).first-1)==H.at(A.at(i).second-1)){
      B.erase(A.at(i).second);
      B.erase(A.at(i).first);
      D.insert(A.at(i).first);
      D.insert(A.at(i).second);
    }
  }

  ll cnt=0;
  FOR(i,1,N+1){
    if(C.count(i)==0){
      cnt++;
    }else if(B.count(i)==1){
      cnt++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 13032
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
	string S, T;
	int A, B;
	string U;
	cin >> S >> T;
	cin >> A >> B;
	cin >> U;

	if (U == S) {
		A--;
	}
	else
		B--;
	cout << A <<" " << B << endl;
	
	
}


Measured memory_bytes: 256
//
// Created by yuu on 2019-04-18.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>
#define INF (1LL<<60)

using namespace std;


int main(void){
    int N,K;

    cin>>N>>K;

    int H[100110];
    for (int i = 0; i < N; ++i) {
        cin>>H[i];
    }
    vector <long long>dp(100110, INF);

    dp[0] = 0;

    for (int j = 0; j < N; ++j) {
        for (int i = 1; i <= K; ++i) {
            dp[j+i] = min(dp[j+i], (dp[j] + abs(H[j+i] - H[j])));
        }
    }

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

Measured memory_bytes: 1408
#include<stdio.h>
int main()
{
	int i,a,w1=0,w2=0,w3=0,k1=0,k2=0,k3=0;
	for(i=0;i<10;i++){
		scanf("%d",&a);
		if(w3<a){
			w3=a;
			if(w2<a){
				w3=w2;
				w2=a;
				if(w1<a){
					w2=w1;
					w1=a;
				}
			}
		}
	}
	for(i=0;i<10;i++){
		scanf("%d",&a);
		if(k3<a){
			k3=a;
			if(k2<a){
				k3=k2;
				k2=a;
				if(k1<a){
					k2=k1;
					k1=a;
				}
			}
		}
	}
	printf("%d %d\n",w1+w2+w3,k1+k2+k3);
	return 0;
}

Measured memory_bytes: 2760
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
 
int main() {
    int n;
    cin >> n;
    vector<int> w(n);
    rep(i,n) cin >> w.at(i);
    int ans=50000;
    rep(i,n+1){
        int s1=0;
        int s2=0;
        rep(j,n){
            if(j<=i)s1+=w.at(j);
            else s2+=w.at(j);
        }        
        ans=min(ans,abs(s2-s1));
    }
    cout << ans << endl;
}

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

#define F first
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 55, M = 1010;

int n, m;
int x[N], y[N];

int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i ++ ) cin >> x[i] >> y[i];
	
	LL res = 4e18;
	for (int a = 0; a < n; a ++ )
		for (int b = 0; b < n; b ++ )
			for (int c = 0; c < n; c ++ )
				for (int d = 0; d < n; d ++ )
				{
					if (x[a] <= x[b] || y[c] <= y[d]) continue;
					
					int cnt = 0;
					for (int i = 0; i < n; i ++ )
						if (x[i] <= x[a] && x[i] >= x[b] && y[i] <= y[c] && y[i] >= y[d])
							cnt ++ ;
					
					if (cnt < m) continue;
					
					LL area = (LL)(y[c] - y[d]) * (x[a] - x[b]);
					res = min(res, area);
				}
					
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
import queue

h, w = map(int, input().split())
maze = [list(input()) for _ in range(h)]
# print(maze)

def bfs(dist, i, j):
    q = queue.Queue()
    q.put((i, j, 0))
    while not q.empty():
        i, j, c = q.get()
        # print(i, j, c, dist)
        if i != 0 and dist[i-1][j] == 0:
            dist[i-1][j] = c+1
            q.put((i-1, j, c+1))
        if j != 0 and dist[i][j-1] == 0:
            dist[i][j-1] = c+1
            q.put((i, j-1, c+1))
        if i != h-1 and dist[i+1][j] == 0:
            dist[i+1][j] = c+1
            q.put((i+1, j, c+1))
        if j != w-1 and dist[i][j+1] == 0:
            dist[i][j+1] = c+1
            q.put((i, j+1, c+1))
    return dist, c

ans = 0
for i in range(h):
    for j in range(w):
        if maze[i][j] == '.':
            dist = [[(maze[y][x] == '#')*-1 for x in range(w)] for y in range(h)]
            dist[i][j] = -10
            dist, c = bfs(dist, i, j)
            tmp_ans = c
            if tmp_ans > ans:
                ans = tmp_ans

print(ans)


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

using namespace std;
typedef long long ll;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;

int main() {
  int A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;
  ll ans = 0;
  if (A + B > 2 * C) {
    ans += min(X, Y) * 2 * C;
  } else {
    ans += A * min(X, Y);
    ans += B * min(X, Y);
  }

  if(X > Y) {
    if (A > 2 * C) {
      ans += (X - Y) * 2 * C;
    } else {
      ans += A * (X - Y);
    }
  } else if (X < Y) {
    if (B > 2 * C) {
      ans += (Y - X) * 2 * C;
    } else {
      ans += B * (Y - X);
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

using ll=long long;


int main(void)
{
	ll a, b, c;

	while(scanf("%lld%lld%lld", &a, &b, &c)==3)
	{
		ll ans=b;

		ans+=min(c, a+b+1);

		printf("%lld\n", ans);
	}

	return 0;
}


Measured memory_bytes: 128
s = gets.strip.split("")
num = s.length/2
count = 2
i = 1
ans = []
(num-1).times do
  if (s[0..(num-count)].join + s[0..(num-count)].join) == s[0..(s.length-count-i)].join
    ans << num-count
  end
  count+=1
  i += 1
end
puts (ans.max+1)*2

Measured memory_bytes: 3836
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll GCD(ll a, ll b){ return a ? GCD(b % a, a) : b; }
int main(){
    int n;
    cin>>n;
    map<ll,int> d;
    for(int i=0; i<n; i++){
        ll D;
        cin>>D;
        d[D]++;
    }
    int m;
    cin>>m;
    bool ok=true;
    for(int i=0; i<m; i++){
        ll t;
        cin>>t;
        if(d[t]==0) ok=false;
        else d[t]--;
    }
    cout<<(ok?"YES":"NO")<<endl;

}

Measured memory_bytes: 12800
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> tiii;


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };
const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 7;



int main() {

	
	int a, b;
	cin >> a >> b;
	cout << (3 * a + b) / 2 << endl;



	return 0;

}


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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using P = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

struct UnionFind {
  vector<int> parent; // parentの番号。親だった場合は-(その集合のサイズ)
  // parentはすべて-1にする。全てバラバラになる
  UnionFind(int n) { parent = vector<int>(n, -1); }
  // aがどのグループに属しているかを調べる
  int root(int a) {
    if (parent[a] < 0) return a;
    return (parent[a] = root(parent[a]));
  }
  // 自分のいるグループの頂点数を調べる
  int size(int a) { return -parent[root(a)]; }
  // aとbをくっつける
  int connect(int a, int b) {
    // aとbを直接つなぐのではなくroot(a)とroot(b)をくっつける
    a = root(a);
    b = root(b);
    if (a == b) return false; // すでにくっついている
    // 大きい方(a)を小さい方(b)にくっつけたいので大小が逆だったらひっくり返す
    if (size(a) < size(b)) swap(a, b);
    parent[a] += parent[b]; // aのサイズを更新する
    parent[b] = a;          // bの親をAに変更する
    return true;
  }
};

void solve() {
  int n, m;
  cin >> n >> m;
  UnionFind uni(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    uni.connect(a, b);
  }
  int ans = 0;
  rep(i, n) maxs(ans, uni.size(i));
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 3984
import java.util.Scanner;

// D - Knapsack 1
// https://atcoder.jp/contests/dp/tasks/dp_d
// #DP #ナップサック
public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = Integer.parseInt(scanner.next());
        int W = Integer.parseInt(scanner.next());

        int[][] wv = new int[N][2];
        for (int i = 0; i < N; i++) {
            wv[i][0] = Integer.parseInt(scanner.next());
            wv[i][1] = Integer.parseInt(scanner.next());
        }

        scanner.nextLine();

        // dp[i][sum_w]: i-1番目までの品目から重さが sum_w
        // を超えないように選んだ際の価値の総和の最大値
        long[][] dp = new long[N + 1][W + 1];

        for (int i = 0; i < N; i++) { // 品目
            for (int sumW = 0; sumW <= W; sumW++) { // 重さ
                if (sumW >= wv[i][0]) {
                    // 選ぶ場合
                    dp[i + 1][sumW] = Math.max(dp[i][sumW], dp[i][sumW - wv[i][0]] + wv[i][1]);
                } else {
                    // 選ばない場合
                    dp[i + 1][sumW] = dp[i][sumW];
                }
            }
        }

        System.out.println(dp[N][W]);
    }
}

Measured memory_bytes: 128980
#include <stdio.h>
#include <math.h>
int getDigit(int n){
    int digit=1;
    while(n!=0){
        n/=10;
        digit*=10;
    }
    return digit;
}
int main(void){
    int a, b;
    scanf("%d %d", &a, &b);
    int num=a*getDigit(b)+b;
    
    if((int)sqrt(num)*(int)sqrt(num)==num)printf("Yes\n");
    else printf("No\n");
    
    return 0;
}


Measured memory_bytes: 2088
count={}
for i in range(97,97+26):
    count[chr(i)] = 0

text=[]
while True:
    try:
        text.append(input())
    except EOFError:
        break

text_out="".join(text)
text_lower=text_out.lower()

for letter in text_lower:
    if letter in count:
        count[letter] += 1

for x,y in sorted(count.items()):
    print("{0} : {1}".format(x,y))

Measured memory_bytes: 7428
#include <stdio.h>

int main(){
  int x,y;

  while(1){
    scanf("%d %d",&x,&y);
    if(x==0&&y==0)
      break;

    if(x>y)
      printf("%d %d\n",y,x);
    else
      printf("%d %d\n",x,y);
  }

  return 0;
}

Measured memory_bytes: 596
n = int(input())
AC  = 0
WA = 0 
TLE = 0
RE = 0
for _ in range(n):
    key = input()
    if key == 'AC':
        AC += 1
    elif key == 'RE':
        RE += 1
    elif key == 'WA':
        WA += 1
    else:
        TLE += 1
print('AC x',AC)
print('WA x',WA)
print('TLE x',TLE)
print('RE x',RE)
    

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

int main()
{
	int n;
	int l[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	cin >> n;
	
	cout << l[n-1];
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,n;
string b[105];
int main()
{
    cin>>a>>n;
    for(int s=0;s<a;s++)
    {
        cin>>b[s];
    }
    sort(b,b+a);
    for(int s=0;s<a;s++)
    cout<<b[s];
    cout<<endl;
}

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

long long int T, x, meven = 0, modd = 0;
long long int seceven = 0, secodd = 0, valme = -1, valmo = -1, valse = -1, valso = -1;
map<long long int, long long int> even, odd; 

int main(){
	cin >> T;
	even.clear();
	odd.clear();
	for(int i = 0; i < T; i++){
		cin >> x;
		if(i % 2){
			if(odd.count(x)){
				odd[x]++;
			} else {
				odd.insert({x, 1});
			}
			if(odd[x] < modd && odd[x] >= secodd){
				secodd = odd[x];
				valso = x;
			} else if(modd <= odd[x]){
				if(valmo != x){
					secodd = modd;
					valso = valmo;
				}
				modd = odd[x];
				valmo = x;
			}
			
		} else {
			if(even.count(x)){
				even[x]++;
			} else {
				even.insert({x, 1});
			}
			if(even[x] < meven && even[x] >= seceven){
				seceven = even[x];
				valse = x;
			} else if(meven <= even[x]){
				if(valme != x){
					seceven = meven;
					valse = valme;
				}
				meven = even[x];
				valme = x;
			}
		}
	}
	
	//cout << "First even: " << meven << ", second even: " << seceven << endl;
	//cout << "First odd: " << modd << ", second odd: " << secodd << endl;
	if(valme == valmo){
		cout << T - max(meven + secodd, modd + seceven) << endl;
		return 0;
	} 
	cout << T - modd - meven << endl;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int N; cin >> N;
	vector<int> a(3 * N, 0);
	rep (i, 3 * N){
		cin >> a[i];
	} // end rep

	sort(ALL(a),greater<int>());

	ll res = 0LL;
	for (int i = 1, j = 0; j < N; i += 2, ++j){
		res += (ll)a[i];
	} // end for

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 100009 /// Still trying to be normal
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e9 + 15;
ll n,m,q;
vector<pair<pii,pii>> qd;
ll solve(ll id,vector<int> ar){
    // cout<<id<<endl;
    if(id==n){
        ll res=0;
        rep(i,0,sz(qd)){
            if(ar[qd[i].F.S-1]-ar[qd[i].F.F-1]==qd[i].S.F)res+=qd[i].S.S;
        }
        return res;
    }
    else{
        ll res=0;
        int ult=1;
        if(id>0)ult=ar[sz(ar)-1];
        rep(i,ult,m+1){
            // cout<<"oi"<<endl;
            ar.push_back(i);
            res=max(res,solve(id+1,ar));
            ar.pop_back();
        }
        return res;
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m>>q;
    ll ans=0;
    rep(i,0,q){
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
        qd.push_back({{a,b},{c,d}});
    }
    vector<int> ar2;
    cout<<solve(0,ar2)<<'\n';
    return 0;   
}

Measured memory_bytes: 3672
class UnionFind():
    def __init__(self,n):
        self.n=n
        self.parents=[-1]*n
    def find(self,x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]
    def unite(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x==y:
            return
        if self.parents[x]>self.parents[y]:
            x,y=y,x
        self.parents[x]+=self.parents[y]
        self.parents[y]=x
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i)==root]
    def roots(self):
        return [i for i,x in enumerate(self.parents) if x<0]
    def group_count(self):
        return len(self.roots())
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
n,m,k=map(int,input().split())
uf=UnionFind(n+1)
cnt=[0]*(n+1)
for i in range(m):
  a,b=map(int,input().split())
  uf.unite(a,b)
  cnt[a]+=1
  cnt[b]+=1
for i in range(k):
  c,d=map(int,input().split())
  if uf.same(c,d):
    cnt[c]+=1
    cnt[d]+=1
ans=[]
for i in range(1,n+1):
  ans.append(uf.size(i)-cnt[i]-1)
print(*ans)

Measured memory_bytes: 99928
#!/usr/bin/env python

from collections import deque, defaultdict
import itertools as ite
import sys
import math
import decimal

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N = input()
ans = 0
if N % 2 == 0:
    N /= 2
    while N > 0:
        N /= 5
        ans += N
print ans


Measured memory_bytes: 4268
n = int(input())
a = list(input())
b = list(input())
c = list(input())

res = 0
for i in range(0, n):
    if a[i] == b[i] == c[i]:
        res += 0
    elif a[i] == b[i] or a[i] == c[i] or b[i] == c[i]:
        res += 1
    else:
        res += 2

print(res)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
 ll dp[N][150];

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

  int n,s;
  cin>>n>>s;
  pair<ll,ll> arr[150];
  for(int i=0;i<n;i++){
    cin>>arr[i].second>>arr[i].first;
  }
for(int cap=0;cap<=s;cap++){
    for(int i=0;i<n;i++){
      dp[cap][i]=-1;
    }

  }
   for(int i=0;i<n;i++){
      dp[0][i]=0;
    }
  dp[0][0]=0;
  if(s>=arr[0].second)
    dp[arr[0].second][0]=arr[0].first;
    ll maxi=dp[arr[0].second][0];
for(int cap=0;cap<=s;cap++){

    for(int i=1;i<n;i++){
        ll op1=-1,op2=-1;
        ll price=arr[i].first;
        ll c=arr[i].second;

        //take it
        if(cap-c>=0&&dp[cap-c][i-1]!=-1){
              op1=dp[cap-c][i-1]+price;
             // cout<<cap-c<<' '<<i-1<<' '<<dp[cap-c][i-1]<<endl;;
        }

        //leave it

        op2=dp[cap][i-1];
        dp[cap][i]=max(op1,op2);
        maxi=max(dp[cap][i],maxi);
    }
  }
  cout<<maxi;

    return 0;
}


Measured memory_bytes: 117504
n=int(input())
a=list(map(int,input().split()))
result = False

a_unique = list(set(a))

if n == 3:
    if a_unique[0]^a_unique[1] == a_unique[2]:
        result = True
    
elif len(a_unique) == 3:
    if a_unique[0]^a_unique[1] == a_unique[2]: 
        if a.count(a_unique[0]) == a.count(a_unique[1]) and a.count(a_unique[1]) == a.count(a_unique[2]):
            result = True

elif len(a_unique) == 1:
    if a_unique[0]^a_unique[0] == a_unique[0]:
        result = True

elif len(a_unique) == 2:
    if a_unique.count(a_unique[0]) == 1:
        if a_unique[0]^a_unique[1] == a_unique[1]:
            if a_unique[1]^a_unique[1] == a_unique[0]:
                if a.count(a_unique[0])*2 == a.count(a_unique[1]):
                    result = True
    elif  a_unique.count(a_unique[1]) == 1:
        if a_unique[0]^a_unique[1] == a_unique[0]:
            if a_unique[0]^a_unique[0] == a_unique[1]:
                if a.count(a_unique[1])*2 == a.count(a_unique[0]):
                    result = True

if len(a_unique) > 3:
    result = False    
            
if result:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14228
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(){
    string s;
    cin>>s;
    ll flag=0;
    if(s[0]=='A'){
        flag++;
    }
    string t=s.substr(2, s.size()-3);
    ll x=0;
    for(ll i=0;i<t.size();++i){
        if(t[i]=='C'){
            x++;
        }
    }
    if(x==1){
        flag++;
    }
    ll y=0;
    for(ll i=0;i<s.size();++i){
        if(isupper(s[i])){
            y++;
        }
    }
    if(y==2){
        flag++;
    }
    if(flag==3){
        cout<<"AC"<<endl;
        return 0;
    }else{
        cout<<"WA"<<endl;
        return 0;
    }
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

N = input()

#print(N[-1])
if int(N[-1]) == 3:
    print("bon")
elif int(N[-1]) == 0 or int(N[-1]) == 1 or int(N[-1]) == 6 or int(N[-1]) == 8:
    print("pon")
else:
    print("hon")
    

Measured memory_bytes: 9172
#include <iostream>

using namespace std;

int main(){
	int w, a, b;
	cin >> w >> a >> b;
	if(a < b){
		cout << ((b - (a + w)) < 0 ? 0 : b - a - w) << endl; 
	}
	else
		cout << ((a - (b + w)) < 0 ? 0 : a - b - w) << endl;
	
	return 0;
}


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

using ll = long long;

struct Mod
{
    static const auto P = int(1e9+7);
    ll k;
    Mod(const ll k) : k(k%P >= 0 ? k%P : k%P + P) {}
};

Mod operator+(const Mod a, const Mod b) { return a.k + b.k; }
Mod operator-(const Mod a, const Mod b) { return a.k - b.k + Mod::P; }
Mod operator*(const Mod a, const Mod b) { return a.k * b.k; }
Mod& operator+=(Mod &a, const Mod b) { return a = a+b; }

int main()
{
    int n, m; cin >> n >> m;

    auto xs = vector<ll>(n);
    for (auto& x : xs) cin >> x;

    auto ys = vector<ll>(m);
    for (auto& y : ys) cin >> y;

    const auto f = [](const vector<ll>& xs)
    {
        auto result = Mod(0);
        auto sum = Mod(0);
        auto seen = 0;
        for (const auto x : xs)
        {
            result += seen*x - sum;
            sum += x;
            seen++;
        }
        return result;
    };

    cout << (f(xs) * f(ys)).k << endl;
}


Measured memory_bytes: 1792
while line = STDIN.gets

	len = line.length

	while !(line =~ /((the)|(this)|(that))/)
	
		for i in 0..len-1 do
			if( line[i,1] =~ /[a-z]/)
				if(line[i,1] =~ /z/)
					line[i] = "a"
				else
					line[i] = line[i].succ
				end
			end
		end
	end
	
	puts line
	
end

Measured memory_bytes: 2600
#include <iostream>
using namespace std;
const int MAX_N = 110;
int i, j, k, v, a[MAX_N], n;
void insertionSort(int A[MAX_N], int N) { // N??????????´??????????0-?????????????????????A
	for (i = 0; i < N-1; ++i) {
		cout << A[i] << " ";
	}
	if(i<N-1)cout<<A[N-1]<<endl;
	if(i==N-1)cout<<A[N-1]<<endl;
	for (i = 1; i < N; i++) {

		v = A[i];
		j = i - 1;
		while (j >= 0 && A[j] > v) {
			A[j + 1] = A[j];
			j--;
			A[j + 1] = v;
		}
		for (k = 0; k < N-1; ++k) {
				cout << A[k] << " ";
		}
		if(i<N-1)cout<<A[N-1]<<endl;
		if(i==N-1)cout<<A[N-1]<<endl;
	}


}

int main() {
	cin >> n;
	for (i = 0; i < n; ++i) {
		cin >> a[i];
	}
	insertionSort(a, n);
	return 0;
}

Measured memory_bytes: 3108
def ceil_div(a, b):
    return (a + b - 1) // b

N = int(input())
t, a = 1, 1
for _ in range(N):
    T, A = map(int, input().split())
    # find the smallest integer k such that
    # t <= k * T and a <= k * A
    k = max(ceil_div(t, T), ceil_div(a, A))
    t = k * T
    a = k * A
print(t + a)

Measured memory_bytes: 3060
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<int> > mat;

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  int ans = 1;
  for (int i = 1; i < n; i++)
  {
    if (a[i] != a[i - 1])
    {
      ans++;
    }
  }
  cout << ((ans + 1) / 2) * 2 - 1 << "\n";
}

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

std::string check(int x, int y)
{
    if(y % 2 == 0)
    {
        int t = (int)(0.5*y) - x;
        if(t >= 0 && (x-t) >= 0)
            return "Yes";
    }
    return "No";
}

int main()
{
    int x, y;
    std::cin >> x >> y;

    std::cout << check(x, y) << std::endl;
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<long long> l(n);
    for (int i = 0; i < n; i++) {
        cin >> l[i];
    }

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

    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (l[i] == l[j]) continue;
            for (int k = j + 1; k < n; k++) {
                if (l[j] == l[k]) continue;
                if (l[i] + l[j] > l[k]) ans++;
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for (int i = 0; i < n; ++i)
#define REP(i,k,n) for (int i = k; i <= n; ++i)
#define REPR(i,k,n) for (int i = k; i >= n; --i)
#define pb push_back
#define F first
#define S second
#define I insert
#define sz(a) (int)((a).size())
#define all(a) (a).begin(), (a).end()
#define debug1(a) cout<<" "<<#a<<" : "<<a<<"\n"
#define debug2(a,b) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<"\n"
#define debug3(a,b,c) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<"\n"
#define debug4(a,b,c,d) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<"\n"
#define INF (int)10000000000000000
#define PI (double)3.14159265358979
// #define M 421412341324321
#define MOD 1000000007


signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

	

	int a, b, c;
	cin>>a>>b>>c;

	if (a>=c)
	{
		a-=c;
	}
	else
	{
		c-=a;
		a=0;
		b=max(0LL, b-c);
	}
	cout<<a<<" "<<b;


	



	return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    ll n, cnt = 0;
    cin >> n;
    vector<ll> l(n);
    for (ll i = 0; i < n; ++i) cin >> l.at(i);
    for (ll i = 0; i < n; ++i) for (ll j = i + 1; j < n; ++j) for (ll k = j + 1; k < n; ++k) if (l.at(i) != l.at(j) && l.at(j) != l.at(k) && l.at(i) != l.at(k) && max({l.at(i), l.at(j), l.at(k)}) * 2 < l.at(i) + l.at(j) + l.at(k)) ++cnt;
    cout << cnt << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int>> vvint;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<int, vector<int>, greater<int>> spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int>> bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;        //大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


int INF = 1e9;
int NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
double EPS = 1e-9;
double PI = M_PI;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}
//-----------------------------------------

//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::chrono::system_clock::time_point start,end;
    start = std::chrono::system_clock::now();

    int  a;
    cin >> a ;
    cout << a + a*a + a*a*a <<endl;


    end = std::chrono::system_clock::now();
    auto elapsed = std::chrono::duration_cast< std::chrono::milliseconds >(end - start).count();
    //std::cout << elapsed <<"ms"<< std::endl;

    

    return 0;
}



Measured memory_bytes: 3648
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    l=[list(input().split()) for i in range(n)]
    x=input()
    cnt=0
    for s,t in l:
        if s!=x:
            cnt+=int(t)
        elif s==x:
            cnt+=int(t)
            break
    suml=0
    for i in range(n):
        suml+=int(l[i][1])
    print(suml-cnt)

resolve()

Measured memory_bytes: 3064
#include<iostream>
#include<stdio.h>
using namespace std;
 
int main(){
unsigned int a,b,d,r;
double f;
 cin >> a >> b;
d=a/b;
r=a%b;
 f=((double)a)/b;
 printf("%d %d %.6f\n",d,r,f);
return 0;
}

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

int main(){
    int n,a,b;
    cin >> n >> a >> b;
    int max=0;
    int min=0;
    if(a>=b) max=b;
    else max=a;
    min=n-a;
    min-=b;
    if(min>=0) min=0;
    cout << max << " " << abs(min) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
    int l,r,s;
int main()
{
  cin>>l>>r;
  if (l>r) swap(l,r);
  for (int i=l;i<=r;++i)
    if (i%10==i/10000&&i%100/10==i/1000%10) ++s;
  cout<<s;
  return 0;
}


Measured memory_bytes: 256
// Copyright (C) 2017 __debug.

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/priority_queue.hpp>

#define x first
#define y second
#define MP std::make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif

using std::pair;
using std::vector;
using std::string;

typedef long long LL;
typedef pair<int, int> Pii;

const int oo = 0x3f3f3f3f;

template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, true : false; }
template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, true : false; }
string procStatus()
{
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}
template<typename T> T read(T &x)
{
    int f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar())
        f = (ch == '-' ? -1 : 1);
    for (x = 0; isdigit(ch); ch = getchar())
        x = 10 * x + ch - '0';
    return x *= f;
}
template<typename T> void write(T x)
{
    if (x == 0) {
        putchar('0');
        return;
    }
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    static char s[20];
    int top = 0;
    for (; x; x /= 10)
        s[++top] = x % 10 + '0';
    while (top)
        putchar(s[top--]);
}
// EOT

const int MAXN = 505;

int H, W, h, w;

void solve()
{
    if (H % h == 0 && W % w == 0) {
        puts("No");
        return;
    }
    puts("Yes");
    int a = (H / h) * (W / w) * h * w * 100;
    int b = H * W * 100;
    assert(a + 1 < b);
    int x0 = 100 * (H / h) * (W / w), y0 = a + 1;
    for (int i = 1; i <= H; ++i) {
        for (int j = 1; j <= W; ++j) {
            int cur = x0;
            if (i % h == 0 && j % w == 0) cur -= y0;
            printf("%d ", cur);
        }
        puts("");
    }
}

int main()
{
#ifdef __DEBUG
    freopen("C.in", "r", stdin);
    freopen("C.out", "w", stdout);
#endif

    read(H); read(W); read(h); read(w);
    solve();

    return 0;
}

// 晓看红湿处，花重锦官城。
//     -- 杜甫《春夜喜雨》


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

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define zeroend __builtin_ctz
#define ones __builtin_popcount
#define ends "\n"
#define space ' '
typedef long long ll;
typedef pair<int, int> pii;

/*
void solve(int i, int j, string s){
	if(i==0)
		ans.insert(s2.substr(0, j)+s);
	else if(j==0)
		ans.insert(s1.substr(0, i)+s);
	else if(s1[i-1]==s2[j-1])
		solve(i-1, j-1, s1[i-1]+s);
	else{
		if(dp[i-1][j]<=dp[i][j-1])
			solve(i-1, j, s1[i-1]+s);
		if(dp[i-1][j]>=dp[i][j-1])
			solve(i, j-1, s2[j-1]+s);
	}
}*/


/*
	cin >> n;
	for(int i=0; i<n; ++i)
		cin >> a[i];

	for(int i=1; i<n; ++i){
		for(int j=0; j<i; ++j){
			if(a[j]>a[i]&&low[i]<high[j]+1)
				low[i]=high[j]+1;
			else if(a[j]<a[i]&&high[i]<low[j]+1)
				high[i]=low[j]+1;
		}
		ans=max({ans, low[i], high[i]});
	}

	cout << ans << ends;


*/

const int N = 1e5, M = 1e9+7;

//ll dp[N];
array<ll, 3> dp;
//set<string> ans;
//vector<int> low(N, 1), high(N, 1);
ll a[N];

int n;

int main(){
	cin >> n;
	for(int i=0, l1, l2, l3; i<n; ++i){
		cin >> l1 >> l2 >> l3;
		ll f1=dp[0], f2=dp[1], f3=dp[2];
		dp[0]=l1+max(f2, f3);
		dp[1]=l2+max(f1, f3);
		dp[2]=l3+max(f1, f2);
	}


	cout << max({dp[0], dp[1], dp[2]}) << ends;
}


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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, k, c; cin >> n >> k >> c;
    string s; cin >> s;
    int curr = -1;
    set<int> w, v;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'o') {
            if (curr == -1 || curr + c < i) {
                curr = i; w.emplace(i);
            }
        }
    }
    curr = n;
    for (int i = n-1; i >= 0; i--) {
        if (s[i] == 'o') {
            if (curr == n || i + c < curr) {
                curr = i; v.emplace(i);
            }
        }
    }
    if (w.size() > k) return 0;
    for (auto &x: v) {
        if (w.count(x)) cout << x + 1 << "\n";
    }
    return 0;
}

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

int sum(int l, int r) {
  int n = r - l + 1;
  return (l + r) * n / 2;
}

void solve() {
  int n, a, b;
  cin >> n >> a >> b;
  cout << max(((n - 1) * b + a) - ((n - 1) * a + b) + 1, 0LL) << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}


Measured memory_bytes: 3636
def make_prime_table(n):
    """n以下の非負整数が素数であるかを判定したリストを出力する
    計算量: O(NloglogN)
    入出力例: 6 -> [False, False, True, True, False, True, False]
    """
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n ** 0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(2 * i, n + 1, i):
            is_prime[j] = False
    return is_prime


is_prime = make_prime_table(2 * 10 ** 6)
while True:
    n = int(input())
    if n == 0:
        break
    l = n
    r = n
    while not is_prime[l]:
        l -= 1
    while not is_prime[r]:
        r += 1
    print(r - l)


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

int main() {
    int N; cin >> N;
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        int x, y; cin >> x >> y;
        if (x == y) cnt++;
        else cnt = 0;
        if (cnt == 3) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <vector>
using namespace std;
using ll=long long;

template<class T>
std::vector<std::vector<T>> make_matrix(long long line,long long row){
    std::vector<std::vector<T>> tmp;
    tmp.resize(line);
    for(long long i=0;i<line;i++){
        tmp.at(i).resize(row);
    }
    return tmp;
}

template<class T>
void PRINT(std::vector<std::vector<T>> matrix){
  for(long long i=0;i<matrix.size();i++){
    for(long long j=0;j<matrix.at(0).size();j++){
      std::cout << matrix.at(i).at(j) << " ";
    }
    std::cout << std::endl;
  }
}

template<class T>
std::vector<std::vector<T>> MATRIX(long long line,long long row){
    auto tmp=make_matrix<T>(line,row);
    for(long long i=0;i<tmp.size();i++){
        for(long long j=0;j<tmp.at(0).size();j++){
            cin >> tmp[i][j];
        }
    }
    return tmp;
}

int main(){
    ll N,W;
    cin >> N >> W;
    auto h=MATRIX<ll>(N,2);
    auto dp=MATRIX<ll>(N+1,W+1);
    for(ll i=0;i<W+1;i++){
        dp[0][i]=0;
    }
    
    for(ll n=1;n<N+1;n++){
        for(ll w=0;w<W+1;w++){
            if(h[n-1][0]<=w){
                dp[n][w]=max(dp[n-1][w],dp[n-1][w-h[n-1][0]]+h[n-1][1]);
            }else{
                dp[n][w]=dp[n-1][w];
            }
        }
    }
    cout << dp.at(N).at(W) << endl;
	
}

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

const long long mod = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  long long a[n];
  for ( int i = 0; i < n; i++ ) { cin >> a[i]; }
  
  long long sm[n];
  sm[0] = a[0];
  for ( int i = 1; i < n; i++ ) {
    sm[i] = sm[i-1] + a[i];
    sm[i] %= mod;
  }

  long long ans = 0;
  for ( int i = 0; i < n; i++ ) {
    ans += ((sm[n-1]-sm[i]+mod)%mod * a[i]) % mod;
    ans %= mod;
  }

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


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

string t[26] = 
{
"100101",
"10011010",
"0101",
"0001",
"110",
"01001",
"10011011",
"010000",
"0111",
"10011000",
"0110",
"00100",
"10011001",
"10011110",
"00101",
"111",
"10011111",
"1000",
"00110",
"00111",
"10011100",
"10011101",
"000010",
"10010010",
"10010011",
"10010000"
};

int main()
{
	string line;
	while(getline(cin,line))
	{
		string buf;
		for(int i=0; i<line.size(); i++)
		{
			switch(line[i])
			{
				case ' ' : buf+="101";      break;
				case '\'': buf+="000000";   break;
				case ',' : buf+="000011";   break;
				case '-' : buf+="10010001"; break;
				case '.' : buf+="010001";   break;
				case '?' : buf+="000001";   break;
				default  : buf+=t[line[i]-'A'];break;
			}
		}
		buf+="0000";

		for(int i=0; i<buf.size()-4; i+=5)
		{
			int x = 0;
			for(int j=0; j<5; j++)
			{
				x+= (buf[i+4-j]=='1' ? 1<<j : 0);
			}
			
			char c;
			switch(x)
			{
				case 26: c=' ';  break;
				case 27: c='.';  break;
				case 28: c=',';  break;
				case 29: c='-';  break;
				case 30: c='\''; break;
				case 31: c='?';  break;
				default: c=x+'A';break;
			}

			cout << c;
		}
		cout << endl;
	}
}

Measured memory_bytes: 0
import static java.lang.Math.*;
import static java.util.Arrays.*;
 
import java.util.*;
import java.io.*;
import java.math.BigInteger;
 
import static java.math.BigInteger.*;
 
public class Main {
	
	void solve() {
		char[] s = sc.next().toCharArray();
		int n = s.length;
		long K = sc.nextLong();
		
		for (int i = 0; i < n; i++) {
			int need = (1 + 'z' - s[i]) % 26;
			if (need <= K) {
				s[i] = 'a';
				K -= need;
			}
		}
		if (K > 0) { K %= 26; }
		while (K-->0) {
			if (s[n-1] == 'z') s[n-1] = 'a'; else s[n-1]++;
		}
		System.out.println(new String(s));
	}
 
	public static void main(String[] args) throws Exception {
		new Main().run();
	}
 
	Scanner sc = null;
	public void run() throws Exception {
		sc = new Scanner(System.in);
		solve();
	}
 
}

Measured memory_bytes: 13940
// https://atcoder.jp/contests/abc151/tasks/abc151_c

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll N, M;
  cin >> N >> M;

  VL done(N);
  VL was(N);

  rep(i, M) {
    ll p;
    string s;
    cin >> p >> s;
    p--;

    if (done[p]) continue;

    if (s == "WA") was[p]++;
    if (s == "AC") done[p] = 1;
  }

  ll ac = 0;
  ll wa = 0;

  rep(i, N) {
    if (done[i]) {
      ac++;
      wa += was[i];
    }
  }

  print_ints({ac, wa});
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


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

int main(){
    int N, M;
    cin >> N >> M;
    
    vector<bool> yosa(N,true);
    
    vector<long long> H(N);
    
    for(int i=0; i<N; i++){
        cin >> H[i];
    }
    
    int a,b;
    
    for(int i=0; i<M; i++){
        cin >> a >> b;
        if(H.at(a-1)>=H.at(b-1)) yosa.at(b-1)=false;
        if(H.at(a-1)<=H.at(b-1)) yosa.at(a-1)=false;
    }
    
    
    int ans=0;
    
    for(int i=0; i<N; i++){
        if(yosa[i])ans++;
    }
    
    cout << ans <<endl;
    return 0;
}


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

using namespace std;

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

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

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

int N, hs[100100];
int dp[100100];
int K;

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

    std::cin >> N >> K;

    for(int i=0;i<N;++i){
        std::cin >> hs[i];
    }

    std::fill(dp, dp+N, 1001001001);
    dp[0] = 0;

    for(int i=0;i+1<N;++i){
        for(int j=1;j<=K;++j){
            if(i + j < N){
                dp[i + j] = std::min(dp[i + j], dp[i] + std::abs(hs[i + j] - hs[i]));
            }
        }
    }

    std::cout << dp[N-1] << std::endl;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(){
  int a[10],b,c,d,i,j,temp;
  for(i=0;i<5;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<4;i++){
    for(j=4;j>i;j--){
      if(a[j]>a[j-1]){
	temp=a[j];
	a[j]=a[j-1];
	a[j-1]=temp;
      }
    }
  }
  for(i=0;i<4;i++){
    printf("%d ",a[i]);
  }
  printf("%d",a[4]);
  printf("\n");
  return 0;
}

Measured memory_bytes: 0