akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int n=0;
int p=0;
int have[55] = {};
int winner=0;
int judge=0;

int main()
{
    while(1){
        scanf("%d %d",&n,&p);
        if(n==0 && p == 0){
            break;
        }
        int pebble = p;
        for(int j=0;j<n;j++){
            have[j]=0;
        }
        while(1){
            for(int j=0;j<n;j++){
                if(pebble != 0){
                    have[j]++;
                    pebble--;
                    if(have[j] == p){
                        winner = j;
                        judge = 1;
                        break;
                    }
                }else{
                    pebble += have[j];
                    have[j] = 0;
                }
            }
            if(judge == 1){
                cout << winner << endl;
                judge = 0;
                break;
            }
        } 
    }

    return 0;
}


Measured memory_bytes: 3120
#include <stdio.h>

int main(void) {
	int S, M;
	int h, m, s;
	scanf("%d", &S);
	
	h = S/3600;
	
	M = S%3600;
	
	m = M/60;
	
	s = M%60;
	
	printf("%d:%d:%d\n", h, m, s);
	
	return 0;
}

Measured memory_bytes: 592
package main

import (
    "fmt"
)

func main(){
    var n uint64
    fmt.Scan(&n)
    switch {
    case n < 10:
        fmt.Println(n)
    case (n >= 10 && n < 100):
        fmt.Println("9")
    case n == 100:
        fmt.Println("10")
    case (n > 100 && n < 1000):
        ans := n - 90
        fmt.Println(ans)
    case (n >= 1000 && 10000 > n):
        fmt.Println("909")
    case (n == 10000):
        fmt.Println("910")
    case (n > 10000 && n < 100000):
        ans := n - 9090
        fmt.Println(ans)
    case (n == 100000):
        fmt.Println("90909")
    }
}


Measured memory_bytes: 512
n,k = map(int, input().split())
x = list(map(int, input().split()))
ans = 10 ** 9
for i in range(n-k+1):
  a = abs(x[i+k-1] - x[i])
  ans = min(ans,min(abs(x[i+k-1])+a,abs(x[i])+a))
print(ans)


Measured memory_bytes: 62576
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int f(string s){
	stringstream ss;
	int n;
	ss<<s;
	ss>>n;
	return n;
}
int main(void){
	string a;
	unsigned int n,x;
	cin>>n;
	while(n--){
		cin>>a;
		sort(a.begin(),a.end());
		x=f(a);
		reverse(a.begin(),a.end());
		cout<<f(a)-x<<"\n";
	}
} 

Measured memory_bytes: 1240
#include<iostream>
#include<cstdio>
const int N=305;
char s[N][N];
int n,m,k,ans[N][N];
int main() {
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=n;i++) scanf("%s",s[i]+1);
    int tot=0;
    for(int i=1;i<=n;i++) {
        bool ok=false;
        for(int j=1;j<=m;j++) {
            if(s[i][j]=='#') ans[i][j]=++tot,ok=true;
            else ans[i][j]=ans[i][j-1];
        }
        if(ok) {
            for(int j=m;j;j--) if(!ans[i][j]) ans[i][j]=ans[i][j+1];
        }
        else {
            for(int j=1;j<=m;j++) {
                ans[i][j]=ans[i-1][j];
            }
        }
    }
    for(int i=n-1;i;i--) for(int j=1;j<=m;j++) {
        if(!ans[i][j]) ans[i][j]=ans[i+1][j];
    }
    for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) printf("%d%c",ans[i][j]," \n"[j==m]);
    return 0;
}


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

int main(){
    int n,i;
    vector<int> p(51);
    cin >> n;
    for(i = 0;i < n;i++){
        cin >> p.at(i);
    }
    int count = 0;
    for(i = 0;i < n;i++){
        if(p.at(i) != i+1){
            count++;
        }
        if(count > 2) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <vector>
#include <string>
#include <bitset>
#include <queue>
#include <tuple>
#include <regex>
#include <cmath>
#include <map>
#include <cstring>

template<typename T> bool chmax( T &a, const T b ) { if ( a <= b ) { a = b; return ( true ); } else { return ( false ); } }
template<typename T> bool chmin( T &a, const T b ) { if ( a >= b ) { a = b; return ( true ); } else { return ( false ); } }

using namespace std;

using ll = long long;
using Pint = pair<int, int>;
using Pll  = pair<ll, ll>;

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define F first
#define S second

#define rep( i, n ) for ( int i = 0; i < (int)( n ); ++i )
#define reps( i, n ) for ( int i = 1; i <= (int)( n ); ++i )
#define rrep( i, n ) for ( int i = (int)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( int i = (int)( ( n ) ); i > 0; --i )
#define arep( i, v ) for ( auto &&i : ( v ) )

template<typename T> T gcd( const T a, const T b ) { return ( b ? gcd( b, a % b ) : a ); }
template<typename T> T lcm( const T a, const T b ) { return ( a / gcd( a, b ) * b ); }

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()
#define UNIQUE( c ) ( c ).erase( unique( ( c ).begin(), ( c ).end() ), ( c ).end() )

constexpr ll MOD = 1000000007LL;
template<typename T = ll> constexpr T MAX = numeric_limits<T>::max();

int main()
{
	ll N; cin >> N;
	ll U, V; cin >> U >> V;
	--U; --V;
	vector<vector<ll>> g( N );
	rep( i, N - 1 )
	{
		ll a, b; cin >> a >> b;
		--a; --b;
		g[a].eb( b );
		g[b].eb( a );
	}

	vector<ll> dist( N, 0 );
	auto dfs = [&]( auto &&dfs, ll p, ll v ) -> void {
		arep( it, g[v] )
		{
			if ( p != it )
			{
				dist[it] = dist[v] + 1;
				dfs( dfs, v, it );
			}
		}
	};
	dfs( dfs, -1, V );

	ll ans = 0;
	auto dfs2 = [&]( auto &&dfs2, ll p, ll v, ll d ) -> void {
		if ( d >= dist[v] ) return;
		ans = max( ans, dist[v] - 1 );
		arep( it, g[v] ) if ( p != it ) dfs2( dfs2, v, it, d + 1 );
	};
	dfs2( dfs2, -1, U, 0 );

	cout << ans << endl;

	return ( 0 );
}


Measured memory_bytes: 11776
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

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

int main(){
    int a, b;
    cin >> a >> b;
    vector<int> vec1(2000),vec2(2000);
    vector<bool> flag(2000);
    rep(i,2000){
        vec1[i] = i * 0.08;
        vec2[i] = i * 0.1;
    }

    rep(i,2000){
        if(vec1[i] == a && vec2[i] == b){
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <math.h>
#include <utility>
#include <stack>
#include <string.h>
#include <complex>
using namespace std;

const int INF = 1<<29;
const double EPS = 1e-8;
typedef vector<int> vec;
typedef pair<int,int> P;
struct edge{int to,cost;};

int main(){

    while(1){
        int b,r,g,c,s,t;
        scanf("%d%d%d%d%d%d",&b,&r,&g,&c,&s,&t);
        if(!b&&!r&&!g&&!c&&!s&&!t)break;
        cout << 100 + b*15 + b*5*13 + r*15 + r*3*13 + g*7 + c*2 - 3*(t - (b*5 + r*3 + s)) << endl;
    }

    return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <vector>
#include <algorithm>
#define pb push_back
#define mp make_pair
using namespace std;

struct T {
	vector<long long> t;

	void init(int n) {
		t.resize(4 * n);
	}

	void pull(int v) {
		t[v] = max(t[2 * v], t[2 * v + 1]);
	}

	void build(int v, int tl, int tr) {
		if (tl == tr) {
			t[v] = 0;
		} else {
			int mid = tl + tr >> 1;
			build(2 * v, tl, mid);
			build(2 * v + 1, mid + 1, tr);
			pull(v);
		}
	}

	void set(int v, int tl, int tr, int i, long long val) {
		if (i < tl or i > tr) return;
		else if (i == tl and i == tr) {
			t[v] = val;
		} else {
			int mid = tl + tr >> 1;
			set(2 * v, tl, mid, i, val);
			set(2 * v + 1, mid + 1, tr, i, val);
			pull(v);
		}
	}

	long long get(int v, int tl, int tr, int l, int r) {
		if (tl > r or tr < l) return 0;
		else if (tl >= l and tr <= r) return t[v];
		else {
			int mid = tl + tr >> 1;
			return max(get(2 * v, tl, mid, l, r), get(2 * v + 1, mid + 1, tr, l, r));
		}
	}
};

void solve() {
	int n; cin >> n;
	vector<int> h(n + 1);
	vector<int> a(n + 1);
	vector<long long> dp(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> h[i];
	}
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	T tree;
	tree.init(n);
	tree.build(1, 1, n);
	for (int i = 1; i <= n; i++) {
		long long mx = tree.get(1, 1, n, 1, h[i]);
		dp[i] = mx + a[i];
		tree.set(1, 1, n, h[i], dp[i]);
	}
	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		ans = max(ans, dp[i]);
	}
	cout << ans << endl;
}

int main() {
	solve();
	return 0;
}

Measured memory_bytes: 9600
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    N = int(input())
    
    def dfs(v):
        visited[v] = 1
        for cost, nv in edge[v]:
            if visited[nv] == 1:
                continue
            d[nv] = d[v] + cost
            dfs(nv)

    #N:頂点数   W:辺数
    edge = [[] for i in range(N)]
    #edge[i] : iから出る道の[重み,行先]の配列
    for _ in range(N-1):
        x,y,z = map(int,input().split())
        edge[x-1].append((z,y-1))
        edge[y-1].append((z,x-1))

    q,k = map(int, input().split())
    d = [-1]*N
    d[k-1] = 0
    visited = [0]*N
    dfs(k-1)

    for _ in range(q):
        x,y = map(int, input().split())
        print(d[x-1]+d[y-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 151640
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a.append(0)
b.append(0)
b.append(0)
ans = 0
for i in range(n+1):
    if a[i]-b[i] > 0:
        ans += b[i]
    elif a[i]-b[i] <= 0 and a[i] + a[i+1] >= b[i]:
        b[i+1] += b[i]-a[i]
        ans += a[i]
    else:
        b[i+1] += a[i+1]
        ans += a[i]
print(ans)

Measured memory_bytes: 18476
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
    x=0;char c=getchar();bool f=0;
    while(!isdigit(c)) f|=c=='-',c=getchar();
    while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
    if(f) x=-x;return  x;
}
template<class t> inline void write(t x){
    if(x<0){putchar('-'),write(-x);}
    else{if(x>9)write(x/10);putchar('0'+x%10);}
}

#define int long long

const int N=55,M=25;
int en,f[N],d[N],h[N],s[M],n,m,ans;

struct edge{
	int n,v;
}e[N<<1];

void add(int x,int y){
	e[++en]=(edge){h[x],y};
	h[x]=en;
}

void dfs(int x){
	d[x]=d[f[x]]+1;
	for(int i=h[x];i;i=e[i].n){
		int y=e[i].v;
		if(y==f[x]) continue;
		f[y]=x;
		dfs(y);
	}
}

signed main(){
	read(n);
	for(int i=1,x,y;i<n;i++){
		read(x);read(y);
		add(x,y);add(y,x);
	}
	dfs(1);
	read(m);
	for(int i=0,x,y;i<m;i++){
		read(x);read(y);
		if(d[x]<d[y]) swap(x,y);
		while(d[x]^d[y]) s[i]|=1ll<<x-1,x=f[x];
		while(x^y) s[i]|=(1ll<<x-1)|(1ll<<y-1),x=f[x],y=f[y];
	}
	int lim=1<<m;
	for(int i=0;i<lim;i++){
		int cnt=0,now=0,tot=0;
		for(int j=0;j<m;j++) if(i>>j&1) cnt++,now|=s[j];
		for(int j=0;j<n;j++) if(now>>j&1) tot++;
		tot=1ll<<(n-1-tot);
		if(cnt&1) ans-=tot;
		else ans+=tot;
	}
	write(ans);
//	write((1ll<<n-1)-ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct point{int x;int y;};
int i,j,k,count1=0,count2=0;

int main(){
    long long int ans=1,def=1;
    int n;
    cin>>n;
    int x;
    for(i=0;i<n;i++){
        cin>>x;
        ans*=3;
        if(x%2==0){
            def*=2;
        }else{
            def*=1;
        }
    }
    cout<<ans-def<<endl;
}


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

#define int long long
int n, a, b, c, d;
bool ok = 1;
string s;

signed main(){
    cin >> n >> a >> b >> c >> d;
    a--;
    b--;
    c--;
    d--;
    cin >> s;
    if(c > d){
        bool ok2 = 0;
        for(int i = b; i <= d; i++){
            if(s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.'){
                ok2 = 1;
                break;
            }
        }
        ok &= ok2;
    }
    bool ok3 = 1;
    for(int i = a + 1; i < c - 1; i++){
        if(s[i] == '#' && s[i + 1] == '#'){
            ok3 = 0;
            break;
        }
    }
    ok &= ok3;
    ok3 = 1;
    for(int i = b + 1; i < d - 1; i++){
        if(s[i] == '#' && s[i + 1] == '#'){
            ok3 = 0;
            break;
        }
    }
    ok &= ok3;
    if(ok) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 640
while True:
    N = int(input())
    if N == 0:
        break
    sum = 0
    s = input().split()
    for i in range(N):
        sum += int(s[i])
    mean = sum/N
    t = 0
    for j in range(N):
        t += (int(s[j]) - mean)**2
    b = t / N
    a = b**0.5
    print('{:.08f}'.format(a))



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

int par[100005];
int high[100005];
//n要素で初期化
void init(int n){
  for(int i=0; i<n; i++){
    par[i]=i;
    high[i]=0;
  }
}
//木の根を求める
int find(int x){
  if(par[x]==x){
    return x;
  }
  else{
    return par[x]=find(par[x]);
  }
}

//xとyの属する集合を併合
void unite(int x,int y){
  x=find(x);
  y=find(y);
  if(x==y)return;
  if(high[x]<high[y]){
    par[x]=y;
  }else{
    par[y]=x;
    if(high[x]==high[y])high[x]++;
  }
}
//xとyが同じ集合に属するか否か
bool same(int x,int y){
  return find(x)==find(y);
}   
int main(){
	ll n,m;
  	cin>>n>>m;
  	init(n);
  	int p[n];
  	for(int i=0; i<n; i++){
      	cin>>p[i];
      	p[i]--;
    }
  	for(int i=0; i<m; i++){
      int x,y;
      cin>>x>>y;
      x--; y--;
      unite(p[x],p[y]);
    }
  	int cnt=0;
  	for(int i=0; i<n; i++){
      if(same(i,p[i])){cnt++;}
    }
     cout<<cnt<<endl; 
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(long long i=0;i<n;i++)
#define REP1(i,n) for(long long i=1;i<=n;i++)
#define PER(i,n) for(long long i=((n)-1);i>=0;i--)
#define PER1(i,n) for(long long i=(n);i>0;i--)
#define REP2D(i,j,w,h) for(long long i=0;i<h;i++) for(long long j=0;j<w;j++)
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define FORE(i,a,b) for(long long i=(a);i<=(b);i++)
#define ITE(arr) for(auto ite=(arr).begin();ite!=(arr).end();++ite)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define YNPRT(b) cout<<((b)?"Yes":"No")<<endl
#define REV(arr) reverse(ALL(arr))
#define PRT(a) cout<<a<<endl;
#define PRTLST(arr,num) REP(_i,num) cout<<_i<<" - "<<arr[_i]<<endl;
#define PRTLST2(arr2,d1,d2) REP(_i,d1) REP(_j,d2) cout<<_i<<","<<_j<<" : "<<arr2[_i][_j]<<endl;
#define PRTLST2D(arr2,d1,d2) do{cout<<"L\t";REP(_i,d2) cout<<_i<<"\t"; cout<<endl; REP(_i,d1){cout<<_i<<"\t";REP(_j,d2){cout<<arr2[_i][_j]<<"\t";}cout<<endl;}}while(0);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF_INT = 2147483647;
const ll INF_LL = 9223372036854775807LL;
const ull INF_ULL = 18446744073709551615Ull;
const ll P = 92540646808111039LL;
const int Move[4][2] = {-1,0,1,0,0,1,0,-1};
const int Move_[8][2] = {-1,-1,-1,0,-1,1,0,-1,0,1,1,-1,1,0,1,1};

//---------------------
#define MAXN 300
//---------------------


template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {os<<"{"; ITE(v) os << *ite << " ";os<<"}";return os;}

ll n,w[MAXN];
ll dpmem[MAXN][MAXN];
vector<ll> idtomove[MAXN];


bool init(){
	n=0;
	ZERO(w);
	MINUS(dpmem);
	REP(i,MAXN) idtomove[i].clear();
	cin>>n;
	if(n<=0) return false;
	REP2D(i,j,n,n) if(i>=j) dpmem[i][j]=0;
	REP(i,n) cin>>w[i];
	REP(i,n){
		for(int j=i+1;j<n;j++){
			if(abs(w[j]-w[i])<=1.1) idtomove[i].push_back(j);
		}
	}
	return true;
}

bool canberemoved(ll a,ll b){
	return abs(w[a]-w[b])<=1.1;
}

ll dp(ll l,ll r){
  	if(l>=n || r>=n || l<0 || r<0) return 0;
  	if(dpmem[l][r]>=0) return dpmem[l][r];
  	ll ret=-1;
	if(r-l==1){
		if(canberemoved(l,r)) ret=dpmem[l][r]=2;
		else ret=0;
	}
	else{
		ITE(idtomove[l]) if(*ite<=r && dp(l+1,(*ite)-1)==((*ite)-l-1)) ret=max(ret,(*ite)-l+1+dp((*ite)+1,r));
		ret=max(ret,dp(l+1,r));
	}
	return dpmem[l][r]=ret;
}

int main(){
	while(init()){
		cout<<dp(0,n-1)<<endl;
		//PRTLST2D(dpmem,n,n);
	}
	return 0;
}


Measured memory_bytes: 4008
import math 
import bisect
import heapq
from operator import mul
from collections import deque

n, q = map(int, input().split())
g=[[] for _ in range(n)]

for i in range(n-1):
    a,b=map(int,input().split())
    g[a-1].append(b-1)
    g[b - 1].append(a - 1)
c = [0] * n

for j in range(q):
    p, x = map(int, input().split())
    c[p - 1] += x

seen = [0] * n
seen[0] = 1
next = deque([0])


while next:
    v = next.popleft()
    cost = c[v]

    for nv in g[v]:

        if seen[nv]:
            continue
        seen[nv] = 1
        next.append(nv)
        c[nv] += cost

print(*c)




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

int main(int argc, char const *argv[]) {
  int x, y;
  cin >> x >> y;
  double fx = x, fy = y;

  printf("%d %d %.5f\n", x / y, x % y, fx / fy);

  return 0;
}



Measured memory_bytes: 3204
/*
Author : farhan132
*/
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef pair<ll , ll> lli;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
typedef vector<lli> vlli;
typedef pair < ll , pair < ll , ll > > cm;

#define ff first
#define ss second
#define pb push_back
#define in insert
#define f0(b) for(int i=0;i<(b);i++)
#define f00(b) for(int j=0;j<(b);j++)
#define f1(b) for(int i=1;i<=(b);i++)
#define f11(b) for(int j=1;j<=(b);j++)
#define f2(a,b) for(int i=(a);i<=(b);i++)
#define f22(a,b) for(int j=(a);j<=(b);j++)
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld", &a , &b)
#define pf(a) printf("%lld\n",a)
#define pff(a,b) printf("%lld %lld\n", a , b)
#define PI 3.14159265359
#define bug printf("**!\n")
#define mem(a , b) memset(a, b ,sizeof(a))
#define front_zero(n) __builtin_clzll(n)
#define back_zero(n) __builtin_ctzll(n)
#define total_one(n) __builtin_popcountll(n)
#define clean cout.flush()

const ll mod = (ll)1e9+7;
const ll maxn = (ll)1e5+100;
const int nnn = 664579+500;
const int inf = numeric_limits<int>::max()-1;
//const ll INF = numeric_limits<ll>::max()-1;
const ll INF = 1e18;

ll dx[]={0,1,0,-1};
ll dy[]={1,0,-1,0};
ll dxx[]={0,1,0,-1,1,1,-1,-1};
ll dyy[]={1,0,-1,0,1,-1,1,-1};


//ifstream rr ("prog.txt");

void setIO(string name = "") { 
    ios_base::sync_with_stdio(0); cin.tie(0); 
    if((name).size()){
        freopen((name+".in").c_str(), "r", stdin); 
        freopen((name+".out").c_str(), "w", stdout);
    }
}

ll dp[3][1000006];
void solve(){
	
	ll n , x;
	cin >> n >> x;
	ll a[n+5];
	ll b[n+5];
	f1(n) cin >>b[i] >> a[i];
	f00(3){f0(100001) dp[j][i] = INF;}
	dp[0][0] = 0;
	for(ll i = 1; i <= n; i++){
		for(ll j = 0; j <= 100000; j++){
			dp[1][j] = min(dp[1][j] , dp[0][j]);
			if(a[i] <= j)dp[1][j] = min(dp[1][j] , dp[0][j-a[i]]+b[i]);
		}
		swap(dp[1] , dp[0]);
	}
	ll ans = -1;
	f0(100001){
		if(dp[0][i] <= x) ans = i;
	}
	cout << ans;
	return;
}

int main() {
   
   //ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    ll T;
    T=1;
    setIO();
   // cin >> T;
    //scanf("%lld",&T);
    ll CT = 0;
    
    //work();
    while(T--){
    	//cout << "Case #" << ++CT <<": " ;
    	//printf("Case %lld: ",++CT);
		solve();
	}
	
    return 0;
}
/*


*/



Measured memory_bytes: 20044
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    int n;
    cin >> n;
    vector<int> b;
    rep(i, n-1){
        int x;
        cin >> x;
        b.push_back(x);
    }
    int res=b[0]+b[n-2];
    rep(i, n-2){
        res += min(b[i], b[i+1]);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <memory>
#include <stack>

using namespace std;

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

        vector<double> P(n + 1);
        vector<double> dp(n + 1, 0.0f);
        for (int i = 0; i < n; i++)
            cin >> P[i];

        dp[0] = 1;
        for (int coin = 0; coin < n; coin++)
        {
            for (int i = coin + 1; i >= 0; i--)
            {
                dp[i] = ((i == 0) ? 0 : dp[i - 1] * P[coin]) + dp[i] * (1 - P[coin]);
            }
        }

        double ans = 0;
        for (int i = 0; i <= n; i++)
        {
            int head = i;
            int tail = n - head;
            if (head > tail)
                ans += dp[i];
        }

        printf("%0.10lf", ans);
  return 0;
}


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

int main(){
  int n;
  cin >> n;
  if(n%1000==0){
    cout << 0 << endl;
    return 0;
  }
  cout << 1000-n%1000 << endl;
  return 0;
}


Measured memory_bytes: 3620
class MyBinaryNode
  attr_accessor :parent, :left, :right

  def initialize
    @parent = -1
    @left = -1
    @right = -1
  end
end

def pre_order(nodes, id)
  if id == -1
    return 
  end
  print ' '
  print id
  pre_order(nodes, nodes[id].left)
  pre_order(nodes, nodes[id].right)
end

def in_order(nodes, id)
  if id == -1
    return 
  end
  in_order(nodes, nodes[id].left)
  print ' '
  print id
  in_order(nodes, nodes[id].right)
end

def post_order(nodes, id)
  if id == -1
    return 
  end
  post_order(nodes, nodes[id].left)
  post_order(nodes, nodes[id].right)
  print ' '
  print id
end

n = gets.to_i
nodes = []
n.times do
  nodes << MyBinaryNode.new
end

n.times do
  inputs = gets.split.map(&:to_i)
  node_id = inputs.shift
  node = nodes[node_id]
  left = inputs.shift
  if left != -1
    node.left = left
    left_node = nodes[left]
    left_node.parent = node_id
  end
  right = inputs.shift
  if right != -1
    node.right = right
    right_node = nodes[right]
    right_node.parent = node_id
  end
end

root_id = nil
nodes.each_with_index do |node, i|
  if node.parent == -1
    root_id = i
  end
end

puts "Preorder"
pre_order(nodes, root_id)
puts ""

puts "Inorder"
in_order(nodes, root_id)
puts ""

puts "Postorder"
post_order(nodes, root_id)
puts ""


Measured memory_bytes: 6880
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#define rep(i,s,e) for(int i=s;i<=e;i++)
#define rep1(i,s,e) for(int i=s;i<e;i++)
#define rep2(i,s,e,c) for(int i=s;i>=e;i--)
#define pfi(x) printf("%d\n",x)
#define pfl(x) printf("%lld\n",x)
#define pfn() printf("\n")
#define pfs() printf(" ")
#define sfi(x) scanf("%d",&x)
#define sfi1(x,y) scanf("%d%d",&x,&y)
#define sff(x) scanf("%lf",&x)
#define sfl(x) scanf("%lld",&x)
#define memset1(x) memset(x,0,sizeof(x))
using namespace std;
typedef long long ll;
const int MAX = 1e4 + 50;
const int mod = 996873654;
int main(){
	int n;
	string s;
	cin>>n>>s;
	if(n<3200) cout<<"red\n";
	else cout<<s<<endl;
	return 0;
}

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

int main()
{

int a;
int b;

	cin >> a;
	cin >> b;

	if( a % 2 == 0 || b % 2 == 0 )
		cout << "Even" << endl;
	else
		cout << "Odd" << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;

int main(){
    int N;cin>>N;
    int A[100010],B[100010],C[100010];
    for(int i=0;i<N;i++)cin>>A[i];
    for(int i=0;i<N;i++)cin>>B[i];
    for(int i=0;i<N;i++)cin>>C[i];
    sort(A,A+N);sort(B,B+N);sort(C,C+N);
    ll ans=0;
    int i=0,j=0,k=0;
    while(j<N){
        while(A[i]<B[j] && i<N)i++;
        while(C[k]<=B[j] && k<N)k++;
        ans+=(ll)(N-k)*(ll)i;
        j++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define ll long long
#define vl vector
#define pb push_back
#define ld long double
#define ff first
#define ss second
using namespace std;

ll fact(ll a)
{
    if(a==0) return 1;
    else return a*fact(a-1);
}

vl<ll> divisor(ll n)
{
    vl<ll> v;
    for(int i=2;i<=sqrt(n);i++)
    {
        if(n%i==0) 
        {
            if(n/i==i) v.pb(i);
            else
            {
                v.pb(i);
                v.pb(n/i);
            }
        }
    }
    return v;
}

int main()
{
    ll i,j,n,k,t,m,a,b;
    vl<ll> v;
    cin>>n;
    for(i=0;i<=1000000;i+=1000)
    {
        if(i>=n) break;
    }
    cout<<i-n;
}

Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<cctype>
#include<iomanip>
#include<limits>
#include<bitset>

using namespace std;
typedef long long int ll; typedef pair<int, int> P; typedef unsigned long long int ull;
const ll mod = 1e9 + 7;
const int inf = 1e9 + 7;
const ll linf = 1LL << 60;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define REP(i,m,n) for(int i=(m);i<(int)n;i++)
#define all(a) (a).begin(),(a).end()
#define allg(a) (a).begin(),(a).end(),greater<>()
#define SUM(a) accumulate((a).begin(),(a).end(),0)
#define d10 std::setprecision(10)
#define d20 std::setprecision(20)
#define sz size()
#define vec vector<int>
using str = string;
const double PI = 3.14159265359;
ll gcd(ll a, ll b) { ll t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
int gcd(int a, int b) { int t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
ll recfact(ll start, ll n) {
	ll i;
	if (n <= 16) {
		ll r = start;
		for (i = start + 1; i < start + n; i++) r = r * i % mod;
		return r % mod;
	}
	i = n / 2;
	return recfact(start, i) % mod * recfact(start + i, n - i) % mod;
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}
ll fct(ll n) { return recfact(1, n); }
ll ncm(ll n, ll m) {
	if (n < m)return 0;
	ll x = (fct(n) % mod / (fct(m) * fct(n - m)) % mod) % mod;
	return x;
}
std::string sreverse(string str, int firstItr, int secondItr) {
	if (firstItr < 0 || secondItr>int(str.size() - 1))return str;
	while (firstItr < secondItr) {
		swap(str[firstItr], str[secondItr]);
		firstItr++; secondItr--;
	}
	return str;
}
std::string RunLengthEncoding(std::string str) {
	int itr = 0; std::string res;
	while (itr < int(str.size())) {
		char tmp = str[itr++];
		int length = 1;
		while (itr <int(str.size()) && str[itr] == tmp) { ++itr; ++length; }
		res.push_back(tmp);
		res += to_string(length);
	}
	return res;
}
std::string split(std::string str, size_t first_itr, bool isFront) {
	if (first_itr < 0 || first_itr > str.size()) {
		return str;
	}
	else {
		if (isFront) {
			std::string tmp;
			for (size_t i = 0; i < first_itr; i++) {
				tmp.push_back(str.at(i));
			}
			return tmp;
		}
		else {
			std::string tmp;
			for (size_t i = first_itr; i < str.size(); i++) {
				tmp.push_back(str.at(i));
			}
			return tmp;
		}
	}
}


bool dfs(int depth, int now) {
	/*if (depth == n)return !now;
	for (int i = 0; i < k; i++) {
		if (dfs(depth + 1, now ^ t[depth][i]))return true;
	}
	/**/
	return false;
}

#define N 1000000
bool prime[N];
void eratosthenes(bool prime[]) {
	rep(i, N) prime[i] = 1;
	prime[0] = prime[1] = 0;
	rep(i, N) {
		if (prime[i]) {
			for (int j = i + i; j < N; j += i) {
				prime[j] = 0;
			}
		}
	}
}


int main() {
	int a; cin >> a;
	eratosthenes(prime);
	rep(i, N) {
		if (prime[i] && i >= a) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <bits/stdc++.h>

using namespace std;


long long int a;

int main(){
  cin >> a;

	if( a%11 == 0){
      
      cout << (a/11)*2<< endl;
    }
  
  else if(a%11 >6){
    cout << (a/11)*2+2 << endl;
  }
  
  else{
    cout << (a/11)*2+1 << endl;
  }
}
  
 

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

char str[100][100];
int main(){
	int h, w;
	scanf("%d%d", &h, &w);
	for(int i = 0;i < h;i++)scanf("%s", str[i]);
	for(int i = 0;i < w+2;i++)printf("#");
	printf("\n");
	for(int i = 0;i < h;i++){
		printf("#");
		for(int j = 0;j < w;j++)printf("%c", str[i][j]);
		printf("#\n");
	}
	for(int i = 0;i < w+2;i++)printf("#");
	printf("\n");
	return 0;
}


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


int main() {
	int n;
	cin >> n;
	if (n == 7 || n == 5 || n == 3)
		cout << "YES";
	else
		cout << "NO";
	cout << endl;
}


Measured memory_bytes: 3564
# include <algorithm>
# include <cassert>
# include <cctype>
# include <cstdio>
# include <cstdlib>
# include <cstring>
# include <cmath>
# include <iostream>
# include <map>
# include <queue>
# include <set>
# include <sstream>
# include <stack>
# include <string>
# include <vector>
# include <iomanip>

# define rep(i, n) for (int i = 0; i < (int)(n); i++)
# define irep(i, n) for (int i = int(n) - 1; i >= 0; i--)
# define FOR(i, m, n) for (int i = int(m); i < (int)(n); i++)

using namespace std;

void pretty_print(vector<int> &A) {
  cout << A[0];
  for (int i = 1; i < A.size(); i++) cout << ' ' << A[i];
  cout << endl;
}

void isort(vector<int> &A) {
  for (int i = 1; i < A.size(); i++) {
    pretty_print(A);
    // choice base element
    int v = A[i];

    int j = i - 1;

    // if i = 3
    //
    // while: 
    // 1: j = 2 A[3] = A[2] if A[j] > v
    // 2: j = 1 A[2] = A[1] if A[j] > v
    // 3: j = 0 A[1] = A[0] if A[j] > v
    while (j >= 0 && A[j] > v) {
      A[j+1] = A[j];
      j--;
    }

    A[j+1] = v;
  }
}


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

  vector<int> A(N);
  rep (i, N) cin >> A[i];

  isort(A);
  pretty_print(A);
}

Measured memory_bytes: 3112
#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 pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n,m;
  cin>>n>>m;

  ll l=m/2+m%2;
  vpl ans(m);
  ll cur=1;
  ll cnt=0;
  for(ll i=l-1; i>=0; i--){
    ll p=cur+1+2*i;
    ans[cnt]=pll(cur,p);
    cnt++;
    cur++;
  }

  ll r=m/2;
  cur=2*l+1;
  for(ll i=r-1; i>=0; i--){
    ll p=cur+2+2*i;
    ans[cnt]=pll(cur,p);
    cnt++;
    cur++;
  }

  REP(i,m)cout<<ans[i].FI<<" "<<ans[i].SE<<endl;

}



Measured memory_bytes: 4496
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	const inputLines = input.split("\n");
	const line0 = inputLines[0];
	const line0vars = line0.split(" ");

	const a = parseInt(line0vars[0], 10);

	console.log(a + Math.pow(a, 2) + Math.pow(a, 3));

	// tmp = input[1].split(" ");
	// //文字列から10進数に変換するときはparseIntを使います
	// var a = parseInt(input[0], 10);
	// var b = parseInt(tmp[0], 10);
	// var c = parseInt(tmp[1], 10);
	// var s = input[2];

	//出力
	// console.log('%d %s',a+b+c,s);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

// node index.js
// 1
// 2 3
// test
// (Ctrl + D)


Measured memory_bytes: 29712
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using ll = long long;
using namespace std;

int main() {
    ll a = 0, b = 0;
    cin >> a >> b;
    if (a*b <= 0) {
        cout << "Zero" << endl;
    }
    else {
        if (a > 0) {
            cout << "Positive" << endl;
        }
        else {
            if ((b-a)%2 == 0) {
                cout << "Negative" << endl;
            }
            else {
                cout << "Positive" << endl;
            }
        }
    }
    return 0;
}


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

namespace G{
	int count = 0;
}

void eat(vector<int> &v, int prev)
{

	//for (int i : v) cout << i << " ";
	int max=0, maxx=0;
	int max_ite=0, maxx_ite=0;
	for (int i = 0; i < v.size(); ++i)
	{
		if (max < v[i])
		{
			maxx = max;
			maxx_ite = max_ite;
			max = v[i];
			max_ite = i;
		}
		else if (maxx < v[i])
		{
			maxx = v[i];
			maxx_ite = i;
		}
	}
	//cout << "max=" << max << " maxx=" << maxx << " max_ite=" << max_ite << " maxx_ite=" << maxx_ite << " prev=" << prev << endl;
	if (maxx == 0 && max_ite == prev)
	{
		G::count += max;
		return;
	}

	if (prev != max_ite)
	{
		v[max_ite]--;
		eat(v, max_ite);
	}
	else
	{
		v[maxx_ite]--;
		eat(v, maxx_ite);
	}
}

int main()
{
	int K, T;
	cin >> K >> T;
	vector<int> v(T);
	for (int i = 0; i < T; ++i)
	{
		cin >> v[i];
	}
	//

	eat(v, -99);
	cout << G::count << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        final Scanner scanner = new Scanner(System.in);
        final String input = scanner.nextLine();
        final String[] coinSize = input.split(" ");
        final int[] coinSizeInt = { Integer.parseInt(coinSize[0]), Integer.parseInt(coinSize[1]) };

        int score = 0;
        for (int i = 0; i < 2; i++) {
            if (coinSizeInt[0] > coinSizeInt[1]) {
                score += coinSizeInt[0];
                coinSizeInt[0]--;
            } else {
                score += coinSizeInt[1];
                coinSizeInt[1]--;
            }
        }

        System.out.println(score);
    }
}


Measured memory_bytes: 23508
#カントリーロード
t=int(input())
for i in range(t):
    N,K=map(int, input().split())
    X=list(map(int,input().strip().split()))
    a=[0]
    for j in range(N-1):
        a.append(X[j+1]-X[j])
    b=sorted(a, reverse=True)
    if K>1:
        del b[0:K-1]

    print(sum(b))   


Measured memory_bytes: 22104
#include <bits/stdc++.h>
#define ll long long
#define MOD 1000000007

using namespace std;

const ll maxn = 200;
const ll mx = 10;
ll n, f[maxn][mx], p[maxn][mx + 1], a[mx];

int main()
{
    cin >> n;
    for (ll i = 0; i < n; ++i) {
        for (ll j = 0; j < mx; ++j) {
            cin >> f[i][j];
        }
    }
    for (ll i = 0; i < n; ++i) {
        for (ll j = 0; j < mx + 1; ++j) {
            cin >> p[i][j];
        }
    }
    ll ans = -1e18;
    for (ll sub = 1; sub < (1 << mx); ++sub) {
        for (ll i = 0; i < mx; ++i) {
            a[i] = (sub >> i) & 1;
        }
        ll res = 0;
        for (ll i = 0; i < n; ++i) {
            ll cnt = 0;
            for (ll j = 0; j < mx; ++j) {
                if (a[j] == 1 && f[i][j] == 1)
                    cnt += 1;
            }
            res += p[i][cnt];
        }
        ans = max(ans, res);
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  ll n;
  cin >> n;
  vector<pair<ll,ll>> p(n);
  rep(i,n) {
    ll a, b;
    cin >> a >> b;
    p[i].first = b;
    p[i].second = a;
  }
  sort(p.begin(), p.end());
  
  ll time = 0;
  bool ok = true;
  rep(i,n) {
    time += p[i].second;
    if (time > p[i].first) {
      ok = false;
      break;
    }
  }
  if (ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;



int main(void) {
	
	while (1) {
		int n, m, a;
		int now;

		cin >> n >> m >> a;
		if (n == 0) {
			break;
		}
		vector<int>h(m), p(m), q(m);
		vector< pair<int, int> > dp(m);
		now = a;
		FOR(i, 0, m-1) {
			cin >> h[i] >> p[i] >> q[i];
			dp[i].first = h[i];
			dp[i].second = i;
		}
		sort(dp.begin(), dp.end());
		RFOR(i, m - 1, 0) {
			if (p[dp[i].second] == now) {
				now = q[dp[i].second];
			}
			else if (q[dp[i].second] == now) {
				now = p[dp[i].second];
			}
		}
		cout << now << endl;
	}

}


Measured memory_bytes: 3108
#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>;
const int INF = 100000000;

int main() {
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n, 0);
    ll sum = 0;
    rep(i, n){
        cin >> a[i];
        sum += a[i];
    }
    ll j = sum / (4 * m);
    ll count = 0;
    rep(i,n){
        if ((sum%(4 * m)==0)&&(a[i] >= j)) count++;
        if ((sum%(4 * m)!=0)&&(a[i] > j)) count++;
    }
    string ans = "No";
    if (count >= m) ans = "Yes";
    cout << ans << endl;
}

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

using namespace std;

int main()
{
	long long int N, K;
	cin >> N >> K;

	vector<int> H(N);
	long long int total = 0;

	for (int i = 0; i < N; i++) 
	{
		cin >> H.at(i);
		total += H.at(i);
	}
	sort(H.begin(), H.end(), std::greater<int>());

	for (int i = 0; i < min(K,N); i++) 
	{
		total -= H.at(i);
	}

	cout << total << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<numeric>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<iomanip>
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,from,to) for(int i=from;i<to;i++)
#define repd(i,from,till) for(int i=from;i>=till;i--)
#define waste ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inf 1e9+1
#define mod 1e9+7
#define inf1 1e18+1
#define pie 3.14159265358979323846
#define N 100005
using namespace std;

int solve(){	
	string n;
	cin>>n;
	rep(i,0,3){
		if(n[i]==n[i+1]){
			cout<<"Bad"<<endl;
			return 0;
		}
	}
	cout<<"Good"<<endl;
}
int main()
{
	waste;
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 1000000000000000007LL
#define ll long long
using namespace std;
signed main(){
	int n,k;
	cin>>n>>k;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort( a.begin(), a.end() );
	int ng = -LINF, ok = LINF;
	while( ok - ng > 1 ){
		int mid = (ok+ng)/2;
		int cnt = 0;
		for(int i=0;i<n;i++){
			int c = 0;
			if( a[i] == 0 ){
				if( mid >= 0 ) cnt += n;
			}
			else if ( a[i] > 0 ){
				if( mid >= 0 ){
					auto it = upper_bound( a.begin(), a.end(), mid/a[i] );
					c = it - a.begin();
					cnt += c;
				}
				else{
					int kij = (-mid)/a[i];
					kij *= -1;
					if( (-mid)%a[i] != 0 ) kij--;
					auto it = upper_bound( a.begin(), a.end(), kij );
					c = it - a.begin();
					cnt += c;
				}
			}
			else{
				if( mid >= 0 ){
					auto it = lower_bound( a.begin(), a.end(), -( mid/(-a[i]) ) );
					c = a.end() - it;
					cnt += c;
				}
				else{
					int kij = (-mid)/(-a[i]);
					if( (-mid)%(-a[i]) != 0 ) kij++;
					auto it = lower_bound( a.begin(), a.end(), kij );
					c = a.end() - it;
					cnt += c;
				}
			}
			//cout<<c<<endl;
		}
		for(int i=0;i<n;i++){
			if( a[i] * a[i] <= mid ) cnt--;
		}
		cnt = cnt/2;
		if( cnt >= k ){
			ok = mid;
		}
		else{
			ng = mid;
		}
		//cout<< mid << cnt <<endl;
	}
	cout<<ok<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
//DEFINE and TYPEDEF--------------------------------------------------------------
 
#define timeKyaHorhaH 1.0 * clock() / CLOCKS_PER_SEC

#define FORG(i,a,n) for(lld i=a;i<n;i++) //for - general
#define FORZ(i,n) for(lld i=0;i<n;i++) //for - zero
#define FORGI(i,a,n,inc) for(lld i=a;i<n;i+=inc) //for - general incremental
#define FORZI(i,n,inc) for(lld i=0;i<n;i+=inc) //for - zero incremental
#define SPEEDUP ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define MEM(a,val) memset(a,val,sizeof(a));
 
#define SORTall(m) sort(m.begin(),m.end());
 
#define st first
#define nd second
#define pb push_back
 
typedef long long int lld;
typedef unsigned long long int ulld;
 
//DEBUGGER------------------------------------------------------------------------
// #define DEBUG(x) cerr<<(#x)<<" is "<<(x)<<"\n" //to debug values of variables
// #define DEBUGON
#define ZINDA cerr<<"\nIdhar-ich hai apun!!\n"; //to debug if code reached that point

vector<string> vec_splitter(string s) {
	for(char& c: s) c = c == ',' ?  ' ': c;
	stringstream ss; ss << s;
	vector<string> res;
	for(string z; ss >> z; res.push_back(z));
	return res;
}

void debug_out(vector<string> args, int idx) { cerr << endl; }
template <typename Head, typename... Tail>
	void debug_out(vector<string> args, int idx, Head H, Tail... T) {
		if(idx > 0) cerr << ", ";
		stringstream ss; ss << H;
		cerr << args[idx] << " = " << ss.str();
		debug_out(args, idx + 1, T...);
	}

#ifdef DEBUGON
	#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __VA_ARGS__);
	#define DEBUG(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __VA_ARGS__);	
#else
	#define debug(...) 320;
	#define DEBUG(...) 320;
#endif

lld power(lld b, lld e)
{
    if(e==0)
        return 1;
    if(e%2==1)
        return b*power(b*b,(e-1)/2);
    else
        return power(b*b,e/2);
}
 
lld power(lld b, lld e, lld m)
{
	if(e==0)
		return 1;
	if(e%2==1)
		return b*power(((b%m)*(b%m))%m,(e-1)/2,m)%m;
	else
		return power(((b%m)*(b%m))%m,e/2,m)%m;
}
 
int nDig(lld n)
{
	if(n<0) 
		n*=-1;
	if(n==0)
		return 1;

    return floor(log10(n) + 1);
}

#define endl '\n'
#define mod 1000000007

//endl : changed to '\n', to flush comment that definition
//--------------------------------------------------------------------------------

void swagWaalaFunction()
{
	lld n;
	cin>>n;

	float x=3.1415926535*2*n;
	cout<<x;
	return;
}

int main()
{
    SPEEDUP;
 	lld t=1;
 	//cin>>t;

 	while(t--)
 		swagWaalaFunction();
	
	// cerr<<"\n"<<timeKyaHorhaH; 	
 	return 0;
}

Measured memory_bytes: 3856
def primeFactor(N):
    i = 2
    ret = {}
    n = N
    mrFlg = 0
    while i**2 <= n:
        k = 0
        while n % i == 0:
            n //= i
            k += 1
            ret[i] = k
        i += 1
        if i == 101 and n >= (2**20):
            def findFactorRho(N):
                def gcd(a, b):
                    while b: a, b = b, a % b
                    return abs(a)
                def f(x, c):
                    return ((x ** 2) + c) % N
                semi = [N]
                for c in range(1, 99):
                    x, y, d = 2, 2, 1
                    while d == 1:
                        x = f(x, c)
                        y = f(f(y, c), c)
                        d = gcd(abs(x-y), N)
                    if d != N:
                        if isPrimeMR(d): return d
                        elif isPrimeMR(N//d):
                            return N//d
                        else:
                            semi.append(d)
            while True:
                if isPrimeMR(n):
                    ret[n], n = 1, 1
                    break
                else:
                    mrFlg = 1
                    j = findFactorRho(n)
                    k = 0
                    while n % j == 0:
                        n //= j
                        k += 1
                        ret[j] = k
                if n == 1: break

    if n > 1: ret[n] = 1
    if mrFlg > 0:
        def dict_sort(X):
            Y={}
            for x in sorted(X.keys()):
                Y[x] = X[x]
            return Y
        ret = dict_sort(ret)
    return ret

def isPrimeMR(n):
    if n == 2:
        return True
    if n == 1 or n & 1 == 0:
        return False
    d = (n - 1) >> 1
    while d & 1 == 0:
        d >>= 1

    for a in [2, 3, 5, 7, 11, 13, 17, 19, 23]:
        t = d
        y = pow(a, t, n)
        while t != n - 1 and y != 1 and y != n - 1:
            y = (y * y) % n
            t <<= 1

        if y != n - 1 and t & 1 == 0:
            return False
        return True

def gcd(a, b):
    while b: a, b = b, a % b
    return abs(a)

A, B = map(int, input().split())
N = gcd(A, B)
pf = primeFactor(N)

print(len(pf)+1)


Measured memory_bytes: 3192
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    ll ans=0, n,m; cin>>n>>m;
    if(n==1 && m==1){
        cout<<1<<endl;
        return 0;
    }
    ans=(n-2)*(m-2);
    if(n==1){
        ans=max((ll)0,m-2);
    }
    if(m==1){
        ans=max((ll)0,n-2);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3560
import java.util.*;

class Main {
	
	static char board[][] = new char[30][30];
	static int dx[] = {1,-1, 0, 0};
	static int dy[] = {0, 0, 1, -1};
	
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		while(true){
			int w = in.nextInt(), h = in.nextInt();
			if(w==0 && h==0) return;
			int sx=0, sy=0;
			for(int i=0; i<30; i++)for(int j=0; j<30; j++) board[i][j] = '#';
			for(int i=1; i<=h; i++){
				String line = in.next();
				for(int j=1; j<=w; j++){
					board[i][j] = line.charAt(j-1);
					if(board[i][j] == '@'){
						sx = i;
						sy = j;
						board[i][j] = '.';
					}
				}
			}
			dfs(sx,sy);
			int cnt=0;
			for(int i=1; i<=h; i++)
				for(int j=1; j<=w; j++)
					if(board[i][j] == '@')
						cnt++;
			System.out.println(cnt);
		}
	}
	
	private static void dfs(int i, int j){
		if(board[i][j] != '.') return ;
		board[i][j] = '@';
		for(int k=0; k<4; k++){
			dfs(i+dx[k], j+dy[k]);
		}
		return ;
	}
}

Measured memory_bytes: 13000
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int r;
	cin >> r;
	if(r < 1200) cout << "ABC" << endl;
	else if(r < 2800) cout << "ARC" << endl;
	else cout << "AGC" << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 256