akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }
const double PI = 3.14159265358979323846;
int vector_finder(vector<int> vec, int number) {
  auto itr = find(vec.begin(), vec.end(), number);
  size_t index = distance(vec.begin(), itr);
  if (index != vec.size()) {  // 発見できたとき
    return 1;
  } else {  // 発見できなかったとき
    return 0;
  }
}
int main() {
  int x, n, d, ans;
  cin >> x >> n;
  if (n == 0) {
    cout << x;
    return 0;
  }
  vector<int> a;
  for (int i = 0; i < n; i++) {
    cin >> d;
    a.push_back(d);
  }
  sort(a.begin(), a.end());
  int x1, x2;
  if (vector_finder(a, x) == 0) {
    cout << x;
  } else {
    for (int j = 1; j < 51; j++) {
      x1 = x - j;
      x2 = x + j;
      if (vector_finder(a, x1) == 0) {
        cout << x1;
        return 0;
      }
      if (vector_finder(a, x2) == 0) {
        cout << x2;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 3632
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int M = scanner.nextInt();
    City[] cities = new City[M];
    List<City>[] cityList = new List[N];
    for (int i = 0; i < N; i++) cityList[i] = new ArrayList<>();
    for (int i = 0; i < M; i++) {
      int P = scanner.nextInt();
      int Y = scanner.nextInt();
      City city = new City(i, Y);
      cityList[P - 1].add(city);
      cities[i] = city;
    }
    for (int i = 0; i < N; i++) {
      cityList[i].sort(Comparator.comparingInt(o -> o.year));
      for (int j = 0; j < cityList[i].size(); j++) {
        cityList[i].get(j).id = String.format("%06d%06d", (i + 1), (j + 1));
      }
    }
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < M; i++) {
      sb.append(cities[i].id).append('\n');
    }
    System.out.println(sb.toString());
  }

  static class City {
    public final int num;
    public final int year;
    public String id;

    City(int num, int year) {
      this.num = num;
      this.year = year;
    }
  }
}


Measured memory_bytes: 180988
main = do
    [n,k] <- map read . words <$> getLine :: IO [Int]
    let ans | k == 0 = n ^ 2
            | otherwise = sum $ map (\b -> let (p,r) = n `divMod` b in p * (max 0 (b-k)) + max 0 (r-k+1)) [1..n]
    print ans

Measured memory_bytes: 3832
s = str(input())

n = len(s) - 1

for i in range(1 << n):
    f = ""
    f += s[0]

    for j in range(n):

        if 1 & (i >> j):

            f += "+"
            f += s[j + 1]
        else :

            f += "-"
            f += s[j + 1]

    if eval(f) == 7:
        print(f + "=7")
        break


Measured memory_bytes: 3064
import sys
import itertools
input = sys.stdin.readline


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


def main():
    N = int(input())
    S, T = input().split()
    
    res = ""
    for s, t in zip(S, T):
        res += s + t
    
    print(res)


if __name__ == "__main__":
    main()


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

int main()
{
int i;
int N;
int T;
int t;
int iPre;
long long iSum;

	cin >> N;
	cin >> T;
	cin >> t;	// 0

	iPre = 0;
	iSum = 0;
	for( i = 1; i < N; i++ )
	{
		cin >> t;

		iSum += min( T, t - iPre );
		iPre = t;
	}

	iSum += T;

	cout << iSum << endl;

	return 0;
}






Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,c,z;
    scanf("%d%d%d",&a,&b,&c);
    z=a*b;
    if(z>c){
        printf("%d\n",c);
    }
    else{
        printf("%d\n",z);
    }
    return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <set>
#include <algorithm>
#include <iostream>
using namespace std;

typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
#define MP make_pair
#define PB push_back
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const int MOD = 1000000007;
const int INF = 1000000007;
const LL LINF = 1LL * INF * INF;
const int MAXN = 100007;
const LD EPS = 1e-12;

int n;
vector <PII> g[MAXN];
LL Ds[MAXN], Dt[MAXN], Cs[MAXN], Ct[MAXN];

void dijkstra(int s, LL *D, LL *C)
{
	set <pair <LL, int> > S;
	REP(i, n)
		D[i] = LINF;
	D[s] = 0;
	C[s] = 1;
	REP(i, n)
		S.insert(MP(D[i], i));
	REP(i, n)
	{
		int v = S.begin()->second;
		S.erase(S.begin());
		REP(i, SZ(g[v]))
		{
			int to = g[v][i].first;
			if (D[v] + g[v][i].second < D[to])
			{
				S.erase(MP(D[to], to));
				D[to] = D[v] + g[v][i].second;
				S.insert(MP(D[to], to));
			}
			if (D[to] + g[v][i].second == D[v])
			{
				C[v] += C[to];
				C[v] %= MOD;
			}
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	int m, s, t, ans;
	cin >> n >> m >> s >> t;
	--s; --t;
	REP(i, m)
	{
		int u, v, d;
		cin >> u >> v >> d;
		--u; --v;
		g[u].push_back(MP(v, d));
		g[v].push_back(MP(u, d));
	}
	dijkstra(s, Ds, Cs);
	dijkstra(t, Dt, Ct);
	ans = (Cs[t] * Cs[t]) % MOD;
	REP(u, n)
	{
		REP(i, SZ(g[u]))
		{
			int v = g[u][i].first, d = g[u][i].second;
			if (Ds[u] + d + Dt[v] == Ds[t] && Dt[v] - Ds[u] + d > 0 && Dt[v] - Ds[u] < d)
			{
				ans -= (((Cs[u] * Ct[v]) % MOD) * ((Cs[u] * Ct[v]) % MOD)) % MOD;
				ans %= MOD;
			}
		}
		if (Ds[u] == Dt[u] && 2 * Ds[u] == Ds[t])
		{
			ans -= (((Cs[u] * Ct[u]) % MOD) * ((Cs[u] * Ct[u]) % MOD)) % MOD;
			ans %= MOD;
		}
	}
	if (ans < 0)
		ans += MOD;
	cout << ans;
	//cout << endl; system("pause");
	return 0;
}

Measured memory_bytes: 18048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}


int main(void)
{
    int n;
    cin >> n;
    vector<int> c(n);
    vector<int> v(n);
    vector<int> a(n);
    REP(i,n){
        cin >> v[i];
    }
    REP(i,n){
        cin >> c[i];
    }
    int sum = 0;
    REP(i,n){
        if(v[i] - c[i] > 0){
            sum += v[i] - c[i];
        }
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

const ll M = 1000000007;

ll C[2002][2002];
ll inv[2002];
ll modpow(ll x,ll k){
	if(k == 0)return 1;
	ll ret = modpow(x,k/2);
	ret *= ret; ret %= M;
	if(k%2 == 1){
		ret *= x;
		ret %= M;
	}
	return ret;
}

int main(){
	rep(i,2002)inv[i] = modpow(i,M-2);
	for(int i = 0 ; i < 2002 ; i ++){
		C[i][0] = 1;
		for(int j = 0 ; j < i ; j ++){
			C[i][j+1] = C[i][j]*(i-j); C[i][j+1] %= M;
			C[i][j+1] *= inv[j+1];
			C[i][j+1] %= M;
		}
	}
	
	int a,b;
	cin >> a >> b;
	
	ll ret = a+1;
	for(int i = 1 ; i <= b-1 ; i ++){
		for(int j = 1 ; j <= b-i ; j ++){
			if(a-(b-i)-(b-i-j) >= 0){
				ll _ret = C[b-1][i-1]*C[b-i-1][j-1]; _ret %= M;
				_ret *= C[a-(b-i)-(b-i-j)+2][2];
				//cout << a-(b-i)-(b-i-j)+2 << " " << 2 << endl;
				_ret %= M;
				ret += _ret;
				ret %= M;
				//cout << i << " " << j << " " << _ret << endl;
			}
		}
	}
	cout << ret << endl;
}
	


Measured memory_bytes: 30080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    string S = in<string>();
    int maxi = 0,now = 0;
    REP(i,S.size()){
        if(S[i] == 'A' || S[i] == 'G' || S[i] == 'C' || S[i] == 'T'){
            now++;
            maxi = max(maxi,now);
        }else{
            now = 0;
        }
    }
    cout << maxi << "\n";
}

Measured memory_bytes: 256
//#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
using namespace std;
//using namespace __gnu_pbds;
//template <class c, class cmp = less<c> > using ordered_set = tree<c, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;



  #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

  #define ff first
  #define ss second
  #define pb push_back
  #define pf push_front
  #define mp make_pair
  #define in insert
  #define ld long double


  #define TRACE
  #ifdef TRACE
  #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
  template <typename Arg1>
  void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
  }
  template <typename Arg1, typename... Args>
  void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
  }
  #else
  #define trace(...) 1
  #endif
  template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
  template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
  template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}
  typedef long long int ll;

  typedef vector<int> vi;
  typedef vector<ll> vl;
  typedef vector<vi> vvi;
  typedef vector<vl> vvl;
  typedef pair<int,int> pii;
  typedef pair<ll,ll> pll;
  typedef vector<pii> vpii;
  typedef vector<pll> vpll;
  const ll mod =1e9+7;
  const ll MAX_NODES =200001;
  const ll MAX_LOG =50;
  //const ll maxn = 400000+10;
  #define endl '\n'
  ll power(ll x, ll n) {
      ll res = 1;
      for (; n > 0; n >>= 1) {
      if (n & 1) res = (res * x) % mod;
      x = (x * x) % mod;
      }
      return res;
  }
const int maxn = 500001;
int t[4*maxn][26];


 
void update(int id,int l,int r,int pos,int val,int n){
	if(pos>r||pos<l||l>r)return;
	if(l==r&&l==pos){
		t[id][n]+=val;
		return;
	}
	int mid=(l+r)>>1;
	update(id*2,l,mid,pos,val,n);
	update(id*2+1,mid+1,r,pos,val,n);
	t[id][n]=t[id*2][n]+t[id*2+1][n];
}
int counter(int id,int l,int r,int lq,int rq,int n){
	if(l>r||l>rq||lq>r||lq>rq)return 0;
	if(lq<=l&&r<=rq){
		return t[id][n];
	}
	int mid=(l+r)>>1;
	return counter(id*2,l,mid,lq,rq,n)+counter(id*2+1,mid+1,r,lq,rq,n);
}

int main()
{

	IOS
	memset(t,0,sizeof(t));
	int n;
	cin>>n;
	string s;
	cin>>s;
	s = "$"+s;
	int q;
	cin>>q;
	for(int i = 1;i<=n;i++)
	{
		update(1,1,n,i,+1,s[i] - 'a');	
	}
	while(q--)
	{
		int ty;
		cin>>ty;
		if(ty==1)
		{
			int i;
			char c;
			cin>>i>>c;
			update(1,1,n,i,-1,s[i]-'a');
			s[i] = c;
			update(1,1,n,i,+1,s[i] - 'a');

		}
		else
		{
			int l,r;
			cin>>l>>r;
			int ans = 0;
			for(ll i=0;i<26;i++)
			{
				if(counter(1,1,n,l,r,i)>0)
				{
					ans++;
				}
			}
			cout<<ans<<endl;
		}
		
	}
	


}
 
  


  
  




Measured memory_bytes: 204444
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
using ld=long double;
using VI=vector<ll>;
using VD=vector<ld>;
using VVI=vector<VI>;
using VC=vector<char>;
using VVC=vector<VC>;
using VS=vector<string>;
using PLL =pair<ll,ll>;
using PLD=pair<ld,ld>;
using VPLL=vector<PLL>;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element((x).begin(),(x).end())
#define MIN(x) *min_element((x).begin(),(x).end())
#define SORTR(x) sort((x).rbegin(),(x).rend())
#define SORT(x) sort((x).begin(),(x).end())
#define SUM(x) accumulate((x).begin(),(x).end(), 0)
#define FILL(x,a) fill(x.begin(),x.end(),a)
#define EACH(i,x) for(typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)
#define COUT(x) cout<<x<<"\n"

const ll INF = 1e18;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template <class BidirectionalIterator>
bool next_partial_permutation(BidirectionalIterator first, BidirectionalIterator middle,BidirectionalIterator last){reverse(middle, last); return next_permutation(first , last);}
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll GCD(VI v){ll a = v[0]; for (ll i = 1; i<SIZE(v); i++) {a = gcd(a, v[i]);} return a;}
ll LCM(VI v){ll a = v[0]; for (ll i = 1; i<SIZE(v); i++) {a = lcm(a, v[i]);} return a;}


void Main()
{
	ll a,b,c,k;
	ll res=0;
	string sres;
	cin>>a>>b>>c>>k;
	if(k<=a) res=k;
	else if(a<k&&k<=a+b) res=a;
	else res=a-(k-(a+b));

	cout << res << "\n";
	return;
}

int main()
{
	std::cin.tie(0);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}


Measured memory_bytes: 3656
import numpy as np
N = int(input())
T, A = map(int, input().split())

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

calc_array = []
for x in array:
    calc_array.append(T - 0.006 * x)

idx = np.abs(np.array(calc_array) - A).argmin()
print(idx+1)

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

int main() {
  int n, a, b, c;
  cin>>n>>a>>b>>c;
  string s[n];
  for (int i=0; i<n; i++) {
    cin>>s[i];
  }
  map<char, int> m;
  m['A'] = a;
  m['B'] = b;
  m['C'] = c;
  vector<char> v;
  for (int i=0; i<n; i++) {
    char c1 = s[i][0];
    char c2 = s[i][1];
    if (m[c1] == 0 && m[c2] == 0) {
      cout<<"No"<<endl;
      return 0;
    }
    if (m[c1] == 0) {
      ++m[c1];
      --m[c2];
      v.push_back(c1);
      continue;
    }
    if (m[c2] == 0) {
      ++m[c2];
      --m[c1];
      v.push_back(c2);
      continue;
    }
    if (i == n - 1) {
      ++m[c1];
      --m[c2];
      v.push_back(c1);
      continue;
    }
    if (m[c1] == 1 && m[c2] == 1) {
      char c3 = s[i+1][0];
      char c4 = s[i+1][1];
      if (c1 == c3 || c1 == c4) {
        ++m[c1];
        --m[c2];
        v.push_back(c1);
      } else {
        ++m[c2];
        --m[c1];
        v.push_back(c2);
      }
    } else if (m[c2] > m[c1]) {
      ++m[c1];
      --m[c2];
      v.push_back(c1);
    } else {
      ++m[c2];
      --m[c1];
      v.push_back(c2);
    }
  }
  cout<<"Yes"<<endl;
  for (char c: v) {
    cout<<c<<endl;
  }
}

Measured memory_bytes: 6876
K,N=map(int,input().split())
A=list(map(int,input().split()))
memo=A[0]
for i in range(N-1):
	Bi=A[i+1]-A[i]
	if Bi>memo:
		memo=Bi
if memo<=K-A[N-1]+A[0]:
	print(A[N-1]-A[0])
else:
	print(K-memo)

Measured memory_bytes: 26444
n=int(input())
k=10000000000000000000000000000000000000000
a=list(map(int,input().split()))
for i in range(n):
  j=0
  while a[i]%2==0:
    a[i]=a[i]/2
    j+=1
  k=min(j,k)
  
print(k)

Measured memory_bytes: 3064
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
const vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";}
template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";}
int main(){
    ll n;
    cin>>n;
    ll ans=0;
    for(int i=1;i<=n;i++){
          ans+=(n-1)/i;
    }
    cout<<ans<<"\n";
}

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

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion


int main()
{
    int n, r;
    while(cin>>n>>r, n) {
        vi v(n);
        rep(i,n) v[i] = n-i;
        rep(i,r) {
            vi tmp = v;
            int p, c;
            cin >> p >> c;
            rep(j,p-1) tmp[j+c] = v[j];
            rep(j,c) {
                tmp[j] = v[j+p-1];
            }
            swap(tmp,v);
        }
        P(v[0]);
    }
    return 0;
}

Measured memory_bytes: 2980
#include <bits/stdc++.h>
using namespace std;
int main(){
string S;
  cin >> S;
  int count=0,ans=0;
  for (int i=0;i<S.size();i++){
  	if (S[i]=='T')count++;
    else count--;
    if (count>ans)ans=count;
  }
  cout << ans*2 <<endl;
}


Measured memory_bytes: 640
using System;
using System.Collections;
using System.Collections.Generic;
using System.Dynamic;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Runtime.InteropServices;
using System.Text;
using static System.Console;
using static System.Math;

class Simple {    
    
    void Solve() {
        //input        
        var s = io.String;
        var t = io.String;
        //cal
        var ss = new string(s.ToCharArray().OrderBy(x=>x).ToArray());
        var tt = new string(t.ToCharArray().OrderByDescending(x=>x).ToArray());
        var ans = ss.CompareTo(tt) < 0 ? "Yes" : "No";
        //ret
        WriteLine(ans);        
    }

    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) => new Simple().Stream();
    private void Stream() {
        //var exStdIn = new System.IO.StreamReader("stdin.txt");
        //SetIn(exStdIn);
        Solve();
        io.Flush();        
    }
}
class SimpleIO {
    string[] _nextBuffer;
    int _bufferCnt;
    char[] cs = new char[] {' ', '"', ','};
    StreamWriter sw = new StreamWriter(OpenStandardOutput()) {
#if DEBUG
        AutoFlush = true
#else
        AutoFlush = false
#endif
    };
    public SimpleIO() {
        _nextBuffer = new string[0];
        _bufferCnt = 0;
        SetOut(sw);        
    }
    string Next() {
        if(_bufferCnt < _nextBuffer.Length)
            return _nextBuffer[_bufferCnt++];
        var st = ReadLine();
        while(st == "")
            st = ReadLine();
        _nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        _bufferCnt = 0;
        return _nextBuffer[_bufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void Flush() => Out.Flush();
}
static class Ex {
    public static void REP(this int n, Action <int> act) {
        for(var i = 0; i < n; ++i) 
            act(i);
    }
}

Measured memory_bytes: 13536
#include<iostream>
#include<algorithm>
#include<queue>

using namespace std;

const int MAX = 260;
bool come[MAX],goal[MAX];
int M,n,d[MAX];

void print(){

  for(int i = 0; i <= n; i++) cout << come[i] << " ";
  cout << endl;
  for(int i = 0; i <= n; i++) cout << goal[i] << " ";
  cout << endl;
}

void init(){
  fill(come,come+MAX,false);
  fill(goal,goal+MAX,false);
  fill(d,d+MAX,0);
}

int move(int now, int num){
  int nex = now+num;
  if(nex > n) return -1;
  nex += d[nex];
  if(nex > n) return -1;
  if(nex < 0) return 0;
  return nex;
}

void make_come(){
  come[0] = true;
  priority_queue<int,vector<int>,greater<int> > Q;
  Q.push(0);
  while(!Q.empty()){
    int now = Q.top();
    Q.pop();

    for(int i = 1; i <= M; i++){
      int nex = move(now,i);
      if(nex == -1) goal[now] = true;
      else if(!come[nex] && nex <= n){
        come[nex] = true;
        Q.push(nex);
      }
    }
  }
}

void make_goal(){

  while(1){
    bool update = false;

    for(int i = n; i >= 0; i--){
      if(!come[i] || goal[i]) continue;
      
      for(int j = 1; j <= M; j++){
        int nex = move(i,j);
        if(nex == -1){
          goal[i] = true;
          update = true;
        }else if(goal[nex]){
          goal[i] = true;
          update = true;
        } 
      }
    }
    if(!update) break;
  }
}


bool solve(){

  make_come();
  make_goal();

  for(int i = 0; i <= n; i++)
    if(come[i] && !goal[i]) return false; 
  return true;
}

int main(){

  while(cin >> M && M){
    init();
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> d[i];
    if(solve()) cout << "OK" << endl;
    else cout << "NG" << endl;
    //print();
  }
  
  return 0;
}

Measured memory_bytes: 1208
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define shows(n) cerr<<#n<<" = ";for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showslr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i];}cerr<<endl

#define YES puts("YES")
#define Yes puts("Yes")
#define yes puts("yes")
#define NO puts("NO")
#define No puts("No")
#define no puts("no")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

inline void io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}

void _DEBUG(){cerr<<endl;}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<",";_DEBUG(b...);}

template<typename T> inline void in(T &e){cin>>e;}
template<typename H,typename... T>void in(H &a, T&... b){in(a);in(b...);}
template<typename T> inline void out(T e){cout<<e<<endl;}
template<typename H,typename... T> void out(H a, T... b){out(a);out(b...);}


const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

const int MAX_H=110,MAX_W=110;

int h,w;
int n;
vi vec;
int grid[MAX_H][MAX_W];

signed main(){
    io();
    in(h,w);
    in(n);
    vec.resize(n);
    rep(i,n) in(vec[i]);
    REP(y,1,h+1){
        for(int x=(y&1)?1:w;(y&1)?x<w+1:x>=1;(y&1)?x++:x--){
            rep(i,vec.size()){
                if(vec[i]>0) {
                    grid[x][y]=i+1;
                    vec[i]--;
                    break;
                }
            }
        }
    }
    REP(y,1,h+1){
        REP(x,1,w+1){
            printf("%lld ",grid[x][y]);
        }
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 888
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<cmath>
#include<functional>
#include<algorithm>
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

long long gcd(long long a,long long b){
	if(b==0)return a;
	return gcd(b,a%b);
}


//分数クラス
struct Fraction{
	long long x,y;
	Fraction(){}
	Fraction(long long x,long long y){
		long long z = gcd_m(x,y);
		if(y<0){
			x=-x;
			y=-y;
		}
		this->x=x/z;
		this->y=y/z;
	}
	Fraction inverse()const{
		return Fraction(y,x);
	}
	Fraction operator + (Fraction a)const{
		long long z = gcd_m(y,a.y);
		return Fraction(a.y/z*x+y/z*a.x, y/z*a.y);
	}
	Fraction operator - (Fraction a)const{
		long long z = gcd_m(y,a.y);
		return Fraction(a.y/z*x-y/z*a.x, y*a.y);
	}
	Fraction operator * (Fraction a)const{
		return Fraction(x*a.x,y*a.y);
	}
	Fraction operator / (Fraction a)const{
		return (*this)*a.inverse();
	}

	Fraction operator + (int a)const{
		return Fraction(x+a*y, y);
	}
	Fraction operator - (int a)const{
		return Fraction(x-a*y, y);
	}
	Fraction operator * (int a)const{
		long long z = gcd_m(a,y);
		return Fraction(a/z*x,y/z);
	}
	Fraction operator / (int a)const{
		long long z = gcd_m(a,x);
		return Fraction(x/z,a/z*y);
	}
	friend Fraction operator + (int a,Fraction r){return r+a;}
	friend Fraction operator - (int a,Fraction r){return Fraction(r.y*a-r.x,r.y);}
	friend Fraction operator * (int a,Fraction r){return r*a;}
	friend Fraction operator / (int a,Fraction r){return r.inverse()*a;}
	long long comp(Fraction a)const{
		if(x==0&&a.x==0)return 0;
		long long s,t;
		s = gcd_m(x,a.x);
		t = gcd_m(y,a.y);
		return (x/s)*(a.y/t) - (a.x/s)*(y/t);
	}
	bool operator == (Fraction a)const{return comp(a)==0;}
	bool operator != (Fraction a)const{return comp(a)!=0;}
	bool operator < (Fraction a)const{return comp(a)<0;}
	bool operator > (Fraction a)const{return comp(a)>0;}
	bool operator <= (Fraction a)const{return comp(a)<=0;}
	bool operator >= (Fraction a)const{return comp(a)>=0;}
	static long long gcd_m(long long a,long long b){
		return gcd(a<0?-a:a,b<0?-b:b);
	}
};


int main(){
	string s;
	while(cin>>s&&s!="#"){
		string dir;
		rep(i,s.size()){
			if(s[i]=='w')dir+='w';
			else if(s[i]=='n')dir+='n';
		}
		int n=dir.size();
		Fraction a(0,1);
		rep(i,dir.size()){
			if(dir[i]=='w'){
				n--;
				a=a+Fraction(90,1<<n);
			}else{
				n--;
				a=a+Fraction(-90,1<<n);
			}
		}
		if(dir[dir.size()-1]=='n')a=a+90;
		if(a.x==0||a.y==1)cout<<a.x<<endl;
		else cout<<a.x<<'/'<<a.y<<endl;
	}
	return 0;
}

Measured memory_bytes: 1196
#include <stdio.h>
int max(int a,int b){
    if (a>b) return a;
    else return b;
}
int main(){
    int l,a,b,c,d;
    scanf("%d",&l);
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);
    scanf("%d",&d);
    a=a/c+(a%c!=0);
    b=b/d+(b%d!=0);
    printf("%d\n",l-max(a, b));
    return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define REP(i,n) for(ll i = 0;i < n; i++)
struct p{
    int x,y;
};
int main(){
    int n;
    cin >> n;
    vector<p>A(n);
    REP(i,n){
        cin >> A[i].x; 
        A[i].y= i;
    }   
    sort(A.begin(), A.end(), [](const p &a, const p &b) { return a.x < b.x; });

    for(p t:A){
        cout << t.y+1 <<" ";
    }cout << endl;
}

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

const LL MAX = 1e18;

int main(){
  int n; cin >> n;
  vector<LL> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(),a.end());
  if(a[0] == 0){
    cout << 0 << endl;
    return 0;
  }
  LL  ans = 1LL;
  rep(i,n){
    if(a[i] > MAX/ans){
      cout << -1 << endl;
      return 0;
    }
    ans *= a[i];
  }
  cout << ans << endl;
    

}



Measured memory_bytes: 4028
n=int(input())
a=list(input().split(' '))
total=0
S_i=0
for i in range(n-1):
    S_i+=int(a[n-1-i])
    S_i=S_i%(7+10**9)
    total+=S_i*int(a[n-2-i])
    total=total%(7+10**9)
print(total)

Measured memory_bytes: 25204
#include <stdio.h>

int main(void){
    int m[101],n,i;
    int max=0;
    for(i=1;i<=100;i++) m[i]=0;
    while(scanf("%d",&n)!=EOF){
        m[n]++;
    }
    for(i=1;i<=100;i++) if(m[i]>max) max=m[i];
    for(i=1;i<=100;i++) if(m[i]==max) printf("%d\n",i);
    return 0;
}


Measured memory_bytes: 2028
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    from itertools import accumulate
    S = accumulate([0] + A)
    from collections import Counter
    c = Counter(S)
    ans = 0
    for v in c.values():
        if v > 1:
            ans += v*(v-1)//2
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 113104
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>

using namespace std;

const int INF = 10000000;
int cap[350][350];

int maximumFlow(int s, int t, int n){
	int res = 0;
	while(true){
		vector<int> prev(n,-1); prev[s] = s;
		queue<int> qu; qu.push(s);
		while(!qu.empty()&&prev[t]<0){
			int u = qu.front(); qu.pop();
			for(int i=0;i<n;i++){
				if(cap[u][i]>0&&prev[i]<0){
					prev[i] = u;
					qu.push(i);
				}
			}
		}
		if(prev[t]<0) return res;
		int inc = 10000000;
		for(int j=t;j!=prev[j];j=prev[j]) inc = min(inc, cap[prev[j]][j]);
		for(int j=t;j!=prev[j];j=prev[j]) cap[prev[j]][j] -= inc, cap[j][prev[j]] += inc;
		res += inc;
	}
	return res;
}

int main(){
	int H, W, C, M, Nw, Nc, Nm;
	while(cin >> H >> W >> C >> M >> Nw >> Nc >> Nm){
		if(H < 0) break;
		memset(cap,0,sizeof(cap));
		for(int i=1;i<=H;i++) cap[0][i] = 1;
		for(int i=1;i<=W;i++){
			int num; cin >> num;
			for(int j=0;j<num;j++){
				int pt; cin >> pt;
				cap[pt][H+i] = 1;
			}
			cap[H+i][H+W+i] = 1;
		}
		for(int i=1;i<=C;i++){
			int num; cin >> num;
			for(int j=0;j<num;j++){
				int pt; cin >> pt;
				cap[H+W+pt][H+2*W+i] = 1;
			}
			cap[H+2*W+i][H+2*W+C+i] = 1;
		}
		for(int i=1;i<=M;i++){
			int num; cin >> num;
			for(int j=0;j<num;j++){
				int pt; cin >> pt;
				cap[H+2*W+C+pt][H+2*W+2*C+i] = 1;
			}
			cap[H+2*W+2*C+i][H+2*W+2*C+M+6] = 1;
		}
		for(int i=1;i<=H;i++) cap[i][H+2*W+2*C+M+1] = 1;
		cap[H+2*W+2*C+M+1][H+2*W+2*C+M+2] = Nw;
		for(int i=1;i<=C;i++) cap[H+2*W+2*C+M+2][H+2*W+i] = 1;
		for(int i=1;i<=W;i++)
			cap[H+W+i][H+2*W+2*C+M+3] = 1;
		cap[H+2*W+2*C+M+3][H+2*W+2*C+M+4] = Nc;
		for(int i=1;i<=M;i++) cap[H+2*W+2*C+M+4][H+2*W+2*C+i] = 1;
		for(int i=1;i<=C;i++)
			cap[H+2*W+C+i][H+2*W+2*C+M+5] = 1;
		cap[H+2*W+2*C+M+5][H+2*W+2*C+M+6] = Nm;
		cout << maximumFlow(0, H+2*W+2*C+M+6, H+2*W+2*C+M+7) << endl;
	}
}

Measured memory_bytes: 0
class Node
  attr_accessor :state, :depth, :path_cost
  attr_reader :parent

  def initialize(state, parent)
    @state = state
    @parent = parent
    @depth = parent.nil? ? 0 : parent.depth + 1
  end

  def goal?(limit, max)
    nums.size == limit && sum == max
  end

  def bad_end?(limit, max)
    nums.length > limit || sum > max
  end

  def nums
    parent.nil? ? [state] : parent.nums << state
  end

  def sum
    nums.inject(:+)
  end
end

STDIN.read.split("\n").each do |line|
  limit, max = line.split.map(&:to_i)

  next if limit == 0 && max == 0

  goals = []
  10.times do |i|
    init_node = Node.new(i, nil)
    queue = [init_node]
    black_list = [init_node.nums.sort]

    loop do
      break if queue.empty?

      elem = queue.shift

      goals << elem if elem.goal?(limit, max)

      next if elem.bad_end?(limit, max)

      10.times do |j|
        next if elem.nums.include?(j)
        new_node = Node.new(j, elem)
        new_nums = new_node.nums.sort
        next if black_list.include?(new_nums)
        black_list << new_nums
        queue << new_node
      end
    end
  end

  puts goals.map { |e| e.nums.sort }.uniq.size
end

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

int main(){
  int N,K;
  int num=0;
  cin>>N>>K;
  vector<int>h(N);
  for(int i=0;i<N;i++){
    cin>>h[i];
  }
  for(int i=0;i<N;i++){
    if(h[i]>=K){
      num++;
    }
  }
  cout<<num<<endl;
}
      
      

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  int k;
  cin >> n >> k;
  int result = 1;
  
  for(int i = 0; i < n; i++){
    if(result < k) {
  		result += result;
    } else {
    	result += k;
    }
  } 
  
  cout << result << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define pb push_back
#define inf 2e18
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define mem(a,v) memset(a,v,sizeof(a))
#define pii pair<int,int>
#define mkp make_pair
using namespace std;
#define N 3005
int n;
int a[30005];
int catche[N][N];
int dp(int l , int h){
    if(l>h)return -inf;
    if(l==h) return a[l];
    if(h-l==1){
        return max(a[l],a[h]);
    }
    int &ans=catche[l][h];
    if(ans!=-1) return ans;
    ans=0;
    ans=a[l]+min(dp(l+1,h-1),dp(l+2,h));
    ans=max(ans,a[h]+min(dp(l+1,h-1),dp(l,h-2)));
    return ans;
}

int32_t main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        mem(catche,-1);
        cin >> n;
        int i;
        int s=0;
        for(i=1; i<=n; i++){ cin >> a[i]; s+=a[i];}
        int x=dp(1,n);
        int y=s-x;
        cout << x-y << '\n';



        
        

}

Measured memory_bytes: 70912
#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <cstdlib>

using namespace std;

signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string s;
    cin >> s;
    for (int i = 1; i < s.size(); i++)
    if (s[i - 1] == 'A' && s[i] == 'C'){
        cout << "Yes";
        return 0;
    }
    cout << "No";

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000

using namespace std;

int main(void) {
	int n;
	int count = 0;
	int flag = 0;
	int a, b;

	cin >> n >> a >> b;

	while (1) {
		count++;
		if (count % 2 == 1) {
			if (a < b) {
				if (a + 1 != b) {
					a++;
				}
				else {
					if (a != 1) {
						a--;
					}
					else {
						flag = 1;
						break;
					}
				}
			}
			else {
				if (b < a) {
					if (a - 1 != b) {
						a--;
					}
					else {
						if (a != n) {
							a++;
						}
						else {
							flag = 1;
							break;
						}
					}
				}
			}
		}
		else {
			if (a < b) {
				if (a != b-1) {
					b--;
				}
				else {
					if (b != n) {
						b++;
					}
					else {
						flag = 2;
						break;
					}
				}
			}
			else {
				if (b < a) {
					if (a != b+1) {
						b++;
					}
					else {
						if (b != 1) {
							b--;
						}
						else {
							flag = 2;
							break;
						}
					}
				}
			}
		}
		if (count > 1000) {
			break;
		}
		if (flag != 0) {
			break;
		}
	}

	switch (flag) {
	case 0:
		cout << "Draw" << endl;
		break;
	case 1:
		cout << "Borys" << endl;
		break;
	case 2:
		cout << "Alice" << endl;
		break;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include <assert.h>
#include <iomanip>


int max1 = 1e9;

using namespace std;
vector<int> forb;

bool pesquisa(int ele){
	int start = 0;
	int end = forb.size();
	int meio;
	bool ans = 1;
	while (start<=end){
		meio = (start + end) / 2;
		if (forb[meio] == ele){
			ans = 0;
			break;
		}
		else if (forb[meio] > ele){
			end = meio -1;
		}
		else{
			start = meio + 1;
		}
	}
	return ans;
}


int main(int argc, const char * argv[]) {

    std::ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cin.tie(NULL);
	int x,n,tmp;
	cin >> x >> n;
	if (n == 0){
		cout << x << endl;
		return 0;
	}


	for(int i =0;i<n;i++){
		cin >> tmp;
		forb.push_back(tmp);
	}
	int index1=0;

	sort(forb.begin(),forb.end());
	while (true){
		int busca = x - index1;
		if (pesquisa(busca)){
			cout << busca << endl;
			break;
		}
		busca = x + index1;
		if (pesquisa(busca)){
			cout << busca << endl;
			break;
		}

		index1++;
	}
	

	return 0;
}



Measured memory_bytes: 3652
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

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

#define MOD 1000000007

void solve(int test_case) {//223
	int a,b;
	cin>>a>>b;
	if(a<9&&b<9)cout<<"Yay!"; else cout<<":(";
	
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3660
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
    int n, m;
    scanf("%d %d", &n, &m);
    int *avalues = (int *)malloc(sizeof(int) * n * m);
    for (int i = 0, end = n * m; i < end; ++i)
    {
        int value;
        scanf("%d", &value);
        avalues[i] = value;
    }
    int *bvalues = (int *)malloc(sizeof(int) * m);
    for (int i = 0; i < m; ++i)
    {
        int value;
        scanf("%d", &value);
        bvalues[i] = value;
    }
    for (int i = 0; i < n; ++i)
    {
        long value = 0;
        for (int j = 0; j < m; ++j)
        {
            value += avalues[m * i + j] * bvalues[j];
        }
        printf("%ld\n", value);
    }
    free(avalues);
    free(bvalues);
    return 0;
}



Measured memory_bytes: 2140
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

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

// 多次元 vector 生成
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int H, N;
    cin >> H >> N;
    vector<int> A(N);
    int sum = 0;
    REP(i, N) {
        cin >> A.at(i);
        sum += A[i];
    }
    if (sum >= H) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define int ll
using namespace std;
using ll=long long;
using pii=pair<int,int>;

#define MOD 1000000007

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

int32_t main()
{
	//ios::sync_with_stdio(false);
	//cin.tie(0);
	
	//return 0;
	int h,w; cin>>h>>w;
	vector<vector<int>> a(h+1),b(h+1); //a= ---   b= |||
	for(auto &i:a) i.resize(w+1);
	for(auto &i:b) i.resize(w+1);
	vector<string> v(h);
	for(auto &i:v) cin>>i;
	For(i,0,h-1) v[i]+='#';
	string s; For(i,0,w) s+='#'; v.emplace_back(s);
	h++; w++;
	int cnt=0;
	For(i,0,h-1)
	{
		For(j,0,w-1)
		{
			if(v[i][j]=='.') cnt++;
			else
			{
				a[i][j]=0;
				for(int k=j-1;k>=0 && v[i][k]=='.';k--) a[i][k]=cnt;
				cnt=0;
			}
		}
	}
	cnt=0;
	For(i,0,w-1)
	{
		For(j,0,h-1)
		{
			if(v[j][i]=='.') cnt++;
			else
			{
				b[j][i]=0;
				for(int k=j-1;k>=0 && v[k][i]=='.';k--) b[k][i]=cnt;
				cnt=0;
			}
		}
	}
	int mx=0;
	For(i,0,h-1)
		For(j,0,w-1)
			mx=max(mx,a[i][j]+b[i][j]-1);
	cout<<mx<<"\n";
	//for(auto i:a)
	//{
	//	for(auto j:i) cout<<j<<" ";
	//	cout<<"\n";
	//}
	return 0;
}















Measured memory_bytes: 67072
def i():
  return int(input())
A = i()
B = i()
C = i()
X = i()
ans = 0
for i in range(A+1):
  for j in range(B+1):
    for k in range(C+1):
      if 500*i+100*j+50*k == X:
        ans += 1
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
using namespace std;

int main(){
  bool ans={0};
  string w;
  cin >> w;
  char A;
  for( A = 'a' ; A <= 'z' ; A++){
    int temp = 0;
    for(int i = 0; i < w.size(); i++){
      if(w[i]==A){
        temp++;
      }
      if(i==w.size()-1){
        if(temp % 2 == 1){
          ans = true;
          goto skip;
        }
      }
    }
  }skip:;
  if(ans){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define base 950527
#define base2 1777771
#define N 1001
using namespace std;
typedef unsigned long long ull;
ull A[N][N];
int w,h,p,ans;
bool a[N][N],b[N][N],tmp[N][N];

void Reverse(){for(int i=0;i<p;i++)reverse(b[i],b[i]+p);}

void rol_90(){
  for(int i=0;i<p;i++)
    for(int j=0;j<p;j++) tmp[p-j-1][i]=b[i][j];
  
  for(int i=0;i<p;i++)
    for(int j=0;j<p;j++) b[i][j]=tmp[i][j];
}

int ctoi(char ch){
  if(isupper(ch)) return ch-'A';
  if(islower(ch)) return 26+ch-'a';
  if(isdigit(ch)) return 52+ch-'0';
  if(ch=='+') return 62;
  return 63;
}

void in(int y,bool tmp[N][N]){
  string str[N];
  for(int i=0;i<y;i++) cin>>str[i];
  
  for(int i=0;i<y;i++)
    for(int j=0;j<str[i].size();j++)
      for(int k=0;k<6;k++)tmp[i][6*j+5-k]=(ctoi(str[i][j])>>k)&1;
}

set <ull> S;
void roll_hs(){
  ull target=0;
  for(int i=0;i<p;i++){
    ull k=0;
    for(int j=0;j<p;j++)k=k*base+b[i][j];
    target=target*base2+k; 
  }
  
  if(S.count(target))return;
  S.insert(target);
  
  for(int i=0;i<h;i++){
    ull k=0,l=1;
    for(int j=0;j<w;j++){
      k=k*base+a[i][j];
      if(j-p>=0) k-=l*a[i][j-p];
      else l*=base;
      A[i][j]=k;
    }
  }

  for(int j=p-1;j<w;j++){
    ull k=0,l=1;
    for(int i=0;i<h;i++){
      k=k*base2+A[i][j];
      if(i-p>=0) k-=l*A[i-p][j];
      else l*=base2;
      if(target==k&&i>=p-1)ans++;
    }
  }
}

int main(){
  while(1){
    cin>>w>>h>>p;
    if(!w&&!h&&!p)break;
    in(h,a),in(p,b);
    
    ans=0,S.clear();
    for(int i=0;i<4;i++){
      rol_90(),roll_hs(); 
      Reverse(),roll_hs(),Reverse();
    }
    cout <<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 10508
/*input
1500 2000 500 90000 100000
*/
#include <bits/stdc++.h>
#define mx 100007
using namespace std;
typedef long long int LL;
int main(int argc, char const *argv[])
{
	LL A, B, C, X, Y;
	cin >> A >> B >> C >> X >> Y;
	LL ans = numeric_limits<long long int> :: max();
	for(LL i = 0; i<=200000; i+=2)
	{
		LL needA = max(X - (i / 2), 1LL * 0);
		LL needB = max(Y - (i / 2), 1LL * 0);
		ans = min(ans, needA * A + needB * B + i * C);
	}
	cout << ans << endl;
	return 0;
}

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

	# define int long long

	std::map < std::pair <int, int>, int > map;
	int aPaint;
	int height;  int width;

signed main() {
  std::cin >> height >> width >> aPaint;

	for (int i = 0; i < aPaint; ++i) {
		int posX;  int posY;
		std::cin >> posX >> posY;
		--posX;  --posY;
		for (int j = 0; j < 3; ++j) {
			for (int k = 0; k < 3; ++k) {
				if (posX - j >= 0 && posX - j + 2 < height && posY - k >= 0 && posY - k + 2 < width)
				  ++map[{ posX - j, posY - k }];
			}
		}
	}

	std::cout << (height - 2) * (width - 2) - map.size() << std::endl;
	for (int i = 1; i < 10; ++i) {
		int count = 0;
		// std::cout << "\n";
		for (auto x : map) {
			if (x.second == i) {
				// std::cout << x.first.first << " " << x.first.second << "\n";
				++count;
			}
		}
		std::cout << count << std::endl;
	}
} 

Measured memory_bytes: 56448