akhauriyash/Code-Regression huggingface dataset:
/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.06.21 15:07:03
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

constexpr int MOD = 1e9 + 7;
struct mint {
private:
    long long x;
public:
    mint(long long x = 0) : x((MOD + x) % MOD) {}
    mint(std::string &s) {
        long long z = 0;
        for (int i = 0; i < s.size(); i++) {
            z *= 10;
            z += s[i] - '0';
            z %= MOD;
        }
        this->x = z;
    }
    mint &operator+=(const mint &a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint &operator-=(const mint &a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint &operator*=(const mint &a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint &operator/=(const mint &a) {
        long long n = MOD - 2;
        mint u = 1, b = a;
        while (n > 0) {
            if (n & 1) {
                u *= b;
            }
            b *= b;
            n >>= 1;
        }
        return *this *= u;
    }
    mint operator+(const mint &a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint &a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint &a) const {
        mint res(*this);
        return res *= a;
    }
    mint operator/(const mint &a) const {
        mint res(*this);
        return res /= a;
    }
    friend std::ostream &operator<<(std::ostream &os, const mint &n) {
        return os << n.x;
    }
    bool operator==(const mint &a) const {
        return this->x == a.x;
    }
};
int main() {
    int n;
    cin >> n;
    vector< int > a(n);
    int now = 1;
    vector< int > b(n);
    int cnt = 0;
    mint ans = 1;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] < now) {
            b[i] = a[i];
            if (i == n - 1) {
                cnt++;
            } else {
                ans *= cnt + 1;
            }
        } else {
            b[i] = now;
            now += 2;
            cnt++;
        }
    }
    
    for (int i = 1; i <= cnt; i++) {
        ans *= i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4044
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;



void main() {
    int t;
    scan(t);

    while (t--) {
        long ai, bi, ci, di;
        scan(ai, bi, ci, di);
        writeln(solve(ai, bi, ci, di) ? "Yes" : "No");
    }
}

bool solve(long a, long b, long c, long d) {
    if (a < b) {
        return false;
    }
    if (b > d) {
        return false;
    }
    if (c >= b) {
        return true;
    }

    // a >= b, d >= b, b > c
    auto g = gcd(b, d);
    auto f = b - g + (a % g);
    if (f > c) {
        return false;
    }
    else {
        return true;
    }
}









































void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 256
using System;
class Program {
  static void Main (string[] args) {
    int D = int.Parse(Console.ReadLine());
    string s = "";
    for (int cnt = 0; cnt <= Math.Abs(25 - D); cnt++) {
      if (cnt == 0) {
        s = "Christmas";
      }
      else
      {
        s += " Eve";
      }
    }
    Console.WriteLine(s);
  }
}

Measured memory_bytes: 11092
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	static HashMap<String,Integer> map = new HashMap<String,Integer>();
	static{
		map.put("000", 0);
		map.put("001", 1);
		map.put("010", 2);
		map.put("011", 3);
		map.put("100", 5);
		map.put("101", 7);
		map.put("110", 8);
		map.put("111", 9);
	}
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(true){
			int n = cin.nextInt();
			if(n==0){
				break;
			}
			String s = Integer.toBinaryString(n);
			int a = s.length()%3;
			if(a!=0)
			for(int i = 0;i<3-a;i++){
				s = "0"+s;
			}
			//System.out.println(s);
			for(int i = 0;i<s.length();i+=3){
				System.out.print(map.get(s.substring(i,i+3)));
			}
			System.out.println();
		}
	}

}

Measured memory_bytes: 13000
import sys
input = sys.stdin.readline
from collections import Counter
from fractions import Fraction
from math import gcd

N=int(input())
mod=10**9+7

S=[tuple(map(int,input().split())) for i in range(N)]

def main():
    C=Counter()
    PLUS=0
    for a,b in S:
        if a==0 and b==0:
            PLUS+=1
        elif a==0:
            C[(0,1)]+=1
        elif b!=0 and a>0:
            C[(a//gcd(a,b),b//gcd(a,b))]+=1
        elif b!=0 and a<0:
            C[(-a//gcd(a,b),-b//gcd(a,b))]+=1
            
        else:
            C[float("inf")]+=1
        
    ANS=1

    #print(C)

    for x in list(C.keys()):
        if x!=float("inf") and x!=(0,1):

            a,b=x

            if b>0:
                ANS=ANS*(pow(2,C[x],mod)+pow(2,C[(b,-a)],mod)-1)%mod
                C[(b,-a)]=0
            else:
                ANS=ANS*(pow(2,C[x],mod)+pow(2,C[(-b,a)],mod)-1)%mod
                C[(-b,a)]=0
                
            C[x]=0

            
        else:
            ANS=ANS*(pow(2,C[float("inf")],mod)+pow(2,C[(0,1)],mod)-1)%mod

            C[float("inf")]=0
            C[(0,1)]=0

    print((ANS-1+PLUS)%mod)

main()
    


Measured memory_bytes: 159716
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <math.h>


int ASC(const void *a,const void *b) {
	return *(int *)b - *(int *)a;//降順
}
int main(void)
{
	long int n;
	long int ans = 0;
	scanf("%ld",&n);
	while (n >= 500) {
		n -= 500;
		ans += 1000;
	}
	//printf("%d\n%d\n",n,ans);
	while (n >= 5) {
		n -= 5;
		ans += 5;
	}
	printf("%ld",ans);
	return 0;
}

Measured memory_bytes: 128
ai = lambda: list(map(int, input().split()))

n = int(input())
a = ai()

ans = 0
start = 0
s = 0
for i in range(n):
    for j in range(start, n):
        if s + a[j] == s ^ a[j]:
            s += a[j]
        else:
            s -= a[i]
            start = j
            ans += j-i
            break
        if j == n-1:
            for k in range(i,n):
                ans += n-k
            print(ans)
            import sys
            sys.exit()
print(ans)


Measured memory_bytes: 24840
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;


int main(){
    int a,b,c,d;
    cin >> a >>b>>c>>d;
    int e = d - b;
    int f = c - a;
    cout << c - e;
    cout << " ";
    cout << d + f;
    cout << " ";
    cout << a - e;
    cout << " ";
    cout << b+f << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(){
    double d,n;
    int a;

    scanf("%lf %lf", &d, &n);
    if(n!=100){
        a = (int)(n * pow(100, d));
    }else{
        a = (int)(101 * pow(100, d));
    }
    printf("%d\n", a);

    return 0;
}

Measured memory_bytes: 384
# frozen_string_literal: true

n = gets.to_i
a = gets.split.map(&:to_i)

b = []
sum = 0
a.each do |e|
  sum += e
  b.push sum
end

w = a.reduce(&:+)

i = b.bsearch_index { |e| e >= w / 2 }
j = i
i -= 1 if i == n - 1
j -= 1 if i.positive?

l = b[i]
r = w - l
diff = (r - l).abs
l2 = b[j]
r2 = w - l2
diff2 = (r2 - l2).abs

puts [diff, diff2].min


Measured memory_bytes: 17804
M, D = map(int, input().split())
if D < 10:
    print(0)
    exit()
ans = 0
for m in range(1, M+1):
    for d in range(10, D+1):
        d10, d1 = map(int, (str(d)[1], str(d)[0]))
        if d10 >= 2 and d1 >= 2 and d10*d1 == m:
            ans += 1

print(ans)


Measured memory_bytes: 9064
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"-----------------"#x"-----------------\n"
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
                    For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int,int> pii;
LL read(){
    LL x=0,f=0;
    char ch=getchar();
    while (!isdigit(ch))
        f=ch=='-',ch=getchar();
    while (isdigit(ch))
        x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return f?-x:x;
}
const int N=2005;
int n,m;
vector <int> e[N],G[N];
int g[N][N],f[N][N];
int dis[N][N];
void dfs1(int s,int x,int d){
	dis[s][x]=d;
	for (auto y : e[x])
		if (y!=s&&!dis[s][y])
			dfs1(s,y,d+1);
}
void Insert(int a,int b){
	if (f[a][b]==b)
		return;
	if (f[a][b]){
		Insert(f[a][b],b);
		return;
	}
	if (f[b][a]){
		Insert(f[b][a],a);
		return;
	}
	vector <pair <int,int> > newE;
	For(_,0,1){
		g[a][b]=1,f[a][b]=b;
		queue <int> q;
		q.push(b);
		while (!q.empty()){
			int x=q.front();
			q.pop();
			for (auto y : e[x])
				if (dis[a][y]>dis[a][x]){
					if (f[a][y]){
						g[f[a][y]][a]=g[a][f[a][y]]=0;
						newE.pb(mp(f[a][y],b));
					}
					else
						f[a][y]=b,q.push(y);
				}
		}
		swap(a,b);
	}
	for (auto i : newE)
		Insert(i.fi,i.se);
}
int T=0;
int ve[N][N],vis[N];
void dfs(int px,int x){
	if (ve[px][x]==T)
		return;
	ve[px][x]=T;
	vis[x]=1;
	for (auto y : G[x])
		if (dis[px][y]==dis[px][x]+dis[x][y])
			dfs(x,y);
}
int main(){
	n=read(),m=read();
	For(i,1,n-1){
		int x=read(),y=read();
		e[x].pb(y),e[y].pb(x);
	}
	For(i,1,n)
		dfs1(i,i,0);
	while (m--){
		int a=read(),b=read();
		Insert(a,b);
	}
	For(i,1,n)
		For(j,1,n)
			if (g[i][j])
				G[i].pb(j);
//	For(i,1,n)For(j,1,i)if (g[i][j])printf("%d <-> %d\n",i,j);
	int ans=0;
	For(i,1,n){
		T=i;
		clr(vis);
		for (auto x : G[i])
			dfs(i,x);
		For(j,1,n)
			if (j!=i){
				ans+=vis[j];
//				if (vis[j])	printf("%d -> %d\n",i,j);
			}
	}
	cout<<ans/2<<endl;
	assert(ans%2==0);
	return 0;
}

Measured memory_bytes: 62720
n, k = map(int, input().split())
d = []
for i in range(n):
    d.append(input())
# [d1, d2, d3, ..., dN]
h = [int(m) for m in d]#int型に直す
h.sort(reverse=True)
li = []
for i in range(n):
    if i + k <= n:
        li.append(h[i] - h[i + k - 1])
    else:
        break
print(min(li))

Measured memory_bytes: 18336
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
#ifdef DEBUG
#define display(x) cerr << #x << " = " << x << endl;
#define displaya(a, st, n)\
	{cerr << #a << " = {";\
	for(int qwq = (st); qwq <= (n); ++qwq) {\
		if(qwq == (st)) cerr << a[qwq];\
		else cerr << ", " << a[qwq];\
	} cerr << "}" << endl;}
#define displayv(v) displaya(v, 0, (int)(v).size() - 1)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define display(x) ;
#define displaya(a, st, n) ;
#define displayv(v) ;
#define eprintf(...) if(0) fprintf(stderr, "...")
#endif
template<typename T> bool chmin(T &a, const T &b) { return a > b ? a = b, true : false; }
template<typename T> bool chmax(T &a, const T &b) { return a < b ? a = b, true : false; }
template<typename A, typename B>
ostream& operator << (ostream& out, const pair<A, B> &p) {
	return out << '(' << p.first << ", " << p.second << ')';
}

const int maxN = (1 << 20);
int n;
string op;
int ch[maxN][3], id[maxN];
int cn = 1, rt;

bool flip = false;
int get(int x) {
	if(x == 0) return x;
	if(flip) return 3 - x; else return x;
}

void build(int &o, int dep, int val, int dval) {
	o = ++cn;
	if(dep == 0) {
		id[o] = dval;
	} else {
		id[o] = 0;
		for(int i = 0; i < 3; ++i) build(ch[o][get(i)], dep - 1, val * 3, i * val + dval);
	}
}

vector<int> q;
void dfs(int o, int dep, int val, int dval) {
	if(dep == 0) {
		q[id[o]] = dval;
	} else {
		for(int i = 0; i < 3; ++i) dfs(ch[o][get(i)], dep - 1, val * 3, i * val + dval);
	}
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
#endif
	cin >> n >> op;
	int cnt = 1;
	for(int i = 0; i < n; ++i) cnt *= 3;
	rt = 1;
	build(rt, n, 1, 0);
	for(char c : op) {
		if(c == 'S') flip ^= 1;
		else {
			assert(c == 'R');
			int o = rt, dep = n;
			while(dep) {
				int &x = ch[o][get(0)], &y = ch[o][get(1)], &z = ch[o][get(2)];
				int t;
				t = x; x = z; z = y; y = t;
				o = x;
				--dep;
			}
		}
	}
	q.assign(cnt, 0);
	dfs(rt, n, 1, 0);
	for(int i = 0; i < (int)q.size(); ++i) cout << q[i] << " \n"[i + 1 == (int)q.size()];
	return 0;
}


Measured memory_bytes: 18880
using System;

namespace _test
{
    class Program
    {
        static void Main(string[] args)
        {
            string name = Console.ReadLine();

            var rand = new Random();
            int pos = rand.Next(0, name.Length - 3);
            string nn = name.Substring(pos, 3);

            Console.WriteLine(nn);
        }
    }
}


Measured memory_bytes: 25876
w,h,n = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(n)]

xmin,xmax,ymin,ymax = 0,w,0,h

for a in A:
  if a[2] == 1:
    xmin = max(xmin, a[0])
  if a[2] == 2:
    xmax = min(xmax, a[0])
  if a[2] == 3:
    ymin = max(ymin, a[1])
  if a[2] == 4:
    ymax = min(ymax, a[1])
    
S = (xmax-xmin) * (ymax-ymin)
if S < 0 or xmin > xmax or ymin > ymax:
  S = 0
print(S)

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

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

using namespace std;

int main(){
	int n; scanf("%d",&n);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	vector<int> ans(n);
	for(int i=n-1;i>=0;i--){
		int sum=0;
		for(int x=i;x<n;x+=i+1) sum=(sum+ans[x])%2;
		if(sum!=a[i]) ans[i]=1;
	}

	printf("%d\n",accumulate(ans.begin(),ans.end(),0));
	rep(i,n) if(ans[i]==1) printf("%d ",i+1);

	return 0;
}


Measured memory_bytes: 2432
S = input()

n = len(S)
N = n + 1

l = [0] * N
r = [0] * N
for i in range(1, N):
    if S[i - 1] == '<':
        l[i] = l[i - 1] + 1
for i in range(N - 1, 0, -1):
    if S[i - 1] == '>':
        r[i - 1] = r[i] + 1
print(sum([max(l[i], r[i]) for i in range(N)]))


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

int main() {
    int N;
    string S;
    cin >> N;
    cin >> S;
    int cnt = 0;

    if(N%2!=0){
        cout <<"No" <<endl;
    }else{
        rep(i,N/2){
            if(S.at(i)==S.at(i+(N/2)))cnt++;
        }
if(cnt==N/2){
    cout<<"Yes"<<endl;
}else{
    cout<<"No"<<endl;
}
    }
    return 0;    
}

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

int count_num(string t, char moji){
  int count = 0;
  for (int i = 0; i<t.length(); i++){
    if (t[i] == moji) count += 1;
  }
  return count;
}
int main(void){
  string alpha = "abcdefghijklmnopqrstuvwxyz";
  int N;
  cin >> N;
  string s[N];
  for (int i = 0; i< N; i++){
    cin >> s[i];
  }
  long count;
  long count_total = 0;
  int alpha_count;
  char mojiretsu;
  string ans;
  for (int i = 0; i<26; i++){
    alpha_count = 51;
    mojiretsu = alpha[i];
    for (int j = 0; j<N; j++){
      //cout << "count_num(s[j], alpha[i]) " << count_num(s[j], mojiretsu) << endl;
      alpha_count = min(alpha_count, count_num(s[j], mojiretsu));
    }
    for (int k = 0; k<alpha_count; k++) ans+= mojiretsu;                
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		int index = s.length() - 1;
		if (index % 2 == 0) {
			index--;
		}
		StringBuilder sb = new StringBuilder(s);
		while (index > 0) {
			sb.deleteCharAt(index);
			index -= 2;
		}

		System.out.println(sb.toString());

		sc.close();
	}
}

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

int main(){
    int N; cin >> N;
    vector<int> A(N+1), B(N);
    for(int i = 0; i < N + 1; i++) cin >> A[i];
    for(int i = 0; i < N; i++) cin >> B[i];
    ll cnt = 0;
    for(int i = 0; i < N; i++){
        if(A[i] < B[i]){
            cnt += A[i];
            int tmp = A[i];
            A[i] = 0;
            if(i != N) {
                cnt += min(A[i+1], (B[i] - tmp));
                A[i+1] -= min(A[i+1], (B[i] - tmp));
            }
        }else{
            cnt += B[i];
            A[i] -= B[i];
        }
    }
    cout << cnt << endl;
}

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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define all(x) (x).begin(), (x).end()
#define en '\n'
#define FILL(x, v) memset(x, v, sizeof(x))
#define pb push_back
#define fast                     \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(NULL);
#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...)       \
	F_ORC(__VA_ARGS__) \
	(__VA_ARGS__)

#define E_ACH2(x, a) for (auto &x : a)
#define E_ACH3(x, y, a) for (auto &[x, y] : a)
#define E_ACH4(x, y, z, a) for (auto &[x, y, z] : a)
#define E_ACHC(...) GET5(__VA_ARGS__, E_ACH4, E_ACH3, E_ACH2)
#define EACH(...)       \
	E_ACHC(__VA_ARGS__) \
	(__VA_ARGS__)

template <typename A, typename B>
inline void chmin(A &a, B b)
{
	if (a > b)
		a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b)
{
	if (a < b)
		a = b;
}

int main()
{
	fast;
	ll n;
	cin >> n;
	string ans;
	while (n)
	{
		int cur = n % 26;
		if (!cur)
			cur = 26;
		ans = char(96 + cur) + ans;
		n -= cur;
		n /= 26;
	}
	cout << ans;
}

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

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

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  ll D,G;
  cin>>D>>G;
  vector<ll>p(D),c(D);
  for(ll i=0;i<D;i++)cin>>p[i]>>c[i];
  ll B=pow(2,D);
  ll ans=LONG_MAX;
  for(ll b=0;b<B;b++){
    ll res=0;
    ll cc=0;
    for(ll i=0;i<D;i++){
      if((b>>i)&1){
        res+=100*(i+1)*p[i]+c[i];
        cc+=p[i];
      }
    }
    for(ll i=D-1;i>=0;i--){
      if(res>=G)break;
      if((b>>i)&1)continue;
      for(ll j=0;j<p[i]-1;j++){
        if(res>=G)break;
        res+=100*(i+1);
        cc++;
      }
    }
    if(res>=G)ans=min(ans,cc);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int H, W;
	int i, j;
	
	while(1){
		scanf("%d %d", &H, &W);
		if(H==0 && W==0){
			break;
		}
		for(i=1; i<=H; i++){
			for(j=0; j<W; j++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 572
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int MAXN=200000+5;
int a[MAXN+5];
int n,x;
int main()
{
	scanf("%d%d",&n,&x);
	if(x==1||x==2*n-1)
	{
		printf("No\n");
	}
	else
	{
		a[n-2]=x-1;
		a[n-1]=x;
		a[n]=x+1;
		int now=1;
		for(int i=0;i<2*n-1;i++)
		{
			if(!a[i])
			{
				while(abs(now-x)<=1)
					now++;
				a[i]=now++;
			}
		}
		printf("Yes\n");
		for(int i=0;i<2*n-1;i++)
			printf("%d\n",a[i]);
	}
	return 0;
}


Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int i=a;i<b;++i)
#define REPN(i,a,b) for(int i=a;i<=b;++i)
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define pb push_back
#define ll long long
//const int M=1e9+7;
const int INF=1e9+5;

int main()
{/*
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#*/
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int n;
    cin>>n;
    vector<int> h(n);
    REP(i,0,n) cin>>h[i];
    vector<int> dp(n+1,INF);
    dp[0]=0;
    for(int i=0;i<n;++i)
    {
    	for(int j:{i+1,i+2})
    	{
    		if(j<n)
    		{
    			dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
			}
		}
	}
    cout<<dp[n-1]<<"\n";

    return 0;
}

Measured memory_bytes: 1024
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	tmp = input[0].split(" ");
	//文字列から10進数に変換するときはparseIntを使います
    var a = parseInt(tmp[0], 10);
    var b = parseInt(tmp[1], 10);
     if((a*b)%2==0){console.log('No');}
         else{console.log('Yes');}
}
   
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"---------------"#x"---------------"<<endl
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
						For(_x,L,R)cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef vector <int> vi;
LL read(){
	LL x=0,f=0;
	char ch=getchar();
	while (!isdigit(ch))
		f|=ch=='-',ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int N=100005;
int n;
int tot[N];
vector <int> e[N];
void dfs(int x,int pre){
	For(i,0,(int)e[x].size()-1)
		if (e[x][i]==pre){
			swap(e[x][i],e[x].back());
			e[x].pop_back();
			break;
		}
	for (auto y : e[x])
		dfs(y,x);
	int cnt=0;
	for (auto y : e[x]){
		tot[x]+=tot[y];
		if (!tot[y])
			cnt++;
	}
	tot[x]+=max(0,cnt-1);
}
int main(){
	n=read();
	For(i,1,n-1){
		int x=read()+1,y=read()+1;
		e[x].pb(y),e[y].pb(x);
	}
	int rt=0;
	For(i,1,n)
		if (e[i].size()==1){
			rt=i;
			break;
		}
	dfs(rt,0);
	int ans=tot[rt],x=rt;
	while (e[x].size()==1)
		x=e[x][0];
	int flag=e[x].size()==0;
	for (auto y : e[x])
		if (!tot[y])
			flag=1;
	cout<<ans+flag<<endl;
	return 0;
}

Measured memory_bytes: 10752
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
using lint=long long;
using namespace std;

const int DGT=100;

lint N,K;
lint A[100010];

lint cnt[110][2];
lint Kbin[110];
lint dp[110][2];

lint rec(int dgt,int isless)
{
	if(dgt==-1)
		return 0;
	
	if(dp[dgt][isless]!=-1)
		return dp[dgt][isless];
	
	lint ret=0;
	if(isless==1)
	{
		if(cnt[dgt][0]>=cnt[dgt][1])
			ret=pow(2,dgt)*cnt[dgt][0]+max(rec(dgt-1,0),rec(dgt-1,1));
		else
			ret=pow(2,dgt)*cnt[dgt][1]+max(rec(dgt-1,0),rec(dgt-1,1));
	}
	else
	{
		if(cnt[dgt][0]>=cnt[dgt][1])
		{
			if(Kbin[dgt]==0)
				ret=pow(2,dgt)*cnt[dgt][0]+rec(dgt-1,0);
			else
				ret=pow(2,dgt)*cnt[dgt][0]+max(rec(dgt-1,0),rec(dgt-1,1));
		}
		else
		{
			if(Kbin[dgt]==0)
				ret=pow(2,dgt)*cnt[dgt][0]+rec(dgt-1,0);
			else
				ret=pow(2,dgt)*cnt[dgt][1]+rec(dgt-1,0);
		}
	}

	dp[dgt][isless]=ret;
	return ret;
}

lint solve(int n)
{
	lint ret=0;
	for(int i=0;i<40;i++)
	{
		lint cost[2]={};
		cost[0]=pow(2,i)*cnt[i][0];
		cost[1]=pow(2,i)*cnt[i][1];
		if(i<n)
		{
			if(Kbin[n]==1)
				ret+=max(cost[0],cost[1]);
			else
			{
				if(Kbin[i]==1)
					ret+=max(cost[0],cost[1]);
				else
					ret+=cost[0];	
			}
		}
		else if(i==n)
		{
			ret+=cost[0];
		}
		else
		{
			if(Kbin[i]==1)
				ret+=max(cost[0],cost[1]);
			else
				ret+=cost[0];
		}
	}

	return ret;
}

int main()
{
	for(int i=0;i<=DGT;i++)
		for(int j=0;j<2;j++)
			dp[i][j]=-1;


	cin >> N >> K;
	for(int i=0;i<N;i++)
		cin >> A[i];
	
	for(int i=0;i<N;i++)
	{
		lint x=A[i];
		for(int j=0;j<=DGT;j++)
		{
			cnt[j][1-(x%2)]++;
			x/=2;
		}
	}
	
	for(int i=0;i<=DGT;i++)
	{
		Kbin[i]=K%2;
		K/=2;
	}

	lint ans=0;
	for(int i=0;i<N;i++)
		ans+=K^A[i];
	for(int i=0;i<40;i++)
		ans=max(ans,solve(i));

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
<?php
$nums = str_split(trim(fgets(STDIN)));

$a = $nums[0];
$b = $nums[1];
$c = $nums[2];
$d = $nums[3];

$opes = [
    ['+', '+', '+'],
    ['+', '+', '-'],
    ['+', '-', '+'],
    ['+', '-', '-'],
    ['-', '+', '+'],
    ['-', '+', '-'],
    ['-', '-', '+'],
    ['-', '-', '-'],
];

$cnt = count($opes);

for ($i=0; $i < $cnt; $i++) { 
    $form = $a.$opes[$i][0].$b.$opes[$i][1].$c.$opes[$i][2].$d;
    if (eval("return $form;") == 7) {
        echo $form.'=7'."\n";
        break;
    }
}

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

UL H, N;
UL dp[40000][16] = {};
UL G[40000] = {};

int main() {
	cin >> H >> N;
	rep(i, N) {
		UL x, y; cin >> x >> y;
		G[y] |= (1 << x);
	}
	rep(y, H - 1) {
		for (pair<UL, UL> g : {
			make_pair(0b0000, 0),
			make_pair(0b1100, 1),
			make_pair(0b0110, 1),
			make_pair(0b0011, 1),
			make_pair(0b1111, 2)
			}) {
			if (G[y] & g.first) continue;
			if (G[y + 1] & g.first) continue;
			rep(i, 16) {
				if (i & g.first) continue;
				dp[y + 1][g.first] = max(dp[y + 1][g.first], dp[y][i] + g.second);
			}
		}
	}
	UL ans = 0;
	rep(i, 16) ans = max(ans, dp[H - 1][i]);
	cout << ans << endl;
	return 0;
}



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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  bool can = false;
  if (a==7 && b==5 && c==5)
    can = true;
  else if (b==7 && a==5 && c==5)
    can = true;
  else if (c==7 && a==5 && b==5)
    can = true;
  if (can)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

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

def main():
    n, m = map(int, input().split())
    p = list(map(int, input().split()))
    parent = list(range(n+1))
    rank = [0]*(n+1)
    cnt = 0
    
    def root(x):
        if parent[x] == x:
            return x
        parent[x] = root(parent[x])
        return parent[x]
    
    def unite(x, y):
        x = root(x)
        y = root(y)
        if x != y:
            if rank[x] > rank[y]:
                parent[y] = x
            elif rank[x] < rank[y]:
                parent[x] = y
            else:
                parent[y] = x
                rank[x] += 1

    for _ in range(m):
        x, y = map(int, input().split())
        unite(x, y)
    for i, pi in enumerate(p, 1):
        if root(i) == root(pi):
            cnt += 1
    print(cnt)

if __name__ == "__main__":
    main()


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

using namespace std;

#define MAX 1010

int main(){
  int N;
  while(cin >> N, N > 0){
    int M[MAX],D[MAX],h[MAX],m[MAX],e[MAX],p[MAX];
    int Point[MAX] = {0},t[MAX];
    char ch;
    for(int i = 0 ; i < N ; i++){
      scanf("%d/%d %d:%d %c %d",
            &M[i],&D[i],&h[i],&m[i],&ch,&p[i]);
      e[i] = (ch == 'I');
    }
    memset(t,-1,sizeof(t));
    for(int i = 0 ; i < N ; i++){
      int totalm = 60*h[i]+m[i];
      if(e[i] == 1){
        t[p[i]] = totalm;
      }else{
        if(p[i] == 0){
          for(int j = 1 ; j < MAX ; j++){
            if(t[j] == -1) continue;
            Point[j] += totalm-max(t[j],t[0]);
          }
        }else{
          if(t[0] != -1){
            Point[p[i]] += totalm-max(t[p[i]],t[0]);
          }
        }
        t[p[i]] = -1;
      }
    }
    cout << *max_element(Point+1,Point+MAX) << endl;
  }
  return 0;
}

Measured memory_bytes: 1272
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

void main ()
{
	int n;
multitest_loop:
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto a = readln.split.map !(to !(int)).array;
		auto total = sum (a, 0L);
		auto once = n * 1L * (n + 1) / 2;
		if (total % once != 0)
		{
			writeln ("NO");
			continue multitest_loop;
		}
		auto num = total / once;
		long cur = 0;
		foreach (i; 0..n)
		{
			int j = (i + 1) % n;
			auto delta = a[j] - a[i];
			delta -= num;
			if (delta > 0 || delta % n != 0)
//			if (((a[j] - a[i]) % n + n) % n != num % n)
			{
				writeln ("NO");
				continue multitest_loop;
			}
			cur += -delta / n;
		}
		writeln (cur == num ? "YES" : "NO");
	}
}


Measured memory_bytes: 3388
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5 + 10;
const ll mod=1e9+7;
ll dp[N][14];

int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	string s;
	while(cin>>s)
	{
		memset(dp,0,sizeof(dp));
		dp[0][0]=1;
		int cur,n=s.length();
		for(int i =0;i <n;i++)
		{
			if(s[i]=='?') cur=-1;
			else cur=s[i]-'0';
			for(int j = 0;j < 10;j++)
			{
				if(cur!=-1&&cur!=j) continue;
				for(int k = 0;k < 13;k++)
				dp[i+1][(k*10+j)%13]+=dp[i][k];
			}
			for(int j=0;j<13;j++) dp[i+1][j]%=mod;
		}
		cout<<dp[n][5]<<endl;
	}
	return 0;
}

Measured memory_bytes: 11472
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <math.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <queue>
#include <sstream>
#include <stack>
#include <deque>
#include <memory.h>
#include <cassert>
#include <ctime>
#include <climits>
#include <list>
#include <time.h>
#include <unordered_map>
#include <bitset>
#include <exception>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned long long ull;
#define pb push_back
#define mp make_pair
#define FILE "file"
#define lc v << 1
#define rc (v << 1) + 1
#define inf 1e+9
#define linf ll(1e+18)
#define dinf 1e+14

typedef long long ll;
#define pb push_back
#define mp make_pair

const int maxn = 100000;
ll a[maxn];

void solve()
{
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());
    if(s < t)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0), cout.tie(0);
    //freopen(FILE ".in", "r", stdin);freopen(FILE ".out", "w", stdout);
    //freopen("file.in", "r", stdin);freopen("file.out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std; 
#define LIM 100003
#define M 1000000007
#define inf 99999999999999999LL	//long long inf
typedef long long ll;

#define sc(x) scanf("%d",&x);
#define sc2(x,y) scanf("%d%d",&x,&y);
#define sc3(x,y,z) scanf("%d%d%d",&x,&y,&z);
#define scl(x) scanf("%lld",&x);
#define scl2(x,y) scanf("%lld%lld",&x,&y);
#define scl3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z);

#define pb push_back
#define mp make_pair
#define fi first
#define se second 
ll power(ll x,ll y,ll z) {	ll ret = 1;	while(y > 0) {	if(y & 1) ret = (ret*x)%z;x = (x*x)%z;y >>= 1;}return ret;}


#define debug(x) cerr<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
#define debug4(x,y,z,a) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#a<<" :: "<<a<<"\n";



ll n, w, dp[102][100020], weight[102], value[102], answer = 0 ;
// dp[i][j] denotes .. for first i values, we need value of j.. two cases if to take this element or not !!
int main() {
	ll i, j, t;
	scl2(n, w) ;
	for(i=1; i<=n; i++)	scl2(weight[i], value[i]) ;
	dp[0][0] = 0 ;
	for(i=1; i<LIM; i++)
		dp[0][i] = inf ;
	
	for(i=1; i<=n; i++) {

		for(j=1; j<=100000; j++) {
			if( j - value[i] >= 0)
				dp[i][j] = min(dp[i-1][j], weight[i] + dp[i-1][j-value[i]]) ;
			else
				dp[i][j] = dp[i-1][j];
			if(dp[i][j] <= w)
				answer = max(answer, j) ;
		}
	}
	
	cout << answer << endl ;
	return 0;
}




Measured memory_bytes: 79232
def main():
    n = int(input())
    a = sorted(map(int,input().split()))
    fld = [-1 for i in range(a[-1]+1)]
    flg = []
    for i in range(n):
        if fld[a[i]]==-1:
            fld[a[i]]=1
            for j in range(2,a[-1]//a[i]+1):
                fld[a[i]*j] = 0
        elif fld[a[i]]==1:
            flg.append(a[i])
    for i in range(len(flg)):
        fld[flg[i]] = 0
    ans = 0
    for i in range(len(fld)):
        if fld[i] == 1:
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 32220
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception{
		new Main(new Scanner(System.in), System.out, System.err).exec();
	}
	public final Scanner sc;
	public final PrintStream out, err;
	public Main(final Scanner sc, final PrintStream out, final PrintStream err) {
		this.sc = sc;this.out = out;this.err = err;
	}
	static public final long pair(int a, int b) {return (((long)a) << 32) + b;}
	static public final int getPair1(long v) {return (int)(v >> 32);}
	static public final int getPari2(long v) {return (int)(v & 0xFFFFFFFF);}

	static public final long quad(long a, long b, long c, long d) {
		return ((a&0xFFFF)<< 48) + ((b&0xFFFF)<< 32) + ((c&0xFFFF)<< 16) +(d&0xFFFF);}
	static public final int getQuad1(long v) {return (int)( v >> 48          );}
	static public final int getQuad2(long v) {return (int)((v >> 32) & 0xFFFF);}
	static public final int getQuad3(long v) {return (int)((v >> 16) & 0xFFFF);}
	static public final int getQuad4(long v) {return (int)( v        & 0xFFFF);}

	static public final long record(int e, int m, int i) {
		return quad(-1, e, m, i);
	}
	static public final int re(long record) {
		return getQuad2(record);
	}
	static public final int rm(long record) {
		return getQuad3(record);
	}
	static public final int ri(long record) {
		return getQuad4(record);
	}

	//------------------------------------------

	private int p;
	private int[] inv;
	private int[] fact;
	private int[] finv;
	public final int mod(long v) {
		v %= p;
		return (int)(v < 0 ? v+p : v);
	}
	public final int mul(long a, long b) {
		return mod(a*b);
	}
	public final void initFact(double limit, double p) {
		initFact((int)limit, (int)p);
	}
	public final void initFact(int limit, int p) {
		this.p = p;
		this.inv = new int[limit+1];
		this.fact = new int[limit+1];
		this.finv = new int[limit+1];
		fact[1] = finv[1] = inv[0] = inv[1] = 1;
		for(int i=2;i<=limit;i++) {
			int a = p / i;
			int b = p % i;
			inv[i]  = mul(-a, inv[b]);
			fact[i] = mul(fact[i-1], i);
			finv[i] = mul(finv[i-1], inv[i]);
		}
	}
	public final int comb(int m, int n) {
		return mul(mul(fact[m], finv[n]), finv[m-n]);
	}

	//------------------------------------------

	public void exec() throws Exception{
		final String S = sc.next();
		if(S.equals("SUN")) {
			out.println(7);
		}
		if(S.equals("MON")) {
			out.println(6);

		}
		if(S.equals("TUE")) {
			out.println(5);

		}
		if(S.equals("WED")) {
			out.println(4);

		}
		if(S.equals("THU")) {
			out.println(3);

		}
		if(S.equals("FRI")) {
			out.println(2);

		}
		if(S.equals("SAT")) {
			out.println(1);
		}
	}
}


Measured memory_bytes: 21716
#include <iostream>
#include <iomanip>
/*cout <<setprecision(11)<<ret<<endl;で、数字部分を計11桁表示*/
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//Shift+Command+bでデバッグ
//その後ターミナルで./a.outを実行
//入力を貼り付ける

//////////////////
//  A
int main(void){
    rep(i,5){
        int a;
        cin>>a;
    if(a==0) cout<<i+1<<endl;
    }
    return 0;
}
//////////////////
//  B
/*int main(void){

    return 0;
}*/
//////////////////
//  C
/*int main(void){

    return 0;
}*/
//////////////////
//  D
/*int main(void){

    return 0;
}*/
//////////////////
//  E
/*int main(void){

    return 0;
}*/
//////////////////
//  F
/*int main(void){

    return 0;
}*/


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
#define PP pair<P,P>
using namespace std;

int main(){
    string s; cin >> s;
    rep(i,s.length()){
        if((i+1)%2==0 && s[i]=='R'){
            cout << "No" << endl;
            return 0;
        }
        if((i+1)%2==1 && s[i]=='L'){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
return 0;
}




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

int main() {
    int A, B, max;
    cin >> A >> B;

    max = A-B;
    if(A+B>A-B){
        max=A+B;
    }
    if(A*B>max){
        max=A*B;
    }
    cout << max << endl;
}

Measured memory_bytes: 256
import itertools
import math
N = int(input())
P = [list(map(int,input().split())) for i in range(N)]
lisN =  [i for i in range(N)]
length = 0
count = 0
for v in itertools.permutations(lisN, N):
    length_here = 0
    for k in range(N-1):
      Pam = P[v[k]]
      Ppm = P[v[k+1]]
      length_here += math.sqrt((Ppm[0] - Pam[0])**2 + (Ppm[1] - Pam[1])**2)

    length += length_here
    count += 1
print(length/count)

Measured memory_bytes: 3064
L, R = map(int, input().split())

MOD = 2019
ans = 2018

if R - L + 1 >= 2019:
    print(0)
else:
    for i in range(L, R):
        for j in range(i+1, R+1):
            n = (i*j)%MOD
            ans = min(n, ans)
    print(ans)

"""
# TLEギリギリ
R = min(R, L+(2019)) # 長さを制限しても同じ2019をyoutube通りに2019*2にするとTLE
MOD = 2019
ans = 2018

for i in range(L, R): # iはLからR-1まで
    for j in range(i+1, R+1): # jはi+1からRまで
        n = (i*j)%MOD
        ans = min(n, ans)

print(ans)
"""

Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
int main(void){
    int x,y;
    scanf("%d%d",&x,&y);
    for(int i=0;i<=x;i++)
      for(int j=0;j<=x-i;j++)
        if(y==4*i+2*j&&x==i+j){ 
            printf("Yes");
            return 0;
        }
    printf("No");
    return 0;
}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main() {
    int N,M; cin >> N >> M;
    vector<pair<ll,ll>> AB(N);
    REP(i,N) cin >> AB[i].first >> AB[i].second;
    sort(AB.begin(), AB.end());
    int count = 0;
    ll ans = 0;
    REP(i,N){
        for(int j = 0; j < AB[i].second; j++){
            count++;
            ans += AB[i].first;
            if (count == M){
                cout << ans << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<int,P>
#define vpp vector<PP>
#define fi first
#define se second
#define INF 1e9
#define MOD 1000000007
#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 all(x) (x).begin(),(x).end()
int main(){
    int a,b,c,x;
    cin>>a>>b>>c>>x;
    int ans=0;
    REP(i,a+1){
        REP(j,b+1){
            REP(k,c+1){
                if(i*500+j*100+k*50==x){
                    ans++;
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
    #define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    i64 N;
    cin >> N;
    vector<i64> a(N);
    rep(i,0,N) cin >> a[i];
    
    bool first=false;
    rep(i,0,N) if(a[i]%2==1){
        first=true;
        break;
    }
    
    cout << (first?"first":"second") << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

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

int s[10000][750];
signed main() {
	int a, b, c; 
	while (cin >> a >> b, a | b) {
		memset(s, 0, sizeof(s));
		cin >> c;
		for (int d = 0; d < c; d++) {
			int e, f, g, h; scanf("%d%d%d%d", &e, &f, &g, &h); g--;
			e -= 540;
			if (h) {
				s[g][e]++;
			}
			else {
				s[g][e]--;
			}
		}
		for (int d = 0; d < b; d++) {
			int k = 0;
			for (int e = 0; e < 750; e++) {
				k += s[d][e];
				s[d][e] = k;
			}
		}
		int d; cin >> d;
		for (int e = 0; e < d; e++) {
			int f, g, h; scanf("%d%d%d", &f, &g, &h); f -= 540; g -= 540; h--;
			int sum = 0;
			for (; f < g; f++) {
				if (s[h][f])sum++;
			}
			cout << sum << endl;
		}
	}
}

Measured memory_bytes: 32368
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <numeric> //lcm


#define ERROR() cout << "ERROR!!" << endl; return 0;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)

#define debug(vec) for(auto v : vec) cout << v << " "; cout << endl;

#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cout << v << " "; cout << endl; } 

using namespace std;

typedef long long ll;

const long long int INF = 1 << 29; //<10^10
//const ll MOD = 998244353;
const ll MOD = 1000000007;

inline bool maxch(int &a, int b) { if (a < b) {a = b; return true;} else return false;}

int main() {
  string _n;
	int k;
	cin >> _n >> k;

	int size = _n.size();

	vector<int> n(size);
	rep(i, size) {
	  n[i] = static_cast<int>(_n[i] - '0');
	}

	vector<vector<int>> dp1(size,vector<int>(k+1,0)), dp2(size,vector<int>(k+1,0));
	dp1[0][1] = 1;
	dp2[0][1] = n[0] - 1;
	dp2[0][0] = 1;

	rep(i, size-1) rep(j,k+1) {
		if (n[i+1] == 0) {
			dp1[i + 1][j] += dp1[i][j];
			dp2[i + 1][j] += dp2[i][j];
			if (j != k) dp2[i + 1][j+1] += dp2[i][j]*9;
		}
		else {
			if (j != k) {
				dp1[i + 1][j + 1] += dp1[i][j];
				dp2[i + 1][j + 1] += dp1[i][j] * (n[i+1] - 1) + dp2[i][j] * 9;
			}		
			dp2[i + 1][j] += dp1[i][j] + dp2[i][j];
		}
	}

	//debug2D(dp1);
	//cout << endl;
	//debug2D(dp2);

	cout << dp1[size-1][k] + dp2[size-1][k] << endl;
}




Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  char s[7];
  scanf("%s", s);
  int bool = 0;
  for(int i = 2; i < 6; i += 2) {
    if(s[i] == s[i + 1]) {
      bool += 1;
    }
  }
  if(bool == 2) {
    printf("Yes");
  } else {
    printf("No");
  }
  return 0;
}


Measured memory_bytes: 1728
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int main(){

    int a,b;
    cin >> a >>b;
    if(a*b % 2 == 0){
        cout << "No" << endl;
    }else{
        cout <<  "Yes" << endl;
    }



    return 0;
}

Measured memory_bytes: 256
mod = 10**9 + 7
def solve():
    s = input()
    t = input()
    ans = len(t)
    for i in range(len(s) - len(t) + 1):
        tmp = 0
        for j in range(len(t)):
            if t[j] != s[j + i]:
                tmp += 1
        ans = min(ans, tmp)
    print(ans)
t = 1
while t > 0:
    solve()
    t -= 1

Measured memory_bytes: 73056
#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;

struct Song{
    string n;
    int t;
}song[51];

int main(){
    string x;
    int n,ans = 0;

    cin >> n;
    for(int i = 0;i < n;i++){
        cin >> song[i].n >> song[i].t;
        ans+=song[i].t;
    }
    cin >> x;
    for(int i = 0;i < n;i++){
        ans-=song[i].t;
        if(song[i].n==x){
            cout << ans;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
#include <cstdint>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++)
#define INF 1000000000
#define MAX 200001
#define PI 3.141592653589793

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
const ll MOD = 1000000007;

template <typename T > inline string toString(const T &a) {ostringstream oss; oss << a; return oss.str();};

int par[1000000];
void init(int N){
    rep(i,N) par[i] = -1;
}

int find(int a){
    if(par[a] < 0) return a;
    else{
        return par[a] = find(par[a]);
    }
}

void unite(int a, int b){
    a = find(a);
    b = find(b);
    if(a == b) return;
    else{
        if(par[a] > par[b]) swap(a,b);
        par[a] += par[b];
        par[b] = a;
    }
}

int size(int A) {
     return -par[find(A)];
}

bool same(int a, int b){
    return find(a) == find(b);
}

int main(){
    int N, M;
    cin >> N >> M;
    int ans = 0;
    init(N);
    vector<int> p(N);
    rep(i,N) cin >> p[i];
    rep(i,M){
        int x,y;
        cin >> x >> y;
        x--;y--;
        unite(x,y);
    }
    vector<int> q(N);
    map<int, vector<int>> m;
    rep(i,N){
        q[i] = find(i);
        m[q[i]].push_back(p[i]);
    }
    rep(i,N){
        if(find(m[q[i]].begin(), m[q[i]].end(),i+1) != m[q[i]].end()) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 15384
#include "bits/stdc++.h"
using namespace std;

int main() {
	
	int n, k;
	cin >> n >> k;
	
	k--;
	
	int arr[n];
	for (int i=0; i<n; i++) cin >> arr[i];
	
	int ans = INT_MAX;
	
	for (int i=0; i<n; i++) {
		if (i - k < 0) continue;
		int mx = arr[i];
		int mn = arr[i-k];
		if (mn > 0) {
			ans = min(ans, mx);
		}
		else if (mx < 0) {
			ans = min(ans, -mn);
		}
		else {
			int mrep = min(abs(mx), abs(mn));
			ans = min(ans, mrep + mx-mn);
		}
	}
	
	cout << ans << endl;
	
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
int main(){
    int a,b;
    cin>>a>>b;
    if(a%b==0) cout<<a/b;
    else cout<<a/b+1;
    cout<<endl;
}

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

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

int main() {
	int A, B, N;
	cin >> N >> A >> B;

	int rtn = 0;
	for(int i = 1; i <= N; i++) {
		int r = getSum(i);		
		if(A <= r && r <= B) {
			rtn += i;
		}
	}
	printf("%d\n", rtn);
}


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

int main(){
 int x;
 int y;
 int z;
 int d;
 cin>>x>>y>>z>>d;
 
  int m = (x+y+z+d) / 60;
  int s = (x+y+z+d) % 60;
    cout<<m<<endl;
    cout<<s<<endl;
     return 0;
}  



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

int main(){
	int n; cin >> n;
	int a[n];
	for(int i = 0; i < n; ++i) cin >> a[i];
	int ans = 0;
	for(int i = 0; i < n; ++i){
		if(a[a[i] - 1] == i + 1) ++ans;
	}
	cout << ans / 2 << endl;
	return 0;
}

Measured memory_bytes: 640