akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int result = 0;
		for(int i = 1; i <= n; i++) {
			int index = i;
			int sum = 0;
			while(index != 0) {
				sum += index % 10;
				index /= 10; 
			}
			if(sum >= a && sum <= b) {
				result += i;
			}
		}
		System.out.println(result);
		
		

		
	}
}

Measured memory_bytes: 21716
class LazySegmentTreeBase
  def initialize(arr, l = 0, r = arr.size - 1)
    @l, @r = l, r
    @lazy = nil
    if l == r
      @agg = arr[l]
    else
      c = (l + r) / 2
      @left_child = self.class.new(arr, l, c)
      @right_child = self.class.new(arr, c + 1, r)
      @agg = aggregation_of(@left_child.agg, @right_child.agg)
    end
  end

  attr_reader :agg, :l, :r

  def update(l, r, x)
    if l == @l && r == @r
      defer(x)
    else
      force
      if r <= @left_child.r
        @left_child.update(l, r, x)
      elsif @right_child.l <= l
        @right_child.update(l, r, x)
      else
        @left_child.update(l, @left_child.r, x)
        @right_child.update(@right_child.l, r, x)
      end
      @left_child.force
      @right_child.force
      @agg = aggregation_of(@left_child.agg, @right_child.agg)
    end
  end

  def force
    return if !@lazy
    x = @lazy
    @lazy = nil
    whole_update(x)
    @left_child.update(@left_child.l, @left_child.r, x) if @left_child
    @right_child.update(@right_child.l, @right_child.r, x) if @right_child
  end

  def query(l, r)
    force
    return @agg if l == @l && r == @r
    if r <= @left_child.r
      return @left_child.query(l, r)
    elsif @right_child.l <= l
      return @right_child.query(l, r)
    else
      agg_left = @left_child.query(l, @left_child.r)
      agg_right = @right_child.query(@right_child.l, r)
      return aggregation_of(agg_left, agg_right)
    end
  end
end

class LazySegmentTree < LazySegmentTreeBase
  def initialize(arr, l = 0, r = arr.size - 1)
    super(arr, l, r)
  end

  def defer(x)
    @lazy = x
  end

  def whole_update(x)
    @agg = x
  end

  def aggregation_of(x, y)
    [x, y].min
  end
end

n, q = gets.split.map(&:to_i)
seg = LazySegmentTree.new(Array.new(n, 2 ** 31 - 1))
q.times do
  c, x, y, z = gets.split.map(&:to_i)
  if c == 0
    seg.update(x, y, z)
  else
    puts seg.query(x, y) 
  end
end


Measured memory_bytes: 34976
#include <iostream>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  if((N+1)%27==0 || (N+14)%27==0)cout<<":("<<endl;
  else if(double(N/1.08)-int(N/1.08)>0)cout<<int(N/1.08)+1<<endl;
  else cout<<N/1.08<<endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b

signed main(){
	int n; cin>>n;
	map<string,int> mp;
	vi v(n+1);
	rep(i,1,n+1){
		string s; cin>>s;
		int a; cin>>a;
		mp[s]=i;
		v[i]=a+v[i-1];
	}
	string x; cin>>x;
	int j=mp[x];
	cout<<v[n]-v[j]<<endl;
	
	return 0;
}

Measured memory_bytes: 3612
import math

n=int(input())
a=list(map(int,input().split()))
table={}
fact_table={}
total=0
for i in a:
    if i in table:
        table[i]+=1
    else:
        table[i]=1
for key in table:
    if table[key]>=2:
        fact_table[key]=math.factorial(table[key])//(math.factorial(2)*math.factorial(table[key]-2))
        total+=fact_table[key]
    else:
        fact_table[key]=0
for i in a:
    ans=total-fact_table[i]+((table[i]-2)*fact_table[i])//table[i]
    print(ans)

Measured memory_bytes: 116172
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

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

int n,a[250010],dist[510][510],val[510][510];

inline void dfs(int x,int y)
{
	for(int dir=0;dir<4;dir++){
		int nx=x+dx[dir],ny=y+dy[dir];
		if(nx<=0||ny<=0||nx>n||ny>n) continue;
		if(dist[nx][ny]>dist[x][y]+val[x][y]){
			dist[nx][ny]=dist[x][y]+val[x][y];
			dfs(nx,ny);
		}
	}
}

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n*n;i++) cin>>a[i];
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			val[i][j]=1;
			dist[i][j]=min(min(i-1,n-i),min(j-1,n-j));
		}
	}
	int ans=0;
	for(int i=1;i<=n*n;i++){
		int x=(a[i]-1)/n+1,y=(a[i]-1)%n+1;
		ans+=dist[x][y];val[x][y]=0;
		dfs(x,y);
	}
	cout<<ans<<endl;
	return 0;
}

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

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int num = Integer.parseInt(in.nextLine());
		int[] values = new int[num];
		String[] tokens = in.nextLine().split(" ");
		for (int i = 0; i < num; ++i) {
			values[i] = Integer.parseInt(tokens[i]);
		}
		Arrays.sort(values);
		System.out.println(values[values.length - 1] + " " + solve(values));
		in.close();
	}

	public static int solve(int[] values) {
		if(values.length <= 2 ) {
			return values[0];
		}
		int total = values[values.length - 1];
		double medium = (double) total / 2.0;
		double diff = Double.MAX_VALUE;
		int result = -1;
		for (int i = 0; i < values.length - 2; ++i) {
			if (diff > Math.abs(medium - (double) values[i])) {
				diff = Math.abs(medium - (double) values[i]);
				result = values[i];
			}
		}
		return result;
	}
}


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

int main()
{
	string s;
	cin >> s;
	map<char, bool> M;
	for (auto o : s)
	{
		if(M[o])
		{
			cout << "no" << endl;
			return 0;
		}
		M[o] = 1;
	}
	cout << "yes" << endl;
	return 0;
}

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

const int N=1000;

int main(){
    while(true){
        string s;
        
        cin >> s;
        
        if(s == "0") break;
        
        int sum = 0;
        for(int i=0; i<(int)s.size(); ++i){
            sum += s[i] - '0';
        }
        
        cout << sum << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
using int64 = int64_t;
#define int int64

signed main() {
  // 2*10^5
  // SSTTでもおK
  // +1+2+1+0
  // SとTのペアを作らせればおk

  string x;cin>>x;
  int s=0,t=0;
  for(int i=0;i<x.size();++i){
    if (x[i] == 'S'){
      ++s;
      continue;
    }
    // t
    if (s>0) {
      --s;
      continue;
    }
    ++t;
  }
  int ans = s+t;
  cout << ans << endl;
	
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
    x=0;char c=getchar();bool f=0;
    while(!isdigit(c)) f|=c=='-',c=getchar();
    while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
    if(f) x=-x;return  x;
}
template<class t> inline void write(t x){
    if(x<0){putchar('-'),write(-x);}
    else{if(x>9)write(x/10);putchar('0'+x%10);}
}





string s,ss,sss;
map<string,int> a;

signed main(){
	cin>>s>>ss;
	cin>>a[s]>>a[ss];
	cin>>sss;
	a[sss]--;
	cout<<a[s]<<" "<<a[ss];
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
ph = h[0]
ans = 0
st = 0
for i in range(1, n):
    if h[i] <= ph:
        st += 1
        ans = max(ans, st)
    else:
        st = 0
    ph = h[i]
print(ans)

Measured memory_bytes: 20468
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))
a.sort(reverse=True)

cand1 = 2 * sum(a[:n//2-1]) + a[n//2-1] \
        + (1 if n%2 else -1) * a[n//2] - 2 * sum(a[n//2+1:])
cand2 = 2 * sum(a[:(n-1)//2]) + (-1 if n%2 else 1) * a[(n-1)//2] \
        - a[(n-1)//2+1] - 2 * sum(a[(n-1)//2+2:])
print(max(cand1, cand2))


Measured memory_bytes: 7512
s = input()
s_list = [s[_] for _ in range(len(s))]

output = list()
for c in s_list:
  if c == '0':
    output.append('0')
  elif c == '1':
    output.append('1')
  else:
    if len(output) > 0:
      output.pop()
print(''.join(output))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    string s,t;
    cin>>s>>t;
    if(s.size()>t.size())
    {
        cout<<"GREATER"<<endl;
    }
    else if(s.size()<t.size())
    {
        cout<<"LESS"<<endl;
    }
    else if(s.size()==t.size())
    {
        if(s==t)
        {
            cout<<"EQUAL"<<endl;
        }
        else
        {
            for(ll i=0; i<s.size(); i++)
            {
                if(s[i]>t[i])
                {
                    cout<<"GREATER"<<endl;
                    break;
                }
                else if(s[i]<t[i])
                {
                    cout<<"LESS"<<endl;
                    break;
                }
            }
        }
    }
    return 0;
}


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

A = [0]+list(map(int,input().split()))+[0]

fee = []
for i in range(1,n+2):
    fee.append(abs(A[i]-A[i-1]))

a = sum(fee)

for i in range(n):
    print(a-fee[i]-fee[i+1]+abs(A[i]-A[i+2]))

Measured memory_bytes: 85776
#include <iostream>
#include <stdio.h>
#include <set>
#include<bits/stdc++.h>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
#include <vector>
#include <algorithm>
using namespace std;
int pos(int a ){
    if(a>=0){return a;}
    return -a;
}
int main(){
    int x , n;
    cin>>x>>n;
    int arr[105] = {0};
    for(int i = 0;i<n;i++){
    int z;
    cin>>z;
    arr[z] = 1;
    }
    int a  = 1000000;
    int b = 0;
    for(int i = -1;i<= 101;i++){
        if(i>=0 ){
            if(arr[i] ){continue;}
            if(pos(i-x)<a   ){
                a = pos(i-x);
                b = i;
            }
        }
        else{
            if(pos(i-x)<a   ){
                a = pos(i-x);
                b = i;
            }
        }
    }
    cout<<b;
}


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

int main(){
    string S,T;
    cin>>S>>T;

    char a=S.at(0);
    char b=S.at(1);
    char c=S.at(2);

    int ans=0;

    if(a==T.at(0))ans++;
    if(b==T.at(1))ans++;
    if(c==T.at(2))ans++;
    cout<<ans<<endl;
    
}

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  for(int i=0;i<s.size();i++){
    s[i] += n;
    if(s[i] > 'Z'){
      s[i]='A'+(s[i]-'Z')-1;
    }
  }
    cout << s << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>

using namespace std;

int main(void)
{
	int n;
	cin >> n;
	vector<int> h(n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &h[i]);
	}

	for (int i = n - 2; i >= 0; i--) {
		if (h[i] >= h[i + 1] + 2) {
			cout << "No" << endl;
			return 0;
		}
		else if(h[i] == h[i+1] + 1){
			h[i]--;
		}
	}

	cout << "Yes" << endl;
	return 0;
}

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

int main(){
    int n,s[10000],q,t,c=0;
    cin>>n;
    for(int i=0;i<n;i++) cin>>s[i];
    cin>>q;
    for(int i=0;i<q;i++){
        cin>>t;
        for(int j=0;j<n;j++){
            if(s[j]==t){
                c++;
                break;
            }
        }
    }
    cout<<c<<endl;
}


Measured memory_bytes: 3112
#pragma warning(disable:4996)
#define loop(i,start,stop) for(int i = start; i < stop; i++)
#define rloop(j,start,stop) for(int j = start; j >= stop; j--)
#include <stdio.h>
#include <iostream>
#include <math.h>
using namespace std;

int A, B;
char s[12];

int strlen_(char* str) {
        char* p = str;
        while (*p++);
        return p - str - 1;
}


int main() {
//        freopen("foo.txt", "r" ,stdin);
        cin >> A >> B;
        scanf("%s", s);
        int len = strlen_(s);

        if (len != A + B + 1) {
                puts("No");
                return 0;
        }
        if (s[A] != '-') {
                puts("No");
                return 0;
        }

        loop(i, 0, A) {
                if (s[i] < '0' || s[i] > '9') {
                        puts("No");
                        return 0;
                }
        }
        loop(i, A+1, A+B+1) {
                if (s[i] < '0' || s[i] > '9') {
                        puts("No");
                        return 0;
                }
        }
        puts("Yes");
        return 0;
}

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

class Program
{
    static void Main()
    {
        var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = a[0];
        var r = a[1];
        Console.WriteLine(n >= 10 ? r : r + 100 * (10 - n));
    }
}

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

int main(void){
    int N;
    cin >> N;
    vector<pair<ll,ll>> a(N);
    for(int i = 0; i < N; i++){
        cin >> a.at(i).second >> a.at(i).first;
    }
    sort(a.begin(), a.end());
    ll tim = 0;
    int ans = 1;
    for(int i = 0; i < N; i++){
        tim += a.at(i).second;
        if(tim > a.at(i).first){
            ans = 0;
            break;
        }
    }
    if(ans == 0){
        printf("No");
    }
    else{
        printf("Yes");
    }
}

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

int main(){
  int n, m;
  cin >> n;
  vector<string> sn(n);
  for(int i = 0; i < n; i++)
    cin >> sn.at(i);
  cin >> m;
  vector<string> tm(m);
  for(int i = 0; i < m; i++)
    cin >> tm.at(i);
  vector<int> sna(n), tna(n);
  for(int i = 0; i < n; i++){
    sna.at(i) = 0;
    tna.at(i) = 0;
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      if(sn.at(i) == sn.at(j))
        sna.at(i)++;
    }
    for(int j = 0; j < m; j++){
      if(sn.at(i) == tm.at(j))
        tna.at(i)++;
    }
  }
  int s = 0;
  for(int i = 0; i < n; i++)
  s = max(s, sna.at(i) - tna.at(i));
  cout << s << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <iostream>

#pragma comment(linker, "/STACK:336777216")  

using namespace std;

const int MAXN = 500000 + 10;

int N;
char S[MAXN];
int DP[MAXN];

void Work()
{
	scanf("%d%s", &N, S + 1);
	int lastone = 0;
	for (int i = 1; i <= 2; i ++)
	{
		if (S[i] == '1') lastone ++;
		else lastone = 0;
	}
	for (int i = 3; i <= N; i ++)
	{
		if (S[i] == '1') lastone ++;
		else lastone = 0;

		DP[i] = DP[i - 1];
		if (S[i] == '1' && S[i - 1] == '0')
		{
			for (int j = i - 2; j >= 1; j --)
				if (S[j] == '1')
					DP[i] = max(DP[i], DP[j - 1] + (i - 1 - j));
				else
					break;
		}
		
		if (lastone >= 1 && i - lastone - 1 >= 1 && S[i - lastone] == '0' && S[i - lastone - 1] == '1')
			DP[i] = max(DP[i], DP[i - lastone - 2] + lastone);
	}
	printf("%d\n", DP[N]);
}

int main()
{
	Work();
	return 0;
}

Measured memory_bytes: 2688
import math
a = list(range(5))
a[0] = int(input())
a[1] = int(input())
a[2] = int(input())
a[3] = int(input())
a[4] = int(input())
b = list(range(5))
c = list(range(5))
d = 0
s = 9
e = 0
total = 0
v = 0
for i in range(5):
    if((a[i]%10)==0):
        b[d] = a[i]
        d += 1
        v += 1
    else:
        if((a[i]%10)<s):
            s = a[i]%10
for i in range(5):
    if((a[i]%10)!=0):
        e = a[i]/10
        e = math.ceil(e)
        e = e*10
        b[d] = e
        d += 1
for i in range(5):
    total += b[i]
if(v != 5):
    total -= 10
    total += s
print(total)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define Rep(var,init,cnt) for(int (var)=(init); (var)<(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(rall(v))
#define SUM(v) accumulate(all(v),0)
#define tget(tp,idx) get<idx>(tp)
#define TF(flag) (flag)?1:0
#define yn(f) cout<<(f?"yes":"no")<<endl
#define Yn(f) cout<<(f?"Yes":"No")<<endl
#define YN(f) cout<<(f?"YES":"NO")<<endl
#define COUT(x) cout<<(x)<<endl
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using ti = tuple<int,int,int>;
using tl = tuple<ll,ll,ll>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;
template<typename T>
using cub = vector<mat<T>>;
template<typename T>
using val = valarray<T>;

template<typename T>
using pq = priority_queue<T>;
template<typename T>
using rpq = priority_queue<T,vec<T>,greater<T>>;

template<typename T1,typename T2>
ostream &operator<<(ostream &os, const pair<T1,T2> &p){
  os<<"P("<<p.first<<", "<<p.second<<") ";
  return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is, pair<T1,T2> &p){
  is>>p.first>>p.second;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &v){
  for(T &in:v) is>>in;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const valarray<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, valarray<T> &v){
  for(T &in:v) is>>in;
  return is;
}

// Usual Template End ================================================

// Template End ======================================================

constexpr int MOD=1e9+7;

int main(void){
  int a; cin>>a; COUT(48-a);
}













Measured memory_bytes: 256
#include<iostream>
using namespace std;
int Tru(int x,int y){
  int c=0;

  while(c!=x+1){
    if(2*c+4*(x-c)==y){
      return 2;
    }
	c++;
 }
 return 1;
}
int main(){
	int x,y;
	cin>>x>>y;
  if(Tru(x,y)==2)
    cout<<"Yes";
  else
    cout<<"No";
  return 0;
}
 

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) rep(i,v.size())cout<<v[i]<<(i==v.size()-1?"\n":" ");
#define vout(v) VOUT(v,z);
#define vdbg(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL)
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
// template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
// template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
bool is_palindrome(string s){return s == string(s.rbegin(),s.rend());}
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
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;
}



int main(){
    long long X;
    scanf("%lld",&X);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> p(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&p[i]);
    }
    if(N==0){
        cout << X << endl;
        return 0;
    }
    SORT(p);
    bool f=false;
    for (long long i = 0; i < N; i++) {
        if(p[i]==X){
            f=true;
            break;
        }
    }
    if(f==false){
        cout << X << endl;
        return 0;
    }

    ll large, small;
    for (long long i = 0; i <= 100; i++) {
        auto res=find(all(p), X+i);
        if(res==p.end()){
            large=X+i;
            break;
        }
    }
    for (long long i = 0; i <= 100; i++) {
        auto res=find(all(p), X-i);
        if(res==p.end()){
            small=X-i;
            break;
        }
    }
    if(abs(large-X) < abs(X-small)){
        cout << large << endl;
    }else{
        cout << small << endl;
    }
    // cout << min(large-X, small) << endl;

    // vector<ll> v(100);
    // for (long long i = 0; i < 100; i++) {
    //     v[i]=i+1;
    // }
    // for (long long i = 0; i < N; i++) {
    //     if(v[i]==)
    // }

    return 0;
}


Measured memory_bytes: 3696
#coding: euc-jp
class Main
  def self.main
    min = 123
    max = 0
    5.times do
      a = read
      min = a if a < min
      max = a if a > max
    end
    k = read
    puts max - min <= k ? 'Yay!' : ':('
  end

  def self.read
    gets.chomp.to_i
  end
end

Main.main


Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int N;
P t[500000];

int main(){
  scanf("%d",&N);
  for(int i=0;i<N;i++){
    scanf("%lld %lld",&t[i].first,&t[i].second);
  }
  sort(t,t+N);
  ll ans=t[0].second;
  
  ll sum=t[0].second;
  ll mix=t[0].first;
  
  for(int i=1;i<N;i++){
    ll tmp = sum + t[i].second - (t[i].first - mix);
    ans=max(ans,tmp);
    ans=max(ans,t[i].second);
    if( tmp < t[i].second ){
      mix=t[i].first;
      sum=t[i].second;
    }else{
      sum+=t[i].second;
    }
  }

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



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

int main(){
	int n, m;
	char c;
	int count = 0;
	cin >> n;
	for(int i=0; i < n; i++){
		cin >> c >> m;
		if(c == '(') count += m;
		else count -= m;

		if(count < 0){
			cout << "NO" << endl;
			return 0;
		}
	}
	if(count == 0) cout << "YES" << endl;
	else cout << "NO" << endl;
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,n) for(int i=1;i<=n;i++)
#define sint(i) scanf("%d",&i);
#define sintt(i,j) scanf("%d%d",&i,&j);
#define sinttt(i,j,k) scanf("%d%d%d",&i,&j,&k);

#define INF 1010000000

int masu[1001][1001];
int dp[1001][1001];

int n,m,k;
int xx,yy;

void saiki(int x,int y,int masu[1001][1001]){
	//printf("%d %d\n",y,x);
	if(x>=m || y>=n){
		xx=x+1;
		yy=y+1;
		return;
	}
	
	if(masu[x][y]==1){
		saiki(x+1,y,masu);
	}else{
		saiki(x,y+1,masu);
	}
}

int main(){
	while(1){
		sinttt(n,m,k);
		if(n==0)break;
		rep(i,n){
			rep(j,m){
				sint(masu[j][i]);
			}
		}
		
		rep(i,1001){
			rep(j,1001)dp[i][j]=0;
		}
		
		dp[0][0]=k-1;
		rep(j,n){
			rep(i,m){
				if(dp[i][j]%2==0){
					dp[i][j+1]+=dp[i][j]/2;
					dp[i+1][j]+=dp[i][j]/2;
				}else{
					if(masu[i][j]==1){
						dp[i][j+1]+=dp[i][j]/2;
						dp[i+1][j]+=dp[i][j]/2+1;
					}else{
						dp[i][j+1]+=dp[i][j]/2+1;
						dp[i+1][j]+=dp[i][j]/2;
					}
				}
			}
		}
		
		rep(j,n){
			rep(i,m){
				if(dp[i][j]%2==1){
					masu[i][j]=!masu[i][j];
				}
			}
		}
		
		saiki(0,0,masu);
		printf("%d %d\n",yy,xx);
		
		/*
		
		puts("");
		rep(i,n){
			rep(j,m){
				printf("%d ",dp[j][i]);
			}puts("");
		}
		puts("");
		rep(i,n){
			rep(j,m){
				printf("%d ",masu[j][i]);
			}puts("");
		}*/
	}
}
/*
3 4 2
1 0 1 1
0 1 0 0
1 0 1 0
0 0 0

*/

Measured memory_bytes: 8708
#include <stdio.h>

int main(void)
{
	int n;
	scanf("%d",&n);
	
	int a[n];
	
	int i;
	
	for(i = 0; i < n; i++){
		scanf("%d",&a[i]);
	}
	
	int max = a[0];
	
	for(i = 0; i < n; i++){
		if(a[i] > max){
			max = a[i];
		}
	}
	
	int sum = 0;
	
	for(i = 0; i < n; i++){
		sum = sum + a[i];
	}
	
	sum = sum - max/2;
	
	printf("%d\n",sum);
	
	return 0;
}
	
	
	
	

Measured memory_bytes: 256
n,y=map(int,input().split())
flag=False
l=[]
for i in range(n+1):
    for j in range(n-i+1):
        if 10000*i+5000*j+1000*(n-i-j)==y:
            flag=True
            l.append([i,j,n-i-j])
            break
        else:
            pass
    if flag:
        break
if flag:
    print(str(l[0][0])+" "+str(l[0][1])+" "+str(l[0][2]))
else:
    print("-1 -1 -1")


Measured memory_bytes: 3064
#include<stdio.h>

int main(){
  int x, y, a, save;

  scanf("%d%d",&x, &y);

  while(1){
    if(x < y){
      save =y;
      y = x;
      x = save;
    }

    a = x % y;
    if(a == 0) {
      printf("%d\n", y);
      return 0;
    }else{
      x = y;
      y = a;
    }
  }

  return 0;
}



Measured memory_bytes: 2148
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(ll i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
//typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
vector<vs>in(6,vs(3));
string q="201133221122";
int w[]={2,2,1};
int main(){
	while(1){
		string t;cin>>t;
		if(t=="#")return 0;
		rep(i,6)rep(j,3){
			if(i+j==0)in[i][j]=t;
			else cin>>in[i][j];
		}
		rep(i,3){
			reverse(all(in[2][i]));
			reverse(all(in[3][i]));
		}
		rep(i,3)
			swap(in[5][0][i],in[5][2][i]);

		int out=inf;
		rep(E,3)rep(k,2)rep(e,2){
			int j=0,i=E;
			if(e)j=2;
			if(E==2)i=4;
			bool h=true;
			bool H=false;
			rep(l,3)if(k&&in[i][l][j]=='*'||!k&&in[i][j][l]=='*')H=true;
			if(!H)h=false;
			H=false;
			rep(l,3)if(k&&in[i+w[E]][l][j]=='*'||!k&&in[i+w[E]][j][l]=='*')H=true;
			if(!H)h=false;
			if(h)out=min(out,q[E*4+k*2+e]-'0');
		}
		cout<<out<<endl;
	}
}







Measured memory_bytes: 3164
A[10000],B[10000];z(int*a,int*b){return*b-*a;}
main(n,i,j){for(;scanf("%d",&n),n;puts(i>n?"No":"Yes")){
for(i=0;i<n;i++)scanf("%d",A+i);
qsort(A,n,4,z);
for(i=0;i<n;i++)scanf("%d",B+i);
for(i=0;i<n;i++){for(j=0;j<n;j++)if(B[j])A[i]--,B[j]--;if(A[i])i=n;}
}exit(0);}

Measured memory_bytes: 736
#include <bits/stdc++.h>
#define MAXN 102
#define MAXM 100004

using namespace std;

long long peso[MAXN], tab[MAXN][MAXM], value[MAXN];
int n;


long long knapsack(int obj, long long aguenta)
{
    
    if(tab[obj][aguenta] >= 0)
    {
        return tab[obj][aguenta];
    }
    if(obj == n || !aguenta)
    {
        return 0;
    }

    long long nao_coloca = knapsack(obj + 1, aguenta);

    if(peso[obj] <= aguenta)
    {
        long long coloca = knapsack(obj + 1, aguenta - peso[obj]) + value[obj];
        return tab[obj][aguenta] = max(coloca, nao_coloca);

    }

    return tab[obj][aguenta] = nao_coloca;


}
 


int main(){

    
    long long limit;

    
        cin >> n >> limit;
        memset(tab, -1, sizeof(tab));
        for (int i = 0; i < n; ++i)
        {
            cin >> peso[i] >> value[i];
        }
        

        cout << knapsack(0, limit) << endl;

    

    











    

    
    return 0;
}


Measured memory_bytes: 80000
#include<stdio.h>
int main(void)
{
	int a,b;
	scanf("%d",&a);
	scanf("%d",&b);
	 if(a==1)	{
		 a=13+a;
	 }
	 if(b==1)	{
		 b=13+b;
	 }
	 if(a>b)	{
		 printf("Alice\n");
	 }
	 if(a<b)	{
		 printf("Bob\n");
	 }
	 if(a==b)	{
		 printf("Draw\n");
	 }
	 return 0;
}


Measured memory_bytes: 128
AB, BC, AC = [int(_) for _ in input().split(" ")]

M = [[0, AB, AC],
     [AB, 0, BC],
     [AC, BC, 0]]

def A(l):
    t = [0] * l
    def Sub(targetList, n):
        if 1:
            if len(targetList) == 1:
                t[n] = targetList[0]
                yield t
                t[n] = 0
            for i in range(len(targetList)):
                p = targetList[:i] + targetList[i+1:]
                t[n] = targetList[i]
                for j in Sub(p, n+1):
                    yield j
        else:
            pass
    
    for i in (Sub(tuple(range(l)), 0)):
        yield i

def Calc(list):
    _sum = 0
    for index in range(1, len(list)):
        _from = list[index-1]
        _to = list[index]
        _sum += M[_from][_to]
    return _sum

_min = Calc([0,1,2])
for i in A(3):
    _sum = Calc(i)
    if _min > _sum:
        _min = _sum
print (_min)
        

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <map>
#include <utility>
#define LL long long
using namespace std;
const int Maxn = 310;
int mp[Maxn][Maxn], tot;
int n, m;
char s[Maxn][Maxn];
int f[2][Maxn<<1][Maxn], g[2][Maxn<<1][Maxn];
int ffind(int x, int y) {
	if(x < 0 || x >= n || y < 0 || y >= m) return 0;
	return mp[x][y] > 0 ? 1 : 0;
}
int calcf(int op, int x, int y) {
	if(y < 0 || x < 0 || x > n-1+m-1) return 0;
	if(y >= n) return f[op][x][n-1];
	return f[op][x][y];
}
int calcg(int op, int x, int y) {
	if(y < 0 || x < 0 || x > n-1+m-1) return 0;
	if(y >= n) return g[op][x][n-1];
	return g[op][x][y];
}
int main() {
	int i, j, k;
	scanf("%d%d", &n, &m);
	for(i = 0; i < n; i++) scanf("%s", s[i]);
	for(i = 0; i < n; i++){
		for(j = 0; j < m; j++){
			if(s[i][j] == '#') mp[i][j] = ++tot;
		}
	}
	for(i = 0; i < n; i++){
		for(j = 0; j < m; j++){
			if(mp[i][j] == 0) continue;
			f[0][i+m-1-j][i] = 1;
			f[1][i+j][i] = 1;
		}
	}
	for(i = 0; i <= n-1+m-1; i++){
		for(j = 1; j < n; j++){
			f[0][i][j] += f[0][i][j-1];
			f[1][i][j] += f[1][i][j-1];
		}
	}
	LL ans = 0;
	for(k = 2; k <= n+m; k += 2){
		memset(g, 0, sizeof(g));
		for(i = 0; i < n; i++){
			for(j = 0; j < m; j++){
				if(mp[i][j] == 0) continue;
				g[0][i+m-1-j][i] = ffind(i-k/2, j-k/2);
				g[1][i+j][i] = ffind(i-k/2, j+k/2);
			}
		}
		for(i = 0; i <= n-1+m-1; i++){
			for(j = 1; j < n; j++){
				g[0][i][j] += g[0][i][j-1];
				g[1][i][j] += g[1][i][j-1];
			}
		}
		for(i = 0; i < n; i++){
			for(j = 0; j < m; j++){
				if(mp[i][j] == 0) continue;
				int x = i, y = j;
				if(ffind(x+k/2, y+k/2) > 0){
					ans += calcf(0, i+m-1-j+k, i+k-1) - calcf(0, i+m-1-j+k, i+k/2-1);
					ans += calcf(0, i+m-1-j-k, i-1) - calcf(0, i+m-1-j-k, i-k/2-1);
				}
				if(ffind(x-k/2, y-k/2) > 0){
					ans += calcf(0, i+m-1-j+k, i+k/2) - calcf(0, i+m-1-j+k, i);
					ans += calcf(0, i+m-1-j-k, i-k/2) - calcf(0, i+m-1-j-k, i-k);
				}
				if(ffind(x+k/2, y-k/2) > 0){
					ans += calcf(1, i+j+k, i+k-1) - calcf(1, i+j+k, i+k/2);
					ans += calcf(1, i+j-k, i-1) - calcf(1, i+j-k, i-k/2);
				}
				if(ffind(x-k/2, y+k/2) > 0){
					ans += calcf(1, i+j+k, i+k/2-1) - calcf(1, i+j+k, i);
					ans += calcf(1, i+j-k, i-k/2-1) - calcf(1, i+j-k, i-k);
				}
				ans += calcg(0, i+m-1-j+k, i+k) - calcg(0, i+m-1-j+k, i+k/2-1);
				ans += calcg(0, i+m-1-j-k, i) - calcg(0, i+m-1-j-k, i-k/2-1);
				ans += calcg(1, i+j+k, i+k) - calcg(1, i+j+k, i+k/2-1);
				ans += calcg(1, i+j-k, i) - calcg(1, i+j-k, i-k/2-1);
			}
		}
	}
	printf("%lld\n", ans/3);
	return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()

int main() {
#ifdef local
	freopen("in.txt", "r", stdin);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int n, m; cin >> n >> m;
	vector<string> vs(n);
	for(auto &s : vs) cin >> s;
	vector<int> r(n, 1), c(m, 1);
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < m; j++) {
			r[i] &= vs[i][j] == '.';
			c[j] &= vs[i][j] == '.';
		}
	}
	for(int i = 0; i < n; i++) {
		if(r[i]) continue;
		for(int j = 0; j < m; j++) {
			if(c[j]) continue;
			cout << vs[i][j];
		}
		cout << '\n';
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define optimizar_io ios_base::sync_with_stdio(false);cin.tie(0);

int main() {
	optimizar_io

	string week[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

	string s;
	cin >> s;
	int cnt = 1;
	for (int i = 6; i >= 0; i--) {
		if (week[i] == s)
			break;
		cnt++;
	}
	cout << cnt << "\n";
	return 0;
}

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

int main() {
    int N, M, C, B[20];
    cin >> N >> M >> C;
    for (int i = 0; i < M; ++i){
        cin >> B[i];
    }
    int ans = 0;
    for (int i = 0; i < N; ++i){
        int dence = C; 
        for (int j = 0; j < M; ++j){
            int a;
            cin >> a;
            dence += a * B[j];
        }
        if (dence > 0) ++ans;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;

ll N, K;
vector<ll> g[MAX];

ll bfs() {
  ll res=K;
  queue<ll> q;
  ll i;
  ll used[MAX]={};
  used[0]=1;
  
  for(i=0; i<g[0].size(); i++) {
    moC(res, *, K-i-1);
    q.push(g[0][i]);
    used[g[0][i]]=1;
  }
  
  while(q.size()) {
    ll u=q.front(); q.pop();
    
    ll t=0;
    for(i=0; i<g[u].size(); i++) {
      ll v=g[u][i];
      if(used[v]) continue;
      
      moC(res, *, K-t-2);
      t++;
      q.push(v);
      used[v]=1;
    }
    
  }
  
  return res;
}

int main(void) {
  ll i, j, k;
  cin >> N >> K;
  
  for(i=0; i<N-1; i++) {
    ll a, b;
    cin >> a >> b;
    a--; b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  
  pt(bfs());
  
}





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

vector<int>E[200000];
int id[200000];
int col[200000];
bool b[200000];

bool dfs(int v,int k,int c){
	id[v]=k;
	col[v]=c;
	bool flag=true;
	for(int u:E[v]){
		if(id[u]==-1){
			flag&=dfs(u,k,!c);
		}
		else{
			if(col[u]==col[v])flag=false;
		}
	}
	return flag;
}
vector<int>v[200000];

int main(){
	int n,m;cin>>n>>m;
	rep(i,m){
		int a,b;scanf("%d%d",&a,&b);a--;b--;
		E[a].push_back(b);
		E[b].push_back(a);
	}
	memset(id,-1,sizeof(id));
	int cnt=0;
	rep(i,n){
		if(id[i]==-1){
			b[cnt]=dfs(i,cnt,0);
			cnt++;
		}
		v[id[i]].push_back(i);
	}
	ll c1=0,c2=0,c3=0;
	rep(i,cnt){
		if(v[i].size()==1){
			c1++;
			continue;
		}
		c2++;
		if(b[i])c3++;
	}
	cout<<c1*(n-c1)*2+c1*c1+c2*c2+c3*c3<<endl;
}

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

int main()
{
	int a, b, c, d,x,y,z;
	cin >> a >> b >> c >> d;

	x = abs(a - c);
	y = abs(a - b);
	z = abs(b - c);

	if (x <= d)
		cout << "Yes" << endl;
	else if (y <= d && z <= d)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 256
/**
 *      ABC 111 B
 *      author  : kyomukyomupurin
 *      created : 2018-09-29 21:01:55
**/

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

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

    if (N % 111 == 0){
        cout << N << endl;
    }
    else {
        cout << 111 * (N / 111 + 1) << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
void print(ll x){
	if(x<0)putchar('-'),x=-x;
	int y=x%10+'0';
	if(x>=10)print(x/10);
	putchar(y);
}
vector<int> g[100009];
bool b[100009];
int dp[100009],n,m,ans;
int dfs(int x){
	if(b[x])return dp[x];
	b[x]=1;
	for(int i=0;i<g[x].size();i++)
		dp[x]=max(dp[x],dfs(g[x][i])+1);
	return dp[x];
}
int main(){
	n=read(),m=read();
	for(int i=0;i<m;i++) {
		int x=read(),y=read();
		g[x].push_back(y);
	}
	for(int i=1;i<=n;i++)
		ans=max(ans,dfs(i));
	print(ans);
	return 0;
}

Measured memory_bytes: 8192
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <map>
#include <string.h>
#include <algorithm>
#include <bits/stdc++.h>
#include <vector>

using namespace std;
#define set_precision cout << fixed << setprecision(10)
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define replb(i, a, b) for (ll i = a; i >= b; i--)
#define repl(i, a, b) for (ll i = a; i < b; i++)
#define repit(arr) for (auto it = arr.begin(); it != arr.end(); it++)
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vl vector<long long int>
#define Vi vector<vector<int>>
#define vpi vector<pair<int,int>>
#define seti set<int>
#define setl set<ll>
#define dseti set<int, greater<int>>
#define dsetl set<ll, greater<ll>>
#define mseti multiset<int>
#define msetl multiset<ll>
#define dmseti multiset<int, greater<int>>
#define dmsetl multiset<ll, greater<ll>>
#define sortA(arr) sort(arr.begin(), arr.end())
#define dsortA(arr) sort(arr.begin(), arr.end(), greater<int>())
#define ssort(arr) stable_sort(arr.begin(), arr.end())
#define search(arr, c) binary_search(arr.begin(), arr.end(), c)
#define pb push_back
#define ll long long
#define cl_bf cin.ignore(numeric_limits<streamsize>::max(), '\n');
#define castl static_cast<ll>
int fact(int n) 
{ 
    int res = 1; 
    for (int i = 2; i <= n; i++) 
        res = res * i; 
    return res; 
}
int nCr(int n, int r) 
{ 
    return fact(n) / (fact(r) * fact(n - r)); 
}
int cel(int a,int b){return((a-1)/b+1);} 
int gcd(int a, int b)
{
    if (a < b)
        swap(a, b);
    if (b == 0)
        return a;
    else
        return gcd(b, a % b);
}
int lcm(int a,int b){
    return (a*b)/gcd(a,b);
} 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,a,ans=0;
    cin>>n;
    rep(i,1,n+1){
        cin>>a;
        if(i%2&&(a%2))ans++;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3584
N = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
count = 0
for i in range(N):
    if a[i] > b[i]:
        count += b[i]
        b[i] = 0
    elif a[i] == b[i]:
        count += a[i]
        b[i] = 0
    else:
        count += a[i]
        b[i] -= a[i]
        if a[i+1] > b[i]:
            count += b[i]
            a[i+1] -= b[i]
            b[i] = 0
        elif a[i+1] == b[i]:
            count += a[i+1]
            a[i+1] = 0
            b[i] = 0
        else:
            count += a[i+1]
            a[i+1] = 0

print(count)


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

LL im(LL a, LL b) { return (a % b + b) % b; }

LL n, l, t, x[100000], w[100000];

int main() {
	cin >> n >> l >> t;
	inc(i, n) { cin >> x[i] >> w[i]; }
	
	inc(i, n) { if(w[i] == 2) { w[i] = -1; } }
	l *= 4; t *= 4;
	inc(i, n) { x[i] *= 4; }
	t--;
	
	int ind = 0;
	inc(i, n) {
		if(w[i] != w[0]) {
			if(w[0] == 1) {
				LL tt = 2 * t - im(x[i] - x[0], l);
				if(tt >= 0) { ind += 1 + tt / l; }
			} else {
				LL tt = 2 * t - im(x[0] - x[i], l);
				if(tt >= 0) { ind -= 1 + tt / l; }
			}
		}
	}
	ind = im(ind, n);
	
	LL s[100000];
	inc(i, n) { s[i] = im(x[i] + w[i] * t, l); }
	sort(s, s + n);
	
	LL pos = im(x[0] + w[0] * t, l);
	int ind2 = -1;
	inc(i, n) { if(s[i] == pos) { ind2 = i; break; } }
	assert(ind2 != -1);
	
	inc(i, n) {
		int p = im(i + ind2 - ind, n);
		cout << im((s[p] + 1) / 4, l / 4) << "\n";
	}
	
	return 0;
}


Measured memory_bytes: 3584
(defn Shiritori [Ws]
  (if-not (= (count Ws) (-> Ws distinct count))
    "No"
    (if 
      (->> Ws 
        (map #(list (first %) (last %))) 
        (apply concat) 
        rest 
        (partition 2)
        (map distinct) 
        (map count) 
        (every? #(= 1 %)))
      "Yes"
      "No"
  )))
(defn input [N]
  (if (zero? N) 
    '()
    (cons (read-line) (input (dec N)))))


(-> (Integer/parseInt (read-line))
  input
  Shiritori
  println)

Measured memory_bytes: 67840
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

using ll = long long;
const ll MOD = 998244353;

typedef pair<ll, ll> P;
struct edge { ll to, cost; };

const int MAX_V =100000;
const ll INF = 1LL<<60;

int V;
vector<edge> G[MAX_V];
ll d[MAX_V];

void dijkstra(ll s) {
    // greater<P>を指定することでfirstが小さい順に取り出せるようにする
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d + V, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        rep(i,G[v].size()) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main() {
    int u, v, A, B;
    cin >> V >> u >> v;
    u--;
    v--;
    rep(i, V - 1) {
        cin >> A >> B;
        A--;
        B--;
        G[A].push_back({B, 1});
        G[B].push_back({A, 1});
    }
    dijkstra(u);
    vector<int> du(V);
    rep(i, V) du[i] = d[i];
    dijkstra(v);
    vector<int> dv(V);
    rep(i, V) dv[i] = d[i];
    int maxdv = 0, maxi = v;
    rep(i, V) {
        if (dv[i] <= du[i]) continue;
        if (dv[i] > maxdv) {
            maxdv = dv[i];
            maxi = i;
            //cout << maxu << "\n";
        }
    }
    //cout << "maxu=" << maxu << " dv[maxu]=" << dv[maxu] << " du[maxu]=" << du[maxu] << "\n";
    cout << dv[maxi] - 1 << "\n";
    //rep(i, V) cout << i << " " << du[i] << " " << dv[i] << "\n";
}

Measured memory_bytes: 10528
#include <stdio.h>

int main()
{
	int n, m, flag = 1,i;
	char s[20];
	scanf("%d %d", &n,&m);
	scanf("%s", s+1);
	for (i=1; i <n+1; i++)
	{
		if (s[i] < 48 || s[i]>57)
		{
			flag = 0;
			break;
		}
	}
	if (s[i++] != '-')
		flag = 0;
	for(;i<n+m+1;i++)
	{
		if (s[i] < 48 || s[i]>57)
		{
			flag = 0;
			break;
		}
	}
	if (flag)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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(){
  ll n;
  cin>>n;
  vector<ll>a(n);
  vector<ll>b(n);
  rep(i,n){cin>>a[i]>>b[i];}
  

  ll ans=0;
  rep(i,n){

    if((a[n-1-i]+ans)%b[n-1-i]==0)continue;
    else ans=ans+b[n-i-1]-((a[n-1-i]+ans)%b[n-1-i]);
    
    
  }
  cout<<ans<<endl; 
    
  return 0;
}


Measured memory_bytes: 4836
#include <bits/stdc++.h>
using namespace std;
int f[60000];
int main(){
    int n;
    cin>>n;
    for(int x=1;x<=100;x++){
        for(int y=1;y<=100;y++){
            for(int z=1;z<=100;z++){
                if(x+y+z<=213){
                    f[x*x+y*y+z*z+x*y+y*z+z*x]++;
                }
            }
        }
    }
    for(int i=1;i<=n;i++){
        cout<<f[i]<<"\n";
    }
}

Measured memory_bytes: 3692
///   ***   ---   |||         In the name of ALLAH        |||   ---   ***   ///



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


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;

#define endl '\n'
#define PB push_back
#define F first
#define S second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sz(x) (int)x.size()

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

#define mem(a,b) memset(a, b, sizeof(a) )
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}


int main()
{
    optimize();

    string s, p, o;

    int n;
    cin >> n;
    for ( int i = 1; i <= n; i++ ) {
        int a;
        cin >> a;
        s += ( a + '0' );
    }

    for ( int i = 1; i <= n; i++ ) {
        int a;
        cin >> a;
        p += ( a + '0' );
    }

    for ( int i = 1; i <= n; i++ ) o += ( i + '0' );

    int p1 = 1;
    do {
        if ( o == s ) break;
        p1++;
    }while ( next_permutation( all ( o ) ) );

    sort ( all (o) );
    int p2 = 1;
    do {
        if ( o == p ) break;
        p2++;
    }while ( next_permutation( all ( o ) ) );


    cout << abs ( p1 - p2 ) << endl;;

    return 0;
}


















Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< int, int> >
#define all(x) x.begin(), x.end()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,n) for(ll i=0;i<n;i++)
#define print(arr,a,n) for(ll i=(a);i<(n);i++)cout<<(arr)[i]<<" ";

int main(){
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
    #endif
    ll n;
    cin>>n;
    ll a[n],i,q,s=0,c[100002]={};
    forn(i,n){
        cin>>a[i];
        s+=a[i];
        c[a[i]]++;
    }
    cin>>q;
    while(q--){
        ll b,cc;
        cin>>b>>cc;
        s=s-(b*c[b])+cc*c[b];
        c[cc]+=c[b];
        c[b]=0;
        cout<<s<<endl;
    }
}

Measured memory_bytes: 5148