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

using namespace std;

#define For(i,a,b) for(int i = a ; i <= b ; ++ i)
#define int long long

const int mod = 1e9 + 7;
int n , x , y , z , check;
int f[42][1<<18][2];

int cal(int val , int mask){
	mask = (mask << val) + (1 << (val - 1));
	mask &= ((1<<17) - 1);
	return mask;
}
signed main(){
	cin >> n >> x >> y >> z;
	x += y + z; y += z;
	check = (1 << (z - 1)) | ( 1 << (y - 1) ) | ( 1 << ( x - 1)); 
	f[0][0][0] = 1;
	For(i , 0 , n){
		For(mask , 0 , (1 << 17) - 1){
			if(f[i][mask][0] > 0)
				For(val , 1 , 10){
					int mask1 = cal(val , mask);
					if( (mask1 & check) == check ){
						f[i + 1][mask1][1] += f[i][mask][0];
						f[i + 1][mask1][1] %= mod;						
					}
					else {
						f[i + 1][mask1][0] += f[i][mask][0];
						f[i + 1][mask1][0] %= mod;
					}
				}
			if(f[i][mask][1] > 0){
				For(val , 1 , 10){
					int mask1 = cal(val , mask);
					f[i + 1][mask1][1] += f[i][mask][1];
					f[i + 1][mask1][1] %= mod;			
				}
			}	
		}
	}
	int ans = 0LL;
	For(mask , 0 , (1 << 17) - 1) ans = (ans + f[n][mask][1]) % mod;
	cout << ans;
} 

Measured memory_bytes: 151808
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

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

		int n = sc.nextInt();
		int[] a = sc.nextIntArray(n + 1);
		int[] b = sc.nextIntArray(n);

		long res = 0;

		for (int i = 0; i < n; i++) {
			if (a[i] - b[i] >= 0) {
				res += b[i];
				b[i] = 0;
				a[i] -= b[i];
			} else {
				res += a[i];
				b[i] -= a[i];
				a[i] = 0;
			}

			if (b[i] != 0) {
				if (a[i + 1] - b[i] >= 0) {
					res += b[i];
					a[i + 1] -= b[i];
				} else {
					res += a[i + 1];
					a[i + 1] = 0;
				}
			}
		}

		System.out.println(res);
	}

	static class FastScanner {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;

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

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

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

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

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

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

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

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

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

	}
}

Measured memory_bytes: 43968
B = [input() for i in range(int(input()))]
R = [input() for i in range(int(input()))]
B_dict = {}

for i in B:
    if i in B_dict:
        B_dict[i] += 1
    else:
        B_dict[i] = 1

max = 0
for item in B_dict:
    b_value = B_dict[item]
    r_value = R.count(item)
    if b_value - r_value > max:
        max = b_value - r_value

print(max)

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define null nullptr
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define precise(x) cout << fixed << setprecision(x)
#define pb push_back
#define mp make_pair
#define test int t; cin>>t; while(t--)
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

using namespace std;

typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef pair<int,int> pii;
typedef unordered_map<int,int> mp;

const int mod = 1e9+7;
const int inf = 1e18;

int fastpowmod(int a,int b){

  int res = 1;
  a %= mod;

  while(b > 0){
    if(b & 1){
      res *= a % mod;
      res %= mod;
    }

    b >>= 1;
    a = ((a%mod)*(a%mod)) %mod;

  }
  return res;

}



int ans(int n){

  int ret = 0;

  int five = 5;

  while(n/five > 0){
    ret += n/five;
    five *= 5;
  }

  return ret;


}

int digsum(int n){
  int ret = 0;
  while(n > 0){
    ret += n % 10;
    n /= 10;
  }
  return ret;
}


int32_t main(){
    FAST;


    int n;  cin >> n;
    int ans = inf;

    for(int x=1;x<n;x++){
      ans = min(ans , digsum(x) + digsum(n-x));
    }

    cout << ans;
    
    return 0;
}


Measured memory_bytes: 256
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<cmath>
#include<iomanip>
#include<iostream>
using namespace std;

int main() {
	long long int k, a, b, bis = 1, coin = 0,count=0;
	cin >> k >> a >> b;
	if (a + 1 >= b)
		bis += k;
	else {
		bis = a;
		k -= (a - 1);
		coin = k / 2;
		count = k % 2;
		bis += coin * (b - a);
		if(count==1){
			bis++;
		}
		
    }
	cout<< bis << endl;
}

Measured memory_bytes: 256
from fractions import gcd
from functools import reduce

def Skip(n , x , xl):

    xl = map(lambda i: abs(i - x), xl)
    return reduce(gcd , xl)

def main():
    n , x = map(int , input().split())
    xl = list(map(int , input().split()))
    print(Skip(n , x , xl))

if __name__ == '__main__':
    main()

Measured memory_bytes: 16304
#include <iostream>
#include <vector>
#include <string>


using namespace std;


int main()
{
	int h, w;
	cin >> h >> w;

	vector<string> a;
	a.resize(h);

	for (int i = 0;i < h;i++)
	{
		cin >> a[i];
	}

	for (int i = 0;i < h + 2;i++)
	{
		if (i == 0 || i == h + 1)
		{
			for (int j = 0;j < w + 2;j++)
			{
				cout << "#";
				
			}
			cout << "\n";
		}
		else
		{
			cout <<"#"<< a[i-1] <<"#"<< endl;
		}
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  int N;
  cin >> N;
  if (N==1) {
    cout << 1 << endl;
    return 0;
  }
  int l,m,n;
  n = 2;
  m = 1;
  rep(i,0,N-1){
    l = m + n;
    n = m;
    m = l;
  }
  cout << l << endl;
  return 0;
}


Measured memory_bytes: 256
from sys import stdin
import sys

s = stdin.readline().rstrip()

A = 'dream'
B = 'dreamer'
C = 'erase'
D = 'eraser'

s = s[::-1]
A = A[::-1]
B = B[::-1]
C = C[::-1]
D = D[::-1]

while True:
    if len(s) >= 5 and s[:5] == A:
        s = s[5:]
    elif len(s) >= 7 and s[:7] == B:
        s = s[7:]
    elif len(s) >= 5 and s[:5] == C:
        s = s[5:]
    elif len(s) >= 6 and s[:6] == D:
        s = s[6:]
    else:
        print("NO")
        sys.exit()

    if s == '':
        print ("YES")
        sys.exit()







Measured memory_bytes: 9240
MOD = 1000000000+7
n = int(input())
a = list(map(int,input().split()))

count = [0]*n
for i,ai in enumerate(a,1):
    count[ai-1] += 1
    if(count[ai-1] == 2):
        common = a.index(ai) + (n+1-i)
        break

fac = [1]*(n+2)
fac_inv =  [0]*(n+2)

for i in range(n+1):
    fac[i+1] = (fac[i] * (i+1)) %MOD
fac_inv[-1] = pow(fac[-1],MOD-2,MOD)
for i in range(n+1,0,-1):
    fac_inv[i-1] = (fac_inv[i] * i) % MOD

for i in range(1,n+2):
    ans = (fac[n+1] * (fac_inv[i] * fac_inv[n+1-i])%MOD)%MOD
    if common >= i-1:
        ans -= (fac[common] * (fac_inv[i-1] * fac_inv[common - (i-1)])%MOD)%MOD
    print(ans%MOD)

Measured memory_bytes: 17252
#include<iostream>
#include<stdlib.h>

using namespace std;

char map[100][100];
char smap[100][100];
int ans;

int serch(int nx,int ny,int maxx,int maxy)
{
	int nextx[4]={1,0,-1,0},nexty[4]={0,1,0,-1};
	map[ny][nx]='0';
	for(int i=0;i<4;i++)
		if(0<=nx+nextx[i] && nx+nextx[i]<maxx && 0<=ny+nexty[i] && ny+nexty[i]<maxy &&map[ny+nexty[i]][nx+nextx[i]]=='.')
				serch(nx+nextx[i],ny+nexty[i],maxx,maxy);
	return ans++;
}

int main()
{
	int x,y;
	int i,j;
	int sx,sy;
	
	for(;;)
	{
		cin >> x >> y ;
		
		if(x==0 && y==0)
			break;
		
		for(i=0;i<y;i++)
		{
			for(j=0;j<x;j++)
			{
				cin >> map[i][j];
				smap[i][j]=map[i][j];
				if(map[i][j]=='@')
				{
					sx=j;
					sy=i;
				}
			}
		}
		
		ans=0;
		serch(sx,sy,x,y);
		
		cout << ans << endl;
	}
}

Measured memory_bytes: 0
S = int(input())

mod = 1000000007

if S < 3:
    print(0)
else:
    sums = [0,0,0]
    vals = [0,0,0]
    runningsum = 0
    i = 3
    while(i<=S):
        val = (1+sums[i-3])%mod
        vals.append(val)
        sums.append((sums[-1]+val)%mod)
        i+=1
    print(vals[-1])


Measured memory_bytes: 9192
a, b, c, d = map(int, input().split())
import math
ab = math.sqrt(abs(a - b) ** 2)
bc = math.sqrt(abs(b - c) ** 2)
ac = math.sqrt(abs(a - c) ** 2)

print("Yes" if ac<=d or ab<=d and bc<=d else "No")

Measured memory_bytes: 3060
import copy

N = int(input())
A = list(map(int, input().split()))
A_copy = copy.deepcopy(A)
B = list(map(int, input().split()))

ans = 0

for i in range(N):
    if A[i] <= B[i]:
        B[i] -= A[i]
        A[i] = 0
        if B[i] > 0:
            if A[i+1]<=B[i]:
                A[i+1] = 0
                B[i] -= A[i+1]
            elif A[i+1]>B[i]:
                A[i+1] -= B[i]
                B[i] = 0
    elif A[i] > B[i]:
        A[i] -= B[i]
        B[i] = 0

ans = sum(A_copy) - sum(A)
print(ans)

Measured memory_bytes: 25344
#include <bits/stdc++.h>
 
#define rep(i, n) for (ll i=0;i<(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define ALL(x) (x).begin(),(x).end()
 
using namespace std;
//using ll=long long;
typedef long long ll;
typedef pair<ll, ll> pi;

ll h,w;
ll ans;
//vector<char> masu;




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

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

  map<ll, ll> m;
  ll tmp = 0;
  m[v[0]] = 0;
  ll modmod;

  rep(i, n){
    ll next = v[tmp] - 1;
    if((i+1)==k){
      cout << next + 1<< endl;
      return 0;
    }
    //cerr << next<<endl;
    if(m[next]) {
      //cerr << "#"<<endl;
      modmod = i+1 - m[next];
      k -= i;
      k %= modmod;
      k += modmod;
      
      //next = v[m[next]];
      //      cerr<<next<<endl;

      rep(kk, k-1) next = v[next] - 1;
      
      
      cout << next+1 << endl;
      return 0;
    }
    m[next] = i+1;
    tmp = next;
  }

  
  //cout << ans<<endl;

  
  
}


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

using namespace std;

struct Hoge {
  int i;
  int a;
  Hoge(int i, int a): i(i), a(a) {};
};

int main() {
  int n;
  cin >> n;
  vector<Hoge> ai;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    ai.push_back(Hoge(i, a));
  }
  
  sort(begin(ai), end(ai), [](Hoge x, Hoge y) { return x.a < y.a; });
  for (int i = 0; i < n; i++) {
    cout << ai[i].i + 1;
    if (i < n-1) cout << ' ';
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1780
N, C = gets.split.map(&:to_i)
if N == 1
  (N + C).times{gets}
  puts 0
else
  ds = Array.new(C)
  cs = Array.new(3){Array.new(C){0}}
  C.times{|i| ds[i] = gets.split.map(&:to_i)}
  N.times do |i|
    line = gets.split.map(&:to_i)
    line.each_with_index do |c, j|
      cs[(i+j)%3][c-1] += 1
    end
  end

  ans = 10000000000
  C.times do |i|
    c1 = i
    val1 = 0
    cs[0].each_with_index do |n, c|
      val1 += n * ds[c][c1]
    end
    C.times do |j|
      c2 = j
      next if c1 == c2
      val2 = 0
      cs[1].each_with_index do |n, c|
        val2 += n * ds[c][c2]
      end
      C.times do |k|
        c3 = k
        next if c1 == c3 || c2 == c3
        val3 = 0
        cs[2].each_with_index do |n, c|
          val3 += n * ds[c][c3]
        end
        ans = [ans, (val1 + val2 + val3)].min
      end
    end
  end
  puts ans
end

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

int main() {
  int n;
  cin >> n;
  vector <int> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  int ans = 0;
  for (int i = 0; i < (n-1); i++) {
    for (int j = i+1; j < n; j++) {
      ans += vec.at(i) * vec.at(j);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;



public class Main {
	public static void main(String[] args) throws IOException {
		InputReader r = new InputReader(System.in);
		String s = r.next();
		System.out.println(s.substring(0, 4)+" "+s.substring(4));
	}
	static class InputReader {
		private BufferedReader reader;
		private StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			tokenizer = null;
		}

		public InputReader(FileReader stream) {
			reader = new BufferedReader(stream);
			tokenizer = null;
		}

		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return null;
			}
		}

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

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

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

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


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define itn int
typedef long long ll;
typedef pair<ll,ll> p;

string s,t;
vector<string> v;

void match(int pos)
{
  for(int i = pos; i < pos + int(t.size()); i++)
  {
    if(s[i] != t[i-pos] && s[i] != '?') return;
  }
  string tmp = s;
  for(int i = 0; i < int(s.size()); i++)
  {
    if(s[i] == '?') tmp[i] = 'a';
    if(i >= pos && i < pos + int(t.size())) tmp[i] = t[i-pos];
  }
  // v.push_back(tmp.substr(pos, int(t.size())));
  v.push_back(tmp);
}

int main()
{
  cin >> s >> t;
  for (int i = 0; i <= int(s.size()) - int(t.size()); i++)
  {
    match(i);
  }
  sort(all(v));
  // for(string tmp : v) cout << tmp << endl;
  if(int(v.size()) == 0) cout << "UNRESTORABLE" << endl;
  else cout << v[0] << endl;
}

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

using namespace std;

int main(){
	int n;
	scanf("%d",&n);
	int prev;
	scanf("%d", &prev);
	int ans=0;
	for(int i=2,current;i<=n;i++){
		scanf("%d", &current);
		if(prev==i-1){
			ans++;swap(prev,current);
		}		
		else if(i==n and current==i){
			ans++;swap(prev,current);
		}
		prev = current;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void)
{
	char map_1[32][2][9] = {{"A", "100101"},   {"B", "10011010"}, {"C", "0101"},     {"D", "0001"},
	                        {"E", "110"},      {"F", "01001"},    {"G", "10011011"}, {"H", "010000"},
							{"I", "0111"},     {"J", "10011000"}, {"K", "0110"},     {"L", "00100"},
							{"M", "10011001"}, {"N", "10011110"}, {"O", "00101"},  	 {"P", "111"},
							{"Q", "10011111"}, {"R", "1000"},     {"S", "00110"},    {"T", "00111"},
							{"U", "10011100"}, {"V", "10011101"}, {"W", "000010"},   {"X", "10010010"},
							{"Y", "10010011"}, {"Z", "10010000"}, {" ", "101"},      {".", "010001"},
							{",", "000011"},   {"-", "10010001"}, {"'", "000000"},   {"?", "000001"} };
	char map_2[32][2][6] = {{"A", "00000"}, {"B", "00001"}, {"C", "00010"}, {"D", "00011"},
							{"E", "00100"}, {"F", "00101"}, {"G", "00110"}, {"H", "00111"},
							{"I", "01000"}, {"J", "01001"}, {"K", "01010"}, {"L", "01011"},
							{"M", "01100"}, {"N", "01101"}, {"O", "01110"}, {"P", "01111"},
							{"Q", "10000"}, {"R", "10001"}, {"S", "10010"}, {"T", "10011"},
							{"U", "10100"}, {"V", "10101"}, {"W", "10110"}, {"X", "10111"},
							{"Y", "11000"}, {"Z", "11001"}, {" ", "11010"}, {".", "11011"},
							{",", "11100"}, {"-", "11101"}, {"'", "11110"}, {"?", "11111"} };
	char str[50001];
	char temp[50001], *ptr;
	int i, flag;
	int ch;
	
	memset(str, '\0', sizeof(str));
	while (scanf("%[^\n]", str) != EOF){
		getchar();
		
		memset(temp, '\0', sizeof(temp));
		
		i = 0;
		while (str[i] != '\0'){
				if ('A' <= str[i] && str[i] <= 'Z') ch = str[i] - 'A';
				else {
					switch (str[i]){
						case ' ' : ch = 26; break;
						case '.' : ch = 27; break;
						case ',' : ch = 28; break;
						case '-' : ch = 29; break;
						case '\'': ch = 30; break;
						case '?' : ch = 31; break;
					}
				}
				strcat(temp, map_1[ch][1]);
				i++;
		}
		
		if (strlen(temp) % 5 != 0) strncat(temp, "00000",5 - strlen(temp) % 5);
		memset(str, '\0', sizeof(str));
		flag = 1;
		ptr = &temp[0];
		while (flag){
			flag = 0;
			for (i = 0; i < 32; i++){
				if (strncmp(map_2[i][1], ptr, 5) == 0){
					strcat(str, map_2[i][0]);
					ptr += 5;
					flag = 1;
				}
			}
		}
		
		printf("%s\n", str);
		memset(str, '\0', sizeof(str));
	}
	return (0);
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<set>
using namespace std;
#define ll long long
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define fi first
#define se second
#define pr(x) cerr<<#x<<"="<<(x)<<endl
#define pri(x,lo) {cerr<<#x<<"={";for (ll ol=0;ol<=lo;ol++)cerr<<x[ol]<<",";cerr<<"}"<<endl;}
#define inf 100000000
#define N 1001000
ll i,sum[N],n,ans,mx[N],v[N],x[N],c;
void solve()
{
	for (i=1;i<=n;i++) sum[i]=sum[i-1]+v[i];
	for (i=1;i<=n;i++) sum[i]=sum[i]-x[i];
	for (i=1;i<=n;i++) mx[i]=mx[i-1],mx[i]=max(mx[i],sum[i]);
//	pri(mx,n);
	ans=max(ans,mx[n]);
	ll now=0;
	for (i=n;i>=1;i--) now+=v[i],ans=max(ans,now-(c-x[i])*2+mx[i-1]);
}
int main()
{
	scanf("%lld %lld",&n,&c);
	for (i=1;i<=n;i++)
	{
		scanf("%lld %lld",&x[i],&v[i]);
	}
	solve();
	//pr(ans);
	for (i=1;i<=n;i++) x[i]=c-x[i];
	reverse(x+1,x+1+n);
	reverse(v+1,v+1+n);
	//pri(x,n);
	//pri(v,n);
	solve();
	printf("%lld\n",ans);
}
	

Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
//#define Max 10001;
struct p{
	int health;
	int point;
};
int main() {
int h,n,fin,x,temp,cand;
cin>>h>>n;
p spell[n];
//int m=1000000;
for(int i=0;i<n;i++){
	cin>>spell[i].health>>spell[i].point;
	//m=min(spell[i].health,m);
}
int len=h+1;
	int health[len];
	health[0]=0;
	//for(int i=1;i<m;i++)
	//health[i]=1000000;
	//cout<<"m is h is "<<m<<" "<<h<<endl;
	for(int i=1;i<=h;i++){

		 fin=1000000004;
		for(int j=0;j<n;j++){

			 x=spell[j].health;
			if((i-x)>-1){
				temp=health[i-x];
			}
			else{
			temp=0;
			}
            cand=spell[j].point+temp;
			fin=min(fin,cand);
		}
		health[i]=fin;

	}
//for(int i=0;i<len;i++)
   // cout<<health[i]<<" ";
   cout<<health[h];
}
/*100 6
1 1
2 3
3 9
4 27
5 81
6 243*/


Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;

ll n;

int cal(ll x) {
	int tot = 0;
	while (x) {
		++tot; x /= 10;
	}
	return tot;
}

int main() {
	cin >> n;
	ll sq = floor(sqrt(n));
	while (sq) {
		if (n % sq == 0) {
			printf("%d\n", cal(n / sq));
			return 0;
		}
		--sq;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define f first
//#define s second
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define loop(i,n) for(int i=0; i<(n); i++)
#define loop3(i,a,n) for(int i=a; i<(n); i++)
const int mod =1e9 + 7;
int main()
{
    fast
 ll n,m;
 cin>>n>>m;
char a[n+1][m+1];
for(int i=1; i<=n; i++)
{
    for(int j=1; j<=m; j++) cin>>a[i][j];
}
   int dp[n+1][m+1];
   memset(dp,0,sizeof(dp));
    if(a[1][1]=='.') dp[1][1]=1;
 for(ll i=1; i<=n; i++)
  {

      for(ll j=1; j<=m; j++)
      {
          if(i==1 && j==1) continue;
          if(a[i][j]=='#') dp[i][j]=0;
          else dp[i][j]=((dp[i-1][j]%mod)+(dp[i][j-1]%mod));
    //      cout<<dp[i][j]<<" ";
      }
  //    cout<<endl;
  }
  cout<<dp[n][m]%mod<<endl;
}


Measured memory_bytes: 8424
/*input
4 -2 -2 4
3
0 0 2
4 0 1
0 4 1
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie(0) , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define MAX 1010
#define INF 0x3f3f3f3f

int n , r[MAX];
PII c[MAX] , s , t;
double dis[MAX];
double DIS(int x , int y){
    double vx = c[x].A - c[y].A;
    double vy = c[x].B - c[y].B;
    double val = sqrt(vx * vx + vy * vy) - r[x] - r[y];
    return max(val , 0.0);
}
int32_t main(){
    IOS;
    cin >> s.A >> s.B >> t.A >> t.B;
    cin >> n;
    REP(i , 1 , n + 1) cin >> c[i].A >> c[i].B >> r[i];
    c[n + 1] = s , c[n + 2] = t , n += 2;

    priority_queue<pair<double , int> , vector<pair<double , int>> , greater<pair<double , int>>> pq;
    REP(i , 1 , n + 1) dis[i] = 1e19;
    pq.push(mp(0 , n - 1)) , dis[n - 1] = 0;
    while(pq.size()){
        double step = pq.top().A;
        int now = pq.top().B;
        pq.pop();
        if(abs(dis[now] - step) > 1e-9) continue;
        REP(i , 1 , n + 1){
            if(dis[i] > dis[now] + DIS(i , now)){
                dis[i] = dis[now] + DIS(i , now);
                pq.push(mp(dis[i] , i));
            }
        }
    }
    printf("%.11f\n", dis[n]);
    return 0;
}

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

int main(int argc, char const *argv[])
{
	int n; cin >> n;
	vector<int> a(n); rep(i, n) cin >> a[i];
	vector<int> l(n); {
		l[0] = a[0];
		rep(i, n - 1) {
			l[i + 1] = max(l[i], a[i + 1]);
		}
	}
	vector<int> r(n); {
		r[n - 1] = a[n - 1];
		for (int i = n - 2; i >= 0; --i) {
			r[i] = max(r[i + 1], a[i]);
		}
	}
	rep(i, n) {
		int ans = 0;
		if (i != 0) ans = max(ans, l[i - 1]);
		if (i != n - 1) ans = max(ans, r[i + 1]);
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3968
#include<stdio.h>

int main()
{
    int n, x, m[1005], i, sum=0, min=1002, total;

    scanf("%d %d", &n, &x);

    for(i=0; i<n; i++){
        scanf("%d", &m[i]);
        sum += m[i];
        if(m[i]<min)
            min=m[i];
    }

    x = x-sum;

    if(x > min){
        total = n+ x/min;
    }
    else
        total = n;

    printf("%d\n", total);

    return 0;
}



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

const int64_t MOD = 1e9+7;

//繰り返し二乗法
int64_t powmod(int64_t x, int64_t n) { 
  int64_t ans = 1;
  while (n > 0) {
    if ((n & 1) == 1) {
      ans = ans * x;
      ans %= MOD;
    }
    x = x * x;//一周する度にx, x^2, x^4, x^8となる
    x %= MOD;
    n >>= 1; //桁をずらす n = n >> 1
  }
  return ans;
}

int main(){
  int64_t N;
  cin >> N;
  int64_t all = powmod(10,N);
  int64_t ans = 0;
  ans += powmod(9,N)*2;
  ans %= MOD;
  ans -= powmod(8,N);
  if(ans < 0){
    ans += MOD;
  }
  ans = all - ans;
  if(ans < 0){
    ans += MOD;
  }
  cout << ans %MOD << endl;
}


Measured memory_bytes: 3604
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n;
vector<i64> p;
int main() {
  cin >> n;
  read_n(p, n);
  i64 ans = 0;
  for (i64 i = 1; i < n - 1; ++i) {
    vector<i64> a(3);
    copy(begin(p) + i - 1, begin(p) + i + 2, begin(a));
    sort(begin(a), end(a));
    if (a[1] == p[i]) ++ans;
  }
  cout << ans << '\n';
  return 0;
}



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

import collections
import math


class Vector2(collections.namedtuple("Vector2", ["x",  "y"])):

    def __add__(self, other):
        return Vector2(self.x + other.x, self.y + other.y)

    def __sub__(self, other):
        return Vector2(self.x - other.x, self.y - other.y)

    def __mul__(self, scalar):
        return Vector2(self.x * scalar, self.y * scalar)

    def __neg__(self):
        return Vector2(-self.x, -self.y)

    def __pos__(self):
        return Vector2(+self.x, +self.y)

    def __abs__(self):  # norm
        return math.sqrt(float(self.x * self.x + self.y * self.y))

    def dot(self, other):  # dot product
        return self.x * other.x + self.y * other.y

    def cross(self, other):  # cross product
        return self.x * other.y - self.y * other.x


def getDistanceSP(segment, point):
    p = point
    p1, p2 = segment
    if (p2 - p1).dot(p - p1) < 0:
        return abs(p - p1)
    if (p1 - p2).dot(p - p2) < 0:
        return abs(p - p2)
    return abs((p2 - p1).cross(p - p1)) / abs(p2 - p1)


def getDistance(s1, s2):
    if 0:  # intersect
        return 0
    a, b = s1
    c, d = s2
    return min(getDistanceSP(s1, c), getDistanceSP(s1, d), getDistanceSP(s2, a), getDistanceSP(s2, b))


def ccw(p0, p1, p2):
    a = p1 - p0
    b = p2 - p0
    if a.cross(b) > 0:
        return 1
    elif a.cross(b) < 0:
        return -1
    elif a.dot(b) < 0:
        return 2
    elif abs(a) < abs(b):
        return -2
    else:
        return 0


if __name__ == '__main__':

    a, b, c, d = map(int, input().split())
    p0 = Vector2(a, b)
    p1 = Vector2(c, d)
    q = int(input())
    ans = []
    for _ in range(q):
        e, f = map(int, input().split())
        p2 = Vector2(e, f)
        ans.append(ccw(p0, p1, p2))
    dic = {1: "COUNTER_CLOCKWISE", -1: "CLOCKWISE",
           2: "ONLINE_BACK", -2: "ONLINE_FRONT", 0: "ON_SEGMENT"}
    for a in ans:
        print(dic[a])



Measured memory_bytes: 6280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+5;
int n;
ll a, b;
ll h[maxn];
ll check(ll m){
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        if((h[i] - b * m) > 0)
            ans+=ceil((double)(h[i] - b * m) / (a-b));
    }
    return ans;
}
int main(){
//freopen("input.txt","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin >> n >> a >> b;
    for(int i = 1; i <= n; i++){
        cin >>  h[i];
    }
    ll l = 1, r = 1e9;
    while(l < r){
        ll mid = l+(r-l)/2;
        if(check(mid) > mid) l = mid+1;
        else r = mid;
   // cout << l << r <<endl;
    }

    cout << l << endl;
    return 0;
}

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

#define ll long long
#define f first
#define se second
#define pb push_back
#define mp make_pair
#define boost cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0)
#define lb lower_bound
#define ub upper_bound
#define pii pair<ll, ll>

using namespace std;

const int N = 1e5 + 100, mod = 1e9, inf = 1e9 + 7;
ll n, m, dp[N];
pii a[N];

ll bin_pow(int x, int y){
    if(y == 0)
        return 1;
    if(y == 1)
        return x;
    if(y % 2 == 0){
        ll z = bin_pow(x, y / 2);
        return (z * z) % mod;
    }
    return (bin_pow(x, y - 1) * x) % mod;
}


int main(){
    boost;
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        cin >> a[i].se >> a[i].f;
    }
    sort(a + 1, a + n + 1);
    reverse(a + 1, a + n + 1);
    for(int i = 1; i <= n; i++){
        for(int j = m; j >= 1; j--){
            if(j - a[i].se == 0 || (j - a[i].se > 0 && dp[j - a[i].se])){
                dp[j] = max(dp[j], dp[j - a[i].se] + a[i].f);
            }
        }
    }
    ll ans = 0;
    for(int i = 1; i <= m; i++){
        ans = max(ans, dp[i]);
    }
    cout << ans;
    return 0;
}



Measured memory_bytes: 1024
N = int(input())
a = []
b = []


for i in range(N):
    tmp_a, tmp_b = map(int, input().split())
    a.append(tmp_a)
    b.append(tmp_b)

ans = max(a)
max_ind = a.index(ans)
ans += b[max_ind]
print(ans)


Measured memory_bytes: 11052
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n), acc(n+1, 0);
    rep(i, 0, n) cin >> a[i];
    sort(a.begin(), a.end());

    rep(i, 0, n) acc[i+1] = acc[i] + a[i];
    rep(i, 0, n+1) cerr << acc[i] << endl;
    ll ans = 1;
    for(ll i = n-1; i > 0; i--) {
        cerr << a[i] << " " << acc[i] << endl;
        if( a[i] <= 2 * (acc[i]) ) ans++; 
        else break;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6112
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    string s;
    cin>>s;
    int n=s.size();
    for(int i=2;i<=n;i+=2){
        int cnt=0;
        for(int j=0;j<(n-i)/2;j++){
            if(s[j]==s[j+(n-i)/2]) cnt++;
        }
        if(cnt==(n-i)/2){
            cout<<n-i;
            return 0;
        }
    }
}

Measured memory_bytes: 3596
#include<iostream>

using namespace std;

int main(){

  int sum[8];
  double r, l;

  for(int i = 0; i < 8; i++) sum[i] = 0;

  while(cin >> r >> l){
    if(r >= 1.1) sum[0]++;
    else if(r >= 0.6)sum[2]++;
    else if(r >= 0.2)sum[4]++;
    else sum[6]++;

    if(l >= 1.1) sum[1]++;
    else if(l >= 0.6)sum[3]++;
    else if(l >= 0.2)sum[5]++;
    else sum[7]++;

  }

  for(int i = 0; i < 8; i+=2){
    cout << sum[i] <<" "<< sum[i+1] <<endl;
  }

  return 0;
}

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

int main(int argc, char const *argv[])
{
	int k, n; cin >> k >> n;
	vector<int> a(n); rep(i, n) cin >> a[i];

	int ans = k;
	rep(i, n) {
		int dist = abs(a[(i + 1) % n] - a[i]);
		int diff = min(k - dist, dist);
		ans = min(ans, k - diff);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int N;
  int Y;

  cin >> N >> Y;

  REP(i, N+1) {
    REP(j, N+1) {
      int k = N - i - j;
      if (k >= 0 && i * 10000 + j * 5000 + k * 1000 == Y) {
        printf("%d %d %d\n", i, j, k);
        return 0;
      }
    }
  }
  cout << "-1 -1 -1";
}

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

long long gcd(long long aaa,long long bbb) {
    if(bbb==0) {
        return aaa;
    }
    return gcd(bbb,aaa%bbb);
}

int main (){

    int H,W,N;
    cin >> H >> W >> N;
    int a[N],count=0,countt=0;
    int ans[H][W];
    for(int i = 0; i < N; i++) {
        cin >> a[i];
    }
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < a[i]; j++) {
            if(count == W) {
                countt ++;
                count = 0;
            }
            ans[countt][count] = i+1;
            count++;
        }
    }
    for(int i = 1; i < H; i+=2) {
        reverse(ans[i],ans[i]+W);
    }
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            cout << ans[i][j];
          	if(j != W) {
              	cout << ' ';
        	}
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <cctype>

using namespace std;

inline string& max_one(string &a, string &b) {
    if(a.size() > b.size()) return a;
    if(b.size() > a.size()) return b;
    return a > b ? a : b;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    while(true) {
        int W, H;
        cin >> W >> H;
        if(!W && !H) break;

        vector<string> matrix(H);
        for(int i = 0; i < H; ++i) {
            cin >> matrix[i];
        }
        vector<vector<string> > largest(H, vector<string>(W));
        string ans = "";
        for(int r = H-1; r >= 0; --r) {
            for(int c = W-1; c >= 0; --c) {
                if(isdigit(matrix[r][c])) {
                    string right(""), down("");
                    if(c+1 < W) {
                        right = largest[r][c+1];
                    }
                    if(r+1 < H) {
                        down = largest[r+1][c];
                    }
                    largest[r][c] = string("") + matrix[r][c] + max_one(right, down);
                    if(matrix[r][c] != '0') {
                        ans = max_one(ans, largest[r][c]);
                    }
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1340
function Main(input) {
    input = input.split('\n')[0];
    qwww = "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";
    Alp = qwww.split("	");
    console.log(Alp[Alp.indexOf(input)+1]);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
N,*A = `dd`.split.map &:to_i
sa = []
A.each{ |a| sa << (sa[-1] || 0) + a }
#p A, sa
ans = A.inject(:+)
(1...N-2).each{ |i|
  bc = sa[0..i]
  de = sa[i+1..N-1]
#  p [bc, de]
  san = sa[N-1]
  sai = sa[i]
  j = (0...i).bsearch{ |j|
    sai/2 <= sa[j]
  } || i-1
  if 0 < j
    j -= 1 if (sai-sa[j-1]-sa[j-1]).abs < (sai-sa[j]-sa[j]).abs
  end

  k = (i+1...N-1).bsearch{ |k|
    (san-sai)/2 <= (sa[k] - sai)
  } || N-2
  if i+1 < k
    k -= 1 if (san-sa[k-1]-sa[k-1]+sa[i]).abs < (san-sa[k]-sa[k]+sa[i]).abs
  end

  vs = [sa[j], sa[i]-sa[j], sa[k]-sa[i], sa[-1]-sa[k]]
  v = vs.max - vs.min
  #p [A[0..j], A[j+1..i], A[i+1..k], A[k+1..-1]]
  #p [sa[0..j], sa[j+1..i], sa[i+1..k], sa[k+1..-1]], vs, v
  #fail if vs.inject(:+) != sa[-1]
  ans = v if v < ans
}
p ans

Measured memory_bytes: 25232
import java.util.*;
import java.lang.*;

/**
 * HowManyWays
 */
public class Main {

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

        while (true) {
            int ans = 0;

            int n = Integer.parseInt(sc.next());
            int x = Integer.parseInt(sc.next());

            if (n == 0 && x == 0)
                break;

            // 1からnまでの数で3つ選んで足してxを作れるのが何パターンか
            for (int i = 1; i < n - 1; i++) {
                for (int j = i + 1; j < n; j++) {
                    for (int k = j + 1; k <= n; k++) {
                        if (i + j + k == x) {
                            ans++;
                        }
                    }
                }
            }

            System.out.println(ans);
        }
        sc.close();
    }
}


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

typedef long long ll;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007


#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define tt int t; cin>>t; while(t--)
#define lo(i,a,b) for(int i=a;i<b;i++)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()
#define mem(a,b) memset(a,b,sizeof(a))

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}


int main()
{
   su;
   int a,b;
   cin>>a>>b;
   if(b%a)
    cout<<b-a<<nl;
   else
    cout<<a+b<<nl;
   return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define ll long long int
const ll mod=1e9+7;
const int maxn=2e5+50;
using namespace std;
 main()
//int found; found=chaine.find(cara); if (found!=std::string::npos) how to verify if a caracter exists in a chaine
// toupper(caractere) ==> return the majuscule of a caractere
//floor(x) Returns the largest integer smaller than x
//ceil(x) returns  Returns the smallest integer greater
//printf("%.10f",res);
{  
  int n,d;
  cin>>n>>d;
  int mat[50][50];
  for(int i=0;i<n;i++)
  {
  	for(int j=0;j<d;j++)
  	{
  		cin>>mat[i][j];
	  }
  }
  int res;
  res=0;
  for(int i=0;i<n;i++)
  {
  	for(int j=i+1;j<n;j++)
  	{
  		double z=0.0;
  		for(int k=0;k<d;k++)
  		{
  			z+=1.0*(mat[i][k]-mat[j][k])*(mat[i][k]-mat[j][k]);
		}
		int x;
		x=sqrt(z);
		if(sqrt(z)==x)
		{
			res++;
		}
	}
  }
  cout<<res;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
#define CHOKUDAI_ const
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using cll = DANCE_ DANCE_ CHOKUDAI_;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll n; cin >> n;
    vector<ll> a(n), b(n), d(n);
    REP(i, n) cin >> a[i];
    REP(i, n) cin >> b[i];
    REP(i, n) d[i] = b[i] - a[i];

    ll pluses = 0, minuses = 0;
    REP(i, n) {
        if (d[i] > 0) {
            pluses += d[i] / 2;
        } else if (d[i] < 0) {
            minuses += -d[i];
        }
    }

    cout << Yes(pluses >= minuses) << endl;
    
}

Measured memory_bytes: 512
import itertools
N, M, Q = map(int, input().split())
m = list()
res = -100
for i in range(Q):
    n = list(map(int, input().split()))
    m.append(n)
l = [x for x in range(1, M + 1)]
p = itertools.combinations_with_replacement(l, N)
for p in p:
    total = 0
    for i in range(Q):
        a = m[i][0]
        b = m[i][1]
        A = p[a - 1]
        B = p[b - 1]
        C = B - A
        if m[i][2] == C:
            total = total + m[i][3]
    if res < total:
        res = total
print(res)

Measured memory_bytes: 9156
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long lli;
typedef pair<lli,lli> ii;
typedef vector<lli> vi;
typedef vector<vector<lli> > vvi;
typedef vector<ii> vii;
 
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define FF first
#define SS second

lli mod = 1e9 +7;
lli n, arr[410][410], inp[410], presum[410];

lli dp(int l, int r)
{
	if(arr[l][r]<1e18) return arr[l][r];
	else if(l==r) return arr[l][r]=0;
	else
	{
		for(int i=l; i<r; i++)
			arr[l][r] = min(dp(l,i)+dp(i+1,r)+presum[r]-presum[l-1], arr[l][r]);
		return arr[l][r];
	}
}

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	for(int i=0; i<410; i++)
	{
		for(int j=0; j<410; j++)
			arr[i][j]=1e18;
	}
	cin >> n;
	for(int i=1; i<=n; i++)
		cin >> inp[i], presum[i]=presum[i-1]+inp[i];
	cout << dp(1, n)<<'\n';
}

Measured memory_bytes: 4988
use proconio::input;

#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::ops::*;

#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
struct Struct;

//#[proconio::fastout]
fn main() {
    input! {
        mut n: usize,
        x: usize,
        m: usize,
    }

    let mut a_to_i = vec![0; m];
    let mut acc = vec![0; m + 1]; // acc[j] = Σai  1<=i<=j

    let mut i = 1;
    let mut a = x;
    let mut asum = x as u64;
    acc[i] = asum;
    a_to_i[a] = i;

    while i < n {
        let next_a = (a as u64 * a as u64 % m as u64) as usize;
        if a_to_i[next_a] != 0 {
            /*
               1  2            before_loop // i_before_loop=2
                     3  4  5   loop // period=3
                     6  7  8   loop // complete_loop_count=2
                     9  10     after_loop // after_loop_len=2
                now i = 5
            */
            let i_before_loop = a_to_i[next_a] - 1;
            let period = i - i_before_loop;
            let complete_loop_count = (n - i_before_loop) / period;
            let after_loop_len = n - i_before_loop - complete_loop_count * period;

            let sum_before_loop = acc[i_before_loop];
            let sum_in_loop = (acc[i] - acc[i_before_loop]) * complete_loop_count as u64;
            let sum_after_loop = acc[i_before_loop + after_loop_len] - acc[i_before_loop];
            let ans = sum_before_loop + sum_in_loop + sum_after_loop;

            println!("{}", ans);

            return;
        }

        i += 1;
        a = next_a;
        asum += a as u64;
        acc[i] = asum;
        a_to_i[next_a] = i
    }

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


Measured memory_bytes: 3072
a,b = map(int,input().split())
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

print(len(set(prime_factorize(a))&set(prime_factorize(b)))+1)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
int main(){
  int a,b;
  cin  >> a >> b;
  int c[b],d[a];
  if (a > b){
    for (int i = 0; i < a; i++){
     d[i] = b;
     cout << d[i];
    }
   cout <<'\n'; 
  }
  else{
   for (int i = 0; i < b; i++){
     c[i] = a;
     cout << c[i];
    }
   cout <<'\n';  
  }
  return 0;   
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define uint unsigned
#define ull unsigned ll
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a))
#define CPY(a,b) memcpy(a,b,sizeof(a))
using namespace std;
int n,spe[300005];
char s[300005];
ll ans;
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	For(i,1,n) if (s[i]=='A') spe[i]=1;
	For(i,2,n) if (s[i-1]=='B'&&s[i]=='C') spe[i]=2,spe[i-1]=3;
	int s1=0;
	For(i,1,n)
		if (!spe[i]) s1=0;
		else if (spe[i]==1) ++s1;
		else if (spe[i]==3) ans+=s1;
	printf("%lld\n",ans);
}

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

    total = sum(A)
    s = 0
    m = total
    for a in A:
        s += a
        tmp = abs(total- 2*s)
        if tmp < m:
            m = tmp

    print(m)
if __name__ == '__main__':
    main()

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

using namespace std;

#define int long long

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; ++i)
    {
        if (i % 3 && i % 5)
        {
            ans += i;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(void)
{
	int x,y;

	while(1)
	{
		cin >> x >> y;
		if((x == 0) && (y == 0))
			break;
		if(x < y)
		{
			cout << x << " " <<  y << endl;
		} else {
			cout << y << " " << 	x << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3072
li = list(map(int,input().split()))

li.sort()

a = li[1] - li[0]
b = li[2] - li[1]
c = li[2] - li[0]

cnt = 0

while True:
    if a != 0:
        if a % 2 == 0:
            a -= 2
            c -= 2
            cnt += 1
        else:
            a -= 1
            b += 1
            cnt += 1
    else:
        cnt += b
        break
    
print(cnt)


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
    cout << "Possible" << endl;
  } else {
    cout << "Impossible" << endl;
  }
  return 0;
}


Measured memory_bytes: 3000
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
long long dp[2][3] = {};

long long pow3[100000];
void init() {
    pow3[0] = 1;
    for(int i=1; i<100000; ++i) {
        pow3[i] = pow3[i - 1] * 3 % MOD;
    }
}

int main() {
    init();
    string S;
    cin >> S;

    int Q = 0;
    for(int i=0; i<S.size(); ++i) {
        if(S[i] == 'A') {
            dp[(i + 1) & 1][0] = dp[i & 1][0] + pow3[Q];
            dp[(i + 1) & 1][1] = dp[i & 1][1];
            dp[(i + 1) & 1][2] = dp[i & 1][2];
        } else if(S[i] == 'B') {
            dp[(i + 1) & 1][0] = dp[i & 1][0];
            dp[(i + 1) & 1][1] = dp[i & 1][1] + dp[i & 1][0];
            dp[(i + 1) & 1][2] = dp[i & 1][2];
        } else if(S[i] == 'C') {
            dp[(i + 1) & 1][0] = dp[i & 1][0];
            dp[(i + 1) & 1][1] = dp[i & 1][1];
            dp[(i + 1) & 1][2] = dp[i & 1][2] + dp[i & 1][1];
        } else {
            dp[(i + 1) & 1][0] = 3 * dp[i & 1][0] + pow3[Q];
            dp[(i + 1) & 1][1] = 3 * dp[i & 1][1] + dp[i & 1][0];
            dp[(i + 1) & 1][2] = 3 * dp[i & 1][2] + dp[i & 1][1];
            ++Q;
        }
        for(int j=0; j<3; ++j) dp[(i + 1) & 1][j] %= MOD;
    }
    cout << dp[S.size() & 1][2] << endl;
}

Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <numeric>
#include <map>
#include <utility>
using namespace std;
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
int main(void){
    int a,b;
    cin>>a>>b;
    if(a==1)a=15;
    if(b==1)b=15;
    cout<<(a>b?"Alice":a<b?"Bob":"Draw")<<endl;
    return 0;
}


Measured memory_bytes: 256