akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <iostream>
#include <string>
#include <vector>

#define rep(inc, bgn, end) for (int inc = bgn; inc < end; ++inc)
#define repe(inc, bgn, end) for (int inc = bgn; inc <= end; ++inc)

using ll = long long;
using namespace std;

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

    string s;
    cin >> s;

    int wsum = 0;
    int bsum = 0;
    rep(i, 0, s.size()) {
        if (s[i] == '.') {
            wsum++;
        } else {
            bsum++;
        }
    }

    int wcnt = 0;
    int bcnt = 0;

    // all black
    int ans = wsum;
    // b and w
    rep(i, 0, s.size()) {
        if (s[i] == '.') {
            wcnt++;
        } else {
            bcnt++;
        }

        ans = min(bcnt + wsum - wcnt, ans);
    }

    // all white;
    ans = min(bsum, ans);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int e;
int main(){
	while(cin>>e,e){
		int ans=10000000;
		for(int z =0;z*z*z<=e;z++){
			for(int y =0;y*y+z*z*z<=e;y++){
				int x =e-y*y-z*z*z;
				if(ans >x+y+z){
					ans =x+y+z;
				}
			}
		}
		cout <<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
#define LL long long
const int N = 100;
const LL inf = 1e11;
struct node{
	int to,rev;
	LL flow;
};
vector<node> g[N+10];
queue<int > q;
int n,m,s,t;
int level[N+10],cur[N+10];
bool bfs() {
	memset(level,0,sizeof(level));
	while(!q.empty()) q.pop();
	q.push(s); level[s]=1;
	while(!q.empty()) {
		int u=q.front(); q.pop();
		//printf("%d\n",u);
		if(u==t) return 1;
		for(int i=0;i<(int)g[u].size();i++) {
			int v=g[u][i].to;
			LL f=g[u][i].flow;
			if(level[v]==0 && f!=0) {
				level[v]=level[u]+1;
				q.push(v);
			}
		}
	}
	return 0;
}
LL dfs(int u,int t,LL maxf) {
	if(u==t) return maxf;
	LL ret=0;
	for(int i=cur[u];i<(int)g[u].size();i++) {
		int v=g[u][i].to;
		LL f=g[u][i].flow;
		if(level[u]+1==level[v] && f) {
			LL Min=min(maxf-ret,f);
			f=dfs(v,t,Min);
			if(f>0) {
				g[u][i].flow-=f;
				g[v][g[u][i].rev].flow+=f;
				ret+=f;
				cur[u]=i;
			}
			if(maxf==ret) return ret;
		}
	}
	return ret;
}
void addedge(int u,int v,LL f) {
	node e; e.to=v; e.flow=f; e.rev=(int)g[v].size();
	g[u].push_back(e);
	e.to=u; e.flow=0; e.rev=(int)g[u].size()-1;
	g[v].push_back(e);
}
int main() {
	scanf("%d",&n);
	s=0,t=n+1;
	LL ans=0;
	for(int i=1;i<=n;i++) {
		int aa;
		scanf("%d",&aa);
		if(aa>0) ans+=aa;
		if(aa==0) continue;
		if(aa>0) addedge(s,i,aa);
		if(aa<0) addedge(i,t,-aa);
	}
	for(int i=1;i<=n;i++)
		for(int j=i+i;j<=n;j+=i)
			addedge(j,i,inf);
	while(bfs()) {
		memset(cur,0,sizeof(cur));
		ans-=dfs(s,t,inf);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;


int main() {
  int a;
  cin>>a;
  int ans=a+a*a+a*a*a;
  cout<<ans<<"\n";

  return 0;
}


Measured memory_bytes: 3588
N, M = map(int, input().split())
H = list(map(int, input().split()))
path = {}

def add_list(key, value, d):
    if key not in d:
        d[key] = []
    d[key].append(value)
    return d

for i in range(M):
    a, b = input().split()
    path = add_list(a, H[int(b)-1], path)
    path = add_list(b, H[int(a)-1], path)

count = 0
for j in range(N):
    if str(j+1) not in path.keys():
        count += 1
        continue
    if H[j] > max(path[str(j+1)]):
        count += 1
print(count)

Measured memory_bytes: 30512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long n = scan.nextLong();
		run(n);
		scan.close();
		System.exit(0);
	}

	private static void run(long n) {
		System.out.print(n + ":");
		double max = Math.sqrt(n);
		for (long i = 2; i <= max && i < n;) {
			if (n % i == 0) {
				System.out.print(" " + i);
				n /= i;
			} else
				i++;
		}
		if (n == 1)
			System.out.println();
		else
			System.out.println(" " + n);
	}

}

Measured memory_bytes: 26300
// atcoder 
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> x(N), y(N), h(N);
    for (int i=0; i<N; i++) cin >> x[i] >> y[i] >> h[i];

    for (int cx=0; cx<=100; cx++){
        for (int cy=0; cy<=100; cy++){
            int hh, flag = 0;
            for (int i=0; i<N; i++){
                if (h[i] != 0){
                    hh = h[i] + max(x[i]-cx, cx-x[i])+max(y[i]-cy, cy-y[i]);
                }
            }
            for (int i=0; i<N; i++){
                if (h[i] != max(0, hh-max(x[i]-cx, cx-x[i])-max(y[i]-cy, cy-y[i]))) {
                    flag = 1;
                    break;
                }
            }
            if (flag==0){
                cout << cx << " " << cy << " " << hh << endl;
            }
        }
    }

    return 0;
}


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

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  
  if(a==b&&b!=c){
    cout<<c<<endl;
  }
  if(a==c&&b!=a){
    cout<<b<<endl;
  }
  if(a!=b&&c==b){cout<<a<<endl;}
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int d = sc.nextInt();
		int[][] a = new int[h][w];
		for(int i = 0 ; i < h ; i++) {
			for(int j = 0 ; j < w ; j++) {
				a[i][j] = sc.nextInt();
			}
		}
		int q = sc.nextInt();
		int[] l = new int[q];
		int[] r = new int[q];
		for(int i = 0 ; i < q ; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}
		// 値がどの盤面の値かをメモ
		long[] px = new long[h * w + 1];
		long[] py = new long[h * w + 1];
		for(int i = 0 ; i < h ; i++) {
			for(int j = 0 ; j < w ; j++) {
				int value = a[i][j];
				px[value] = i;
				py[value] = j;
			}
		}
		// 盤面上の各値それぞれに対する魔力の合計値を求める
		long[] ruisekiwa = new long[90001];
		for(int i = d + 1 ; i <= h * w ; i++) {
			ruisekiwa[i] = ruisekiwa[i - d] + Math.abs(px[i] - px[i - d]) + Math.abs(py[i] - py[i - d]);
		}
		for(int i = 0 ; i < q ; i++) {
			System.out.println(ruisekiwa[r[i]] - ruisekiwa[l[i]]);
		}
	}
}


Measured memory_bytes: 96972
import java.util.stream.LongStream;

public class Main {
	public static void main(String[] args) {
		java.util.Scanner s = new java.util.Scanner(System.in);
		System.out.println(Main.calc(s.nextLong()));
	}

	public static long calc(long n) {
		return LongStream.rangeClosed(1, (int) Math.sqrt(n))
				.filter(a -> n % a == 0)
				.map(a -> Main.calcF(a, n / a)).min().getAsLong();
	}

	public static int calcF(long a, long b) {
		return Math.max((int) (Math.log10(a) + 1), (int) (Math.log10(b) + 1));
	}

}

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

XYH = set()
flag = True
for i in range(N):
    x, y, h = map(int, input().split())
    if (flag is True) and h > 0:
        flag = False
        ex_x = x
        ex_y = y
        ex_h = h
        continue
    XYH.add((x, y, h))

flag = False
for x in range(0, 101):
    for y in range(0, 101):
        # print(x, y)
        hight = ex_h + abs(x - ex_x) + abs(y - ex_y)
        for tx, ty, th in XYH:
            div = abs(x - tx) + abs(y - ty)
            if div > hight:
                if th == 0:
                    continue
                else:
                    break

            if hight != th + abs(x - tx) + abs(y - ty):
                break
        else:
            print(x, y, hight)
            exit()

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;




int main(void) {
	int x, y, ans = 2147483647;
	cin >> x >> y;

	int absx = abs(x);
	int absy = abs(y);
	int abs_diff = abs(absx - absy);
	
	if (x < 0) {
		if (y < 0) {
			if (x > y) {
				ans = std::min(ans, absy - x + 1);
				ans = std::min(ans, 1 + abs_diff + 1);
			}
			if (x < y) {
				ans = y - x;
			}
		}
		if (y == 0) {
			ans = y - x;
		}
		if (y > 0) {
			ans = y - x;
			if (absx < absy) {
				ans = std::min(ans, abs_diff+1);
			} else {
				ans = std::min(ans, abs_diff+1);
			}
		}
	}
	if (x == 0) {
		if (y < 0) {
			ans = abs_diff+1;
		}
		if (y == 0) {
			ans = 0;
		}
		if (y > 0) {
			ans = y - x;
		}
	}
	if (x > 0) {
		if (y < 0) {
			if (absx >= absy) {
				ans = 1 + abs_diff;
			} else {
				ans = abs_diff + 1;
			}
		}
		if (y == 0) {
			ans = 1 + absx;
		}
		if (y > 0) {
			if (x <= y) {
				ans = y - x;
			} else {
				ans = 1 + abs_diff + 1;
			}
		}
	}
	
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.buffer.readline().rstrip()
def resolve():
    n,k=map(int,input().split())
    m=k.bit_length()
    A=list(map(int,input().split()))
    flag=False # x<=kが確定したかどうか
    x=0
    for d in range(m-1,-1,-1):
        d_sum=sum((a>>d)&1 for a in A)
        if(d_sum<=(n//2)): # xのd桁目を1にしたい
            if(flag or ((k>>d)&1==1)):
                x+=(1<<d)
        else: # xのd桁目を0にする
            if((k>>d)&1==1):
                flag=True
    print(sum(a^x for a in A))
resolve()

Measured memory_bytes: 62576
#include <bits/stdc++.h>
using namespace std;
#define pb push_back

int ncr(int n,int r){ int res=1; if(r>n-r)r=n-r; for(int i=0;i<r;i++) {  res*=n-i;  res/=i+1; } return res; }

int gcd(int a,int b){
    if(b==0) return a;
    else return gcd(b,a%b);
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin>>t;
    int sum=0;
    while(t--){
    
        double arr[5];
        int brr[5];
        for(int i=0;i<5;i++){
            cin>>arr[i];
        }
        for(int i=0;i<5;i++){
            brr[i]=ceil(arr[i]/10)*10-arr[i];
        }
        sort(brr,brr+5);
        for(int j=0;j<5;j++){
                    sum=ceil((sum+arr[j])/10)*10;
        }
        cout<<sum-brr[4];
    }
}
    

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

const int INF = 1e9;
const int MAX_N = 3010, MAX_E = 10000;
int n, m; //????????° ???????????¬??°
vector<pair<int, int> > G[MAX_N];//??°???????????¨?????£??\????????? fi:to se:cost
int d[MAX_N]; //s?????????????????????
typedef pair<int, int> P;//first??????????????¢,second??????????????????
int k; vector<int> shop;//???????¨????

void dijkstra(void){
	priority_queue<P, vector<P>, greater<P> > que;//first????°?????????????
    rep(i, n)d[i] = INF;//?????????
    
    //k????????????????????°????????????
    for(auto i : shop){
    	d[i] = 0;
    	que.push(make_pair(0, i));
    }
  
    while(!que.empty()){
       	auto p = que.top(); que.pop();
       	int v = p.second;
       	if(d[v] < p.first) continue;
       	for(auto e : G[v]){//e.fi:??£??\??????????????????????????? e.se:?????????????????§????????????
       		if(d[e.first] > d[v] + e.second){//???????????¢?????´??°???????????¨???
       			d[e.first] = d[v] + e.second;
       			que.push(make_pair(d[e.first], e.first));
       		}
       	}
    }
}

int main(void){
    cin >> n >> m >> k;
    rep(i, m){
        int a, b, l; cin >> a >> b >> l;
        a--; b--;
       	G[a].push_back(make_pair(b, l)); G[b].push_back(make_pair(a, l));
    }
    rep(i, k){
    	int s; cin >> s; s--;
    	shop.push_back(s);
    }
    dijkstra();//????????????????????????????°?????????????
    //?????????????????¶????????????????°?????????????
    double ans = 0.0;
    //x-y???????????????????????????
    rep(i, n) ans = max(ans, (double)d[i]);
    //??????????????????????????¢????????¨???????????????????????¶???????????´?????????????????????????????¢?????????
   	for (int x = 0; x < n; ++x){
   		for(auto y : G[x]){
   			if(d[x] == 0 || d[y.first] == 0) continue;
   			double tmp = (d[x] + d[y.first] + y.second) / 2.0;//+1????????¨?????\??¨
   			ans = max(tmp, ans);
   		}
   	}
   	cout << round(ans) << endl;
   	return 0;
}

Measured memory_bytes: 6196
#include <stdio.h>

int main()
{
        int n, i = 1, j, a, b, mod, div, sum;
        int min = 999999;
        double st, en;

        scanf("%d", &n);

        while(i <= n / 2) {
                a = i;
                b = n - i;
                mod = 100000;
                sum = 0;
                for (j = 0; j < 6; j++) {
                         sum += a / mod;
                         a %= mod;
                         sum += b / mod;
                         b %= mod;
                         mod /= 10;
                }
                if (min > sum)
                        min = sum;
                i++;
        }
        printf("%d\n", min);
        return 0;
}

Measured memory_bytes: 128
n,k=map(int,input().split())

#割ってk//2な数の個数を求めるｗ
kosu=0
temp=k//2
while temp<=n:
  kosu+=1
  temp+=k

ans=0

if k%2:
  ans=(n//k)**3
else:
  ans+=(n//k)**3
  ans+=kosu**3


print(ans)

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

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

typedef long long int64;

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

  int sum = 0;
  int min = 999999;
  int tmp = 0;

  for(int i=0; i<n; i++){
    sum += l + i;
    if(min > abs(l + i)){
      min = abs(l + i);
      tmp = l + i;
    }
  }

  sum -= tmp;
  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long LL;
int main()
{
	LL A,B,C,D;
	cin>>A>>B>>C>>D;
	
	LL ans=max(A*C,max(A*D,max(B*C,B*D)));
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    string a;
    cin>>a;
    int b=0;
    int sum=0;
    for(int i=0;i<a.size();i++){
      if(a[i]=='A'||a[i]=='C'||a[i]=='G'||a[i]=='T'){
          sum++;
          b=max(b,sum);
      }
      else{
        sum=0;  
      }
    }
    cout<<b<<endl;
}

Measured memory_bytes: 764
from collections import deque
def bfs(start, g, vals, n):
    visited = [-1]*n
    q = deque([start])
    visited[start] = 0
    while q:
        curr_node = q.popleft()
        added_val = vals[curr_node]
        for next_node in g[curr_node]:
            if visited[next_node] >= 0: continue
            visited[next_node] = visited[curr_node] + 1
            vals[next_node] += added_val
            q.append(next_node)


n,q = map(int, input().split())
g = [ [] for _ in range(n) ]
for _ in range(n-1):
    a, b = map(int, input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)

vals = [0]*n
for _ in range(q):
    p,x = map(int, input().split())
    vals[p-1] += x

bfs(0, g, vals, n)
print(*vals)

Measured memory_bytes: 128236
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int x, y;
    cin >> x >> y;
    int b = y-2*x;
    int a = 4*x-y;
    if (b % 2 == 0 && a % 2 == 0 && a >= 0 && b >= 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3612
s = readline.chomp
l = 0
r = s.size - 1
res = 0
while l < r
    if s[l] == s[r]
        l += 1
        r -= 1
    elsif s[l] == "x"
        l += 1
        res += 1
    elsif s[r] == "x"
        r -= 1
        res += 1
    else
        puts -1
        exit
    end
end

puts res

Measured memory_bytes: 2044
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){

	while(1){
		int a; cin >> a;
		if(a == 0) return 0;
		a = 1000 - a;

		int ans = 0;

		ans += a/500;
		a %= 500;
		ans += a/100;
		a %= 100;
		ans += a/50;
		a %= 50;
		ans += a/10;
		a %= 10;
		ans += a/5;
		a %= 5;
		ans += a;

		cout << ans << endl;
	}

}


Measured memory_bytes: 2988
#include<iostream>
#include<cmath>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<cstdlib>
#include<queue>
#include<list>
using namespace std;

int main(){
    string a, b, c;
    cin>>a>>b>>c;
    cout<<((a.back()==b.front())&&(b.back()==c.front())?"YES": "NO")<<endl;
}


Measured memory_bytes: 256
<?php

$n = 1000000;
$t = new SplFixedArray($n);
for ($i = 0; $i < $n; $i++) {
    $t[$i] = 1;
}
$t[0] = $t[1] = 0;

for ($i = 0; $i < $n; $i++) {
    if ($t[$i] === 1) {
        for ($j = $i * $i; $j < $n; $j += $i) {
            $t[$j] = 0;
        }
    }
}

for ($i = 1; $i < $n; $i++) {
    $t[$i] += $t[$i - 1];
}

while (TRUE) {
    fscanf(STDIN, "%d", $n);
    if (feof(STDIN)) {
        break;
    }
    $c = $t[$n];
    echo (string) $c . PHP_EOL;
}

Measured memory_bytes: 61188
#include<bits/stdc++.h>
using namespace std;
const int M=1e5+5;

int n;long long A[M];
long long s;
long long Ans[M];

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%lld",&A[i]);
	for(int i=1;i<=n;i++)s+=A[i];
	Ans[1]=s;
	for(int i=2;i<=n;i+=2)Ans[1]-=A[i]<<1;
	for(int i=2;i<=n;i++)Ans[i]=A[i-1]*2-Ans[i-1];
	for(int i=1;i<=n;i++)printf("%lld ",Ans[i]);
	return 0;
} 

Measured memory_bytes: 2816
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int q = Integer.parseInt(sc.next());
        char[] s = sc.next().toCharArray();
        int[] sum = new int[n+1];
        for(int i=1;i<n;i++){
            if(s[i] == 'C' && s[i-1] == 'A'){
                sum[i+1] = sum[i] + 1;
            }else{
                sum[i+1] = sum[i];
            }
        }
        int l,r;
        StringBuilder sb = new StringBuilder();
        for(int i=0;i<q;i++){
            l = Integer.parseInt(sc.next());
            r = Integer.parseInt(sc.next());
           
            sb.append(sum[r]-sum[l]);
            sb.append('\n');
        }
        System.out.println(sb.toString());
        sc.close();
        
    }
    
}

Measured memory_bytes: 52592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

template <ll Mod>
struct modint {
  ll n;

  modint(const ll x = 0) : n(x) { while (n < 0) n += Mod; n %= Mod; }
  modint operator+(const modint r) const { return modint(*this) += r; }
  modint operator-(const modint r) const { return modint(*this) -= r; }
  modint operator*(const modint r) const { return modint(*this) *= r; }
  modint operator/(const modint r) const { return modint(*this) /= r; }
  modint &operator+=(const modint r) {
    n += r.n;
    if (n >= Mod) n -= Mod;
    return *this;
  }
  modint &operator-=(const modint r) {
    if (n < r.n) n += Mod;
    n -= r.n;
    return *this;
  }
  modint &operator*=(const modint r) { n = n * r.n % Mod; return *this; }
  modint &operator/=(const modint r) { return *this *= r.inv(); }
  modint pow(ll x) const {
    modint<Mod> ret(1), tmp(*this);
    while (x) {
      if (x&1) ret *= tmp;
      tmp *= tmp;
      x >>= 1;
    }
    return ret;
  }
  modint inv() const { return pow(Mod-2); }
  friend ostream& operator<<(ostream& os, const modint& obj) { return os << obj.n; }
  friend istream& operator>>(istream& is, modint& obj) { ll t; is >> t; obj = modint(t); return is; }
};
constexpr ll mod = 1000000007;
using mint = modint<mod>;
mint operator"" _mi(unsigned long long n) { return mint(n); }

ll dfs(ll now, ll p, const vector<vl>& g, vl &size) {
  ll cnt = 1;
  for (auto&& i : g[now]) {
    if (i != p) {
      cnt += dfs(i, now, g, size);
    }
  }
  return size[now] = cnt;
}

int main() {
  cin.tie(0); ios::sync_with_stdio(false);

  ll n;
  cin >> n;
  vector<vl> g(n);
  rep(i, n-1) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  // size[i] := 頂点iを根とする部分木の頂点数
  vl size(n);
  dfs(0, 0, g, size);

  mint ans(0);
  rep(i, n) {
    mint cnt(0);

    for (auto&& j : g[i]) {
      ll t;
      if (size[j] < size[i]) t = size[j];
      else t = size[0]-size[i];
      cnt += mint(2).pow(t)-1;
    }

    ans += mint(2).pow(n-1)-(cnt+1_mi);
  }

  ans /= mint(2).pow(n);
  cout << ans << endl;
}


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

#ifdef DEBUG
#define NDEBUG
#include "cout11.h"
#endif
#undef NDEBUG
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))

class UnionFind {
  vector<int> data;
 public:
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) { return root(x) == root(y); }
  int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
  int size(int x) { return -data[root(x)]; }
};



bool solve(int H,int W,vector<string>&m) {
    UnionFind uf(H*W);

    rep(r,H)rep(c,W){
        if (m[r][c] == '.') continue;

        int a = r*W+c;
        if (r != H-1 && m[r+1][c] == '#') {
            uf.unionSet(a, a+W);
        }
        if (c != W-1 && m[r][c+1] == '#') {
            uf.unionSet(a, a+1);
        }
    }
    rep(r,H)rep(c,W){
        if (m[r][c] == '.') continue;

        int a = r*W+c;
        if (uf.size(a) == 1) return false;
    }
    return true;
}

int main() {
    int H,W;cin>>H>>W;
    vector<string>m(H);
    rep(i,H) cin>>m[i];
    cout << (solve(H,W,m) ? "Yes" : "No") << endl;
    return 0;
}


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

int main()
{
	int a, b;
	cin >> a >> b;
	int x, ans;
	if (a < b) {
		ans += b;
		b--;
	}
	else {
		ans += a;
		a--;
	}
	if (a < b) {
		ans += b;
		b--;
	}
	else {
		ans += a;
		a--;
	}
	cout << ans;
}

Measured memory_bytes: 256
<?php
$a = array(0,1,2,3,4,5,6,7,8,9);

function dfs($i, $n, $s, $sum, $stack){
	//PHPでグローバル変数を書き換える場合はglobal宣言が必要
	global $a;
	global $ans;

	//終了条件
	if ( $i == count($a) ) {
		//解に当てはまるかチェック
		if ($sum == $s && count($stack) == $n) {
			$ans[] = array_slice($stack, 0);	//解の状態をansスタックに保持
		}
		return ;
	}
	
	//スタックに追加するかどうかの分岐
	// a[i]を使わない場合
	dfs($i+1, $n, $s, $sum, $stack);
	// a[i]を使う場合
	array_push($stack, $a[$i]);	//スタックに追加
	dfs($i+1, $n, $s, $sum+$a[$i], $stack);
	array_pop($stack);	//スタックから下ろす
}

while (1) {
	fscanf(STDIN, '%d %d', $n, $s);
	
	//変数の初期化
	$i = 0;
	$sum = 0;
	$stack = array();
	$ans = array();
	
	if ($n == 0 && $s == 0) {
		break;
	}

	//探索の実行
	dfs($i, $n, $s, $sum, $stack);
	//解の数をカウント
	$len_ans = count($ans);
	//出力
	echo $len_ans;
	echo PHP_EOL;
}

Measured memory_bytes: 6656
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		long lcm = lcm(a[0], a[1]);
		for (int i = 2; i < n; i++) {
			lcm = lcm(lcm, a[i]);
		}
		System.out.println(lcm);
	}
	static long gcd(long a, long b) {
	    if (b == 0) {
	        return a;
	    }
	    return gcd(b, a % b);
	}
	static long lcm(long a, long b) {
		return a * b / gcd(a, b);
	}
}


class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}
	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}
	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
		return hasNextByte();
	}
	public String next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || Integer.MAX_VALUE < nl) {
			throw new NumberFormatException();
		}
		return (int) nl;
	}
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 24424
#include<bits/stdc++.h>
using namespace std;
int n,k,s,t,a[55],b[55],cnt,ct,cc,ka[333333],kb[333333],kc[333333],pop[333333],rt;
long long c[55][55],fuck[55],ans;
void FWT_or(int a[],int flg)
{
	for (int i=2;i<=(1<<rt);i<<=1)
	{
		for (int p=i>>1,j=0;j<(1<<rt);j+=i)
		{
			for (int k=j;k<j+p;k++)
			{
				a[k+p]+=a[k]*flg;
			}
		}
	}
}
int main()
{
	scanf("%d%d",&n,&k);
	scanf("%d%d",&s,&t);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	c[0][0]=1;
	for (int i=1;i<=n;i++)
	{
		c[i][0]=1;
		for (int j=1;j<=i;j++)
		{
			c[i][j]=c[i-1][j]+c[i-1][j-1];
		}
	}
	for (int i=0;i<18;i++)
	{
		if (s&(1<<i)) continue;
		if (!(t&(1<<i))) continue;
		ct++;
	}
	for (int i=1;i<=n;i++)
	{
		if ((a[i]&s)!=s) continue;
		if (a[i]&((1<<18)-1-t)) continue;
		++cnt;cc=0;
		for (int j=0;j<18;j++)
		{
			if (s&(1<<j)) continue;
			if (!(t&(1<<j))) continue;
			if (a[i]&(1<<j)) b[cnt]|=(1<<cc);
			cc++;
		} 
	}
	for (int i=0;i<=n;i++)
	{
		for (int j=1;j<=k;j++)
		{
			fuck[i]+=c[i][j];
		}
	}
	for (int i=0;i<(1<<ct);i++) pop[i]=__builtin_popcount(i);
	for (int i=0;i<(1<<ct);i++)
	{
		rt=0;
		for (int j=0;j<ct;j++)
		{
			if (i&(1<<j)) continue;
			rt++;
		}
		for (int j=0;j<(1<<rt);j++) ka[j]=0;
		for (int j=1;j<=cnt;j++)
		{
			if ((b[j]&i)!=i) continue;
			int cmsk=0;cc=0;
			for (int k=0;k<ct;k++)
			{
				if (i&(1<<k)) continue;
				if (b[j]&(1<<k)) cmsk|=(1<<cc);
				cc++;
			}
			ka[cmsk]++;
		}
		FWT_or(ka,1);
		for (int j=0;j<(1<<rt);j++)
		{
			if ((pop[i]+rt-pop[j])&1) ans-=fuck[ka[j]];
			else ans+=fuck[ka[j]];
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 5876
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin >> s;
	int a=s[0]-'0',b=s[1]-'0',c=s[2]-'0',d=s[3]-'0';
	if(a+b+c+d==7){
		cout << a << '+' << b << '+' << c << '+' << d << "=7" << endl;
	}else if(a-b+c+d==7){
		cout << a << '-' << b << '+' << c << '+' << d << "=7" << endl;
	}else if(a+b-c+d==7){
		cout << a << '+' << b << '-' << c << '+' << d << "=7" << endl;
	}else if(a+b+c-d==7){
		cout << a << '+' << b << '+' << c << '-' << d << "=7" << endl;
	}else if(a-b-c+d==7){
		cout << a << '-' << b << '-' << c << '+' << d << "=7" << endl;
	}else if(a-b+c-d==7){
		cout << a << '-' << b << '+' << c << '-' << d << "=7" << endl;
	}else if(a+b-c-d==7){
		cout << a << '+' << b << '-' << c << '-' << d << "=7" << endl;
	}else if(a-b-c-d==7){
		cout << a << '-' << b << '-' << c << '-' << d << "=7" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
b = [int(input()) for _ in range(N)]
for k in b:
    for i in range(3):
        for j in range(3):
            if A[i][j] == k:
                A[i][j] = 0

for i in range(3):
    for j in range(2):
        if A[i][j] != A[i][j+1]: break
    else:
        print('Yes')
        exit()

for j in range(3):
    for i in range(2):
        if A[i][j] != A[i+1][j]: break
    else:
        print('Yes')
        exit()

for i in range(2):
    if A[i][i] != A[i+1][i+1]: break
else:
    print('Yes')
    exit()

for i in range(2):
    if A[2-i][i] != A[1-i][i+1]: break
else:
    print('Yes')
    exit()

print('No')


Measured memory_bytes: 38384
#include<cstdio>
#include<algorithm>
#define mo 1000000007
using namespace std;
int n,ans,now;
int a[100005];
inline int read(){
    int ret=0;char c=getchar();
    while((c>'9')||(c<'0'))c=getchar();
    while((c>='0')&&(c<='9'))ret=(ret<<1)+(ret<<3)+c-'0',c=getchar();
    return ret;
}
int main(){
	n=read();ans=1;
	for(int i=1;i<=n;i++)a[i]=read();
	a[0]=-1;
	now=n;
	for(int i=1;i<=n;i++){
		a[i]=min(a[i],a[i-1]+2);
		if(a[i]-a[i-1]==1)ans=1LL*ans*(i+now-n)%mo,now--,a[i]--;
	}
	for(int i=now;i>1;i--)ans=1LL*ans*i%mo;
	printf("%d",ans);
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(void){
    int a,b,c;
    cin>>a>>b;
    c=b+a;
    if(c==0){
        cout<<"0"<<endl;
    }else if(c>0){
        cout<<"1"<<endl;
    }else if(c<0){
        cout<<"-1"<<endl;
    }
    
}



Measured memory_bytes: 3092
x = input().split(' ')
n = int(x[0])
m = int(x[1])
c = int(x[2])
temp = []
b = []
ans = 0
b = list(map(int, input().split()))
for i in range(n):
    temp = list(map(int, input().split()))
    sum = 0
    for a in range(m):
        sum += temp[a] * b[a]
    if (sum + c) > 0:
        ans += 1
print(ans)


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

int main() {
  Int N, X, Y;
  cin >> N >> X >> Y;
  X--;
  Y--;
  auto L = vector<Int>(N-1, 0);
  for(int s=0; s<N-1; s++) {
    for(int t=s+1; t<N; t++) {
      auto l = min(t-s, abs(X-s)+1+abs(Y-t));
      L[l-1]++;
    }
  }   
  for(auto l : L) {
    cout << l << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;                                                                                  

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        int x = Integer.parseInt(line);

        int y = (int)Math.pow(x, 3); 
        System.out.println(y);
    }   
}

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

using namespace std;

void hawawa(){
	int n;
	cin >> n;
	set<string> strs;
	string str;
	cin >> str;
	strs.insert(str);
	char startchar = str.back();
	while (--n) {
		cin >> str;
		if (strs.count(str) || str[0] != startchar) {
			cout << "No\n";
			return;
		}
		strs.insert(str);
		startchar = str.back();
	}
	cout << "Yes\n";
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	hawawa();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,a,n) for(int i=a;i<=n;i++)
using namespace std;
int main(){
	int n,m,s;
	while(cin>>n>>m>>s,n){
		int sum=0;
		r(a,1,n){if(m==1&&s==a)sum++;
			if(m>1)r(b,a+1,n){if(m==2&&s==a+b)sum++;
				if(m>2)r(c,b+1,n){if(m==3&&s==a+b+c)sum++;
					if(m>3)r(d,c+1,n){if(m==4&&s==a+b+c+d)sum++;
						if(m>4)r(e,d+1,n){if(m==5&&s==a+b+c+d+e)sum++;
							if(m>5)r(f,e+1,n){if(m==6&&s==a+b+c+d+e+f)sum++;
								if(m>6)r(g,f+1,n){if(m==7&&s==a+b+c+d+e+f+g)sum++;
									if(m>7)r(h,g+1,n){if(m==8&&s==a+b+c+d+e+f+g+h)sum++;
										if(m>8)r(i,h+1,n){if(m==9&&s==a+b+c+d+e+f+g+h+i)sum++;
											if(m>9)r(j,i+1,n){if(m==10&&s==a+b+c+d+e+f+g+h+i+j)sum++;
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
		cout<<sum<<endl;
	}
}

Measured memory_bytes: 3100
s=list(input())
n=len(s)
flag=1
if n%2==0:
  flag=0
else:
  for i in range(n-2):
    if s[i]!=s[i+2]:
      flag=1
  for i in range(1,n-2):
    if s[i]!=s[i+2]:
      flag=1
if s[0]==s[n-1]:
  flag^=1
print('First' if flag==1 else 'Second')

Measured memory_bytes: 4084
#include <bits/stdc++.h>
#include <stdlib.h>
#include <time.h> 
 
using namespace std;
long long mod=1e9+7;
long long INF=1e7;
double EPS = 1e-12;
typedef long long int lld;
double tick(){static clock_t oldt;clock_t newt=clock();double diff=1.0*(newt-oldt)/CLOCKS_PER_SEC;oldt = newt;return diff;}
#define rep(i,a,n) for(long long int i = (a); i <= (n); ++i)
#define repI(i,a,n) for(int i = (a); i <= (n); ++i)
#define repD(i,a,n) for(long long int i = (a); i >= (n); --i)
#define repDI(i,a,n) for(int i = (a); i >= (n); --i)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sc(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld%lld",&a,&b)
#define sc3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define scd(a) scanf("%d",&a)
#define scd2(a,b) scanf("%d%d",&a,&b)
#define scd3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scf(a) scanf("%lf",&a)
#define scf2(a,b) scanf("%lf%lf",&a,&b)
#define scf3(a,b,c) scanf("%lf%lf%lf",&a,&b,&c)
#define prL(a) printf("%lld\n",a)
#define prS(a) printf("%lld ",a)
#define prdL(a) printf("%d\n",a)
#define prdS(a) printf("%d ",a)
#define all(c) c.begin(), c.end()
#define sz(a) ((int)a.size())
#define Error(x) cout<< #x << " = " << (x) <<endl;
#define Error2(a,b) cout<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n";
#define Error3(a,b,c) cout<<"("<<#a<<" , "<<#b<<" , "<<#c<<" ) = ( "<<(a)<<" , "<<(b)<<" , "<<(c)<<")\n";
#define Error4(a,b,c,d) cout<<"("<<#a<<" , "<<#b<<" , "<<#c<<" , "<<#d<<" ) = ( "<<(a)<<" , "<<(b)<<" , "<<(c)<<" , "<<(d)<<")\n";
#define errop(a) cout<<#a<<" = ( "<<((a).x)<<" , "<<((a).y)<<" )\n";
#define mset(a, v) memset(a, v, sizeof(a))
#define popcount __builtin_popcountll
 
typedef pair<lld,lld> PA;
 
lld powP(lld a,lld b){
    if(b==0) return 1%mod;
    lld k;
    k=powP(a,b/2);
    k=k*k%mod;
    if(b%2==0) return k;
    else return a*k%mod;
}
 
bool bitSet(lld n,lld i){
    if((n&(1LL<<i))!=0) return true;
    else return false;
}
 
lld findGcd(lld a,lld b){
    if(a==0) return b;
    else return findGcd(b%a,a);
}
 
#define lim 300010
#define lim2 200010
#define qqqqqq 210
// Ab :)
// inline lld sqr(lld x) { return x * x; }
// unordered_map<lld,lld>::iterator it;
// std::ios::sync_with_stdio(false);
// priority_queue<PA> Q;
// lld dp[1<<18];

// vector<lld> G[lim];
// string S[lim];
lld A[lim],B[lim],C[lim];
// map<lld,lld> M;

int main(){
    lld T,i,p,j,l,n,e,r,b,c,k,m,q,a,d,w,x,y,u,v,z,t,curr,prev,sum,ans,pos,val,countA,indicator;
    sc(curr);
    lld sign = 1;
    if(curr < 0) c = -1;
    else if(curr > 0) c = 1;
    else {
        printf("0\n");
        return 0;
    }
    vector<int> V;
    rep(i,0,32) {
        if(curr == 0) break;
        t = 1LL << i;
        a = 1LL << (i + 1);
        x = curr % a;
        // Error4(curr,t,a,x);
        if((c * curr) % a != 0) {
            curr -= sign * t;
            // printf("1");
            V.pb(1);
        }
        else V.pb(0);
        sign = - sign;
    }
    reverse(all(V));
    for(auto t : V) printf("%d",t );
    return 0;
}

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


int main() {
  int A, B, C, max_count;
  cin >> A >> B >> C;
  max_count = B / A;
  if (C <= max_count) cout << C << endl;
  else cout << max_count << endl;
}

Measured memory_bytes: 3572
N, W = (int(n) for n in input().split())
w, v = [], []
for _ in range(N):
    w_, v_ = (int(n) for n in input().split())
    w.append(w_)
    v.append(v_)

dp = [[0] * (W + 1) for _ in range(N + 1)]

for i in range(N):
    for w_ in range(W + 1):
        if w_ >= w[i]:
            dp[i + 1][w_] = max(dp[i][w_], dp[i][w_ - w[i]] + v[i])
        else:
            dp[i + 1][w_] = dp[i][w_]

print(dp[N][W])

Measured memory_bytes: 120044
n = int(input())
graph = [[0 for i in range(n)] for j in range(n)]
d = [0] * n
f = [0] * n
g = [0] * n

time = 0

for i in range(n):
   a = list(map(int, input().split()))
   for j in range(0, a[1], 1):
       graph[a[0] - 1][a[2 + j] - 1] = 1

def search(i):
    global time
    time = time + 1
    d[i] = time
    g[i] = 1
    for j in range(n):
        if (graph[i][j] == 1) & (g[j] == 0):
            search(j)
    time = time + 1
    f[i] = time

for i in range(n):
    if g[i] == 0:
        search(i)
[print(i+1, d[i], f[i]) for i in range(n)]


Measured memory_bytes: 5808
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

typedef long long ll;

int main(){

	int A,B,C,X;
	cin >> A >> B >> C >> X;

	int count = 0;

	for (int a = 0; a <= A ; a++){
		for (int b = 0; b <= B ; b++){
			for (int c = 0; c <= C ; c++)
			{
				if(X == a*500 + b*100 + c*50)
					count += 1;
			}
		}
	}

	cout << count << endl;


	return 0;
}

Measured memory_bytes: 256
from sys import stdin
input = stdin.readline

N = int(input())
WHITE = 0
GRAY = 1
BLACK = 2

M = [[0]*N for _ in range(N)]
color = [WHITE]*N  # colorの初期化は最初に行っておく。
d = [0]*N
f = [0]*N

def dfs_visit(u):
    global tt
    color[u] = GRAY
    tt += 1
    d[u] = tt # 最初の訪問
    for v in range(N):
        if M[u][v] == 0:
            continue
        if color[v] == WHITE:
            dfs_visit(v)
    color[u] = BLACK
    tt += 1
    f[u] = tt # 訪問の完了

def dfs():
    global tt
    tt = 0

    for u in range(N):
        if color[u] == WHITE:
            # 未訪問のuを始点として深さ優先探索
            dfs_visit(u)
    for u in range(N):
        print(str(u+1) + ' ' + str(d[u]) + ' ' + str(f[u]))
for _ in range(N):
    u, k, *vv = input().split()
    u = int(u)-1  # 0オリジンにする
    k = int(k)    # kは使わない
    for v in vv:
        v = int(v)-1
        M[u][v] = 1
dfs()


Measured memory_bytes: 5732
/*
      author : Nishikawa
      created: 10.08.2020 13:05:55
*/

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


int main(){
    int n,k;
    cin >> n >> k;
    vector<bool> have(n,true);
    for(int i=0; i<k; i++){
        int d;
        cin >> d;
        for(int j=0; j<d; j++){
            int a;
            cin >> a;
            --a;
            have[a]=false;
        }
    }
    int ans = 0;
    for(int i=0; i<n; i++){
        if(have[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3612
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
		int s = sc.nextInt();
		int h = s/3600;
		int m = s%3600/60;
		s = s%60;
		System.out.println(h+":"+m+":"+s);
    }
}


Measured memory_bytes: 26196
N = int(input())
Inf = float("inf")
dp = [Inf]*(N+1)
dp[0] = 0
for i in range(1,N+1):
        still1 = 1
        while still1 <= N:
                dp[i] = min(dp[i],1+dp[i-still1])
                still1 *= 6
        still2 = 1
        while still2 <= N:
                dp[i] = min(dp[i],1+dp[i-still2])
                still2 *= 9
print(dp[i])

Measured memory_bytes: 3828
n, x, y = map(int, input().split())
li = [0]*(n-1)
num = 0

for i in range(1,n+1):
    for j in range(i+1,n+1):
        if j<=x or y<i:
            num = j-i
        elif i<=x and x<j<=y:
            num = (x-i)+min(j-x, y-j+1)
        elif i<=x and y<j:
            num = (x-i)+(j-y)+1
        elif x<i and j<=y:
            num = min(j-i,(i-x)+(y-j)+1)
        elif x<i<=y and y<j:
            num = min(i-x+1, y-i)+(j-y)
        li[num-1] += 1

for i in li:
    print(i)

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

using LL = long long;
using VL = vector<LL>;

#define REP(i, n) for (LL i = 0, i##_size = n; i < i##_size; ++i)
#define RREP(i, n) for (LL i = LL(n) - 1; i >= 0; --i)

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

#define IN_LL(var) LL var; cin >> var;
#define IN_VL(var, n) VL var(n); REP(i, n) { cin >> var[i]; };

#define OUT(var) cout << (var) << '\n';

void myMain();
int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	myMain();
	return 0;
}

void myMain() {
	IN_LL(N);
	IN_VL(A, N + 1);

	if (N == 0) {
		if (A[0] == 1) {
			cout << 1 << endl;
		}
		else {
			cout << -1 << endl;
		}
		return;
	}

	VL minCount(N + 1);
	VL maxCount(N + 1);

	minCount[N] = A[N];
	maxCount[N] = A[N];
	RREP(i, N) {
		minCount[i] = (minCount[i + 1] + 1) / 2 + A[i];
		maxCount[i] = maxCount[i + 1] + A[i];
	}

	LL ans = 1;
	maxCount[0] = 1;
	REP(i, N) {
		LL m = (maxCount[i] - A[i]) * 2;
		if (m < minCount[i + 1]) {
			OUT(-1);
			return;
		}

		chmin(maxCount[i + 1], m);
		ans += maxCount[i + 1];
	}

	OUT(ans);
}

Measured memory_bytes: 5528
#include<bits/stdc++.h>
using namespace std;
namespace FAST_IO
{
	template<typename T> void read(T &a)
	{
		a=0;
		int f=1;
		char c=getchar();
		while(!isdigit(c))
		{
			if(c=='-')
			{
				f=-1;
			}
			c=getchar();
		}
		while(isdigit(c))
		{
			a=a*10+c-'0';
			c=getchar();
		}
		a=a*f;
	}
	template <typename T> void write(T a)
	{
		if(a<0)
		{
			a=-a;
			putchar('-');
		}
		if(a>9)
		{
			write(a/10);
		}
		putchar(a%10+'0');
	}
	template <typename T> void writeln(T a)
	{
		write(a);
		puts("");
	}
}
int main()
{
  string s;
  cin>>s;
  if(s=="ABC")
  {
  	cout<<"ARC";
  }
  else
  {
  	cout<<"ABC";
  }
}


Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007
 

int main() {
	string s;
	cin >> s;
	s.insert(s.begin()+4, ' ');
	print(s);





	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
long long X;
double r=1.01;
cin >> X;

long long Y=100;
for (int i = 1; i <4000 ; i++)
{Y=Y*r;
if(Y>=X){
    cout << i << endl;
    return 0;
}

}
}


Measured memory_bytes: 3636
//In The Name Of Godd
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<string> vs;
typedef pair<ll, ll> ii;
typedef pair<int, ii> iii;
typedef pair<double, double> dd;
typedef pair<dd, double> ddd;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<dd> vdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vii> vvii;

#define forn(i, n) for (int i = 0; i < n; i++)
#define all(a) (a).begin(), (a).end()
#define inf 100000000000
#define eps 1e-9
const int maxn = 2e5;
ll dp[maxn];
ll cst[maxn];

int main() {
  int n, k; cin >> n >> k;
  forn(i, n) cin >> cst[i], dp[i] = inf;
  dp[0] = 0;
  forn(i, n) {
    forn(j, k + 1) if(j && i + j < n)
      dp[i + j] = min(dp[i + j], dp[i] + abs(cst[i] - cst[i + j]));
  }
  cout << dp[n - 1] << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;

int main() {
  int n, X;
  cin >> n >> X;
  vector<ll> x(n);
  vector<ll> len(n);
  rep(i, n) cin >> x[i];
  rep(i, n) len[i] = abs(x[i] - X);
  ll now = __gcd(len[0], len[1]);
  rep(i, n) now = __gcd(len[i], now);
  cout << now << endl;
}

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

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if((a+b)>=c) cout <<"Yes" << endl;
    else cout <<"No" <<endl;
    return 0;
}

Measured memory_bytes: 256
import itertools
N,K = map(int,input().split())
H = []
for i in range(N):
	h = int(input())
	H.append(h)
H.sort()

ans = 100000000000000000000000000000
for i in range(N-K+1):
	if(ans>H[i+K-1]-H[i]):
		ans = int(H[i+K-1]-H[i])

print(ans)

Measured memory_bytes: 7540
import itertools

N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
for i in range(N):
    P[i] -= 1
    Q[i] -= 1

R = list(itertools.permutations(range(N)))
length = len(R)
for i in range(length):
    r = list(R[i])
    if P == r:
        a = i
    if Q == r:
        b = i
print(abs(a - b))

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

using namespace std;

int main() {
  int N; cin >> N;
  vector<int> H(N);
  for (int i = 0; i < N; ++i) {
    cin >> H[i];
  }
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    bool is_candidate = true;
    for (int j = 0; j < i; ++j) {
      if (H[j] > H[i]) {
        is_candidate = false;
        break;
      }
    }
    if (is_candidate) {
      ++ans;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
fun main(args : Array<String>) {
    val k = readLine()!!.toLong()
    var ans = 0L
    var tmp = 0L

    while (ans < k) {
        tmp *= 10
        tmp += 7
        tmp %= k
        ans++

        if (tmp == 0L) {
            println(ans)
            return
        }
    }

    println(-1)
}

Measured memory_bytes: 34520
#include <iostream>
#include <algorithm>
#include <map>

using namespace std;

int n;
pair<int, int> p[25];

bool solve(){
  int sum = 0;
  for(int i=0;i<n;i++){
    sum += p[i].second;
    if(sum > p[i].first) return false;
  }
  return true;
}

main(){
  while(cin >> n && n){
    for(int i=0;i<n;i++){
      cin >> p[i].second >> p[i].first;
    }
    sort(p, p+n);
    cout << (solve() ? "Yes" : "No") << endl;
  }
  return 0;
}

Measured memory_bytes: 0