akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

void z_algorithm(const string& s, vector<int>& Z){
    const int n = s.size();
    Z = vector<int>(n, 0);
    for(int i = 1, j = 0; i < n; ++i){
        if(i+Z[i-j] < j+Z[j]){
            Z[i] = Z[i-j];
        }else{
            auto k = max(0, j+Z[j]-i);
            while(i+k < n && s[k] == s[i+k]) ++k;
            Z[i] = k;
            j = i;
        }
    }
    Z[0] = n;
}

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

    string S;
    cin >> S;

    vector<vector<int>> dp(N, vector<int>(N, 0));
    for(int i = 0; i < N; ++i){
        const int n = S.substr(i).size();
        vector<int> Z;
        z_algorithm(S.substr(i), Z);
        copy(begin(Z), end(Z), &dp[i][i]);
    }

    int ans = 0;
    for(int i = 0; i < N; ++i){
        for(int j = i+1; j < N; ++j){
            ans = max(min(j-i, dp[i][j]), ans);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 98176
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    int n, m, p;
    cin >> n >> m >> p;
    vector<tuple<int, int, int>> es;
    vector<vector<int>> graph(n);
    vector<vector<int>> rev(n);
    for(int i = 0; i < m; ++i){
        int a, b, c;
        cin >> a >> b >> c;
        --a, --b;
        es.emplace_back(a, b, p - c);
        graph[a].emplace_back(b);
        rev[b].emplace_back(a);
    }

    vector<bool> visited(n, false);
    vector<bool> rev_visited(n, false);

    auto dfs = [](auto&& self, vector<vector<int>>& g, vector<bool>& memo, int from) -> void {
        if(memo[from])  return;
        memo[from] = true;
        for(int to : g[from]){
            self(self, g, memo, to);
        }
        return;
    };
    dfs(dfs, graph, visited, 0);
    dfs(dfs, rev, rev_visited, n - 1);

    vector<bool> used(n);
    for(int i = 0; i < n; ++i){
        used[i] = visited[i] && rev_visited[i];
    }

    constexpr ll inf = 1e+11;
    vector<ll> dist(n, inf);
    dist[0] = 0;
    bool update = false;
    for(int loop = 0; loop < n; ++loop){
        update = false;
        for(int i = 0; i < m; ++i){
            int u, v, cost;
            tie(u, v, cost) = es[i];
            if(!used[u] || !used[v])    continue;
            if(dist[v] > dist[u] + cost){
                dist[v] = dist[u] + cost;
                update = true;
            }
        }
    }

    ll ans = max(0LL, -dist[n - 1]);
    if(update)  ans = -1;
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

int main(){
    ll T;
    cin>>N>>T;
    vec a(N), b(N), ord(N);
    rep(i,N) cin>>a[i]>>b[i], ord[i] = i;
    sort(ALL(ord), [&](ll x, ll y){
        return a[x] > a[y];
    });
    mat dp(N + 1, vec(6010,-INF));
    dp[0][0] = 0;
    ll ans = 0;
    rep(i,N){
        ll id = ord[i];
        rep(j,6010){
            if(j == 0){
                dp[i+1][j] = max(dp[i][j], b[id]);
            }else if(j < a[id]){
                dp[i+1][j] = dp[i][j];
            }else{
                dp[i+1][j] = max(dp[i][j], dp[i][j - a[id]] + b[id]);
            }
            if(j < T) ans = max(ans, dp[i+1][j]);
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 141440
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
const int MOD = ((int)1e9)+7;
const int INF = (int)(1e9)+(int)(1e7);
const ll INFL = (ll)(1e18)+INF;
const double EPS = 1e-8;
using namespace std;
int main()
{
   vector<vector<int>>map(3,vector<int>(3));
   rep(i,3)rep(j,3)cin >> map[i][j];
   int N;
   cin >> N;
   rep(i,N){
       int b;
       cin >> b;
       rep(j,3)rep(k,3){
           if(map[j][k]==b)map[j][k]*=-1;
       }
   }
   bool ok=false;
   rep(i,3)ok|=(map[i][0]<0&&map[i][1]<0&&map[i][2]<0);
   rep(i,3)ok|=(map[0][i]<0&&map[1][i]<0&&map[2][i]<0);
   ok|=(map[0][0]<0&&map[1][1]<0&&map[2][2]<0);
   ok|=(map[0][2]<0&&map[1][1]<0&&map[2][0]<0);

   if(ok)cout << "Yes" << endl;
   else cout << "No" << endl;

   return 0;
}

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

int n;

void CountingSort(int [],int [], int);

int main(){
  int *A, *B;
  int max=0;
  int i;

  scanf("%d",&n);
  A = (int *)malloc(n * sizeof(int));
  B = (int *)malloc(n * sizeof(int));

  for(i=0; i<n; i++){
    scanf("%d",&A[i]);

    if(max < A[i])
      max = A[i];
  }

  CountingSort(A,B,max+2);

  for(i=0; i<n; i++){
    printf("%d",B[i]);

    if(i<n-1)
      printf(" ");
  }
  printf("\n");
  
  free(A);
  free(B);
  return 0;
}

void CountingSort(int A[],int B[], int k){
  int C[k];
  int i;

  for(i=0; i<k; i++)
    C[i] = 0;

  for(i=0; i<n; i++)
    C[A[i]]++;

  for(i=1; i<k; i++)
    C[i] += C[i-1];

  for(i=n-1; i>=0; i--){
    B[C[A[i]]-1] = A[i];
    C[A[i]]--;
  }
}



Measured memory_bytes: 17108
#include <iostream>
#include <string>
#include <iomanip>
#include <ios>
using namespace std;
int main(void){
  string s;
  cin >> s;
  
  int n = s.length();
  
  if(n == 2)
    cout << s << endl;
  else{
    for(int i=2;i>=0;i--){
      cout << s[i];
    }
    cout << endl;
  }
  
  return 0;
}

  
  

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

int main() {
    ll v = 100, ans = 0, x; cin >> x;
    while (v < x) {
        v = 1.01 * v;
        ans++;
    }
    cout << ans << endl;
    return 0;
}


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

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

    int T, F, count = 0;
    char C;
    string L, R;
    for (int i = 0; i < Q; i++) {
        cin >> T;
        if (T == 1) {
            count++;
        }
        else {
            cin >> F >> C;
            if (F == 1 && count % 2 == 0) {
                L = C + L;
            }
            if (F == 1 && count % 2 == 1) {
                R += C;
            }
            if (F == 2 && count % 2 == 0) {
                R += C;
            }
            if (F == 2 && count % 2 == 1) {
                L = C + L;
            }
        }
    }

    if (count % 2 == 0) {
        cout << L + S + R << endl;
    }
    else {
        reverse(L.begin(), L.end());
        reverse(S.begin(), S.end());
        reverse(R.begin(), R.end());
        cout << R + S + L << endl;
    }
}

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

int main() {
  int a, b, x;
  cin >> a >> b;
  
  if(a < 10 && b < 10) {
    x = a * b;
  }
  else {
    x = -1;
  }
  
  cout << x << endl;
}

Measured memory_bytes: 256
while true
    n, r = gets.chomp.split.map(&:to_i)
    break if [n, r] == [0, 0]
    cards = (1..n).to_a.reverse
    r.times{
        p, c = gets.chomp.split.map(&:to_i)
        cards = cards[p - 1, c] + cards[0, p - 1] + cards[(p - 1 + c) .. -1]
    }
    puts cards[0]
end


Measured memory_bytes: 7164
import sys
from string import ascii_lowercase

INPUT = lambda: sys.stdin.readline().rstrip()

sys.setrecursionlimit(10 ** 9)


def main():
    C = INPUT()

    flag = False
    for s in ascii_lowercase:
        if flag:
            print(s)
            sys.exit()
        if s == C: flag = True


if __name__ == '__main__':
    main()

Measured memory_bytes: 38640
#include <iostream>

using namespace std;

int v[100003];
int am2[3];
int am[3];
int n;

inline int type(int a) {

    if(a%4 == 0) {
        return 0;
    } else if(a%2 == 0) {
        return 1;
    } else {
        return 2;
    }

}

bool tryy(int typ) {

    am[0] = am2[0];
    am[1] = am2[1];
    am[2] = am2[2];

    if(am[typ] == 0)
        return false;

    if(typ == 0)
        v[1] = 4;
    else if(typ == 1)
        v[1] = 2;
    else
        v[1] = 1;

    int t;
    am[type(v[1])]--;
    //cout << "TEST " << am[0] << " " << am[1] << " " << am[2] << '\n';

    for(int i = 1; i < n; i++) {

        t = type(v[i]);

        if(t == 2) {
            if(am[0] == 0) {
                return false;
            }
            v[i+1] = 4;
            am[0]--;
        } else if(t == 1) {

            if(am[1] == 0 && am[0] == 0) {
                return false;
            }

            if(am[1] != 0) {
                v[i+1] = 2;
                am[1]--;
            } else {
                v[i+1] = 4;
                am[0]--;
            }

        } else {

            if(am[2] == 0 && am[1] == 0 && am[0] == 0) {
                return false;
            }

            if(am[2] != 0) {
                v[i+1] = 1;
                am[2]--;
            } else if(am[1] != 0) {
                v[i+1] = 2;
                am[1]--;
            } else {
                v[i+1] = 4;
                am[0]--;
            }

        }

    }

}

int main() {

    ios::sync_with_stdio(false);

    cin >> n;

    for(int i = 1; i <= n; i++) {
        cin >> v[i];
        am2[type(v[i])]++;
    }

    if(tryy(0) || tryy(1) || tryy(2)) {
        cout << "Yes";
    } else {
        cout << "No";
    }

    return 0;
}


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

int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    int sum=0;
    for(int i=0;i<n;i++){
        int x;
        scanf("%d",&x);
        if(x >= m){
            sum++;
        }
    }
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 256
import math
L, R = map(int, input().split())
R=min(R,L+2019)
m=2018
for i in range(L,R+1):
  for j in range(i,R+1):
    if i==j:
      continue
    if (i*j)%2019<m:
      m=(i*j)%2019
print(m)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define mkt make_tuple
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int N, M, Q, L, R, p, q, t[501][501];

int main(){
	cin >> N >> M >> Q;
	for (int i = 0; i != M; ++i) {
		cin >> L >> R;
		++t[L][R];
	}
	for (int i = 1; i != N + 1; ++i) {
		for (int j = 1; j != N + 1; ++j) {
			t[i][j] += t[i][j - 1];
		}
	}
	for (int i = 1; i != N + 1; ++i) {
		for (int j = 1; j != N + 1; ++j) {
			t[j][i] += t[j - 1][i];
		}
	}
	for (int i = 0; i != Q; ++i) {
		cin >> p >> q;
		cout << t[p - 1][p - 1] + t[q][q] - t[p - 1][q] - t[q][p - 1] << endl;
	}
	return 0;
}


Measured memory_bytes: 1920
#include <stdio.h>

int main(void){
	int x1,y,ylim,y1,p,xsum,ysum;
	scanf("%d%d%d%d%d",&x1,&y,&ylim,&y1,&p);
	xsum=p*x1;
	if(ylim < p)
		ysum=y+(p-ylim)*y1;
	else
		ysum=y;
	if(xsum<=ysum)
		printf("%d\n",xsum);
	else
		printf("%d\n",ysum);
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
   #define PP pair<int,pair<int,int>>
const int MAX = 1000001;
const int MOD =  998244353;
const int INV2 = (MOD+1)/2;
int x[1000001]={};
int  inv[MAX];

// テーブルを作る前処理
void COMinit() {
    //fac[0] = fac[1] = 1;
   // finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
   //     fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
  //      finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
     signed main(){
        COMinit();
        int n;
        cin>>n;
        int a,s=0;
        for(int i=0;i<n;i++){
          cin>>a;
          s=(s+a)%MOD;
          x[a]=(x[a]+a)%MOD;
        }
        for(int i=1;i<=500000;i++){
          for(int j=i*2;j<1000001;j+=i){
            x[i]=(x[i]+x[j])%MOD;
          }
        }
        for(int i=1;i<1000001;i++)x[i]=(x[i]*x[i])%MOD;
        for(int i=500000;i>0;i--){
          for(int j=2*i;j<1000001;j+=i){
            x[i]=(x[i]+MOD-x[j])%MOD;
          }
        }
        int ans=0;
        for(int i=1;i<1000001;i++)ans=(inv[i]*x[i]%MOD+ans)%MOD;
        cout<<((ans+MOD-s)%MOD*INV2)%MOD<<endl;


 




}


        


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

int main() {
    int m = 998244353;
    int N;
    cin >> N;
    vector<int> D(N);
    for (int i = 0; i < N; i++) {
        cin >> D.at(i);
    }
    int Dmax = 0;
    vector<int> numD(N, 0);
    for (int i = 0; i < N; i++) {
        numD.at(D.at(i))++;
        Dmax = max(Dmax, D.at(i));
    }

    if (D.at(0) != 0) {
        cout << 0 << endl;
        return 0;
    }
    if (numD.at(0) != 1) {
        cout << 0 << endl;
        return 0;
    }

    int64_t ans = 1;
    for (int i = 1; i <= Dmax; i++) {
        int64_t a = 1;
        for (int j = 0; j < numD.at(i); j++) {
            a *= numD.at(i-1);
            a %= m;
        }
        ans *= a;
        ans %= m;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;

bool primeNumber(long long n){
    if(n < 2){
        return false;
    }
    else{
        for(long long i = 2; i*i <= n; i++){
            if(n % i == 0){
                return false;
            }
        }
        return true;
    }
}

int main(){
    vector<long long> likeNumber(100000, 0);
    vector<long long> sum(100001, 0);

    for(long long i = 1; i <= 100000; i++){
        if(primeNumber(i) == true and (i+1) % 2 == 0 and primeNumber((i+1)/2) == true){
            likeNumber[i] = 1;
        }
    }

    for(long long i = 0; i <= 100000; i++){
        sum[i+1] = sum[i] + likeNumber[i];
    }


    long long q;
    cin >> q;

    vector<long long> result(q);

    for(long long i = 0; i < q; i++){
        long long r, l;
        cin >> r >> l;
        result[i] = sum[l+1] - sum[r];
    }

    for(long long i = 0; i < q; i++){
        printf("%lld\n", result[i]);
    }
    return 0;
}

Measured memory_bytes: 5604
let z=List.fold_left2 and k=[0;1;2;3]and h()=Scanf.scanf"%d %d %d %d "(fun a b c d->[a;b;c;d]);;let rec f()=let a,b=h(),h()in let m,n=z(fun(m,n)s i->z(fun(p,q)x j->if x=s&&i=j then(p+1,q)else if x<>s then(p,q)else(p,q+1))(m,n)a k)(0,0)b k in f(Printf.printf"%d %d
"m n);;try f()with _->()

Measured memory_bytes: 2316
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
const int MOD=998244353;
const double eps=1e-8;
typedef long long ll;
//orz yht
using namespace std;
ll n,s,a[3005];
ll dp[3005],ans;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n>>s;
	dp[0]=1;
	for(ll i=0;i<n;i++){
		cin>>a[i];
		if(s>=a[i])
		ans=(ans+dp[s-a[i]]*(n-i))%MOD;
		for(ll j=s-a[i]-1;j>=0;j--)
		dp[j+a[i]]=(dp[j+a[i]]+dp[j])%MOD;
		dp[0]++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){

    int n;
    cin >> n;

    map<int, int> mp;

    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        if(mp[a]){
            cout << "NO" << endl;
            return 0;
        }
        else mp[a] = 1;
    }

    cout << "YES" << endl;
    

}

Measured memory_bytes: 9600
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		if (a < b) {
			if (b < c) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 26344
'use strict'

const main = (input) => {
    const N = parseInt(input)

    for(let i = 0; i <= 25; i++){
        for(let j = 0; j <= 25; j++){
            let total = i * 4 + j * 7
            if(total === N){
                console.log('Yes')
                return
            }
        }
    }
    console.log('No')
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Measured memory_bytes: 7372
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	int N;
	int M;
	Tuple[] nodes;
	boolean enable = true;

	static class Pair {
		int id, D;

		Pair(int id, int D) {
			this.id = id;
			this.D = D;
		}
	}

	static class Tuple {
		int id;
		Long pos;
		Set<Pair> prevs, nexts;

		Tuple(int id) {
			this.id = id;
			this.pos = null;
			this.prevs = new HashSet<>();
			this.nexts = new HashSet<>();
		}
	}

	Main(BufferedReader in) throws IOException {
		String[] tokens = in.readLine().split(" ");
		N = Integer.parseInt(tokens[0]);
		M = Integer.parseInt(tokens[1]);
		nodes = new Tuple[N];
		for (int i = 0; i < N; ++i) {
			nodes[i] = new Tuple(i);
		}
		for (int i = 0; i < M; ++i) {
			tokens = in.readLine().split(" ");
			int L = Integer.parseInt(tokens[0]) - 1;
			int R = Integer.parseInt(tokens[1]) - 1;
			int D = Integer.parseInt(tokens[2]);
			nodes[L].nexts.add(new Pair(R, D));
			nodes[R].prevs.add(new Pair(L, D));
		}
	}

	boolean check(int current, long pos) {
		if (nodes[current].pos != null) {
			if (nodes[current].pos != pos) {
				// 矛盾
				return false;
			}else {
				// すでにチェック済みで問題なし
				return true;
			}
		} else {
			// 初期設定
			nodes[current].pos = pos;
		}
		// 次を探索
		for (Pair pair : nodes[current].nexts) {
			boolean cond = check(pair.id, pos + pair.D);
			if (!cond) {
				// 矛盾
				return false;
			}
		}
		// 前を探索
		for (Pair pair : nodes[current].prevs) {
			boolean cond = check(pair.id, pos - pair.D);
			if (!cond) {
				return false;
			}
		}
		return true;
	}

	void calc() {
		if (M != 0) {
			for (int i = 0; i < N; ++i) {
				if (nodes[i].pos == null) {
					boolean cond = check(i, 0L);
					if (!cond) {
						enable = false;
						return;
					}
				}
			}
		}
	}

	void showResult() {
		System.out.println((enable ? "Yes" : "No"));
	}
}

Measured memory_bytes: 150092
from math import gcd
from functools import reduce


k = int(input())

def gcd_(*numbers):
    return reduce(gcd, numbers)

k += 1
ans = 0

#for i in range(1,k):
#    for j in range(i,k):
#        #print(i,j)
#        if i == j:
#            ans += gcd(i,j)
#        else:
#            ans += gcd(i,j)*6

for i in range(1,k):
    for j in range(1,k):
        for h in range(1,k):
            #print(i,j,h)
            ans += gcd_(i,j,h)


print(ans)


Measured memory_bytes: 69560
#include<bits/stdc++.h>
using namespace std;
int main () {
  int N, M;
  cin >> N >> M;
  if (N >= M) {
    cout << 0 << endl;
    return 0;
  }
  vector<int>koma(M);
  for (int i = 0; i < M; i ++) cin >> koma[i];
  sort(koma.begin(), koma.end());
  vector<int>len(M - 1);
  for (int i = 1; i < M; i ++) {
    len[i - 1] = koma[i] - koma[i - 1];
  }
  sort(len.begin(), len.end());
  int ans = 0;
  for (int i = 0; i < M - N; i ++) {
    ans += len[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORe(i, k, n) for(int i = (k); i <= (n); i++)
#define FORr(i, k, n) for(int i = (k); i > (n); i--)
#define FORre(i, k, n) for(int i = (k); i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

const int INF = 1001001001;
const int mod = 1000000007;

int main(void){
  int n, x;
  cin >> n >> x;
  int ans = 1;
  int d = 0;
  REP(i, n){
    int l;
    cin >> l;
    d += l;
    if(d <= x) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include <vector>
#include <numeric>
using namespace std;
typedef long long ll;

int main()
{
  int n,m,x;
  scanf("%d %d %d",&n,&m,&x);
  
  int a[n];
 
  int adj[n][m];
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);

    for(int j=0;j<m;j++){
      scanf("%d",&adj[i][j]);
  
    }
  }
  vector<int> s;
  int ans = 999999999;
 // vector<int> algo(n,0);
  for(int i=0;i<(int)(pow(2,n));i++){
    s.clear();
    vector<int> algo(m);
    for(int j=0;j<n;j++){
      if(i&(1<<j)) s.push_back(j);
    }
    for(auto k:s){
      for(int c=0;c<m;c++){
        algo[c]+=adj[k][c];
      }
    }
        
    bool tr = true;
    for(auto z:algo){
      if(z<x){
        tr = false; break;
      }
    }
    
    if(tr){
      int sum = 0;
    
      for(auto l:s) sum+=a[l];
      ans = min(ans,sum);
    }
    
  }
  if(ans==999999999) cout<<-1;
  else cout<<ans;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  char c;
  bool data[26] = { false,};
  while (cin >> c) {
    data[c - 'a'] = true;
  }
  string ans = "None";
  for (int i = 0; i < 26; i++) {
    if (data[i] == false) {
      ans = char(i + 'a');
      break;
    }
  }
  cout << ans << '\n';
}


Measured memory_bytes: 256
/**
 * File    : E.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-6-23 21:49:57
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <random> // random_device rd; mt19937 mt(rd());
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int N, M;
set<int> W[1000];
vector<int> V[1000];

vector<pair<int, int>> res;

int visited[1000];
int cnt[2];

bool nuri(int v, int k)
{
  visited[v] = k;
  for (auto x : V[v])
  {
    if (visited[x] == 0)
    {
      if (!nuri(x, 3 - k))
      {
        return false;
      }
    }
    else if (visited[x] == k)
    {
      return false;
    }
  }
  cnt[k - 1]++;
  return true;
}

bool reach[1000][1000];

int main()
{
  cin >> N >> M;
  for (auto i = 0; i < M; i++)
  {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    W[a].insert(b);
    W[b].insert(a);
  }
  for (auto i = 0; i < N; i++)
  {
    for (auto j = 0; j < N; j++)
    {
      if (i == j)
        continue;
      if (W[i].find(j) == W[i].end())
      {
        V[i].push_back(j);
        // cerr << "V[" << i << "].push_back(" << j << ")" << endl;
      }
    }
  }
  fill(visited, visited + 1000, 0);
  for (auto k = 0; k < N; k++)
  {
    if (visited[k] != 0)
    {
      continue;
    }
    cnt[0] = cnt[1] = 0;
    if (!nuri(k, 1))
    {
      cout << -1 << endl;
      return 0;
    }
    res.push_back(make_pair(cnt[0], cnt[1]));
  }
  fill(&reach[0][0], &reach[0][0] + 1000 * 1000, false);
  reach[0][0] = true;
  for (int i = 0; i < (int)res.size(); i++)
  {
    auto e = res[i];
    int x = e.first;
    int y = e.second;
    // cerr << "i = " << i << endl;
    // cerr << "x = " << x << ", y = " << y << endl;
    for (auto j = N; j >= 0; j--)
    {
      if (reach[i][j])
      {
        // cerr << "j = " << j << endl;
        reach[i + 1][x + j] = true;
        reach[i + 1][y + j] = true;
      }
    }
  }
  int ans = 1000000007;
  for (auto i = 0; i <= N; i++)
  {
    int j = N - i;
    if (reach[(int)res.size()][i])
    {
      ans = min(ans, i * (i - 1) / 2 + j * (j - 1) / 2);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 24192
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int a, b, c;
    cin >> a >> b >> c;
    int sum = 0;
    sum += a;
    sum += b;
    sum += c;
    if(sum >= 22){
        cout << "bust" << endl;
    }else{
        cout << "win" << endl;
    }
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")
int H, W;
char F[22][22];
int cost[22][22];

int bfs(int start, int end) {
	queue<pair<int, int>> K;
	K.push(make_pair(start,end));
	fx(H) {
		fy(W) {
			cost[x + 1][y + 1] = 10000;
		}
	}
	cost[start][end] = 0;
	while (!K.empty()) {
		auto p = K.front(); K.pop();
		int x = p.first,y=p.second;
		if (F[x-1][y]=='.' && cost[x-1][y]>cost[x][y]+1) {
			cost[x - 1][y] = cost[x][y] + 1;
			K.push(make_pair(x-1,y));
		}
		if (F[x + 1][y] == '.' && cost[x + 1][y] > cost[x][y] + 1) {
			cost[x + 1][y] = cost[x][y] + 1;
			K.push(make_pair(x + 1, y));
		}
		if (F[x ][y - 1] == '.' && cost[x ][y - 1] > cost[x][y] + 1) {
			cost[x ][y - 1] = cost[x][y] + 1;
			K.push(make_pair(x , y - 1));
		}
		if (F[x ][y + 1] == '.' && cost[x ][y + 1] > cost[x][y] + 1) {
			cost[x ][y + 1] = cost[x][y] + 1;
			K.push(make_pair(x , y + 1));
		}
	}
	int res = 0;
	pairs(Z);
	fx(H) {
		fy(W) {
			if (F[x+1][y+1]=='.') {
				if (res < cost[x+1][y+1]) {
					res = cost[x + 1][y + 1];
				}
			}
		}
	}
	return res;
}

int main()
{
	cin >> H >> W;
	int start, end;
	fx(22) {
		fy(22) {
			F[x][y] = '#';
		}
	}

	fx(H) {
		string s;
		cin >> s;
		fy(W) {
			F[x+1][y+1] = s[y];
			if (s[y]=='.') {
				start = x+1;
				end = y+1;
			}
		}
	}

	int ans = 0;
	fx(H) {
		fy(W) {
			if (F[x+1][y+1]=='.') {
				ans = max(ans, bfs(x + 1, y + 1));
			}
		}
	}

	ce(ans)
	return 0;
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007; 
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

template<class T, class S> inline bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S> inline bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}






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


Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

struct UnionFind {
	vector<int> par;
	UnionFind(int x) : par(x, -1) {}
	void init(int x) { par.assign(x, -1); }
	int root(int x) {
		if (par[x] <= -1) return x;
		else return root(par[x]);
	}
	bool issame(int x, int y) {
		return root(x) == root(y);
	}
	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}
	int size(int x) {
		return -par[root(x)];
	}
};
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    UnionFind UF(N);
    rep(i, M) {
        int A, B;
        cin >> A >> B;
        A--; B--;
        UF.merge(A, B);
    }
    int ans = 0;
    rep(i, N) {
        ans = max(ans, UF.size(i));
    }
    cout << ans << endl;

    return 0;
}


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

int dp[2][2010], a[2010];
int N, Z, W;
const int INF = 1000000000;

int rec(int i, int j) {
  if (dp[i][j] != -1) {
    return dp[i][j];
  }

  int ret;
  if (i == 0) {
    ret = -2 * INF;
    for (int k = j + 1; k <= N; k++) {
      ret = max(ret, rec(1, k));
    }
    ret = max(ret, abs(a[N] - a[j - 1]));
  } else if (i == 1) {
    ret = 2 * INF;
    for (int k = j + 1; k <= N; k++) {
      ret = min(ret, rec(0, k));
    }
    ret = min(ret, abs(a[N] - a[j - 1]));
  }
  dp[i][j] = ret;
  return ret;
}

int main() {
  cin >> N >> Z >> W;
  a[0] = W;
  for (int i = 0; i < N; i++) cin >> a[i + 1];
  memset(dp, -1, sizeof(dp));
  cout << rec(0, 1) << endl;
}


Measured memory_bytes: 3720
#include<bits/stdc++.h>
#define MAXN 3005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
int n,m;
int dp[MAXN][MAXN];
int pow_mod(int a,int i,int m)
{
    if(i==0) return 1;
    int s=1;
    while(i>0)
     {
         if(i&1) s=(1LL*s*a)%m;
         a=(1LL*a*a)%m;
         i>>=1;
     }
     return s;
}
int fact[MAXN],invf[MAXN],p2[MAXN*MAXN];
int cnk(int i,int j)
{
	return 1LL*fact[i]*invf[j]%m*invf[i-j]%m;
}
int main()
{
	scanf("%d%d",&n,&m);
	fact[0]=1;invf[0]=1;p2[0]=1;
	for(int i=1;i<=n;i++)
	{
		fact[i]=1LL*fact[i-1]*i%m;
		invf[i]=pow_mod(fact[i],m-2,m);
	}
	for(int i=1;i<=n*n;i++) p2[i]=1LL*p2[i-1]*2%m;
	int ans=0;
	memset(dp,0,sizeof(dp));
	dp[0][0]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=i;j++)
			dp[i][j]=(1LL*j*dp[i-1][j]+dp[i-1][j-1])%m;
	}
	int sum=0;
	for(int i=0;i<=n;i++)
	{
		sum=0;
		for(int j=0;j<=i;j++)
			sum=(sum+(1LL*dp[i][j]+1LL*dp[i][j+1]*(j+1))%m*p2[(n-i)*j]%m*pow_mod(2,pow_mod(2,n-i,m-1),m))%m;
		if(i&1) ans=(ans+m-1LL*cnk(n,i)*sum%m)%m;
		else ans=(ans+1LL*cnk(n,i)*sum)%m;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
int city[50];
int main() {
  int N,M,num;
  cin >> N>>M;
  
  for(int i=0; i<M*2; i++){
    cin>>num;
    city[num]++;
  }
  
  for(int i=1; i<=N; i++){
   cout << city[i] << endl;
  }
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n, q = map(int, input().split())

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

memo = [0] * n

for i in range(q):
    p, x = map(int, input().split())
    p -= 1
    memo[p] += x

def dfs(v, par):
    for nv in g[v]:
        if nv == par:
            continue
        memo[nv] += memo[v]
        dfs(nv, v)

dfs(0, -1)

print(*memo)


Measured memory_bytes: 230960
n=int(raw_input())
up=list(map(int,raw_input().split()))
dw=list(map(int,raw_input().split()))
ans=[]
for i in range(n-1):
	ans.append(sum(up[:i+1])+sum(dw[i:]))
ans.append(sum(up)+dw[-1])
print max(ans)


Measured memory_bytes: 2568
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int c = sc.nextInt();
			int n = sc.nextInt();
			int m = sc.nextInt();
			int s = sc.nextInt()-1;
			int d = sc.nextInt()-1;
			if(c==0 && n==0 && m==0 && s==-1 && d==-1) break;
			
			int[][] f = new int[n][n];
			for(int i=0;i<n;i++) Arrays.fill(f[i], Integer.MAX_VALUE);
			for(int i=0;i<m;i++){
				int a = sc.nextInt()-1;
				int b = sc.nextInt()-1;
				f[a][b] = sc.nextInt();
				f[b][a] = f[a][b];
			}
			
			int[][] dp = new int[c+1][n]; //ticket & city
			for(int i=0;i<=c;i++) Arrays.fill(dp[i], Integer.MAX_VALUE);

			ArrayDeque<Integer> q = new ArrayDeque<Integer>(); //ticket
			ArrayDeque<Integer> p = new ArrayDeque<Integer>(); //city
			q.offer(c);
			p.offer(s);
			dp[c][s] = 0;
			while(q.size()!=0){
				int x = q.poll();
				int y = p.poll();
				for(int i=0;i<n;i++){
					if(f[y][i]==Integer.MAX_VALUE) continue;
					if(x>0 && dp[x-1][i] > dp[x][y]+f[y][i]/2){
						dp[x-1][i] = dp[x][y]+f[y][i]/2;
						q.offer(x-1);
						p.offer(i);
					}
					if(dp[x][i] > dp[x][y]+f[y][i]){
						dp[x][i] = dp[x][y]+f[y][i];
						q.offer(x);
						p.offer(i);
					}
				}
			}
			
			int ans = Integer.MAX_VALUE;
			for(int i=0;i<=c;i++) ans = Math.min(ans, dp[i][d]);
			System.out.println(ans);
		}
	}	
}

Measured memory_bytes: 52088
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main(){
  ll N, M; cin >> N >> M;
  vector<vector<ll>> A(N, vector<ll>(M));
  REP(i,N) REP(j,M){
    cin >> A[i][j];
    A[i][j]--;
  }
  vector<ll> p(N,0);
  vector<bool> use(M,true);
  ll ans = N;
  
  REP(j,M-1){
    vector<ll> cnt(M,0);
    REP(i,N){
      while(!use[A[i][p[i]]]) p[i]++;
      cnt[A[i][p[i]]]++;
    }
    ll tmp = 0, idx = -1;
    REP(i,M){
      if(tmp < cnt[i]){
        tmp = cnt[i];
        idx = i;
      }
    }
    ans = min(ans,tmp);
    use[idx] = false;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }

    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int L = scan.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = scan.nextInt();
        }
        boolean found = false;
        int left = 0;
        for (int i = 0; i < N-1; i++) {
            if (L <= a[i] + a[i + 1]) {
                found = true;
                left = i;
                break;
            }
        }
        if (!found) {
            System.out.println("Impossible");
            return;
        }
        System.out.println("Possible");
        for (int i = 0; i < left; i++) {
            System.out.println(i + 1);
        }
        for (int i = N-1; left < i; i--) {
            System.out.println(i);
        }
    }

}

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

long P = 10^^9+7;
long[10^^5+50] F, RF;

long pow(long x, long n) {
    long y = 1;
    while (n) {
        if (n%2 == 1) y = (y * x) % P;
        x = x^^2 % P;
        n /= 2;
    }
    return y;
}

long inv(long x)
{
    return pow(x, P-2);
}

void init()
{
    F[0] = F[1] = 1;
    foreach (i, ref x; F[2..$]) x = (F[i+1] * (i+2)) % P;

    {
        RF[$-1] = 1;
        auto x = F[$-1];
        auto k = P-2;
        while (k) {
            if (k%2 == 1) RF[$-1] = (RF[$-1] * x) % P;
            x = x^^2 % P;
            k /= 2;
        }
    }
    foreach_reverse(i, ref x; RF[0..$-1]) x = (RF[i+1] * (i+1)) % P;
}

long comb(N)(N n, N k)
{
    if (k > n) return 0;
    auto n_b = F[n];    // n!
    auto nk_b = RF[n-k]; // 1 / (n-k)!
    auto k_b = RF[k];    // 1 / k!

    auto nk_b_k_b = (nk_b * k_b) % P; // 1 / (n-k)!k!

    return (n_b * nk_b_k_b) % P;  // n! / (n-k)!k!
}

void main()
{
    init();
    auto N = readln.chomp.to!long;
    auto ii = new long[](N+1);
    ii[] = -1;
    long l, r;
    foreach (i, a; readln.split.to!(long[])) {
        if (ii[a] == -1) {
            ii[a] = i;
        } else {
            l = ii[a];
            r = i;
        }
    }
    foreach (k; 1..N+2) {
        long c;
        (c += comb(N-1, k)) %= P;
        if (k == 1) {
            writeln(c+1);
            continue;
        }
        (c += comb(N-1, k-2)) %= P;
        (c += comb(l + N-r, k-1)) %= P;
        long d = comb(N-1, k-1);
        (d += P - comb(l + N-r, k-1)) %= P;
        (d *= 2) %= P;
        (c += d) %= P;
        writeln(c);
    }
}

Measured memory_bytes: 8088
n=gets.to_i
s=gets.split.map &:to_i
(n-1).times{
a=gets.split.map &:to_i
s=[a[0]+[s[1],s[2]].max,a[1]+[s[0],s[2]].max,a[2]+[s[0],s[1]].max]
}
p s.max

Measured memory_bytes: 1788
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <tuple>
#include <queue>
#include <set>
#include <cstdio>
#include <climits>
#include <cmath>
#include <array>
#include <functional>
#include <list>
#include <iomanip>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const double eps=1e-9;
const int inf=1e9;
typedef pair<int,int> P;
int n,l,r;
int main(void)
{
  while(cin >> n >> l >> r && n)
    {
      vi A;
      for(int i=0;i<n;i++)
	{
	  int a;
	  cin >> a;
	  A.push_back(a);
	}
      int ans=0;
      for(int j=l;j<=r;j++)
	{
	  bool ca=false;
	  for(int i=0;i<n;i++)
	    {
	      if(j%A[i]==0)
		{
		  ca=true;
		  if((i+1)%2!=0) 
		    {
		      ans++;
		    }
		  break;
		}
	    }
	  if(ca) continue;
	  else
	    {
	      if(n%2==0) ans++;
	    }	    
	}
      cout << ans << endl;
    }
  return 0;
}



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

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
typedef vector<int>vint;
typedef pair<int,int>pint;

int get(int n){
    int ret=114514;
    rep(i,n){
        int a;cin>>a;
        ret=min(ret,a);
    }
    return ret;
}


int main(){
    int x=get(3);
    int y=get(2);
    cout<<x+y-50<<endl;
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>

using namespace std;

int main()
{

   int n,b=0,c=0,d=0,e;
   cin>>n;
  string a[n];

   for(int i=0;i<n;i++){

    cin>>a[i];

   }
    for(int i=0;i<n;i++){

        if(a[i]=="AC")
            b++;

}
     for(int i=0;i<n;i++){

        if(a[i]=="WA")
            c++;
     }


for(int i=0;i<n;i++){

        if(a[i]=="TLE")
            d++;
     }

    e=n-b-c-d;


    cout<<"AC"<<" "<<"x"<<" "<<b<<endl;
    cout<<"WA"<<" "<<"x"<<" "<<c<<endl;
    cout<<"TLE"<<" "<<"x"<<" "<<d<<endl;
    cout<<"RE"<<" "<<"x"<<" "<<e<<endl;


}

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

#define Komachi is retarded
#define REP(i,a,b) for(int i=(a),i##_end_=(b);i<i##_end_;i++)
#define M 200004

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0;}
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0;}
 
template<class T>void Rd(T &res){
    char c;res=0;
    while((c=getchar())<48);
    do res=(res<<3)+(res<<1)+(c^48);
    while((c=getchar())>47);
}
 
template<class T>void pf(T res){
    if(res<0)putchar('-'),res=-res;
    else if(!res){putchar('0');return ;}
    static int stk[24],tp;
    for(tp=0;res;res/=10)stk[tp++]=res%10;
    while(tp)putchar(stk[--tp]^48);
}
int n,m,A[M],N[M],Cnt[M],Ans;
int main(){
	Rd(n);Rd(m);
	Ans=n;
	REP(i,0,n){
		Rd(A[i]),N[A[i]]++;
		int p=A[i]-N[A[i]]+1;
		if(p>0){
			Ans-=!Cnt[p];
			Cnt[p]++;
		}
	}
	while(m--){
		int x,y;
		Rd(x);Rd(y);x--;
		int p=A[x]-N[A[x]]+1;
		if(p>0){
			Ans+=Cnt[p]==1;
			Cnt[p]--;
		}
		N[A[x]]--;
		A[x]=y;
		N[A[x]]++;
		p=A[x]-N[A[x]]+1;
		if(p>0){
			Ans-=!Cnt[p];
			Cnt[p]++;
		}
		printf("%d\n",Ans);
	}
	return 0;
}

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

int main(){
  vector<int> A(3); cin >> A[0] >> A[1] >> A[2];
  sort(A.begin(), A.end());

  int ans = 0;
  if(A[0] % 2 != A[1] % 2){
    A[0]++; A[2]++; 
    ans++;
  }

  int k = min(A[2]-A[0], A[2]-A[1]);
  ans += k; A[0] += k; A[1] += k;

  ans += (A[2]-min(A[0], A[1]))/2;

  cout << ans << endl;
}


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

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  long long N, M;
  cin >> N >> M;
  vector<pair<long long, long long>> store(N);
  for(long long i = 0; i < N; i++) {
    cin >> store[i].first >> store[i].second;
  }

  sort(store.begin(), store.end());

  long long ans = 0, cnt = 0;
  for(long long i = 0; i < N; i++) {
    if(M - cnt <= store[i].second) {
      ans += store[i].first * (M - cnt);
      cnt += M - cnt;
    }
    else {
      ans += store[i].first * store[i].second;
      cnt += store[i].second;
    }
    // cout << ans << ": " << cnt << endl;
    if(cnt == M) {
      break;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4740
#include <iostream>
#include <complex>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cassert>
#include <cstdio>
using namespace std;

int d[6][8][2] = {
  1,0,1,3,2,0,2,3,4,0,4,3,3,0,3,3,
  0,2,0,1,3,3,3,2,5,0,5,3,2,1,2,0,
  0,3,0,2,1,3,1,2,5,3,5,2,4,1,4,0,
  1,2,1,1,3,2,3,1,4,2,4,1,2,2,2,1,
  0,0,0,3,2,3,2,2,5,2,5,1,3,1,3,0,
  0,1,0,0,4,3,4,2,5,1,5,0,1,1,1,0
};

struct Cube {
  Cube() {
    string s = "rybgwo";
    for (int i=0;i<6; ++i)
      for (int j=0; j<4; ++j)
        a[i][j] = s[i];
  }
  char a[6][4];
  void rotate(char c) {
    int id = string("UFRDBL").find(c);
    for (int i=0; i<6; ++i) {
      int j1 = d[id][i][0];
      int k1 = d[id][i][1];
      int j2 = d[id][(i+2)%8][0];
      int k2 = d[id][(i+2)%8][1];
      // printf("%d,%d  -  %d,%d\n",j1,k1,j2,k2);
      swap(a[j1][k1], a[j2][k2]);
    }
    int id2 = string("UFRLBD").find(c);
    for (int i=0; i<3; ++i) {
      swap(a[id2][i],a[id2][(i+1)%4]);
    }
  }
  void print() {
    printf("..%c%c....\n",a[0][0],a[0][3]);
    printf("..%c%c....\n",a[0][1],a[0][2]);    
    printf("%c%c%c%c%c%c%c%c\n",a[3][0],a[3][3],a[1][0],a[1][3],a[2][0],a[2][3],a[4][0],a[4][3]);
    printf("%c%c%c%c%c%c%c%c\n",a[3][1],a[3][2],a[1][1],a[1][2],a[2][1],a[2][2],a[4][1],a[4][2]);
    printf("..%c%c....\n",a[5][0],a[5][3]);
    printf("..%c%c....\n",a[5][1],a[5][2]);
  }
};

int main() {
  string s;
  while(cin >> s) {
    Cube cube;
    for (int i=0;i<s.size(); ++i) {
      cube.rotate(s[i]);
    }
    cube.print();  
  }
}

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

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

    for(auto a:mp){
        if(a.second % 2 == 1) ans++;
    }
    
    put(ans);
}

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

int r, c;
bool senbei[10][10000];
bool status[10];
int ans = 0;

int counter()
{
  int ret = 0;
  for(int i = 0; i < c; i++){
    int b = 0, w = 0;
    for(int j = 0; j < r; j++){
      if(senbei[j][i] ^ status[j])
	w++;
      else
	b++;
    }
    ret += max(b, w);
  }
  
  return ret;
}

int search(int t = 0)
{
  if(t == r)
    return counter();

  int ret = 0;
  status[t] = false;
  ret = search(t + 1);
  status[t] = true;
  ret = max(ret, search(t + 1));
  return ret;
}

int main()
{
  while(cin >> r >> c && (r || c)){
    ans = 0;
    for(int i = 0; i < r; i++)
      for(int j = 0; j < c; j++)
	cin >> senbei[i][j];

    cout << search() << endl;
  }
  return 0;
}

Measured memory_bytes: 1252
class UnionFind():
    # 初めは全ての頂点が別々の木の根
    def __init__(self, n):  # n要素で初期化
        self.parent = list(range(n)) # 親
        self.rank = [0] * n   # 木の深さ

    def root_of(self, x):
        children = [x]
        while self.parent[x] != x:
            x = self.parent[x]
            children.append(x)

        for ch in children:
            self.parent[ch] = x
        return x

    # xとyの属する集合を併合
    def union(self, x, y):
        rx = self.root_of(x)
        ry = self.root_of(y)
        if rx == ry:
            return
        if self.rank[rx] < self.rank[ry]: # ランクの小さい木から大きい木の根に辺を張る
            self.parent[rx] = ry  # rxをryの子とする
        else:
            self.parent[ry] = rx
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

    # 同じ集合に属するかどうか
    def same(self, x, y):
        return self.root_of(x) == self.root_of(y)


N = int(input())
X = [None] * N
Y = [None] * N
for i in range(N):
    x, y = [int(x) for x in input().split()]
    X[i] = (x, i)
    Y[i] = (y, i)

X.sort()
Y.sort()
E = []
xp = X[0][0]
ip = X[0][1]
for (x, i) in X:
    E.append((x - xp, (ip, i)))
    xp = x
    ip = i

yp = Y[0][0]
ip = Y[0][1]
for (y, i) in Y:
    E.append((y - yp, (ip, i)))
    yp = y
    ip = i

E.sort()
uf = UnionFind(N)
cost = 0
for c, (e1, e2) in E:
    if uf.same(e1, e2): continue
    cost += c
    uf.union(e1, e2)

print(cost)

Measured memory_bytes: 70900
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

int main()
{
    ll n, t[1100], a[1100], tr, ar;
    cin >> n;
    REP(i, n)
    {
        cin >> t[i] >> a[i];
        if (i == 0)
            continue;

        ll r = max((t[i - 1] + t[i] - 1) / t[i], (a[i - 1] + a[i] - 1) / a[i]);
        t[i] *= r;
        a[i] *= r;
    }

    cout << t[n - 1] + a[n - 1] << endl;

    return 0;
}

Measured memory_bytes: 256