akhauriyash/Code-Regression huggingface dataset:
def solve():
    import math
    N,M = [int(i) for i in input().split()]
    A = list(map(int, input().split()))

    lcm = A[0]
    for i in range(1, N):
        lcm = lcm * A[i] // math.gcd(lcm, A[i])
    first = lcm // 2

    ans_exists = True
    for i in range(N):
        if first % A[i] == 0:
            ans_exists = False

    if ans_exists:
        ans = int((M-first) // lcm + 1)
        print(ans)
    else:
        print('0')

if __name__ == "__main__":
    solve()

Measured memory_bytes: 20600
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i, a, n) for(int i=a; i<n; i++)
#define ll long long
#define all(x) begin(x), end(x)
#define toInt(x) (x - '0')
#define pll pair<ll, ll>
#define pli pair<ll, int>
// #define int long long
const int inf = 1 << 30;
#define INF 1e+9
#define MAX_V 100008


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



int main(){
  ll n;
  cin >> n;
  vector<ll> v(n);
  map<ll, ll> mp;
  long long ans = 0;
  rep(i, 0, n){
    cin >> v[i];
    mp[v[i]]++;
    ans += v[i];
  }

  int q;
  cin >> q;
  rep(i, 0, q){
    int b, c;
    cin >> b >> c;
    long long m = b * mp[b];
    long long p = c * mp[b];

    mp[c] += mp[b];
    mp[b] = 0;

    ans = ans + p - m;
    cout << ans << endl;
  }
}


Measured memory_bytes: 9860
fun main(args: Array<String>) {
    val mod = 1000000007L
    fun divWithMod(a: Long, b: Long, mod: Long): Long {
        return ((a % mod) * java.math.BigInteger.valueOf(b).modInverse(java.math.BigInteger.valueOf(mod)).toLong()) % mod
    }

    fun getSosuList(max: Int): MutableList<Int> {
        val list = mutableListOf<Int>()
        (2..max).filter { i ->
            (2..Math.sqrt(i.toDouble()).toInt()).all { j -> i % j != 0 }
        }
                .forEach { n -> list.add(n) }
        return list
    }

    fun calcFactors(n: Int): Map<Int, Int> {//素因数分解
        val factors = mutableMapOf<Int, Int>()
        var tmp = n
        var i = 2
        while (i * i <= tmp) {
            while (tmp % i == 0) {
                factors[i] = factors.getOrElse(i) { 0 } + 1
                tmp /= i
            }
            i++
        }
        if (tmp > 1) factors[tmp] = 1
        return factors
    }

    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(' ').map(String::toLong).toLongArray()
    val totalFactors = mutableMapOf<Int, Int>()
    for (a in aList) {
        val factors = calcFactors(a.toInt())
        for (key in factors.keys) {
            totalFactors[key] = Math.max((totalFactors.get(key) ?: 0), factors[key]!!)
        }
    }


    var koubai = 1L
    for (key in totalFactors.keys) {
        for (k in 1..totalFactors[key]!!) {
            koubai *= key
            koubai %= mod

        }
    }
    var ans = 0L
    for (a in aList) {
        ans += divWithMod(koubai, a, mod)
        ans %= mod
    }
    println(ans)
}

Measured memory_bytes: 50216
def primes(n):
    res = [1]
    a = 2
    while n > 1 and a < (10**6):
        if n % a == 0:
            res.append(a)
            while n % a == 0:
                n //= a
        a += 1
    if a == 10**6:
        res.append(n)
    return set(res)


if __name__ == '__main__':
    a, b = map(int, input().split(' '))
    print(len(primes(a) & primes(b)))


Measured memory_bytes: 3060
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    vector<ll>a(5);
    rep(i,5)cin>>a[i];
    rep(i,5){
        if(a[i]==0){
            cout<<i+1<<endl;
            return 0;
        }
    }
}



















































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

int A[55];
bool boleh[55];
int B[55];
int C[55];
int indx[55];
long long ncr[55][55];

long long ncrUpTo[55][55];
vector<int> s[(1<<18)+5];

int cnt2[(1<<18)+5];

int main(){
    int N, K, S, T;
    scanf("%d%d%d%d", &N, &K, &S, &T);

    if( ((S&T) == S) && ((S|T) == T) ){
    }else{
        printf("0");
        return 0;
    }

    memset(ncr, 0, sizeof(ncr));
    ncr[0][0] = 1;
    for(int i = 1; i <= N; i ++){
        ncr[i][0] = 1;
        for(int j = 1; j <= i; j ++){
            ncr[i][j] = ncr[i-1][j] + ncr[i-1][j-1];
        }
    }

    ncrUpTo[0][0] = 0;
    for(int i = 1; i <= N; i ++){
        ncrUpTo[i][0] = 0;
        for(int j = 1; j <= N; j ++){
            ncrUpTo[i][j] = ncrUpTo[i][j-1] + ncr[i][j];
        }
    }

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

    int L = 0;
    for(int i = 0; i < 20; i ++){
        if( (S&(1<<i)) == (T&(1<<i)) ){
            for(int j = 0; j < N; j ++){
                if( (S&(1<<i)) != (A[j]&(1<<i)) ){
                    boleh[j] = false;
                    //printf("boleh[%d]=false\n", j);
                }
            }
        }else{
            indx[L ++] = i;
        }
    }

    for(int i = 0; i < L; i ++){
        for(int j = 0; j < N; j ++){
            if(A[j]&(1<<indx[i])){
                B[j] |= (1<<i);
            }
        }
    }

    int M = 0;
    for(int i = 0; i < N; i ++){
        if(boleh[i]){
            C[M ++] = B[i];
        }
    }

    for(int i = 0; i < M; i ++){
        //printf("C[%d]=%d\n", i, C[i]);
    }

    memset(cnt2, 0, sizeof(cnt2));
    long long ans = 0;
    for(int U = 0; U < (1<<L); U ++){
        long long f = 0;

        for(int i = 0; i < M; i ++){
            if(!cnt2[U&C[i]]){s[U].emplace_back(U&C[i]);}
            cnt2[U&C[i]] ++;
        }

        for(int j: s[U]){
            int cnt = cnt2[j];
            f += ncrUpTo[cnt][K];
            cnt2[j] = 0;
        }

        int temp = __builtin_popcount(U);
        if(temp&1){
            ans -= f;
        }else{
            ans += f;
        }
    }

    printf("%lld", ans);
    return 0;
}


Measured memory_bytes: 78244
N, A, B  = map(int, input().split())

X = list(map(int, input().split()))

cost = 0
# 隣町への移動
for i in range(N-1):
    # 隣待ちへの徒歩での移動コストと、テレポートでの移動コストを比較して、
    # 小さい方を採用する
    cost += min((X[i+1]-X[i])*A, B)
    
print(cost)

Measured memory_bytes: 62704
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt(); int m=scan.nextInt(); int l=scan.nextInt();
		int a[][]=new int [100][100]; int b[][]=new int [100][100]; long c[][]=new long [100][100];
		int i,j,k;
		
		for(i=0;i<n;i++){
			for(j=0;j<m;j++){
				a[i][j]=scan.nextInt();
			}
		}
		
		for(i=0;i<m;i++){
			for(j=0;j<l;j++){
				b[i][j]=scan.nextInt();
			}
		}
		
		for(i=0;i<n;i++){
			for(j=0;j<l;j++){
				c[i][j]=0;
				for(k=0;k<m;k++){
					c[i][j]+=a[i][k]*b[k][j];
				}
			}
		}
		
		for(i=0;i<n;i++){
			for(j=0;j<l-1;j++){
				System.out.printf("%d ",c[i][j]);
			}
			System.out.println(c[i][l-1]);
		}
	}
}


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


int main()
{
	int N,K;
	cin>>N>>K;
	vector<bool> sunuke(N,false);
	rep(i,K)
	{
		int d;
		cin>>d;
		rep(j,d)
		{
			int a;
			cin>>a;
			a--;
			sunuke[a]=true;
		}
	}
	int ans=0;
	for(bool f : sunuke)
	{
		if(!f) ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using Lint=long long;

const int mod=1e9+7;
const int sz=2000005;
 
int fact[sz],inv[sz],ifact[sz];
 
void make(){
    fact[0]=fact[1]=inv[1]=ifact[0]=ifact[1]=1;
    for(int i=2;i<sz;i++){
        fact[i]=fact[i-1]*i%mod;
        inv[i]=inv[mod%i]*(mod-mod/i)%mod;
        ifact[i]=ifact[i-1]*inv[i]%mod;
    }
}
 
int comb(int n,int k){
    if(n<k) return 0;
    return fact[n]*ifact[k]%mod*ifact[n-k]%mod;
}

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

    int X,Y; cin>>X>>Y;
    make();
    int ans=0;
    for(int i=0;i<=X;i++) if((X-i)%2==0){
        int j=(X-i)/2;
        if(2*i+j==Y){
            ans+=comb(i+j,i);
            ans%=mod;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 47104
# 安定なソート
import copy


def BubbleSort(C, N):
    for i in range(0, N):
        for j in range(N - 1, i, -1):
            if C[j].value < C[j - 1].value:
                C[j], C[j-1] = C[j-1], C[j]


def SelectionSort(C, N):
    for i in range(0, N):
        minj = i
        for j in range(i, N):
            if C[j].value < C[minj].value:
                minj = j
        C[i], C[minj] = C[minj], C[i]


class Card:
    value = 0
    x = ""

    def __init__(self, x):
        self.x = x
        self.value = int(x[1])


N = int(input())
C = list(map(lambda x: Card(x), input().split(" ")))

c1 = copy.copy(C)
c2 = copy.copy(C)

BubbleSort(c1, N)
SelectionSort(c2, N)
print(" ".join([x.x for x in c1]))
print("Stable")
print(" ".join([x.x for x in c2]))
isStable = True
for i in range(0, N):
    if c1[i] != c2[i]:
        isStable = False
        break
if isStable:
    print("Stable")
else:
    print("Not stable")



Measured memory_bytes: 6348
#include<bits/stdc++.h>
using namespace std;
int n,a[100010],b[100010],ans;
int main()
{    
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
    	scanf("%d",&a[i]);
    	b[a[i]]++;
    	b[a[i]-1]++;
    	b[a[i]+1]++;
	}
	for(int i=0;i<=100000;i++)
	{
		ans=max(ans,b[i]);
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<iostream> 
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<string> 
#define ll long long
#define ull unsigned long long
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define lowbit(x) (x& -x)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define eps 1e-18
#define maxn 100010
inline ll read(){ll tmp=0; char c=getchar(),f=1; for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1; for(;'0'<=c&&c<='9';c=getchar())tmp=(tmp<<3)+(tmp<<1)+c-'0'; return tmp*f;}
inline ll power(ll a,ll b){ll ans=1; for(;b;b>>=1){if(b&1)ans=ans*a%mod; a=a*a%mod;} return ans;}
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void swap(int &a,int &b){int tmp=a; a=b; b=tmp;}
using namespace std;
int a[maxn];
int n,m;
int main()
{
	n=read(); m=read();
	for(int i=1;i<=n;i++)
		a[i]=read();
	sort(a+1,a+n+1);
	int ans=0;
	for(int i=1;i<n;i++)
		if(a[i]<=m)++ans,m-=a[i];
	if(m==a[n])++ans;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <tuple>
#include <cmath>
using namespace std;

int main(int argc, const char * argv[]) {
  string w;
  vector<int> cnt(26,0);
  cin >> w;
  for(int i = 0; i < w.size();i++){
    cnt.at(w.at(i)-'a')++;
  }
  for(int i = 0; i < 26;i++){
    if(cnt.at(i)%2!=0){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#define int long long
using namespace std;
signed main() {
	int A,B;
    cin>>A>>B;

    if(A+B>23){
        cout<<A+B-24<<endl;
    }
    else{
        cout<<A+B<<endl;
    }
}

Measured memory_bytes: 3584
import java.util.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] w = new int[n];
		for(i = 0; i <n; i++) {
			w[i] = Integer.parseInt(sc.next());
		}
		sc.close();
//		Arrays.sort(w);
		int[] a = new int[n];
		int[] b = new int[n];
		a[0] = w[0];
		b[n-1] = w[n-1];
		for(i = 1; i <n; i++) {
			a[i] = a[i-1] + w[i];
			b[n-i-1] = b[n-i] + w[n-1-i];
		}
		int dif = 100*n;
		int min = 0;
		for(i = 0; i <n-1; i++) {
			min = Math.abs(a[i] - b[i+1]); 
			if(min < dif) {
				dif= min;
			}
		}
		System.out.println(dif);
	}
}


Measured memory_bytes: 23764
#include <iostream>
#include <vector>
using namespace std;
#define rep2(x,from,to) for(int x=(from); x<(to); (x)++)
#define rep(x,to) rep2(x,0,to)
vector<int> v;
int ret = 0;
void check(int s) {
	int total = 0;
	for(int x : v) {
		total += x;
	}
	if(s == total) ret++;
}
void select(int a, int l, int s) {
	if(!l) {
		check(s);
		return;
	}
	rep2(i,a,10) {
		v.push_back(i);
		select(i+1, l-1, s);
		v.pop_back();
	}
}
		
int main() {
	int n, s;
	while(cin >> n >> s && (n || s)) {
		select(0, n, s);
		cout << ret << endl;
		ret= 0;
	}
	return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>

using namespace std;
#define vsort(v) sort(v.begin(), v.end());
#define vunique(v) unique(v.begin(), v.end());

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, A;
	cin >> N >> A;
	N %= 500;
	if(N <= A) cout << "Yes" << endl;
	else cout << "No" << endl;
}



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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    vector<int> w(10);
    rep(i, 10) cin >> w[i];
    vector<int> k(10);
    rep(i, 10) cin >> k[i];
    sort(w.begin(), w.end());
    sort(k.begin(), k.end());

    cout << w[9]+w[8]+w[7] << " " << k[9]+k[8]+k[7] << '\n';
    return 0;
}


Measured memory_bytes: 3160
#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; }

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

  ll n, a, b;
  cin >> n >> a >> b;

  ll d = abs(a-b);
  cerr << d << endl;
  if (d%2 == 0) {
    cout << d/2 << endl;
  } else {
    cout << min(a-1+1, n-b+1) + (d-1)/2 << endl;
  }
}


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

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

typedef long long Int;

int main() {
  int N, cnt = 0;
  cin >> N;
  vector<Int> A(N);
  rep(i,N) {
    cin >> A[i];
    if (A[i] < 0) cnt++;
  }
  
  if (cnt % 2 == 0) {
    Int ans = 0;
    rep(i,N) {
      if (A[i] > 0) ans += A[i];
      else if (A[i] < 0) ans -= A[i];
    }
    cout << ans << endl;
    return 0;
  }
  else {
    sort(A.begin(),A.end());
    if (cnt == N) {
      Int ans = 0;
      rep(i,N-1) {
        ans -= A[i];
      }
      ans += A[N-1];
      cout << ans << endl;
      return 0;
    }
    else {
      Int lastminus = A[0], firstnonminus, index;
      rep(i,N) {
        if (A[i] < 0) {
          lastminus = A[i];
          continue;
        }
        else {
          firstnonminus = A[i];
          index = i;
          break;
        }
      }
      Int ans = 0;
      if (-lastminus >= firstnonminus) {
        rep(i,N) {
          if (A[i] < 0) ans -= A[i];
          else if (i == index) ans -= A[i];
          else ans += A[i];
        }
      }
      else {
        rep(i,N) {
          if (A[i] < 0 && i != index-1) ans -= A[i];
          else ans += A[i];
        }
      }
      cout << ans << endl;
      return 0;
    }
  }
}
        

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
    
using namespace std;
    
int main(){
 int a,b;
 long double f;
 cin >> a;
 cin >> b;
 f=(a+0.0)/b;
 cout << a/b << " " << a%b << " ";
 cout << std::fixed;
 cout << std::setprecision(6)<< f << endl;
 return 0;
}



Measured memory_bytes: 3268
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N; ll K; int A[201010];
int dp[61][201010];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> K;
	rep(i, 0, N) cin >> A[i], A[i]--;

	rep(cu, 0, N) dp[0][cu] = A[cu];
	rep(p, 1, 61) rep(cu, 0, N) dp[p][cu] = dp[p - 1][dp[p - 1][cu]];

	int cu = 0;
	rrep(p, 60, 0) if (K & (1LL << p)) cu = dp[p][cu];
	cout << cu + 1 << endl;
}







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

int main() {
    long long a, b, c, d; cin >> a >> b >> c >> d;

    vector<long long> ans(4);
    ans.at(0) = a * c;
    ans.at(1) = a * d;
    ans.at(2) = b * c;
    ans.at(3) = b * d;
    sort(ans.begin(), ans.end());
    cout << ans.at(3) << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define LINF 1e18
#define INF 1e9
using namespace std;

int main(){
    ll n,k;
    cin >> n >> k;
    
    if(n >= k) cout << min(n % k,k - (n % k)) << endl;
    else cout << min(n,k-n) << endl;
    return 0;
}

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


int main(){
 int A,B;
  cin >> A >>B;
  cout << A*B <<endl;
}

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

int main()
{
    int n,a,b,x,y,z;
    scanf("%d %d %d",&n,&a,&b);
    if(a>b) swap(a,b);
    a++;
    x = abs(b-a);
    //cout<<x<<endl;
    y = (x/2)+(x%2);
    z = x-y;
    //cout<<y<<" "<<z<<endl;
    if(y==z)    puts("Borys");
    else    puts("Alice");
    return  0;
}


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

int main(){

  //initialization
  int r, g ,b;
  int ans;

  //input data
  cin  >> r >> g >> b;

  //solver
  ans = ((r * 100) + (g * 10) +  b) % 4;
  if(ans == 0){
    cout << "YES" << "\n";
  } else {
    cout << "NO" << "\n";
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define MAXN (int)(2 * 1e5 + 5)
#define MAXL 20
#define F first
#define S second
#define endl "\n"
#define MOD (lli)(1e9 + 7)
#define lli long long int
#define sz(a) int(a.size())
#define DEBUG if (0) cout << "aqui" << endl;
#define PI 2 * acos(0.0)
typedef pair<int, int> ii;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int dddx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dddy[] = {0, 0, 1, -1, 1, -1, 1, -1};

int n, m;
vector<lli> vec;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> n >> m;
  lli sum = 0;
  for(int i=0;i<m;i++) {
    lli a;
    cin >> a;
    sum += a;
  }

  if(sum <= n) cout << n - sum << endl;
  else cout << -1 << endl;


  return 0;
}

Measured memory_bytes: 3644
N, M, C = [int(i) for i in input().split()]
b_list = [int(b) for b in input().split()]
a_lists = [[a for a in input().split()] for N in range(N)]

seikai = 0

for a_list in a_lists:
    m = 0
    siki = 0
    for a in a_list:
        siki += int(a) * b_list[m]
        m += 1
    if siki + C > 0:
        seikai += 1

print(seikai)

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

const int _ = 1e6 + 7;
vector < int > pot[26];
int N; char S[_] , T[_];

int main(){
	scanf("%d %s %s" , &N , S , T);
	for(int i = 0 ; i < N ; ++i) pot[S[i] - 'a'].push_back(i);
	int mx = 0 , mrk = 0; char curc; deque < int > q; q.push_back(1e9);
	for(int i = N - 1 ; ~i ; --i){
		if((q.front() + mrk <= i ? curc : S[i]) != T[i]){
			if(pot[T[i] - 'a'].empty()){puts("-1"); return 0;}
			int t = pot[T[i] - 'a'].back(); curc = T[i];
			for(int j = min(i , q.front() + mrk - 1) ; j >= t ; --j) pot[S[j] - 'a'].pop_back();
			--mrk; q.push_front(t - mrk); while(q.back() + mrk >= i) q.pop_back();
			q.push_back(i - mrk); mx = max(mx , (int)q.size() - 1);
		}
		if(q.front() + mrk > i) pot[S[i] - 'a'].pop_back();
	}
	cout << mx; return 0;
}

Measured memory_bytes: 10680
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll mod= 1e9 + 7;



int main(){
  int n;
  ll k;
  cin >> n>> k;
  int a[n+1],b[n+1]={};//aはワープ先bはカウント
  rep(i,n)cin >> a[i+1];
  ll count=0;
  ll count2=0;
  int r=1;//現在地
  while(1){
    b[r]++;
    if(b[r]>=2)break;
    count++;
    r=a[r];
  }
  int g=r;//繰り返す出発地点
    while(1){
    if(b[r]>=3)break;
    count2++;
    r=a[r];
    b[r]++;
  }
  int ans=1;
  if(k<=count){
    rep(i,k){ans=a[ans];}
    cout << ans << endl;
    return 0;
  }else{
    ans=g;
    k-=count;
    k=k%count2;
    rep(i,k){ans=a[ans];}
    cout << ans << endl;
    return 0;
  }
}

Measured memory_bytes: 5176
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a = II()
    s = input()
    print(s if a >= 3200 else "red")
    return

#B
def B():
    II()
    a = LI()
    ans = 0
    for ai in a:
        ans += 1 / ai
    print(1/ans)
    return

#C
def C():
    n = II()
    v = LI()
    q = []
    for vi in v:
        heappush(q, vi)
    while 1:
        a = heappop(q)
        if q:
            b = heappop(q)
            heappush(q, (a + b) / 2)
        else:
            print(a)
            return

#D
def D():
    n, q = LI()
    tree = [[] for i in range(n)]
    for _ in range(n - 1):
        a, b = LI_()
        tree[a].append(b)
        tree[b].append(a)
    ans = [0] * n
    c = defaultdict(int)
    for _ in range(q):
        p, x = LI_()
        x += 1
        ans[p] += x
    c[0] = 1
    q = deque([0])
    while q:
        p = q.pop()
        for nex in tree[p]:
            if c[nex]:
                continue
            c[nex] += 1
            ans[nex] += ans[p]
            q.append(nex)
    print(*ans)
    return

#E
def E():
    return

#F
def F():
    return

#Solve
if __name__ == '__main__':
    D()


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

int main(){
  int n,ans;
  cin >> n;
  int a[n],tmp[n];
  for (int i=0;i<n;i++)
    cin>>a[i];
  
  tmp[0]=0;
  
  for(int i=0;i<n;i++){
    tmp[i+1]=a[tmp[i]]-1;
    if(tmp[i]==1){
      cout<<i;
      break;
    }
    if(i==n-1 && tmp[i]!=1)
      cout<<-1;
  }

}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<map>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<iomanip>
#define BUG puts("no bug")
#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define ll long long
#define ull unsigned long long
#define REP(a,b,c) for(int a=b;a<=c;a++)
#define PER(a,b,c) for(int a=b;a>=c;a--)
#define lb(a) (a&(-a))
#define pp (p<<1)
#define ppp (p<<1|1)
#define pi pair<int,int>
#define pii pair<pair<int,int>,int>
using namespace std;
const int MAXN=1e6+5;
int n,m,t;
struct NODE{
    int a,b,c,d;
}q[MAXN];
int ans;
int A[MAXN];
void dfs(int x,int dep){
    if(dep==n+1){
        int tmp=0;
        REP(i,1,t){
            if(A[q[i].b]-A[q[i].a]==q[i].c)tmp+=q[i].d;
        }
        ans=max(ans,tmp);
        return;
    }
    A[dep]=x;
    REP(i,x,m){
        dfs(i,dep+1);
    }
}

int main(){
    cin>>n>>m>>t;
    REP(i,1,t)cin>>q[i].a>>q[i].b>>q[i].c>>q[i].d;
    dfs(1,1);
    cout<<ans;
}

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

using namespace std;

long long int mod = 1e9+7;

int main()
{
    int N, K;
    cin >> N >> K;
    long long int sum = 0;
    for (long long int i = K; i <= N + 1; i++)
    {
        long long int back = i*(N+N-i+1)/2;
        long long int front = i*(i-1)/2;
        
        sum += back - front + 1;
        sum %= mod;
    }
    
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
int a[105];
int sum = 0;
using namespace std;
int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	for(int i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
		sum += a[i];
	}
	sort(a, a + n);
	double maxn = (double)sum / (4 * m);
	int t = n - (lower_bound(a, a + n, maxn) - a);
	if(t >= m)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1<<30;

int main(){
  int n;cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  int ans = 0;
  int pos=0;
  vector<bool> visited(n);
  while(true){
    ans++;
    if(a[pos]-1==pos || visited[a[pos]-1]){ans=-1;break;}
    visited[pos]=true;
    pos=a[pos]-1;
    if(pos==1)break;
    else if(pos==0){ans=-1;break;}
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include<stdio.h>

int main(void) {
    int s,h,m;

    scanf("%d",&s);

    h = s/3600;
    s %= 3600;
    m = s/60;
    s %= 60;

    printf("%d:%d:%d\n",h,m,s);

    return 0;
} 

Measured memory_bytes: 592
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;
using System.Diagnostics;
using System.Globalization;
using static System.Console;
using static System.Math;

namespace abc79_c
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            int a = int.Parse(str[0].ToString());
            int b = int.Parse(str[1].ToString());
            int c = int.Parse(str[2].ToString());
            int d = int.Parse(str[3].ToString());

            char op1 = 'a';
            char op2 = 'b';
            char op3 = 'c';

            for(int i=0; i<(1<<3); i++){
                int tmp=a;

                if((i&1) == 1){
                    tmp += d;
                    op3 = '+';
                }else{
                    tmp -= d;
                    op3 = '-';
                }

                if(((i>>1)&1) == 1){
                    tmp += c;
                    op2 = '+';
                }else{
                    tmp -= c;
                    op2 = '-';
                }

                if(((i>>2)&1) == 1){
                    tmp += b;
                    op1 = '+';
                }else{
                    tmp -= b;
                    op1 = '-';
                }

                if(tmp == 7){
                    WriteLine($"{a}{op1}{b}{op2}{c}{op3}{d}=7");
                    break;
                }
            }
        }
    }
}

Measured memory_bytes: 13140
/*
 * fudq.cpp
 *
 *  Created on: 2015-10-24
 *      Author: bjfudq
 */
#include <functional>
#include <algorithm>
#include <iostream>
//#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,102400000")


#define MEM(a) (memset((a),0,sizeof(a)))
#define LEN(a) (int)strlen((a))
#define fr(a) for(int i=0;i<(a);i++)
#define sf(a) scanf("%d",&(a))
#define sf64(a) scanf("%I64d",&(a))
#define sff(a) scanf("%lf",&(a))
#define sfs(a) scanf("%s",(a))
#define sf2(a,b) scanf("%d%d",&(a),&(b))
#define sf3(a,b,c) scanf("%d%d%d",&(a),&(b),&(c))
#define sf2s(a,b) scanf("%s%s",(a),(b))
#define sf2f(a,b) scanf("%lf%lf",&(a),&(b))
#define sf3f(a,b,c) scanf("%lf%lf%lf",&(a),&(b),&(c))
#define sf264(a,b) scanf("%I64d%I64d",&(a),&(b))
#define sf364(a,b,c) scanf("%I64d%I64d%I64d",&(a),&(b),&(c))
#define pf(a) printf("%d\n",(a))
#define pfc(a) printf("%c",(a))
#define pf64(a) printf("%I64d\n",(a))
#define pff(a) printf("%lf\n",(a))
#define pfs(a) printf("%s\n",(a))
#define pf2(a,b) printf("%d %d\n",(a),(b))
#define pf2s(a,b) printf("%s%s\n",(a),(b));
#define pf2f(a,b) printf("%lf %lf\n",(a),(b))
#define pf264(a,b) printf("%I64d %I64d\n",(a),(b))
#define pfn printf("\n")
#define pfk printf(" ")
#define LL long long

const int N=1000010;
const int M=1000010;
const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const int dir4[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
const int dir8[8][2]={{-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1}};
const double eps=1e-12;
const double PI=acos(-1.0);

inline int sign(double x){return (x>eps)-(x<-eps);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
/*************************/

int tot,prime[N+10],f[N+10];

void Getprime()
{
	memset(f,0,sizeof(f));
	tot=0;
	for(int i=2;i<=N;i++)
	{
		if(f[i] == 0)
			prime[tot++]=f[i]=i;
		for(int j=0;j<tot && prime[j]<=f[i] && i*prime[j]<=N;j++)
			f[i*prime[j]]=prime[j];
	}
}



int main(){
    Getprime();
    int n;
    while(sf(n)!=EOF){
    	int p=lower_bound(prime,prime+tot,n)-prime;
    	if(prime[p] != n) p--;
    	pf(p+1);
    }
    return 0;
}

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

int main() {
    int n, l;
    cin >> n >> l;
    string s[110];
    for (int i = 0; i < n; i++) cin >> s[i];
    sort(s, s + n);

    string ans;
    for (int i = 0; i < n; i++) {
        ans += s[i];
    }

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

Measured memory_bytes: 256
import bisect

N = int(input())

a = - int(input())

a_array = [a]

for i in range(N-1):
    a = - int(input())
    index = bisect.bisect_right(a_array,a)
    if index == len(a_array):
        a_array.append(a)
    else:
        a_array[index] = a
    # print(a_array)
print(len(a_array))


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

using namespace std;

typedef long long ll;
#define INF (1<<29)
#define INFF 0x7fffffff
#define LINF (1ll<<60)
#define LINFF 0x7fffffffffffffff
#define PI 3.14159265359
#define _fi(n) for(int i = 0;i < n;i++)
#define _fj(n) for(int j = 0;j < n;j++)
#define _fk(n) for(int k = 0;k < n;k++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define YESNO(ans) cout << (ans?"YES":"NO") << endl;
#define pqueue priority_queue
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl '\n'

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

    int n, m;cin>>n>>m;
    int pen[100005] = {};
    set<int>ac;
    int total = 0;
    _fi(m){
        int k;cin>>k;
        string s;cin>>s;

        if (s == "WA") pen[k]++;
        else{
            if (ac.find(k) == ac.end()){
                total += pen[k];
                pen[k] = 0;
                ac.insert(k);
            }
        }
    }

    cout << ac.size() << " "<< total << endl;

    return 0;
}


Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n;
ll dp[110][4][4][4];

int main() {
    cin >> n;

    rep(i, 4) {
        rep(j, 4) {
            rep(k, 4) {
                if (i==0 && j==1 && k==2) continue;
                if (i==0 && j==2 && k==1) continue;
                if (i==2 && j==0 && k==1) continue;
                dp[3][i][j][k] += 1;
            }
        }
    }

    for (int t = 3; t < n; t++) {
        rep(i, 4) {
            rep(j, 4) {
                rep(k, 4) {
                    if (i==0 && j==2 && k==1) continue;
                    if (i==2 && j==0 && k==1) continue;
                    if (i==0 && j==1 && k==2) continue;
                    rep(l, 4) {
                        if (j==0 && k==2 && l==1) continue;
                        if (j==2 && k==0 && l==1) continue;
                        if (j==0 && k==1 && l==2) continue;
                        if (i==0 && k==2 && l==1) continue;
                        if (i==0 && j==2 && l==1) continue;
                        dp[t+1][j][k][l] += dp[t][i][j][k];
                        dp[t+1][j][k][l] %= MOD;
                    }
                }
            }
        }
    }

    ll ans = 0;
    rep(i, 4) {
        rep(j, 4) {
            rep(k, 4) {
                if (i==0 && j==1 && k==2) continue;
                if (i==0 && j==2 && k==1) continue;
                if (i==2 && j==0 && k==1) continue;
                ans += dp[n][i][j][k];
                ans %= MOD;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
x, y = map(int, input().split())

mod = 10 ** 9 + 7


def choose(n, r):
    cx = 1
    cy = 1
    for i in range(r):
        cx = cx * (n - i) % mod
        cy = cy * (i + 1) % mod
    cy = pow(cy, mod - 2, mod)
    return cx * cy % mod


if (x + y) % 3 != 0:
    print(0)
    exit()
else:
    n = (x + y) // 3
    x -= n
    y -= n
    if x < 0 or y < 0:
        print(0)
        exit()
    print(choose(x + y, x))


Measured memory_bytes: 3064
n=int(input())
ll=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

l=["a"]
for j in range(2,n+1):
    tmp=[]
    for s in l:
        m=len(set(list(s)))
        for i in ll[:m+1]:
            tmp.append(s+i)
    l=tmp

l.sort()
print('\n'.join(map(str,l)))





Measured memory_bytes: 15444
s = gets.chomp.chars
s_start = [s[0], s[1]]
s_end = [s[2], s[3]]
def search(x, y)
  if x == '0'
    if y.match(/[1-9]/)
      'Yes'
    else
      'No'
    end
  elsif x == '1'
    if y.match(/[0-2]/)
      'Yes'
    else
      'No'
    end
  else
    'No'
  end
end
a = search(s_start[0], s_start[1])
b = search(s_end[0], s_end[1])
if a == 'Yes' && b == 'Yes'
  puts 'AMBIGUOUS'
elsif a == 'Yes' && b == 'No'
  puts 'MMYY'
elsif a == 'No' && b == 'Yes'
  puts 'YYMM'
elsif a == 'No' && b == 'No'
  puts 'NA'
end


Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

int ans;
string s;

int main(void) {
    cin >> s;

    for (int i = 0; i < (int)s.size(); i++) s[i] = 'x';
    cout << s << endl;

	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
 
// syakutori-hou
class Program
{
    static void Main()
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        new Program().solve();
        Console.Out.Flush();
    }
    Scanner cin = new Scanner();
 
 
    void solve()
    {
		int N = cin.nextint;
		int S = cin.nextint;
		
		var A = cin.scanint;
		
		int high = 0, low = 0, sum = 0;
		int ans = int.MaxValue;
		
		while(true)
		{
			while(high < N && sum < S)
			{
				sum += A[high++];
			}
			if(sum < S) break;
			ans = Math.Min(ans, high - low);
			sum -= A[low++];
		}
		if(ans> N)
		{
			ans = 0;
		}
		
		Console.WriteLine(ans);
    }
 
}
 
class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return Console.ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 15248
#include<iostream>

int main(){
  int n, k, num = 1;
  std::cin >> n >> k;
  for(int i = 1; i <= n; i++){
    if(num*2 <= num + k)
      num *= 2;
  	else
      num += k;
  }
  std::cout << num << std::endl;
  return 0;
}


Measured memory_bytes: 256
import sys
n = int(input())
abc_list = []

for i in range(n):
    abc_list.append(list(map(int,input().split())))

pre_suma,pre_sumb,pre_sumc = abc_list[0][0],abc_list[0][1],abc_list[0][2]

if n == 1:
    print(max(pre_suma,pre_sumb,pre_sumc))
    sys.exit()

for i in range(1,n):
    a,b,c = abc_list[i][0],abc_list[i][1],abc_list[i][2]
    suma = a + max(pre_sumb,pre_sumc)
    sumb = b + max(pre_suma,pre_sumc)
    sumc = c + max(pre_suma,pre_sumb)
    pre_suma,pre_sumb,pre_sumc = suma,sumb,sumc
    # print(suma,sumb,sumc)
print(max(suma,sumb,sumc))

    

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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

typedef long long ll;
typedef pair<int, int> p;

int n;
vector<int> v;

ll calc(ll s) {
  ll sum = 0, res = 0;
  for (int i = 0; i < n; ++i, s *= -1) {
    sum += v[i];
    if (sum * s > 0) continue;
    res += abs(sum - s);
    sum += s * abs(sum - s);
  }
  return res;
}

int main(){
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    int tmp;
    cin >> tmp;
    v.push_back(tmp);
  }
  cout << min(calc(1), calc(-1)) << endl;
}


Measured memory_bytes: 892
#include<iostream>
using namespace std;
int main(){
  double x[2],y[2],z[2],p[2];
  while(cin >>x[0]>>x[1]>>y[0]>>y[1]>>z[0]>>z[1]>>p[0]>>p[1]){
    double v[3][2],vp[3][2];
    v[0][0] = y[0]-x[0];
    v[0][1] = y[1]-x[1];
    v[1][0] = z[0]-y[0];
    v[1][1] = z[1]-y[1];
    v[2][0] = x[0]-z[0];
    v[2][1] = x[1]-z[1];
    vp[0][0] = p[0]-x[0];
    vp[0][1] = p[1]-x[1];
    vp[1][0] = p[0]-y[0];
    vp[1][1] = p[1]-y[1];
    vp[2][0] = p[0]-z[0];
    vp[2][1] = p[1]-z[1];
    int n=0;
    for(int i=0; i<3; i++){
      if(v[i][0]*vp[i][1]-v[i][1]*vp[i][0]<0) n--;
      else n++;
    }
    if(n == 3 || n == -3) cout <<"YES"<<endl;
    else cout <<"NO"<<endl;
  }
  return 0;
}

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

int k[15], s[15][15], p[15];
int main() {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> k[i];
        for (int j = 0; j < k[i]; j++) {
            cin >> s[i][j];
            s[i][j]--;
        }
    }
    int ans = 0;
    for (int i = 0; i < m; i++) cin >> p[i];
    for (int bit = 0; bit < (1 << n); bit++) {
        int f = 1;
        for (int i = 0; i < m; i++) {
            int cnt = 0;
            for (int j = 0; j < k[i]; j++) {
                if ((bit >> s[i][j]) & 1) cnt++;
            }
            if (cnt % 2 != p[i]) f = 0;
        }
        if (f) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc061/tasks/abc061_c
import sys

def main():
    n, k = map(int, input().split())
    ans = [0 for _ in range(10**5+1)]
    for x in sys.stdin.readlines():
        a, b = map(int, x.split())
        ans[a] += b

    cnt = 0
    for i in range(10**5+1):
        cnt += ans[i]
        if cnt >= k:
            print(i)
            exit()

if __name__ == "__main__":
    main()

Measured memory_bytes: 18776
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <string>
#include <complex>
#include <cmath>
#include <iostream>
#include <iomanip>

int A, B, H, M;
long  double gannma, c ,zeta;
const long double PI=3.14159265358979323846;

int main() {
  std::cin >> A >> B >> H >> M;
  zeta = std::abs(((long double)(H+((long double)M)/60))/12 - ((long double)M)/60);
  // gannma = 2 * PI * (zeta > 0.5 ? zeta - 0.5 : zeta) ;
  gannma = 2 * PI * zeta;
  c = std::sqrt((long double)(A*A + B*B) - (long double)(2*A*B)*std::cos(gannma));

  std::cout << std::fixed << std::setprecision(20) <<  c << std::endl;
}


Measured memory_bytes: 4140
# coding: utf-8
import collections
n=int(input())
all_str=list(map(int,input().split()))
i=0
j=0
o_str=[]   # 0, ,2,
e_str=[]   #  ,1, ,3,
while(2*i<n):
  o_str.append(all_str[2*i])
  i+=1
while(2*j+1<n):
  e_str.append(all_str[2*j+1])
  j+=1

o_c=collections.Counter(o_str)
e_c=collections.Counter(e_str)
o_mode=o_c.most_common()[0][0]
e_mode=e_c.most_common()[0][0]
o_mode_n=o_str.count(o_mode)
e_mode_n=e_str.count(e_mode)
if(o_mode==e_mode):
  if(len(o_c)==1 and len(e_c)==1):
    if(o_mode_n>e_mode_n):
      e_mode_n=0
      
    else:
      
      o_mode_n=0
      
  else:
    if(len(o_c)==1):
      o_c_sec=0
      e_c_sec=e_c.most_common()[1][1]
    elif(len(e_c)==1):
      e_c_sec=0
      o_c_sec=o_c.most_common()[1][1]
    else:
      o_c_sec=o_c.most_common()[1][1]
      e_c_sec=e_c.most_common()[1][1]
    if(o_c_sec>e_c_sec):
      o_mode_n=o_c.most_common()[1][1]
    else:
      e_mode_n=e_c.most_common()[1][1]
alt=len(all_str)-o_mode_n-e_mode_n
print(alt)

Measured memory_bytes: 19040
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

template <typename T, T N>
class UnionFind {
    T parent_[N];
    T rank_[N];
    T size_[N];

public:
    UnionFind();
    T Root(T idx);
    bool IsSame(T x, T y);
    void Unite(T x, T y);
    T GetSize(T idx);
};

template <typename T, T N>
UnionFind<T, N>::UnionFind()
{
    for (T i = 0; i < N; i++) {
        parent_[i] = i;
        rank_[i] = 0;
        size_[i] = 1;
    }
}

template <typename T, T N>
T UnionFind<T, N>::Root(T idx)
{
    return parent_[idx] == idx ? idx : parent_[idx] = Root(parent_[idx]);
}

template <typename T, T N>
bool UnionFind<T, N>::IsSame(T x, T y)
{
    return Root(x) == Root(y);
}

template <typename T, T N>
void UnionFind<T, N>::Unite(T x, T y)
{
    x = Root(x);
    y = Root(y);
    if (x == y) {
        return;
    }

    if (rank_[x] < rank_[y]) {
        parent_[x] = y;
        size_[y] += size_[x];
    } else {
        parent_[y] = x;
        size_[x] += size_[y];
        if (rank_[x] == rank_[y]) {
            rank_[x]++;
        }
    }
}

template <typename T, T N>
T UnionFind<T, N>::GetSize(T idx)
{
    return size_[Root(idx)];
}

long long pow_mod(long long n, long long p, long long m)
{
    if (p == 0) {
        return 1;
    }

    if (p % 2 == 0) {
        long long t = pow_mod(n, p / 2, m);
        return t * t % m;
    }
    return n * pow_mod(n, p - 1, m) % mod;
}

long long nCr_mod(long long n, long long r)
{
    long long x = 1;
    for (long long i = n - r + 1; i <= n; i++) {
        x *= i;
        x %= mod;
    }

    long long a = 1;
    for (long long i = 1; i <= r; i++) {
        a *= i;
        a %= mod;
    }

    long long y = pow_mod(a, mod - 2, mod) % mod;

    return x * y % mod;
}

int main()
{
    long long n;
    std::cin >> n;

    std::vector<long long> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }

    std::map<long long, long long> l, r;
    for (int i = 0; i < n; i++) {
        l[i + a[i]]++;
        r[i - a[i]]++;
    }

    long long count = 0;
    for (auto t : l) {
        count += t.second * r[t.first];
    }

    std::cout << count << std::endl;
}


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

import numpy as np

G = np.array([list(map(int,input().split())) for i in range(N)], dtype=np.uint32)

import scipy.sparse.csgraph as csg

G2 = csg.floyd_warshall(G,directed=False)

if np.any(G != G2):
  print(-1)
else:
  G[G==0] = 2*10**9
  t = 0
  for i in range(N):
    for j in range(i+1,N):
      n = np.min(G[i]+G[j])
      if n > G[i,j]:
        t += G[i,j]


  print(t)

Measured memory_bytes: 19000
#include <iostream>

int main(){
	
	int n, debt = 100000;
	std::cin >> n; // input
	// calc debt
	for(int i = 0; i < n; ++i){
		debt *= 1.05;
		// need this process for submitting
		if(debt % 1000 != 0){
			debt += 1000;
			debt -= debt % 1000;
		}
	}
	// output
	std::cout << debt << std::endl;
	return 0;
}

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

int main() {
  int x,a,b;
  cin>>x>>a>>b;
  a=x/500;
  b=(x-500*a)/5;
  cout<<1000*a+5*b<<endl;
}

Measured memory_bytes: 256