akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

int dy[] = {0,1,0,-1};
int dx[] = {1,0,-1,0};
int dy8[] = {0,1,1,1,0,-1,-1,-1};
int dx8[] = {1,1,0,-1,-1,-1,0,1};

/*==================================================*/
/*variable*/
ll N, a;
/*==================================================*/
/*function*/

/*==================================================*/

int main() {
    cin>>N;

    vector<ll> v4;
    vector<ll> v2;
    vector<ll> v1;

    REP(i,0,N) {
        cin>>a;
        if(a % 4 == 0){
            v4.push_back(a);
        }else if(a % 2 == 0){
            v2.push_back(a);
        }else{
            v1.push_back(a);
        }
    }

    if((v1.size() <= v4.size() + 1 && v2.size() == 0) || (v1.size() <= v4.size() && 0 < v2.size())){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

//    ll d[100010];
//    REP(i,0,N) d[i] = -1;
//
//    int ind = -1;
//    REP(i,0,v4.size()){
//        ind += 2;
//        if(ind >= N) break;
//        d[ind] = v4[i];
//    }
//
//    if(ind >= N){
//        cout<<"Yes"<<endl;
//        return 0;
//    }
//
//    ind++;
//    REP(i,0,v2.size()){
//        if(ind >= N) break;
//        d[ind] = v2[i];
//        ind++;
//    }
//
//    int cnt = 0;
//    REP(i,0,N){
//        if(cnt == v1.size()) break;
//        if(d[i] == -1) d[i] = v1[cnt], cnt++;
//    }
//
//
//    REP(i,0,N-1){
//        if((d[i] * d[i+1]) % 4LL != 0LL || d[i]==-1 || d[i+1]==-1){
//            cout<<"No"<<endl;
//            return 0;
//        }
//    }
//    cout<<"Yes"<<endl;

    return 0;
}


Measured memory_bytes: 1528
import copy
N = int(input())
A = list(map(int,input().split()))

result = ['' for _ in range(N)]
s = A[0]
for i in range(1,N):
    s = s ^ A[i]

for i in range(N):
    result[i] = str(s ^ A[i])

print(' '.join(result)) 

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


int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    
    ll i,j,n;
    cin>>n;
    string s;
    cin>>s;
    ll w = 0, r = 0;
    for(i=0;i<n;i++)
    {
        if(s[i]=='W') w++;
        else r++;
    }
    ll ans = 0;
    j = n-1;
    while(j>0 && s[j]=='W') j--;
    i = 0;
    while(i<n && s[i]=='R') i++;
    while(i<j)
    {
        ans++;
        swap(s[i],s[j]);
        while(j>0 && s[j]=='W') j--;
        while(i<n && s[i]=='R') i++;
    }
    cout<<min({w,r,ans})<<"\n";
}

Measured memory_bytes: 3800
import java.util.*;

class Main {
	public static void main(String args[]){
	
    Scanner scan = new Scanner(System.in);
    int N=scan. nextInt();
    int T=scan.nextInt();
    
 
    
    int time[]=new int[N];
    int cost[]= new int[N];
    
    for(int i=0;i<N;i++){
    	cost[i]=scan.nextInt();
    	time[i]=scan.nextInt();
    }
    
    int mincost=1001;
   
  
    	for(int i=0;i<N;i++){
    		if(time[i]<=T){
    		  if(cost[i]<mincost){
    			  mincost=cost[i];
    		  }
    		}
    	}
    		if(mincost==1001){
    			System.out.println("TLE");
    		}else{
    			System.out.println(mincost);
    		}
    		
         }
    	
	
}


Measured memory_bytes: 22740
H, N = map(int, input().split())
AB = []
for _ in range(N):
    AB.append(tuple(map(int, input().split())))
# print(AB)
f_inf = float('inf')
dp = [f_inf] * (H + 1)
dp[0] = 0
for h in range(H):
    for damage, cost in AB:
        next_index = min(h + damage, H)
        dp[next_index] = min(dp[next_index], dp[h] + cost)

print(dp[H])

Measured memory_bytes: 43100
//ΔATCODER QUALC A
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
int main()
{
	char ch[11];
	int i;
	cin>>ch;
	for(i=0;i<strlen(ch)-1;i=i+1)
		if(ch[i]=='A'&&ch[i+1]=='C'){
			cout<<"Yes\n";
			return 0;
		}
	cout<<"No\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#define MOD 1000000007LL
using namespace std;

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	int ans = 0;
	for(int i = 0; i < b; i++){
		if((a * i) % b == c) ans = 1;
	}
	if(ans == 1) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    priority_queue<int> q;
    while(cin>>s,s!="end"){
        if(s[0]=='i'){
            int n;
            cin>>n;
            q.push(n);
        }else{
            cout<<q.top()<<endl;
            q.pop();
        }
    }
}



Measured memory_bytes: 7012
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

int dfs(int i, vector<int> &color, vector<vector<int>> &G){
    int ret = 1;
    for(int j : G[i]){
        if(color[j] == color[i]) ret = 2;
        else if(color[j] == -1){
            color[j] = 1 - color[i];
            ret = max(ret, dfs(j, color, G));
        }
    }
    return ret;
}

int paint(int i, vector<int> &color, vector<vector<int>> &G){
    if(color[i] != -1) return -1;
    color[i] = 0;
    return dfs(i, color, G);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long N, M;
    cin >> N >> M;
    vector<vector<int>> G(N);
    for(int i=0; i<M; i++){
        int u, v;
        cin >> u >> v;
        u--; v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    long long n1 = 0, n2 = 0, n3 = 0;

    vector<int> color(N, -1);
    for(int i=0; i<N; i++){
        if(G[i].empty()) n1++;
        else{
            int p = paint(i, color, G);
            if(p == 1) n2++;
            else if(p == 2) n3++;
        }
    }

    long long ans = n1 * N * 2 - n1 * n1 + n2 * n2 * 2 + n2 * n3 * 2 + n3 * n3;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 11776
#ifdef __APPLE__
#include <cassert>
#include <iostream>
#include <iomanip>
#include <ctime>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <sstream>
#include <map>
#include <set>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <cctype>
#include <list>
#include <cmath>
#include <limits>
#include <bitset>
#include <numeric>
#include <climits>
#include <complex>
#else
#include<bits/stdc++.h>
#endif // __APPLE__
using namespace std;
typedef pair<int,int>   II;
typedef vector<II>     VII;
typedef vector<int>     VI;
typedef vector< VI > 	VVI;
typedef long long int LL;
typedef  unsigned long long int ULL;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define SET(a,b) memset(a,b,sizeof(a))
#define LET(x,a) __typeof(a) x(a)
#define ALL(c) (c).begin(),(c).end()
#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define REP(i,a,b) for(int i = (int)a; i < (int)b; i++)
#define ROUNDOFFINT(d) d = (int)((double)d + 0.5)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1)	{
cerr << name << " : " << arg1 << std::endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
     const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);}
#else
#define trace(...)
#endif
//A






int main()
{
	//fr;fw;
	fast_io;
    int a,b;
    cin>>a>>b;
    cout<<(a+b)%24<<endl;



	return 0;
}





Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int a[] = new int[n];
		int odd = 0;
		for(int i = 0; i < n; i++){
			a[i] = sc.nextInt();
			if(a[i]% 2 == 1){
				odd++;
			}
		}

		int even = n - odd;

		if(odd % 2 == 1){
			System.out.println("NO");
		}
		else {
			System.out.println("YES");
		}

	}
}


Measured memory_bytes: 49332
#include<bits/stdc++.h>
using namespace std;
#define int long long
int memo[100];
int luca(int n){
    if(n==0)return 2;
    if(n==1)return 1;
    if(memo[n]!=0)return memo[n];
    return memo[n]=luca(n-2)+luca(n-1);
}
signed main(){
    int n;
    cin>>n;
    int ans=luca(n);
    cout<<ans<<endl;
    return 0;
}

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

int main()
{
    int x, ans;
    for(int i = 1; i <= 5; ++i){
        cin >> x;
        if(x == 0) ans = i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
#define N 1000005
using namespace std;
inline int read(){
	int ans=0;
	char ch=getchar();
	while(!isdigit(ch))ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
	return ans;
}
int cnt[N][2],n,a[N];
int main(){
	n=read();
	for(int i=1;i<=n;++i)a[i]=read(),cnt[a[i]][i%2]++;
	if(n==2)return printf("%d",a[1]==a[2]?1:0),0;
	int mx1=-1,mx2=-1,v1=-1,v2=-1;
	for(int i=1;i<=1000000;++i){
		if(cnt[i][0]){
			if(cnt[i][0]>mx1)mx2=mx1,v2=v1,mx1=cnt[i][0],v1=i;
			else if(cnt[i][0]>mx2)mx2=cnt[i][0],v2=i;
		}
	}
	int mx3=-1,mx4=-1,v3=-1,v4=-1;
	for(int i=1;i<=1000000;++i){
		if(cnt[i][1]){
			if(cnt[i][1]>mx3)mx4=mx3,v4=v3,mx3=cnt[i][1],v3=i;
			else if(cnt[i][1]>mx4)mx4=cnt[i][1],v4=i;
		}
	}
	if(v1!=v3)return printf("%d",n-mx1-mx3),0;
	if(v2==-1&&v4==-1)return printf("%d",n-max(mx1,mx3)),0;
	if(v2==-1)return printf("%d",n-mx1-mx4),0;
	if(v4==-1)return printf("%d",n-mx2-mx3),0;
	printf("%d",n-max(mx1,mx3)-max(mx2,mx4)),0;
	return 0;
}

Measured memory_bytes: 4736
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <set>
#include <cmath>
#include <array>
#include <bitset>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b+1;i++)
#define Per(i,b,a) for(int i=b;i>=a;i--)
int main(){
    int N;
    cin>>N;
    int *W = new int[N];
    rep(i,N) cin>>W[i];
    int sum = 0;
    rep(i,N) sum += W[i];
    int ans = sum;
    int temp = 0;
    rep(i,N){
        temp+=W[i];
        ans = min(ans,abs(sum-2*temp));
    }
    cout<<ans<<endl;
    return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007
#define IN freopen("hard1.txt","r",stdin)
#define OUT freopen("hard1.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 1000005

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<i64, i64> pii;

#define INF 2000000000000000000LL
#define alpha 26

#define maxn 300005
#define LOG 18

int main()
{
    i64 n ;
    scanf("%lld",&n) ;

    int b = 0 ;

    for(int i=1 ; ; i++)
    {
        if( (1LL<<i) <= n ) b = i ;
        else break ;
    }

    vector <int> ans ;

    for(int i=1 ; i<=b ; i++)
    {
        ans.pb(i) ;
    }
    for(int i=1 ; i<=b ; i++) ans.pb(50+i) ;

    for(int i=1 , j=b ; i<=b ; i++,j--)
    {
        if( ((1LL<<(i-1))&n) ) ans.pb(50+j) ;
        ans.pb(i) ;
    }
    ans.pb(100) ; ans.pb(100) ;

    printf("%d\n",(int)ans.size()) ;
    for(int i=0 ; i<ans.size(); i++) printf("%d ",ans[i]) ;
    printf("\n") ;

    return 0 ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAX 200111
#define mod 1000000007
const long long  inf = 2000000000000000000;
using namespace std;

int main(){ 
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 
    int n,k,a,ans = MAX,id;
    cin>>n>>k;
    for(int i =0 ; i < n ; i++){
        cin>>a;
        if(a == 1)id = i;
    }
    if(k == 2){
        cout<<n-1;
        return 0;
    }
    for(int i = min(0,id - k + 1); i <= id ; i++ ){
        int t = (n)/(k-1);
        if(n % (k-1) != 0 && (n - 1) % (k-1) > i%(k-1)) t++;
        if(i%(k-1) != 0)t++;
        ans = min(ans,t);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }


template<int MOD>
struct ModInt {
	static const int Mod = MOD;
	unsigned x;
	ModInt() : x(0) { }
	ModInt(signed sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	ModInt(signed long long sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	int get() const { return (int)x; }

	ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }

	ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
	ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
	ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
};
typedef ModInt<1000000007> mint;


vector<int> primes;
vector<int> smallestPrimeFactor;
void linearSieve(int n) {
	if (n < 1) n = 1;
	if ((int)smallestPrimeFactor.size() >= n + 1) return;
	int primePiBound = n < 20 ? n - 1 : (int)(n / (log(n * 1.) - 2) + 2);
	primes.assign(primePiBound + 1, numeric_limits<int>::max());
	int P = 0;
	smallestPrimeFactor.assign(n + 1, 0);
	smallestPrimeFactor[1] = 1;
	int n2 = n / 2, n3 = n / 3, n5 = n / 5;
	if (n >= 2)
		primes[P++] = 2;
	if (n >= 3)
		primes[P++] = 3;
	for (int q = 2; q <= n; q += 2)
		smallestPrimeFactor[q] = 2;
	for (int q = 3; q <= n; q += 6)
		smallestPrimeFactor[q] = 3;
	for (int q = 5; q <= n5; q += 2) {
		if (smallestPrimeFactor[q] == 0)
			primes[P++] = smallestPrimeFactor[q] = q;
		int bound = smallestPrimeFactor[q];
		for (int i = 2; ; ++i) {
			int p = primes[i];
			if (p > bound) break;
			int pq = p * q;
			if (pq > n) break;
			smallestPrimeFactor[pq] = p;
		}
	}
	for (int q = (n5 + 1) | 1; q <= n; q += 2) {
		if (smallestPrimeFactor[q] == 0)
			primes[P++] = smallestPrimeFactor[q] = q;
	}
	primes.resize(P);
}

typedef int FactorsInt;
typedef vector<pair<FactorsInt, int> > Factors;
void primeFactors(FactorsInt x, Factors &out_v) {
	linearSieve(x);
	out_v.clear();
	while (x != 1) {
		int p = smallestPrimeFactor[x], k = 0;
		x /= p, k++;
		while (x % p == 0) x /= p, k++;
		out_v.push_back(make_pair(p, k));
	}
}

int main() {
	int N;
	while (~scanf("%d", &N)) {
		linearSieve(N);
		map<int, int> a;
		rer(x, 1, N) {
			Factors fs;
			primeFactors(x, fs);
			for (auto p : fs)
				a[p.first] += p.second;
		}
		mint ans = 1;
		for (auto p : a)
			ans *= p.second + 1;
		printf("%d\n", ans.get());
	}
	return 0;
}


Measured memory_bytes: 764
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
string s;
vector<int> parse(string str) {
	vector<int> ret; str += " "; int t = 0;
	for(int i = 0; i < str.size(); i++) {
		if(str[i] == ' ') ret.push_back(t), t = 0;
		else t = t * 10 + str[i] - 48;
	}
	return ret;
}
int main() {
	while(s = "", getline(cin, s)) {
		if(s == "0") break;
		vector<int> v = parse(s);
		int a = 0, b = 0;
		for(int i = 0; i < v.size(); i++) {
			if(v[i] > 10) a += 10;
			else a += v[i];
			if(v[i] == 1) b++;
		}
		cout << ((a < 22) ? a + min(b, (21 - a) / 10) * 10 : 0) << endl;
	}
}

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

int main(){
	ll n,k;
	cin >> n >> k;
	ll ans = 1;
	rep(i,n){
		if(i == 0){
			ans *= k;
		}else{
			ans *= k-1;
		}
	}
	cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
typedef pair<int,int> P;
typedef pair<int,P> PP;
int n;
int a[200005];
int main()
{
	cin>>n;
	string s;
	cin>>s;
	if(n%2!=0)
	{
		cout<<"No"<<endl;return 0;
	}
	rep(i,n/2)
	{
		if(s[i]!=s[i+n/2])
		{
			cout<<"No"<<endl;return 0;
		}
		
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int a,b,c,k;
    cin>>a>>b>>c;
    cin>>k;
    while(k&&b<=a)
    {
        b=b*2;
        k--;
    }
    while(k&&c<=b)
    {
        c=c*2;
        k--;
    }
    
    if(a<b&&b<c)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3104
s = list(input())
if len(set(s)) == 4:
    print('Yes')
elif len(set(s)) == 2:
    if ('S' in s and 'N' in s) or ('E' in s and 'W' in s):
        print('Yes')
    else:
        print('No')
else:
    print('No')

Measured memory_bytes: 3060
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define _upgrade ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}

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

const ll mod = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.14159265358979323846;


// ****************************************CODE***************************************//







int main()
{



        string s;
        cin >> s;

        for(int i = 0; i < 3; i++){
                if(s[i] == s[i+1]){
                        cout << "Bad" << endl;
                        return 0;
                }
        }

        cout << "Good" << endl;
        return 0; 





}

















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

using namespace std;

int main()
{
	int N;
	float x[11];
	string u[11];
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> x[i] >> u[i];
	}
	float JPY_per_BTC = 380000.0;
	float res = 0;
	for (int i = 0; i < N; ++i) {
		if (u[i].compare("BTC") == 0) {
			res += x[i] * JPY_per_BTC;
		}
		else {
			res += x[i];
		}
	}
	cout << res << endl;
	return 0;
}

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

using namespace std;

struct UFTree{
	vector<int> p;
	UFTree(int n):p(n,-1){}
	void Unite(int a,int b){
		int ra=Find(a),rb=Find(b);
		if(ra!=rb){
			if(-p[ra]<-p[rb])
				swap(ra,rb);
			p[ra]+=p[rb];
			p[rb]=ra;
		}
	}
	int Find(int n){
		return p[n]<0?n:p[n]=Find(p[n]);
	}
};

int main()
{
	for(int w,h;cin>>w>>h,w|h;){
		int grid[50][50];
		for(int i=0;i<h;i++)
			for(int j=0;j<w;j++)
				cin>>grid[i][j];
		UFTree uft(h*w);
		for(int i=0;i<h;i++)
			for(int j=0;j<w;j++){
				if(!grid[i][j])
					continue;
				int di[]={0,1,1,1},dj[]={1,-1,0,1};
				for(int k=0;k<4;k++){
					int ni=i+di[k],nj=j+dj[k];
					if(0<=ni && ni<h && 0<=nj && nj<w && grid[ni][nj])
						uft.Unite(i*w+j,ni*w+nj);
				}
			}
		int res=0;
		for(int i=0;i<h;i++)
			for(int j=0;j<w;j++)
				if(grid[i][j] && uft.p[i*w+j]<0)
					res++;
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
def writeSum
	number1 = gets.to_i
	number2 = gets.to_i
	sum = number1 + number2
	if sum >= 10 ** 80
		puts "overflow"
	else
		puts sum
	end
end

dataSet = gets.to_i
1.upto(dataSet) do |i|
	writeSum()
end

Measured memory_bytes: 6116
import java.util.*;
import java.math.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    char[] s = sc.next().toCharArray();
    long k = sc.nextLong();

    for (int i = 0; i < k; i++) {
      if (s[i] != '1') {
        System.out.println(s[i]);
        return;
      }
    }

    System.out.println(1);

  }

}


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

public class Main {

	int[] a;
	int n;
	int[] count;
	
	long ans = Long.MAX_VALUE;
	
	void go(int pos, long sum) {
		if (pos * 3 > n) {
			for (int i = pos; i <= n; i++) {
				if (i % 2 == 0 && i / 2 >= pos) {
					continue;
				}
				if (i * 2 > n) {
					if (count[i] == 0 && a[i] < 0) {
						sum += a[i];
					}	
				} else {
					long cur1 = count[i] == 0 ? a[i] : 0;
					long cur2 = count[2 * i] == 0 ? a[2 * i] : 0;
					sum += Math.min(0, Math.min(cur1 + cur2, cur2));
				}
			}
			ans = Math.min(ans, sum);
			return;
		}
		go(pos + 1, sum);
		if (count[pos] == 0) {
			for (int i = pos; i <= n; i += pos) {
				if (count[i] == 0) {
					sum += a[i];
				}
				count[i]++;
			}
			go(pos + 1, sum);
			for (int i = pos; i <= n; i += pos) {
				count[i]--;
			}
		}
	}
	
	void solve() {
		n=  in.nextInt();
		a = new int[n + 1];
		count = new int[n + 1];
		long res = 0;
		for (int i = 1; i <= n; i++) {
			a[i] = in.nextInt();
			res += a[i];
		}
		go(1, 0);
		out.println(res - ans);
	}

	FastScanner in;
	PrintWriter out;

	void run() {
		in = new FastScanner();
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		public String nextToken() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextToken());
		}

		public long nextLong() {
			return Long.parseLong(nextToken());
		}

		public double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}


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

int main() {
	int N,M;
  cin >> N >> M;
  vector <int>s(M);
  vector <int>c(M);
 vector<int> Ans(N,0);
  
  
  
  int A = 1;
  
  for(int i = 0; i < M; i++){
  cin >> s.at(i) >> c.at(i);
  }
  
  for(int i = 0; i < M; i++){
  	if(N == 1 && c.at(i) == 0){
    A = 0;
    }
    else if(s.at(i) == 1 && c.at(i) == 0){
  		A = -1;
    }
  }
  
  for(int i = 0; i < M; i++){
    for(int j = i; j < M; j++){
  		if(s.at(i) == s.at(j) && c.at(i) != c.at(j)){
  			A = -1;
    	}
    }
  }
  
  if(M == 0 && N ==1){
  A =0 ;
  }
  
  for(int i = 0; i < M; i++){
  	Ans.at(s.at(i)-1) = c.at(i);
  }

  if(A == 0){
    
    cout << A;

}else if(A != -1){
    if(Ans.at(0) == 0){
    Ans.at(0) = 1;
    }
  	for(int i = 0; i < N ; i++){
  	cout<< Ans.at(i);
    }
  }else{
      cout << A;
    }
  cout << endl;
}


Measured memory_bytes: 256
//#pragma GCC optimize "trapv"
//-D_GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define pm(m) for(auto itr=(m).begin();itr!=(m).end();itr++){itr->first<<" "<<itr->second<<"\n";}
#define int long long int
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define ii pair<int,int>
#define Max 100000+5
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define f first
#define s second
#define pb push_back
#define bug(x) cout<<(x)<<" ";exit(0);
int mod = 1000000007;
int mod1 = 998244353;
vector<int> g[Max];
bool vis[Max];
int d, x, y;
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
void ex(int A, int B) {
    if(B == 0) {
        d = A;
        x = 1;
        y = 0;
    }
    else {
        ex(B, A%B);
        int temp = x;
        x = y;
        y = temp - (A/B)*y;
    }
}


void dfs(int u){

	vis[u]=1;
	for(int i=0;i<g[u].size();i++){
		int v=g[u][i];
		if(vis[v]!=1)
			dfs(v);
	}
}



int power(int a,int b){
    if(b==1)return a;
    if(a>mod)a%=mod;
    int r=1;
    while(b){
        if(b&1)r=r%mod*a%mod;
        a=a%mod*a%mod;
        b/=2;
    }
    return r;
}
class uf{
    vector<int> v;
    vector<int> sz;
    
    
    public :
    uf(int n){
        v.resize(n+1);
        iota(v.begin()+1,v.end(),1);
        sz.resize(n+1,1);
        //1 to sz
    }
    int root(int b){
        while(v[b]!=b){
            b = v[b];
        }   
        return b;
    }
    void u(int a, int b){
        //combine a and b
        
        int ra=root(a);
        int rb=root(b);
        if(ra==rb)return ;
        if(sz[ra]<sz[rb]){
            v[ra] = v[rb];
            sz[rb]+=sz[ra];
        }else{
            v[rb]=v[ra];
            sz[ra]+=sz[rb];
        }
    }
    bool f(int a,int b){
        //same set
        return (root(a)==root(b));
    }
   
    
};
vector<int> matmul(vector<int> a,vector<int> b){
    vector<int> c(4,0);
    c[0] = (a[0]%mod*b[0]%mod + a[1]%mod*b[2]%mod)%mod;
    c[1] = (a[0]%mod*b[1]%mod + a[1]%mod*b[3]%mod)%mod;
    c[2] = (a[2]%mod*b[0]%mod + a[3]%mod*b[2]%mod)%mod;
    c[3] = (a[2]%mod*b[1]%mod + a[3]%mod*b[3]%mod)%mod;
    return c;
}
vector<int> id={1,0,0,1};

int32_t main(){
	IO
	//freopen("input.txt","r",stdin);
    	//freopen("output.txt","w",stdout);
    	
	int n,W;
	cin>>n>>W;
	vector<vector<int> > v(W+1,vector<int> (n+1,0));
	vector<int> val(n+1),w(n+1);
	for(int i=1;i<=n;i++){
	    cin>>w[i]>>val[i];
	}
	for(int i=1;i<=n;i++){
	    for(int wt=0;wt<=W;wt++){
	        if(wt-w[i]>=0){
	            v[wt][i] = max(v[wt][i-1],v[wt-w[i]][i-1]+val[i]);
	        }
	        else{
	            v[wt][i] = v[wt][i-1];
	        }
	    }
	}
	cout<<v[W][n];
	
}

Measured memory_bytes: 87544
#include <iostream>
#include <fstream>
#include <utility>
#include <vector>
#include <algorithm>

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

typedef long long ll;

int main()
{
    
    int n;
    ll k;
    cin >> n;
    cin >> k;
    vector<int> a(n);
    vector<int> f(n);

    REP(i, n)
    cin >> a[i];
    REP(i, n)
    cin >> f[i];

    sort(a.begin(), a.end());
    sort(f.rbegin(), f.rend());

    ll l = -1, r = 1e12;
    while (l + 1 < r)
    {
        ll c = (l + r) / 2;
        bool ok = [&] {
            ll s = 0;
            REP(i, n)
            {
                s += max(0ll, a[i] - c / f[i]);
            }
            return s <= k;
        }();
        if (ok)
            r = c;
        else
            l = c;
    }
    cout << r << endl;

    return 0;
}

Measured memory_bytes: 1792
use std::io::*;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::HashSet;
use std::cmp;
use std::f64::consts;

fn main() {
    let n: i64 = read();
    let mut vec: Vec<String> = (0..n).map(|_| read()).collect();
    let mut map: HashMap<char, i64> = HashMap::new();

    map.insert('M', 0);
    map.insert('A', 0);
    map.insert('R', 0);
    map.insert('C', 0);
    map.insert('H', 0);

    let march_vec = vec!['M', 'A', 'R', 'C', 'H'];

    for s in vec.iter() {
        let char_vec: Vec<char> = s.chars().collect();
        let first_letter = char_vec[0];

        if march_vec.contains(&first_letter) {
            let count = map.get(&first_letter).unwrap().clone();
            map.insert(first_letter, count+1);
        }
    }

    let mut count = 0;

    for i in 0..i64::pow(2, march_vec.len() as u32) {
        let mut each_vec: Vec<char> = Vec::new();
        for j in 0..march_vec.len() {
            if (1 & i >> j) == 1 {
                each_vec.push(march_vec[j].clone());
            }
        }

        let mut each_count = 1;

        if each_vec.len() == 3 {
            for s in each_vec.iter() {
                let val = map.get(s).unwrap().clone();
                each_count *= val;
            }
            count+=each_count;
        }
    }

    println!("{:?}", count);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// 最大公約数
fn gcd(a: i32, b: i32) -> i32 {
    match b {
        0 => a,
        _ => gcd(b, a % b)
    }
}

// 最小公倍数
fn lcm(a: i32, b: i32) -> i32 {
    a * b / gcd(a, b)
}

// 階乗
fn kaijou(n: i32)->i32 {
    if n == 1 {
        return n;
    }
    return n * kaijou(n-1);
}

Measured memory_bytes: 8444
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);cout.precision(10);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) (upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X))
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
long long max(long long x,int y){return max(x,(long long)y);}
long long max(int x,long long y){return max((long long)x,y);}
long long min(long long x,int y){return min(x,(long long)y);}
long long min(int x,long long y){return min((long long)x,y);}

/* liblary */



/* main */

signed main(){
    vl v(3);
    FOR(i,0,3)cin >> v[i];
    sort(ALL(v));
    cout << v[0]*v[1]/2 << endl;
}

Measured memory_bytes: 256
x,y,a,b,c=map(int,input().split())
p=sorted(list(map(int,input().split())))[-x:]
q=sorted(list(map(int,input().split())))[-y:]
r=sorted(list(map(int,input().split())))[::-1]

i=j=k=0
oi=0
while i<c:
  if x>j and y>k:
    if p[j]>=q[k] and q[k]<r[i]:
      q[k]=r[i]
      k+=1
      i+=1
    elif p[j]<q[k] and p[j]<r[i]:
      p[j]=r[i]
      j+=1
      i+=1
  elif x>j:
    if p[j]<r[i]:
      p[j]=r[i]
      j+=1
      i+=1
  elif y>k:
    if q[k]<r[i]:
      q[k]=r[i]
      k+=1
      i+=1
  if oi==i:break
  oi=i

print(sum(p)+sum(q))



Measured memory_bytes: 27404
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
  int n, m;
  cin >> n >> m;
  int days = 0;
  for (int i = 0; i < m; i++)
  {
    int temp;
    cin >> temp;
    days += temp;
  }
  if (n - days < 0)
  {
    cout << -1 << endl;
  }
  else
  {
    cout << n - days << endl;
  }
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define endl "\n"
#define F first
#define S second
 
 
int pow1(int n, int p)
{
	if(p==0)	return 1;
	int x=pow1(n, p/2);
	x=(x*x)%mod;
	if(p%2==0)
		return x;
	else
		return (x*n)%mod;
}

void update(vector<int> &v, int x, int v1, int n)
{
	if(x==0)
		return;
	while(x<n)
	{
		if(v[x]<1e16)
			v[x]+=v1;
		x+=(x&-x);
	}
}

int query(vector<int> &v, int x)
{
	int s=0;
	while(x>0)
	{
		if(v[x]>=1e16)
			return 1e16;
		s+=v[x];
		x-=(x&-x);
	}
	return s;
}

int bina(int s, int e, vector<int> &v, int x)
{
	if(s>e)
		return -1;
	int mid=(s+e)/2;
	if(v[mid]==x)
		return mid;
	else if(v[mid]>x)
		return bina(s, mid-1, v, x);
	else
		return bina(mid+1, e, v, x);
}

int func(int s, int e, vector<pair<int, int>> &v, int d, int x, vector<int> &v1)
{
	if(s>e)
		return -1;
	int mid=(s+e)/2;
	// cout<<mid<<endl;
	int c=0;
	int l=(int)v1.size();
	vector<int> tr(l+1, 0);
	for(int i=0;i<(int)v.size();i++)
	{
		int c1=bina(0, l, v1, v[i].F);
		int a=query(tr, c1+1);
		int h=v[i].S;
		h-=a;
		if(h>0)
		{
			int ca=(h+x-1)/x;
			c+=ca;
			int idx2=bina(0, l, v1, v[i].F+2*d);
			// cout<<"I : "<<idx2<<endl;
			update(tr, c1+1, ca*x, l+1);
			update(tr, idx2+2, -ca*x, l+1);
		}
		if(c>mid)
			break;
	}
	if(c>mid)
		return func(mid+1, e, v, d, x, v1);
	else
	{
		int a=func(s, mid-1, v, d, x, v1);
		if(a==-1)
			return mid;
		return a;
	}
}

int32_t main()
{
	fast;

	set<int> s;

	int n, d, a1;
	cin>>n>>d>>a1;
	vector<pair<int, int>> v(n);
	int c=0;
	for(int i=0;i<n;i++)
	{
		int a, b;
		cin>>a>>b;
		s.insert(a);
		s.insert(a+2*d);
		v[i]={a, b};
		c+=(b+a1-1)/a1;
	}
	sort(v.begin(), v.end());
	vector<int> v1;
	for(auto i:s)
		v1.push_back(i);

	int a=func(1, c, v, d, a1, v1);

	cout<<a<<endl;

	return 0;
}

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

int main() {
  int n, m, X, Y;
  cin >> n >> m >> X >> Y;
  vector<int> x(n);
  vector<int> y(m);
  
  int max_x = -100;
  int min_y = 100;
  
  for(int i = 0; i < n; i++) {
    cin >> x.at(i);
    max_x = max(x.at(i), max_x);
  } //cout << max_x << endl;
  for(int i = 0; i < m; i++) {
    cin >> y.at(i);
    min_y = min(min_y,y.at(i));
  } //cout << min_y << endl;
  
  int Z = min_y;
  //cout << Z << endl;
  if(X < Z && Z <= Y && Z > max_x)
    cout << "No War" << endl;
  else
    cout << "War" << endl;
 
}

Measured memory_bytes: 256
package main

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

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func main() {
	sc := NewScanner()
	N, X := sc.nextInt(), sc.nextInt()
	D := make([]int, N+1)
	D[0] = 0
	for i := 1; i < N+1; i++ {
		D[i] = D[i-1] + sc.nextInt()
	}
	count := 0
	for _, v := range D {
		if v > X {
			break
		}
		count++
	}
	fmt.Println(count)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(auto& i:a)cin>>i;
  sort(a.begin(),a.end());
  cout<<(!a[n-1]||(!a[n/3-1]&&a[n/3]==a[n-1])||(a[0]==a[n/3-1]&&a[n/3]==a[2*n/3-1]&&a[2*n/3]==a[n-1]&&!(a[0]^a[n/3]^a[2*n/3]))?"Yes":"No");
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int a[N];
int main()
{
    int n;
    cin>>n;
    int cnt4=0,cnt2=0;
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
        a[i]%=4;
        if(a[i]==0)
            cnt4++;
        else if(a[i]==2)
            cnt2++;
    }
    int cnt=n-cnt2-cnt4;
    if(cnt2)
    {
        if(cnt4>=cnt){
            cout<<"Yes";
            return 0;
        }
    }
    else
    {
        if(cnt4&&(cnt4+1>=cnt)){
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
    return 0;
}

Measured memory_bytes: 640
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val Array(h, w) = in.readLine().split("\\s+").map(_.toInt)
    val map = Array.ofDim[Char](h, w)

    for (i <- 0 until h) {
      map(i) = in.readLine().toCharArray
    }

    val dp = Array.ofDim[Int](h, w)

    for {
      y <- 0 until h
      x <- 0 until w
    } {
      if (map(y)(x) == '.') {
        if (x == 0 && y > 0) {
          dp(y)(x) = dp(y - 1)(x)
        } else if (y == 0 && x > 0) {
          dp(y)(x) = dp(y)(x - 1)
        } else if (x > 0 && y > 0) {
          dp(y)(x) = Math.min(dp(y - 1)(x), dp(y)(x - 1))
        }
      } else {
        if (x == 0 && y == 0) {
          dp(y)(x) = 1
        } else if (x == 0 && y > 0) {
          if (map(y - 1)(x) == '#') {
            dp(y)(x) = dp(y - 1)(x)
          } else {
            dp(y)(x) = dp(y - 1)(x) + 1
          }
        } else if (y == 0 && x > 0) {
          if (map(y)(x - 1) == '#') {
            dp(y)(x) = dp(y)(x - 1)
          } else {
            dp(y)(x) = dp(y)(x - 1) + 1
          }
        } else {
          dp(y)(x) = Math.min(dp(y - 1)(x) + {
            if (map(y - 1)(x) == '#') {
              0
            } else {
              1
            }
          }, dp(y)(x - 1) + {
            if (map(y)(x - 1) == '#') {
              0
            } else {
              1
            }
          })
        }
      }
    }

    out.println(dp(h - 1)(w - 1))

    out.flush()
  }
}


Measured memory_bytes: 26544
package main

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

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) main() error {
	var w, a, b int
	con.Scan(&w, &a, &b)
	x := (a + w) - b
	if x < 0 {
		x = -x
	}
	y := (b + w) - a
	if y < 0 {
		y = -y
	}
	if x > y {
		x = y
	}
	if a+w >= b && a <= b+w {
		x = 0
	}
	con.Println(x)
	return nil
}


Measured memory_bytes: 640
use std::io::{stdin, stdout, BufReader, BufRead, StdinLock, Write, BufWriter};
use std::cmp::min;

fn main() {
    let (std_in, std_out) = (stdin(), stdout());
    let mut br = BufReader::new(std_in.lock());
    let mut bw = BufWriter::new(std_out.lock());
    
    let n = rn::<usize>(&mut br);
    let mut a = rvn::<usize>(&mut br);
    let mut b = rvn::<usize>(&mut br);

    let mut res = 0;
    for i in (0..n) {
        let kill = min(b[i], a[i]);
        a[i] -= kill;
        b[i] -= kill;
        res += kill;
        let kill = min(b[i], a[i+1]);
        a[i+1] -= kill;
        b[i] -= kill;
        res += kill;
    }
    writeln!(&mut bw, "{}", res);
}


//////////////////////////////////////////////////////////////////////////////////
#[allow(dead_code)]
fn rs(br: &mut BufReader<StdinLock>) -> Vec<char> {
    let mut buf = String::new();
    br.read_line(&mut buf).ok();
    buf.trim().chars().collect()
}

#[allow(dead_code)]
fn rn<T: std::str::FromStr>(br: &mut BufReader<StdinLock>) -> T {
    let mut buf = String::new();
    br.read_line(&mut buf).ok();
    buf.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn rvs(br: &mut BufReader<StdinLock>) -> Vec<Vec<char>> {
    let mut buf = String::new();
    br.read_line(&mut buf).ok();
    buf.trim().split_whitespace().map(|e| e.chars().collect()).collect()
}

#[allow(dead_code)]
fn rvn<T: std::str::FromStr>(br: &mut BufReader<StdinLock>) -> Vec<T> {
    let mut buf = String::new();
    br.read_line(&mut buf).ok();
    buf.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

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

int main(){
	int n, m;
	cin >> n >> m;
	
	rep(i, m){
		int a;
		cin >> a;
		n -= a;
	}

	if(n < 0) cout << -1 << endl;
	else cout << n << endl;

	return 0;
}

Measured memory_bytes: 3624
h,w,k=map(int, input().split())

# 以下の計算結果から、フィボナッチ数列であることがわかる
# existRight=[0 for _ in range(w-1)] # 右はしに横棒がある場合の数
# nonexistRight=[0 for _ in range(w-1)] # 右端に横棒がない場合の数
# nonexistRight[0]=1
# for i in range(1,w-1):
#     existRight[i]=nonexistRight[i-1]
#     nonexistRight[i]=existRight[i-1]+nonexistRight[i-1]

# patternSize[w-1]:縦軸w本のときのパターン数
# patternSize[-2],[-1]の対応のためのpatternSize[w],[w+1]
patternSize=[1for _ in range(w+2)]
patternSize[1]=2
for i in range(2,w):
    patternSize[i]=patternSize[i-1]+patternSize[i-2]

# 動的計画法
# a(h,x): h列目を通過した直後にx行目にいる場合の数とする
a=[[0for _ in range(w)]for _ in range(h+1)]
a[0][0]=1
for i in range(1,h+1):
    for j in range(0,w):
        # i-1行j列からの場合の数の漸化式
        if j!=0:
            a[i][j-1]+=a[i-1][j]*patternSize[j-2]*patternSize[w-1-j-1]
        a[i][j]+=a[i-1][j]*patternSize[j-1]*patternSize[w-1-j-1]
        if j!=w-1:
            a[i][j+1]+=a[i-1][j]*patternSize[j-1]*patternSize[w-1-j-2]

# import numpy as np
# print(np.array(a))
print(a[h][k-1]%1000000007)

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

int main() {
  vector<int> to[4] = {};
  for (int i = 0; i < 3; ++i) {
    int a, b;
    cin >> a >> b;
    to[a-1].push_back(b);
    to[b-1].push_back(a);
  }
  bool ans = false;
  vector<int> perm{1, 2, 3, 4};
  do {
    bool ok = true;
    for (int i = 0; i < 3; ++i) {
      if (find(to[perm[i]-1].begin(), to[perm[i]-1].end(), perm[i+1]) == to[perm[i] - 1].end())
        ok = false;
    }
    if (ok)
      ans = true;
  } while (next_permutation(perm.begin(), perm.end()));
  if (ans)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){

	int cnt = 0;
	int sum = 0;

	int n,x;
	cin >> n >> x;
	//cout << "n = " << n << endl << "x = " << x << endl;

	int jump[n+1];

	int i;
	for(i = 0; i < n+1; i++){

		if(i == 0) jump[i] = 0;
		else       cin >> jump[i];

		//cout << "jump[" << i << "] = " << jump[i] << endl;
	}

	while( (sum + jump[cnt])  <= x){

		sum = sum + jump[cnt];
		cnt++;

		/*cout << "sum = " << sum << endl;
		cout << "cnt = " << cnt << endl;
		cout << "jump[" << cnt << "] = " << jump[cnt] << endl;
		*/
	}

	cout << cnt << endl;
}

Measured memory_bytes: 256
if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
pI(x)=parse(Int,x)
pM(x::Array{SubString{String},1})=map(pI,x)
function main()
  w=chomp(readline())
  flag=true
  for i='a':'z'
    if count(x->x==i,w)%2!=0; flag=false; end
  end
  println(flag ? "Yes" : "No")
end
main()
if isdefined(Base, :mystdin);close(mystdin);end

Measured memory_bytes: 167652
#include <stdio.h>
#include <math.h>

int main(){
  int i,n,j,k,l,q;
  int p[301],m[301][301];
  scanf("%d",&n);
  for(i=1;i<=n;i++)
    scanf("%d %d",&p[i-1],&p[i]);
  for(i=1;i<=n;i++) 
    m[i][i]=0;
  for(l=2;l<=n;l++)
    for(i=1;i<=n;i++){
      j=i+l-1;
      m[i][j]=2000000;
      for(k=i;k<=j;k++){
	q=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
	m[i][j]=fmin(m[i][j],q);
      }
    }
  printf("%d\n",m[1][n]);
  return 0;
}



Measured memory_bytes: 2052
# coding: utf-8
import math
from decimal import Decimal

N = int(input())

votes = []

for _ in range(N):
    votes.append([Decimal(n) for n in input().split()])

befa = 1
befb = 1

for a, b in votes:
    kakeru = Decimal(max(math.ceil(befa / a), math.ceil(befb / b)))
    befa = a * kakeru
    befb = b * kakeru

print(int(befa)+int(befb))

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

const int MAX_N = 100100;
const int INF = 1001001000;
const int WHITE = 0, GRAY = 1, BLACK = 2;

vector<int> M[MAX_N];
int p[MAX_N], d[MAX_N], color[MAX_N];

void init(){
    rep(i,MAX_N){
        d[i] = INF;
        color[i] = WHITE;
    }
}

void bfs(){
    d[0] = 0;
    color[0] = GRAY;
    queue<int> Q;
    Q.push(0);
    int u;
    while(!Q.empty()){
        u = Q.front(); Q.pop();
        for(int v: M[u]){
            if(color[v] == WHITE){
                color[v] = GRAY;
                d[v] = d[u] + 1;
                p[v] = u; p[v]++;
                Q.push(v);
            }
        }
        color[u] = BLACK;
    }
}

int main()
{
    int n, m; cin >> n >> m;
    init();
    rep(_,m){
        int x, y;
        cin >> x >> y;
        x--; y--;
        M[x].push_back(y);
        M[y].push_back(x);
    }
    bfs();
    bool isOK = true;
    rep(i,n){
        if(d[i] == INF){
            isOK = false;
        }
    }
    if(isOK){
        cout << "Yes" << endl;
        rep(i,n){
            if(i != 0) cout << p[i] << endl;
        }
    }else{
        cout << "No" << endl;
    }

}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    int sum = 0;
    if (K>0) {
        if (K>A) {
            sum += A;
            K -= A;
        } else {
            sum += K;
            K = 0;
        }
    }
    if (K>0) {
        if (K>B) {
            K -= B;
        } else {
            K = 0;
        }
    }
    if (K>0) {
        sum -= K;
    }
    cout << sum << "\n";
    return 0;
}

Measured memory_bytes: 3612