akhauriyash/Code-Regression huggingface dataset:
s = input()
line = s[::-1]
n = len(s)
mods = [1] + [0] * 2018
i = 1
now = 0
for d in line:
    now += int(d) * i
    now %= 2019
    mods[now] += 1
    i *= 10
    i %= 2019

ans = 0
for mod in mods:
    ans += mod*(mod-1) / 2

print(int(ans))

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

int main()
{
	int64_t x;
	cin >> x;

	vector<int64_t> as;
	for (int64_t i = 0; i <= 5; i++)
	{
		as.emplace_back(100 + i);
	}

	vector<bool> dp(x + 1, false);
	dp[0] = true;

	for (int64_t i = 0; i <= x; i++)
	{
		for (auto &&a : as)
		{
			if (i + a <= x)
			{
				dp[i + a] = dp[i + a] or dp[i];
			}
		}
	}

	cout << dp[x] << endl;

	return 0;
}

Measured memory_bytes: 256
import math

def Eratos(n):
	primes = [2]
	num = [2*i+1 for i in range(1,n//2)]
	tmp = []

	top = 1
	while top < math.sqrt(n):
		top = num[0]
		for i in range(1,len(num)):
			if num[i] % top != 0:
				tmp.append(num[i])
		num = tmp
		tmp = []
		primes.append(top)
	for i in range(len(num)):
		primes.append(num[i])
	return primes

n = int(input())
cont = 0
primes = Eratos(15000)
for i in range(n):
	a = int(input())
	if a<10000:
		if primes.count(a)!=0:
			cont += 1
	else:
		for j in range(len(primes)):
			if a%primes[j]==0:
				break
			else:
				if math.sqrt(a)<primes[j]:
					cont += 1
					break
print(cont)


Measured memory_bytes: 6008
w, h, n = [int(i) for i in input().split()]

left = 0
right = w
upper = h
lower = 0

for i in range(n):
	x, y, a = [int(k) for k in input().split()]
	if a == 1 and left < x:
		left = x
	elif a == 2 and right > x:
		right = x
	elif a == 3 and lower < y:
		lower = y
	elif a == 4 and upper > y:
		upper = y

S = (right-left)*(upper-lower)
if right-left < 0 or upper-lower < 0:
	print(0)
else:
	print(S)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
long long a[2010];
long long m=1e9+7;
int main(){
	long long n,k;
	cin >> n >> k;
	long long aa=(((k+1)*k)/2)%m;
	long long bb=((k*(k-1))/2)%m;
	for(long long i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	long long qian=0,hou=0;
	for(long long i=0;i<n;i++){
		for(long long j=i+1;j<n;j++){
			if(a[i]<a[j]){
				qian++;
				qian=qian%m;
			}
			else if(a[i]>a[j])
				hou++;
				hou=hou%m;
		}
	}
	long long ans=((hou*(aa%m))%m+(qian*(bb%m))%m)%m;
	cout << ans;
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	
	private class Dish implements Comparable<Dish> {
		public long A;
		public long B;
		
		public Dish(long A, long B) {
			this.A = A;
			this.B = B;
		}
		
		@Override
		public int compareTo(Dish o) {
			if (this.A + this.B > o.A + o.B) {
				return 1;
			} else if (this.A + this.B == o.A + o.B) {
				if (this.A > o.A) {
					return 1;
				}
				return 0;
			} else {
				return -1;
			}
		}
		
	}
	
	public long solve() {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();

		Dish[] dish = new Dish[N];
		
		for (int i=0; i<N; i++) {
			long Ai = in.nextLong();
			long Bi = in.nextLong();
			
			dish[i] = new Dish(Ai, Bi);
		}
		in.close();
		
		Arrays.sort(dish);
		
		long score = 0;
		
		for (int i=0; i<N; i++) {
			if (i%2 == 0) {
				score += dish[N-i-1].A;
			} else {
				score -= dish[N-i-1].B;
			}
		}
		
		return score;
	}
	
	public static void main(String[] args) {
		Main main = new Main();
		long result = main.solve();
		
		System.out.println(result);
	}
}


Measured memory_bytes: 93556
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc1 = new Scanner(System.in);

		while(true) {

			int h = sc1.nextInt();
			int w = sc1.nextInt();

			if ( h == 0 && w == 0) {
				break;
			}

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

				for ( int j = 0 ; j < w ; j++) {
					if ( i%2 == 0) {
						if ( j%2 == 0) {
							System.out.print("#");
						}
						else {
							System.out.print(".");
						}
					}
					else {
						if ( j%2 == 0) {
							System.out.print(".");
						}
						else {
							System.out.print("#");
						}
					}
				}

				System.out.println();

			}

			System.out.println();

		}

		sc1.close();

	}
}



Measured memory_bytes: 34192
n = int(input())
a = input()
a = [int(i) for i in a.split(' ')]

out = 0
loop = True

while loop:
  for i in range(0, n):
    if a[i] % 2 == 1:
      loop = False
      break
    a[i] = a[i]/2
  if loop:
    out += 1

print(out)

Measured memory_bytes: 3064
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include<bits/stdc++.h>
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i,a,b) for(register int i=a,bbb=b;i<=bbb;++i)
#define repd(i,a,b) for(register int i=a,bbb=b;i>=bbb;--i)
#define reps(s) for(register int i=head[s],v=e[i].to;i;i=e[i].nxt,v=e[i].to)
#define ce(i,r) i==r?'\n':' '
#define pb push_back 
#define all(x) x.begin(),x.end()
#define gmn(a,b) a=min(a,b)
#define gmx(a,b) a=max(a,b)
#define fi first
#define se second
#define pr(x) cout<<#x<<": "<<x<<endl
using namespace std;
std::mt19937 rnd(time(0));//std::mt19937_64 rnd(time(0));
typedef long long ll;
typedef double db;
inline int qi(){
    int f=0,fu=1; char c=getchar();
    while(c<'0'||c>'9'){ if(c=='-')fu=-1; c=getchar(); }
    while(c>='0'&&c<='9'){ f=(f<<3)+(f<<1)+c-48; c=getchar(); }
    return f*fu;
}
inline ll ql(){
	ll f=0;int fu=1; char c=getchar();
    while(c<'0'||c>'9'){ if(c=='-')fu=-1; c=getchar(); }
    while(c>='0'&&c<='9'){ f=(f<<3)+(f<<1)+c-48; c=getchar(); }
    return f*fu;
}
inline ll ceil_div(ll a,ll b){ return (a+b-1)/b; }
//start!
const int MAX_N=1e6+5;
bool is_prime[MAX_N];
int prime[MAX_N],cntp=0;
int f[MAX_N],sum[MAX_N],low[MAX_N];//f:?????? sum:f??? low:i???????p^a
void mf_sieve()
{
	repi(i,2,MAX_N-1) is_prime[i]=true;
	f[1]=sum[1]=1;//?????????
	repi(i,2,MAX_N-1){
		if(is_prime[i]) prime[++cntp]=i,low[i]=i,f[i]=2;//?????????(?????????)
		for(register int j=1;j<=cntp&&i*prime[j]<MAX_N;j++){
			is_prime[i*prime[j]]=false;
			if(i%prime[j]==0){
				low[i*prime[j]]=low[i]*prime[j];
				if(low[i]==i) f[i*prime[j]]=f[i]+1;//??i??????????,f(p^k) low[i]=p^a i%prime[j]=0 => p=prime[j]
				else f[i*prime[j]]=f[i/low[i]]*f[low[i]*prime[j]];
				break;
			}
			low[i*prime[j]]=prime[j];
			f[i*prime[j]]=f[i]*f[prime[j]];
		}
	}
}
int main()
{
	mf_sieve();
	int ans=0;
	int n=qi();
	repi(i,1,n-1) ans+=f[i];
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 12844
#include <stdio.h>


int main(void) {
  int a,b;
  int ans;
  

  scanf("%d %d",&a,&b );

  if (a>=b) {
    ans=a;
    a--;
  }
  else{
    ans=b;
    b--;
  }
  if (a>=b) {
    ans=ans+a;
  }
  else{
    ans=ans+b;
  }
  printf("%d\n",ans );
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first setprecision

#if MYDEBUG
#include "lib/cp_debug.h"
#else
#define DBG(...) ;
#endif

using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL  MOD=1E9+7;

struct Problem{
    int n,cnt;
    vector<vector<int>> t;
    vector<int> par,col;
    Problem(LL n):n(n),t(n),par(n),col(n,-1){};
    void dfs1(int p, int c){
        par[c]=p;
        for(auto x: t[c]){
            if(p!=x){
                dfs1(c,x);
            }
        }
    }
    void dfs2(int p, int c){
        cnt++;
        for(auto x: t[c]){
            if(p!=x and col[x]!=1){
                dfs2(c,x);
            }
        }
    }

    void solve(){
        for(int i=0; i<n-1; ++i){
            int a,b;
            cin >> a >> b;
            --a;--b;
            t[a].push_back(b);
            t[b].push_back(a);
        }
        col[0]=0;
        col[n-1]=1;
        dfs1(-1,0);
        deque<int> r;
        for(int i=par[n-1];i!=0;i=par[i]){
            r.push_back(i);
        }
        DBG(r)
        while(!r.empty()){
            col[r.back()]=0;
            r.pop_back();
            if(r.empty())break;
            col[r[0]]=1;
            r.pop_front();
            if(r.empty())break;
        }
        cnt=0;
        dfs2(-1,0);
        DBG(cnt)
        if(cnt>=n/2+1)cout << "Fennec" <<"\n";
        else cout << "Snuke" <<"\n";
    }
};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    long long n=0;
    cin >> n;
    Problem p(n);
    p.solve();
    return 0;
}



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

int main(){
    //n 参加者数(自分を除く)、 c ケーキ持ってきた人の数
    int n,c;
    cin >> n >> c;

    //ケーキの数の総和
    int sum = 0;

    for(int i=0;i<c;i++){
        int x;
        cin >> x;
        sum += x;
    }

    int ans = sum/(n+1);

    if(sum%(n+1)!=0){
        ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 3096
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
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);
        CABSubstrings solver = new CABSubstrings();
        solver.solve(1, in, out);
        out.close();
    }

    static class CABSubstrings {
        static final char A = 'A';
        static final char B = 'B';

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();


            String[] strings = new String[n];
            for (int i = 0; i < n; i++) {
                strings[i] = in.next();
            }

            int ans = 0;

            int a = 0, b = 0, ab = 0;
            for (String s : strings) {
                if (s.charAt(0) == B) {
                    b++;
                    if (s.charAt(s.length() - 1) == A) {
                        ab++;
                    }
                }
                if (s.charAt(s.length() - 1) == A) {
                    a++;
                }
                for (int i = 0; i + 1 < s.length(); i++) {
                    if (s.charAt(i) == A && s.charAt(i + 1) == B) {
                        ans++;
                    }
                }
            }

            a -= ab;
            b -= ab;

            int extra = Math.min(a, b) + ab;
            if (Math.max(a, b) == 0 && ab > 0) {
                extra--;
            }

            ans += extra;

            out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



Measured memory_bytes: 25172
#include<stdio.h>

int main()
{
    int a, b;
    scanf("%d%d", &a, &b);
    if(a < 1 || a > 9 || b < 1 || b > 9)
    {
    	putchar('-');
        putchar('1');
    }
    else
    {
        printf("%d", a*b);
    }
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main(void)
{
	int x1,y1,x2,y2,a,b;
	scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
	a=x2-x1;
	b=y2-y1;
	printf("%d %d %d %d\n",x2-b,y2+a,x2-b-a,y2+a-b);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
	int matrix[100][100];
	int vector[100];
	int ans[100] = { 0 };
	int n, m;
	int i, j;

	scanf("%d %d", &n, &m);

	for (i = 1; i <= n; i++) {
		for (j = 1; j <= m; j++) {
			scanf("%d", &matrix[i - 1][j - 1]);
		}
	}
	for (i = 0; i < m; i++) {
		scanf("%d", &vector[i]);
	}

	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			ans[i] += (matrix[i][j] * vector[j]);
		}
	}

	for (i = 0; i < n; i++) {
		printf("%d\n", ans[i]);
	}
	
	
	return 0;
}


Measured memory_bytes: 2112
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<complex>
#include<numeric>
#include<bitset>
#define INF 1001001001
#define EPS 0.000001

using namespace std;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int,int> pint;

int memo[10001][800];
int memo2[10001][800];
int main(){
	int n,m,r,q;
	while(1){
		scanf("%d %d",&n,&m);
		if(n==0 && m==0) break;
		scanf("%d",&r);
		int i,j;
		for(i=0;i<=m;i++) for(j=0;j<=721;j++) memo[i][j]=0;
		int t,tn,tm,ts;
		for(i=0;i<r;i++){
			scanf("%d %d %d %d",&t,&tn,&tm,&ts);
			t-=539;
			if(ts==1) memo[tm][t]+=1;
			else memo[tm][t]+=-1;
		}
		for(i=0;i<=m;i++) for(j=1;j<=721;j++) memo[i][j]+=memo[i][j-1];
		for(i=0;i<=m;i++){
			memo2[i][0]=0;
			for(j=1;j<=721;j++){
				if(memo[i][j]>0) memo2[i][j]=memo2[i][j-1]+1;
				else memo2[i][j]=memo2[i][j-1];
			}
		}
		scanf("%d",&q);
		for(i=0;i<q;i++){
			int te;
			scanf("%d %d %d",&ts,&te,&tm);
			ts-=539;
			te-=539;
			printf("%d\n",memo2[tm][te-1]-memo2[tm][ts-1]);
		}
	}
		
	return 0;
}

Measured memory_bytes: 59000
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    unordered_map<int, LL> cnt;
    LL ans = 0;
    for (int i = 0 ; i < n ; i++) {
        int v; cin >> v;
        int x = v - (n - i);
        int t = i - v - n;
        if (cnt.count(t))
            ans += cnt[t];
        cnt[x]++;
    }
    cout << ans << '\n';
}

Measured memory_bytes: 11252
#include <stdio.h>
int main(void){
    int W, H, x, y, r;
    
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
    if(W >= x+r && H >= y+r && r <= x && r <= y && x >= 0 && y >= 0){
        printf("Yes\n");
    }
        else{
            printf("No\n");
        }
    return 0;
}



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



int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, k; cin >> n >> k;
    ll res = 0LL;
    ll zeros = n / k;
    res += 1LL*zeros*zeros*zeros;
    if (k % 2 == 0) {
        int half = (n + k/2)/k;
        res += 1LL*half*half*half;
    }
    cout << res << '\n';

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int):
    def combination(n, r, mod=10**9+7):
        n1, r = n+1, min(r, n-r)
        numer = denom = 1
        for i in range(1, r+1):
            numer = numer * (n1-i) % mod
            denom = denom * i % mod
        return numer * pow(denom, mod-2, mod) % mod
    
    
    from collections import defaultdict
    d = defaultdict(int)
    for i in range(N+1):
        s = str(i)
        d[int(s[0]+s[-1])] += 1

    ans = 0


    # for k, v in d.items():
    #     ans +=  combination(v, 2)
    for i in range(10):
        for j in range(10):
            ans += d[int(str(i)+str(j))]*d[int(str(j)+str(i))]

    print(ans-1)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
# coding: utf-8
import sys

stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces


def BinarySearch(num, nums):
    if len(nums) == 0:
        print("Erorr : list has no element")
        return
    left,right = 0,len(nums)
    while left < right:
        mid  = (left+right)//2
        if num < nums[mid]:
            right = mid
        else:
            left = mid + 1
    return right


def main():
    n = ni()
    a = sorted(na()) + [float('inf')]
    b = sorted(na())
    c = sorted(na()) + [float('inf')]
    ans = 0
    small = 0
    big = 0
    for mid in b:
        while a[small] < mid:
            small += 1
        while c[big] <= mid:
            big += 1
        ans += small * (n-big)
    print(ans)
    return


if __name__ == '__main__':
    main()

Measured memory_bytes: 97508
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
#include <fstream>
//#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const ll INF = (1 << 30);
const ll inf = (1LL << 50LL);
const int  maxn = 1e5 + 5;
string a, b;
int dp[3005][3005];
pair<int, int> backtrack[3005][3005];
char mat[3005][3005];
int n, m;
int rek(int i, int j){
    if(i == -1 || j == -1){
        return 0;
    }
    if(dp[i][j] != -1){
        return dp[i][j];
    }
    int ret1 = rek(i - 1, j);
    int ret2 = rek(i, j - 1);
    int ret3 = 0;
    if(a[i] == b[j]){
        ret3 = rek(i - 1, j - 1) + 1;
    }
    int ret = max(ret1, max(ret2, ret3));
    if(ret == ret1){
        backtrack[i][j] = make_pair(i - 1, j);
        mat[i][j] = '.';
    }
    else if(ret == ret2){
        backtrack[i][j] = make_pair(i, j - 1);
        mat[i][j] = '.';
    }
    else{
        backtrack[i][j] = make_pair(i - 1, j - 1);
        mat[i][j] = a[i];
    }
    return dp[i][j] = ret;
}

int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
//    ifstream cin("in.txt");
    cin >> a >> b;
    n = (int)a.size();
    m = (int)b.size();
    memset(dp, -1, sizeof dp);
    rek(n - 1, m - 1);
    string ret = "";
    pair<int, int> at = make_pair(n - 1, m - 1);
    while(true){
        if(at.first == -1 || at.second == -1){
            break;
        }
        ret += mat[at.first][at.second];
        at = make_pair(backtrack[at.first][at.second].first, backtrack[at.first][at.second].second);
    }
    for(int i = (int)ret.size() - 1; i >= 0; i --){
        if(ret[i] == '.')continue;
        cout << ret[i];
    }
    return 0;
}


Measured memory_bytes: 115328
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int x[MAX_N] = {}, y[MAX_N] = {};
    int n, q;
    scanf("%d%d", &n,&q);
    ll ans = (ll)(n-2)*(n-2);
    srep(i,2,n){
        x[i] = n;
        y[i] = n;
    }
    int xx = n;
    int yy = n;
    while(q--){
        int t, z;
        scanf("%d%d", &t,&z);
        if(t == 1){
            if(z < xx){
                ans -= yy - 2;
                srep(i,z,xx) x[i] = yy;
                xx = z;
            }else{
                ans -= x[z] - 2;
            }
        }else{
            if(z < yy){
                ans -= xx - 2;
                srep(i,z,yy) y[i] = xx;
                yy = z;
            }else{
                ans -= y[z] - 2;
            }
        }
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 5248
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
const ll inf=(1e18);
const ll mod=1000000007;
const ll mod2=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
map<int,int> mp;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s;
cin>>s;
int n=s.size();
for(int i=0;i<n-1;i++){
    if(i<n-2){
        if(s[i]==s[i+2]){
            cout<<i+1<<" "<<i+3<<endl;
            return 0;
            }
    }
    if(s[i]==s[i+1]){
        cout<<i+1<<" "<<i+2<<endl;
        return 0;
    }
}
cout<<-1<<" "<<-1<<endl;
}

Measured memory_bytes: 512
// どのボーナスをとるかどうかで全探索したらいい
// D bit用意し、1ならばボーナス取得、0ならば取得せず
#include<bits/stdc++.h>
#define rep(i,n) for(long long i=0;i<(n);i++)
#define ll long long
using namespace std;
int main(){
    ll d,g;
    cin >> d >> g;
    ll p[10],c[10];
    rep(i,d) cin >> p[i] >> c[i];

    ll ans = 1e9;
    for(int tmp=0; tmp<(1 << d); tmp++){
        ll key = 0;
        ll num = 0;
        ll money = 0;
        for(int i = 0; i<d; i++){
            if(tmp & (1 << i)){
                num += p[i];
                money += 100*(i+1)*p[i] + c[i];
            } else key = i;
        }

        if(g <= money) {
            ans = min(ans,num);
            continue;
        }
        ll surplus = (g - money) / 100;        
        int l = surplus % (key+1);
        int x;
        if(l > 0) x = surplus/(key+1) + 1;
        else x = surplus/(key+1);

        if(x > p[key]) continue;

        money += x*100*(key+1); 
        num += x; 
        if(g <= money) ans = min(ans,num);
    }
    cout << ans << endl; 
    
    return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	iv, _ := strconv.Atoi(scanString())
	return iv
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 100001), 100001*100)
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func main() {
	h, w := scanInt(), scanInt()
	dp := make([][]int, h)
	s := make([]string, h)
	for i := range dp {
		dp[i] = make([]int, w)
		s[i] = scanString()
		for j := range dp[i] {
			if i == 0 && j == 0 {
				if s[i][j] == '#' {
					dp[i][j] = 1
				} else {
					dp[i][j] = 0
				}
			} else {
				dp[i][j] = 101
			}

			if i > 0 {
				x := 0
				if s[i-1][j] == '.' && s[i][j] == '#' {
					x++
				}
				dp[i][j] = min(dp[i][j], dp[i-1][j]+x)
			}
			if j > 0 {
				x := 0
				if s[i][j-1] == '.' && s[i][j] == '#' {
					x++
				}
				dp[i][j] = min(dp[i][j], dp[i][j-1]+x)
			}
		}
	}
	fmt.Println(dp[h-1][w-1])
}


Measured memory_bytes: 768
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n;
  cin >> n;
  ll a[n];
  REP(i, n) cin >> a[i];
  int t = 0;
  ll ans = 0, sum = 0;
  REP(s, n) {
    while (t < n && sum + a[t] == (sum ^ a[t])) {
      sum += a[t++];
    }
    ans += t - s;
    if (s == t) {
      t++;
    } else {
      sum ^= a[s];
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

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

vector<bool> isp;
ll MN = pow(10,6)+20;

void sieve(int x=MN) {
  isp.resize(x,true); 
  isp[0] = false;
  isp[1] = false;
  for (int i=2; pow(i,2)<=x; i++) {
    if (isp[i]) for(int j=2; i*j<=x; j++) isp[i*j] = false;
  }
}

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

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

  sieve();
  vector<ll> prime; rep(i,MN) if (isp[i]) prime.push_back(i);
  ll g = 0; rep(i,N) g = gcd(g,A[i]);

  bool used[MN] = {};
  bool ok = true;
  rep(i,N) {
    if (isp[A[i]]) { 
      if (used[A[i]]) { ok = false; break; } 
      used[A[i]] = true;
    }
    else {
      for (auto np: prime) {
        if (A[i]%np==0) {
          while (A[i]%np==0) A[i] /= np;
          if (used[np]) { ok = false; break; } 
          used[np] = true;
        }
        if (np*np>A[i]) break;
      }
      if (A[i]!=1) {
        if (used[A[i]]) { ok = false; break; } 
        used[A[i]] = true;
      }
    }
    if (!ok) break;
  }

  string result = g!=1 ? "not coprime" : ok ? "pairwise coprime" : "setwise coprime";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 12936
def check(n):
  d=[]
  for i in range(1,int(n**0.5)+1,2):
    if n%i==0:
      d.append(i)
      if i!=n//i:
        d.append(n//i)
  if len(d)==8: return True
  else: return False

r=[]
for i in range(1,int(input())+1,2):
  r.append(int(check(i)))
print(sum(r))

Measured memory_bytes: 9256
#include<bits/stdc++.h>
using namespace std;
#define P pair<int,int>
#define ll long long
int main(){
  int n;
  cin >> n;
  vector<P> v[n];
  bool used[n]={};
  ll dst[n]={};
  queue<int> qu;
  int a,b,c;
  for(int i=0;i<n-1;i++){
    cin >> a >> b >> c;
    a--;b--;
    v[a].push_back(P(b,c));
    v[b].push_back(P(a,c));
  }
  int q,k;
  cin >> q >> k;
  k--;
  qu.push(k);
  used[k] = true;
  while(!qu.empty()){
    int tp = qu.front();
    qu.pop();
    for(int i=0;i<v[tp].size();i++){
      P next = v[tp][i];
      if(!used[next.first]){
        dst[next.first] = dst[tp] + next.second;
        used[next.first] = true;
        qu.push(next.first);
      }
    }
  }
  int x,y;
  for(int i=0;i<q;i++){
    cin >> x >> y;
    x--;y--;
    cout << dst[x] + dst[y] << endl;
  }
}

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

int main(){
    ll a, b;
    cin >> a >> b;
    if(a > 0){
        cout << "Positive" << endl;
        return 0;
    }
    else if(a == 0){
        cout << "Zero" << endl;
        return 0;
    }
    else {
        if(b >= 0){
            cout << "Zero" << endl;
            return 0;
        }
        else if((b-a+1)%2 == 0){
            cout << "Positive" << endl;
            return 0;
        }
        else{
            cout << "Negative" << endl;
            return 0;
        }
        
    }
}


Measured memory_bytes: 256
import sys
N, K = map(int, input().split())
S = input()

if '0' not in S:
    print(N)
    sys.exit()

S += '2'
count_lis = []
cnt_1 = 0
first_one = True
for n in range(N):
    if S[n] == '1':
        if first_one:
            tmp = n
            first_one = False
        cnt_1 += 1
        if S[n + 1] == '0' or n == N - 1:
            #始まったところ、終わるところ、何回1があるか
            count_lis.append([tmp, n, cnt_1])
            cnt_1 = 0
            first_one = True

length = len(count_lis)
ans = 0

if length >= K:
    if S[0] == '0':
        ans = max(count_lis[K - 1][1] + 1, ans)
    if S[N - 1] == '0':
        ans = max(N - count_lis[len(count_lis) - K][0], ans)
    for j in range(length - K):
        tmp_ans = count_lis[j + K][1] - count_lis[j][0] + 1
        #print(tmp_ans)
        if ans < tmp_ans:
            ans = tmp_ans
else:
    ans = N
#print(count_lis)
print(ans)

Measured memory_bytes: 9716
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<bitset>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();++itr)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
#define spln(i,n) (i==n?'\n':' ')
#define fac_init(n){fac[0]=fac[1]=inv[1]=fi[0]=fi[1]=1;fz(i,2,n){fac[i]=1ll*fac[i-1]*i%mod;inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;fi[i]=1ll*fi[i-1]*inv[i]%mod;}}
using namespace std;
inline void read(int &x)
{
	char c;int f=1;
	while(!isdigit(c=getchar()))if(c=='-')f=-1;
	x=(c&15);while(isdigit(c=getchar()))x=(x<<1)+(x<<3)+(c&15);
	x*=f;
}
inline void read(long long &x)
{
	char c;int f=1;
	while(!isdigit(c=getchar()))if(c=='-')f=-1;
	x=(c&15);while(isdigit(c=getchar()))x=(x<<1)+(x<<3)+(c&15);
	x*=f;
}
int n,m,i,j;
long long a[200005],b[200005],tmp[200005],c[200005],y[200005],ans;
int stk[200005],tp;
long long crs(long long x1,long long y1,long long x2,long long y2)
{
	return x1*y2-y1*x2;
}
int main()
{
	read(n);
	fz1(i,n){
		read(a[i]);
	}
	fz1(i,n){
		read(b[i]);
	}
	int mx=0;
	fz1(i,n){
		if(a[i]>a[mx]) mx=i;
	}
	fz0k(i,n){
		tmp[i]=a[(mx+i-1+n)%n+1];
	}
	fz0g(i,n){
		a[i]=tmp[i%n];
	}
	fz0k(i,n){
		tmp[i]=b[(mx+i-1+n)%n+1];
	}
	fz0g(i,n){
		b[i]=tmp[i%n];
	}
	fz(i,2,n){
		c[i]=2*(c[i-1]+b[i-1])-c[i-2];
	}
	fz0g(i,n){
		y[i]=a[i]-c[i];
	}
	stk[tp=1]=0;
	fz1(i,n){
		while(tp>1&&crs(stk[tp]-stk[tp-1],y[stk[tp]]-y[stk[tp-1]],i-stk[tp-1],y[i]-y[stk[tp-1]])>=0){
			tp--;
		}
		stk[++tp]=i;
	}
	fz1(i,tp-1){
		long long dx=stk[i+1]-stk[i];
		ans+=(dx+1)*y[stk[i]]+(dx-1)*y[stk[i+1]];
	}
	fz0k(i,n){
		ans+=2*c[i];
	}
	printf("%.10f\n",ans/2.0/n);
	return 0;
}

Measured memory_bytes: 11684
from collections import Counter
N = int(input())
S = [input() for _ in range(N)]
C = Counter(S)
ans = ['AC x {}'.format(C['AC']),'WA x {}'.format(C['WA']),'TLE x {}'.format(C['TLE']),'RE x {}'.format(C['RE'])]
print(*ans, sep='\n')

Measured memory_bytes: 78736
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::string S;
  cin >> S;
  int N = S.size();

  vector<char> C(N, '.');
  int C_index{};
  rep(i, N) {
    if (C_index != 0 && S[i] != C[C_index-1]) {
      --C_index; // delete
    } else {
      C[C_index] = S[i];
      ++C_index;
    }
  }
  cout << N-C_index << '\n';
}


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

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

typedef long long LL;

const int INF = 0x3f3f3f3f;


int main(void) {
    std::ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int h, n;
    cin >> h >> n;
    int a[n];
    for (int i = 0; i < n; ++i) cin >> a[i];

    cout << (accumulate(a, a+n, 0) >= h ? "Yes" : "No") << endl;

    return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define bitrep(X,N) for(ll X = 0; X < (1 << (N)); X++)
#define PI (acos(-1.0))
#define sorta(V) sort(V.begin(), V.end())
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end() 
#define CERR if(false) cerr

using namespace std;


int main(){

    int a,b,c;
    cin >> a >> b >> c;

    cout << (a + b >= c ? "Yes" : "No") << endl;
    return 0; 
}

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

int main()
{
    
  unsigned long long int n, in1, in2, sum = 0, frm, to;
  
  register int i, q;
  
  int hash[100001];
  
  for(i = 0; i < 100001; i++)
    hash[i] = 0;
  
  cin >> n;
  
  for(i = 0; i < n; i++)
  {
      cin >> in1;
      
      hash[in1]++;
      
      sum += in1;
  }
  
  cin >> q;
  
  while(q--)
  {
      cin >> in1 >> in2;
      
      hash[in2] += hash[in1];
      
      frm = hash[in1];
      
      hash[in1] = 0;
      
      sum += (in2 - in1)* frm;
      
      cout << sum << "\n";
      
  }
  
  
  
  return 0;
}

Measured memory_bytes: 4024
use std::io;
use std::cmp;

// read a line(without line feed)
fn read_line() -> String {
    let mut in_str = String::new();
    io::stdin().read_line(&mut in_str).unwrap();
    return in_str.trim().to_string();
}

// read wods on a line
pub fn read_words_in_line() -> Vec<String> {
    let s = read_line();
    return s.split_whitespace().map(|x| x.to_string()).collect::<Vec<String>>()
}

// read type t on a line
pub fn read_t_in_line<T : std::str::FromStr>() -> Vec<T> {
    let mut v : Vec<T> = Vec::new();
    for e in read_words_in_line().iter().map(|x| x.parse::<T>()) {
        if let Ok(r) = e {
            v.push(r);
        }
        else{
            return Vec::new();
        }
    }
    return v;
}

// sort slice
pub fn sort<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort();
}
// sort slice by reverse order
pub fn sort_rev<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort_by(|x, y| y.cmp(x));
}

pub fn min<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::min(a, b);
}

pub fn max<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::max(a, b);
}

fn main() {

    let l = read_t_in_line::<i32>();
    let (a, b) = (l[0], l[1]);
    for c in 1..4 {
        if (a * b * c) % 2 == 1 {
            println!("Yes");
            return;
        }
    }
    println!("No");
}


Measured memory_bytes: 4352
#include <iostream>

using namespace std;

int main() {
	
	int n;

	while (cin >> n) {

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

			int k, p;
			cin >> k >> p;

			if (k > p) {
				if (k % p)
					cout << k % p << "\n";
				else
					cout << p << "\n";
			}
			else
				cout << k << "\n";
		}

	}
	
	return 0;

}







Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
 
int main(){
    int n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    sort(all(a));
    vector<ll> s(n+1,0);
    rep(i,n) s[i+1]=s[i]+a[i];
    vector<bool> ok(n,false);
    ok[n-1]=true;
    int ans=1;
    for(int i=n-2;i>=0;i--){
        if(!ok[i+1]) continue;
        if(s[i+1]*2>=a[i+1]){
            ans++;
            ok[i]=true;
        }
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 4744
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define CHAL_BC_APNE_BAAP_KO_MAT_SIKHA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define fr first
#define se second 
signed main()
{
	CHAL_BC_APNE_BAAP_KO_MAT_SIKHA;		
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		if(n%i==0){
			if(n/i<=9 and i<=9)
			{
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;
}


Measured memory_bytes: 256
//#pragma GCC oplmize(2)
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define sc(x) scanf("%lld",&x)
#define scs(x) scanf("%s",x+1)
#define pr(x) printf("%lld\n",x)
#define prs(x) printf("%s\n",x)
using namespace std;
const int maxn=2e5+5;
const int mod=1e9+7;
const double pi=acos(-1.0);
const double eps = 1e-8;
ll n,a[maxn],ma,s;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    sc(n);
    for(int i=1;i<=n;i++){
        sc(a[i]);
    }
    ma=a[1];
    for(int i=2;i<=n;i++){
        if(ma>a[i]){
            s=s+ma-a[i];
        }
        else{
            ma=a[i];
        }
    }
    pr(s);
    return 0;
}


Measured memory_bytes: 5304
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    long n, k;
    cin >> n >> k;

    long a[100000];
    for (int i = 0; i < n; i++) cin >> a[i];

    //cout << ceil((n - 1 + (k - 1) - 1) / (k - 1)) << endl;
    cout << (n - 1 + (k - 1) - 1) / (k - 1) << endl;
    return 0;
}

Measured memory_bytes: 1272
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
    answer = 9999;

    for(i=0 ;i < input.length-2; i++){
        tmp  =Number(input.slice(i, i+3));
        check = Math.abs(tmp-753);
        if(check < answer){
            answer = check;
        }


    }

    console.log(answer);

    
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
N = int(input())
W = []
for i in range(N):
    W.append(input())

c = 0
for j in range(N-1):
    if W.count(W[j+1]) == 1:
        if W[j+1][0] == W[j][-1]:
            c += 1

if c == N-1:
    print("Yes")
else:
    print("No")

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

int main()
{
	int N, M, P, sum, tosen, temp;
	while (cin >> N >> M >> P, N || M || P) {
		sum = 0;
		for (int i = 1; i <= N; i++) {
			cin >> temp;
			if (i == M)
				sum += tosen = temp;
			else
				sum += temp;
		}
		if (tosen)
			cout << sum * (100 - P) / tosen << endl;
		else
			cout << 0 << endl;
	}
	return 0;
}

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

long long n,a,m,k,q,b,c=1,a1,a2,b1,b2;
float qq,ww,ff=2,qs;
string ss,s1,s2;
int main(){
    cin>>n;
    vector<ll>v(n,0);
    for (int i=0; i<n; i++){
        cin>>v[i];
    }
    for (int i=1; i<n-1; i++){
        vector<ll>v1(3,0);
        v1[0]=v[i-1];
        v1[1]=v[i];
        v1[2]=v[i+1];
        sort(v1.begin(), v1.end());
        if (v1[2]>v[i] and v[i]==v1[1]){
            a++;
        }
    }
    cout<<a<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
using namespace std;

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

int main(void){
	string s;
	cin >> s;
	bool ans = false;
	LOOP(i, 3){
		if (s[i] == s[i + 1])ans = true;
	}
	cout << (ans ? "Bad" : "Good") << endl;
	return 0;
}

Measured memory_bytes: 256
while 1:
	n=input()
	if n==0:break
	p=[0]*n
	l=[[0]*31 for i in range(n)]
	a=sorted([raw_input().split() for i in range(n)])
	for j in range(n):
		for t in a[j][2:]:
			l[j][int(t)]=1
	for t in range(30):
		c=0
		for j in range(n):
			if l[j][t]:c+=1
		for j in range(n):
			if l[j][t]:p[j]+=n-c+1
	print min(p),a[p.index(min(p))][0]

Measured memory_bytes: 4248
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define fill(x,y) memset(x,y,sizeof(x))
#define name(x) #x
using namespace std;


const int INF = INT_MAX-100;
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

template< typename T >
struct edge{
    int src, to;T cost;
    edge(int to,T cost) :src(-1),to(to),cost(cost){}
    edge(int src, int to, T cost) :src(src),to(to),cost(cost){}edge
    &operator=(const int &x){
        to =x;
        return *this;
    }
    operator int() const{ return to;}
};

template< typename T >
using Edges =vector< edge<T> >;
template< typename T >
using WeightedGraph =vector< Edges<T> >;
using UnWeightedGraph =vector< vector<int> >;
template< typename T >
using Matrix =vector< vector<T> >;



int main() {
    // if double is required
    //cout<<fixed<<setprecision(10);

    ll K,A,B;
    cin >> K >> A >> B;
    
    if (B-A <= 2){
        cout << K+1 << endl;
        return 0;
    }
    

    ll bis = 1;
    for(auto i = 0; i<K; i++){
        
        if(bis >= A && i+1 <K){
            bis += (B-A);
            i+=1;
            continue;
        }
        
        bis+=1;
        
    }
    
    cout << bis << endl;
    
    
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

int main(){
    ll n, m;
    cin >> n >> m;

    ll x = n * 2;
    ll ans = 0;
    if(x >= m)
        ans = m / 2;
    else{
        m -= x;
        ans = n + m / 4;
    }
    cout << ans << endl;
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

int main() {
   int n, d, x;
   cin >> n >> d >> x;
   int sum = 0;
   rep (i, n) {
      int a;
      cin >> a;
      for (int j = 0; j <= d; j++) {
         int day = j * a + 1;
         if (day > d) break;
         sum++;
      }
   }
   cout << sum + x<< endl;

   return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"

using namespace std;

void solve()
{
	int n, s = 0;
	cin >> n;
	vector<int> as(n);
	for (int i = 0; i < n; i++)
	{
		cin >> as[i];
		s += as[i];
	}
	bitset<4000001> dp;
	dp[0] = 1;
	for (int a : as)
	{
		bitset<4000001> nx;
		nx |= dp;
		nx |= dp << a;
		swap(dp, nx);
	}
	for (int x = (s+1)/2; x <= 4000000; x++)
	{
		if (dp[x])
		{
			cout << x << endl;
			return;
		}
	}
}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 2176
#define _USE_MATH_DEFINES
#include <math.h>
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int n,a,b;
    string s;
    cin >> n >> a >> b >> s;
    int pass[2] = {};
    for(int i = 0;i < s.size();i++)
    {
        if(s[i] == 'a')
        {
            pass[0]++;
            if((pass[0] + pass[1]) <= (a + b))
            {
                cout << "Yes\n";
            }
            else
            {
                cout << "No\n";
            }
        }
        else if(s[i] == 'b')
        {
            pass[1]++;
            if((pass[0] + pass[1]) <= (a + b) && pass[1] <= b)
            {
                cout << "Yes\n";
            }
            else
            {
                cout << "No\n";
                pass[1]--;
            }
        }
        else
        {
            cout << "No\n";
        }
    }

    return 0;
}

Measured memory_bytes: 896
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n,a,b;
    cin >> n >> a >> b;
    ll ans =0;
    ans += n/(a+b) * a;
    n -= n/(a+b) * (a+b);
    if(a==0){
        cout << 0;
        return 0;
    }
    else{
        ans += min(a,n); 
    }
    cout << ans;


    return 0;
}

Measured memory_bytes: 3624
'use strict'

function topological_sort(nodes_count, in_count, outs){
  let start_nodes = Array.from(Array(nodes_count+1).keys()).filter(x => in_count[x]==0)
  start_nodes.shift()

  let result = [];
  let from = start_nodes.shift();
  while(from != undefined){
    result.push(from);
    for(let out_node of outs[from]){
      in_count[out_node]--;
      if(in_count[out_node]==0){ start_nodes.push(out_node); }
    }
    from = start_nodes.shift();
  }

  return result;
}

function main(input){
  const lines = input.split('\n');
  const NM = lines.shift().split(' ').map(x => parseInt(x));
  const N = NM[0];
  const M = NM[1];
  const XY = []
  for(var i=0;i<M;i++){
    let xy = lines.shift().split(' ').map(x => parseInt(x));
    XY.push(xy);
  }

  let ins = [];
  let outs = [];
  let in_count = []
  for(var i=0;i<N+1;i++){
    ins.push([]);
    outs.push([]);
  }

  for(var i=0;i<M;i++){
    let x = XY[i][0];
    let y = XY[i][1];
    ins[y].push(x);
    outs[x].push(y)
  }
  in_count = ins.map(x => x.length)
  let topological_nodes = topological_sort(N, in_count, outs);

  let dp=Array(N+1).fill(0);
  for(let current of topological_nodes){
    dp[current] = Math.max(...ins[current].map(x => dp[x]+1).concat(0) )
  }

  let result = Math.max(...dp);
  console.log(result);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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


using namespace std;


int main() {

    int N, num, countOdd = 0;
    cin >> N;

    for(int i = 1; i <= N;i++){
        cin >> num;
        if(num&1){
            countOdd++;
        }
    }

    if(!(countOdd&1)){
        cout << "YES" << endl;
    }else {
        cout << "NO" << endl;
    }



    return 0;
}


Measured memory_bytes: 3624