akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;

int main(){
  ll N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];

  rep(i, N){
    if(A[i] % 2 == 0){
      if((A[i] % 3 != 0) && (A[i] % 5 != 0)){
	cout << "DENIED\n";
	return 0;
      }
    }
  }

  cout << "APPROVED\n";
  
  return 0;
}


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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int cnt[200000];

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	int n;
	cin >> n;

	vector<int> a;
	for(int i=0; i<n; i++){
		int t;
		cin >> t;
		a.push_back(t);
		cnt[t]++;
	}

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

	ll ans = 0;
	for(int i=0; i<=100000; i++){
		if(cnt[i] > 1){
			ans += cnt[i] - 1;
		}
	}

	if(ans % 2 == 1) ans++;
	cout << n - ans << endl;
	
	return 0;
}


Measured memory_bytes: 1276
import collections,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,Q = LI()
ab = [LI() for _ in range(N-1)]
px = [LI() for _ in range(Q)]
ans = [0]*(N+1) #1_index
graph = [collections.deque() for _ in range(N+1)] #1_index
for a,b in ab:
        graph[a].append(b)
        graph[b].append(a)
for p,x in px:
    ans[p] += x
seen = [0]*(N+1) #1_index
stack = []
def dfs():
    seen[1] = 1
    stack.append(1)
    while stack:
        s = stack.pop()
        if not graph[s]:
            continue
        for j in range(len(graph[s])):
            g_NO = graph[s].popleft()
            if seen[g_NO]:
                continue
            seen[g_NO] = 1
            stack.append(g_NO)
            ans[g_NO] += ans[s]
dfs()
print(*ans[1:])


Measured memory_bytes: 241964
//
// Created by 佐竹俊哉 on 2019/11/12.
//

#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os<<"("<<p.first<<","<<p.second<<")";
    return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os<<"{";
    rep(i, v.size()) {
        if (i) os<<",";
        os<<v[i];
    }
    os<<"}";
    return os;
}

int main() {
    int N; cin >> N;
    V<pii> vec(N);
    rep(i, N) {
        int x; cin >> x;
        vec[i] = mp(x, i+1);
    }
    sort(ALL(vec));
    rep(i, N) printf("%d%c", vec[i].se, i == N-1 ? '\n' : ' ');
    return 0;
}

Measured memory_bytes: 1536
from sys import stdin

def solve(a, k):
    count = 0
    for i in range(5):
        for j in range(5):
            if i == j:
                continue
            elif abs(a[i]-a[j]) > k:
                return ":("
    return "Yay!"


if __name__ == '__main__':
    antena = [int(input()) for i in range(5)]
    k = int(input())
    print(solve(antena, k))


Measured memory_bytes: 2940
#include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>
#include <map>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <stack>
#include <queue>
#include <cstring>
#include <iterator>

#define FOR(n) for(int i=0;i<(n);++i)
#define FOR_R(it,cont) for(auto it=rbegin(cont);it!=rend(cont);++it)
#define FOR_F(it,cont) for(auto it=begin(cont);it!=end(cont);++it)
#define ALL(cont) begin(cont), end(cont)
#define LB(b,e,v) lower_bound(b,e,v)
#define UB(b,e,v) upper_bound(b,e,v)
#define AS_MOD(a,b) ((((a) % (b) ) + (b)) % (b))

using namespace std;
typedef pair<int,int> P;
typedef pair<int, P> iP;
typedef long long ll;
int N;
int A[300][300];
vector<iP> Ps;
int main() {
  scanf("%d", &N);
  for(int i=0;i<N;++i) {
    for(int j=0;j<N;++j) {
      scanf("%d", &A[i][j]);
      if (i<j) {
        Ps.push_back(iP(A[i][j],P(i,j)));
      }
    }
  }
  for(int i=0;i<N;++i) {
    for(int j=0;j<N;++j) {
      for(int k=0;k<N;++k) {
        if (A[i][j] > A[i][k] + A[k][j]) {
          printf("-1\n");
          return 0;
        }
      }
    }
  }
  long long answer = 0;
  FOR_F(it, Ps) {
    iP ip1 = *it;
    P p1=ip1.second;
    bool ok=false;
    for(int k=0;k<N;++k) {
      if (k!=p1.first && k!=p1.second && ip1.first == A[p1.first][k] + A[k][p1.second]) {
        ok=true;
      }
    }
    if(!ok)answer += ip1.first;
  }

  printf("%lld\n", answer);
  return 0;
}



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

int main() {
    int N, K;
    cin >> N >> K;
    int ans = (N - 2) / (K - 1) + 1;
    cout << ans << endl;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
//void chmin(int &a, int b) { if (a > b) a = b; }
//void chmax(int &a, int b) { if (a < b) a = b; }

const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

//重みある時
using Edge = pair<int,int>;
using Graph = vector<vector<Edge> >;

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = 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); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};

int main() {
    int n,m;
    cin >> n >> m;
    vector<int> p(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }
    UnionFind uf(n);
    for (int i = 0; i < m; ++i) {
        int x,y;
        cin >> x >> y;
        uf.merge(x-1,y-1);
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if(uf.issame(i,p[i]-1)) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<deque>
#include<string>
#define dint __int128
using namespace std;
#define kk putchar(32)
#define gc getchar()
#define fup(i,a,b) for(int i=a,i##e=b;i<=i##e;++i)
#define fdn(i,a,b) for(int i=a,i##e=b;i>=i##e;--i)
#define mem(a,b) memset(a,b,sizeof(a))
#define hh putchar(10)
#define ll long long
inline ll rrr(){ll x,f=1;char a;while((a=gc)<48||a>57)if(a==45)f=-1;
for(x=a^48;(a=gc)>47&&a<58;x=(x<<3)+(x<<1)+(a^48));return f*x;}
void Main();int main(){Main();return 0;}
int a[100005];
void Main()
{
    int n;cin>>n;
    fup(i,1,n)a[i]=rrr();
    int ans=0;
    fup(i,1,n){
        if(a[i]==i)
        {
//            cout<<i<<' '<<a[i];hh;fup(x,1,n)cout<<a[x]<<' ';hh;
            if(a[i+1]!=i+1)swap(a[i],a[i+1]),++ans,++i;
            else swap(a[i],a[i+1]),++ans,++i;
        }
    }
    cout<<ans;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion
#pragma region chminmax
template <typename T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

int main()
{
    // 出発点に戻らなきゃいけない！
    // 気づかず時間を溶かした

    int INF = 1 << 25;

    int v, e;
    cin >> v >> e;
    vector<vector<int>> g(v, vector<int>(v, INF));
    rep(i, e)
    {
        int f, t, c;
        cin >> f >> t >> c;
        g[f][t] = c;
    }
    vector<vector<int>> dp(1LL << v, vector<int>(v, INF));
    // dp[0][0] = 0;
    dp[1][0] = 0;

    rep(i, 1LL << v)
    {
        rep(j, v)
        {
            // Is node j contained in current set i?
            bool in = (i & (1LL << j)) != 0LL;

            if (!in)
                continue;

            // generate set without j
            ll prev = i ^ (1LL << j);

            rep(f, v)
            {
                // is f in prev?
                bool inPrev = ((1LL << f) & prev) != 0LL;

                if (!inPrev)
                    continue;

                if (g[f][j] == -1)
                    continue;

                chmin(dp[i][j], dp[prev][f] + g[f][j]);
            }
        }
    }

    int ans = INF;
    rep(i, v)
    {
        chmin(ans, dp[(1LL << v) - 1][i] + g[i][0]);
    }

    if (ans == INF)
        ans = -1;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6340
#include <iostream>

using namespace std;

int sum_of_digits(int i){
    string s = to_string(i);
    int v=0;
    for (i=0;i<s.size();i++){
        v+=atoi(&s[i]);
    }
    return v;
}

int sum_of_digits2(int i){
    int sum = 0;
    while (i>0){
        sum += i%10;
        i/=10;
    }
    return sum;
}

int main(void){
    int n,a,b;
    int sum = 0;

    cin >> n >> a >> b;

    for (int i=1;i<=n;i++){
        int v = sum_of_digits2(i);
        if ((v>=a)&&(v<=b)) sum+=i;
    }
    cout << sum;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define AfterDecimal(n) cout << fixed << setprecision(n);
#define pb push_back
#define pp(a, b) pair <a, b>
#define ll long long int
#define ld long double
#define all(a) a.begin(), a.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
#define itr iterator
#define bits(x) __builtin_popcount(x)
#define fori(n)  for (ll i = 0; i < n; i++)
#define forj(n)  for (ll j = 0; j < n; j++)
#define fork(n)  for (ll k = 0; k < n; k++)
#define vll vector <ll>
#define mll map <ll, ll>
#define vpll vector <pll>
 
 
using namespace __gnu_pbds;
using namespace std;
 
template <class T> T printr(T p){ cout << p << '\n'; return 0; }
template <class T> T printe(T p){ cout << p << '\n'; exit(0); }
template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
 
 
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
#ifdef LOCAL
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << "# "<< name << " = " << arg1 << '\n';
}
template<typename Arg1, typename... Args>
void __f(const char* names, Arg1 && arg1, Args &&... args){
        const char* comma = strchr(names + 1 ,',');
        cout << "# ";
        cout.write(names, comma - names)<< " = " << arg1 << " | ";
        __f(comma + 1, args...);
}
#else
#define debug(...) 36
#endif
 
ll power(ll x, ll y, ll p){ 
   ll res = 1;
   x = x % p;  
   while (y > 0) {
      if (y & 1) 
         res = (res * x) % p; 
      y = y >> 1;
      x = (x * x) % p; 
   }
   return res;
}
 
const ll INF = (ll)(8e18);
const ll MOD = 1e9 + 7;
 
const int maxn = 100010;

int color[maxn];
vector <pii> g[maxn];

void dfs(int v, int par, int paredge){
    int k = 1;
    for(int i = 0; i < (int)g[v].size(); i++){
        if(g[v][i].first == par) continue;
        if(k == color[paredge]) k += 1;
        color[g[v][i].second] = k;
        k += 1;
    }
    for(auto i : g[v]){
        if(i.first != par){
            dfs(i.first, v, i.second);
        }
    }
}

int32_t main(){
    IOS;
    #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    int n; cin >> n;
    for(int i = 1; i < n; i++){
        int u,v; cin >> u >> v;
        g[u].push_back({v, i});
        g[v].push_back({u, i});
    }
    int ans = 0;
    for(int i = 1; i <= n; i++){
       uax(ans, (int)g[i].size());
    }
    cout << ans << '\n';
    for(int i = 1; i <= n; i++){
        if((int)g[i].size() == ans){
            dfs(i, 0, 0);
            break;
        }
    }
    for(int i = 1; i < n; i++) cout << color[i] << '\n';
    #ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
}


Measured memory_bytes: 7552
a, b, c, d = map(int, input().split())
on_btn = [0]*(101)

for i in range(a, b):
  on_btn[i] += 1
for i in range(c, d):
  on_btn[i] += 1  

ans = 0
for i in on_btn:
  if i == 2:
    ans += 1
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>

int main(void)
{
        int a,b,c,d;
        int diff, up,low;
        scanf("%d%d%d%d",&a,&b,&c,&d);

        if(a>c){
                low = a;
        }else{
                low = c;
        }

        if(b<d){
                up = b;
        }else{
                up = d;
        }

        if(b<c){
                up=0;
        }

        diff=up-low;
        if(diff<0){
                diff=0;
        }

        printf("%d",diff);
        return 0;
}

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

int N;
int sum = 0,mem = 10e3;

int main()
{
    scanf("%d",&N);
    for(int i = 0; i < N; i++)
    {
        int s;
        scanf("%d",&s);
        sum += s;
        if(s % 10)
        {
            mem = min(mem,s);
        }
    }
    if(sum % 10)
    {
        printf("%d\n",sum);
        return 0;
    }
    if(mem == 10e3)
    {
        printf("0\n");
        return 0;
    }
    printf("%d\n",sum - mem);
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace D
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        static int R;
        static int[] r;
        static bool[] checker = new bool[8];
        static int[][] path;
        static int limit = (int)1e9;
        static int answer;

        public static void Solve()
        {
            var NMR = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var N = NMR[0];
            var M = NMR[1];
            R = NMR[2];
            r = Console.ReadLine().Trim().Split(' ').Select(x => int.Parse(x) - 1).ToArray();
            path = (new int[N][]).Select(x => x = Enumerable.Repeat(limit, N).ToArray()).ToArray();
            for (var i = 0; i < N; i++)
            {
                path[i][i] = 0;
            }
            for (var i = 0; i < M; i++)
            {
                var ABC = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
                var A = ABC[0] - 1;
                var B = ABC[1] - 1;
                var C = ABC[2];
                path[A][B] = path[B][A] = Math.Min(path[A][B], C);
            }

            for (var k = 0; k < N; k++)
            {
                for (var i = 0; i < N; i++)
                {
                    for (var j = 0; j < N; j++)
                    {
                        path[i][j] = Math.Min(path[i][j], path[i][k] + path[k][j]);
                    }
                }
            }

            answer = limit;
            Dfs();
            Console.WriteLine(answer);
        }

        public static void Dfs(int step = 0, int current = -1, int sum = 0)
        {
            if (step == R)
            {
                answer = Math.Min(answer, sum);
                return;
            }
            for (var next = 0; next < R; next++)
            {
                if (checker[next]) continue;
                checker[next] = true;
                if (current == -1) Dfs(step + 1, next);
                else Dfs(step + 1, next, sum + path[r[current]][r[next]]);
                checker[next] = false;
            }
        }
    }
}


Measured memory_bytes: 34972
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Main {

	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int count = 0;
			int n = in.nextInt();
			int[] a = in.nextIntArray(n);
			int q = in.nextInt();
			int[] b = in.nextIntArray(q);

			for (int i : b) {
				if (ArrayUtils.binarySearch(a, i) >= 0) count++;
			}
			out.println(count);
		}

	}

	static class ArrayUtils {
		public static Map<Integer, Integer> getCountMap(int[] array) {
			Map<Integer, Integer> map = new TreeMap<>();
			for (int x : array)
				map.merge(x, 1, Integer::sum);
			return map;
		}

		public static int binarySearch(int[] a, int obj) {
			int l = 0;
			int r = a.length - 1;

			while (l <= r) {
				int c = (l + r) / 2;
				if (obj == a[c]) {
					return c;
				} else if (obj < a[c]) {
					r = c - 1;
				} else if (obj > a[c]) {
					l = c + 1;
				}
			}
			return -1;
		}

	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

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

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

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

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}
}



Measured memory_bytes: 49484
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
using namespace std;

#define fi first
#define se second
typedef long long LL;
typedef long double LD;

int N,a[100010],l[100010];
vector<int> g[100010];

void dfs(int nod, int f){
    for (int nxt : g[nod])
        if (nxt!=f){
            dfs(nxt,nod);
            l[nod]^=(l[nxt]+1);
        }
}

int main(){
    cin >> N;

    int x,y,i;
    for (i=1; i<N; i++){
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    dfs(1,0);
    cout << (l[1] ? "Alice" : "Bob") << "\n";

    return 0;
}


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

#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int A,B,C,D; cin >> A>>B>>C>>D;
    
    cout << max(A*B,C*D) << endl;
}


Measured memory_bytes: 256
//#include <boost/multiprecision/cpp_dec_float.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
using namespace std;
//namespace mp = boost::multiprecision;
//using llll = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
//using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main(){
  ll n,x;
  cin>>n>>x;
  vector<ll>v(n+1,0);
  ll ans=0;
  for(ll i=0;i<n;i++){
    cin>>v[i+1];
    v[i+1]+=v[i];
  }
  for(ll i=0;i<n+1;i++){
    if(v[i]<=x)ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 888
#include <iostream>
#include <string>
using namespace std;
#define MAX 200000
string str;

int main(void){
    int N, cnt;
    cnt = 0;
    
    cin >> N;
    cin >> str;
    
    int i = 0;
    int j = N - 1;
    while(i < j){
        while(str[i] == 'R') i++;
        while(str[j] == 'W') j--;
        
        if(str[i] == 'W' && str[j] == 'R' && i < j) cnt++;
        i++;
        j--;
    }
    
    cout << cnt << endl;
    
    return 0;
}


Measured memory_bytes: 3760
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

int main(){
    int n, y;
    cin >> n >> y;
    bool exist=false;
    for(int i=0; i<=n; i++){
        for(int j=0; i+j<=n; j++){
            int k=n-(i+j);
                if(10000*i+5000*j+1000*k==y && i+j+k==n){
                    cout << i << " " << j << " " << k << endl;
                    exist = true;
                    goto loop_end;
                }
        }
    }
    loop_end:
    if(!exist) cout << -1 << " " << -1 << " " << -1  << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    int arr[n+1];
    for(int i=1; i<=n; i++){
        cin>>arr[i];
    }
//    for(int i=1; i<=n; i++){
//        if(arr[i]<mx){
//            pos=i;
//            mx=arr[i];
//        }
//    }
    int ans=0;
    while(n>0){
        n-=k;
        ans++;
        if(n==0)break;
        else n++;

    }
    cout<<ans<<endl;

}





Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        String S = sc.next();

        int x = 0;
        int M = 0;
        for(int i = 0; i < N; i++){
            if(S.charAt(i) == 'I'){
                x++;
            }else{
                x--;
            }
            if(x > M) M = x;
        }

        System.out.println(M);
    }
}


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

using namespace std;

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int64_t res = 1LL << 60;
  for (int bit = 0; bit < (1 << N); bit++) {
    int k = 1, ma = A[0];
    int64_t cost = 0;
    for (int i = 1; i < N; i++) {
      int diff = 0;
      if ((bit >> i) & 1) {
        diff = max(0, ma - A[i] + 1);
        cost += diff;
      }
      if (chmax(ma, A[i] + diff)) k++;
    }
    if (k >= K) res = min(res, cost);
  }
  cout << res << '\n';
  return 0;
}


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

void main() {
    auto S = readln.chomp;
    auto N = S.length.to!int;
    auto C = new long[](26);
    foreach (i; 0..N) C[S[i] - 'a'] += 1;

    long ans = N.to!long * (N - 1).to!long / 2;

    foreach (i; 0..26) {
        ans -= C[i] * (C[i] - 1) / 2;
    }

    writeln(ans + 1);
}


Measured memory_bytes: 2684
import sys
from collections import defaultdict

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(IN())
mod=1000000007

#+++++

def main():
	#a = int(input())
	H, W, N = tin()
	#s = input()
	dd=defaultdict(lambda : 0)
	for _ in range(N):
		a, b = tin()
		for da in range(3):
			for db in range(3):
				if a - da <= 0 or b - db <= 0:
					continue
				if a - da > H -2 or b -db > W-2:
					continue
				ii = (a - da)*(W+1)+(b - db)
				dd[ii]+=1
	
	nn = [0]*10
	for k in dd:
		nn[dd[k]]+=1
	nn[0]=((H-2)*(W-2))-sum(nn[1:])
	for v in nn:
		print(v)
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 131828
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int N, K, d,A;
  cin >> N >> K;
  
  bitset<100> sunuke;
	
  for(int i=0; i<K; i++){
  	cin >> d;
    for (int j=0; j<d; j++){
      cin >> A;
      sunuke.set(A-1,1);
    }
  }
  
  cout << N - sunuke.count() <<endl;
}

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

using namespace std;
bool P(int &a, int &b)
{
    return (a<b);
}
int main()
{
    int n;
    cin>>n;
    int niza[n];
    for(int i=0; i<n; i++)
    {
        cin>>niza[i];
    }
    sort(niza,niza+n,P);
    int cnt=0;
    for(int k=0; k<=niza[n-1]; k++)
    {
        int posle=upper_bound(niza,niza+n,k)-niza;
        if(n-posle==n/2)cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 640
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);

		BigDecimal A = sc.nextBigDecimal();
		BigDecimal B = sc.nextBigDecimal();
		BigDecimal B2 = B.multiply(new BigDecimal(100.00));
		BigDecimal ans = A.multiply(B2);
		String str = null;
		if (new BigDecimal(100.00).compareTo(ans) <= 0) {
			str = ans.toString();
			int int1 = str.indexOf(".");
			if (int1 > -1) str = str.substring(0,int1);
			str = str.substring(0, str.length() - 2);
		} else {
			str = "0";
		}
		
		// 出力
		System.out.println(str);
	}
}

// String str1 = sc.next();　// Stringで取得
// int int1 = sc.nextInt();　// intで取得
// BigDecimal bd1 = sc.nextBigDecimal();　// BigDecimalで取得
// byte byte1 = sc.nextByte();　// byteで取得
// 
// 区切り文字　－＞　タブ、スペース、改行

Measured memory_bytes: 37612
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

#define ll long long
#define ull unsigned long long
#define REP(i, n) for(int i=0; i<n; i++)

int C[500];
ull S[500];
int F[500];
int main(){
    int N;
    cin >> N;
    REP(i,N-1){
        cin >> C[i] >> S[i] >> F[i];
    }

    ull path;
    REP(i, N-1){
        path = S[i] + C[i];
        for(int k=i+1; k < N-1; k++){
            if(path < S[k])
                path = S[k];
            else{
                //path += ((path - S[k]) % F[k]);
                //path = S[k] + F[k]*((path-S[k])/F[k]);
                ull num = 0;
                while(S[k] + F[k]*num < path){
                    num++;
                }
                path = S[k] + F[k]*num;
            }
            path += C[k];
        }
        cout << path << endl;
    }
    cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N;
vector<ll> T;
void input(){
    fast_io();
    cin >> N;
    T = fetch_vec<ll>(N);
}

ll __gcd(ll x, ll y){
    if(x==0) return y;
    return __gcd(y%x,x);
}

ll lcm(ll x, ll y){
    return x/__gcd(x,y)*y;
}

int solve(){
    // ll d = 0;
    // for (int i = 0; i < N; i++)
    // {
    //     d = __gcd(d,T[i]);
    // }
    ll ans = 1;
    for (int i = 0; i < N; i++)
    {
        ans = lcm(ans,T[i]);
    }
    cout << ans << endl;
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    if (C == -1 || D == -1) {
        if (A < B) {
            write("Alice");
        }
        else if (A == B) {
            write("Draw");
        }
        else {
            write("Bob");
        }
    }
    else if (C < D) {
        write("Bob");
    }
    else if (C == D) {
        write("Draw");
    }
    else {
        write("Alice");
    }
}


Measured memory_bytes: 3212
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	//	"strings"
)

func main() {
	sc := NewScanner()

	n := sc.NextInt()
	k := sc.NextInt()

	for i := 0; i < n; i++ {
		_ = sc.NextInt()
	}
	if n <= k {
		fmt.Printf("%+v\n", 1) // output for debug
		return
	}
	ans := (n-k)/(k-1) + 1

	if (n-k)%(k-1) != 0 {
		ans++
	}
	fmt.Printf("%v\n", ans)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


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

signed main() {
  int n;
  string s;
  cin>>n>>s;
  int cntR = 0;
  for (int i=0; i<n; i++) if (s[i] == 'R') cntR++;
  int ans = 0;
  for (int i=0; i<cntR; i++) if (s[i] == 'W') ans++;
  cout<<ans;
}

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

using namespace std;

const int MAX = 1e5 + 20;
int n, a[MAX], dp[MAX];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	
	memset(dp, -1, sizeof dp);
	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	dp[1] = 0, dp[2] = abs(a[2] - a[1]);
	for(int i = 3; i <= n; i++) {
		dp[i] = min(dp[i - 1] + abs(a[i - 1] - a[i]), 
		            dp[i - 2] + abs(a[i - 2] - a[i]));
	}
	cout << dp[n] << "\n";

	return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int mod = 1e9+7;
const int maxn = 2e5+5;
ll kpow(ll a,ll b){
	ll ans = 1;
	while(b){
		if(b&1) ans*=a;
		ans%=mod;
		a*=a;
		a%=mod;
		b>>=1;
	}
	return ans;
} 
ll dp[maxn];
int main() {
	ll n,k;
	cin>>n>>k;
	for(int i=1;i<=k;i++){
		dp[i] = kpow(k/i,n); //表示最小公因数为i的排列组合的数量 
	}
	
	for(int i=k;i>=1;i--){
		for(int j=i*2;j<=k;j=j+i){
			dp[i]-=dp[j]; 
			dp[i] = (dp[i]+mod)%mod;
		}
	} 
	ll ans = 0;
	for(int i=k;i>=1;i--){
		ans+=(i*dp[i]);
		ans%=mod;
	}
	cout<<(ans+mod)%mod<<endl;
    return 0;
}



Measured memory_bytes: 4324
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
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; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};


int main(){
    int n;cin >> n;
    string s;cin >> s;
    vector<vector<LL>> cum(n+1,vector<LL> (3,0));
    string u = "RGB";
    map<char,int> key;
    key['R'] = 0;
    key['G'] = 1;
    key['B'] = 2;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            cum[i+1][j] = cum[i][j] + (s[i] == u[j]);
        }
    }
    LL ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i+2; j < n; j++) {
            if(s[i] == s[j]) continue;
            int k = key[s[i]] ^ key[s[j]] ^ 3;
            ans += cum[j][k] - cum[i+1][k];
            if((j - i)%2 == 0){
                int mid = i + (j - i) / 2;
                if(s[mid] == u[k]) ans--;
            }
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3764
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<unordered_set>
#include<queue>
#define MAX 100005

using namespace std;
int  friends[MAX]={0};
int blocks[MAX]={0};
int parents[MAX];
int size[MAX];		//并查集中所有点的大小


int find(int x){
	if(parents[x]==x) return x;
	return parents[x] = find(parents[x]);
}
 
void Unite(int a,int b){
	int pa=find(a);
	int pb=find(b);
	if(pa==pb) return;
	else {
		if(size[pa]<size[pb]) swap(pa,pb);
		
//		printf("root %d : %d",pa,pb); 
		parents[pb]=pa;			//小树接在大树上 
		size[pa]+=size[pb];
	}
}



int main(){
	int n,m,k;
	scanf("%d %d %d",&n,&m,&k);
	for(int i=1;i<=n;i++){
		parents[i]=i;
		size[i]=1;
	}
	
	for(int j=1;j<=m;j++){
		int s,e;
		scanf("%d %d",&s,&e);
		friends[s]+=1;;
		friends[e]+=1;
		Unite(s,e);
	}
	
	for(int i=0;i<k;i++){
		int s,e;
		scanf("%d %d",&s,&e);
		if(find(s)==find(e)){
			blocks[s]+=1;
			blocks[e]+=1;
		}
	}
	
	for(int i=1;i<=n;i++){
		int root =find(i);
		int res = size[root] - friends[i] - blocks[i]-1;
		printf("%d ",res);
	}
	

	return 0;
}

Measured memory_bytes: 2432
N, M = map(int, input().split())

ans = []

for i in range(M):
    if N % 2 != 0 or (M + (i + 1)) - (M - (i)) < N // 2:
        tmp = [str(M - (i)), str(M + (i + 1))]
    else:
        tmp = [str(M - (i)), str(M + (i + 2))]
    tmp = ' '.join(tmp)
    ans.append(tmp)
print(*ans, sep='\n')


Measured memory_bytes: 78608
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP1(i,n) for(int i = 1; i < n+1 ;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()
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;

int main(){
    ll n,a,b;
    cin >> n >> a >> b;
    ll sum = a+b ;
    ll re = n/sum;
    ll ans= re * a;
   // ll amari = min(n-re*sum,a);  
   ll amari;
   if(n-re*sum > a) amari = a;
   else amari = n-sum*re;
    ans+=amari;
    cout << ans << endl;
    return 0;



   


    /*ll n,a,b;
    cin >> n >> a >> b;
    ll sum = a+b ;
    ll re = int(n/sum);
    ll ans= re * a;
    bool flag = true;
    if(n%sum != n-sum*re){
        flag = false;
    }

    cout << flag << endl;
    return 0;*/




}



Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

template<typename T> using minimum_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

using namespace std;

vector<set<uint64_t>> edge;
vector<int64_t> dp;
// dp[i]; ノードiを始点とした有向パスの最大長

int64_t dfs(uint64_t src) {
  if (dp[src] > 0) { return dp[src]; }

  for (uint64_t dst : edge[src]) {
    dp[src] = max(dp[src], dfs(dst) + 1);
  }

  return dp[src];
}

int main()
{
  uint64_t N, M;
  cin >> N >> M;

  edge = vector<set<uint64_t>>(N);
  N_TIMES(m, M) {
    uint64_t x, y;
    cin >> x >> y;

    edge[x - 1].insert(y - 1);
  }

  dp = vector<int64_t>(N, 0);

  int64_t ans = 0;
  N_TIMES(i, N) {
    if (dp[i] == 0) {
      dp[i] = dfs(i);
    }
    ans = max(ans, dp[i]);
  }

  cout << ans << endl;

  return 0;
}

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

int main() {
    int n,count=0,iter=1;
    cin>>n;
    vector<int> a(n);
    rep(i,n) {
        cin>>a[i];
    }
    rep(i,n) {
        if (a[i]==iter) iter++;
    }
    if (iter==1) cout<<-1<<endl;
    else cout<<n-iter+1<<endl;
}

Measured memory_bytes: 1024
#!py2
from fractions import gcd

def solve(initial, burn, check, resupply):
    if burn > initial or burn > resupply:
        return False
    if check >= burn:
        return True

    x = initial % burn
    g = gcd(resupply, burn)
    
    # k largest with x + k*g < burn, then decide if x + k*g <= check
    k = (burn - x) // g
    if k * g + x == burn: k -= 1
    return x + k * g <= check

for _ in xrange(int(raw_input())):
    print "Yes" if solve(*map(int, raw_input().split())) else "No"


Measured memory_bytes: 34664
#include<stdio.h>

int main(){
	int a,b,c,k;
	int i;
	int cnt = 0;
	
	scanf("%d%d%d%d", &a, &b, &c, &k);
	
	for(i = 0;i < a && i < k;i++){
		cnt++;
	}
	k -= a;
	k -= b;
	
	if(k){
		for(i = 0;i < c && i < k;i++){
			cnt--;
		}
	}
	printf("%d", cnt);
	
	return 0;
}

Measured memory_bytes: 1732
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}

void solve(){
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	int ans=0;
	ans=min(k,a);
	k=max(0,k-a);
	//ans+=min(k,b);
	k=max(0,k-b);
	ans-=min(k,c);
	k=max(0,k-c);
	cout<<ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 3612
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
count = 0
for i in range(n-1,-1,-1):
    # i+1の討伐
    if a[i+1] < b[i]:
        count += a[i+1]
        b[i] -= a[i+1]
        a[i+1] = 0
    else:
        count += b[i]
        a[i+1] -= b[i]
        b[i] = 0
    # iの討伐
    if a[i] < b[i]:
        count += a[i]
        b[i] -= a[i]
        a[i] = 0
    else:
        count += b[i]
        a[i] -= b[i]
        b[i] = 0
print(count)

Measured memory_bytes: 19000
package main

import (
	"fmt"
)

func main() {
	var N, M, X, A int
	fmt.Scan(&N, &M, &X)
	arr := make([]int, N+1)
	for i := 0; i < M; i++ {
		fmt.Scan(&A)
		arr[A]++
	}
	var b, a, r int
	for i := X; i > 0; i-- {
		b += arr[i]
	}
	for i := X; i <= N; i++ {
		a += arr[i]
	}
	if b < a {
		r = b
	} else {
		r = a
	}
	fmt.Println(r)
}


Measured memory_bytes: 512
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 998244353
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    A,B,C,D = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    dp=[[0]*(D+1) for _ in range(C+1)]
    dp[A][B]=1
    for i in range(A,C+1):
        for j in range(B,D+1):
            if i==A and j==B:continue
            #print(i,j)
            dp[i][j]=((dp[i-1][j]*j+dp[i][j-1]*i)-dp[i-1][j-1]*(i-1)*(j-1))%mod
    print(dp[-1][-1])





if __name__ == "__main__":
    main()

Measured memory_bytes: 143640
#include <iostream>
#include <cstdio>
#define N 105
using namespace std;

int n, c, a[N];
int main()
{
	int i;
	cin >> n;
	for (i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		if (a[i] == a[i - 1]) a[i] = 0, c++;
	}
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 384