akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	vi a(n);
	rep(i, n) cin >> a[i];
	int f = 1;
	if(a[0] != 0){
		cout << -1 << endl;
		return 0;
	}
	ll ans = 0;
	repn(i, 1, n){
		if(a[i]){
			if((a[i] - a[i - 1]) > 1){
				f = 0;
				break;
			}
			if(a[i] != a[i - 1] + 1){
			    ans += a[i];
			}
			else ans++; //the usual
		}
	}
	if(!f){
		cout << -1 << endl;
		return 0;
	}
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/



Measured memory_bytes: 1024
#[allow(unused_imports)]
use std::io::{stdin, Read, StdinLock};
#[allow(unused_imports)]
use std::str::FromStr;
#[allow(unused_imports)]
use std::vec::Vec;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    #[allow(dead_code)]
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner {cin: cin}
    }

    #[allow(dead_code)]
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
                    .skip_while(|c| c.is_whitespace())
                    .take_while(|c| !c.is_whitespace())
                    .collect::<String>();
        token.parse::<T>().ok()
    }

    #[allow(dead_code)]
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}


fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let n: usize = sc.read();
    let k: usize = sc.read();
    let mut plan: Vec<usize> = vec![0; n];
    for _i in 0..k {
        let a: usize = sc.read();
        plan[a - 1] = sc.read();
    }

    let mut dp: Vec<Vec<i32>> = vec![vec![0; 1 << 4]; n + 1];
    dp[0][0] = 1;
    for i in 0..n {
        for b in 0..(1 << 4) {
            for p in 1..4 {
                let ban = p | (p << 2);
                if b != ban && (plan[i] == 0 || plan[i] == p) {
                    let nb = (b & 0b0011) << 2 | p;
                    dp[i + 1][nb] = (dp[i + 1][nb] + dp[i][b]) % 10000;
                }
            }
        }
    }
    println!("{}", dp[n].iter().fold(0, |sum, a| (sum + a) % 10000));
}


Measured memory_bytes: 5028
import java.util.*;


public class Main {

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

        int current = 0;
        int max = 0;
        for(int i = 0 ; i<s.length(); i++){
            char x = s.charAt(i);
            if(x=='A' || x=='C'|| x=='G'||x=='T'){
                current++;
            }else{
                current = 0;
            }
            max = Math.max(current,max);
        }
        System.out.println(max);

    }
}

Measured memory_bytes: 23124
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

N,Q=map(int,input().split())
*A,=map(int,input().split())

bit=Bit(N)
for i in range(1,N+1):
    bit.add(i,A[i-1])

abc=[list(map(int,input().split()))for _ in range(Q)]

for a,b,c in abc:
    if a:print(bit.sum(c)-bit.sum(b))
    else:bit.add(b+1,c)

Measured memory_bytes: 172352
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m,x,y;
  	cin>>n>>m>>x>>y;
  	int a=-1;
  	int b=1000000;
  	for(int i=0; i<n; i++){
		int k;	
      	cin>>k;
      	a=max(k,a);
    }
  	for(int i=0; i<m; i++){
		int k;
      	cin>>k;
      	b=min(k,b);
    }
  	for(int i=x+1; i<=y; i++){
      if(a<i&&b>=i){
        cout<<"No War"<<endl;
        return 0;
      }
    }
	cout<<"War"<<endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw_2(62,1);


int main(){
    ll N,K; cin>>N>>K;
    ll ans=0;
    vector<ll> A(N);
    vector<ll> X;
    rep(i,N){
        cin>>A[i];
    }
    sort(all(A));
    ll rem=A[0],cnt=0;
    rep(i,N){
        if(A[i]==rem) cnt++;
        else{
            X.pb(cnt);
            cnt=1;
            rem=A[i];
        }
    }
    X.pb(cnt);
    sort(all(X));
    
    if(sz(X)<=K) cout<<0<<endl;
    else{
        rep(i,sz(X)-K) ans+=X[i];
        cout<<ans<<endl;
    }
}



Measured memory_bytes: 6864
#include<cstdio>
#include<iostream>
#include<queue>

using namespace std;

int main(void){

	int num;
	double m,kg;
	queue<int> out;
	char gava;

	while(cin>>num>>gava>>kg>>gava>>m){
		if(kg/(m*m)>=25){
			out.push(num);
		}
	}

	while(!out.empty()){
		cout<<out.front()<<endl;
		out.pop();
	}

	return 0;
}

Measured memory_bytes: 1240
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    
    int H, W;
    cin >> H >> W;
    
    string S[100];
    
    for(int i = 0; i < H; i++){
        cin >> S[i];
    }
    
    for(int i = 0; i < W+2; i++){
        cout << "#";
        }
        cout << endl;
        
    for(int i = 0; i < H; i++){
        cout <<"#"<< S[i] << "#"<< endl;
    }
    
    for(int i = 0; i < W+2; i++){
        cout << "#";
    }
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long ll;
typedef pair<ll,ll> P;


int n, a, x[101];
ll dp[10101][101];

ll dfs(int num, int i){
	if(i == n){
		if(num == 5000) return 1;
		return 0;
	}
	if(dp[num][i] != -1) return dp[num][i];
	
	dp[num][i] = dfs(num+x[i], i+1) + dfs(num, i+1);
	return dp[num][i];
}

int main(){
	cin >> n >> a;
	for(int i = 0; i < n; i++){
		cin >> x[i];
		x[i] -= a;
	}
	
	for(int i = 0; i < 10101; i++){
		for(int j = 0; j < 101; j++){
			dp[i][j] = -1;
		}
	}
	
	cout << dfs(5000, 0)-1 << endl;
	
	return 0;
}

Measured memory_bytes: 8192
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math
from collections import deque
import itertools
import heapq
#import bisect
from fractions import Fraction
import copy
from functools import lru_cache
from collections import defaultdict
import pprint

#oo=list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
# ko=list("abcdefghijklmnopqrstuvwxyz")

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)

def soinsubunkai(n):
    a = []
    i = 1
    while i*i <= n:
        if n % i == 0 and i!=1:
            a.append(i)
            n=n//i

        if n% i !=0 or i==1:
            i += 1
    nokori=[n]
    return a + nokori

def soinsubunkai_e(n,m): #高速素因数分解 m[n]=nを割ることの出来る最小の素数
    a = set()
    i = 1
    while n>1:
        a.add(m[n])
        n=n//m[n]
    nokori=n
    a.add(nokori)
    return a

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


def era(n): #b[n]=nを割ることの出来る最小の素数　の配列を生成　エラトステネスの篩
    b=[i for i in range(n+1)]
    for i in range(2,int(math.sqrt(n)+10)):
        j=1
        temp=i*j
        while temp<=n:
            b[temp]=min(i,b[temp])
            temp+=i
    return b


def main():
    #l,r,d=map(int,input().split())
    n=int(input())
    ans="No"
    rep=0
    for i in range(n):
        x,y=map(int,input().split())
        if x==y:
            rep+=1
        else:
            rep=0
        if rep>=3:
            ans="Yes"
    print(ans)





if __name__ == "__main__":

    main()


Measured memory_bytes: 72780
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind
#define rt (a); return (a); 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
llint gcd(llint a, llint b) {
	if (b > a)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
llint Tow(int n) {//2のn乗
	if (n == 0)return 1;
	llint x = Tow(n / 2);
	x %= mod;
	x *= x;
	x %= mod;
	if (n % 2 == 1)x *= 10;
	x %= mod;
	return x;
}

int main(){
	string s;
	cin >> s;
	bool ans = false;
	int n = s.size();
	for (int bit = 0; bit < (1 << 4); bit++) {
		string akiba = "";
		if (bit & (1 << 0))akiba += "A";
		akiba += "KIH";
		if (bit & (1 << 1))akiba += "A";
		akiba += "B";
		if (bit & (1 << 2))akiba += "A";
		akiba += "R";
		if (bit & (1 << 3))akiba += "A";
		if (s == akiba)ans = true;
	}
	YES(ans)
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x,a,b;
  cin>>x>>a>>b;
  if(abs(x-a)<abs(x-b)){
    cout<<'A'<<endl;
  }
  else if(abs(x-a)>abs(x-b)){
    cout<<'B'<<endl;
  }
}


Measured memory_bytes: 256
nk = input().split(' ');
n = int(nk[0]);
k = int(nk[1]);
p = input().split(' ');
p = list(map(int,p));

e = [0] *n;
ruiseki = [0]*(n+1);

for i in range(n) :
	e[i] = p[i]*(p[i]+1)//2/p[i];
	ruiseki[i+1] = ruiseki[i] + e[i];

ans = 0;
for i in range(n-(k-1)) :
	if ans < ruiseki[i+k] - ruiseki[i] :
		ans = ruiseki[i+k] - ruiseki[i];

print(ans);

Measured memory_bytes: 25060
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s, t;
    cin >> s >> t;
    int m = s.size(); int n = t.size();
    vector<vector<int>> dp(n+1, vector<int>(m+1,0));
    for(int i=0; i<m+1; ++i) dp[0][i] = i;

    for(int i=0; i<n; ++i){
        dp[i+1][0] = i+1;
        for(int j=0; j<m; ++j){
            int cost = (t[i]==s[j]) ? 0 : 1;
            dp[i+1][j+1] = min(dp[i+1][j]+1, min(dp[i][j+1]+1, dp[i][j]+cost));
        }
    }

    cout << dp[n][m]<< endl;
    
}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

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

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const string YES = "YES";
const string NO = "NO";

int main(){
    int a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    if (w > v) {
        cout << NO << endl;
        return 0;
    }
    int d = abs(b - a);
    int s = v - w;
    if (d <= (ll)t * s) cout << YES << endl;
    else cout << NO << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<typename T> using rev_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using vector2d = vector<vector<T>>;
template<class S, class T> void map_init(map<S, T> &m, S k, T v){if(!m.count(k)) m[k] = v;}
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }
int main() {
    int N;
    cin >> N;
    vector<int> d(N);
    for(auto &x : d) cin >> x;
    i64 ans = 0;
    for(int i = 0; i < N; i++) {
        for(int j = i + 1; j < N; j++) {
            ans += d[i] * d[j];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (n, q) = readLine()!!.split(" ").map { it.toInt() }
    val s = readLine()!!
    val lr = (1..q).map { readLine()!!.split(" ").map { it.toInt() } }
    
    var cumsum = Array(n + 1) { 0 }

    for (i in 1 until n) {
        if (s[i - 1] == 'A' && s[i] == 'C') {
            cumsum[i + 1] = cumsum[i] + 1
        } else {
            cumsum[i + 1] = cumsum[i]
        }
    }

    for ((l, r) in lr) {
        val ans = cumsum[r] - cumsum[l]
        println(ans)
    }
}

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

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;

string A[50];
string B[50];

int main()
{
	int N, M;
	bool ans = false;

	cin >> N >> M;
	rep(i, N) cin >> A[i];
	rep(i, M) cin >> B[i];

	rep(i, N - M + 1) {
		rep(j, N - M + 1) {
			bool tmp = true;

			rep(k, M) {
				if (A[i + k].substr(j, M) != B[k]) {
					tmp = false;
				}
			}

			ans = tmp;
			if (ans) break;
		}
		if (ans) break;
	}

	cout << (ans ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 256
def main():
    S = input()
    n = len(S)

    ans = 0
    for i in range(1<<n-1):
        t = ''
        for j in range(n):
            t += S[j]
            if i & (1 << j):
                t += '+'
        ans += eval(t)

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
H,W,D = map(int,input().split())
Point = {}
for y in range(H) :
    line = list(map(int,input().split()))
    for x,p in enumerate(line) :
        Point[p] = (y,x)

Q = int(input())

def dist(ny,nx,py,px) :
    return abs(ny-py) + abs(nx-px)

Cost = [0]*(H*W+1)
for i in range(D+1, H*W+1) :
    yi,xi = Point[i-D]
    yj,xj = Point[i]
    Cost[i] = Cost[i-D] + dist(yi,xi,yj,xj)


for i in range(Q) :
    l,r = map(int,input().split())
    print(Cost[r] - Cost[l])


Measured memory_bytes: 22620
#include <iostream>
#include<bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
vector<P> v;
ll n,a[100000],b[100000],c[100000],p,q,ans,rans,pp=1e9;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>p>>q;
        v.push_back({p,-q});
        pp=min(pp,q);
    }
    sort(v.begin(),v.end());
    for(int i=0;i<n;i++){
        v[i].S=-v[i].S;
        //cout<<v[i].S<<endl;
    }
    b[0]=v[0].S;
    for(int i=1;i<n-1;i++){
        b[i]=min(b[i-1],v[i].S);
    }
    c[n-2]=v[n-1].S;
    for(int i=n-2;i>0;i--){
        c[i-1]=min(c[i],v[i].S);
    }
    for(int i=0;i<n-1;i++){
        //cout<<b[i]<<" "<<v[i].F<<" "<<c[i]<<" "<<v[n-1].F<<endl;
        rans=max(0LL,b[i]-v[i].F)+max(0LL,c[i]-v[n-1].F);
        //cout<<rans<<endl;
        if(b[i]-v[i].F>=0)rans++;
        if(c[i]-v[n-1].F>=0)rans++;
        rans=max(rans,max(0LL,pp-v[n-1].F+1)+v[i].S-v[i].F+1);
        ans=max(ans,rans);
    }
    cout<<ans<<endl;
}


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

//#define int long long
typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    set<pair<int,int>> p;
    if (N%2==0){
        for (int i=1;i<=N/2;i++){
            p.insert(make_pair(i,N+1-i));
        }
    } else {
        for (int i=1;i<=N/2;i++){
            p.insert(make_pair(i,N-i));
        }
    }
    vector<pair<int,int>> ans;
    for (int i=1;i<N;i++){
        for (int j=i+1;j<=N;j++){
            if (p.find(make_pair(i,j)) == p.end()){
                ans.emplace_back(i,j);
            }
        }
    }
    cout << ans.size() << "\n";
    for (int i=0;i<ans.size();i++){
        cout << ans[i].first << " " << ans[i].second << "\n";
    }
}

Measured memory_bytes: 3724
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<queue>

#define ipair pair<int,int>
#define rep(i,n) for(i=0;i<n;i++)

using namespace std;

typedef long long int lli;
typedef vector<int> vi;

int main() {
	lli s, c, i, j, k;

	cin >> s >> c;

	if (s * 2 > c) {
		i = c / 2;
	}
	else if (s * 2 == c) {
		i = s;
	}
	else {
		i = s;
		c -= s * 2;
		i += c / 4;
	}

	cout << i;

	return 0;
}

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

namespace AtCoderBeginnerContest157
{
	class Program
	{
		static void Main(string[] args)
		{
			var nm = ReadIntArray();
			var pairs = new List<int[]>(nm[1]);
			for(var i = 0; i < nm[1]; i++)
			{
				var tmp = ReadIntArray();
				if ((nm[0] != 1  &&  tmp[0] == 1 && tmp[1] == 0)
					|| (i != 0 && pairs.Any(x => x[0] == tmp[0] && x[1] != tmp[1])))
				{
					Console.WriteLine("-1");
					return;
				}
				pairs.Add(tmp);
			}

			switch (nm[0])
			{
				case 1:
				{
					if(nm[1] != 0 && pairs.Any(x => x[0] == 1))
					{
						Console.WriteLine(pairs.Where(x => x[0] == 1).ToArray()[0][1]);
						return;
					}
					else
					{
						Console.WriteLine(0);
						return;
					}
				}
				case 2:
				{
					var two = 1;
					var one = 0;
					if(nm[1] != 0 && pairs.Any(x => x[0] == 1))
					{
						two = pairs.Where(x => x[0] == 1).ToArray()[0][1];
					}
					if(nm[1] != 0 && pairs.Any(x => x[0] == 2))
					{
						one = pairs.Where(x => x[0] == 2).ToArray()[0][1];
					}
					Console.WriteLine(two * 10 + one);
					return;
				}
				case 3:
				{
					var three = 1;
					var two = 0;
					var one = 0;
					if (nm[1] != 0 && pairs.Any(x => x[0] == 1))
					{
						three = pairs.Where(x => x[0] == 1).ToArray()[0][1];
					}
					if (nm[1] != 0 && pairs.Any(x => x[0] == 2))
					{
						two = pairs.Where(x => x[0] == 2).ToArray()[0][1];
					}
					if (nm[1] != 0 && pairs.Any(x => x[0] == 3))
					{
						one = pairs.Where(x => x[0] == 3).ToArray()[0][1];
					}
					Console.WriteLine(three * 100 + two * 10 + one);
					return;
				}
			}
		}

		public static int ReadInt()
			=> int.Parse(Console.ReadLine());

		public static int[] ReadIntArray()
			=> Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

		public static long ReadLong()
			=> long.Parse(Console.ReadLine());

		public static long[] ReadLongArray()
			=> Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();

		public static string ReadString()
			=> Console.ReadLine();

		public static string[] ReadStringArray()
			=> Console.ReadLine().Split();
	}
}


Measured memory_bytes: 13524
#include<iostream>
using namespace std;
int main(){
	int a,b,c,d,e,f,g=0,w,h,n,y,z;
	cin >> w >> h >> n;
	int x[h][w]={0};
	for(a=0;a<n;a++){
		cin >> b >> c >> d;
		if(d==1){
			for(e=0;e<h;e++){
				for(f=0;f<b;f++){
					x[e][f]=1;
				}
			}
		}
		if(d==2){
			for(e=0;e<h;e++){
				for(f=b;f<w;f++){
					x[e][f]=1;
				}
			}
		}
		if(d==3){
			for(e=h-c;e<h;e++){
				for(f=0;f<w;f++){
					x[e][f]=1;
				}
			}
			
		}
		if(d==4){
			for(e=0;e<h-c;e++){
				for(f=0;f<w;f++){
					x[e][f]=1;
				}
			}
		}
	}
	for(y=0;y<h;y++){
		for(z=0;z<w;z++){
			if(x[y][z]==0){
				g++;
			}
		}
	}
	cout << g;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  double lon=0;
  double n;
  cin>> n;
  double x[10],y[10];
  for(int i=0;i<n;i++){
    cin>>x[i]>>y[i];
  }
  for(int k=0;k<n-1;k++){
    for(int i=k+1;i<n;i++){
      lon+=sqrt((x[k]-x[i])*(x[k]-x[i])+(y[k]-y[i])*(y[k]-y[i]));
    }
  }
  cout<<fixed;
  cout<<setprecision(10)<<lon*2/n<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

int N;
double p[3010];

// dp[i][j]: i枚目までコインを投げて，表がj枚出る確率
// (i-1番までのコイン)
double dp[3010][3010];

int main()
{
  cin >> N;
  REP(i,0,N) cin >> p[i];

  // Init:
  // REP(i,0,N+1) REP(j,0,N+1) dp[i][j] = 0; // 0に初期化
  dp[0][0] = 1;

  // Update:
  // REP(i,0,N) REP(j,0,N) {
  //   // i+1回目が表/裏で場合分け
  //   // dp[i+1][j+1] = dp[i][j] * p[i+1] + dp[i][j+1] * (1.0 - p[i+1]);
  // }
  REP(i,0,N+1) REP(j,0,N+1) {
    // (i,j) を計算 (貰う)
    // dp[i][j] = 0; (i,j)が(0,0)のとき以外
    // i回目が表 (i-1枚目のコインを投げる)
    if (i >= 1 && j >= 1) dp[i][j] += dp[i-1][j-1] * p[i-1];
    // i回目が裏
    if (i >= 1) dp[i][j] += dp[i-1][j] * (1.0 - p[i-1]);
  }

  // 表の個数が裏の個数を上回る確率
  double res = 0.0;
  REP(j,0,N+1) {
    if (j > N - j) res += dp[N][j];
  }
  cout << fixed << setprecision(10) << res << endl;

  return 0;
}


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

using namespace std;
using namespace std;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e9+7;
const ll mod = 1e9+7;

int main(){
    ll n,a,b,c,d,e;
    cin>>n>>a>>b>>c>>d>>e;

    ll MIN=min({a,b,c,d,e});

    cout<<(n+MIN-1)/MIN+4<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using std::cin;
using std::cout;
using std::endl;
using std::string;

int main() 
{
	string date;

	// input
	cin >> date;

	// output
	cout << ( (date <= "2019/04/30") ? "Heisei" : "TBD" );
	cout << endl;

	return 0;
}

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

int main() {
	string s;
	cin>>s;
	bool found=false;
	char left, right;
	left = s[0];
	right = s[1];
	if(left==right)
	{
		found=true;
		cout<<"1 2";
	}
	if(s.size()>2)
	{
		for(int i=2;i<s.size();i++)
		{
			if(found) break;
			if(s[i]==left || s[i]==right)
			{
				found=true;
				cout<<i-1<<" "<<i+1;
				break;
			}
			left = right;
			right = s[i];
		}
	}
	if(!found)
	cout<<"-1 -1";
	return 0;
}

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

//#define int long long

using namespace std;
#define REP(i, s, n) for(signed i = (s); i < signed(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(co) co.begin(), co.end()

typedef pair<int, int> P;
typedef unsigned long long LL;

#ifdef int
const long long INF = 1ll << 61ll;
#else
const signed INF = 1 << 29;
#endif

template<typename T = int>
vector<vector<T>> vvector(int h, int w, T def = T()) { return move(vector<vector<T>>(h, vector<T>(w, def))); }


signed main() {

	int n, k;
	while (scanf("%d %d", &n, &k) && n)
	{
		n++;
		vector<int> dp(n + 2);
		bool white = false;
		rep(i, k) {
			int x; cin >> x;
			if(x) dp[x] = 1;
			else white = true;
		}
		rep(i, n) if (dp[i + 1]) dp[i + 1] = dp[i + 1] + dp[i];
		rep(i, n) if (dp[n - i]) dp[n - i] = max(dp[n - i], dp[n - i + 1]);
		int ans = 0;
		rep(i, n - 1) ans = max(ans, (white && !dp[i + 1] ? dp[i] + dp[i + 1] + dp[i + 2] + 1 : dp[i + 1]));
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1528
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int p[] = new int[N];
		int val = 0;
		for(int i = 0;i < N;i++) {
			p[i]  = sc.nextInt();
			
		}
		Arrays.sort(p);	
		p[N-1] = p[N-1] / 2;
		for(int i = 0;i < N;i++) {
			val = val + p[i];
		}
		System.out.println(val);
		sc.close();
	}
}

Measured memory_bytes: 23764
N, M = map(int, input().split())
dd = {}
for i in range(1, N+1):
    dd[i] = []
temp = list(map(int, input().split()))
li_h = [0]
li_h.extend(temp)
for i in range(M):
    a, b= map(int, input().split())
    dd[a].append(b)
    dd[b].append(a)
#print(dd)
ans = 0
d = {}
for i in range(1, N+1):
    d[i] = True
for i in range(1, N+1):
        if not d:
            continue
        else:
            for k in dd[i]:
                if li_h[k] < li_h[i]:
                    d[k] = False
                elif li_h[k] == li_h[i]:
                    d[k] = False
                    d[i] = False
                    break
                else:
                    d[i] = False
                    break
            if d[i]:
                ans += 1
                #print(i)
            else:
                continue
print(ans)


Measured memory_bytes: 50916
import java.util.*;
import static java.lang.Math.*;

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

		// 入力
		String x = sc.next();
		String y = sc.next();
		
		// 計算
		String result = "=";

		if(x.compareTo(y) > 0){
		    result = ">";
		}else if(x.compareTo(y) < 0){
		    result = "<";
		}

		// 出力
		System.out.println(result);
	}
}




Measured memory_bytes: 23892
from collections import defaultdict
d=defaultdict(int)
n,m=map(int,input().split())
l=list(map(int,input().split()))
for i in l:
  d[i]+=1
for i in range(m):
  b,c=map(int,input().split())
  d[c]+=b
count=[]
for i in d:
  count.append([i,d[i]])
count=sorted(count)
count=count[::-1]
count1=0
now=0
ans=0
while count1<n:
  if count[now][1]+count1>n:
    ans+=count[now][0]*(n-count1)
    count1=n
  else:
    ans+=count[now][0]*count[now][1]
    count1+=count[now][1]
    now+=1
print(ans)

Measured memory_bytes: 49056
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = ((B)-1); I >= (A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define pri(a) cout << (a) << endl

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll N,W;
	cin >> N >> W;
	vector<ll> v(N),w(N);
	FOR(i,0,N)cin>>v[i]>>w[i];
	ll dp[2][10200],ans=0;
	FOR(j,0,10200)dp[1][j] = dp[0][j] = MOD;
	dp[0][0] = dp[1][0] = 0;
	FOR(i,1,N+1){
		FOR(j,0,N*101){
			ll k = i%2;
			ll l = 1-k;
			dp[k][j] = min(dp[l][j],dp[k][j]);
			dp[k][j+v[i-1]] = min(dp[l][j+v[i-1]],dp[l][j]+w[i-1]);
		}
	}
	FOR(i,0,2){
		FOR(j,0,N*101){
			if(dp[i][j]<=W)ans = max(ans,j);
		}
	}
	cout << ans << endl;
}


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

int main(void)
{
    int n, x, t;
    int ans, mod;

    cin >> n;
    cin >> x;
    cin >> t;

    ans = n / x;
    mod = n % x;

    if(mod != 0){
        ans += 1;
    }

    cout << ans * t;

    return 0;
}

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

int main() 
{
	vector<long long> loc[1<<17];
	int n, m; 
	cin >> n >> m;
	vector<int> a(n), b(n);
	for(int i=0;i<n;i++) {
		cin >> a[i] >> b[i];
	}
	for(int i=0;i<n;i++) 
	{
		if (m - a[i] < 0)
			continue;
		loc[m - a[i]].push_back(b[i]);
	}
	long long ans = 0;
	priority_queue<long long> q;
	for (int i = m; i >= 0; i--) {
		for(int j=0;j<loc[i].size();j++)
			q.push(loc[i][j]);
		if (!q.empty()) {
			ans += q.top(); q.pop();
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 7168
#include <cstdio>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <climits>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <deque>
#include <vector>
#include <string>
#include <bitset>
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define INF 1000000007
#define PI acos(-1.0)
#define endl "\n"
#define IOS cin.tie(0);ios::sync_with_stdio(false)
#define MP_ make_pair
#define PB_ push_back
#define FIR first
#define SEC second
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP_R(i,n) for(int i=((int)(n)-1);i>=0;--i)
#define FOR(i,m,n) for(int i=((int)(m));i<(int)(n);++i)
#define FOR_R(i,m,n) for(int i=((int)(m)-1);i>=(int)(n);--i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define SIZ(x) ((int)(x).size())
typedef long long int lli;
using namespace std;
int c2i(char c){switch(c){case '0':return 0;case '1':return 1;case '2':return 2;case '3':return 3;case '4':return 4;case '5':return 5;case '6':return 6; case '7':return 7;case '8':return 8;case '9':return 9;default:return -1;}}



int digiS(int n)
{
  int cnt = 0;
  int m = n;
  string S = to_string(m);
  
  REP(i,SIZ(S))
    {
      cnt += c2i(S[i]);
      
    }
  return cnt;
  
  
}

int main()
{
  IOS; /* making cin faster */
  int N;
  cin >> N;

  int b;
  int mn = INF;
  
  FOR(a,1,N)
    {
      b = N - a;

      if( digiS(a) + digiS(b) < mn )
	{
	  mn = digiS(a) + digiS(b);
	  
	}
      
    }

  
  cout << mn << endl;
  

}


Measured memory_bytes: 256
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let a: i32 = read();
    let b: i32 = read();

    println!("{}", std::cmp::max(a - b * 2, 0));
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  ll n;
  cin >> n;
  vector<P> p(n);
  rep(i,n){
    cin >> p[i].first;
    p[i].second=i;
  }
  sort(p.begin(),p.end());
  reverse(p.begin(),p.end());
  /*rep(i,n){
    cout << p[i].first << " " << p[i].second << endl;
  }*/
  vvl dp(n,vl(n+1,0));
  dp[0][0]=p[0].first*abs(p[0].second-n+1);
  dp[0][1]=p[0].first*p[0].second;//ここまでOK
  FOR(i,1,n){
    ll x=p[i].second,v=p[i].first;
    rep(j,i+2){
      if(i*j!=0){
        dp[i][j]=max(dp[i-1][j]+abs(x-(n-i+j-1))*v,dp[i-1][j-1]+abs(x-j+1)*v);
      }
      else if(j==0){
        dp[i][j]=dp[i-1][j]+abs(x-(n-i-1))*v;
      }
    }
  }
  /*rep(i,n){
    rep(j,n+1){
      cout << i << " " << j << ":" << dp[i][j] << endl;
    }
  }*/
  ll ans=0;
  rep(i,n+1){
    ans =max(ans,dp[n-1][i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 34688
#include <stdio.h>

int main(void)
{
	int a,b,i;
	char op;


	for(i = 0; i < 10000; i++)
	{
		scanf("%d %c %d",&a,&op,&b);
		if(op == '?')
		{
			break;
		}else if(op == '+')
		{
			printf("%d\n",a + b);
		}else if(op == '-')
		{
			printf("%d\n", a - b);
		}else if(op == '*')
		{
			printf("%d\n",a * b);
		}else
		{
			printf("%d\n",a / b);
		}
	}
	return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<algorithm>
using namespace std;
int n,ans;
int a[10];
main()
{
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        ans+=a[i];
    }
    sort(a,a+n);
    ans+=(a[n-1]/2);
    cout<<ans-a[n-1]<<endl;  
}

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

int main()
{
	ios::sync_with_stdio(false);
	
	int N,M,c;
	int a[25][25];
	int b[25];
	
	cin>>N>>M>>c;
	for(int i=1;i<=M;i++) cin>>b[i];
	for(int i=1;i<=N;i++)
		for(int j=1;j<=M;j++) cin>>a[i][j];
	int res=0;
	for(int i=1;i<=N;i++)
	{
		int sum=0;
		for(int j=1;j<=M;j++)
		{
			sum+=a[i][j]*b[j];
		}
		res+=(sum+c>0);
	}
	cout<<res;
}


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

int main()
{
    int a[50], n, p, q;

    while( cin >> n >> p )
    {
        if( n == 0 && p == 0 )
            break;

        for( int i = 0; i < 50; i++ )
            a[i] = 0;

        q = p;
        
        for( int i = 0; i < n; i++, i %= n )
        {
            if( p > 0 )
            {
                a[i]++;
                p--;
            }
            else if( a[i] != q )
            {
                p += a[i];
                a[i] = 0;
            }
            else
            {
                cout << i << endl;
                break;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1000000000000000LL
using pint = pair<int,int>;
using vec = vector<int>;
using ll=long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


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

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

    for(int i=0; i<1e7; i++){
        if(a%2==1 || b%2==1 || c%2==1){
            cout<<i<<endl;
            return 0;
        }

        int x=(b+c)/2;
        int y=(a+c)/2;
        int z=(b+a)/2;

        a=x;
        b=y;
        c=z;
    }
    cout<<-1<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/
 
int main(){
    int N; cin >> N;
    string s; cin >> s;
 
    vector<int> a(N, 0);
    int b = 1000000;
 
 
    if(s[0] == '(') a[0] = 1;
    else a[0] = -1;
    b = min(b, a[0]);
 
    for(int i=1; i<N; i++){
        if(s[i] == '(') a[i] = a[i-1]+1;
        else a[i] = a[i-1]-1;
 
        b = min(b, a[i]);
    }
 
    if(b < 0){
        for(int i=0; i<-b; i++) s = '(' + s;
        a[N-1] = a[N-1]-b;
    }
    for(int i=0; i<a[N-1]; i++) s += ')';
 
    cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#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;
typedef pair<dd,dd> d_d;
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);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
//template<class T>void max(T a,T b){if(a<b)return b;else return a;}
//template<class T>void min(T a,T b){if(a>b)return b;else return a;}
//template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;}
//template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;}

//////////////////////////


int main(){fastio
    ll n,k;cin>>n>>k;
    vector<ll>d(k);rep(i,0,k-1)cin>>d[i];
    rep(i,n,inf){
        string s=to_string(i);
        bool f=true;
        rep(j,0,s.size()-1){
            rep(x,0,k-1){
                if((s[j]-'0')==d[x])f=false;
            }
        }
        if(f){
            cout<<i<<endl;return 0;
        }
    }
    
    return 0;
}


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

std::vector<int> vec;
int n, p, a, b;

int main() {
  std::cin >> n;
  for (int i = 0; i < n; i++) {
    std::cin >> p;
    vec.push_back(p);
  }
  std::sort(vec.begin(), vec.end(), std::greater<int>());
  a = 0;
  b = 0;
  for (int i = 0; i < vec.size(); i++) {
    if (i % 2 == 0) {
      a += vec[i];
    }
    else {
      b += vec[i];
    }
  }
  std::cout << (a - b) << std::endl;
}

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

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template <typename T> using pq = priority_queue<T>;
template <typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template <typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for (auto &i : mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template <class T> ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template <class T> istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template <class T> ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    ll diff = 0;
    if (m2 >= m1) {
        diff += m2 - m1;
        diff += 60 * (h2 - h1);
    }
    else {
        diff += (60 - (m1 - m2));
        diff += 60 * (h2 - 1 - h1);
    }
    cout << diff - k << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}


Measured memory_bytes: 3684
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;

typedef unsigned long long LL;

LL Combination(int n, int r){
	if(n < 0 || r < 0 || r > n) return 0;

	if(n - r < r) r = n - r;
	if(r == 0) return (LL)1;
	if(r == 1) return (LL)n;

	int *numerator   = (int*)calloc(r, sizeof(int));
	int *denominator = (int*)calloc(r, sizeof(int));
	if(numerator == NULL || denominator == NULL) return 0;

	for(int i=0; i<r; i++){
		numerator[i] = n - r + 1 + i;
		denominator[i] = i + 1;
	}

	for(int p=2; p<=r; p++){
		int pivot = denominator[p-1];
		if(pivot > 1){
			int offset = (n - r) % p;
			for(int k=p-1; k<r; k+=p){
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	LL res = 1;
	for(int i=0; i<r; i++){
		if(numerator[i]) res *= numerator[i];
	}
	return res;
}

LL N, P;

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

	cin >> N >> P;
	long long odd = 0, even = 0;
	for(int i=0; i<N; i++){
		long long a;
		cin >> a;
		if((a % 2) == 0){
			even++;
		}
		else{
			odd++;
		}
	}

	LL ans = 0;
	if(P == 0){
		for(int i=0; i<=odd; i+=2){
			for(int j=0; j<=even; j++){
				ans += ( Combination(odd, i)*Combination(even, j) );
			}
		}
	}
	else{
		for(int i=1; i<=odd; i+=2){
			for(int j=0; j<=even; j++){
				ans += ( Combination(odd, i)*Combination(even, j) );
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3724
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>



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

using namespace std;
int d,n;
int main(){
  cin >> d >> n;
  if (n==100) n=101;
  if (d==0) cout << n << endl;
  else if(d==1) cout << 100 * n << endl;
  else if(d==2) cout << 10000 * n << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
  private static int solve(int[] a) {
    int prev = a[0];
    int count = 0;
    for (int i = 1; i < a.length; i++) {
      if (a[i] == prev) {
        count++;
        prev = 0;
      } else {
        prev = a[i];
      }
    }
    return count;
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int n = reader.nextInt();
    int[] a = reader.nextIntArray(n);
    out.println(solve(a));
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public int[] nextIntArray(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLongArray(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
}

class Algorithm {
  private static void swap(Object[] list, int a, int b) {
    Object tmp = list[a];
    list[a] = list[b];
    list[b] = tmp;
  }
  
  public static <T extends Comparable<? super T>> boolean nextPermutation(T[] ts) {
    int rightMostAscendingOrderIndex = ts.length - 2;
    while (rightMostAscendingOrderIndex >= 0 &&
        ts[rightMostAscendingOrderIndex].compareTo(ts[rightMostAscendingOrderIndex + 1]) >= 0) {
      rightMostAscendingOrderIndex--;
    }
    if (rightMostAscendingOrderIndex < 0) {
      return false;
    }
    
    int rightMostGreatorIndex = ts.length - 1;
    while (ts[rightMostAscendingOrderIndex].compareTo(ts[rightMostGreatorIndex]) >= 0) {
      rightMostGreatorIndex--;
    }
    
    swap(ts, rightMostAscendingOrderIndex, rightMostGreatorIndex);
    for (int i = 0; i < (ts.length - rightMostAscendingOrderIndex - 1) / 2; i++) {
      swap(ts, rightMostAscendingOrderIndex + 1 + i, ts.length - 1 - i);
    }
    return true;
  }
}



Measured memory_bytes: 21460
#include <stdio.h>
int main(void){
	int n;
	int x = 0;
	scanf("%d", &n);
	for(int i=1; i<=n; i++){
		int a;
		scanf("%d", &a);
		if(i%2 == 1 && a%2 == 1){
			x++;
		}
	}
	printf("%d\n", x);
	return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
set <string> st;
cin >> n;

vector<string> s(n+1);
for (int i = 1;i <= n;i++) {
    cin >> s[i];
   st.insert(s[i]);
}
sort (s.begin(),s.end());
//cout << endl;
map<string,int> cnt;
int ma=-1;
//cout << s[0] << " " <<s[1] << endl;
for (int i = 1;i <= n;i++){
    cnt[s[i]]++;
    //cout << s[i] << " " << cnt[s[i]] << endl;

    //cout << s[i] << endl;
    ma = max(cnt[s[i]],ma);
    //cout << ma << endl; 
}
for (string s:st){
    //cout << s << endl;
    //cout << endl;
    if(cnt[s]==ma) cout << s << endl;
}

}

Measured memory_bytes: 36096
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
void READ() {
#define R READ();
#define INFI 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define MEMX(x,num) memset(x,num,sizeof(x))
#define prln(x) cout<<#x<<"="<<x<<endl
#define sz(x) int(x.size())
#define PB(x) push_back(x)
#define LINK(x,y) G[x].PB(y),G[y].PB(x)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#ifndef ONLINE_JUDGE
    freopen("A.in", "r", stdin);
#endif
    std::ios::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed << setprecision(6);
}
///////////////////////////
const int N = 5 + 2e5;

int n;
int tot, a[N], dp[N], pre[N], ansid, ma;
map<int,int>lst;
int main() {
    
    cin >> n;
    rep(i, 1, n) {
        cin >> a[i];
        lst[ a[i] ]=i;
        dp[i]=dp[ lst[a[i]-1] ]+1;
        pre[i]=lst[a[i]-1];
        if(dp[i]>ma)ma=dp[i],ansid=i;
    }
    cout <<n- ma << '\n';
    return 0;
}



Measured memory_bytes: 11904