akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline
import numpy as np
base_list = np.array(['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'])
dict_list = []
dict_list.append(base_list)
for i in range(26):
    tmp_char = dict_list[i][0]
    tmp_list = dict_list[i][1:]
    tmp_list = np.append(tmp_list,tmp_char)
    dict_list.append(tmp_list)

def print_ans(N, sr):
    """Test Case
    >>> print_ans(2, ['A', 'B', 'C', 'X', 'Y', 'Z'])
    CDEZAB
    >>> print_ans(0, ['A', 'B', 'C','X', 'Y', 'Z'])
    ABCXYZ
    """
    idx_list = []
    for s in sr:
        tmp = np.where(base_list == s)[0]
        idx_list.append(int(tmp))
    ans = ''.join(dict_list[N][idx_list])
    print(ans)

if __name__ == '__main__':
    N = int(input().rstrip())
    tmp_s= input().rstrip()
    sr = []
    for s in tmp_s:
        sr.append(s)
    print_ans(N, sr)




Measured memory_bytes: 21772
import java.util.Scanner;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
	//宣言
		int
				sum;
		String
				input,
				output = "";
		
	//入力
		input = sc.next();
		//終了判定
		while(!(input.equals("0"))){
			sum = 0;
			for(int i = 0;i < input.length();i++){
				//文字列のi番目の文字を数値として合計に加算
				sum += Character.getNumericValue(input.charAt(i));
			}
			output += sum + "\n";
			input = sc.next();
			
		}
		
	//出力
		System.out.println(output.substring(0, output.length()-1));
		
	}
}



Measured memory_bytes: 26560
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>

using namespace std;

int main() {
	int h[10] = { 0 };

	for (int i = 0; i < 10; i++)
	{
		scanf("%d", &h[i]);
		//printf("%d\n", h[i]);
	}

	sort(h, h + 10, std::greater<int>());
	for (int i = 0; i < 3; i++)
	{
		printf("%d\n", h[i]);
	}
	
}

Measured memory_bytes: 1044
mi = {"1": 2, "2": 5, "3": 5, "4": 4, "5": 5, "6": 6, "7": 3, "8": 7, "9": 6}
n, m = map(int, input().split())
A = input().split()
dpn = [0] + [-1] * 10010
dp = [""] * 10010
for i in range(n):
    for a in A:
        if dpn[i] != -1:
            cnt = dpn[i] + 1
            if dpn[i + mi[a]] < cnt:
                dpn[i + mi[a]] = cnt
                dp[i + mi[a]] = max(a + dp[i], dp[i] + a)
            elif dpn[i + mi[a]] == cnt:
                dp[i + mi[a]] = max(dp[i + mi[a]], a + dp[i], dp[i] + a)
print(dp[n])


Measured memory_bytes: 30784
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include<math.h>
using namespace std;

#define int long long
#define endl "\n"
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define mod 1000000007
#define all(v)  v.begin(),v.end()
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define all(v)  v.begin(),v.end()
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
using namespace std;

int jousu(int, int);
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}


signed main() {
	int n, t=0;
	cin >> n;
	vector<pair<int, int>>vec(n);
	rep(i, n) {
		cin >> vec[i].sec >> vec[i].fir;
	}
	sort(all(vec));
	rep(i, n) {
		t += vec[i].sec;
		vec[i].second = t;
		if (t > vec[i].fir) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}



Measured memory_bytes: 3456
using System;
using System.Collections;
using System.Collections.Generic;

class Program {
    static void Main (string[] args) {
        var tempstr = Console.ReadLine ().Split (' ');
        int N = int.Parse (tempstr[0]);
        int K = int.Parse (tempstr[1]);
        var A = new long[N];
        var tempstr2 = Console.ReadLine ().Split (' ');
        for (int i = 0; i < N; i++) {
            A[i] = long.Parse (tempstr2[i]);
        }
        for (int i = K + 1; i <= N; i++) {
            if (A[i - K - 1] < A[i - 1]) {
                Console.WriteLine ("Yes");
            } else {
                Console.WriteLine ("No");
            }
        }
    }

}

//dotnet run --project test

Measured memory_bytes: 46664
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1000000007;
const ll INF = 1061109567;
const ll MAX = 1e18;
const double EPS = 1e-10;
int main(){

    long long int a;
    long double b;
    long long int ans;
    cin >> a >> b;
    
    b = b*100;
    b = b + 0.5;
    int tmpB = b;
    ans = a*tmpB/100;
    cout << ans<< endl;
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;

typedef pair<int,int>P;

struct edge{
	int to;
	int cost;
};

const int MAX_N = 3002;

int n,m,K,d[MAX_N];
vector<int> S;
vector<edge> G[MAX_N];

void dijkstra()
{
	priority_queue<P,vector<P>,greater<P> > que;
	rep(i,S.size()){
		d[S[i]] = 0;
		que.push(P(0,S[i]));
	}
	while(!que.empty()){
		P p = que.top();
		que.pop();
		int v = p.second;
		if(d[v] < p.first) continue;
		vector<edge>::iterator it = G[v].begin();
		while(it != G[v].end()){
			if(d[it->to] > d[v] + it->cost){
				d[it->to] = d[v] + it->cost;
				que.push(P(d[it->to],it->to));
			}
			it++;
		}
	}
}

int main()
{
	scanf("%d%d%d",&n,&m,&K);
	rep(i,m){
		int x,y,z;
		edge e1,e2;
		scanf("%d%d%d",&x,&y,&z);
		e1.to = y-1,e1.cost = z;
		G[x-1].push_back(e1);
		e2.to = x-1,e2.cost = z;
		G[y-1].push_back(e2);
	}
	rep(i,K){
		int x;
		scanf("%d",&x);
		S.push_back(x-1);
	}
	fill(d,d+n,INF);
	dijkstra();
	int ans=0;
	rep(i,n){
		rep(j,G[i].size()){
			if(d[i]>=d[G[i][j].to]){
				if(d[i]>=d[G[i][j].to]+G[i][j].cost){
					ans = max(ans,d[i]);
				}else{
					ans = max(ans,(d[i]+d[G[i][j].to]+G[i][j].cost+1)/2);
				}
			}else{
				if(d[G[i][j].to]>=d[i]+G[i][j].cost){
					ans = max(ans,d[G[i][j].to]);
				}else{
					ans = max(ans,(d[i]+d[G[i][j].to]+G[i][j].cost+1)/2);
				}
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 6012
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, k;
    cin >> n >> k;
    map<int, int> mmap;
    for (int i = 0, x; i < n; mmap[x]++, i++)
        cin >> x;
    vector<int> dp(k + 1, 1);
    for (int i = 1; i <= k; i++)
        for (auto &p : mmap)
            if (i - p.first >= 0)
                dp[i] = min(dp[i], 1 ^ dp[i - p.first]);
    if (dp[k] == 0)
        cout << "First\n";
    else
        cout << "Second\n";
    return 0;
}

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

int main() {
	int n;
	cin >> n;
	int arr[n];
	for(int i=0;i<n;i++){
		cin >> arr[i];
	}
	int dp[n];
	dp[0]=0;
	dp[1]=abs(arr[1]-arr[0]);
	for(int i=2;i<n;i++){
		dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
	}
	cout << dp[n-1];
	// your code goes here
	return 0;
}

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

#define ull unsigned long long int
#define ll long long

using namespace std;

long long A[100000+1];

int main() {
    
    int n,m;
    cin>>n>>m;
    int c[n+1] = {0};
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        c[a]++;
        c[b]++;
    }
    
    for(int i=1;i<=n;i++)
    {
        cout<<c[i]<<"\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 10 ** 9 + 7
S = sr()
# 桁DP, 上から
dp = [0] * 13
dp[0] = 1
for s in S:
    prev = [x for x in dp]
    num = s
    dp = [0] * 13
    if num != '?':
        num = int(num)
        for j in range(13):
            dp[(10*j+num)%13] = prev[j]
    else:
        for j in range(13):
            for k in range(10):
                dp[(10*j+k)%13] += prev[j]
    dp = [x%MOD for x in dp]

answer = dp[5]
print(answer%MOD)


Measured memory_bytes: 43756
/*Author : Sambhu show(jgec)*/
#include<bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define itc ll t;cin>>t;while(t--)
#define PI 3.141592653589793238
#define Max(a,b,c) max(a,max(b,c));
#define Min(a,b,c) min(a,min(b,c));
#define all(v) v.begin(),v.end()
#define ll long long int
#define ld long double
#define pb push_back
#define eb emplace_back
#define gcd(a,b) __gcd(a,b)
#define fi first
#define se second
#define endl "\n"
int dx[4] = {0, -1, 0, 1};
int dy[4] = {1, 0, -1, 0};
int XX[8] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
int tc = 0;
void solve()
{

	int x;
	cin >> x;

	int v = 8;
	if (x >= 400 && x <= 599)
		v = 8;
	else if (x >= 600 && x <= 799)
		v = 7;
	else if (x >= 800 && x <= 999)
		v = 6;
	else if (x >= 1000 && x <= 1199)
		v = 5;
	else if (x >= 1200 && x <= 1399)
		v = 4;
	else if (x >= 1400 && x <= 1599)
		v = 3;
	else if (x >= 1600 && x <= 1799)
		v = 2;
	else
		v = 1;

	cout << v;


}
int main()
{
	fio
	//itc
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 3632
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int k = sc.nextInt();
		
		// 計算
		int result = -1;
		if(k%2 == 0 || k%5 == 0){
		    System.out.println(result);
		    return;
		}
		result = 1;
		int r = 7;
		while(r%k != 0){
		    r = r*10 + 7;
		    r %= k;
		    result++;
		}
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}


Measured memory_bytes: 25576
//OH
#include<iostream>
using namespace std;

int main()
{
	int n, b, f, r, v;
	int tt[4][3][10];
	for(int i = 0; i < 4; i++)
		for(int j = 0; j < 3; j++)
			for(int m = 0; m < 10; m++)
				tt[i][j][m] = 0;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> b >> f >> r >> v;
		tt[b-1][f-1][r-1] += v;
	}
	
	for(int i = 0; i < 4; i++){
		for(int j = 0; j < 3; j++){
			for(int m = 0; m < 10; m++)
				cout << " " << tt[i][j][m];
		cout << endl;
		}
		if (i < 3)
	cout << "####################" << endl;
	}
	return 0;
}


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int  b[100000] ;
long  dp[100105];

int main(){
	int n,k; cin>>n>>k;
	for(int i=0;i<n;i++)cin>>b[i];
	memset(dp,1000000,sizeof(dp));
	dp[0]=0;
	for(int i=0;i<n;i++){
		for(int j=1;j<=k;j++){
			dp[i+j]=min(dp[i]+abs(b[i+j]-b[i]),dp[i+j]);
		}
	}
	cout<<dp[n-1];
}


Measured memory_bytes: 1408
#include<cstdio>
#include<cstdlib>
#include<vector>


using namespace std;

using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;


void min_u(ll&m, ll v)
{
	if(m>v) m=v;
}


int main(void)
{
	int n;

	while(scanf("%d", &n)==1)
	{
		vi a(n);
		vll s(n);
		ll t=0;

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

		s[0]=a[0];
		for(int i=1;i<n;i++)
		{
			s[i]=s[i-1]+a[i];
		}

		ll ans=llabs(t-a[0]*2);
		for(int i=1;i+1<n;i++)
		{
			min_u(ans, llabs(t-s[i]*2));
		}
		printf("%lld\n", ans);
	}

	return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>




using namespace std;
typedef long long ll;
struct point{
  int x;
  int y;

};
int gcd(int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	// ユークリッドの方法
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}//gcd
int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm
int input(){
  int x;
  cin>>x;
  return x;
}

int moji(char in)
{
    int ans = (int)in-(int)'a';
    if((ans < 0) || (ans > 25)){
        ans = 26;
    }
    return ans;
}
const int VV=10;//場合に応じてVVの値のみ変更する必要あり
//dijkstra(s)sがスタート地点でそこからの最短距離を配列dで表す。正の重みのみ使用可能
int cost[VV][VV];
int d[VV];
bool used[VV];
void dijkstra(int s){
  fill(d,d+VV,100000);
  fill(used,used+VV,false);
  d[s]=0;
  while(true){
    int v=-1;
    for(int u=0;u<VV;u++){
      if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
    }
    if(v==-1)break;
    used[v]=true;
    for(int u=0;u<VV;u++){
      d[u]=min(d[u],d[v]+cost[v][u]);
    }
  }

}

int compare_int(const void *a, const void *b)//qsort(quick sort利用時に使用)
{
    return *(int*)a - *(int*)b;
}

int binary_searchh(long long x,long long k[],int n){
  int l=0;
  int r=n;
  while(r-l>=1){
    int i=(l+r)/2;
    if(k[i]==x)return i;
    else if(k[i]<x)l=i+1;
    else r=i;
  }
  return -1;
}




int main(){
  int N;
  cin>>N;
  int h[N];
  for(int i=0;i<N;i++){
    cin>>h[i];
  }  
  int dp[N];
  dp[0]=0;
  dp[1]=abs(h[1]-h[0]);
  for(int i=2;i<N;i++){
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i-2]-h[i]));
  }
  cout<<dp[N-1]<<endl;




  

  



}


  
  


  


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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n,k;
  cin >> n >> k;
  ll ans = 0;
  REP(i,n){
    ll h;
    cin >> h;
    if(h>=k) ans++;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main(){
    int64_t x;
    cin >> x;
    int64_t a = 100;
    for (int i = 0; i <= 3760; i++){
        if (a >= x){
            cout << i << endl;
            return 0;
        }
        a += a / 100;
    }
}

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

#ifdef _DEBUG
#define debug(x) cout<<#x<<": "<<x<<endl
#else
#define debug(x)
#endif

using namespace std;

#define mp make_pair

int main() {
    int n;
    cin >> n;
    vector<int> ps;
    for (int i = 0; i < n; ++i) {
        int p;
        cin >> p;
        ps.push_back(p);
    }
    int mx = n + 1, cnt = 0;
    for (int i = 0; i < n; ++i) {
        mx = min(mx, ps[i]);
        if (ps[i] <= mx) {
            cnt++;
            debug(i);
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1400
#-*-coding:utf-8-*-

import sys

def main2():
    n,k = map(int,(input().split()))
    items=[list(map(int,input().split())) for _ in range(n)]
    dp = [[0 for _ in range(k+1)] for _ in range(n)]
    for i in range(n):
        for j in range(k+1):
            if i==0 and j>=items[0][0]:
                dp[0][j]=items[0][1]
            elif i>0 and j>=items[i][0]:
                dp[i][j]=max(dp[i-1][j],items[i][1]+dp[i-1][j-items[i][0]])
            elif j < items[i][0] and i > 0:
                dp[i][j]=dp[i-1][j]
    print (dp[-1][-1])

if __name__ == "__main__":
    main2()

Measured memory_bytes: 171400
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

int main() {
    fastio();

    int x1, x2, x3, x4, x5;
    cin >> x1 >> x2 >> x3 >> x4 >> x5;

    cout << 15 - (x1 + x2 + x3 + x4 + x5) << endl;

    return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>

using namespace std;

#define rep(i,n) for(int i = 0;i < n;i++)
#define ull unsigned long long
#define int ull
#define ll int

struct RHS {
	int n;
	string s;
	vector<int> hs; //???????????\????´???????
	vector<int> bp; //b????´?????????????????¨??????????(??????????????????????????????)
	const int b = 1e9 + 7;
	//?????????
	RHS(string s) : n(s.size()), s(s), hs(n+1) , bp(n+1){
		bp[0] = 1;
		rep(i, n) {
			bp[i + 1] = bp[i] * b;
			hs[i + 1] = hs[i] * b + s[i];
		}
	}
	//s[l,r]??????????????\????????????
	int subhash(int l, int r) {
		return hs[r+1] - hs[l] * bp[r+1 - l];
	}
};

signed main() {
	int n, m;
	cin >> n >> m;
	string s;
	cin >> s;
	RHS hs(s);
	int l = 0, r = 0;
	set<int> se;
	rep(i, m) {
		string t;
		cin >> t;
		if (t == "R++") {
			r++;
		}
		if (t == "L++") {
			l++;
		}
		if (t == "R--") {
			r--;
		}
		if (t == "L--") {
			l--;
		}
		se.insert(hs.subhash(l, r));
	}
	cout << se.size() << endl;

	return 0;
}

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

const int Nmax=200010;
//#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//#definr REP(i,n) FOR(i,0,n)
//#define dump(x) cout << #x << "=" << (x) << endl;
//#define debug(x) cout << #x << "=" << (x) << "(L" << _LINE_ << ")" << "" << _FILE_ << endl;
//ll a[Nmax];
//int* P = new int[N];

int main() {
	int A,B,C,X,Y;
	ll price=0;
	cin >> A >> B >> C >> X >> Y;
	
	if((A+B)/2 >= C){
		price += 2*C*min(X,Y);
	
		if(max(X,Y) == X){//Aを買い足し
			if(A >= 2*C) price += 2*C*(X-Y);
			else price += A*(X-Y);
		}else{
			if(B >= 2*C) price += 2*C*abs(Y-X);
			else price += B*abs(Y-X);
		}
	}else{
		price += X*A + Y*B;
	}
	cout << price << endl;
	
	return 0;
}

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

int main() {
	int n; cin>>n;
  	int count;
  	for (int i=0;i<n;i++){
     	int a,b;cin>>a>>b;
      	count+=b-a+1;
    }  
  	cout<<count<<endl;
}

Measured memory_bytes: 256
//**KEEP IT SHORT AND SIMPLE**

#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FILES freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define REP(i,a,b) for (int i = a; i < b; i++)
#define NL '\n'
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef bool bl;
typedef vector < vector<long long> > vvl;
typedef vector <long long> vll;
typedef pair <long long, long long> pll;
typedef set <long long> sll;
typedef map <long long, long long> mll;
typedef map <long long, bool> mlb;
typedef priority_queue<long long, vector<long long>, greater<long long> > minPq;
double pi = 2 * acos(0.0);
int OO = 0x3f3f3f3f;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }
const int NMAX = 110;
ll n, w, W[NMAX], V[NMAX], dp[NMAX][100010];
ll solve(ll i, ll rem)
{
    if(i == n)          return 0;
    if(~dp[i][rem])     return dp[i][rem];
    return dp[i][rem] = max(solve(i + 1, rem), rem >= W[i] ? solve(i + 1, rem - W[i]) + V[i] : 0);
}
int main()
{
    IO
    cin >> n >> w;
    REP(i, 0, n)
        cin >> W[i] >> V[i];
    memset(dp, -1, sizeof dp);
    cout << solve(0, w);
    return 0;
}


Measured memory_bytes: 86272
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100105;

int inv[MAX_N],fac[MAX_N],finv[MAX_N];

void make()
{
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(int i=2;i<MAX_N;i++){
		inv[i] = MOD - (ll)inv[MOD%i] * (MOD/i) % MOD;
		fac[i] = (ll)fac[i-1] * i % MOD;
		finv[i] = (ll)finv[i-1] * inv[i] % MOD;
	}
}

int comb(int a,int b)
{
	if(a<b){
		return 0;
	}
	return fac[a] * ((ll)finv[b] * finv[a-b] % MOD) % MOD;
}

inline int add(int x,int y)
{
    return (x+y)%MOD;
}

inline int sub(int x,int y)
{
    return (x+MOD-y)%MOD;
}

inline int mul(int x,int y)
{
    return (ll)x*y%MOD;
}

vector<ll> dev;
vector<int> id;

void prime_factor(ll N)
{
	for(ll i=2;i*i<=N;i++){
		int cnt = 0;
		while(N%i == 0){
			cnt++;
			N /= i;
		}
		if(cnt){
			dev.pb(i);
			id.pb(cnt);
		}
	}
	if(N != 1){
		dev.pb(N);
		id.pb(1);
	}
	return;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    prime_factor(m);
    make();
    int ans = 1;
    each(val,id){
        ans = mul(ans, comb(val+n-1,val));
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1408
from itertools import permutations

l = [int(input()) for _ in range(5)]

minT = 10000

for a in permutations(l,5):
    t = 0
    for dish in a:
        if t%10 != 0:
            t += 10 - t%10
        t += dish
    minT = min(minT,t)
print(minT)


Measured memory_bytes: 3060
is_triangle a b c = (a^2 == b^2 + c^2) || (b^2 == a^2 + c^2) || (c^2 == a^2 + b^2)

main = do
     n_str <- getLine
     let n = read n_str::Int
     rs <- sequence $ [fmap words getLine | x <- [1..n]]
     let rsint = [map (read::String->Int) r | r <- rs]
     mapM putStrLn [if is_triangle (r!!0) (r!!1) (r!!2) then "YES" else "NO" | r <- rsint]

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

int main() {
 int A,B,C,D;
  cin>>A>>B>>C>>D;
  if((A+B)>(C+D)){
    cout<<"Left"<<endl;
  }
  if((A+B)==(C+D)){
    cout<<"Balanced"<<endl;
  }
  if((A+B)<(C+D)){
    cout<<"Right"<<endl;
  }
}


Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (N, M): (usize, usize) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };
    let (s, t): (Vec<usize>, Vec<usize>) = {
        let (mut s, mut t) = (vec![], vec![]);
        for _ in 0..M {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            s.push(iter.next().unwrap().parse().unwrap());
            t.push(iter.next().unwrap().parse().unwrap());
        }
        (s, t)
    };

    #[derive(PartialEq, PartialOrd)]
    pub struct Total<T>(pub T);

    impl<T: PartialEq> Eq for Total<T> {}

    impl<T: PartialOrd> Ord for Total<T> {
        fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
            self.0.partial_cmp(&other.0).unwrap()
        }
    }

    let G = {
        let mut G = vec![std::collections::HashSet::new(); N + 1];
        for i in 0..M { G[s[i]].insert(t[i]); }
        G
    };
    const INF: f64 = 1_000_000_000.0;
    let mut dp = vec![0.0; N + 1];
    for i in (1..N).rev() { dp[i] = G[i].iter().map(|&j| 1.0 + dp[j]).sum::<f64>() / (G[i].len() as f64); }
    let ans = (1..N).map(|k|
        if G[k].len() == 1 { Total(dp[1]) }
        else {
            let l = G[k].iter().map(|&i| i).max_by_key(|&i| Total(dp[i])).unwrap();
            let mut dp2 = vec![0.0; N + 1];
            for i in (1..N).rev() {
                dp2[i] = if i == k {
                    G[i].iter().map(|&j|
                        if j == l { 0.0 }
                        else { 1.0 + dp2[j] }
                    ).sum::<f64>() / ((G[i].len() - 1) as f64)
                } else { G[i].iter().map(|&j| { 1.0 + dp2[j] }).sum::<f64>() / (G[i].len()as f64) };
            }
            Total(dp2[1])
    }).min().unwrap().0;

    println!("{}", ans);
}

Measured memory_bytes: 14528
#include <iostream>

using namespace std;

int main(int argc, char *argv[]) {
	int N;
	cin >> N;
	int A[300][300];

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			cin >> A[i][j];
		}
	}

	for (int k = 0; k < N; k++) {
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				if (A[i][j] > A[i][k] + A[k][j]) {
					cout << -1 << endl;
					return 0;
				}
			}
		}
	}

	for (int k = 0; k < N; k++) {
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				if (A[i][j] == 0 || A[i][k] == 0 || A[k][j] == 0) continue;
				if (A[i][j] == A[i][k] + A[k][j]) {
					A[i][j] = A[j][i] = 0;
				}
			}
		}
	}

	long long ans = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			ans += A[i][j];
		}
		cout << endl;
	}

	cout << ans / 2 << endl;

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>

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

using namespace std;
typedef long long int ll;
const int INF = 1000000000;
const double PI = 3.1415926535897932;
const ll MOD = 1000000007;

// 素因数分解を行う関数
map<ll, int> PrimeFactor(ll n) {
    map<ll, int> res;
    for (ll i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            res[i]++;
            n /= i;
        }
    }
    if (n != 1) res[n] = 1;
    return res;
}

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

    map<ll, int> mp = PrimeFactor(n);
    int ans = 0;
    for (auto itr = mp.begin(); itr != mp.end(); itr++) {
        int e = itr->second;
        int i = 1;
        while (e >= i) {
            e -= i;
            i++;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
import java.util.*;
import java.io.*;
public class Main{
	static class node{
		int x,y,d;
		 node(int x1, int y1,int d1){x=x1;y=y1;d=d1;}
	}
static int bfs(int[][] arr, int sx,int sy,int dx,int dy){
	int n=arr.length,m=arr[0].length;
	Queue<node> q=new LinkedList<>();
	boolean[][] b=new boolean[n][m];
	if(arr[sx][sy]!=0)q.add(new node(sx,sy,0));
	b[sx][sy]=true;
	while(!q.isEmpty()){
		node curr=q.poll();
		int x=curr.x,y=curr.y,d=curr.d;
		if(x==dx&&y==dy){return d;}
		if(y+1<m&&arr[x][y+1]!=0&&!b[x][y+1]){q.add(new node(x,y+1,d+1));b[x][y+1]=true;}
		if(y-1>=0&&arr[x][y-1]!=0&&!b[x][y-1]){q.add(new node(x,y-1,d+1));b[x][y-1]=true;}
		if(x+1<n&&arr[x+1][y]!=0&&!b[x+1][y]){q.add(new node(x+1,y,d+1));b[x+1][y]=true;}
		if(x-1>=0&&arr[x-1][y]!=0&&!b[x-1][y]){q.add(new node(x-1,y,d+1));b[x-1][y]=true;}
	}
	return -1;
}
public static void main(String[] args) throws FileNotFoundException, IOException{
       Scanner s=new Scanner(System.in);
       BufferedWriter out=new BufferedWriter(new OutputStreamWriter(System.out));
       int n=s.nextInt(),m=s.nextInt();
       s.nextLine();
       int[][] arr=new int[n][m];
       int[][][][] dp=new int[n][m][n][m];
       for(int i=0;i<n;i++){
       	String ss= s.nextLine();
       	for(int j=0;j<m;j++){
       		if(ss.charAt(j)=='.'){arr[i][j]=1;}
       	}
       }
       int res=0;
        for(int i=0;i<n;i++){
        	for(int j=0;j<m;j++){
        		for(int k=0;k<n;k++){
        			for(int l=0;l<m;l++){
        				dp[i][j][k][l]=bfs(arr,i,j,k,l);
        				res=Math.max(res,dp[i][j][k][l]);
        			}
        		}
        	}
        }
                out.write(res+" ");
        
        out.flush();
  }
}


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

int main() {
  int A,B,C,D,L,R;
  cin >> A >> B >> C >> D;
  L = A + B;
  R = C + D;
  if (L > R) {
    cout << "Left" << endl;
  }
  else if (L < R) {
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Created by Santa on 2016/10/16.
 */
public class Main {
    static int N;
    static pair[] map;


    static class pair implements Comparable{
            public int a;
            public int b;
            public boolean c;

            pair(){
                this.a = 0;
                this.b = 0;
                this.c = false;
            }

            pair(int a, int b, boolean c){
                this.a = a;
                this.b = b;
                this.c = c;
            }

            public void set(int a, int b, boolean c) {
                this.a = a;
                this.b = b;
                this.c = c;
            }

        @Override
        public int compareTo(Object o) {
            pair aite = (pair)o;
            if(this.a > aite.a)return 1;
            if(this.a < aite.a)return -1;
            if(this.b > aite.b)return 1;

            return 0;
        }
    }

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

        N = scanner.nextInt();
        map = new pair[2 * N];

        for (int i = 0; i < N; i++) {
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            map[i] = new pair(a, b, false);
        }
        for (int i = 0; i < N; i++) {
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            map[i + N] = new pair(a, b, true);
        }

        Arrays.sort(map);
        boolean[] temp = new boolean[N];
        ArrayList<pair> a  = new ArrayList<>();

        int ans = 0;
        for (int i = 0; i < 2 * N; i++) {
            if(map[i].c == false){
                // Aの時
                a.add(map[i]);
            }else{
                // Bの時
                int max = -1;
                int maxj = -1;

                for (int j = 0; j < a.size(); j++) {
                    if(a.get(j).b < map[i].b && max < a.get(j).b){
                        max = a.get(j).b;
                        maxj = j;
                    }

                }
                if(maxj != -1){
                    ans++;
                    a.remove(maxj);
                }
            }
        }

        System.out.println(ans);


    }
}

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

int main() {
  int X;
  cin >> X;
  int A,S;
  A=X/100;
  A=A/2;
  S=10-A;
  cout << S <<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a, b, k;
    cin >> a >> b >> k;
    for (int i = a; i >= 0; i--) {
        if (a % i == 0 && b % i == 0) {
            k--;
        }
        if (k == 0) {
            cout << i << endl;
            break;
        }
    }
}

Measured memory_bytes: 256
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		text := scanner.Text()
		data := strings.Split(text, " ")
		A, _ := strconv.Atoi(data[0])
		B, _ := strconv.Atoi(data[1])

		if A == B && A == 1 {
			fmt.Println("Draw")
		} else if B == 1 {
			fmt.Println("Bob")
		} else if A == 1 {
			fmt.Println("Alice")
		} else if A < B {
			fmt.Println("Bob")
		} else if A > B {
			fmt.Println("Alice")
		} else {
			fmt.Println("Draw")
		}

	}
	if err := scanner.Err(); err != nil {
		panic(err)
	}

}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define int long long
using namespace std;

const int mod=1e9+7;
const int N=1e6+5;
int n,dp[N][4];

main()
{
    cin>>n;
    dp[0][0]=1;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<=3;j++)
        {
            for(int k=0;k<=9;k++)
            {
                int val=0;
                if(k==0) val|=1;
                if(k==9) val|=2;
                (dp[i+1][j|val]+=dp[i][j])%=mod;
            }
        }
    }
    cout<<dp[n][3];
}


Measured memory_bytes: 34792
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <functional>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define	BitSetV(Val,Bit)		((Val) |= (Bit))			
#define	BitTstV(Val,Bit)		((Val) & (Bit))				
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define MAX_DWORD				(0xFFFFFFFF)
#define	MAX_SDWORD				((SDWORD)0x7FFFFFFF)
#define	MIN_SDWORD				((SDWORD)0x80000000)
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define	MIN_QWORD				((QWORD)0x0000000000000000)
#define	MAX_SQWORD				((SQWORD)0x7FFFFFFFFFFFFFFF)
#define	MIN_SQWORD				((SQWORD)0x8000000000000000)
#define M_PI					3.14159265358979323846

typedef long					SDWORD;
typedef long long				SQWORD;
typedef unsigned long			DWORD;
typedef unsigned long long int	QWORD;
typedef long long ll;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
#define N_MAX	(200 * 1000)
#define K_MAX	(10)
#define M_MAX	(10)
#define Q_MAX	(10)
#define H_MAX	(1000)
#define W_MAX	(1000)

class UnionFind 
{
private:
	vector<int> par, rank, sz;

public:
	// コンストラクタ
	UnionFind(int n) 
	{
		par.resize(n);
		rank.resize(n, 0);
		sz.resize(n, 1);
		for (int i = 0; i < n; i++) {
			// 始めは全部ROOT
			par[i] = i;
		}
	}

	int root(int x) 
	{
		return par[x] == x ? x : par[x] = root(par[x]);
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}

	int size(int x) {
		return sz[root(x)];
	}

	void unite(int x, int y) {
		x = root(x);
		y = root(y);
		if (x == y) return;
		if (rank[x] < rank[y]) {
			par[x] = y;
			sz[y] += sz[x];
		} else {
			par[y] = x;
			sz[x] += sz[y];
			if (rank[x] == rank[y]) rank[x]++;
		}
	}
};


int main()
{
	ll N, M;
	cin >> N >> M;
	vector<ll> a(M), b(M);
	REP(i, M) {
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
	}

	UnionFind uTree(N);
	vector<ll> ans(M, 0);
	ans[M - 1] = N * (N - 1) / 2;
	for (int i = M - 1; i >= 1; i--) {
		if (uTree.same(a[i], b[i])) {
			ans[i - 1] = ans[i];
		} else {
			ll	temp1 = uTree.size(a[i]);
			ll	temp2 = uTree.size(b[i]);
			ans[i - 1] = ans[i] - temp1 * temp2;
		}
		uTree.unite(a[i], b[i]);
	}

	REP(i, M) {
		cout << ans[i] << endl;
	}
	return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<double> x(n);
  vector<string> u(n);
  rep(i,n){
    cin >> x.at(i);
    cin >> u.at(i);
  }
  int sumy=0;
  double sumbit=0;
  
  rep(i,n){
    if(u.at(i)=="JPY"){
      sumy+=x.at(i);
    }
    else if(u.at(i)=="BTC"){
      sumbit+=x.at(i);
    }
  }
  cout << sumy+sumbit*380000 << endl;
}

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

using namespace std;

#define MAX 21
typedef vector<int> Vec;
typedef vector<Vec> Mat;

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

bool inField(int x, int y)
{
    return (0 <= x && x < W && 0 <= y && y < H);
}

void put(int x, int y, Mat &f)
{
    f[y][x] = -1;
    for (int i = 0; i < 4; i++) {
        int nx = x + dx[i], ny = y + dy[i];
        while (inField(nx, ny) && f[ny][nx] != -1) {
            f[ny][nx] = -1;
            nx += dx[i]; ny += dy[i];
        }
    }
}

int memo[MAX][MAX][MAX][MAX];

int grundy(int x1, int y1, int x2, int y2, Mat &f)
{
    if (x1 > x2 || y1 > y2) {
        return 0;
    }

    if (memo[y1][x1][y2][x2] != -1) {
        return memo[y1][x1][y2][x2];
    }
        
    set<int> st;
    for (int i = y1; i <= y2; i++) {
        for (int j = x1; j <= x2; j++) {
            if (f[i][j] == 0) {
                Mat nf = f;
                put(j, i, nf);
                st.insert(grundy(x1, y1, j-1, i-1, nf) ^
                          grundy(j+1, y1, x2, i-1, nf) ^
                          grundy(x1, i+1, j-1, y2, nf) ^
                          grundy(j+1, i+1, x2, y2, nf));
            }
        }
    }   
    
    int res = 0;
    while (st.count(res)) res++;
    return (memo[y1][x1][y2][x2] = res);
}

int main()
{    
    cin >> H >> W;
    Mat f(H);
    for (int i = 0; i < H; i++) {
        f[i].resize(W);
        for (int j = 0; j < W; j++) {
            char ch;
            cin >> ch;
            f[i][j] = (ch == 'X');
        }
    }
    memset(memo, -1, sizeof(memo));
    cout << (grundy(0, 0, W-1, H-1, f) != 0 ? "First" : "Second") << endl;
    return 0;
}

Measured memory_bytes: 2024
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    string S;
    cin >> S;
    
    vector<int> N;
    rep(i, S.size()) N.push_back(S[i] - '0');
    vector<vector<int>> dp(N.size() + 1, vector<int>(2, -100100100));
    dp[0][0] = 0;
    rep(i, N.size()) rep(j, 2) {
        for (int x = 0; x <= (j ? 9 : N[i]); ++x) {
            dp[i + 1][j || x < N[i]] = max(dp[i + 1][j || x < N[i]], dp[i][j] + x);
        }
    }
    cout << max(dp[N.size()][0], dp[N.size()][1]) << endl;
    return 0;
}


Measured memory_bytes: 256
rolls = raw_input().split()
n = input()
nsrolls = [rolls[0],rolls[1],rolls[5],rolls[4]]
werolls = [rolls[0],rolls[2],rolls[5],rolls[3]]
nsrolls2 = [rolls[1],rolls[2],rolls[4],rolls[3]]
werolls2 = [rolls[1],rolls[5],rolls[4],rolls[0]]
for x in xrange(n):
    top,front = raw_input().split()
    if top in nsrolls and front in nsrolls:
        topps = nsrolls.index(top)
        frontps = nsrolls.index(front)
        tmprolls = werolls
        listmode = 0
    elif top in werolls and front in werolls:
        topps = werolls.index(top)
        frontps = werolls.index(front)
        tmprolls = nsrolls
        listmode = 1
    elif top in nsrolls2 and front in nsrolls2:
        topps = nsrolls2.index(top)
        frontps = nsrolls2.index(front)
        tmprolls = werolls2
        listmode = 1
    elif top in werolls2 and front in werolls2:
        topps = werolls2.index(top)
        frontps = werolls2.index(front)
        tmprolls = nsrolls2
        listmode = 0
    revflag = topps-frontps
    if listmode == 0:
        pass
        if revflag==3 or revflag==-1:
            print tmprolls[1]
        elif revflag==-3 or revflag==1:
            print tmprolls[3]
    else:
        if revflag==3 or revflag==-1:
            print tmprolls[3]
        elif revflag==-3 or revflag==1:
            print tmprolls[1]

Measured memory_bytes: 6468
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
	string S;
	cin >> S;
	int paper = 0, rock = 0, cnt = 0;
	for (ll i = 0; i < S.size(); i++) {
		if (paper < rock) {
			if (S[i] == 'g') { paper++; cnt++; }
			else { paper++; }
		}
		else if (paper == rock) {
			if (S[i] == 'g') { rock++; }
			else { rock++; cnt--; }
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
#define LLINF 2000000000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
// #define int long long

int main (){
  int n;
  cin >> n;
  int p[2][8];
  // 昇順にソート済みの入力
  LOOP(i,n){
    cin >> p[0][i];
  }LOOP(i,n){
    cin >> p[1][i];
  }
  int mode = -1;
  LOOP(i,n){
    if(p[0][i]!=p[1][i]){
      if(p[0][i]<p[1][i]){
        mode = 0;
      }else{
        mode = 1;
      }break;
    }
  }
  int ans = 0;
  if(mode==-1){cout << 0 << endl; return 0;}
  while( next_permutation(p[mode], p[mode]+n) ) {
    bool f = true;
    LOOP(i,n){
      if(p[0][i]!=p[1][i]){
        f = false;
        break;
      }
    }
    ans++;
    if(f==true){
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int v[N],memo[N];
int main(){
	int n,A;cin>>n>>A;
	if(n==2){
		int x,y;cin>>x>>y;
		cout<<abs(x-y);return 0;
	}
	long long ans=0LL;
	for(int i=1;i<=n;i++){
		cin>>v[i];
		if(i==1){memo[i]=0;continue;}
		if(i==2){memo[i]=abs(v[i]-v[i-1])+memo[i-1];continue;}
		if(i>A){
		memo[i]=abs(v[i]-v[i-A])+memo[i-A];
		for(int j=1;j<=A;j++){
			memo[i]=min(memo[i],abs(v[i]-v[i-j])+memo[i-j]);			
		}
		}
		else{
		memo[i]=abs(v[i]-v[1])+memo[1];
		
		}
	}
	cout<<memo[n];
	return 0;
} 

Measured memory_bytes: 4408
import sys
from itertools import accumulate
from operator import xor

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** -10

N = INT()
A = [0] + LIST() + [0]

acc1 = list(accumulate(A, xor))
acc2 = list(accumulate(A[::-1], xor))[::-1]
ans = [0] * (N+1)
for i in range(1, N+1):
    ans[i] = acc1[i-1] ^ acc2[i+1]
print(*ans[1:])


Measured memory_bytes: 45220
#include <iostream>
//#include <string>
#include <vector>
//#include <cstdlib>
//#include <algorithm>
//#include <cmath>
using namespace std;
 
int main() {
    int N, X, M=1100;
    int sum=0;
    cin >> N >> X;
    
    vector<int> m(N);
    
    for(int i = 0; i<N; i++){
        cin >> m.at(i);
        sum += m.at(i);
        if(m.at(i) < M){
            M = m.at(i);
        } 
    }
    
    
    int ans = N + (X - sum) / M;
    //cout << sum << endl;
    //cout << M << endl;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
# -*- coding: utf-8 -*-
n,W = map(int, input().split())
iw,v = map(int, input().split())
d = {
    0: [v]
    ,1: []
    ,2: []
    ,3: []
}
for _ in range(1,n):
    w,v = map(int,input().split())
    d[w-iw].append(v)

for i in range(4):
    d[i] = sorted(d[i], reverse=True)

ret = -1
for i in range(min(n,len(d[0]))+1):
    if i*iw>W:
        break
    for j in range(min(n-i,len(d[1]))+1):
        if i*iw+j*(iw+1)>W:
            break
        for k in range(min(n-(i+j),len(d[2]))+1):
            if i*iw+j*(iw+1)+k*(iw+2)>W:
                break
            for l in range(min(n-(i+j+k),len(d[3]))+1):
                if i*iw+j*(iw+1)+k*(iw+2)+l*(iw+3)>W:
                    continue
                V = sum(d[0][:i])+sum(d[1][:j])+sum(d[2][:k])+sum(d[3][:l])
                ret = max(ret, V)
print(ret)


Measured memory_bytes: 3064