akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOREACH(element, vec_name) for (auto &(element) : (vec_name))

#define VECCIN(vec_name) for (auto &element : (vec_name)) cin >> element

#define dump(x) cout << #x << " = " << (x) << endl;

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

const int INF = 1e9;
const int MOD = 1e9+7;

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

int GCD(vector<int> vec){ //多入力のGCD．入力はvectorとして与える
    int g = vec[0];
    FOREACH(element, vec){
        g = gcd(g, element);
    }
    return g;
}


int main()
{
    int h;
    int n;
    cin >> h >> n;
    vector<int> a(n);
    VECCIN(a);
    int sum = 0;
    FOREACH(e,a) sum = sum + e;
    if(sum >= h) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <deque>
#include <numeric>
#include <utility>
#define sign(a) ((a>0)-(a<0))
#define LL long long
#define INF (LL)(1LL<<60)

using namespace std;


void solve(long long N, long long Z, long long W, std::vector<long long> a){
    LL ans = abs(a[N-1]-W);
    for(LL i=0; i<N-1; i++){
        auto Z2 = a[i];
        auto minv = abs(a[N-1]-Z2);
        for(LL j=i+1; j<N-1; j++){
            auto tmp = abs(a[j]-Z2);
            if(tmp < minv)minv=tmp;
        }
        if(minv==abs(a[N-1]-Z2) && (N<2 || minv <= abs(a[N-1]-a[N-2])) && minv > ans)ans=minv;
    }

    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long Z;
    scanf("%lld",&Z);
    long long W;
    scanf("%lld",&W);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, Z, W, std::move(a));
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>

using namespace std;

int main(void){
    int a, b;
    cin >> a >> b;
    std::cout << std::fixed;
    cout << a/b << " " << a%b<< " "<< setprecision(8) << (long double)a/(long double)b << endl;
}


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

using namespace std;
int D, N;
int base[100];

int main()
{
  cin >> D >> N;
  for(int i = 0; i < 100; i++) {
    if (i != 99)
      base[i] = i + 1;
    else
      base[i] = 101;
  }
  cout << int(pow(100.0, float(D)) * base[N-1]) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 //Compiler version g++ 6.3.0

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define all(a) begin(a),end(a)
#define FOR(x,val,to) for(int x=(val);x<int((to));++x)
#define FORE(x,val,to) for(auto x=(val);x<=(to);++x)
#define FORR(x,arr) for(auto &x: arr)
#define FORS(x,plus,arr) for(auto x = begin(arr)+(plus); x != end(arr); ++x)
#define FORREV(x,plus,arr) for(auto x = (arr).rbegin()+(plus); x !=(arr).rend(); ++x)
#define REE(s_) {cout<<s_<<'\n';exit(0);}
#define GET(arr) for(auto &i: (arr)) sc(i)
#define whatis(x) cerr << #x << " is " << (x) << endl;
#define e1 first
#define e2 second
#define INF 0x7f7f7f7f
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
typedef std::vector<std::string> vs;
typedef int64_t ll;
typedef uint64_t ull;
#define umap unordered_map
#define uset unordered_set
using namespace std;
using namespace __gnu_pbds;

#ifdef _WIN32
#define getchar_unlocked() _getchar_nolock()
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
template<class L, class R> ostream& operator<<(ostream &os, map<L, R> P) { for(auto const &vv: P)os<<"("<<vv.first<<","<<vv.second<<")"; return os; }
template<class T> ostream& operator<<(ostream &os, set<T> V) { os<<"[";for(auto const &vv:V)os<<vv<<","; os<<"]"; return os; }
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os<<"[";for(auto const &vv:V)os<<vv<<","; os<<"]"; return os; }
template<class L, class R> ostream& operator<<(ostream &os, pair<L, R> P) { os<<"("<<P.first<<","<<P.second<<")"; return os; }
inline int fstoi(const string &str){auto it=str.begin();bool neg=0;int num=0;if(*it=='-')neg=1;else num=*it-'0';++it;while(it<str.end()) num=num*10+(*it++-'0');if(neg)num*=-1;return num;}
inline void getch(char &x){while(x = getchar_unlocked(), x < 33){;}}
inline void getstr(string &str){str.clear(); char cur;while(cur=getchar_unlocked(),cur<33){;}while(cur>32){str+=cur;cur=getchar_unlocked();}}
template<typename T> inline bool sc(T &num){ bool neg=0; int c; num=0; while(c=getchar_unlocked(),c<33){if(c == EOF) return false;} if(c=='-'){ neg=1; c=getchar_unlocked(); } for(;c>47;c=getchar_unlocked()) num=num*10+c-48; if(neg) num*=-1; return true;}template<typename T, typename ...Args> inline void sc(T &num, Args &...args){ bool neg=0; int c; num=0; while(c=getchar_unlocked(),c<33){;} if(c=='-'){ neg=1; c=getchar_unlocked(); } for(;c>47;c=getchar_unlocked()) num=num*10+c-48; if(neg) num*=-1; sc(args...); }
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; //s.find_by_order(), s.order_of_key() <- works like lower_bound
template<typename T> using ordered_map = tree<T, int, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 1000001

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    ll n,m;
    sc(n,m);
    pair<ll,ll> a[n];
    FOR(i,0,n){
        sc(a[i].e1,a[i].e2);
    }
    sort(a,a+n);
    ll ans = 0;
    FORR(i,a){
        if(!m) break;
        int wh = min(m,i.e2);
        ans += wh*i.e1;
        m -= wh;
    }
    cout << ans << '\n';
}



Measured memory_bytes: 1792
package main

import (
	"fmt"
	"strings"
)

func main() {
	s := SingleStr()
	ss := strings.Split(s, "")
	l := len(ss)

	if l == 0 {
		fmt.Printf("%#v\n", 0)
		return
	}

	var re int
	base := ss[0]
	for i := 1; i < l; i++ {
		if base == ss[i] {
			re++
			base = reverse(base)
		} else {
			base = ss[i]
		}
	}
	fmt.Printf("%#v\n", re)
}

func reverse(v string) string {
	if v == "0" {
		return "1"
	}
	return "0"
}

func SingleStr() string {
	var s string
	fmt.Scan(&s)
	return s
}


Measured memory_bytes: 2944
import Control.Monad
import Data.List

main :: IO()
main = do
    n <- readLn
    ls <- replicateM n (map read . words <$> getLine)
    print $ getsolve (head (head ls)) (last (head ls)) (tail ls)

getsolve :: Integer -> Integer -> [[Integer]] -> Integer
getsolve tpoint apoint ls
    | ls == []								= tpoint + apoint
    | tpoint <= nextT && apoint <= nextA	= getsolve nextT nextA (tail ls)
    | otherwise								= getsolve (nextMult * nextT) (nextMult * nextA) (tail ls)
    where nextT = head (head ls)
          nextA = last (head ls)
          tMult = kiriageDiv tpoint nextT
          aMult = kiriageDiv apoint nextA
          nextMult = max tMult aMult
    

kiriageDiv :: Integer -> Integer -> Integer
kiriageDiv a b
    | mod a b == 0				= div a b
    | otherwise					= 1 + div a b



Measured memory_bytes: 1532
#include <bits/stdc++.h>
using namespace std;
const long INF=1000000000000000;

void bfs(long p,vector<vector<long>> &edge,vector<long> &cost,vector<long> &ans){
    for(int i=0;i<edge.at(p).size();i++){
        if(ans.at(edge.at(p).at(i))== -1){
            ans.at(edge.at(p).at(i))=ans.at(p)+cost.at(edge.at(p).at(i));
            bfs(edge.at(p).at(i),edge,cost,ans);
        }
    }
}


int main() {
    long N,Q;
    cin>>N>>Q;
    
    vector<vector<long>> edge(N,vector<long>());
    
    for(int i=0;i<N-1;i++){
        long a,b;
        cin>>a>>b;
        a--;
        b--;
        edge.at(a).push_back(b);
        edge.at(b).push_back(a);
    }
    
    vector<long> cost(N,0);
    for(int i=0;i<Q;i++){
        long p,x;
        cin>>p>>x;
        p--;
        cost.at(p)+=x;
    }
    vector<long> ans(N,-1);
    ans.at(0)=cost.at(0);
    bfs(0,edge,cost,ans);
    
    for(int i=0;i<N;i++){
        cout<<ans.at(i);
        if(i==N-1) cout<<endl;
        else cout<<" ";
    }
}

Measured memory_bytes: 32128
#include<stdio.h>
#include<string>
#include<iostream>
#include<math.h>
using namespace std;
#define N 317

int main(void) {
	string a, b, c;
	int i;
	cin >> a >> b;
	c = a + b;
	int x = stoi(c);
	for (i = 0;i < N;i++) {
		if (pow(i, 2) == x) {
			cout << "Yes" << endl;
			break;
		}
	}
	
	if(i==N)cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
/*input
10 4
2 0 1 3 7 5 4 6 8 9
*/
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;
const ll w = 1112333;
const ll w1 = 727272;
ll po[202020];
ll po1[202020];
struct ST
{
	ll kiek = 0;
	ll l, r;
	ll H = 0;
	ll H1 = 0;
	ST *left, *right;
	ST(ll l, ll r): l(l), r(r)
	{
		if (l < r)
		{
			left = new ST(l, (l + r) / 2);
			right = new ST((l + r) / 2 + 1, r);
		}
	}
	void set(ll i, ll x)
	{
		if (l < r)
		{
			if (i <= (l + r) / 2)
				left->set(i, x);
			else
				right->set(i, x);
			H = (left->H + right->H * po[left->kiek]) % mod;
			H1 = (left->H1 + right->H1 * po1[left->kiek]) % mod;
			kiek = left->kiek + right->kiek;
		}
		else
		{
			kiek = x;
			H = (i * kiek) % mod;
			H1 = (i * kiek) % mod;
		}
	}
} medis(0, 202000);
ll power(ll a, ll b)
{
	ll ans = 1;
	while (b > 0)
	{
		if (b % 2 == 1)
			ans = (ans * a) % mod;
		b /= 2;
		a = (a * a) % mod;
	}
	return ans;
}
int main()
{
	po[0] = 1;
	po1[0] = 1;
	for (ll i = 1; i < 202020; i++)
	{
		po[i] = (po[i - 1] * w) % mod;
		po1[i] = (po1[i - 1] * w1) % mod;
	}
	ios_base::sync_with_stdio(false);
	ll n, k;
	cin >> n >> k;
	ll p[n];
	for (ll i = 0; i < n; i++)
	{
		cin >> p[i];
		p[i]++;
	}
	set<pair<ll, ll>>ans;
	ll H[n];
	ll H1[n];
	H[0] = p[0];
	H1[0] = p[0];
	for (ll i = 1; i < n; i++)
	{
		H[i] = (p[i] * po[i] + H[i - 1]) % mod;
		H1[i] = (p[i] * po1[i] + H1[i - 1]) % mod;
	}
	auto check = [&](ll l, ll r)
	{
		ll X = 0;
		if (l != 0)
			X += H[l - 1];
		X += medis.H * po[l];
		X -= H[r];
		X %= mod;
		if (X < 0)
			X += mod;


		ll Y = 0;
		if (l != 0)
			Y += H1[l - 1];
		Y += medis.H1 * po1[l];
		Y -= H1[r];
		Y %= mod;
		if (Y < 0)
			Y += mod;
		ans.insert({X, Y});
	};
	for (ll i = 0; i < k; i++)
		medis.set(p[i], 1);
	check(0, k - 1);
	for (ll l = 1; l + k - 1 < n; l++)
	{
		medis.set(p[l - 1], 0);
		medis.set(p[l + k - 1], 1);
		check(l, l + k - 1);
	}
	cout << ans.size() << "\n";
}

Measured memory_bytes: 45824
# time complexity: O(NlogN)
# space complexity: O(N)

from fractions import gcd
from functools import reduce

def gcd_list(numbers):
    return reduce(gcd, numbers)

N, X = [int(elem) for elem in input().split(' ')]
x_list = [int(elem) for elem in input().split(' ')]
assert len(x_list) == N

difference_list = [abs(X - x) for x in x_list if X - x != 0]
max_gcd = gcd_list(difference_list)
print(max_gcd)


Measured memory_bytes: 16268
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int Y = sc.nextInt();
        int Z = sc.nextInt();
 
        int n = (X - Z) / (Y + Z);
        
        System.out.println(n);
        
    }
}

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

using namespace std;


int main(){
    string num;
    getline (cin, num);

    for(string::iterator it = num.begin(); it != num.end()-1; ++it) {
        if(*it == *(it+1)){
            cout << "Bad" << endl;
            return 0;
        }
    }

    cout << "Good" << endl;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
using namespace std;
int actionFunction(vector<vector<int>> &daysActivities) {
    if(daysActivities.size()<=0)return 0;
    vector<vector<int>> activityMax(daysActivities.size(),vector<int>(3));
    if(daysActivities.size()>0) activityMax[0]=daysActivities[0];
    for(int i=1;i<daysActivities.size();i++) {
        activityMax[i][0]=daysActivities[i][0]+max(activityMax[i-1][1],activityMax[i-1][2]);
        activityMax[i][1]=daysActivities[i][1]+max(activityMax[i-1][0],activityMax[i-1][2]);
        activityMax[i][2]=daysActivities[i][2]+max(activityMax[i-1][1],activityMax[i-1][0]);
    }
    return max({activityMax[daysActivities.size()-1][0],activityMax[daysActivities.size()-1][1],activityMax[daysActivities.size()-1][2]});
}
int main(void){
    vector<vector<int>> daysActivities;
    int n,tmp;
    cin>>n;
    for(int i=0;i<n;i++) {
        vector<int> tmpVector;
        for(int act=0;act<3;act++) {
            cin>>tmp;
            tmpVector.push_back(tmp);   
        }
        daysActivities.push_back(tmpVector);
    }
    cout<<actionFunction(daysActivities)<<endl;
    
}


Measured memory_bytes: 11696
###==================================================
### import
#import bisect
#from collections import Counter, deque, defaultdict
#from copy import deepcopy
#from functools import reduce, lru_cache
#from heapq import heappush, heappop
#import itertools
#import math
#import string
import sys
### stdin
def input(): return sys.stdin.readline()
def iIn(): return int(input())
def iInM(): return map(int, input().split())
def iInM1(): return map(int1, input().split())
def iInLH(): return list(map(int, input().split()))
def iInLH1(): return list(map(int1, input().split()))
def iInLV(n): return [iIn() for _ in range(n)]
def iInLV1(n): return [iIn()-1 for _ in range(n)]
def iInLD(n): return [iInLH() for _ in range(n)]
def iInLD1(n): return [iInLH1() for _ in range(n)]
def sInLH(): return list(input().split())
def sInLV(n): return [input().rstrip("\n") for _ in range(n)]
def sInLD(n): return [sInLH() for _ in range(n)]
### stdout
def OutH(lst): print(*lst)
def OutV(lst): print(*lst, sep="\n")
### setting
sys.setrecursionlimit(10 ** 6)
### utils
int1 = lambda x: int(x) - 1
### constants
INF = int(1e9)
MOD = 1000000007
dx = (-1, 0, 1, 0)
dy = (0, -1, 0, 1)
###---------------------------------------------------

N_ALP = 26

D = iIn()
C = iInLH()
S = iInLD(D)
T = iInLV1(D)

score = 0
past = [0] * N_ALP
for i in range(D):
    score += S[i][T[i]]
    past = [x+1 for x in past]
    past[T[i]] = 0
    for j in range(N_ALP):
        score -= C[j] * past[j]
    print(score)



Measured memory_bytes: 68364
#include <stdio.h>

int main(void){

 long long A,B;

  scanf("%lld %lld",&A,&B);

  int res = 0;

  long long tmp = A;

  while(tmp <= (long long)B){
    res++;
    tmp = tmp * 2;
  } 
  printf("%d\n",res);
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
#include<math.h>
#include<string.h>
#include<time.h>
typedef long long int ll;
int int_comp(const void*a,const void*b){return *(int*)a-*(int*)b;}
void yes(){printf("Yes\n");}
void no(){printf("No\n");}

int main(void)
{
    char s[11];
    int flg=0;
    int cnt=0;

    scanf("%s",s);
    for(int i=0;s[i]!='\0';i++){
        if(s[i]=='h'&&s[i+1]=='i'){
            i++;
        }
        else{
            flg=1;
        }
    }
    if(flg==1)no();
    else yes();
    




    return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<iostream>
#include<vector>
using namespace std;
const long long Maxn=10000+10,mval=1e18;
long long a[Maxn];
long long n=8005,m,ans;
inline long long power(long long x)
{
	return x*x*x*x*x;
}
inline long long read()
{
	long long s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0' && ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
int main()
{
	m=read();
	for(int i=1;i<=n;++i)
	a[i]=power(i-4001);
	for(int i=1;i<=n;++i)
	for(int j=1;j<=n;++j)
	if(a[i]-a[j]==m)
	{
		cout<<i-4001<<' '<<j-4001<<endl;
		return 0;
	}
	
	return 0;
}


Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
int n;
#define ll long long
ll a[300005], pref[300005], suff[300005];
int main () {
	scanf("%d", &n);
	for (int i=0; i<3*n; i++) scanf("%lld", &a[i]);
	priority_queue<ll>pq;
	ll sum=0;
	for (int i=0; i<n; i++) {
		sum+=a[i];
		pq.push(-a[i]);
		pref[i]=sum;
	}
	for (int i=n; i<3*n; i++) {
		sum+=a[i];
		pq.push(-a[i]);
		sum+=pq.top();
		pq.pop();
		pref[i]=sum;
	}
	while (!pq.empty()) pq.pop();
	sum=0;
	for (int i=3*n-1; i>=2*n; i--) {
		sum+=a[i];
		pq.push(a[i]);
		suff[i]=sum;
	}
	for (int i=2*n-1; i>=0; i--) {
		sum+=a[i];
		pq.push(a[i]);
		sum-=pq.top();
		pq.pop();
		suff[i]=sum;
	}
	ll ans=-(1LL<<61);
	for (int i=n-1; i<2*n; i++) ans=max(ans, pref[i]-suff[i+1]);
	printf("%lld\n", ans);
}

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

int main(){
  ll n,m;
  cin >> n >> m;
  vector<ll> a(n);
  ll sum = 0;
  rep(i,n){
    cin >> a.at(i);
    sum += a.at(i);
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  if( 4*m*a.at(m-1) < sum ){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
  
  return 0;
}

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

int main()
{
  int n,t,ans;
  ans=2000;
  cin>>n>>t;
  vector<int> c(n);
  vector<int> tt(n);
  for(int i=0;i<n;i++)
  {
    cin>>c.at(i)>>tt.at(i);
    if(tt.at(i)<=t)
      ans=min(ans,c.at(i));
  }
  if(ans!=2000)
    cout<<ans<<endl;
  else
    cout<<"TLE"<<endl;
}

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

using namespace std;

int main(){
    int N,buf,res;
    int a[100002];
    scanf("%d",&N);

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

    for(int i=0;i<N;i++){
        scanf("%d",&buf);
        a[buf]++;
        a[buf+1]++;
        a[buf+2]++;
    }
    
    res = 0;
    for(int i=0;i<=100001;i++){
        if(res<a[i])
            res = a[i];
    }

    printf("%d\n",res);
    
    return 0;
}

Measured memory_bytes: 640
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
N,W = map(int,input().split())
v = [0] * (N+1)
w = [0] * (N+1)

for j in range(1, N+1):
    v[j], w[j] = map(int,input().split())

dp = [[0 for i in range(W+1)] for j in range(N+1)]

for j in range(1, N+1):
    for i in range(1, W+1):
        if w[j] <= i:
            dp[j][i] = max(dp[j-1][i], dp[j-1][i-w[j]] + v[j])
        else:
            dp[j][i] = dp[j-1][i]

print(dp[N][W])

Measured memory_bytes: 27828
import itertools

def calc(nums, n, k):
    total = 0
    for i in range(k):
        total += nums[i] * n[i]
    return total

N = int(input())
k = len(str(N))

nums = [10 ** i for i in range(k)]
nums.reverse()

finish = False
count = 0
for i in range(3, k+1):
    if finish:
        break
    if i == k:
        flag = True
    else:
        flag = False
    for n in itertools.product([3,5,7], repeat=i):
        if 3 in n and 5 in n and 7 in n:
            if flag:
                if N < calc(nums, n, i):
                    finish = True
                    break
            count += 1
print(count)

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

int solve(int n,int r){
    vector<pair<int,int> >p;
    for(int i=0;i<r;i++){
        int a,b;
        cin >> a >> b;
        p.push_back(make_pair(a,b));
    }

    reverse(p.begin(),p.end());
    int x = n;
    for(vector<pair<int,int> >::iterator it=p.begin();
        it != p.end();
        ++it){
        int a = (*it).first;
        int b = (*it).second;
        if(x >= (n-b+1)){
            x = x - (a-1);
        }else if(x >= (n-b)-(a-1)+1){
            x = x + b;
        }
    }
    cout << x << endl;
}

int main(){
    int n,r;
    while(cin >> n >> r){
        if(n==0 && r==0){
            break;
        }
        solve(n,r);
    }
    return 0;
}

Measured memory_bytes: 0
X, N = map(int,input().split())
P = list(map(int,input().split()))
list = [0] * 102
res = X
dist = 102
for p in P:
    list[p] = 1
for i in range(102):
    if list[i] == 0:
        if abs(i - X) < dist:
            dist = abs(i - X)
            res = i
        elif abs(i - X) == dist:
            res = min(res,i)
print(res)


Measured memory_bytes: 9108
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i,n) cin >> a[i];
  int cnt = 0;
  REP(i,n){
    if(a[i]==cnt+1) cnt++;
  }
  
  cout << (cnt==0 ? -1 : n-cnt) << '\n';
  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
	int n;
	
	while (scanf("%d", &n) != EOF){
		if (n % 39 == 0){
			printf("3C39\n");
		}
		else if (n % 39 <= 9 && n % 39 >= 1){
			printf("3C0%d\n", n % 39);
		}
		else {
			printf("3C%d\n", n % 39);
		}
	}
	
	return (0);
}

Measured memory_bytes: 608
#include <iostream>

typedef long long ll;

class XORworld{
  private:
  	ll A, B;
  	ll func ( ll i, ll j ) {
      if ( i != 0 ) return func(0,i-1) ^ func(0,j);
      else {
	  	ll pair = (j+1) / 2;
        if ( j % 2 == 1 ) {
          if ( pair % 2 == 0 ) return 0;
          if ( pair % 2 == 1 ) return 1;
        }
        else {
          if ( pair % 2 == 0 ) return 0 ^ j;
          if ( pair % 2 == 1 ) return 1 ^ j;
        }
      }
    }
  
  public:
  	XORworld(ll A_, ll B_) : A(A_), B(B_) {
    }
  
  	void Sol(){
      std::cout << func(A, B) << std::endl;
    }
};

int main (void){
  ll A, B; std::cin >> A >> B;
  
  XORworld x(A, B); x.Sol();
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define MP make_pair
#define F first
#define S second
#define ff(i, c, n) for (ll i = c; i < n; i++)
#define fr(i, c, n) for (ll i = c; i >= n; --i)
#define INF 1e9 + 7

ll modpow(ll a, ll b, ll c)
{ //a^b%c in O(logb)
	ll res = 1;
	while (b > 0)
	{
		if (b & 1)
		{
			res = (res * a) % c;
		}
		a = (a * a) % c;
		b >>= 1;
	}
	return res;
}
ll modinv(ll m, ll n)
{ //modular inverse of n w.r.t m provided 1<=n<=(m-1) in O(logn) and m is prime
	ll inv[n + 1];
	inv[1] = 1;
	for (int i = 2; i < n + 1; ++i)
		inv[i] = (m - (m / i) * inv[m % i] % m) % m;
	return inv[n];
}

//a+b=a^b+2*(a&b)
int main()
{
	// your code goes here
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,k;
	cin>>n>>k;
	n=n%k;
	cout<<min(n,k-n);
	


	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static AtCoder.Io;
namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var abc = ReadIntArray();
            Console.WriteLine(abc.Sum() == abc.Max() * 2 ? "Yes" : "No");
        }
    }

    public static class Io
    {
        public static string ReadString() => Console.ReadLine();
        public static string[] ReadStringArray() => ReadString().Split(' ');
        public static int ReadInt() => int.Parse(ReadString());
        public static long ReadLong() => long.Parse(ReadString());
        public static int[] ReadIntArray() => ReadStringArray().ParseInt().ToArray();
        public static long[] ReadLongArray() => ReadStringArray().ParseLong().ToArray();
        public static IEnumerable<int> ParseInt(this IEnumerable<string> source) => source.Select(int.Parse);
        public static IEnumerable<long> ParseLong(this IEnumerable<string> source) => source.Select(long.Parse);
    }
}


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



int main(){
    int N; cin >> N;
    bool flag=false;
    for(int i=0; i<100; i++){
        int l = N-4*i;
        if(l>=0 && l%7==0) flag = true;
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

using namespace std;


class Solution{

public:
    long long sum(const string& s){

        if(s.size() == 1) return s[0] - '0';

        int n = (1 << (s.size() - 1));
        long long sum = 0ll;
        for(int i = 0; i < n; i ++)
            sum += eval(s, i);
        return sum;
    }

private:
    long long eval(const string& s, int state){

        long long res = 0ll;
        long long cur = s[0] - '0';

        for(int i = 1; i < s.size(); i ++){
            int op = state % 2; state /= 2;
            if(op) res += cur, cur = (s[i] - '0');
            else cur = cur * 10ll + (s[i] - '0');
        }
        res += cur;
        return res;
    }
};

int main() {

//    cout << Solution().sum("125") << endl;
//    // 176
//
//    cout << Solution().sum("9999999999") << endl;
//    // 12656242944

    string s;
    cin >> s;
    printf("%lld\n", Solution().sum(s));

    return 0;
}


Measured memory_bytes: 3232
import numpy as np

N=int(input())
arr=[int(i) for i in input().split()]

#calc binCount
binCount=np.zeros(9)
for rate in arr:
    rateBin=rate//400
    binCount[min(rateBin,8)]+=1

colorCount=int(np.sum(binCount[:-1]>0))
nc=int(np.sum(binCount[:-1]))
nf=int(binCount[-1])
assert N==(nc+nf)

if nc>0:
    minColor=colorCount
elif nf>0:
    minColor=1
else:
    minColor=0

maxColor=int(colorCount+nf)
print(minColor, maxColor)

Measured memory_bytes: 12504
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

def main():
	x=RD()

	ans=0
	s=0

	for i in x:
		if i=="S":
			s+=1
		else:
			if s==0:
				ans+=1
			else:
				s-=1

	print(ans+s)









if __name__ == "__main__":
	main()


Measured memory_bytes: 9116
# import sys
from collections import defaultdict
# input = sys.stdin.readline
def main():
    N = int( input())
    A = [ int( input()) for _ in range(N)]
    B = sorted(A)
    d = defaultdict( int)
    for i in range(N):
        d[B[i]] = i
    odd = 0
    for i in range(N):
        if (i+1)%2 == d[A[i]]%2 and d[A[i]]%2 == 1:
            odd += 1
    print(odd)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 62936
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s string
	fmt.Scan(&s)

	result := "Yes"

	if strings.Contains(s, "N") && !strings.Contains(s, "S") {
		result = "No"
	} else if !strings.Contains(s, "N") && strings.Contains(s, "S") {
		result = "No"
	}
	if strings.Contains(s, "W") && !strings.Contains(s, "E") {
		result = "No"
	} else if !strings.Contains(s, "W") && strings.Contains(s, "E") {
		result = "No"
	}

	fmt.Println(result)
}


Measured memory_bytes: 640
//
//  main.cpp
//  CP
//
//  Created by Shiv Pavan Raj on 22/02/20.
//  Copyright © 2020 Shiv Pavan Raj. All rights reserved.
//

#include <bits/stdc++.h>

using namespace std;

#define SZ(x) ((int)(x).size())
#define FOR(it,c) for ( __typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++ )
using namespace std;
typedef pair<int,int> PII;
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define M 1000000007
#define MM 998244353
#define SZ(a) int((a).size())

using ll = long long;
using VI = vector<int>;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
using VLL = vector<ll>;
using ld = long double;

int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
      
}
const int MX = 2e5+10;
const int MX2 = 1e6+5;

ll INF= 4 * (ll)1e18;
int mx = 2 * (ll)1e9 + 10;


int main(int argc, const char * argv[]) {
    
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0); // insert code here...
    string s;
    cin >> s;
    int notPalin = 0;
    int n = s.size();
    for (int i= 0;i < n /2 ; ++i) {
        if (s[i] != s[n - i - 1]) {
            notPalin = 1;
            break;
        }
        if (i < (n - 1) / 2 && s[i] != s[(n - 1) / 2 - 1 - i]) {
            notPalin = 1;
            break;
        }
        if (i >= (n + 3) / 2 - 1 && s[i] != s[n - 1 - i]) {
            notPalin = 1;
            break;
        }
    }
    if (notPalin) {
        cout <<"No"<<endl;
    }
    else {
        cout <<"Yes"<<endl;
    }
    return 0;
}






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

int main() {
  int N;
  cin >> N;
  int64_t L[N];
  L[0] = 2LL;
  L[1] = 1LL;
  
  for (int i = 2; i < N + 1; i++) {
    L[i] = L[i - 1] + L[i - 2];
  }
  
  cout << L[N] << endl;
  
}

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


using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(ll i=st; i<ed; i++)
#define repn(i, st, ed) for(ll i=st; i<=ed; i++)
#define repb(i, ed, st) for(ll i=ed; i>=st; i--)
#define all(v) v.begin(),v.end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 1e5 + 10;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}



// Main Code
bool dp[85][85][100000];
int a[85][85];
int main()
{
	int h,w;
	cin>>h>>w;
	repn(i, 1, h)
	{
		repn(j, 1, w)
		{
			cin>>a[i][j];
		}
	}
	int x;
	repn(i, 1, h)
		repn(j, 1, w)
			cin>>x, a[i][j] = abs(a[i][j] - x);
	dp[1][1][a[1][1]] = 1;
	ll ans = LONG_MAX;
	repn(i, 1, h)
	{
		repn(j, 1, w)
		{
			rep(k, 0, 10000)
			{
				if(dp[i][j][k])
				{
					int nxtk = k + abs(a[i+1][j]);
					dp[i+1][j][nxtk] = 1;
					nxtk = abs(k - abs(a[i+1][j]));
					dp[i+1][j][nxtk] = 1;
					nxtk = k + abs(a[i][j+1]);
					dp[i][j+1][nxtk] = 1;
					nxtk = abs(k - abs(a[i][j+1]));
					dp[i][j+1][nxtk] = 1;
					if(i == h && j == w)
						ans = min(ans, k);
				}
			}
			//cout<<i<<" "<<j<<endl;
		}
	}
	cout<<ans<<endl;
}


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

signed main(){
	int n;cin>>n;
	vector<int>p(n),a(n),b(n),q(n);
	for(auto&& w:p)cin>>w;
	for(int i=0;i<n;i++)q[p[i]-1]=i;

	int d=30000;

	for(int i=0;i<n;i++){a[i]=d*(i+1);b[i]=d*(n-i)+q[i];}
	for(int i=0;i<n-1;i++)cout<<a[i]<<" ";
	cout<<a[n-1]<<endl; 
	for(int i=0;i<n-1;i++)cout<<b[i]<<" ";
	cout<<b[n-1]<<endl; 

	
	
}

Measured memory_bytes: 1280
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<functional>

using namespace std;

int main(void)
{
	int array[10];
	for(int i = 0; i < 10; i++){
		cin >> array[i];
	}
	
	sort(array, array+10, greater<int>());
	
	for(int j = 0; j < 3; j++){
		cout << array[j] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1176
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,l;cin>>n>>l;
  string s;vector<string>v;
  for(int i=0;i<n;i++)
  {
    cin>>s;
    v.push_back(s);
  }
  sort(v.begin(),v.end());
  for(auto w:v)
  {
    cout<<w;
  }
  return 0;
}

Measured memory_bytes: 3652
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <queue>
#include <iomanip>
#include <algorithm>
using namespace std;

const int Maxn = 105;

int A[Maxn], B[Maxn];
int n;
int res;

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &A[i]);
		A[i] += A[i - 1];
	}
	for (int i = 1; i <= n; i++)
		scanf("%d", &B[i]);
	for (int i = n - 1; i > 0; i--)
		B[i] += B[i + 1];
	for (int i = 1; i <= n; i++)
		res = max(res, A[i] + B[i]);
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 764
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int M_1 = sc.nextInt();
		int D_1 = sc.nextInt();
		int M_2 = sc.nextInt();
		int D_2 = sc.nextInt();

		if (M_1 != M_2) {
			System.out.println("1");
		} else {
			System.out.println("0");
		}

	}
}

Measured memory_bytes: 35856
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
var n=arr.shift()-0;
while(n--){
   var ary=arr.shift().split("");
   var ans="Yes";
   var s="";
   ary.forEach(function(v){
      if(v==s)ans="No";
      s=v;
   });
   console.log(ans);
}

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  string S;
  IN(S);
  string S_1 = "";
  string S_2 = "";
  ll Q;
  IN(Q);
  bool r_flag = false;
  REP(q,Q){
    ll T;
    IN(T);
    if(T==1){
      r_flag = !r_flag;
    }else{
      ll F;
      IN(F);
      char C;
      IN(C);
      if((r_flag+F)%2){
        S_1 += C;
      }else{
        S_2 += C;
      }
    }
  }

  debug_print(S_1);
  debug_print(S_2);

  if(!r_flag){
    REP(i,S_1.size()){
      printf("%c", S_1[S_1.size()-i-1]);
    }
    REP(i,S.size()){
      printf("%c", S[i]);
    }
    REP(i,S_2.size()){
      printf("%c", S_2[i]);
    }
  }else{
    REP(i,S_2.size()){
      printf("%c", S_2[S_2.size()-i-1]);
    }
    REP(i,S.size()){
      printf("%c", S[S.size()-i-1]);
    }
    REP(i,S_1.size()){
      printf("%c", S_1[i]);
    }
  }

  printf("\n");

  return 0;
}


Measured memory_bytes: 1040
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
typedef long long ll;
using namespace std;
//#define int long long

//素数判定
inline bool IsPrime(int p) {
	if (p == 1) return false;
	for (int i = 2; i <= sqrt(p); i++) {
		if (p%i == 0) return false;
	}
	return true;
}

//10進数の自然数の桁数を返す
inline int GetDigit(int num) {
	return (int)log10(num) + 1;
}

//各位の和を返す
int GetDigitsSum(int num) {
	int N = 0;
	while (num > 0) {
		N += num % 10;
		num /= 10;
	}
	return N;
}

//互除法
ll gcd(ll a, ll b) {
	if (a < b) {
		return gcd(b, a);
	}
	else if (a%b) {
		return gcd(b, a%b);
	}
	else {
		return b;
	}
}

//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b; // Be careful not to overflow

}

//異なるn個からr個の整数を取り出す組合せの数を求める
int combination(int n, int r) {
	if (r == 0 || n == r) {
		return 1;
	}
	else if (r == 1) {
		return n;
	}
	else {
		return combination(n - 1, r - 1) + combination(n - 1, r);
	}

}

//Ｏ(√n)
//素因数分解
map<int, int> prime_factor(int n) {
	map<int, int> res; // map[i]:=ｎを素因数分解したときiは何乗か。
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			while (n % i == 0) {
				res[i]++;
				n /= i;
			}
		}
	}
	if (n != 1)
		res[n] = 1;
	return res;
}

//Ｏ(√n)
//素因数分解
map<int, int> prime_factor_ver2(int n, map<int, int> res) {
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			while (n % i == 0) {
				res[i]++;
				n /= i;
			}
		}
	}
	if (n != 1)
		res[n]++;
	return res;
}


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

	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(a*b, c*d) << endl;

	return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

A = sorted(A, reverse = True)

counter = A[0]

if N ==2:
    print(A[0])
    exit()

for i in range (1, N-1):
    if i%2 ==1:
        counter+=A[(i+1)//2]
    else:
        counter+=A[i//2]

print(counter)

Measured memory_bytes: 31620
inputlist=input().split()
s=inputlist[0]
t=inputlist[1]

aaa=input()
b=aaa.split(sep=" ")
c=list(map(int, b))

new_dict={}
new_dict[s]=c[0]
new_dict[t]=c[1]

inputfruit  =   input()
if inputfruit==s:
    ans = new_dict[s]-1
    new_dict[s] = ans
else:
    ans = new_dict[t]-1
    new_dict[t]=ans

sonoichi =new_dict[s]
sononi  =   new_dict[t]
print(sonoichi, sononi)


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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i= 0; i < N; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  int sum_a = 0, sum_b = 0;
  for (int i = 0; i < N; i++) {
    if (i%2 == 0) sum_a += a.at(a.size()-1);
    else sum_b += a.at(a.size()-1);
    a.pop_back();
  }
  cout << sum_a - sum_b << endl;
}

Measured memory_bytes: 256
//Contains functions for implementing a disjoint set union
#include<bits/stdc++.h>
using namespace std;
//#define num 1000000007
#define num 998244353
#define inf 1000000000000000000ll
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define inarr(i,a,n,A) for(ll i=a;i<n;i++) { cin>>A[i]; }
#define vll vector<long long>
#define pi pair <int,int>
#define pll pair<long long, long long>
#define vpii vector< pair <int,int>>
#define vpll vector< pair<long long, long long>>
#define max(a,b) (a>b)?a:b
//#define min(a,b) (a>b)?b:a
#define max3(a,b,c) (a>b)?(a>c)?a:c:(b>c)?b:c
#define min3(a,b,c) (a<b)?(a<c)?a:c:(b<c)?b:c
#define avg(a,b) ((a)+(b))/2
//#define push push_back
//#define pop pop_back
#define mp make_pair
#define sf int flag=0     //Remember semicolon
#define assmin(a,b) if(b<=a) { a=b; }
#define assmax(a,b) if(b>=a) { a=b; }
#define fir first
#define sec second
#define mod(a) ((a)>0)?(a):(-(a))
 
 
typedef long long ll;
 
ll next(ll a, ll n)
{
    return (a==n-1)?0:a+1;
}
ll parent[1000005],size[1000005],  tail[300005];
set<ll> cur_par;
ll n,m,q;
ll pos(ll x,ll y)
{
    return (m*(x-1))+y;
}
void init_parent(ll n)
{
    memset(parent,-1,sizeof(parent[0])*n);
}
void make_set(ll v)
{
    parent[v]=v;
    ::size[v]=1;
    tail[v]=v;
}
ll find_set(ll v)
{
    if(parent[v]==v)
    return v;
    return parent[v]=find_set(parent[v]);
}
void union_sets(ll a,ll b, ll A[])
{
    a=find_set(a);
    b=find_set(b);
    if(a==b)
    return;
    if(::size[a]<::size[b])
    {
        swap(a,b);
    }
    parent[b]=a;
    ::size[a]+=::size[b];
    A[a] = min(A[a], A[b]);
}
ll prev(ll a,ll n)
{
    if(a==0)
    return n-1;
    return a-1;
}
ll nex(ll a,ll n)
{
    if(a==n-1)
    return 0;
    else
    return a+1;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll A[n+1];
    REP(i,1,n+1)
    {
        cin>>A[i];
    }
    ll dpfloor[n+1], dpceil[n+1];
    dpfloor[1] = 0;
    dpceil[1] = A[1];
    dpfloor[2] = dpceil[2] = max(A[1], A[2]);
    REP(i,3,n+1)
    {
        if(i&1)
        {
            dpfloor[i] = max(dpfloor[i-1], dpfloor[i-2]+A[i]);
            dpceil[i] = dpceil[i-2] + A[i];
        }
        else
        {
            dpfloor[i] = dpceil[i] = max(dpceil[i-1], dpfloor[i-2]+A[i]);
        }
    }
    cout<<dpfloor[n]<<endl;
    return 0;
}


Measured memory_bytes: 8308
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
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() {
  cout << fixed << setprecision(10);

  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n){
    cin >> a[i];
  }
  vector<int> b(n);
  vector<int> c(n);
  b[0]=a[0];
  c[n-1]=a[n-1];
  for(int i=1; i<n; i++){
    b[i]=b[i-1]^a[i];
  }
  for(int i=n-2; i>=0; i--){
    c[i]=c[i+1]^a[i];
  }
  cout << c[1] << " ";
  for(int i=1; i<n-1; i++){
    int temp = b[i-1]^c[i+1];
    cout << temp << " ";
  }
  cout << b[n-2] << endl;
}


Measured memory_bytes: 5576
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
using namespace std;

#define YES(condition) if(condition) cout << "YES" << endl; else cout << "NO" << endl
#define Yes(condition) if(condition) cout << "Yes" << endl; else cout << "No" << endl
#define POSS(condition) if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl
#define Poss(condition) if(condition)cout << "Possible" << endl; else cout << "Impossible" << endl
#define First(condition) if(condition)cout << "First" << endl; else cout << "Second" << endl
#define negative(condition, num) if(condition)cout << -1 << endl; else cout << num << endl
long power(long base, long exponent, long mod){ if(exponent % 2){ return power(base, exponent - 1, mod) * base % mod; }else if(exponent){ long root_ans = power(base, exponent / 2, mod); return root_ans * root_ans % mod; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
long gcd(long a, long b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }}
#define division long(1e9 + 7)

long factorial(long n){
    if(n){
        return n * factorial(n - 1) % division;
    }else{
        return 1;
    }
}

int main(){
    long N, M;
    cin >> N >> M;
    if(abs(N - M) <= 1){
        cout << factorial(N) * factorial(M) * (!abs(N - M) + 1) % division << endl;
    }else{
        cout << 0 << endl;
    }
}


Measured memory_bytes: 1792
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <bitset>
#include <iterator>
#include <deque>
#include <string>
#include <queue>
#include <omp.h>
#include <fstream>   // ifstream, ofstream
typedef int64_t ll;
using namespace std;
const ll INF=1e16;
const double EPS=1e-8;
const ll mod = 1000000007;

int64_t powm(int64_t a,int64_t b){//a^bを求める
	if(b==0){
		return 1;
	}else{
		int64_t temp = powm(a,b/2);
		temp = temp * temp;
		if(b%2==1){
			temp = temp * a;
		}
		return temp;
	}
}

int main(){
	const double PI=3.1415926535897932;
	double r;
	cin>>r;
	cout<<setprecision(10)<<PI*2*r<<endl;


}


Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'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'};
char moji2[26]={'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'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e18 + 3)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
bool Add(int &a,int b){a = (a + b) % MOD;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

signed main(){
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    ans = 1;
    FOR(i,1,n){
        if(s[i-1] != s[i]) ans ++; 
    }
    cout << ans << endl;

}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

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

int n, k;
int dp[2][1000];

int main() {
	int N, K;
	cin >> N >> K;
	
	fill(dp[0], dp[1], 1);
	
	int *now = dp[0], *next = dp[1];
	
	FOR(i, 1, N) {
		int sum = 0;
		REP(j, K) sum += now[j];
		
		REP(j, K) next[j] = sum - now[j];
		swap(now, next);
	}
	
	int ans = 0;
	REP(i, K) ans += now[i];
	cout << ans << endl;
	return 0;
}


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

#define f(i,a,b) for(  ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x);
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define inter ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)

#define PI acos(-1)

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;

const ll MAX = 1e5+12;
const ll inf = 5e18;


ll mod = 1e9 +7;

ll p[MAX];

ll bp(ll a,ll e){
	if(e==0) return 1LL;
	if(e&1) return (a*(bp(a,e-1)))%mod;
	ll x = bp(a,e>>1);
	return (x*x)%mod; 
}

ll phi(ll a){
	ll ans=a;
	while(a>1){
		ll fac=p[a];
		while(a%fac==0) a/=fac;
		ans*=(fac-1);
		ans/=fac;
	}
	return ans;
}



int main(){
	f(i,2,MAX){
		if(p[i]==0){
			rep(j,i,MAX,i) p[j]=i;
		}
	}
	fastio;
	ll tc,n,k;
//	cin>>tc;
	cin>>n>>k;
	ll ans=0;
	f(i,1,k+1){
		ans+=(phi(i)*bp(k/i,n))%mod;
		ans=ans%mod;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 4432
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

int main() {
  int a,b,k;
  cin>>a>>b>>k;
  if(a+k-1>=b-k+1){
    for(int i=a;i<=b;i++){
      cout<<i<<endl;
    }
  }
  else{
    for(int i=a;i<=a+k-1;i++){
      cout<<i<<endl;
    }
    for(int i=b-k+1;i<=b;i++){
      cout<<i<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF 2 << 29
#define MOD 1000000007
#define Yes(f) puts((f)? "Yes" : "No")
#define YES(f) puts((f)? "YES" : "NO")
int gcd(int a, int b) {
	if (b != 0)return gcd(b, a % b);
	return a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}

using Graph = vector<vector<int>>;

int main(){
	int n, k; cin >> n >> k;
	int d[10];
	rep(i, k) cin >> d[i];
	while(true){
		bool g = true;
		for(int N = n; N; N /= 10){
			rep(i, k){
				if(N % 10 == d[i]) g = false;
			}
		}
		if(g) break;
		n++;
	}
	cout << n << endl;
}

Measured memory_bytes: 256