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

typedef long int32;
typedef unsigned long uint32;
typedef long long int64;
typedef unsigned long long uint64;

#define st first
#define nd second
#define pb push_back
#define mp make_pair
#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 min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define all(x) (x).begin(),(x).end()
#define debug(x,n) FOR(i,0,n) cout << x[i] << " "; cout << endl

// Custom global variable 



// ----------------------

auto main() -> int
{
  #ifdef DEBUG
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
  #endif
  // Fast I/O
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  // Code starts here ----

	int a,b;
	cin >> a >> b;
	cout << ((a*3+b)>>1);
  // ---------------------
  #ifdef DEBUG
    cerr << endl << "Time:" << double(clock())/CLOCKS_PER_SEC << " secs" << endl;
  #endif
}


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

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF (int)1e9  //
#define LINF (ll)4e18  //
#define MOD (1e9)+7
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define PI 3.1415926535898

//------------------------------------------------------

int main() {
    int n;
    cin >> n;
    cout << n / 3 << endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define  REP(i,n) for(int i=1;i<=n;i++)
int main(){
  int n;
  cin>>n;
  int ans,maxc=0;
  REP(i,n){
    int cnt=0;
    int a=i;
    while(a%2==0){
      a/=2;
      cnt++;
    }
    if(cnt>=maxc){
      maxc=cnt;
      ans=i;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<list>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))

typedef pair<int,int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<PII > VP;

#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
typedef long long int LL;
//typedef __int64 LL;

VI V[200005];
int n;
int cnt[200005];
int color[200005];

int main()
{
	scanf("%d", &n);
	for (int i = 1; i < n; i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		V[u].push_back(v);
		V[v].push_back(u);
	}

	MEM(color, -1);
	queue<PII> Q;
	Q.push({ 1, 0 });
	Q.push({ n, 1 });
	color[1] = 0;
	color[n] = 1;
	cnt[0]++;
	cnt[1]++;
	while (!Q.empty()) {
		PII u = Q.front();
		Q.pop();

		for (int v : V[u.first]) {
			if (color[v] == -1) {
				color[v] = u.second;
				cnt[u.second]++;
				Q.push({ v, u.second });
			}
		}
	}

	if (cnt[0] > cnt[1]) {
		printf("Fennec\n");
	}
	else {
		printf("Snuke\n");
	}
	return 0;
}


Measured memory_bytes: 9088
from statistics import mean
from decimal import Decimal, ROUND_HALF_UP

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

m = Decimal(str(mean(X))).quantize(Decimal('0'), rounding=ROUND_HALF_UP)

ans = 0
for x in X:
  ans += (x - m) ** 2

print(ans)


Measured memory_bytes: 5148
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int main(){
	ll x,y; cin>>x>>y;
	cout<<(1LL<<y)*(100LL*x+1800LL*y)<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    if (a + b == c + d) printf ("Balanced");
    if (a + b > c + d) printf ("Left");
    if (a + b < c + d) printf ("Right");
    return (0);
}


Measured memory_bytes: 128
#include <iostream>
#define N 1000000
using namespace std;

int main(){
  int n;
  bool prime[N];
  for(int i=0;i<N;i++) prime[i]=true;
  prime[0]=prime[1]=false;
  for(int i=0;i<N/2;i++){
    if(!prime[i]) continue;
    for(int j=i+i;j<N;j+=i) prime[j]=false;
  }
  while(cin>>n){
    int ans=0;
    for(int i=0;i<=n;i++)
      if(prime[i]) ans++;
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 2132
import scala.io.StdIn.readInt
  
object Main {
  val r = Array(2,3,5,7)
  
  def twoPow(d:Int,s:Int):(Int,Int) = {
    if(d%2 == 1) (d,s)
    else twoPow(d>>1,s+1)
  }
  
  def maybePrime(i:Int,d:Int,s:Int, n:Int):Boolean = {
    if(i>3) true
    else {
      val a = r(i)
      val x = BigInt(a).modPow(d,n).toLong
  
      if(x==1 || x==n-1) maybePrime(i+1,d,s,n)
      else repeat(s-1,x*x%n, i, d, s, n)
    }
  }
  
  def repeat(j:Int, x:Long, i:Int, d:Int, s:Int, n:Int):Boolean = {
    if(j==0) false
    else if(x==1) false
    else if(x==n-1) maybePrime(i+1,d,s,n)
    else repeat(j-1,x*x%n,i,d,s,n)
  }
  
  def isPrime(n:Int):Boolean = {
    if(n<2000) (2 to Math.sqrt(n).toInt).forall(n%_ != 0)
    else if(n%2==0) false
    else {
      val (d,s) = twoPow(n-1,0)
      maybePrime(0,d,s,n)
    }
  }
  
  def main(args:Array[String]) = {
    val n = readInt
    println((0 until n).count{ _=> isPrime(readInt) })
  }
}

Measured memory_bytes: 61996
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include <cassert>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using namespace std;
using testimony = pair<set<int>, set<int>>;

int main() {
    vector<int> primes;
    primes.push_back(2);
    for(int i=3; i<100010; ++i) {
        bool is_prime = true;
        for(auto p: primes) {
            if(i % p == 0) {
                is_prime = false;
                break;
            }
            if(p*p >= i) {
                break;
            }
        }
        if(is_prime) {
            primes.push_back(i);
        }
    }
    vector<int> like_nums;
    for(int i=1; i<100010; i+=2) {
        auto it = lower_bound(primes.begin(), primes.end(), i);
        if(it == primes.end() || *it != i)
            continue;
        it = lower_bound(primes.begin(), primes.end(), (i+1) / 2);
        if(it == primes.end() || *it != (i+1)/2)
            continue;
        like_nums.push_back(i);
    }

    int Q;
    int l, r;
    cin >> Q;
    rep(i, Q) {
        cin >> l >> r;
        auto il = lower_bound(like_nums.begin(), like_nums.end(), l); 
        auto ir = upper_bound(like_nums.begin(), like_nums.end(), r); 
        //cout << *il << " " << *ir << " " << ir-il << endl;
        cout << ir-il << endl;
    }

    return 0;
}



Measured memory_bytes: 3216
#include"bits/stdc++.h"
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;
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; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill( (T*)array, (T*)(array+N), val ); }
#define INF 1e9
#define PI (acos(-1))
#define mod (int)1e9+7
int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    REP(i, n)cin >> s[i];
    vector<int> c(4,0);
    REP(i, n) {
        if (s[i] == "AC")c[0]++;
        if (s[i] == "WA")c[1]++;
        if (s[i] == "TLE")c[2]++;
        if (s[i] == "RE")c[3]++;
    }
    cout << "AC x " << c[0] << endl;
    cout << "WA x " << c[1] << endl;
    cout << "TLE x " << c[2] << endl;
    cout << "RE x " << c[3] << endl;
    return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define show(x) cerr << #x << " " << x << endl

typedef long long ll;
typedef unsigned long long ull;

constexpr const int INT_INF=0x3f3f3f3f; // 1061109567
constexpr const ll LL_INF=0x3f3f3f3f3f3f3f3f; // 4557430888798830399

template <typename T> bool chmin(T &a, T b) {
    if (a > b) {a = b;return true;}return false;
}

template <typename T> bool chmax(T &a, T b) {
    if (a < b) {a = b;return true;}return false;
}

// INT
#define GCD(a, b) __gcd(a, b)
template <typename T> T LCM(T a, T b) {return a / GCD(a, b) * b;}
template <typename T> T EXTGCD(T a, T b, T& x, T& y) {
    T d = a;
    if (b != 0) {d=EXTGCD(b,a%b,y,x);y-=(a/b)*x;}
    else x=1,y=0;
    return d;
}
template <typename T> bool is_prime(T a) {
    for(int i=2;i*i<=a;i++)if(a%i==0)return 1;
    return 0;
}

// MOD
const ll MOD = 1000000000 + 7;
#define add(a, b) ((a % MOD) + (b % MOD)) % MOD
#define mul(a, b) ((a % MOD) * (b % MOD)) % MOD
#define sub(a, b) ((a % MOD) + MOD - (b % MOD)) % MOD
template <typename T> T mod_inverse(T a, T mod, bool prime){ // if mod is prime, "prime" is true.
    if(prime){
        T tmp=mod-2,now=a,res=1;while(tmp){if(tmp&1)res=mul(res,now);now=mul(now,now);tmp>>=1;}
        return res;
    }else{T x,y;EXTGCD(a,mod,x,y);return (mod+x%mod)%mod;}
}
#define divide(a, b) ((a % MOD) * (mod_inverse(b, MOD, true))) % MOD

//LLの数値をつかう時は最後にLをつける癖をつけよう
//
//  　　┓　　　┏
//  　＊┗┓　┏┛
//  　　　┫　┣　＊
//  　┏┳┻━┻┳┓
//  　┗┫　　　┣┛
//  ＊　┣　　━┃　＊        Merry Christmas!!
//  　┏┛　　〃┃
//  　┃●　　　┣━┳┓
//  　┗┻┳━━┛　┣┛
//  　＊　┃┏┓┣┓┃
//WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW

ll n, x;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    FILE *stream1;
    //FILE *stream2;
    stream1 = freopen("/Users/aim_cpo/CLionProjects/competitive/in.txt", "r", stdin);
    //stream2 = freopen("out.txt", "w", stdout);
    if (stream1 == nullptr) return 0;
    //if (stream2 == NULL) return 0;
#endif
    cin >> n >> x;
    ll len1 = x, len2 = n - x;
    ll ans = n;
    while (true) {
        // show(len1);
        // show(len2);
        if (len1 > len2) {
            if (len1 % len2 == 0) {
                ans += len1 / len2 * 2L * len2 - len2;
                len1 = 0;
            } else {
                ans += len1 / len2 * 2L * len2;
                len1 %= len2;
            }
        } else {
            if (len2 % len1 == 0) {
                ans += len2 / len1 * 2L * len1 - len1;
                len2 = 0;
            } else {
                ans += len2 / len1 * 2L * len1;
                len2 %= len1;
            }
        }
        if (len1 == 0 || len2 == 0) break;
    }
    cout << ans << endl;
#ifdef  LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
#endif
    return 0;
}

Measured memory_bytes: 256
# import sys
# import math #sqrt,gcd
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
from itertools import product,permutations,combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

def readInt():
    return list(map(int,input().split()))

def main():
    n = int(input())
    k = int(input())
    x = readInt()
    ans = 0
    for i in range(n):
        ans += min(x[i],abs(x[i]-k)) * 2
    print(ans)
    return

if __name__=='__main__':
    main()

Measured memory_bytes: 3064
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T3;

int main(){
	int sx,sy,tx,ty;
	cin >> sx >> sy >> tx >> ty;

	string ans = "";
	for(int i = 0;i < tx - sx;i++)ans += 'R';
	for(int i = 0;i < ty - sy;i++)ans += 'U';
	for(int i = 0;i < tx - sx;i++)ans += 'L';
	for(int i = 0;i < ty - sy;i++)ans += 'D';

	ans += 'D';
	for(int i = 0;i < tx - sx + 1;i++)ans += 'R';
	for(int i = 0;i < ty - sy + 1;i++)ans += 'U';

	ans += 'L';
	ans += 'U';
	for(int i = 0;i < tx - sx + 1;i++)ans += 'L';
	for(int i = 0;i < ty - sy + 1;i++)ans += 'D';
	ans += 'R';
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;

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

const int inf = 1e9 + 1;
const double eps = 1e-9;
const int MAXN = 1e3 + 1;
const int MOD = 1e9 + 7;

int h, w;
char p[MAXN][MAXN];
int dp[MAXN][MAXN];

int main(){

    cin >> h >> w;
    for (int i = 0; i < h; i++) cin >> p[i];

    dp[0][0] = 1;
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            if (p[i][j] == '#') continue;
            if (i > 0) dp[i][j] = (dp[i][j]%MOD + dp[i-1][j]%MOD)%MOD;
            if (j > 0) dp[i][j] = (dp[i][j]%MOD + dp[i][j-1]%MOD)%MOD;
        }
    }

    cout << dp[h-1][w-1];

    return 0;

}


Measured memory_bytes: 5120
#include<iostream>                    
using namespace std;
int main(){
 
  int n,a[10000],i,s(1000000),b(-1000000);
  long long w=0;
  cin>>n;
  for(int i=0;i<n; i++)
  {
         cin>>a[i];
 
           w+=a[i];
		   
         if(s>a[i])
         {
	       s=a[i];
         }
        if(b<a[i])
         {      

	         b=a[i];

		}
  
  }
  cout<<s<<" "<<b<<" "<<w<<endl;


  return 0;
  }  



Measured memory_bytes: 3160
#include<iostream>
using namespace std;
int main(){

long long a, b, c, k, ans = 0, tmp;
    cin >> a >> b >> c >> k;
    tmp = min(a, k);
    ans += tmp;
    k -= tmp;
    tmp = min(b, k);
    k -= tmp;
    tmp = min(c, k);
    ans -= tmp;
    k -= tmp;
    cout << ans << endl;
}

Measured memory_bytes: 3568
A, B, K = map(int, input().split())

B += 1
K = min(B-A, K)

ans_F = [x for x in range(A, A+K)]
ans_B = [x for x in range(B-K, B)]

ans = sorted(set(ans_F)|set(ans_B))

for i in ans:
    print(i)


Measured memory_bytes: 3060
#[allow(unused_imports)]
use std::io;
#[allow(unused_imports)]
use std::cmp;

#[allow(dead_code)]
fn getline() -> Vec<String> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok().unwrap();
    s.split(' ').map(|x| x.trim().to_string()).collect::<Vec<String>>()
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>(s: &String) -> T {
    s.parse().ok().unwrap()
}

fn main() {
    let abc = getline().into_iter()
        .map(|s| s.chars().collect::<Vec<_>>()).collect::<Vec<_>>();
    for i in 0..2 {
        if abc[i].last() != abc[i+1].first() {
            println!("NO");
            return;
        }
    }
    println!("YES");
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef pair<int, int> pii;

int main() {
  int N;
  cin >> N;
  for (int i = 0; i <= N; i++) {
    if (floor(1.08 * i) == N) {
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int n = 0, m = 0;
vector<vector<int>> g;
vector<bool> vi;
vector<int> comp;
stack<int> post;
vector<pair<int, int>> q;
void input() {
    cin >> n >> m;
    g = vector<vector<int>>(n, vector<int>());
    vi = vector<bool>(n, false);
    comp = vector<int>(n, -1);
    q = vector<pair<int, int>>(0);
    while (m--) {
        int a = 0, b = 0;
        cin >> a >> b;
        g[a].push_back(b);
    }
    int Q = 0;
    cin >> Q;

    while (Q--) {
        int q1 = 0, q2 = 0;
        cin >> q1 >> q2;
        q.push_back({q1, q2});
    }
}

void dfs1(int i) {
    vi[i] = true;
    for (auto nig : g[i]) {
        if (vi[nig] == false) {
            dfs1(nig);
        }
    }
    post.push(i);
}
void reverseG() {
    vector<vector<int>> rev(n, vector<int>(0));
    for (int i = 0; i < g.size(); i++) {
        for (int j = 0; j < g[i].size(); j++) {
            int node = g[i][j];
            rev[node].push_back(i);
        }
    }
    g = rev;
}
void dfs2(int i, int comp_n) {
    comp[i] = comp_n;
    for (auto nig : g[i]) {
        if (comp[nig] == -1) {
            dfs2(nig, comp_n);
        }
    }
}
void compute() {
    for (int i = 0; i < n; i++) {
        if (vi[i] == false) dfs1(i);
    }
    reverseG();
    int comp_n = 0;
    while (!post.empty()) {
        int curr = post.top();
        post.pop();
        if (comp[curr] == -1) dfs2(curr, ++comp_n);
    }
    for (auto qq : q) {
        if (comp[qq.first] == comp[qq.second])
            cout << "1" << endl;
        else
            cout << "0" << endl;
    }
}

int main() {
    input();
    compute();
    return 0;
}


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

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

int a[3];

int main(void)
{
  REP(i, 3) cin >> a[i];
  sort(a, a + 3);
  cout << a[0] + a[1] << endl;
  return 0;
}


Measured memory_bytes: 888
N = gets.to_i
a = gets.split(' ').map(&:to_i)
N.times do |i|
	a[i] -= (i + 1)
end
a.sort!
b = a[N / 2]
ans = 0
N.times do |i|
	ans += (a[i] - b).abs
end
puts ans

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

int main() {
	int x; cin>>x;
  	int t=1,mymax=1;
  	for (int i=1;i<=32;i++){
      	t=i;
    	for (int j=2;j<=10;j++){
        	t=t*i;
          	if(t<=x){
            	mymax=max(mymax,t);
            }
        }
    }
  	cout<<mymax<<endl;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
D=0
k=1
while k>=0:
 for i in range(n):
  if a[i]%2**k==0:
    D+=1
 if D==n:
    k+=1
    D=0
 else:
  print(k-1)
  break
    

Measured memory_bytes: 2940
from collections import deque

n = int(input())

linked_list = deque([])

for _ in range(n):
    command = input()

    if "insert" in command:
        x = command.split()[-1]
        linked_list.appendleft(x)
    elif command == "deleteFirst":
        linked_list.popleft()
    elif command == "deleteLast":
        linked_list.pop()
    elif "delete" in command:
        x = command.split()[-1]
        if x in linked_list:
            linked_list.remove(x)

print(*linked_list)



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

#define REP(i,n) for(int i = 0;i < n;i++)
#define REPR(i,n) for(int i = n-1;i >= 0;i--)
#define FOR(i,m,n) for(int i = m;i < n;i++)
#define PRINT(s) cout<<s
#define PRINTS(s) cout<<s<<' '
#define PRINTL(s) cout<<s<<endl
#define INF 2e9
#define ALL(v) v.begin(),v.end()
#define ll long long

using namespace std;

string pop_back(string s){
    string t = s.substr(0,s.size()-1);
    return t;
}

int gcd(int max,int min){
    
    if(max<min){
        int tmp=max;
        max=min;
        min=tmp;
    }

    if(max%min==0)return min;
    else return gcd(min,max%min);

}

int main(void){

    int n;
    cin>>n;
    int m = n;
    int sumx = 0;
    while(m>0){
        sumx+=m%10;
        m/=10;
    }
    cout<<(n%sumx==0?"Yes":"No")<<endl;

    return 0;
}




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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, double> pid;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N;
	cin >> N;

	cout << N * (N + 1) / 2 << endl;

	return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  if ((A + B) > (C + D)) {
    cout << "Left" << endl;
  } else if ((A + B) < (C + D)) {
    cout << "Right" << endl;
  } else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	char s;
	cin >> s;
		if (s == 'A')s = 'T';
		else if (s == 'T')s = 'A';
		else if (s == 'C')s = 'G';
		else if (s== 'G')s = 'C';
		cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
n, k = int(input()), int(input())
l = len(str(n))
s = [0] + list(map(int, str(n)))
if k > l: print(0); exit()

dp = [[[0] * 2 for _ in range(k+1)] for _ in range(l+1)]
dp[0][0][1] = 1

for dig in range(l):
    for i in range(k+1):
        dp[dig+1][i][0] += dp[dig][i][0]
        dp[dig+1][i][1 if s[dig+1] == 0 else 0] += dp[dig][i][1]
        if i < k:
            dp[dig+1][i+1][0] += dp[dig][i][0] * 9
            if s[dig+1] > 0:
                dp[dig+1][i+1][1] += dp[dig][i][1]
                dp[dig+1][i+1][0] += dp[dig][i][1] * (s[dig+1]-1)

print(dp[l][k][0] + dp[l][k][1])


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	/**
	 * Main method.
	 */
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		
		int A = s.nextInt();
		int B = s.nextInt();
		
		int count = 0;
		
		for (int i = B; i >= A; i--) {
			int tenThousand = (int)(i / 10000);
			int thousand = (i / 1000) % 10;
			int ten = (i / 10) % 10;
			int one = i % 10;
			
			if (tenThousand == one && thousand == ten) {
				count++;
			}
		}
		
		System.out.println(count);
		
	}
}

Measured memory_bytes: 22608
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A,B,N;
    cin >> A >> B >> N;
    ll ans = 0;

    auto f = [&](ll x){
        return A*x/B-A*(x/B);
    };

    cout << f(min(B-1,N)) << "\n";

}

Measured memory_bytes: 3648
# N = m x n (m <= n) と表される時、m <= √n である
# この時の最大となるmを求める
import math

N = int(input())

limit = int(math.sqrt(N))
for i in reversed(range(1, limit + 1)):
    if N % i == 0:
        m = i
        n = int(N / i)
        print((m - 1) + (n - 1))
        exit()


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

main :: IO ()
main = do
  [w,h] <- map read . words <$> getLine
  ps <- replicateM w $ readLn
  qs <- replicateM h $ readLn
  let s = sort $ zip ps (repeat False) ++ zip qs (repeat True)
  print $ solve (fromIntegral w+1) (fromIntegral h+1) s

solve :: Integer -> Integer -> [(Integer,Bool)] -> Integer
solve w h [] = 0
solve w h ((c,False):s) = c*h + solve (w-1) h s
solve w h ((c,True):s) = c*w + solve w (h-1) s

Measured memory_bytes: 107900
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long ,long long>pll;

ll gcd(ll a, ll b) {return (!b ? a : gcd(b, a % b));}
ll lcm(ll a, ll b) {return ((a*b)/gcd(a,b));}
bool cmp(int a,int b){return a>b;}

const ll mod = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;

unsigned long long modpow(unsigned long long n, unsigned long long k, unsigned long long mod)
{
if (k == 0) return 1;
long long r = modpow(n * n % mod, k >> 1, mod);
if (k & 1) r = r * n % mod;
return r;
}
vector<ll>parent(1e5+10,-1);
vector<ll>rk(1e5+10,0);
vector<ll>sum(1e5+10,1);
int find_root(int x){
   ll x_root = x;
   while(parent[x_root]!=-1) x_root = parent[x_root];
   return x_root;
}
void union_uv(int x,int y){
   ll x_root = find_root(x);
   ll y_root = find_root(y);
   if(rk[x_root]<rk[y_root]){
    parent[x_root] = y_root;
    sum[y_root] += sum[x_root];
    sum[x_root] = 0;
   }
   else if(rk[x_root]>rk[y_root]){
    parent[y_root] = x_root;
    sum[x_root] += sum[y_root];
    sum[y_root] = 0;
   }
   else{
    rk[x_root]++;
    parent[y_root] = x_root;
    sum[x_root] += sum[y_root];
    sum[y_root] = 0;
   }
}
void solve(){
    ll n,m;cin >> n >> m;
    vector<ll>v(m);
    vector<ll>u(m);
    for(int i = 0;i<m;i++)
        cin >> v[i] >> u[i];
    vector<ll>ans(m+1,n*(n-1)/2);
    for(int i = m-1;i>=0;i--){
        ll vv = find_root(v[i]);ll uu = find_root(u[i]);
        if(vv==uu)
            ans[i] = ans[i+1];
        else{
            ans[i] = ans[i+1] - sum[vv]*sum[uu];
            union_uv(v[i],u[i]);
        }
    }
    for(int i = 1;i<=m;i++)
        cout << ans[i] <<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 7940
N, M = [int(i) for i in input().split()]
d = {i+1: 0 for i in range(M)}
for _ in range(N):
  for j in [int(i) for i in input().split()][1:]:
    d[j] += 1
ans = 0
for k in d.values():
  if k == N:
    ans += 1
print(ans)

Measured memory_bytes: 38256
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		double r = sc.nextDouble();
		
		double pi = Math.PI;//円周率
		double menseki = r * r * pi;//面積算出
		double ensyu = 2 * r * pi;//円周算出
		System.out.printf("%.6f %.6f",menseki,ensyu);//計算結果を６桁で表示
		
	}
}

Measured memory_bytes: 18948
#include<bits/stdc++.h>
/*
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<numeric>
#include<iomanip>
#include<utility>
#include<cstdlib>
#include<typeinfo>
#include<stack>
#include<cassert>
#include<functional>
*/
#define int long long int
#define double long double
using namespace std;
#define INT_DMAX 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define rep(i,n) for(int (i)=0, i##_len = (n);(i)<i##_len;(i)++)
#define reps(i,x) for(int (i)=1;(i)<=(int)(x);(i)++)
#define rrep(i,x) for(int (i)=((int)(x)-1);(i)>=0;(i)--)
#define rreps(i,x) for(int (i)=((int)(x));(i)>0;(i)--)
#define FOR(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define bit(n) ((int)(1)<<(n))
#define all(x) (x).begin(),(x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl 
#define nint int
using namespace std;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
typedef pair<int,int> p;
typedef pair<double,double> dop;
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 gcd(int a,int b){return b?gcd(b,a%b):a;}
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

struct node{
    std::vector<int> nextnode;
};


signed main()
{
int n,m;
std::cin >> n >> m;
std::vector<node> nodelist(n);
for(int i = 0; i < m; i++){
    int a,b;
    std::cin >> a >> b;
    a--;
    b--;
    nodelist[a].nextnode.pb(b);
    nodelist[b].nextnode.pb(a);
}
int r = INF;
int l = INF;
for(int i = 0; i < n; i++){
    if(nodelist[i].nextnode.size() > 0){
        r = i;
        l = nodelist[i].nextnode[0];
        break;
    }
}
std::vector<int> lpath;
std::vector<int> rpath;
std::vector<int> check(n,0);
rpath.pb(r);
lpath.pb(l);
check[r]++;
check[l]++;
int sum = 2;
while(1){
    int flag = 0;
    for(int i = 0; i < nodelist[r].nextnode.size(); i++){
        if(check[nodelist[r].nextnode[i]] == 0){
            r = nodelist[r].nextnode[i];
            flag = 1;
            rpath.pb(r);
            check[r]++;
            sum++;
            break;
        }
    }
    if(flag == 0){
        break;
    }
}
while(1){
    int flag = 0;
    for(int i = 0; i < nodelist[l].nextnode.size(); i++){
        if(check[nodelist[l].nextnode[i]] == 0){
            l = nodelist[l].nextnode[i];
            flag = 1;
            lpath.pb(l);
            check[l]++;
            sum++;
            break;
        }
    }
    if(flag == 0){
        break;
    }
}

std::cout << sum << std::endl;
for(int i = lpath.size() - 1; i >= 0; i--){
    std::cout << lpath[i] + 1 << " ";
}
for(int i = 0; i < rpath.size() - 1; i++){
    std::cout << rpath[i] + 1<< " ";
}
std::cout << rpath[rpath.size() - 1] + 1 << std::endl;
return 0;
}

Measured memory_bytes: 8052
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};

int s(int n) {
    return ceil((double)n / 10) * 10;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, a, b, c, d, e; cin >> n >> a >> b >> c >> d >> e;
    cout << fixed << (ll)ceil((double)n / min({a, b, c, d, e})) + 4 << endl;
    
}




Measured memory_bytes: 256
def gcd(x,y):
  if x%y==0:
    return y
  else:
    return gcd(y,x%y)

a,b,k=map(int,input().split())
z=gcd(a,b)
ans=[]
for i in range(1,z+1):
  if z%i==0:
    ans.append(i)
    
print(ans[-k])  
    


Measured memory_bytes: 2940
//https://atcoder.jp/contests/abc123/tasks/abc123_c
function setUp(input) {
  input = input.split("\n");
  n = Number(input[0]);
  a = Number(input[1]);
  b = Number(input[2]);
  c = Number(input[3]);
  d = Number(input[4]);
  e = Number(input[5]);
  main();
}
function main() {
  arr = [a, b, c, d, e];
  arr.sort(function (A, B) {
    return A - B;
  });
  var min = arr[0];
  var bottleNeck = Math.ceil(n / min);
  console.log(4 + bottleNeck);
}
setUp(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
# coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)
#from heapq import heappop, heappush
#from collections import defaultdict
# import math
# from itertools import product, accumulate, combinations, product
# import bisect# lower_bound etc
#import numpy as np
# from copy import deepcopy
#from collections import deque
#import numba
#import math

def run():
    X = list(map(int, input().split()))
    print(X.index(0)+1)


if __name__ == "__main__":
    run()

Measured memory_bytes: 9184
use std::io::*;
use std::char;

fn get_line() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_string()
}

fn make_number(v: &mut Vec<u32>, s: String, d: usize, digits: &Vec<char>) {
    if d > 0 {
        for c in digits.iter() {
            let mut s2: String = s.clone();
            s2.push(*c);
            make_number(v, s2, d - 1, digits);
        }
    } else {
        v.push(s.parse().unwrap());
    }
}

fn main() {
    let n: String = get_line().split_whitespace().next().unwrap().to_string();
    let ds: Vec<usize> = get_line()
                             .split_whitespace()
                             .map(|x| x.parse().unwrap())
                             .collect();

    let mut cs: Vec<char> = Vec::new();
    for i in 0..10 {
        if ds.iter().all(|c| *c != i) {
            cs.push(char::from_digit(i as u32, 10).unwrap());
        }
    }

    let mut nums: Vec<u32> = Vec::new();
    for i in n.len()..6 {
        make_number(&mut nums, String::new(), i, &cs);
    }
    nums.sort();
    let n2: u32 = n.parse().unwrap();
    println!("{}", nums.iter().find(|x| **x >= n2).unwrap());
}


Measured memory_bytes: 1148
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

int main(){

    int h, w;
    cin >> h >> w;

    vector<vector<int>> v(h, vector<int>(w));
    char tmpc;
    REP(i,h){
        REP(j,w){
            cin >> tmpc;
            if(tmpc == '.'){
                v[i][j] = 0;
            }else{
                v[i][j] = 1;
            }
        }
    }

    int tmpi=0;
    
    REP(i,h){
        REP(j,w){
            tmpi += v[i][j];
        }

        if(tmpi==0){
            REP(j,w){
                v[i][j]=2;
            }
        }
        tmpi = 0;
    
    }
    
    REP(i,w){
        REP(j,h){
            
            if(v[j][i]!=2){
                tmpi += v[j][i];
            }
        }

        if(tmpi==0){
            REP(j,h){
                v[j][i]=2;
            }
        }
        tmpi = 0;
    
    }

    REP(i,h){
        REP(j,w){
            
            
            if(v[i][j] == 0){
                cout <<'.';
            }else if(v[i][j]==1){
                cout<<'#';
            }
            
            
        }

        if(accumulate((v[i].begin()), (v[i].end()), 0)==2*w){
            continue;
        }

        cout << endl;
        
    }

    return 0;
}

Measured memory_bytes: 888
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
  int n,x,i,sum,l,low;
  cin >> n >> x;
  cin >> l;
  sum=l;
  low=l;
  for(i=0;i<n-1;i++){
    cin >> l;
    sum+=l;
    if(l<low)low=l;
  }
  cout << n+(x-sum)/low << endl;
}

Measured memory_bytes: 256
#include  <bits/stdc++.h>
#define range(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define rep(i,n) range(i,0,n)
using namespace std;

typedef bool B;
typedef long double D;
typedef complex<D> P;
typedef vector<P> VP;
typedef struct {P s,t;} L;
typedef vector<L> VL;
typedef struct {P c;D r;} C;
typedef vector <C> VC;

const D eps=1.0e-10;
const D pi=acos(-1.0);
template<class T> bool operator==(T a, T b){return abs(a-b)< eps;}
template<class T> bool operator< (T a, T b){return a < b-eps;}
template<class T> bool operator<=(T a, T b){return a < b+eps;}
//template<class T> int sig(T r) {return (r==0||r==-0) ? 0 : r > 0 ? 1 : -1;}
template<class T> int sig(T a,T b = 0) {return a < b ? -1 : b > a ? 1 : 0;}
#define X real()
#define Y imag()

D ip(P a, P b) {return a.X * b.X + a.Y * b.Y;}
D ep(P a, P b) {return a.X * b.Y - a.Y * b.X;}
D sq(D a) {return sqrt(max(a, (D)0));}
P vec(L l){return l.t-l.s;}
inline P input(){D x,y;char c;cin >> x >> c >> y; return P(x,y);}

inline B cmp_x(const P &a,const P &b){
	return (abs(a.X-b.X)<eps ) ?  a.Y<b.Y : a.X<b.X;
}  // base x

VP convex_hull(VP pol){
	int n=pol.size(),k=0;
	sort(pol.begin(),pol.end(),cmp_x);
	VP res(2*n);

	//??\??????while?????????????????????
	//????????????????????????????????????????????´??????<=0
	//???????????????????????????????????????????????´??????<0

	// down
	rep(i,n){
		while( k>1 && ep(res[k-1]-res[k-2],pol[i]-res[k-1])<0) k--;
		res[k++]=pol[i];
	}
	// up
	for(int i=n-2,t=k;i>=0;i--){
		while( k>t && ep(res[k-1]-res[k-2],pol[i]-res[k-1])<0) k--;
		res[k++]=pol[i];
	}
	res.resize(k-1);
	return res;
}

int main(void){
    for(int n; cin >> n, n;){
        VP p(n);
        for(auto & e : p) e = input();

        VP cp = convex_hull(p);

        cout << p.size() - cp.size() << endl;
    }

	return 0;
}

// inline??????????????????
// eps????°????????????????
// double??????????????????

Measured memory_bytes: 1248
#include<iostream>
using namespace std;
int main()
{
  int n,m,t,tt=1,o,i,j,k,f,b;
  long long res;
  cin >> n;
  if(n<10){
    cout << n << endl;
    return 0;
  }
  b=n%10;
  f=n;
  for(o=1;;o++){
    if(f<10) break;
    f/=10;
  }
  res=9;
  t=1;
  for(k=2;k<o;k++){
    res+=2*9*t;
    t*=10;
  }
  res+=2*(f-1)*t;
  m=n/10-f*t+1;
  res+=2*m;
  if(f>b)
    res-=2;
  for(i=2,t=1;i<o;i++,t*=10)
    for(k=2,tt=1;k<o;k++,tt*=10)
      res+=81*t*tt;
  for(i=2,t=1;i<o;i++,t*=10){
    res+=2*9*(f-1)*t*tt;
    res+=2*9*(m-1)*t+2*b*t;
  }
  res+=(f-1)*(f-1)*tt*tt;
  if(f>b)
    m--;
  res+=2*(f-1)*m*tt;
  res+=m*m;
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::collections::HashSet;

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let hw = read_vec::<usize>();
    let h = hw[0];
    let w = hw[1];

    let mut shogai_yoko : Vec<Vec<usize>> = Vec::with_capacity(h);
    let mut shogai_tate : Vec<Vec<usize>> = Vec::with_capacity(w);
    for _i in 0..w {
        let v : Vec<usize> = Vec::with_capacity(h);
        shogai_tate.push(v)
    }
    
    for i in 0..h {
        let mut v : Vec<usize> = Vec::with_capacity(w);
        let s = read::<String>();
        for (j, c) in s.chars().enumerate() {
            if c == '#' {
                v.push(j);
                shogai_tate[j].push(i)
            }
        }
        v.push(w);
        shogai_yoko.push(v);
    }
    for j in 0..w {
        shogai_tate[j].push(h)
    }


    let answer = solve(h, w, &shogai_yoko, &shogai_tate);
    println!("{}", answer);
}

fn solve(h: usize, w: usize, shogai_yoko: &[Vec<usize>], shogai_tate: &[Vec<usize>]) -> usize {
     // (yoko, tate)
     let mut dp : Vec<Vec<usize>> = Vec::with_capacity(h);
     for _i in 0..h {
        let v : Vec<usize> = vec![0; w];
        dp.push(v);
     }

     // yoko
     for i in 0..h {
        let mut from = 0;
        for x in &shogai_yoko[i] {
            let d = x - from;
            if d > 0 {
                for j in from..*x {
                    dp[i][j] = d - 1;
                }
            }
            from = x + 1;
        }
    }

    // tate (and total)
    let mut max = 0;
    for j in 0..w {
        let mut from = 0;
        for x in &shogai_tate[j] {
            let d = x - from;
            if d > 0 {
                for i in from..*x {
                    let val = dp[i][j] + (d - 1);
                    if val > max {
                        max = val
                    }
                }
            }
            from = x + 1;
        }
    }
    return max + 1
}


Measured memory_bytes: 192764
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;

int main(){

  int x[30],y[30];
  char d[40];
  int l[40];
  int n,m;
  int mama[30];
  while(scanf("%d",&n),n){
    fill(mama,mama+30,0);
    int rx=10,ry=10;

    rep(i,n) scanf("%d %d",&x[i],&y[i]);
    scanf("%d",&m);
    rep(i,m){
      //scanf(" %c%d",&d[i],&l[i]);
      cin >> d[i] >> l[i];
      if(d[i]=='N'){
        reg(j,ry,ry+l[i]){
          rep(k,n){
            if(x[k]==rx && y[k]==j) mama[k]=1;
          }
        }
        ry=ry+l[i];
      }
      else if(d[i]=='E'){
        reg(j,rx,rx+l[i]){
          rep(k,n){
            if(x[k]==j && y[k]==ry) mama[k]=1;
          }
        }
        rx=rx+l[i];
      }
      else if(d[i]=='S'){
        reg(j,ry-l[i],ry){
          rep(k,n){
            if(x[k]==rx && y[k]==j) mama[k]=1;
          }
        }
        ry=ry-l[i];
      }
      else if(d[i]=='W'){
        reg(j,rx-l[i],rx){
          rep(k,n){
            if(x[k]==j && y[k]==ry) mama[k]=1;
          }
        }
        rx=rx-l[i];
      }
    }
    bool yu=true;
    rep(i,n){ if(mama[i]==0) yu=false;}
    if(yu) printf("Yes\n");
    else printf("No\n");
  }

  return 0;

}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;


const int N = 2e5+5;

// it's swapnil07 ;)
 
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif


void solve(){
    int x, n; cin>>x>>n;
    set<int> s;
    For(i, 0, n){
        int a; cin>>a;
        s.insert(a);
    }
    int v = INF;
    int cur = -INF;
    For(i, -1, 201){
        if(s.find(i)!=s.end())
            continue;
        if(abs(i-x)<v){
            cur = i;
            v = abs(i-x);
        }
    }
    cout<<cur;
}


signed main()
{
    fast
    #ifdef SWAPNIL07
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    int t=1; 
    // cin>>t;
    while(t--){
        solve();
        cout<<"\n";
    }
    return 0;
}



Measured memory_bytes: 3660
import bisect
import time

def main():
    N = int(input())
    L = [int(i) for i in input().split()]
    #N = 2000
    #L = [int(i) for i in range(N)]

    L.sort()
    ans = 0
    for i in range(N-2):
        for j in range(i+1,N-1):
            #ans += bisect.bisect_left(L[j+1:], L[i]+L[j])
            index = bisect.bisect_left(L, L[i]+L[j])
            ans += (index - (j+1))

    print(ans)


if __name__ == "__main__":
    #start = time.time()
    main()
    #elapsed_time = time.time() - start
    #print ("elapsed_time:{0}".format(elapsed_time) + "[sec]")


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

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

//NodePointer listSearch(int key){
//  /* your code */
//}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  t->next->prev = t->prev;
  t->prev->next = t->next;
  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  NodePointer t = nil->prev;
  if (t == nil) return;
  deleteNode(t);
}

void delete(int key){
  NodePointer x = nil->next;

  for(x = nil->next; x != nil; x = x->next) {
    if (x->key == key) {
      if (x->next == nil)
        deleteLast();
      else if (x->prev == nil)
        deleteFirst();
      else 
        deleteNode(x);
      break;
    }
  }
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;

  x->next = nil->next;
  x->prev = nil;
  nil->next->prev = x;
  nil->next = x;
  
  //x->next = nil->next;
  //x->prev = nil;

  //nil->next->prev = x;
  //nil->next = x;

}


int main(void)
{
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;

  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {
      insert(key);
      np++;
      size++;
    } else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
        if ( com[6] == 'F' ) deleteFirst();
        else if ( com[6] == 'L' ) deleteLast();
      } else {
        delete(key);
        nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}



Measured memory_bytes: 32952
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
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; }

const lli mod = 1e9+7;
lli n;

int main(void){
    cin >> n;
    vector<lli> a(n);
    rep(i, n){
        cin >> a[i];
    }
    vector<lli> x(n+1), y(n+1), z(n+1);
    rep(i, n){
        x[i+1] = x[i];
        y[i+1] = y[i];
        z[i+1] = z[i];
        if(a[i] == x[i]) x[i+1]++;
        else if(a[i] == y[i]) y[i+1]++;
        else if(a[i] == z[i]) z[i+1]++;
    }
    lli ans = 1;
    rep(i, n){
        lli t=0;
        if(a[i] == x[i]) t++;
        if(a[i] == y[i]) t++;
        if(a[i] == z[i]) t++;
        ans*=t;
        ans%=mod;
    }
    cout << ans << endl;

    return 0;
}


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

using namespace std;

const int N = 107;
const int W = 1e5 + 7;

long long f[N][W];
int v[N], w[N], n, k;

int main()
{
    //freopen("D.inp","r",stdin);
   // freopen("D.out","w",stdout);

    cin >> n >> k;

    for(int i = 1; i <= n; i++) cin >> w[i] >> v[i];

    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= k; j++)
        {
            if(j - w[i] < 0) f[i][j] = f[i - 1][j];
            else{ f[i][j] = max(f[i - 1][j - w[i]] + v[i], f[i - 1][j]);
            //cout << f[i - 1][j - w[i]] + v[i]  << " ";
            }
        }
        //cout << "\n";
    }
    cout << f[n][k];
}


Measured memory_bytes: 79360