akhauriyash/Code-Regression huggingface dataset:
N,M = map(int, input().split())
a = set()
for i in range(M):
    a.add(int(input()))

if N == 1:  print(1)
elif N == 2:
    if 1 == M:  print(1)
    else:   print(2)
else:
    temp, temp1, temp2 = 0,0,0
    if 1 not in a:  temp1 = 1
    if 2 not in a:  temp2 = 1 + temp1
    
    for i in range(2,N-1):
        temp = 0
        if i+1 not in a:    temp = temp1 + temp2
        temp1 = temp2
        temp2 = temp

    print( int((temp1+temp2) % 1000000007) )

Measured memory_bytes: 12012
#include <iostream>
using namespace std;
int main(void){
    string s;
    cin >> s;

    int mass_cnt = 0;
    for(int i=0;i<s.length();i++) {
    	if(s[i] == '1') {
	        mass_cnt++;
	    }
    }

    cout << mass_cnt << endl;
    return 0;
}


Measured memory_bytes: 256
# -*- coding:utf-8 -*-

def solve():
    N, X, M = list(map(int, input().split()))

    def f(x, m):
        return x%m

    # A[i]の値は必ず mod Mの範囲に収まる
    # ということはたかだかMの周期でループする
    # ただし、ループして戻るのはA[0]とは限らず、適当なA[?]に戻る
    # 注意として、A[i]=0になったら、A[i+1]以降は必ず0
    A = [0]*(10**5+2)  # A[i]
    Ar = [0]*(10**5+2)  # Ar[i] := A[i]以下の累積和
    A[0], Ar[0] = X, X
    Adic = {X:0}  # Adic[A[i]]=i => 過去のA[i]はi番目に出現した
    stop_i = 0
    is_zero = False
    for i in range(1, N):
        A[i] = f(pow(A[i-1], 2, M), M)
        Ar[i] = Ar[i-1] + A[i]
        if A[i] == 0:
            is_zero = True
            stop_i = i
            break
        if A[i] in Adic:
            stop_i = i
            break
        Adic[A[i]] = i

    if stop_i == 0:
        print(Ar[N-1])
    elif is_zero:
        print(Ar[stop_i])
    else:
        start_i = Adic[A[stop_i]]
        t = stop_i - start_i
        restN = N - start_i
        if start_i-1 >= 0:
            ans = Ar[start_i-1]
            ans += (Ar[stop_i-1] - Ar[start_i-1]) * (restN//t)
            ans += Ar[start_i-1+(restN%t)] - Ar[start_i-1]
        else:
            ans = Ar[stop_i-1] * (restN//t)
            ans += Ar[start_i-1+(restN%t)]
        print(ans)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 18884
import sys
input=lambda: sys.stdin.readline().rstrip()
x,n=map(int,input().split())
P=set([int(i) for i in input().split()])
ans=0
for i in range(1,102):
  if i in P:
    continue
  else:
    if abs(i-x)<abs(ans-x):
      ans=i
print(ans)

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

using namespace std;

int main(){

  int N,D,X[11][11],Y[11][11],z=0;

cin >>N>>D;

for(int i=0;i<N;i++){
  for(int j=0;j<D;j++){
    cin>>X[i][j];
  }
}
for(int i=0;i<11;i++){
  for(int j=0;j<11;j++){
    Y[i][j]=0;
  }
}



for(int i=0;i<N;i++){
  for(int j=i+1;j<N;j++){
    for(int k=0;k<D;k++){
      Y[i][j]=Y[i][j]+ (X[i][k]-X[j][k])*(X[i][k]-X[j][k]);
    }

  }
}
for(int i=0;i<N;i++){
  for(int j=i+1;j<N;j++){
for(int a=1;a<1000;a++){
  if(a*a==Y[i][j]){
    z=z+1;
  }
}
}



}
cout<<z<<endl;

  return 0;
}


Measured memory_bytes: 256
import itertools
import operator


N = int(input())
d = list(map(int, input().split()))

n = N * (N - 1) // 2
l = []
c = list(itertools.combinations(d, 2))
for i in range(n):
    l.append(operator.mul(c[i][0], c[i][1]))
ans = sum(l)
print(ans)

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {

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

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int x = 0;

		for (int i = a; i <= b; i++) {//a～b間で数字を増やす
			if (i < b && c % i != 0) {//iがb以下で約数でもない

			} else if ((c % i == 0)) {//cの約数
				x++;

			} else if (i == b) {//bまで行ったら脱出

			}

		}
		System.out.println(x);

	}

}



Measured memory_bytes: 26400
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
#define lint long long int
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
*/

int main() {
	int N;
	cin >> N;
	vector<int>A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	vector<int>B(N);
	for (int i = 0; i < N; i++) {
		B[A[i] - 1] = i + 1;
	}
	for (int i = 0; i < N; i++) {
		cout << B[i] << ' ';
	}
	cout << endl;
}


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

used = set()
now = 1
ret = 0
while True:
    if now == 2:
        print(ret)
        exit()
    elif now in used:
        print(-1)
        exit()
    used.add(now)
    now = a[now - 1]
    ret += 1


Measured memory_bytes: 13200
#!/usr/bin/env python3

import sys


P = 10 ** 9 + 7
MAX = 10 ** 5


class BinomModPrime(object):
    

    def __init__(self):
        self.fac = [0 for _ in range(MAX)]
        self.finv = [0 for _ in range(MAX)]
        self.inv = [0 for _ in range(MAX)]
        self.fac[0] = self.fac[1] = 1
        self.finv[0] = self.finv[1] = 1
        self.inv[1] = 1
        for i in range(2, MAX):
            self.fac[i] = self.fac[i - 1] * i % P
            self.inv[i] = P - self.inv[P % i] * (P // i) % P
            self.finv[i] = self.finv[i - 1] * self.inv[i] % P
    
    def binom(self, n, k):
        if n < k or n < 0 or k < 0:
            return 0
        else:
            return self.fac[n] * (self.finv[k] * self.finv[n - k] % P) % P

    def h(self, n, k):
        return self.binom(n + k - 1, k)


def compute(s):
    res = 0
    bmp = BinomModPrime()
    # print(bmp.binom(10, 0), file=sys.stderr)
    for n in range(1, s // 3 + 1):
        d = bmp.binom(s - 3 * n + n - 1, n - 1)
        res += d
        res %= P
        if s < 10:
            pass
            # print(n, s - 3 * n, d, file=sys.stderr)
    return res


def main():
    s = int(input())
    print(compute(s))


if __name__ == '__main__':
    main()

Measured memory_bytes: 20964
import java.util.*;

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

        for(int i = x - k + 1; i < x + k; i++){
            System.out.println(i);
        }
        return;
    }
}


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

using namespace std;

#define fi first
#define se second

typedef pair<int ,int> ii;

int main(){
    int n;
    cin >> n;
    vector <ii> v(n);
    for (int i = 0; i < n; ++i){
        cin >> v[i].fi;
        v[i].se = i + 1;
    }
    sort(v.begin(),v.end(),[&](ii x, ii y){return x.fi < y.fi;});
    for (auto x : v){
        cout << x.se << " ";
    }
    return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
int main() {
    int K;
    cin >> K;
    long long int result = 0;
    for(int a = 1; a <= K; a++) {
        for(int b = 1; b <= K; b++) {
            for(int c = 1; c <= K; c++) {
                result += gcd(gcd(a, b), c);
            }
        }
    }
    cout << result << endl;
}


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

int main() {
  long long N;
  cin >> N;
  long long ans = 0, pow5 = 5;
  while (N >= pow5)
    ans += N / pow5 / 2, pow5 *= 5;
  if (N % 2 == 0)
    cout << ans << endl;
  else
    cout << 0 << endl;
}

Measured memory_bytes: 256
s = input()
left = int(s[:2])
right = int(s[2:])
 
if 1 <= left and left <=12 and 1 <= right and right <= 12:
  print("AMBIGUOUS")
elif 1 <= left and left <= 12:
  print("MMYY")
elif 1 <= right and right <= 12:
  print("YYMM")
else:
  print("NA")

Measured memory_bytes: 3060
#include<stdio.h>

int main()
{
    int a ,row,colm;
    scanf("%d",&row) ;
 a=row/1000 ;
 if(row%1000==0)
    printf("0") ;
 else
 {
     printf("%d",(a+1)*1000  - row) ;
 }
    return 0 ;
}


Measured memory_bytes: 1728
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr double HDINF = 50000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))),(c).end())
# define LOWER(s)    transform(ALL((s)),(s).begin(),TL<char>)
# define UPPER(s)    transform(ALL((s)),(s).begin(),TU<char>)
# define FOR(i,a,b)  for(LL i=(a);i<(b);i++)
# define RFOR(i,a,b) for(LL i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

int main() {
	int n;
	cin >> n;
	LL sumb = 0;
	LL minl = INF;
	bool f = true;
	REP(i, n) {
		LL a, b;
		cin >> a >> b;
		sumb += b;
		if (a > b) minl = min(b, minl);
		if (a != b) f = false;
	}
	if (f) cout << 0 << endl;
	else cout << sumb - minl << endl;
}

Measured memory_bytes: 256
# Date [ 2020-09-19 21:01:49 ]
# Problem [ b.py ]
# Author Koki_tkg

import sys
# import math
# import bisect
# import numpy as np
# from decimal import Decimal
# from numba import njit, i8, u1, b1 #JIT compiler
# from itertools import combinations, product
# from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_ints2(x):   return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def GCD(a: int, b: int) -> int: return b if a%b==0 else GCD(b, a%b)
def LCM(a: int, b: int) -> int: return (a * b) // GCD(a, b)

def Main():
    n = read_int()
    cnt = 0
    flag = False
    for _ in range(n):
        d1, d2 = read_ints()
        if d1 == d2:
            cnt += 1
        else:
            cnt = 0
        if cnt == 3:
            flag = True
    print('Yes' if flag else 'No')

if __name__ == '__main__':
    Main()

Measured memory_bytes: 9252
N = int(input())
W = list(map(int,input().split()))
for i in range(N-1):
  if i == 0:
        min = abs( W[0] - sum(W[1:]) )
  else:
    if min > abs( sum(W[:i+1]) - sum(W[i+1:])):
      min = abs( sum(W[:i+1]) - sum(W[i+1:]) )
print(min)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <stack>
#include <set>
#include <cstdio>
using namespace std;

typedef long long ll;
typedef pair<int,int> P1;
typedef pair<int,P1> P2;
const int inf=1000000000;
struct edge{
	int to,cost;
};

int main() {
	int n;
	int l[201]={};
	cin>>n;
	for(int i=0;i<2*n;++i)cin>>l[i];
	sort(l,l+2*n);
	int t=0;
	for(int i=2*n-1;i>=0;i-=2){
		t+=l[i-1];
	}
	cout<<t<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main(){
    string s;cin>>s;
    ll g=0,p=0;
    rep(i,0,s.size()-1){
        if(s[i]=='g')g++;
        else p++;
    }
    cout<<(ll)(g-p)/2<<endl;
    
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
int main() {
    int i, sum =0, a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    for(i = a; i <= b; i++){
        if(c%i == 0) sum++;
    }
    printf("%d", sum);
    printf("\n");
    return 0;
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  string s;
  cin >> n >> s;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'W') cnt++;
  }
  int w = 0, ans = n;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'W') {
      ans = min(ans, w + (n - (i + 1) - (cnt - (w + 1))));
      w++;
    } else {
      ans = min(ans, w + (n - (i + 1) - (cnt - w)));
    }
  }
  cout << ans << '\n';
  return 0;
}

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

int n;

int main(){
	cin>>n;
	if (n == 1){
		cout<<0<<endl;
	}else if(n % 2 == 1){
		cout<< n / 2 <<endl;
	}else{
		cout<< n / 2 - 1 <<endl;
	}
}


Measured memory_bytes: 256
import scala.io.StdIn._

object Main {
  def main(args: Array[String]) = {
    val a = readLine.split(' ').map(a => a.toInt)
    println(gcd(a(0), a(1)))
  }

  def gcd(x: Int, y: Int): Int = {
    if (x == y) x
    else if (x == 0) y
    else if (y == 0) x
    else if (x > y) gcd(y, x % y)
    else gcd(x, y % x)
  }
}

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

const int N = 200054, mod = 1000000007;

struct linear {
	int k, b, id;
	linear * read() {return scanf("%d%d", &b, &k), this;}
} a[N];

int n;
int L[N], R[N], F[N];

inline void up(int &x, const int y) {x < y ? x = y : 0;}
inline void down(int &x, const int y) {x > y ? x = y : 0;}
inline int & add(int &x, const int y) {return x += y - mod, x += x >> 31 & mod;}
inline int & sub(int &x, const int y) {return x -= y, x += x >> 31 & mod;}

int main() {
	int i, j = 0, ans;
	scanf("%d", &n);
	for (i = 0; i < n; ++i) a[i].read();
	std::sort(a, a + n, [] (const linear &A, const linear &B) {return A.k < B.k;});
	for (i = 0; i < n; ++i) a[i].id = i;
	std::sort(a, a + n, [] (const linear &A, const linear &B) {return A.b < B.b;});
	for (i = n - 1, L[i] = a[i].id; --i >= 0; down(L[i] = L[i + 1], a[i].id));
	for (*R = a->id, i = 1; i < n; ++i) up(R[i] = R[i - 1], a[i].id);
	for (*F = 1, i = 0; i < n; ++i) {
		for (; R[j] < L[i] - 1; ++j);
		add(F[i + 1] = F[i], F[i]);
		if (L[i]) sub(F[i + 1], F[j]);
	}
	for (ans = F[n]; R[j] < n - 1; ++j);
	printf("%d\n", sub(ans, F[j]));
	return 0;
}

Measured memory_bytes: 4992
import math
n = int(input())
xy = [tuple(map(int, input().split())) for _ in range(n)]
dists = []
for i in range(n):
  for j in range(i+1, n):
    dx = xy[i][0] - xy[j][0]
    dy = xy[i][1] - xy[j][1]
    dists.append(math.sqrt(dx * dx + dy * dy))
print(2 * sum(dists) / n)

Measured memory_bytes: 3060
# Author: S Mahesh Raju
# Username: maheshraju2020
# Date: 22/08/2020

from sys import stdin, stdout, setrecursionlimit
from math import gcd, ceil, sqrt
from collections import Counter, deque
from bisect import bisect_left, bisect_right
ii1 = lambda: int(stdin.readline().strip())
is1 = lambda: stdin.readline().strip()
iia = lambda: list(map(int, stdin.readline().strip().split()))
isa = lambda: stdin.readline().strip().split()
setrecursionlimit(100000)
mod = 1000000007

n, x, t = iia()
print(ceil(n / x) * t)

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

using namespace std;

const int INF = 0x0fffffff;

int N;
int K;

typedef pair<int, int> ii;

vector< vector<int> > M;
vector<bool> V; // visited

vector<ii> R; // range

const ii inf = make_pair(-INF, INF);
const ii fail = make_pair(INF, -INF);

ii dfs(int i) {
    if (V[i]) {
        return inf;
    }

    V[i] = true;

    for (size_t j = 0; j < M[i].size(); ++j) {
        int ni = M[i][j]; // next i

        ii rv = dfs(ni);

        //if (rv == make_pair(-INF-1, INF+1)) {
        //    rv = inf;
        //}

        if (rv == fail) {
            return fail;
        //} else if (R[i] == inf){
        //    R[i] = rv;
        //} else if (rv == inf) {
        //    continue;
        } else if (R[i] != inf && rv != inf && R[i].first % 2 != rv.first % 2) {
            return fail;
        //} else if (R[i].second < rv.first) {
        //    return fail;
        //} else if (rv.second < R[i].first) {
        //    return fail;
        } else {
            R[i].second = min(R[i].second, rv.second);
            R[i].first  = max(R[i].first, rv.first);
        }
    }

    if (R[i].second < R[i].first) {
        return fail;
    }

    if (R[i] == inf) {
        return inf;
    } else {
        return make_pair(R[i].first-1, R[i].second+1);
    }
}

void dfs2(int i) {
    if (V[i]) {
        return;
    } 

    V[i] = true;

    R[i] = make_pair(R[i].first, R[i].first);
    
    for (size_t j = 0; j < M[i].size(); ++j) {
        int ni = M[i][j]; // next i
        
        if (V[ni]) {
            continue;
        }

        R[ni] = make_pair(max(R[ni].first, R[i].first-1), min(R[ni].second, R[i].second+1));

        dfs2(ni);
    }
}

int main(int argc, char* argv[]) {
    // for cin
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> N;

    M.resize(N);

    for (int i = 0; i < N; ++i) {
        M[i].clear();
    }

    for (int i = 0; i < N-1; ++i) {
        int a;
        int b;

        cin >> a >> b;
        a--;
        b--;

        M[a].push_back(b);
        M[b].push_back(a);
    }

    V.resize(N);
    fill(V.begin(), V.end(), false);

    R.resize(N);
    fill(R.begin(), R.end(), inf);

    cin >> K;

    for (int i = 0; i < K; ++i) {
        int v;
        int p;

        cin >> v >> p;
        v--;

        R[v] = make_pair(p, p);
    }

    ii rv = dfs(0);

    if (rv == fail) {
        printf("No\n");
        return 0;
    }

    printf("Yes\n");
    fill(V.begin(), V.end(), false);

    dfs2(0);

    for (int i = 0; i < N; ++i) {
        printf("%d\n", R[i].first);
    }

    return 0;
}


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

using namespace std;
typedef long long ll;

int main()
{
  ll a, b, c;
  cin >> a >> b >> c;
  
  if (a+b+1 > c)
  {
    cout << c + b << endl;
  }
  else
  {
    cout << a + b + 1 + b << endl;
  }
    
  return 0;
}

Measured memory_bytes: 256
n=int(input())

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

l=[-1 for _ in range(n)]
for i in reversed(range(1,n+1)):
    si=0
    j=2*i-1
    while j<=n-1:
        si+=l[j]
        j+=i
    si=si%2
    if si==0:
        l[i-1]=a[i-1]
    elif a[i-1]==0:
        l[i-1]=1
    else:
        l[i-1]=0

b=[]
for i in range(n):
    if l[i]==1:
        b.append(i+1)

print(len(b))
if len(b)!=0:
    print(*b)

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

int main(){
    int N, A[100000];
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }

    sort(A, A+N);

    long long sum = 0;
    int ans = 0;
    for(int i = 0; i < N-1; i++){
        sum += A[i];
        if(2*sum >= A[i+1]){
            ans++;
        }else{
            ans = 0;
        }
    }
    ans++;

    cout << ans << endl;
}	


Measured memory_bytes: 640
#include<iostream>

using namespace std;

int main(void){

  string S,T;

  cin >> S >> T;

  
  int s_size = S.size();
  int t_size = T.size();

  int d = 0;
  int ans = 1000;


  for(int i=0;i < s_size - t_size+1;i++){
    d = 0;
    for(int j = 0;j < t_size;j++){
      if(T[j]!=S[i+j]){
        d++;
      }
    }
    ans = min(d,ans);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3576
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		int n=scn.nextInt();
		int k=scn.nextInt();
		String str=scn.next();
		ArrayList<Integer> al=new ArrayList<>();
		int cnt=1;
		for(int i=1;i<str.length();i++) {
			if(str.charAt(i)==str.charAt(i-1)) {
				cnt++;
			}else {
				al.add(cnt);
				cnt=1;
			}
		}
		al.add(cnt);
		long []sum=new long[al.size()];
		for(int j=0;j<al.size();j++) {
			if(j>0) {
				sum[j]+=sum[j-1]+al.get(j);
			}else {
				sum[j]=al.get(j);
			}
		}
//		System.out.println(al.size());
//		for(int i=0;i<al.size();i++) {
//			System.out.print(al.get(i)+" ");
//		}
//		System.out.println();
		n=al.size()/2;
		if(str.charAt(0)=='0'&&al.size()%2!=0)
			n++;
      int start=0;
      if(str.charAt(0)=='1') start=1;
		if(k>=n) {
			System.out.println(sum[al.size()-1]);
		}
      else {
			long max=sum[start+(k-1)*2+1<al.size()?start+(k-1)*2+1:al.size()-1];
			for(int j=start+2;j<al.size();j+=2) {
              int r = j+(k-1)*2+1;
              if(r>=al.size()) r=al.size()-1;
				if(sum[r]-sum[j-2]>max) {
					max=sum[r]-sum[j-2];
				}
			}
			System.out.println(max);
		}
	}

}


Measured memory_bytes: 27368
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e18;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int dp[3005][3005];
signed main() {
    int N,T;
    cin >> N >> T;
    vector<P>A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i].first >> A[i].second;
    }
    sort(A.begin(),A.end());
    for(int i = 0; i < N; i++) {
        if(i == 0) {
            dp[i][A[i].first] = A[i].second;
            continue;
        }
        for(int j = 0; j < T; j++) {
            dp[i][min(T,j+A[i].first)] = max(dp[i][min(T,j+A[i].first)],dp[i-1][j]+A[i].second);
        }
        for(int j = 0; j < 3005; j++) {
            dp[i][j] = max(dp[i][j],dp[i-1][j]);
        }
    }
    int ans = 0;
    for(int i = 0; i < 3005; i++) {
        ans = max(ans,dp[N-1][i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 74020
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL (1LL<<62) // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

// Union-Find; 素集合データ構造
class UnionFind {
public:
    vector<long long> parent;
    long long n;
    UnionFind(long long x) :parent(x, -1), n(x){}
    bool unite(long long x, long long y){
        x = find(x); y = find(y);
        if (x == y) return false;
        if (size(x) < size(y)) swap(x, y);
        parent[x] += parent[y]; parent[y] = x;
        return true; }
    bool same(long long x, long long y){ return find(x) == find(y); }
    long long find(long long x){ return parent[x] < 0 ? x : parent[x] = find(parent[x]); }
    long long size(long long x){ return -parent[find(x)]; }
    long long leader(long long x){ return (parent[x] < 0 ? x : leader(parent[x])); }
};

int main(){
    Init();
    ll n, m;
    cin >> n >> m;
    UnionFind uf(n);
    vi a(m), b(m);
    rep(i, m){
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
        uf.unite(a[i], b[i]);
    }
    set<ll> st;
    for(ll i=0; i<n; i++){
        st.insert(uf.leader(i));
    }
    cout << st.size() -1 << endl;
}

Measured memory_bytes: 7884
#include<bits/stdc++.h>
#define ll long long
using namespace std;
string s[] = {"Sunny", "Cloudy", "Rainy"};
string ss;;
int  main()
{
    cin >> ss;
    for(int i = 0; i < 3; i++){
        if(s[i] == ss)
            return cout << s[(i + 1) % 3], 0;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
using namespace std;
#define PAIR pair<string, int>
int main()
{
    int n, q;
    string name;
    int time;
    queue<PAIR> P;
    cin >> n >> q;
    for (int i = 0; i < n; i++)
    {
        cin >> name >> time;
        P.push(make_pair(name, time));
    }
    PAIR T;
    int elaps = 0, a;
    while (!P.empty())
    {
        T = P.front();
        P.pop();
        a = min(T.second, q);
        T.second -= a;
        elaps += a;
        if (T.second > 0)
        {
            P.push(T);
        }
        else
        {
            cout << T.first << " " << elaps << endl;
        }
    }
}


Measured memory_bytes: 6324
import heapq
N, M = map(int, input().split())
A = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(A)

while M:
  m = heapq.heappop(A) * (-1)
  heapq.heappush(A, (-1) * (m // 2))
  M -= 1
print (sum(A) * (-1))


Measured memory_bytes: 14180
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <string>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	int n; cin>>n;
	VI a(n); rep(i,n)cin>>a[i]; sort(ALL(a));
	int ans = 0;
	int cnt = 1;
	reps(i,n){
		if(i<n&&a[i-1]==a[i]) cnt++;
		else{
			if(cnt%2) ans++, cnt=1;
			else cnt=1;
		}
	}
	cout << ans << endl;

  return 0;
}


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

using namespace std;

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

const ll INF=1e9+7;
ll n,g;
ll a[100002],b[100001];
int main()
{
	/*freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);*/
	cin>>n;
	rep(i,n+1){
		cin>>a[i];
	}
	rep(i,n){
		cin>>b[i];
	}
	rep(i,n){
		if(b[i]<=a[i]){
			g+=b[i];
		}
		else if(b[i]-a[i]<=a[i+1]){
			g+=b[i];
			a[i+1]-=b[i]-a[i];
		}
		else{
			g+=a[i]+a[i+1];
			a[i+1]=0;
		}
	}
	cout<<g;
	return 0;
}

Measured memory_bytes: 1792
using System;

namespace Application
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			int[] a = new int[10];
			for(int i=0; i<10; i++) {
				a[i]=int.Parse(Console.ReadLine());
			}
			Array.Sort (a);
			for(int i=9; i>=7; i--) {
				Console.WriteLine("{0}",a[i]);
			}
		}
	}
}


Measured memory_bytes: 11896
// Mon Aug 24 16:24:09 IST 2020        
#include <bits/stdc++.h>        
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define forn(ii,a,b)       for(int64 ii = (int64)a ; ii < (int64)b  ; ii++ )
#define scan(any)          for(auto &i:any) cin>>i;
#define debug(x)           cerr << #x << " " << x << " -- \n"
#define I__O               ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define int64              long long   
#define all(x)             (x).begin(),(x).end() 
#define ff                 first
#define ss                 second
#define pppp               pair <int,int> 
#define flushOff           fflush(stdout) 
#define precise(x)         cout << fixed << setprecision(12) << x << '\n'; 
using namespace std ;    
// policy based   
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set ; 
 
const int MOD1 = 1e9+7;
const int MOD2 = 1e9+9;
const double pi = 3.141592653589793238;
const int INF = 2e9+7; 
// const int N = 2e5+7;
struct compare{
    bool operator()(pair <int,int> A, pair <int,int> B){
        if(A.first == B.first)
            return A.second > B.second;
        return A.first > B.first;
    }
}; 
void print(vector <int>v){
    for(int t : v){
        cout << t << ' ';
    }
    cout << '\n';
} 
const int64 big = INT64_MAX;

int tests(){ 
    int n;
    cin >> n ;
    cout << 1-n;
    return 0;
}    
int main(){
    I__O ;      
    int cases = 1 ;  
    // cin >> cases ;
    while(cases--)
        tests(); 
    return 0 ; 
}
 


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll c[100009],l[100009],r[100009],b[100009],sc[100009],sc1[100009];
main(){
    ll n,X;

    cin >> n >> X;

    vector<pair<ll,ll> > v;
    long long s = 0,ms = 0;
    for(ll i = 1; i <= n; i++){
        cin >>b[i] >> l[i] >> r[i];
        sc[i] = l[i] * b[i] + (X - b[i]) * r[i];
        s += l[i] * b[i];
        v.push_back({sc[i], i});

    }
    sort(v.rbegin(), v.rend());
    ll j= 0;
    while(j < v.size() && ms + v[j].first <= s) ms +=v[j].first,j++;
    if(ms == s) {cout<<j*X<<endl; return 0;}
    ll  ans = X+1;
    ll lo = 0, hi = X;
    while(lo < hi){
        ll mi = (lo + hi)/2;
        ll S = -1e18;
        for(ll i = 0; i < n; i++){
            ll k = v[i].second;
            if(mi <= b[k]) sc1[k] = mi* l[k];
            else sc1[k] = b[k] * l[k] + (mi -b[k] )*r[k];
        }
        for(ll i =0 ;i < j; i++)
            S = max(S, sc1[v[i].second] - sc[v[i].second]);
            bool fl = 0;
        for(ll i = j; i < v.size(); i++){
            ll k = v[i].second;
            if(sc1[k] + ms >= s) {
                hi = mi;
                fl = 1;
                break;
            }
            if(sc[k] + S + ms >= s) {
                hi = mi;
                fl = 1;
                break;
            }
        }
        if(!fl) lo = mi+1;
    }
    cout<<lo + j*X<<endl;
    //sum(r[i1]) * X
}


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

main(){
	int n ;
	while( cin >> n ){
		if( cin.eof() ) break ;
		int ans = n%39 ;
		if( !ans ) ans = 39 ;
		
		cout << "3C" ;
		if( ans < 10 ) cout << 0 ;
		cout << ans << endl ;
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int main () {
	int a = 0;
	int p[2];
	cin >> p[0] >> p[1];
	for (int i = 0; i < 2; i++) {
		int g[] = {300000, 200000, 100000};
		if (p[i] <= 3) a += g[p[i]-1];
	}
	if (a == 600000) a += 400000;
	cout << a << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO                     \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0);
typedef long long ll;
/**
 * Uncomment the #define below if problem contains multiple test cases
 */
// #define MULTIPLE_TESTS 1

void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> cnt(1e6 + 10, 0);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    ++cnt[a[i]];
  }
  sort(a.begin(), a.end());
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int cur = a[i];
    bool possible = true;
    for (int j = 1; j <= sqrt(cur); ++j) {
      if (j == cur && cnt[j] >= 2) {
        possible = false;
        break;
      }
      if (j == 1 && cnt[cur] >= 2) {
        possible = false;
        break;
      }
      if (j != cur && cur % j == 0 && cnt[j] >= 1) {
        possible = false;
        break;
      }
      if (j != 1 && cur % (cur / j) == 0 && cnt[(cur / j)] >= 1) {
        possible = false;
        break;
      }
    }
    if (possible) {
      ++ans;
    }
  }
  cout << ans << endl;
}

int main() {
  FAST_IO;
  int t = 1;
#ifdef MULTIPLE_TESTS
  cin >> t;
#endif

  while (t--) {
    solve();
  }

  return 0;
}

Measured memory_bytes: 7864
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
 
#define coutv(v) for (int i = 0; i < (v).size(); ++i) cout << v[i] << ' '; cout << endl;
#define coutvv(v) for (int i = 0; i < (v).size(); ++i) {for (int j = 0; j < (v[i]).size(); ++j) cout << v[i][j] << ' '; cout << endl;}
#define debugv(v) {for (int i = 0; i < (v).size(); ++i) cerr << v[i] << ' '; cerr << endl;}
#define debugvv(v) {for (int i = 0; i < (v).size(); ++i) {for (int j = 0; j < (v[i]).size(); ++j) cerr << v[i][j] << ' '; cerr << endl;}}
#define TC int TESTCASE; cin >> TESTCASE; while (TESTCASE--)
typedef long long ll;


int main() {
	int a,b;
	cin >> a >> b;
	if (b >= 0 && a <= 0) {
		cout << "Zero";
	}
	if (a > 0 && b > 0) {
		cout << "Positive";
	}
	if (a < 0 && b < 0) {
		if ((abs(a) - abs(b)) % 2 == 0) {
			cout << "Negative";
		} else {
			cout << "Positive";
		}
	}
}
 


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

using namespace std;
typedef long long ll;

// #define DEBUG

vector<vector<int>> connenct_list;
vector<vector<int>> connenct_list_rev;
vector<int> visit_list;
vector<int> timestamp_list;
stack<int> postorder;

int counter = 1;
void dfs_1(int k)
{
    // cout << k << x << p<< endl;
    visit_list[k] = 1;
    for (int j : connenct_list[k])
    {

        // cout << k << " " << j << endl;
        if (!visit_list[j])
        {
            dfs_1(j);
        }
    }
    timestamp_list[k] = counter;
    postorder.push(k);
    counter++;
}

void dfs_2(int k)
{
    // cout << k << x << p<< endl;
    visit_list[k] = counter;
    for (int j : connenct_list_rev[k])
    {
        // cout << k << " " << j << " " << counter << endl;
        if (!visit_list[j])
        {
            dfs_2(j);
        }
    }
}
int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int v, e, a, b, q;
    vector<pair<int, int>> node;
    vector<pair<int, int>> bridge;
    vector<pair<int, int>> query;

    cin >> v >> e;

    connenct_list.resize(v);
    connenct_list_rev.resize(v);
    timestamp_list.resize(v);
    visit_list.resize(v);

    for (int i = 0; i < e; i++)
    {
        cin >> a >> b;
        connenct_list[a].push_back(b);
        connenct_list_rev[b].push_back(a);
        node.push_back(make_pair(a, b));
    }

    cin >> q;
    for (int i = 0; i < q; i++){
        cin >> a >> b;
        query.push_back(make_pair(a, b));
    }
    
    counter = 1;
    fill(visit_list.begin(), visit_list.end(), 0);

    for (int i = 0; i < v; i++)
        if (!visit_list[i])
            dfs_1(i);

    counter = 1;
    fill(visit_list.begin(), visit_list.end(), 0);

    while (!postorder.empty())
    {
        a = postorder.top();
        postorder.pop();
        if (!visit_list[a]){
            dfs_2(a);
            counter++;
        }
    }
    // for (int i = 0; i < v; i++)
    //     cout << visit_list[i] << endl;

    for (auto x : query){
        cout << ( (visit_list[x.first] == visit_list[x.second]) ? 1 : 0) << endl;
    }
    return 0;
}



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

int main()
{
  long long int i,n;
  cin>>n;
  vector<long long int> subs(n,0);
  for(int j=1; j<n; j++)
  {
    cin>>i;
    subs[i-1]++;
  }
  for(auto s:subs)
    printf("%lld\n", s);
  return 0;
}
  


Measured memory_bytes: 4788
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <queue>
#include <deque>
#include <complex>
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> prl;
typedef pair<prl,ll> pprl;
const ll INF=ll(1)<<60;
ll node[100001];
prl small[100001];
vector<prl> edge[100001];
int main() {
	ll N,M,X,a,b,c;
	cin >> N >> M >> X;
	node[1]=X;
	FOR(i,1,N+1){
		cin >> node[i];
		small[i]=prl(INF,0);
	}
	REP(i,M){
		cin >> a>>b>>c;
		edge[a].push_back(prl(b,c));
		edge[b].push_back(prl(a,c));
	}
	queue<pprl> qup;
	qup.push(pprl(prl(0,X),1));
	small[1]=prl(0,X);
	while(!qup.empty()){
		ll point=qup.front().second;
		prl longs=qup.front().first;
		qup.pop();
		if(longs!=small[point])
		continue;
		ll dist=longs.first,tall=longs.second;
		REP(i,edge[point].size()){
			ll distWay=edge[point][i].second;
			ll next=edge[point][i].first;
			ll nDist=dist,nTall=tall;
			if(node[point]-distWay<0)
				continue;
			if(nTall-distWay<0){
				nDist+=abs(distWay-nTall);
				nTall=distWay;
			}
			if(nTall-distWay>node[next]){
				nDist+=nTall-distWay-node[next];
				nTall=node[next]+distWay;
			}
			nDist+=distWay;
			nTall-=distWay;
			if(prl(nDist,nTall)<small[next]){
				small[next]=prl(nDist,nTall);
				qup.push(pprl(small[next],next));
			}
			
		}
	}
	if(small[N].first+node[N]-small[N].second >INF/ll(10))
	cout <<-1 << endl;
	else 
	cout << small[N].first+node[N]-small[N].second << endl;
	// your code goes here
	return 0;
}

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

const int mod = 1e9 + 7, N = 1e5 + 10;

ll pw(ll a, ll b) {
    ll r = 1;
    for( ; b ; b >>= 1, a = a * a % mod) {
        if(b & 1) {
            r = r * a % mod;
        }
    }
    return r;
}

ll getinv(ll n) {
    return pw(n, mod - 2);
}

int main() {
	ll w, h, x, y;
	cin >> w >> h >> x >> y;
	int flag = 0;
	if(x * 2 == w && y * 2 == h) {
		flag = 1;
	}
	cout << fixed << setprecision(10) << (long double) (w * h) / 2.0 << ' ';
	cout << flag << endl;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);

    ll N;
    cin >> N;

    ll ans = 0;
    ll maxp = 0;
    REP(i, N){
        ll p;
        cin >> p;
        ans += p;
        maxp = max(maxp, p);
    }
    ans = ans - maxp + maxp/2;

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

Measured memory_bytes: 256
N = int(input())
S = input()

def search(c, text):
    pos = -1
    for i, s in enumerate(text):
        if s == c:
            pos = i
            break
    return pos

cnt = 0
for i in range(10):
    ip = search(str(i), S[0:])
    if ip < 0:
        continue
    for j in range(10):
        jp = search(str(j), S[ip+1:])
        if jp < 0:
            continue
        for k in range(10):
            kp = search(str(k), S[ip+jp+2:])
            if kp < 0:
                continue
            cnt += 1

print(cnt)


Measured memory_bytes: 3064
N, M = map(int, input().split())
ans = 0
mod = 10**9+7
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

fac = [0]*(M+1)
fac[0] = 1
fac[1] = 1
for i in range(2,M+1):
    fac[i] = fac[i-1] * i % mod
#nCr (mod p)
def combi(n,r,mod=10**9+7):
    return( ( fac[n] * modinv(fac[r]) )%mod * modinv(fac[n-r]) % mod)

for k in range(N+1):
    ans += (fac[M-k]*modinv(fac[M-N])) % mod * combi(N, k) * (-1)**k

print(ans*fac[M]*modinv(fac[M-N]) % mod)

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

int main() {
    int r, d, x;
    cin >> r >> d >> x;
    rep(i,10) {
        x = r*x - d;
        cout << x << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
long long a[200],n,x;
long long ans=1;
long long gcd(long long a,long long b) {
	if (b==0) return a;
	else  return gcd(b,a%b);
}
int main() {
	scanf("%d",&n);
	ans=1;
	for (int i=1;i<=n;i++)
	scanf("%lld",&x),ans=ans/gcd(ans,x)*x;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
typedef long long ll;
using namespace std;

int main(void) {
	ll L, R, tmp;
	ll min = 2019;
	scanf("%lld%lld", &L, &R);

	if (R > L + 4038) {
		R = L + 4038;
	}
	for (ll i = L; i <= R - 1; i++) {
		for (ll j = i + 1; j <= R; j++) {
			tmp = (i * j) % 2019;
			if (min > tmp) {
				min = tmp;
			}
		}
	}
	
	printf("%lld", min);

	return 0;
}

Measured memory_bytes: 128
from collections import defaultdict
N = int(input())
s = [input() for i in range(N)]
M = int(input())
t = [input() for i in range(M)]
d = defaultdict(int)
for i in range(N):
    d[s[i]] += 1
for i in range(M):
    d[t[i]] -= 1
print(max(0,max(d.values())))


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

const ll NX = 1100000;
ll dp[NX][2];
int main() {
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    s += '0';
    ll n = s.size();

    rep(i,NX) rep(j,2) dp[i][j] = INF;
    dp[0][0] = 0;
    rep(i,n) rep(j,2) {
        ll d = s[i] - '0';
        d += j;
        if(d < 10) chmin(dp[i+1][0], dp[i][j] + d);
        if(d > 0) chmin(dp[i+1][1], dp[i][j] + 10 - d);
    }
    cout << dp[n][0] << endl;
}

Measured memory_bytes: 21648
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define vector2(a,b,c) vector<vector<int>> a(b/*縦！w*/,vector<int>(c/*横！w*/))
#define INF 1e10
#define MOD 1e9+7
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; }
using Graph = vector<vector<int>>;
signed main(){
  int a;
  cin>>a;
  vector<P> b(a);
  vector<P> c(a);
  rep(i,a)
    cin>>b[i].first>>b[i].second;
  rep(i,a){
    c[i].first=b[i].first+b[i].second;
    c[i].second=b[i].first-b[i].second;
  }
    sort(all(c));
  int d=-INF,e=0;
 rep(i,a){
    if(d<=c[i].second){
  d=c[i].first;
      e++;
  }
  }
  cout<<e<<endl;
}

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

#define FOR(i,l,r) for(int i = int(l);i < int(r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N,K;
vector<int> A,B;

ll get_ans(int bit)
{
	ll res = 0;
	FOR(i,0,N) if((bit | A [i]) == bit){
		res += B [i];
	}
	return res;
}

int main()
{
	scanf("%d%d",&N,&K);
	A.assign(N,0);
	B.assign(N,0);

	FOR(i,0,N){
		scanf("%d%d",&A [i],&B [i]);
	}

	ll ans = get_ans(K);
	for(int i = 0;i < 30;i++) if(K >> i & 1){
		int x = K - (1 << i);
		x |= (1 << i) - 1;
		chmax(ans,get_ans(x));
	}
	printf("%lld\n",ans);

	return 0;
}


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

using namespace std;
const int N = 1e5 + 5, M = 16, inf = 1e9;
int a[N], cnt[M], p[M], dp[1<<M], Xor[1<<M];

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n; cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int u, v, x; cin >> u >> v >> x;
        a[u] ^= x, a[v] ^= x;
    }
    for (int i = 0; i < n; i++) cnt[a[i]]++;
    int res = cnt[0], m = 0;
    for (int i = 1; i < M; i++) {
        res += (cnt[i]>>1);
        if (cnt[i]&1) p[m++] = i;
    }
    fill(dp + 1, dp + (1<<M), -inf);
    for (int mask = 1; mask < (1<<m); mask++) {
        Xor[mask] = p[__builtin_ctz(mask)] ^ Xor[mask^(mask&(-mask))];
        for (int sub = mask; sub; sub = (sub - 1)&mask) if (Xor[sub] == 0)
            dp[mask] = max(dp[mask], dp[mask^sub] + 1);
    }
    cout << n - res - dp[(1<<m) - 1] << "\n";

    return 0;
}


Measured memory_bytes: 1024
#include <ios>
#include <iostream>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);

	int n, m = 0, i, j, k, a[10000] = {}, c = 0, p[10000] = {};
	bool b;
	
	cin >> n;
	for(i = 0; i < n; ++i){
		cin >> a[i];
		if( m < a[i] ) 
			m = a[i];
	}
	++m;
	m = min(m, 10000);
	
	for(i = 2; i < m; ++i){
		if( p[i] == 0 ){
			p[i] = 1;
			k = m/i;
			for(j = 2; j <= k; ++j)
				p[i * j] = 2;
		}
	}

	for(i = 0; i < n; ++i){
		if( a[i] <= 10000 ){
			if( p[a[i]] == 1 )
				++c;
		} else {
			b = true;
			for(j = 2; j < 10000; ++j){
				if( p[j] == 1 && a[i] % j == 0 ){
					b = false;
					break;
				}
			}
			if( b )
				++c;
		}
	}

	cout << c << "\n";

	return 0;
}

Measured memory_bytes: 1284
import java.io.*;
import java.util.*;
public class Main {
	static PrintWriter out = new PrintWriter(System.out); 

	public static void main(String[] args)throws Exception {
		try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
			
			int n = Integer.parseInt(br.readLine());
			
			Map<String,Integer> map = new HashMap<>();
			int max = 0,tmp = 0;
			for(int i = 0; i < n; i++) {
				String s =  br.readLine(); 
				
				if(map.containsKey(s)) {
					tmp = map.get(s)+1;
					map.put(s,tmp);
					max = Math.max(tmp, max);
				}else {
					map.put(s,1);
					max = Math.max(max, 1);
				}

				
			}
			
			List<String> list = new ArrayList<>();
			for(String key: map.keySet()) {
				if(map.get(key)==max) {
					list.add(key);
				}
			}
			
			Collections.sort(list);
			
			for(String a: list) {
				System.out.println(a);
			}
			out.flush();
			
		}		
		
		
	}

}


Measured memory_bytes: 66600
s = input()
t = input()
l = len(s)
m = len(t)
res = m
for j in range(l - m + 1):
  a = 0
  for i in range(m):
    if s[i + j] != t[i]:
      a += 1
  if a < res:
    res = a
print(res)

Measured memory_bytes: 8924