akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
//#define int ll
//#define endl '\n'

// use unique(x) - removec consecutive items, returns vec.begin() + number of items
// for vector: sort(all(vec)); vec.erase(unique(all(vec)), vec.end());
// use iota(all(vec), 0) for filling a vector with 0,1,2...
// use fill(all(vec), 1) for filling a vector with 1,1,1...
// use rotate(vec.begin(), vec.begin() + 1, vec.end()) to rotate a vector | middle arg becomes first
// print number in binary -> cout << bitset<20>(n);

const int N=110,K=100100,mod=1e9+7;
int a[N];
int dp[N][K];
int n,k;

main(){
	cin.tie(0);cin.sync_with_stdio(0);
	cin>>n>>k;
	for(int i=0;i<n;++i)cin>>a[i];
	dp[0][0]=1;
	dp[0][1]=-1;
	for(int i=0;i<=n;++i)
		for(int j=0;j<=k;++j){
			dp[i+1][j]=(dp[i+1][j]+dp[i][j])%mod;
			if(j+a[i]+1<=k)dp[i+1][j+a[i]+1]=(dp[i+1][j+a[i]+1]-dp[i][j]+mod)%mod;
			dp[i][j+1]=(dp[i][j+1]+dp[i][j])%mod;
		}
	cout<<dp[n][k]<<endl;
}


Measured memory_bytes: 43452
#include<bits/stdc++.h>
using namespace std;
#define int long long
int X;
signed main(){
	scanf("%lld",&X);
	for(int i=-3981;i<=3981;i++)for(int j=-3981;j<=3981;j++)if(i*i*i*i*i-j*j*j*j*j==X){printf("%lld %lld\n",i,j);exit(0);}
	return 0;
}

Measured memory_bytes: 3828
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);


    public static void main(String[] args) {
        int k = sc.nextInt();
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        int max = Integer.MIN_VALUE;
        int count = 0;
        for (int i = 1; i < n; i++) {
            int value = a[i] - a[i - 1];
            count += value;
            max = Math.max(max, value);
        }
        int value = k - a[n - 1] + a[0];
        count += value;
        max = Math.max(max, value);
        System.out.println(count - max);
    }
}


Measured memory_bytes: 80892
H, W = map(int, input().split())
HW = []
for i in range(H):
    HW.append(list(input()))
cnt = [[0 for i in range(W)] for j in range(H)]
for i in range(H):
    for j in range(W):
        if HW[i][j] == "#":
            if i != 0 and j != 0:
                cnt[i - 1][j - 1] += 1
            if i != 0:
                cnt[i - 1][j] += 1
            if i != 0 and j != W - 1:
                cnt[i - 1][j + 1] += 1
            if j != 0:
                cnt[i][j - 1] += 1
            if j != W - 1:
                cnt[i][j + 1] += 1
            if i != H - 1 and j != 0:
                cnt[i + 1][j - 1] += 1
            if i != H - 1:
                cnt[i + 1][j] += 1
            if i != H - 1 and j != W - 1:
                cnt[i + 1][j + 1] += 1
for i in range(H):
    for j in range(W):
        if HW[i][j] == "#":
            print("#", end = "")
        else:
            print(str(cnt[i][j]), end = "")
    print()
print()


Measured memory_bytes: 3572
import sys
input=sys.stdin.readline

N,K=(int(x) for x in input().rstrip('\n').split())
L = list(input())
now = L[0]
same = 0
for x in L[1:]:
  if x == now:
    same += 1
  else:
    now = x
res = same + K*2
if res > N-1:
  res = N-1
print(res)

Measured memory_bytes: 10452
import sys
from collections import deque
s=sys.stdin.readlines()
_,q=map(int,s[0].split())
f=lambda x,y:(x,int(y))
d=deque(f(*e.split())for e in s[1:])
t=0
while d:
 k,v=d.popleft()
 if v>q:
  v-=q
  t+=q
  d.append([k,v])
 else:
  t+=v
  print(k,t)


Measured memory_bytes: 16304
fun main(args: Array<String>) {
    val (a, b, c) = readInputLine().split(" ").map { it.toInt() }
    val list = mutableListOf<Int>(a, b, c)
    list.sortDescending()
    
    var ans = 0
    
    if (!list.all { it % 2 == 0 } && !list.all { it % 2 == 1 }) {
        // 3数の偶奇が一致していない場合は一致させたうえで答えを求める
        ans++
        val newList =
            if (list.count { it % 2 == 0 } == 2) {
                list.map { if (it % 2 == 0) it + 1 else it }
            } else {
                list.map { if (it % 2 == 1) it + 1 else it }
            }
        ans += (newList[0] - newList[1]) / 2
        ans += (newList[0] - newList[2]) / 2
    } else {
        // 3数の偶奇が一致しているので愚直に求める
        ans += (list[0] - list[1]) / 2
        ans += (list[0] - list[2]) / 2
    }
    
    println(ans)
}
 
fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 37940
#include <iostream>
#include <cassert>
#include <cmath>
//#define NDEBUG
int main(void){
	using namespace std;
	static const int INPUT_MAX = 20000;
	static const int INPUT_MIN = 0;
	int input_a = 0;
	int input_b = 0;
	int ans = 0;			/* 解 */
	int end_flag = 0;		/* 終了フラグ */
	char op = 0;	    	/* 演算子 */

	/* 入力値の前提条件 最大・最小の制限*/
	assert (INPUT_MIN <= input_a && input_a <= INPUT_MAX);
	assert (INPUT_MIN <= input_b && input_b <= INPUT_MAX);
	/* 入力値の前提条件 0の割り算でないこと*/
	assert (!((input_a == 0 || input_b == 0) && op == '/'));

	do{
		cin >> input_a >> op >> input_b;
		
		/* Calculation */
		if(op == '+'){
			ans = input_a + input_b;
			cout  << ans << endl;
		}
		else if(op == '-'){
			ans = input_a - input_b;
			cout  << ans << endl;
		}
		else if(op == '*'){
			ans = input_a * input_b;
			cout  << ans << endl;
		}
		else if(op == '/'){
			ans = input_a / input_b;
			cout  << ans << endl;
		}
		else if(op == '?'){
			end_flag = 1;
		}
		else{
			cout  << "Input Error" << endl;
			end_flag = 1;
		}
	}while(end_flag == 0);
		
	return 0;
}



Measured memory_bytes: 3112
#include<cstdio>
#define N 100005
#define P pair<int,int>
#define int long long
inline int read(){
    int x=0;char ch=getchar();
    for(;ch<48||ch>57;ch=getchar());
    for(;ch>47&&ch<58;ch=getchar())
    x=(x<<1)+(x<<3)+(ch^48);return x;
}
using namespace std;
signed main()
{
    int n=read();
    if(n>=195)puts("5");else
    if(n>=189)puts("4");else
    if(n>=165)puts("3");else
    if(n>=135)puts("2");else
    if(n>=105)puts("1");else
    puts("0");
    return 0;
}

Measured memory_bytes: 128
N = int(input())

if N>=64:
  ans = 64
elif 32<=N<64:
  ans = 32
elif 16<=N<32:
  ans = 16
elif 8<=N<16:
  ans = 8
elif 4<=N<8:
  ans = 4
elif 2<=N<4:
  ans = 2
else:
  ans = 1
  
print(ans)

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int n,a,b,ans,sum;
int main()
{
	cin>>n>>a>>b;
	for(int i=1;i<=n;i++)
	{
		int y=i;
		while(y>0)
		{
			ans+=y%10;
			y=y/10;
		}
		if(ans>=a&&ans<=b)
		sum+=i;
		ans=0;
	}
	cout<<sum<<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;
const ll INF = 1e9;

int main() {
  ll g, d;
  cin >> d >> g;
  vector<ll> p(d), c(d);

  rep(i, d) cin >> p[i] >> c[i];

  ll cnt = INF;
  for (int i = 0; i < 1 << d; ++i) {
    ll po = 0, tcnt = 0, id = -1;
    for (int j = 0; j < d; ++j) {
      if (i & 1 << j) {
        po += (j + 1) * 100 * p[j] + c[j];
        tcnt += p[j];
      } else {
        id = j;
      }
    }

    if (po < g) {
      ll need = ceil((g - po) / (id + 1) / (double)100.0);
      if (need > p[id]) continue;
      tcnt += need;
    }
    cnt = min(cnt, tcnt);
  }

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
N, M = map(int,input().split())
 
user = {}
for i in range(N):
    user[i] = list(map(int,input().split()))
 
tmp = list(range(1,31))
for k in user.keys():
    user[k].pop(0)
    tmp = list(set(tmp) & set(user[k]))
print(len(tmp))

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

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

const ll mod =  1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;   // INFの値は1152921504606846976

ll gcd(ll a, ll b)
{
    if(b == 0){
        return a;
    }
    return gcd(b,a%b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a,b);
    return (a / g) * b;
}

int main()
{
    ll n,m;
    cin >> n >> m;
    ll a[n];
    bool even = false;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        a[i] /= 2;
        if(a[i] % 2 == 0) even = true;
    }

    ll k = a[0];
    if(!even){
        for(int i = 1; i < n; i++){
            k = lcm(k,a[i]);
        }
        ll x = m/k;
        cout << (x+1)/2 << endl;
    }else{
        int div = 0;
        bool e = true;
        for(int i = 0; i < n; i++){
            int cnt = 0;
            int A = a[i];
            while(A % 2 == 0){
                A /= 2;
                cnt++;
            }
            if(i != 0 && div != cnt){
                e = false;
            }
            div = cnt;
        }
        if(e){
            for(int i = 1; i < n; i++){
                k = lcm(k,a[i]);
            }
            cout << (m/k+1)/2 << endl;
        }else{
            cout << 0 << endl;
        }
    }
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acosl(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define MXN 200005
set<int> v[100005];
int f[100005];
int Find(int x){
    if(f[x]==x)return x;
    return f[x]=Find(f[x]);
}
int main(){ 
    int n;
    scanf("%d",&n);
    queue<pii> q;
    for(int t=0;t<2;t++){
        for(int i=1;i<n;i++){
            int x,y;
            scanf("%d %d",&x,&y);
            if(v[x].find(y)==v[x].end()){
                v[x].insert(y);
                v[y].insert(x);
            }
            else{
                v[x].erase(y);
                v[y].erase(x);
                q.push(mp(x,y));
            }
        }
    }
    for(int i = 1;i<=n;i++)f[i]=i;
    while(!q.empty()){
        pii p=q.front();
        q.pop();
        p.x=Find(p.x);
        p.y=Find(p.y);
        if(v[p.x].size()>v[p.y].size()){
            swap(p.x,p.y);
        }
        f[p.x]=p.y;
        for(auto it:v[p.x]){
            it=Find(it);
            v[it].erase(p.x);
            if(v[p.y].find(it)==v[p.y].end()){
                v[p.y].insert(it);
                v[it].insert(p.y);
            }
            else{
                v[p.y].erase(it);
                v[it].erase(p.y);
                q.push(mp(p.y,it));
            }
        }
    }
    int cnt=0;
    for(int i = 1;i<=n;i++){
        if(f[i]==i)cnt++;
    }
    if(cnt==1)printf("YES\n");
    else printf("NO\n");
}
/**/

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

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    if(a == b){
        cout << a + b << "\n";
    }
    else{
            cout << (2 * max(a, b) - 1) << "\n";
    }
    return 0;
}

Measured memory_bytes: 3548
#include <vector>
#include <cstdio>
#include <stack>
#include <string>
#define help cout<<"I don't want to die!"<<endl;
using namespace std;
const int S=(1<<20)+5;
char buf[S],*H,*T;
inline char Get()
{
    if(H==T) T=(H=buf)+fread(buf,1,S,stdin);
    if(H==T) return -1;return *H++;
}
inline int read()
{
    int x=0;char c=Get();
    while(!isdigit(c)) c=Get();
    while(isdigit(c)) x=x*10+c-'0',c=Get();
    return x;
}
int main(){
    long long marxism = -10000000000000;
    vector<stack<int> > ms;//monotonic stack;
    vector<int> dis;
    vector<long long> cf;//distance between shops,0:0->1;chafenshuzu
    vector< vector<int> > tickets;
    int shop = read(),tic = read();
    /*initialization*/
    cf.assign(shop-1,0);
    tickets.assign(tic,vector<int>());
    ms.assign(tic,stack<int>());
    dis.reserve(shop);
    /*done*/
    for (register int i = 1;i<shop;++i){
        int temp = read();
        dis.push_back(-temp);
    }
    //convert the distance into "chafen" form;
    for (register int i = 0;i<shop;++i){
        for (register int j = 0;j<tic;++j){
            int temp=read();
            tickets[j].push_back(temp);
        }
    }
    //get the tickets'value
    //tickets[i][j]:the value of ticket i in the shop j
    for (register int i = shop-1;i>=0;--i){
	long long result = 0;
        //enumerate start point from tail to head;
        for (register int j = 0;j<ms.size();++j){
            //process the "chafenshuzu" of each ticket.
            int cur = tickets[j][i],prev = 0;//prev is the previous shop,used to determine how large to shrink in the next shop;
            while (!ms[j].empty()){
                if (cur>tickets[j][ms[j].top()]){//the one we have is greater than the top of the stack;
                    cf[ms[j].top()-1] -=(tickets[j][ms[j].top()]-prev);
                    prev = tickets[j][ms[j].top()];
                    ms[j].pop();
                }
                else{
                    cf[ms[j].top()-1] -=(cur-prev);
                    break;
                }
            }
	    result += cur;
	    if (i) cf[i-1] +=cur;
            ms[j].push(i);
        }
	//update the 'chafen' completed;
        marxism = max(marxism,result);
        for (register int j = i;j<shop-1;++j){
            result +=  dis[j];
            result +=  cf[j];
            marxism = max(marxism,result);
        }
    }
    printf("%lld",marxism);
}


Measured memory_bytes: 7040
#include<bits/stdc++.h>
#define ll long long int
#define fip ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define reptUsual(b) for(i=0; i<b; ++i)
#define reptArIn(i,a,b,ar) for( i=a; i<b; ++i) cin>>ar[i];
#define rept(i,a,b) for(i=a; i<b; ++i)
#define maX(a,b)    ( (a) > (b) ? (a) : (b))
#define miN(a,b)    ( (a) < (b) ? (a) : (b))
#define pb(a) push_back(a)
#define bigPrime 1000000007
using namespace std;

struct intDef
{
    int value = 0;
};



int main()
{
    map < pair<int ,int> ,intDef > mp ;
    int n,i,a,x,y,j,diffY,diffX,max=0;
    cin>>n;
    int ar[n][2];
    reptUsual(n)
    {
        cin>>x>>y;
        ar[i][0]=x;
        ar[i][1]=y;
    }
    if(n==1)
    {
        cout<<"1";
        return 0;
    }
    map< pair<int ,int> , intDef>::iterator it ; 
    reptUsual(n)
    {
        rept(j,0,n)
        {

            diffX = ar[i][0]-ar[j][0];
            diffY = ar[i][1]-ar[j][1];
            if(diffY == 0 && diffX == 0)
                continue;
            it = mp.find( make_pair(diffX,diffY));
            if(it!=mp.end())
            {
                a=(++(mp[{diffX,diffY}].value));
                if(a>max)
                    max=a;

            } 

            else
            {
                (mp[{diffX,diffY}].value)++;
            }
        }
    }

    if(max==0)
    {
        cout<<(n-1);
    }
    else
        cout<<(n-max);


    return 0;

}

Measured memory_bytes: 384
#include <map>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int Q, H, W, r, a[409], pre[1048588], dp[1048588];
int main() {
	cin >> Q;
	int cnt = 0;
	while (Q--) {
		cin >> W >> H; r = (1 << W) - 1;
		for (int i = 0; i < H * W; i++) cin >> a[i];
		fill(pre, pre + (1 << W), -999999999); pre[0] = 0; pre[1] = a[0];
		for (int i = 0; i < H * W - 1; i++) {
			fill(dp, dp + (1 << W), -999999999);
			for (int j = 0; j < 1 << W; j++) {
				if (pre[j] >= 0) {
					dp[(j * 2) & r] = max(dp[(j * 2) & r], pre[j]);
					bool flag = true;
					if (i % W != W - 1 && (j & 1)) flag = false;
					if (j & (1 << (W - 1))) flag = false;
					if (flag) {
						dp[(j * 2 + 1) & r] = max(dp[(j * 2 + 1) & r], pre[j] + a[i + 1]);
					}
				}
			}
			for (int j = 0; j < 1 << W; j++) pre[j] = dp[j];
		}
		int ret = *max_element(pre, pre + (1 << W));
		cout << "Case " << ++cnt << ": " << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 11136
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include<climits>
#include <string>
#include <map>
#include <set>
#include <list>

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)

using namespace std;

int i,j,k,l,m,n;
/////////////////////////////////////////////////////


int N,T;
int c[1010],t[1010];
int ans=9999;

int main(){
    scanf("%d%d",&N,&T);
    fornum(i,0,N){
        scanf("%d%d",&c[i],&t[i]);
    }
    fornum(i,0,N){
        if(t[i]<=T){
            ans=ans<c[i]?ans:c[i];
        }
    }
    if(ans!=9999)
        printf("%d\n",ans);
    else
        printf("TLE\n");
    return 0;
}

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

int main(){
  int N, M, C;
  cin >> N >> M >> C;
  vector<int> B(M);
  
  for(int i = 0; i < M; i++){
    cin >> B.at(i);
  }
  
  vector<vector<int>> A(N,vector<int>(M));
  
  for(int i = 0; i < N; i++){
    for(int j = 0; j < M; j++){
      cin >> A.at(i).at(j);
    }
  }
  
  int ans = 0;
  
  for(int i = 0; i < N; i++){
    int sum = 0;
    for(int j = 0; j < M; j++){
      sum += A.at(i).at(j) * B.at(j);
    }
    if(sum + C > 0){
      ans++;
    }
    
  }
  cout << ans;
  
}

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

int main(){
  ll a,b,c;
  cin>>a>>b>>c;
  for(int i=0;i<c;i++){
	if(i%2==0){
	  a-=a%2;
	  a/=2;
	  b+=a;
	}else{
	  b-=b%2;
	  b/=2;
	  a+=b;
	}
  }
  cout<<a<<" "<<b<<endl;
  return 0;
}


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

#define nl '\n'
#define F fisrt
#define S second
#define pb push_back
#define mp make_pair
#define REP(i,a,b) for(int i = a; i < b; i++)
#define ForeachTC int t; cin >> t; while(t--)
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef stack<int> si;
typedef deque<int> di;
typedef pair<int,int> pi;

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

	//your code here
	int a, b, c;
	cin >> a >> b >> c;
	if(a+b+c-10 == 7) cout << "YES";
	else cout << "NO";
}


Measured memory_bytes: 256
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#define pb push_back 
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<30)
#define MOD 1000000007
using ll = long long;
using namespace std;

int main() {
    ll n;
    vector<ll> a;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int t;
        cin >> t;
        if (i == 0)a.pb(t);
        else a.pb(t + a[i - 1]);
    }
    ll ans = INF, l=0,r=2;
    for (int middle = 1; middle <= n - 3; middle++) {
        while (l < middle && abs((a[middle] - a[l]) - a[l]) >= abs((a[middle] - a[l + 1]) - a[l + 1])) {
            l++;
        }
        while (r < n - 1 && abs((a[n - 1] - a[r]) - (a[r] - a[middle])) >= abs((a[n - 1] - a[r + 1]) - (a[r + 1] - a[middle]))) {
            r++;
        }
        ans = min(ans, max({ a[l],a[middle] - a[l],a[r] - a[middle],a[n-1] - a[r] }) - min({ a[l],a[middle] - a[l],a[r] - a[middle],a[n-1] - a[r] }));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
#define fo(i,a,n) for(i=a;i<n;i++)
#define ll long long
#define ld long double
#define deb(x) cout << #x << "=" << x << endl
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define sortrev(x) sort(all(x),greater<int>())
#define pi 3.1415926535897932384626

typedef pair<int,int> pii;
typedef pair<ll, ll> pl;
typedef vector<int>	vi;
typedef vector<ll>	vl;
typedef vector<pii>	vpii;
typedef vector<pl>	vpl;
typedef vector<vi>	vvi;
typedef vector<vl>	vvl;


const int mod = 100000007;
const int inf = 100005;
const int N = 3e5, M = N;
ll i,j,n,m,idx,cnt;
char d[31][31];
int dx[] = {-1,1,0,0};
int dy[] = {0,0,-1,1};


void solve() {
    ll n,k,r,s,p;
    string t;
    cin>>n>>k>>r>>s>>p>>t;

    ll ans = 0;
    vi vec(n,0);
    fo(i,0,n) {
        if(t[i] == 'r') {
            if(i<k || t[i-k] != 'r' || (t[i-k] == 'r' && !vec[i-k])) {
                vec[i] = 1,ans+=p;
            }
        }
        else if(t[i] == 's') {
            if(i<k || t[i-k] != 's' || (t[i-k] == 's' && !vec[i-k])) {
                vec[i] = 1,ans+=r;
            }
        }
        else {
            if(i<k || t[i-k] != 'p' || (t[i-k] == 'p' && !vec[i-k])) {
                vec[i] = 1,ans+=s;
            }
        }
    }
    cout<<ans<<"\n";
}



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

    int t = 1;
    //cin >> t;
    while(t--) {
      solve();
    }

    return 0;
}




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

public class Main {

    static String S;

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

        S = sc.next();

        System.out.println( solve() ? "YES" : "NO" );
    }

    static boolean solve() {
        int a = 0;
        int b = 0;
        int c = 0;
        for (int i = 0; i < S.length(); i++) {
            if( S.charAt(i) == 'a' ) {
                a++;
            } else if( S.charAt(i) == 'b' ) {
                b++;
            } else {
                c++;
            }
        }

        int diff = Math.max(Math.max(Math.abs(a-b), Math.abs(b-c)), Math.abs(c-a));
        return diff <= 1;
    }

    static class FastScanner {

        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


Measured memory_bytes: 22996
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include<set>
#include<queue>

typedef long long ll;


#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h, w, n,m,k; string s;
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);

}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}

int main() {
	cin >> n;
	vector<ll> h(n);
	rep(i, n) {
		cin >> h[i];
	}

	vector<ll> dp(n);
	rep(i, n) {
		dp[i] = INF;
	}
	dp[0] = 0;
	for (ll i = 1; i < n; i++) {
		chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
		if (i > 1)chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
	}
	cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1792
#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;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A, B, K;
    cin >> A >> B >> K;
    ll now = min(A, K);
    A -= now;
    K -= now;
    B -= min(K, B);
    cout << A << " " << B << endl;
    return 0;
}


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

int main()
{
    int n,k;
    std::cin >> n >> k;
    std::vector<int> p(n, 1);

    for (int i = 1; i <= n; i++) {
        for (int j = 1*i; j < k; j*=2) {
            p[i-1] *= 2;
        }
    }

    double ans = 0.0;
    for (int i = 0; i < n; i++) {
        ans += 1.0 / p[i];
    }
    std::cout << std::setprecision(10) << ans / n << std::endl;
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);++i)
#define erep(i,j,n) for(int i=(j);i<=(n);++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	string s;
	cin >> s;
	int i = 1;
	while (1) {
		string t = s.substr(0, s.size() - i * 2);
		if (t.substr(0, t.size() / 2) == t.substr(t.size() / 2)) {
			cout << t.size() << endl;
			return 0;
		}
		i++;
	}
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    int n, m;
    int i;
    multiset<int> a;
    ll ans = 0;

    cin >> n >> m;

    for (i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        a.insert(x);
    }

    for (i = 0; i < m; i++)
    {
        int k = *a.rbegin();

        a.erase(a.find(k));
        a.insert(k / 2);
    }

    for (auto x : a)
    {
        ans += x;
    }

    cout << ans << endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using intl = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for(intl i = (intl)((n) - 1); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin,(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define length(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, length(a))cin >> a[i]
#define ccin(i, j, a) rep(i, length(a))rep(j, length(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define sqrtl sqrt
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool flag){
    if(flag)cout << "Yes" << endl;
    else cout << "No" << endl;
}
int main(){
    string s;
    cin >> s;
    s[5] = ' ';
    s[13] = ' ';
    cout << s << endl;
    return 0;
}

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

for i in range(1,1+N):
    ans=0
    M=int(i**0.5)+1
    for x in range(1,M):
        if x**2<i:
            for y in range(1,x+1):
                if x**2+y**2+x*y<i:
                    for z in range(1,y+1):
                        if x**2+y**2+z**2+x*y+y*z+z*x==i:
                            if x==y==z:
                                ans+=1
                            elif x!=y and y!=z and z!=x:
                                ans+=6
                            else:
                                ans+=3
    print(ans)

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

int N;
vector<long long> a;

int main() {
    cin >> N;
    a.resize(N);
    for (int i = 0; i < N; ++i) cin >> a[i];
    long long res = 0;
    for (int i = 0; i < N; ++i) {
        int tmp = 0;
        while (a[i] % 2 == 0) {
            ++tmp;
            a[i] /= 2;
        }
        res += tmp;
    }
    cout << res << endl;
}



























Measured memory_bytes: 384
def main():
    N = int(input())
    A = list(map(int, input().split()))

    for i in range(0,N):
        if A[i] == 0:
            print(0)
            return

    ans = 1
    for i in range(0,N):
        ans *= A[i]
        if ans > 10**18:
            ans = -1
            break
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 84528
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char last = '\0';
        Set<String> set = new HashSet<>();
        for (int i = 0; i < n; i++) {
            String w =  sc.next();

            if (last != '\0' && last != w.charAt(0)) {
                System.out.println("No");
                return;
            }
            if (set.contains(w)) {
                System.out.println("No");
                return;
            }
            set.add(w);
            last = w.charAt(w.length() -1);
        }
        System.out.println("Yes");
    }
}


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

typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;

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

    bool ans(false);
    for(int i=9;i>0;i--){
        if(n%i==0){
            if(n/i<10){
                ans = true;
                break;
            }
        }
    }

    if(ans) cout << "Yes" << endl;
    else    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3620
package main

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

var sc = bufio.NewScanner(os.Stdin)

type triple struct {
	a, b, c int
}

func ri() (n int) {
	sc.Scan()
	for _, v := range sc.Bytes() {
		n = n*10 + int(v-48)
	}
	return
}

func larger(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func max(a []int) int {
	x := a[0]
	for _, v := range a {
		if v > x {
			x = v
		}
	}
	return x
}

func main() {
	sc.Split(bufio.ScanWords)
	n := ri()
	h := triple{a: 0, b: 0, c: 0}
	for i := 0; i < n; i++ {
		x, y, z := ri(), ri(), ri()
		var today triple
		today.a = x + larger(h.b, h.c)
		today.b = y + larger(h.c, h.a)
		today.c = z + larger(h.a, h.b)
		h = today
	}
	fmt.Println(max([]int{h.a, h.b, h.c}))
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
ll a[100000];
void output(int ind,int n)
{
	cout<<"Possible"<<endl;
	for(int i=1;i<ind;i++)
		cout<<i<<endl;
	for(int i=n-1;i>ind;i--)
		cout<<i<<endl;
	cout<<ind<<endl;
	return;
}
int main()
{
	int n;
	ll l;
	cin>>n>>l;
	for(int i=0;i<n;i++)
		cin>>a[i];
	bool f=false;
	for(int i=1;i<n;i++)
  {
		if(a[i]+a[i-1]>=l)
		{
			f=true;
			output(i,n);
			break;
		}
	}
	if(!f)
		cout<<"Impossible"<<endl;
	return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long fact[200005];
void precalc(){
    fact[0] = 1;
    for(long long i = 1; i <= 200000; i++){
        fact[i] = (fact[i - 1] * i) % mod;
    }
}
long long bigmod(long long a, long long p){
    if(p == 0){
        return 1;
    }
    long long ans = bigmod(a, p/2);
    ans = (ans * ans) % mod;
    if(p % 2 == 1){
        ans = (ans * a) % mod;
    }
    return ans;
}
long long inverse(long long a){
    return bigmod(a, mod - 2);
}
long long nCr(long long n, long long m){
    long long ans = (fact[n] * inverse(fact[n - m])) % mod;
    ans = (ans * inverse(fact[m])) % mod;
    return ans;
}
long long sum(long long n, long long m){
    long long ans = (m * (m - 1) * (m + 1))/6;
    ans = ans % mod;
    ans = (ans * n) % mod;
    ans = (ans * n) % mod;
    return ans;
}
int main(){
    precalc();
    int n, m, k;
    cin >> n >> m >> k;
    long long ans = (sum(n, m) + sum(m, n)) % mod;
    ans = (ans * nCr(n * m - 2, k - 2)) % mod;
    cout << ans;
    return 0;
}

Measured memory_bytes: 5204
#include<iostream>
using namespace std;
int s,k,ans;
int main()
{
    cin>>k>>s;
    for(int i=0;i<=k;++i)
        for(int j=0;j<=k;++j)
            if(s-i-j>=0&&s-i-j<=k)
                ++ans;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define N 110

int main(){
  int A[N][N];
  int n;
  std::cin >> n;

  for(int i=0; i<n; i++){
    int u, k;
    std::cin >> u >> k;
    int v;
    for(int j=0; j<k; j++){
      std::cin >> v;
      A[u][v]=1;
    }
  }
  for(int i=1; i<=n; i++){
    for(int j=1; j<=n; j++){
      std::cout << A[i][j];
      if( j!=n ){
      std::cout << " ";
      }
    }
    std::cout << std::endl;
  }

  return 0;
}



Measured memory_bytes: 3116
n = int(input())
s = str(input())

l = ['SS', 'SW', 'WS', 'WW']

for i in range(4):
  ans = l[i]
  for j in range(1, n):
    if ans[j] == 'S' and s[j] == 'o':
      if ans[j-1] == 'S':
        ans += 'S'
      else:
        ans += 'W'
    elif ans[j] == 'S' and s[j] == 'x':
      if ans[j-1] == 'S':
        ans += 'W'
      else:
        ans += 'S'
    elif ans[j] == 'W' and s[j] == 'o':
      if ans[j-1] == 'S':
        ans += 'W'
      else:
        ans += 'S'
    else:
      if ans[j-1] == 'S':
        ans += 'S'
      else:
        ans += 'W' 
  flag = 0
  if ans[-1] == ans[0]:
    if ans[0] == 'S' and s[0] == 'o':
      if ans[-2] == ans[1]:
        flag = 1
    elif ans[0] == 'W' and s[0] == 'o':
      if ans[-2] != ans[1]:
        flag = 1
    elif ans[0] == 'S' and s[0] == 'x':
      if ans[-2] != ans[1]:
        flag = 1
    else:
      if ans[-2] == ans[1]:
        flag = 1
  if flag == 1:
    print(ans[:-1])
    exit()
else:
  print('-1')
  
 
  
  

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    int i;
    int dp[1020];
    dp[1] = 1;
    dp[2] = 3;
    for(i=3;i<=999;i++)
    {
        dp[i] = dp[i-1] + i;
    }
    for(i=1;i<999;i++)
    {
        if(dp[i] - n == dp[i+1] - k){
            printf("%d\n",dp[i] - n);
            break;
        }
    }
    return 0;
}


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

def dfs(s): # 文字列 s で始まる七五三数の個数
    if int(s) > N:
        return 0
    ret = 0
    flag = True
    for c in '753':
        if s.count(c) == 0:
            flag = False
    if flag:
        ret = 1
    for c in '753':
        ret += dfs(s + c)
    return ret

print(dfs("0"))

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

bool solve(int n, const std::string &str) {
  if (n % 2 == 1) return false;
  int dis = n / 2;
  for (int i = 0; i < dis; ++i) {
    if (str[i] != str[i + dis]) return false;
  }
  return true;
}

int main() {
  int n;
  std::string str;
  std::cin >> n >> str;
  if (solve(n, str)) std::cout << "Yes" << std::endl;
  else std::cout << "No" << std::endl;
  return 0;
}


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

using namespace std;
using ll = long long;

int main(int argc, const char *argv[]) {
  ll n;
  cin >> n;
  if (n == 0) {
    cout << 0 << '\n';
    return 0;
  }

  string ans;
  while (n != 0) {
    ll r = n % 2;
    if (r < 0) {
      r += 2;
    }

    ans += '0' + r;
    n = (n - r) / -2;
  }

  reverse(ans.begin(), ans.end());
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3620
#include <stdio.h> 
#include <ctype.h>

 int main(void){ 
     int count[26]={0}; 
     char ch; 
     int i, n; 
 
 
     while(scanf("%c", &ch)!=EOF){ 
         if(islower(ch)){ 
             n=ch-'a'; 
         }else if(isupper(ch)){ 
             n=ch-'A'; 
         }else{ 
             continue; 
        } 
         count[n]++; 
     } 
     for(i=0;i<26;i++){ 
         printf("%c : %d\n", 'a'+i, count[i]); 
     } 
 
 
     return 0; 
 } 



Measured memory_bytes: 2712
import math
N,M = (int(T) for T in input().split())
S = input()
T = input()

NMG = math.gcd(N,M)
Length = N*M//NMG
Flag   = True
SIndex = [Nk*(M//NMG) for Nk in range(0,N)]
SList  = list(S)

Count = 0
for Mk in range(0,M):
    if Mk%(M//NMG)==0:
        if SList[Count*(N//NMG)]!=T[Mk]:
            Flag = False
            break
        else:
            Count += 1
if Flag:
    print(Length)
else:
    print(-1)

Measured memory_bytes: 13308
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 0
    for a in A:
        while a % 2 == 0:
            a /= 2
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 5040
#include<stdio.h>
int main(){
	long long N, T;
	scanf("%ld %ld", &N,&T);
	
	long long t[N];
	long long t0 = 0;
    for(int i = 0; i < N; i++){
    	scanf("%ld", &t[i]);
	}
	
    for(int j = 0; j < N; j++){

		if(t[j+1]-t[j] < T && j < N-1){
    		t0 = t0 + (t[j+1] - t[j]);
		}else{
			t0 = t0 + T;
		}
	}
	
	printf("%ld", t0);
	return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
 
using namespace std;
using S = set<long long>;
using D = deque<long long>;
using L = vector<long long>;
using M = map<int,long long>;
using A = vector<vector<long long>>;
using Q = priority_queue<long long>;
using U = unordered_map<int,long long>; //mapとの違いはkeyの順番を保持していない

#define sorted(vector) sort(vector.begin(),vector.end()) //O(nlongn)
#define vmin(vector) *min_element(vector.begin(),vector.end()) //O(N)
#define vmax(vector) *max_element(vector.begin(),vector.end()) //O(N)
#define vsum(vector) accumulate(vector.begin(),vector.end(),0) //O(N)
#define vcount(vector,a) count(vector.begin(), vector.end(),a) //O(N)
#define bisect_left(vector,a) (lower_bound(vector.begin(),vector.end(),a)-vector.begin())
#define bisect_right(vector,a) (upper_bound(vector.begin(),vector.end(),a)-vector.begin())
#define vfind(vector,a) find(vector.begin(), vector.end(), a) != vector.end() //遅いからあんまり使うな
//存在確認はmap!!!!!!!!!!!!!
//__gcd(a,b)はコンパイラがGCC時のみ

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    long long n,k,q,pre;
    cin>>n;
    L a(n+1,0),b(n,0);
    long long ans=0,ans2=0;
    for(int i=0  ;i<n+1  ;i++){
        cin>>a[i];
    }
    for(int i=0  ;i<n  ;i++){
        cin>>b[i];
    }
    L a2,b2;
    a2=a;
    b2=b;
    for(int i=0  ;i<n  ;i++){
        ans+=min(b2[i],a2[i]);
        b2[i]-=min(b2[i],a2[i]);
        ans+=min(b2[i],a2[i+1]);
        a2[i+1]-=min(b2[i],a2[i+1]);
    }
    L a3,b3;
    a3=a;
    b3=b;
    for(int i=n-1  ;i==0  ;i--){
        ans2+=min(b3[i+1],a3[i]);
        b3[i+1]-=min(b3[i+1],a3[i]);
        ans2+=min(b3[i],a3[i]);
        b3[i]-=min(b3[i],a3[i]);
    }
    cout<<max(ans2,ans)<<endl;
}
    

Measured memory_bytes: 4992
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<50;
const double pi=acos(-1);
const double eps=1e-6;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,1,1,1,0},DY[8]={1,0,-1,-1,-1,0,1,1};

int n,W;
vi w,v;

int main(){
	cin>>n>>W;
	w=v=vi(n);
	for(int i=0;i<n;i++) cin>>w[i]>>v[i];
	int res=0;
	for(int i=min(n,W/w[0]);i>0;i--){
		vvi dp(i+1,vi(305));
		for(int j=0;j<n;j++){
			vvi DP(i+1,vi(305));
			for(int k=1;k<=i;k++) for(int l=0;l<305;l++){
				DP[k][l]=max(dp[k][l],(l-w[j]+w[0]<0?-inf:dp[k-1][l-w[j]+w[0]]+v[j]));
			}
			dp=DP;
		}
		res=max(res,dp[i][min(304,W-i*w[0])]);
	}
	cout<<res<<endl;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define vec vector

int main(void)
{
    while(1) {
	int n;
	cin >> n;
	if (!n) break;
	int cur = 0, ret = 0;
	int l = 0, r = 0;
	rep(i, n) {
	    string s;
	    cin >> s;
	    if (s == "lu") l = 1;
	    else if (s == "ru") r = 1;
	    else if (s == "ld") l = 0;
	    else r = 0;

	    if (cur == 0 && l == 1 && r == 1) {
		cur = 1;
		ret++;
	    } else if (cur == 1 && l == 0 && r == 0) {
		cur = 0;
		ret++;
	    }
	}
	cout << ret << endl;
    }
    return 0;
}




Measured memory_bytes: 3152
#include<iostream>
#include<string>
#include<cstdlib>
using namespace std;
int pos,n;
string s;
string f();
string expr(){
	string a=f();
	while(isdigit(s[pos])||isalpha(s[pos])){
		if(a.size()>n)
		return a;
		a+=f();
	}
	return a;
}
string f(){
	string t;
	if(isdigit(s[pos])){
		int ret=0;
		for(;isdigit(s[pos]);pos++){
			ret*=10;
			ret+=s[pos]-'0';
		}
		t="";
		string p=f();
		for(int i=0;i<ret;i++){
			t+=p;
			if(t.size()>n)
				return t;
		
		}
	}else if(s[pos]=='('){
		pos++;
		t=expr();
		pos++;
	}else{
		t="";
		for(;isalpha(s[pos]);pos++){
			t+=s[pos];
			if(t.size()>n)
				return t;
		}
	}
	return t;
}
int main(){
	while(cin>>s>>n,s!="0"||n){
		pos=0;
		s+="#";
		string t=expr();
		if(t.size()-1<n)
		cout<<0<<endl;
		else
		cout<<t[n]<<endl;
	}
	return 0;
}

Measured memory_bytes: 3768
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <tuple>
#include <queue>

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

const int inf = 1e9;

void show(const VI &v) {
	for (int i = 0; i < v.size(); i++) {
		printf("%d: %d\n", i+1, v[i]);
	}
}

VI make_dist(int st, const VVI &connect) {
	int n = connect.size();
	VI dist(n, inf);
	queue<int> que;
	que.push(st);
	dist[st] = 0;

	while (!que.empty()) {
		auto x = que.front();
		que.pop();

		for (auto y: connect[x]) {
			if (dist[y] == inf) {
				dist[y] = dist[x] + 1;
				que.push(y);
			}
		}
	}
	return dist;
}

int get_closer(int pos, const VI &dist, const VVI &connect) {
	int to = pos;
	for (auto x: connect[pos]) {
		if (dist[x] < dist[to]) {
			to = x;
		}
	}
	return to;

}

int main() {
	int n, u, v, a, b;
	cin >> n >> u >> v;
	u--;
	v--;


	VVI connect(n);
	for (int i = 0; i < n - 1; i++) {
		cin >> a >> b;
		a--;
		b--;
		connect[a].push_back(b);
		connect[b].push_back(a);
	}


	int ans = 0;
	if (u == v) {
		cout << ans << endl;
		return 0;
	}

	int pos_t = u;
	int pos_a = v;
	auto dist_t1 = make_dist(pos_t, connect);
	auto dist_a1 = make_dist(pos_a, connect);

	// 捕まらない範囲でできるだけ近づく
	// その後、そこから捕まらない方向への最遠点へ
	while (dist_a1[pos_t] - dist_a1[pos_a] > 2) {
		pos_t = get_closer(pos_t, dist_a1, connect);
		pos_a = get_closer(pos_a, dist_t1, connect);
		ans++;
	}

	// printf("takahashi %d, aoki %d, walk %d\n", pos_t+1, pos_a+1, ans);

	auto dist_a2 = make_dist(pos_a, connect);

	// pos_tからpos_aへ近づく辺を切る
	auto connect2 = connect;
	for (auto x: connect[pos_t]) {
		if (dist_a2[x] < dist_a2[pos_t]) {
			// printf("cut %d %d\n", pos_t+1, x+1);
			connect2[pos_t].clear();
			for (auto y: connect[pos_t]) {
				if (y != x) {
					connect2[pos_t].emplace_back(y);
				}
			}
			connect2[x].clear();
			for (auto y: connect[x]) {
				if (y != pos_t) {
					connect2[x].emplace_back(y);
				}
			}
			break;
		}
	}
	auto dist_t2 = make_dist(pos_t, connect2);
	// show(dist_t2);

	int to = pos_t;
	// printf("to %d\n", to+1);
	for (int i = 0; i < n; i++) {
		if (
			connect[i].size() == 1 &&
			dist_t2[i] < dist_a2[i] &&
			dist_t2[i] != inf &&
			dist_t2[i] > dist_t2[to]
		) {
			to = i;
			// printf("change to %d\n", to+1);
		}
	}

	// printf("to %d, dist_t2[%d] %d\n", to+1, to, dist_t2[to]);

	ans += dist_t2[to];
	if (dist_a2[pos_t] == 2) {
		ans += 1;
	}

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


Measured memory_bytes: 12928
def divisor_num(x):
    num = 0
    for i in range(1,int(x**0.5)+1):
        num += (x%i == 0)*2
    num -= (x**0.5).is_integer()
    return num

N = 100000

prime = [-1]*(N+1)
sim2017 = [0]*(N+1)

for i in range(N+1):
    if prime[i] == -1:
        if divisor_num(i) == 2:
            prime[i] = 1
            for j in range(2,N//i+1):
                prime[i*j] = 0
        else:
            prime[i] = 0
    
    if prime[i] == 1 and prime[(i+1)//2 ] == 1:
        sim2017[i] += 1

for i in range(N):
    sim2017[i] += sim2017[i-1]

q = int(input())
for i in range(q):
    l,r = map(int,input().split())
    print(sim2017[r]-sim2017[l-1])

Measured memory_bytes: 7156
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
 
 int main()
 {
   int arr[3]={1,0,0};
   char temp;
   char a,b;
   while(cin>>a>>temp>>b)
   {
     if(a=='A'&&b=='B') swap(arr[0],arr[1]);    
     else if(a=='A'&&b=='C') swap(arr[0],arr[2]);  
     else if(a=='B'&&b=='A') swap(arr[1],arr[0]);  
     else if(a=='B'&&b=='C') swap(arr[1],arr[2]);  
     else if(a=='C'&&b=='A') swap(arr[2],arr[0]);  
     else swap(arr[2],arr[1]);                    
   }
   for(int i=0;i<3;i++)
   {
     if(arr[i]==1)
     {
       if(i==0) cout<<"A"<<endl;
       else if(i==1) cout<<"B"<<endl;
       else cout<<"C"<<endl;
       break;             
     }        
   }
   //while(1);
   return 0;
 }

 

Measured memory_bytes: 3056
#include <stdio.h>

long long minn(long long a[], int n)
{
  long long min = a[0];
  int i;
  for (i = 1; i < n; i++)
    if (a[i] < min)
      min = a[i];
  return min;
}

int main(void)
{
  long long n, ans;
  long long a[5];
  scanf("%lld %lld %lld %lld %lld %lld", &n, &a[0], &a[1], &a[2], &a[3], &a[4]);
  
  ans = 5 + (n - 1) / minn(a, 5);
  printf("%lld\n", ans);
  return 0;
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int keta(int n) {
	int res = 0;
	while (n) n /= 10, res++;
	return res;
}

int main() {
	int n = ri();
	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		if (keta(i) % 2) cnt++;
	}
	std::cout << cnt << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
  string S, T;
  int A, B;
  string U;
  
  cin >> S >> T;
  cin >> A >> B;
  cin >> U;
  
  if (S == U) {
    cout << A - 1 << " " << B << endl;
  }
  
  else if (T == U) {
    cout << A << " " << B - 1 << endl;
  }
   
}


Measured memory_bytes: 256