akhauriyash/Code-Regression huggingface dataset:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

INF = float("inf")

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

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

n,k = myinput()

ans = 1
for i in range(n):
    if i==0:
        ans *= k
    else:
        ans *= k-1
print(ans)

Measured memory_bytes: 38256
/*
 * Author : Andrew J
*/
#include <bits/stdc++.h>
using namespace std;
#define rall(x) x.rbegin() , x.rend()
#define all(x) x.begin() , x.end()
#define fi first
#define se second
#define pb push_back
using ll = long long;
using ii = pair <int , int>;
void in(int &x);
const int N = 1050;
#define singleCase
// #define multipleCase
int n,m,a,b;
string grid[N];

void work() {
   cin >> n >> m >> a >> b;
   string s = "";
   for (int i = 1 ; i <= a ; i++) {
      s += "1";
   }
   for (int i = 1 ; i <= m - a ; i++) {
      s += "0";
   }
   for (int i = 1 ; i <= b ; i++) {
      grid[i] = s;
   }
   for (int i = 0 ; i < m ; i++) {
      s[i] = s[i] == '0' ? '1' : '0';
   }
   for (int i = b + 1 ; i <= n ; i++) {
      grid[i] = s;
   }
   for (int i = 1 ; i <= n ; i++) {
      for (int j = 0 ; j < m ; j++) {
         printf("%c" , grid[i][j]);
      } puts("");
   }
   return;
}

int main() {
   #ifdef multipleCase
      int nQ; in(nQ);
      while (nQ--)
         work();
   #endif
   #ifdef singleCase
      work();
   #endif
   return 0;
}

void in(int &x) {
	bool neg = false;
	register int c;
	x = 0;
	c = getchar();
	if(c == '-') {
		neg = true;
		c = getchar();
	}
	for (; c > 47 && c < 58; c = getchar())
	  x = (x << 1) + (x << 3) + c - 48;
	if (neg) x *= -1;
}


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

#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/2;
const ll MOD = 1e9+7;
const double EPS=1e-12;

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N,K;cin>>N>>K;
  vll g[N];
  for(ll i=0;i<N-1;i++){
    ll a,b;cin>>a>>b;a--;b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  queue<tuple<ll,ll,ll,ll> > Q;
  Q.push(make_tuple(0,0,0,0));
  ll ans=1;
  while(!Q.empty()){
    ll v,p,d,a;tie(v,p,d,a)=Q.front();Q.pop();
    ll k=K;
    if(d>=2)k-=2;
    else k-=d;
    k-=a;
    ans = ans*k%MOD;
    int cnt=0;
    for(ll u:g[v])if(u!=p){
      Q.push(make_tuple(u,v,d+1,cnt++));
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

int main() {
    string s;
    int i;
    cin >> s;
    int leng = s.length(), small = (leng - 1)/2, big = (leng + 3)/2;
    for(i = 0; i < s.length()/2 - 1; i++){
        if(s.at(i) != s.at(leng-i-1)){
            cout << "No" << endl;
            return 0;
        }
    }
    for(i = 0; i < small/2 - 1; i++){
        if(s.at(i) != s.at(small-i-1)){
            cout << "No" << endl;
            return 0;
        }
    }
    for(i = 0; i < (leng-big+1)/2; i++){
        if(s.at(big+i-1) != s.at(leng-i-1)){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
static const ll INF = 9223372036854700;
static const ll MOD = 1000000007;

ll csum[200009];

int main(){
  int N;
  cin >> N;

  cin >> csum[0];
  for(int i=1;i<N;i++){
    int a;
    cin >> a;
    csum[i] = csum[i-1] + a;
  }

  ll ans=INF;
  for(int i=0;i<N-1;i++){
    ans = min( ans , abs(csum[N-1]-csum[i]*2) );
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>

void bubble_sort( int *a, int n ){
	int i, j, t;

	for( i=0; i<n-1; i++ ){
		for( j=n-1; j>i; j-- ){
			if(  a[j-1] < a[j] ){
				t=a[j]; a[j]=a[j-1]; a[j-1]=t;
			}
		}
	}
}

int main(){
	int a[5], i;

	for( i=0; i<5; i++ )
		scanf("%d", &a[i]);

	bubble_sort( a, 5 );

	for( i=0; i<5; i++ ){
		printf("%d", a[i]);
		if( i == 4 ) printf("\n");
		else         printf(" ");
	}

	return 0;
}

Measured memory_bytes: 600
use std::collections::HashMap;

fn main() {
    let n = read::<usize>();
    let v = read_vec::<usize>();
    let mut map = HashMap::new();
    for a in v.iter() {
        let entry = map.entry(*a).or_insert(0);
        *entry += 1;
    }
    let mut sum = 0;
    for (_, value) in map.iter() {
        sum += comb2(*value);
    }

    for i in 0..n {
        let a = v[i];
        let value = map.get(&a).unwrap();
        let ret = sum - (comb2(*value) - comb2(*value - 1));
        println!("{}", ret);
    }
}

fn comb2(a: usize) -> usize {
    if a == 0 || a == 1 { return 0 }

    let b = 2;
    a * (a - 1) / b
}

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

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()
}


Measured memory_bytes: 12300
#include <iostream>
#include <algorithm>
#define INF 1000000000000000000
typedef long long LL;
using namespace std;
LL N,M,K;
LL ary[20010],dp[20010];
int main(){
	cin>>N>>M>>K;
	for(int i=1;i<=N;i++){
		cin>>ary[i];
	}
	fill(dp,dp+N+1,INF);
	LL a,b;
	dp[0]=0;
	for(int i=0;i<N;i++){
		a=b=ary[i+1];
		for(int j=1;j<=M&&(i+j)<=N;j++){
			a=max(a,ary[i+j]);
			b=min(b,ary[i+j]);
			dp[i+j]=min(dp[i+j],dp[i]+K+j*(a-b));
		}
	}
	cout<<dp[N]<<endl;
	return 0;
}

Measured memory_bytes: 1468
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INTF = 1e9 + 7;

int main() {  
  int n;
  cin >> n;

  vector<vector<ll>> v(n, vector<ll>(n));
  for(int i=0; i<n; i++)
    for(int j=0; j<n; j++)
      cin >> v[i][j];

  vector<ll> dp(1<<n), d(1<<n);

  for(int mask=0; mask < (1<<n); mask++)
  {
    ll ans =0;
    for(int i=0; i<n; i++)
    {
      if(mask & (1<<i))
      {
        for(int j=0 ;j<i;j++)
        {
          if(mask & (1<<j))
          {
            ans += v[i][j];
          }
        }
      }
    }
    dp[mask] = ans;
  }


  for (int i=1;i<(1<<n);i++){
    d[i] = -1e18;
    for (int j=i;j;j=(j-1)&i){
      if (d[i] < d[i-j] + dp[j])
        d[i] = d[i-j] + dp[j];
    }
  }
  
  cout<<d[(1<<n) - 1];
  return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define int long long

using namespace std;

string s; 
int ans = 0 ;

int32_t main(){
	
     ios_base::sync_with_stdio(0); cin.tie(0);
     
     cin >> s ;
     int i = 0 , j = (int)s.size() - 1 ;
     while( i <= j ){
         if(s[i]!=s[j])ans++;
         i++;
         j--;
     }
     cout << ans << endl;
     return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <string>
#include <map>

using namespace std;
int main(int argc, const char * argv[]) {
    
    int n;
    cin >> n;

    map<string, bool> m;

    string p, c;
    cin >> p;
    bool b=true;
    for (int i = 1; i < n; i++)
    {
        cin >> c;
        if ( c[0] != p[p.size()-1] || m[c] ) {
            b=false;
            break;
        }
        m[p] = true;
        p = c;
    }
    
    cout << ( b ? "Yes" : "No" ) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>

template <class T>
inline void read(T &x) {
    x = 0;
    int f = 0;
    char ch = getchar();
    while (!isdigit(ch))    { f |= ch == '-'; ch = getchar(); }
    while (isdigit(ch))     { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); }
    x = f ? -x : x;
    return;
}

int a[110];
int n, m, sum, s;

int main() {
    read(n), read(m);
    for (int i = 1; i <= n; ++i)    read(a[i]), sum += a[i];
    sum = (sum - 1) / (4 * m) + 1;
    std::sort(a + 1, a + n + 1);
    for (int i = n; i >= 1; --i) {
        if (a[i] >= sum)    ++s;
        else    break;
    }
    puts(s >= m ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a,b,c;
  cin>>a;
  cin>>b;
  cin>>c;
  if(a[a.size()-1]==b[0]&&b[b.size()-1]==c[0]) cout<<"YES";
  else cout<<"NO";
  cout<<"\n";
}


Measured memory_bytes: 256
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
// constexpr ll MOD = 998244353;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<ll> par;
//     vector<ll> siz;
    
//     UnionFind(ll N): par(N), siz(N,1) {
//         for (ll i=0;i<N;i++) par[i] = i;
//     }

//     ll root(ll x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(ll x, ll y) {
//         ll rx = root(x);
//         ll ry = root(y);
//         if (rx == ry) return;
//         // if (siz[rx] < siz[ry]) swap(rx,ry);
//         par[rx] = ry;
//         siz[ry] += siz[rx];
//     }

//     bool same(ll x, ll y) {
//         ll rx = root(x);
//         ll ry = root(y);
//         return rx == ry;
//     }

//     ll size(ll x) {
//         return siz[root(x)];
//     }
// };

//     vector<ll> par;
//     vector<ll> siz;
    
//     UnionFind(ll N): par(N), siz(N,1LL) {
//         for (ll i=0;i<N;i++) par[i] = i;
//     }

//     ll root(ll x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(ll x, ll y) {
//         ll rx = root(x);
//         ll ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//         siz[ry] += siz[rx];
//     }

//     bool same(ll x, ll y) {
//         ll rx = root(x);
//         ll ry = root(y);
//         return rx == ry;
//     }

//     ll size(ll x) {
//         return siz[root(x)];
//     }
// };

int main(void) {
    int N, M, Q;
    cin >> N >> M >> Q;
    int a[60], b[60], c[60], d[60];
    for (int k=0;k<Q;k++) cin >> a[k] >> b[k] >> c[k] >> d[k];

    set<vector<int>> S[N+1];
    for (int j=1;j<=M;j++) S[1].insert(vector<int>(1,j));
    for (int i=2;i<=N;i++) {
        for (auto itr: S[i-1]) {
            itr.push_back(0);
            int k = itr.size();
            for (int j=itr[k-2];j<=M;j++) {
                itr[k-1] = j;
                S[i].insert(itr);
            }
        }
    }
    // for (auto itr: S[N]){
    //     for (auto k: itr) cout << k << ", ";
    //     cout << endl;
    // }
    set<int,greater<int>> R;
    for (auto itr: S[N]) {
        int score = 0;
        for (int k=0;k<Q;k++) {
            if (itr[b[k]-1] - itr[a[k]-1] == c[k]) score += d[k];
        }
        R.insert(score);
    }
    // for (auto itr: R) {
    //     cout << itr << endl;
    // }
    cout << *(R.begin()) << endl;

    return 0;
}


Measured memory_bytes: 23620
#include <algorithm>
#include <iostream> 
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
	int n,m,h,w;
	scanf("%d%d%d%d",&n,&m,&h,&w);
	printf("%d",n*m-h*m-w*n+h*w);
	return 0;
}

Measured memory_bytes: 256
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
signed main(){
  init_io();
  ll a,tb;
  string b;
  cin >> a >> b;
  tb = (b[0]-'0')*100 + (b[2]-'0')*10 + (b[3]-'0');
  ll ans = a*tb;
  cout << ans / 100 << endl;

}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define exists(s,x) (s).find(x)!=(s).end()
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)
#define fi first
#define se second
typedef long long ll;
const double INF = 1e15;
const ll MOD = 1000000007;

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

void dijkstra(int s,vector<double> &d, const vector<vector<edge> > &G){
    priority_queue<P,vector<P>,greater<P>> que;
    fill(d.begin(),d.end(),INF);
    d[s]=0;
    que.push(P(0,s));
    while(!que.empty()){
        P p=que.top();que.pop();
        int v=p.second;
        if(d[v]<p.first)continue;
        for(int i=0;i<G[v].size();i++){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}

int main(){
    vector<pair<pair<double,double>,double>> v;
    double xs, ys, xt, yt; cin >> xs >> ys >> xt >> yt;
    v.push_back(make_pair(make_pair(xs,ys),0.0));
    v.push_back(make_pair(make_pair(xt,yt),0.0));
    int N; cin >> N;
    REP(i,N) {
        double x, y;
        double r;
        cin >> x >> y >> r;
        v.push_back(make_pair(make_pair(x,y),r));
    }
    int V = N + 2; // 頂点数
    vector<vector<edge>> G(V);
    vector<double> d(V);
    REP(i,V) REP(j,V) {
        if(i==j) continue;
        double x = v[i].fi.fi;
        double y = v[i].fi.se;
        double z = v[j].fi.fi;
        double w = v[j].fi.se;
        double kyori = sqrt((x-z)*(x-z)+(w-y)*(w-y));
        double r1 = v[i].se;
        double r2 = v[j].se;
        G[i].push_back((edge){j,max(0.0,kyori-r1-r2)});
    }
    dijkstra(0,d,G);
    cout << fixed << setprecision(10);
    cout << d[1] << endl;
    return 0;
}

Measured memory_bytes: 22640
using System.Collections.Generic;
using System;

public class hello
{
    public static void Main()
    {
        var lst = new HashSet<string>();
        var n = int.Parse(Console.ReadLine().Trim());
        for (int i = 0; i < n; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            if (line[0] == "insert") lst.Add(line[1]);
            else
            {
                if (lst.Contains(line[1])) Console.WriteLine("yes");
                else Console.WriteLine("no");
            }
        }
    }
}


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

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int M = stdIn.nextInt();
		int L[] = new int[M];
		int R[] = new int[M];
		
		for(int i = 0; i < M; i++) {
			L[i] = stdIn.nextInt();
			R[i] = stdIn.nextInt();
		}
		int maxL = L[0];
		int minR = R[0];
		
		for(int i = 1; i < M; i++) {
			if(maxL < L[i]) {
				maxL = L[i];
			}
			if(minR > R[i]) {
				minR = R[i];
			}
		}
		
		if((minR - maxL) >= 0) {
			System.out.println(minR - maxL + 1);
		}
		else {
			System.out.println(0);
		}

	}

}

Measured memory_bytes: 82496
n = gets.to_i
s = []
max = 0
ans = []
n.times do
  s.push(gets)
end
s.group_by{|e| e}.each do |k, v|
  max = v.length if max < v.length
end
s.group_by{|e| e}.each do |k, v|
  ans.push(k) if max == v.length
end
ans.sort.each do |v|
  puts v
end

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

int main()
{
    std::string in;
    std::cin >> in;

    std::string ret;
    if(in == "A")
    {
        ret = "T";
    }
    else if(in == "T")
    {
        ret = "A";
    }
    else if(in == "G")
    {
        ret = "C";
    }
    else if(in == "C")
    {
        ret = "G";
    }

    std::cout << ret << std::endl;
    
    return 0;
}

Measured memory_bytes: 256
/* 2018-01-07-17.30.16 */

#include<bits/stdc++.h>
#define ll long long int
#define N 1000010
using namespace std;
struct type {ll n, t;};
bool compare(type a,type b) {return a.n>b.n;}
int main()
{
    ll n,h,i;
    cin >> n >> h;
    type a[N];
    for(i=0;i<n;i++)
    {
        ll x,y;
        cin >> x >> y;
        a[2*i].n=x,a[2*i].t=1;
        a[2*i+1].n=y,a[2*i+1].t=2;
    }
    sort(a,a+2*n,compare);
    ll cnt=0;
    for(i=0;i<2*n;i++)
    {
        if(a[i].t==1)
        {
            if(h%a[i].n==0) cnt+=h/a[i].n;
            else cnt+=(h/a[i].n+1);
            break;
        }
        h-=a[i].n;
        cnt++;
        if(h<=0) break;
    }
    cout << cnt << endl;
    return 0;
}


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

int main()
{
    int n;
    int m;
    cin >> n >> m;
    if(n==m){
        cout <<"Yes"<<endl;
    }else{
        cout <<"No"<<endl;
    }

    return 0;
}

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

int main(){
    int x,h;
    while(cin >> x >>h, x+h){
        double ss = sqrt(.25*x*x+h*h)*x/2;
        double s = 4*ss+x*x;
        printf("%.10f\n",s);
    }
    return 0;
}

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

#define pb push_back
#define ll long long
using namespace std;

const int mod = 1e9 + 7;

int pow(int n, int x) {
    ll res = 1;
    while (n) {
        if (n & 1) res = (res * x) % mod;
        x = ((ll)x * x) % mod;
        n >>= 1;
    }
    return res;
}

int inv(int x) { return pow(mod - 2, x); }

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    //cin >> t;
    for (int T = 0; T < t; T++) {
        ll n;
        cin >> n;
        ll a[n], sum = 0, sqsum = 0;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
            sum += a[i];
            sqsum += ((a[i] * a[i]) % mod);
            sum %= mod;
            sqsum %= mod;
        }
        ll ans = (((sum * sum) % mod - sqsum % mod + mod)) % mod;
        cout << ans * (ll)inv(2) % mod << endl;
    }
    return 0;
}


Measured memory_bytes: 5100
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main(){
    int x,y,z;
    string s1, s2;
    char s;

    cin >> s1;

    std::vector<string> day{"","SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"};

    for (int i = 0; i < day.size();i++){
        if (day[i] == s1){
            cout << i << endl;
        }
    }
    

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>

using namespace std;


int main() {
	map<int, int> mp;
	long long int n, m=0,tmp=0,ax=0,k=0,t[5000],p[5000],x,y,res[5000],a,b,c;
	string str, str2[5000];
	cin >>a>>b>>c>>x>>y;
	if (a+b<= 2*c) {
		cout << x * a + y * b;
	}
	else if (a + b > 2*c) {
		k += min(x, y)*2*c;
		if (x > y&&a > 2 * c) { k = x * 2 * c; }
		else if (y > x&&b > 2 * c) {
			k = y * 2 * c;
		}
		else if (x > y&&a <= 2 * c) {
			k += (x - y)*a;
		}
		else if (y > x&&a <= 2 * c) {
			k += (y - x)*b;
		}
		cout << k;
	}
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long ;
int main(){
    ll n,d;
    ll ans=0;
    cin >> n >> d;
    d = d*d;
    vector<ll> x(n);
    vector<ll> y(n);
    rep(i,n){
        cin >> x[i];
        cin >> y[i];
    }
    rep(i,n){
        ll a,b;
        a = x[i];
        b = y[i];
        if((a*a+b*b)<= d) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6420
while True:
  a, op, b = map(str, raw_input().split())
  a = int(a)
  b = int(b)
  
  if op == "+":
    print a+b
  elif op == "?":
    break
  elif op == "-":
    print a-b
  elif op == "/":
    print a/b
  elif op == "*":
    print a*b
  

Measured memory_bytes: 6364
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repR(i, n) for(int i = (n) - 1; i > -1; i--)
#define rep1(i, n) for(int i = 1; i < (int)(n + 1); i++)
#define rep1R(i, n) for(int i = (n); i > 0; i--)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main() {
  int N; cin >> N;
  vector<int> a(N);
  rep(i, N) cin >> a[i];
  int sum = 0;
  rep(i, N) sum += a[i];
  int ave = sum / N;
  int diff = 1000000;
  int ans;
  rep(i, N) {
    if (diff > abs(sum - N * a[i])) {
      diff = abs(sum - N * a[i]);
      ans = i;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI=acos(-1.0);
#define t1(x)             cerr<<#x<<"="<<x<<endl
#define t2(x, y)          cerr<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define t3(x, y, z)       cerr<<#x<<"=" <<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
#define t4(a,b,c,d)       cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<endl
#define t5(a,b,c,d,e)     cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<" "<<#e<<"="<<e<<endl
#define t6(a,b,c,d,e,f)   cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<" "<<#e<<"="<<e<<" "<<#f<<"="<<f<<endl
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define t(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fastio() ios::sync_with_stdio(0);cin.tie(0)
#define MEMS(x,t) memset(x,t,sizeof(x));
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
/*-------------------------------------------------------------------------------------------------------------------------------------*/
#define MOD 1000000007
#define endl "\n" 
#define int long long
#define inf 1e18
#define ld long double
/*-------------------------------------------------------------------------------------------------------------------------------------*/
int n,m;
const int N=105;
int ar[N][N];
int dp[N][N][2];

int rec(int i,int j,int prev)
{
	if(i>n || j>m)
	{
		return 1e9;
	}
	if(i==n && j==m)
	{
		return (ar[i][j]!=prev);
	}
	int &ans=dp[i][j][prev];
	if(ans>=0)return ans;
	ans=(ar[i][j]!=prev)+min(rec(i+1,j,ar[i][j]),rec(i,j+1,ar[i][j]));
	return ans;
}
int32_t main()
{
	fastio();
	cin>>n>>m;
	memset(dp,-1,sizeof(dp));
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			char x;
			cin>>x;
			ar[i][j]=((x=='.')?0:1);
		}
	}
	cout<<(rec(1,1,0)+1)/2<<endl;
}


Measured memory_bytes: 1148
#include <bits/stdc++.h>
using namespace std;
struct BiIndTree{
	long long val[200005];
	inline void init(){
		memset(val,0,sizeof(val));
	}
	inline void add(int x,long long v){
		x++;
		while(x<200005){
			val[x]+=v;
			x+=x&-x;
		} 
	}
	inline long long query(int x){
		x++;
		long long res=0;
		while(x>0){
			res+=val[x];
			x-=x&-x;
		}
		return res;
	}
}bit; 
int n;
long long k;
long long sum[200005];
long long ans;
vector<long long> s;
int main(){
	cin>>n>>k;
	int sz=0;
	sum[sz++]=0;
	for(int i=0;i<n;++i){
		cin>>sum[sz];
		sum[sz]-=k;
		sum[sz]+=sum[sz-1];
		sz++;
	}
	for(int i=0;i<sz;++i){
		s.push_back(sum[i]);
	}
	sort(s.begin(),s.end());
	s.erase(unique(s.begin(),s.end()),s.end());
	bit.init();
	for(int i=0;i<sz;++i){
		int pos=lower_bound(s.begin(),s.end(),sum[i])-s.begin();
		ans+=bit.query(pos);
		bit.add(pos,1);
	} 
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 5104
#ifdef Prateek
  #include "Prateek.h"
#else
  #include <bits/stdc++.h>
  using namespace std;
  #define debug(...) 42
#endif
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   string s;
   cin >> s;
   int sm = 0;
   for(char c : s) sm += c-'0';
   cout << ((sm%9)?"No":"Yes");
   return 0;
} 

Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
const int maxn=2e5+1;
const int MOD=1e9+7;
typedef long long ll;
int parent[maxn];
int rnk[maxn];
int w[maxn];
int c[maxn];
int used[maxn];
ll fact[maxn];
ll ost[maxn];
ll inv[maxn];
vector<int> fin[maxn];
vector<int> cmps[maxn];
int _find(int v){
    if (v==parent[v])
        return v;
    return parent[v]=_find(parent[v]);
}
void unit(int a,int b){
    a=_find(a);
    b=_find(b);
    if (a!=b){
        if (rnk[a]<rnk[b])
            swap(a,b);
        else if (rnk[a]==rnk[b])
            ++rnk[a];
        parent[b]=a;
    }
}
int col[maxn];
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,x,y;
    cin>>n>>x>>y;
    fact[0]=1;
    fact[1]=1;
    inv[1]=1;
    ost[1]=1;
    for(int i=2; i<=n; ++i){
        fact[i]=(fact[i-1]*i)%MOD;
        ost[i]=(ost[MOD%i]*(MOD-MOD/i))%MOD;
        inv[i]=(inv[i-1]*ost[i])%MOD;
    }
    int ind1=-1;
    for(int i=1; i<=n; ++i){
        parent[i]=i;
        cin>>c[i]>>w[i];
        if (ind1==-1 || w[ind1]>w[i])
            ind1=i;
        cmps[c[i]].push_back(i);
    }
    int ind2=-1;
    for(int i=1; i<=n; ++i){
        if (c[i]!=c[ind1]){
            if (ind2==-1 || w[ind2]>w[i])
                ind2=i;
        }
    }
    for(int i=1; i<=n; ++i){
        int indi=-1;
        for(int j=0; j<cmps[i].size(); ++j)
            if (indi==-1 || w[indi]>w[cmps[i][j]])
                indi=cmps[i][j];
        for(int j=0; j<cmps[i].size(); ++j)
            if (w[indi]+w[cmps[i][j]]<=x)
                unit(indi,cmps[i][j]);
    }
    for(int i=1; i<=n; ++i){
        if (c[i]!=c[ind1]){
            if (w[ind1]+w[i]<=y)
                unit(ind1,i);
        }
    }
    for(int i=1; i<=n; ++i)
        if (ind2!=-1){
            if (c[i]!=c[ind2]){
                if (w[i]+w[ind2]<=y)
                    unit(i,ind2);
            }
        }
    ll ans=1;
    for(int i=1; i<=n; ++i)
        fin[_find(i)].push_back(i);
    for(int i=1; i<=n; ++i){
        if (fin[i].empty())
            continue;
        map<int,int> cl;
        for(int j=0; j<fin[i].size(); ++j){
            cl[c[fin[i][j]]]++;
        }
        ans=(ans*fact[fin[i].size()])%MOD;
        for(auto it=cl.begin(); it!=cl.end(); ++it)
            ans=(ans*inv[it->second])%MOD;
    }
    cout<<ans;
}


Measured memory_bytes: 30068
s = input()

n = len(s)
ss1 = s[:int((n-1)/2)]
ss = s[int((n+3)/2)-1:]

if s != s[::-1]:
    print('No')
    exit()
if s[:int((n-1)/2)] != ss1[::-1]:
    print('No')
    exit()
if s[int((n+3)/2)-1:] != ss[::-1]:
    print('No')
    exit()

print('Yes')


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

int main() {
  int N;
  cin >> N;
  int sum = 0;
  
  rep(i, N){
    int s,e;
    cin >> s >> e;
    sum = sum + e - s + 1;
    
    
  }
  cout << sum << endl;
}

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

using namespace std;

const int MAX=21;

int n,q,a[50],m;

//??????a?????????i?????????????´?????????§m?????????????????????????????¢??°???
int judge(int i,int m){
  if(m==0) return 1;
  if(i>=n) return 0;
  int temp=judge(i+1,m) || judge(i+1,m-a[i]); //i????????????????????????????????????
  return temp;
}



int main(){
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  cin >> q;
  for(int j=0;j<q;j++){
    cin >> m;
    if(judge(0,m)) cout << "yes" << endl;
    else cout << "no" << endl;
  }
  return 0;
}

Measured memory_bytes: 1152
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        
        if(M==N){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
            
        }
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#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 ll MOD = 1e9+7;

int main(){
    ll N;
    cin >> N;

    
    ll ans = 0;
    ll n = N-1;

    ans += n*(n+1)/2;

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


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var h int

func main() {
	fmt.Scan(&h)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	a := make([]int, h+1)
	for i := 1; i < h+1; i++ {
		sc.Scan()
		a[i], _ = strconv.Atoi(sc.Text())
	}

	for i := h / 2; i >= 1; i-- {
		maxHeapify(a, i)
	}

	wr := bufio.NewWriter(os.Stdout)
	for i := 1; i < h+1; i++ {
		wr.Write([]byte(fmt.Sprintf(" %d", a[i])))
	}
	wr.Write([]byte("\n"))
	wr.Flush()
}

func maxHeapify(a []int, i int) {
	var l, r, largest int
	l = 2 * i
	r = 2*i + 1

	//左の子、自分、右の子で値が最大のノードを選ぶ
	if l <= h && a[l] > a[i] {
		largest = l
	} else {
		largest = i
	}
	if r <= h && a[r] > a[largest] {
		largest = r
	}

	if largest != i {
		tmp := a[largest]
		a[largest] = a[i]
		a[i] = tmp

		maxHeapify(a, largest)
	}
}



Measured memory_bytes: 10216
#include<stdio.h>
int f_max(int a, int b)
{
	if (a > b)return a;
	else return b;
}
int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	char s[100005];
	scanf("%s", s);
	int c = 0;
	int i;
	for (i = 0; i < n; i++)
	{
		if (s[i] == '0')
			c = 0;
		else
			c++;
		if (c >= m)
		{
			printf("-1\n");
			return 0;
		}
	}
	int v[100005];
	v[0] = 0;
	for (i = 0; i <= n; i++)
	{
		if (s[i] == '0')
			v[i + 1] = v[i] + 1;
		else
			v[i + 1] = v[i];
	}
	int min, mid, max;
	int ans[100005], p = 0;
	i = n;
	while (i > 0)
	{
		if (s[f_max(0, i - m)] == '0')
		{
			ans[p] = i - f_max(0, i - m);
			i = f_max(0, i - m);
			p++;
		}
		else
		{
			min = f_max(0, i - m + 1);
			max = i;
			while (max - min > 1)
			{
				mid = (max + min) / 2;
				if (v[mid] == v[min])
					min = mid;
				else
					max = mid;
			}
			ans[p] = i - min;
			i = min;
			p++;
		}
	}
	for (i = p - 1; i > 0; i--)
		printf("%d ", ans[i]);
	printf("%d\n", ans[0]);
	return 0;
}

Measured memory_bytes: 1280
# -*- coding: utf-8 -*-

c11, c12, c13 = map(int, input().split())
c21, c22, c23 = map(int, input().split())
c31, c32, c33 = map(int, input().split())

# c = [c1, c2, c3]

if(c21 - c11 == c22 - c12 == c23 - c13 and c31 - c11 == c32 - c12 == c33 - c13 and c12 - c11 == c22 - c21 == c32 - c31 and c13 - c11 == c23 - c21 == c33 - c31 ):
    if(isinstance(c21 - c11, int) and isinstance(c31-c11, int) and isinstance(c22-c12, int) and isinstance(c32-c12, int) and isinstance(c23-c13, int) and isinstance(c33-c13, int) and isinstance(c12-c11, int) and isinstance(c13-c11, int) and isinstance(c22-c21, int) and isinstance(c23-c21, int) and isinstance(c32-c31, int) and isinstance(c33-c31, int) ):
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 3064
import java.util.Scanner;

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

       for (int i = 0; i < 4; i++) {
           String str = S.substring(i,i+1);
           //System.out.println(str);
           if (str.equals("+")) {
        	   x = x + 1;
           } else if (str.equals("-")) {
        	   x = x - 1;
           }
           //System.out.println(x);
       }

       System.out.println(x);
   }
}

Measured memory_bytes: 22100
object Main extends App {
	val n = scala.io.StdIn.readInt
	val a = scala.io.StdIn.readLine.split(" ").map(_.toLong)

	var ans = 0

	for(x <- a){
		var tp = x

		while(tp%2 == 0){
			ans += 1
			tp = tp/2
		}
	}

	println(ans)
}

Measured memory_bytes: 29420
# 各金額を取得
X = int(input())
A = int(input())
B = int(input())

# 残金を計算
# 1.ケーキ1つの購入
Balance = X - A
# 2.残金で購入可能な最大個数のドーナツを購入
Balance = Balance - (Balance // B) * B

# 残金の出力
print(Balance)

Measured memory_bytes: 9036
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int n,k,a[101],dp[100001];
int cal(int i)
{
	int ans=-1;
	for(int j=0;j<n;j++)
	{
		if(i>a[j])
		{
			ans=max(ans,-dp[i-a[j]]);
		}
	}
	return ans;
}
main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		dp[a[i]]=1;
	}
	for(int i=1;i<a[0];i++)
		dp[i]=-1;
	for(int i=a[0];i<=k;i++)
	{
		if(dp[i]==0)
		{
			dp[i]=cal(i);
		}
	}
	
	if(dp[k]==1)
		cout<<"First";
	else
		cout<<"Second";
	
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define maxn 505
using namespace std;
int n,x[maxn],a[maxn*maxn],c[maxn];
bool solve(){
	for(int i=1;i<=n*n;i++){
		for(int j=1;j<=n;j++) if(x[j]==i){
			if(++c[j]<j) return 0;
			a[i]=j; break;
		}
		if(a[i]) continue;
		int k=0;
		for(int j=1;j<=n;j++) if(x[j]>i&&c[j]<j-1&&x[j]<x[k]) k=j;
		if(k) {c[a[i]=k]++;continue;}
		for(int j=1;j<=n;j++) if(x[j]<i&&c[j]<n) {k=j;break;}
		if(k) c[a[i]=k]++;
		else return 0;
	}
	return 1;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&x[i]); x[0]=n*n+1;
	if(!solve()) return puts("No"),0;
	puts("Yes");
	for(int i=1;i<=n*n;i++) printf("%d%c",a[i],i==n*n?10:32);
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+1;
int a[101];
bool dp[N];
main()
{
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=k;i++){
        for(int x=1;x<=n;x++){
            if(i>=a[x]&&dp[i-a[x]]==0)dp[i]=1;
        }
    }
    if(dp[k]) cout<<"First";
    else cout<<"Second";
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

struct union_find {
    vector<int> parent; //親の番号を格納する。親だった場合は-(その集合のサイズ)
    union_find(int N) {
        parent = vector<int>(N, -1); //parentの値を-1にする(すべてバラバラ)
     }
    int root(int A) { //Aがどのグループに属しているか調べる
        if (parent[A] < 0) return A;
        return parent[A] = root(parent[A]);
    }
    int size(int A) { //自分のいるグループの頂点数を調べる
        return -parent[root(A)];//親をとってきたい
    }
    bool connect(int A, int B) { //AとBをくっ付ける．すでにつながっていた場合false
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) return false; //すでにくっついてるからくっ付けない
        if (size(A) < size(B)) swap(A, B); //大小が逆だったらひっくり返しちゃう。
        parent[A] += parent[B]; //Aのサイズを更新する
        parent[B] = A; //Bの親をAに変更する
        return true;
    }
};

int main(void)
{
    int N,M,K;
    cin >> N >> M >> K;
    vector<vector<int>> AB(N);
    vector<vector<int>> CD(N);
    union_find uf(N);
    REP(i, M){
        int a,b;
        cin >> a >> b;
        a--;b--;
        AB[a].pb(b);
        AB[b].pb(a);
        uf.connect(a, b);
    }
    REP(i, K){
        int a,b;
        cin >> a >> b;
        a--;b--;
        CD[a].pb(b);
        CD[b].pb(a);
    }

    REP(i, N){
        int n = uf.size(i)-1-AB[i].size();
        int CD_n = CD[i].size();
        REP(j, CD_n){
            if(uf.root(i) == uf.root(CD[i][j])) n--;
        }
        cout << n << " ";
    }
    cout << endl;
}

Measured memory_bytes: 12152
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int[] line = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int a = line[0];
            int b = line[1];
            Console.WriteLine(a <= b ? a : a - 1);
        }
    }
}

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

int main(){
    vector<int> a(100000);
    for(int i = 0;i<100000;i++){
        a[i] = 0;
    }
    int N, in, in_max = 0;
    cin >> N;
    for(int i = 0;i<N;i++){
        cin >> in;
        if(in > in_max) in_max = in;
        if(in>0) a[in-1]++;
        a[in]++;
        a[in+1]++;
    }
    // cout << endl;
    int max = 0;
    for(int i = 0;i<=in_max;i++){
        // cout << i << ":" << a[i] << endl;
        if(max < a[i]) max = a[i];
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 640
//xtwakioi! xtwddYnoi(双重含义)!
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=20010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
signed main()
{
    int a,b,c;
    a=read(), b=read(), c=read();
    for(ri int i=1;i<=b;i++)
    {
        if(i*a%b==c) { puts("YES"); return 0; }
    }
    puts("NO");
    return 0;
}

Measured memory_bytes: 3524
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

vector<int> V[3];
int n,r;

void pop(int i, int m){
  int end = min((int)V[i].size(),m);
  for(int j = 0; j < end; j++){
    V[2].push_back(V[i][0]);
    V[i].erase(V[i].begin());
  } 
}

void shuffle(int m){
  while(V[0].size() || V[1].size()){
    pop(0,m);
    pop(1,m);
  }
  for(int i = 0; i < V[2].size(); i++)
    V[0].push_back(V[2][i]);
  V[2].clear();
}

void init(){
  for(int i = 0; i < 3; i++)
    V[i].clear();
  for(int i = 0; i < n; i++)
    V[0].push_back(i);
}

void half(){
  for(int i = 0; i < n/2; i++){
    V[1].push_back(V[0][0]);
    V[0].erase(V[0].begin());
  }
}
int main(){
  while(cin >> n >> r){
    init();
    for(int i = 0; i < r; i++){
      int num;
      cin >> num;
      half();
      shuffle(num);
    }
    cout << V[0].back() << endl;
  }
  return 0;
}

Measured memory_bytes: 0
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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;}

const int MAXV = 1e5;
const int INF = 1e9;
struct edge{ int to, cap, rev; };
vector<edge> G[MAXV];
bool used[MAXV];

// from -> to へ向かう容量capの辺をグラフに追加
void add_edge(int from, int to, int cap){
  G[from].push_back((edge){to, cap, G[to].size()});
  G[to].push_back((edge){from, 0, G[from].size()-1});
}

int dfs(int v, int t, int f){
  if(v == t) return f;
  used[v] = true;
  REP(i, G[v].size()){
    edge &e = G[v][i];
    if(!used[e.to] && e.cap>0){
      int d = dfs(e.to, t, min(f, e.cap));
      if(d > 0){
	e.cap -= d;
	G[e.to][e.rev].cap += d;
	return d;
      }
    }
  }
  return 0;
}

int max_flow(int s, int t){
  int flow = 0;
  while(true){
    memset(used, 0, sizeof(used));
    int f = dfs(s, t, INF);
    if(f==0) return flow;
    flow += f;
  }
}

int a[575], b[575], c[575], d[575];

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

  int n;
  cin >> n;
  REP(i, n) cin >> a[i] >> b[i];
  REP(i, n) cin >> c[i] >> d[i];

  int s, t;
  s = n*2, t = s+1;
  REP(i, n) add_edge(s, i, 1);
  REP(i, n) add_edge(n+i, t, 1);
  
  REP(i, n){
    REP(j, n){
      if(a[i] < c[j] && b[i] < d[j]) {
	add_edge(i, n+j, 1);	
      }
    }
  }

  cout << max_flow(s, t) << endl;
  
  return 0;
}


Measured memory_bytes: 2816
/*
THE BEST IS YET TO COME
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define r(i, s, l) for (int i = s; i < l; i++)
#define mod 1000000007
#define INT_BITS 32
#define ld long double
#define pp pair<int,int>
#define ss second
#define ff first
#define INF 1e18
#define N 2000005
#define all(a) a.begin(), a.end()
#define pb push_back
using namespace std;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

signed main() {

    fast();
    string s,t;
    cin>>s>>t;
    int flag =0;
    r(i,0,s.length())
    {
      if(s[i]!=t[i])
         {
           flag =1;
           break;
         }
    }
    if(flag)
    cout<<"No";
    else
    cout<<"Yes";


	return 0;
}


Measured memory_bytes: 3652
def main():
    with open(0) as f:
        N, H = map(int, f.readline().split())
        ab = list(map(int, f.read().split()))
    max_slash = max(ab[0::2])
    throw = sorted([x for x in ab[1::2] if x > max_slash], reverse=True)
    cnt = 0
    for t in throw:
        if H <= 0:
            break
        H += -t
        cnt += 1
    if H > 0:
        cnt += (H+max_slash-1)//max_slash
    print(cnt)

main()

    

Measured memory_bytes: 32336
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <iomanip>


using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

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

#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
//             0123456789 - digits. check the limits, int vs long
const int MX = 100001;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(6);
    cout << std::fixed;
    // freopen("ex.in","r",stdin);
    // freopen("ex.out","w",stdout);
    int n;
    cin >> n;
    if (n&1)
        cout << (double) (n + 1) / (2 * n) << endl;
    else 
        cout << "0.5000000000" << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	H, W := scanInt(), scanInt()
	Map := make([][]int, H)
	for i := 0; i < H; i++ {
		Map[i] = make([]int, W)
		for j := 0; j < W; j++ {
			Map[i][j] = scanInt()
		}
	}

	N := 0
	ans := make([][4]int, 0)
	for i := 0; i < H; i++ {
		for j := 0; j < W-1; j++ {
			if Map[i][j]%2 == 1 {
				N++
				Map[i][j]--
				Map[i][j+1]++
				ans = append(ans, [4]int{i + 1, j + 1, i + 1, j + 2})
			}
		}
	}
	for i := 0; i < H-1; i++ {
		if Map[i][W-1]%2 == 1 {
			N++
			Map[i][W-1]--
			Map[i+1][W-1]++
			ans = append(ans, [4]int{i + 1, W, i + 2, W})
		}
	}

	fmt.Println(N)
	for i := 0; i < N; i++ {
		fmt.Printf("%d %d %d %d\n", ans[i][0], ans[i][1], ans[i][2], ans[i][3])
	}
}


Measured memory_bytes: 21276
#include <iostream>
#include <string>
#include <vector>
using namespace std;

typedef long long int ll;

const ll MAXN = 8020;

int main()
{
  string s;
  cin >> s;
  int x,y;
  cin >> x >> y;

  vector<int> t;
  int cnt = 0;
//文字列を変形する
  for(int i = 0; i < s.size(); i++){
    if(s[i] == 'T'){
      if(cnt != 0) t.push_back(cnt);
      t.push_back(0);
      cnt = 0;
    }else{
      cnt++;
      if(i == s.size()-1) t.push_back(cnt);
    }
  }

  bool dp_x[MAXN][MAXN*2] = {false}, dp_y[MAXN][MAXN*2] = {false};
  dp_x[0][8000] = true;
  dp_y[0][8000] = true;

  bool flag = false;
  bool xy = true; // trueならx軸について見ている
  int cnt_x = 0,cnt_y = 0;

  for(int i = 0; i < t.size(); i++){
    if(t[i] == 0){
      xy  = !xy;
    }else if(xy){
      cnt_x++;
      for(int j = 0; j < MAXN*2; j++){
        if(dp_x[cnt_x-1][j]){
          if(j+t[i] < MAXN*2) dp_x[cnt_x][j+t[i]] = true;
          if(j-t[i] >= 0 && flag) dp_x[cnt_x][j-t[i]] = true;
        }
      }
    }else if(!xy){
      cnt_y++;
      for(int j = 0; j < MAXN*2; j++){
        if(dp_y[cnt_y-1][j]){
          if(j+t[i] < MAXN*2) dp_y[cnt_y][j+t[i]] = true;
          if(j-t[i] >= 0) dp_y[cnt_y][j-t[i]] = true;
        }
      }
    }

    if(!flag) flag = true;
  }

  cout << ((dp_x[cnt_x][x+8000] && dp_y[cnt_y][y+8000]) ? "Yes" : "No") << endl;

  return 0;
}

Measured memory_bytes: 251520
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
typedef long long ll;
const ll inf = 1e9;
int main(){
    int n; cin >> n;
    vector<ll> a(n);
    rep(i,n)cin >> a[i];
    int q; cin >> q;
    rep(i,q){
        int b, e;
        cin >> b >> e;
        reverse(a.begin()+b, a.begin()+e);
    }
    rep(i,n)cout << a[i] << ((i < n-1)?" ":"\n");
    return 0;
} 


Measured memory_bytes: 3104
N = int(input())
S = list(input())

lst = [0]*N
Re = S.count("E")
Lw = 0

for i in range(N):
    if S[i] == "E":
        Re -= 1
        lst[i] = Re + Lw
    else:
        Lw += 1
        lst[i] = Re + Lw - 1

ans = min(lst)
print(ans)


Measured memory_bytes: 23124
# ABC151 D-Maze Master
import queue
H,W = map(int,input().split())
maze = [input() for _ in range(H)]
dydx = ((0,1),(0,-1),(1,0),(-1,0))

def reach(sy,sx):
    visited = [[0]*W for _ in range(H)]
    visited[sy][sx] = 1
    q = queue.Queue()
    q.put((sy,sx,0))
    while True:
        y,x,d = q.get()
        for dy,dx in dydx:
            if (0<=y+dy<H)&(0<=x+dx<W):
                if (maze[y+dy][x+dx] == '#') or (visited[y+dy][x+dx] == 1):
                    continue
                visited[y+dy][x+dx] = 1
                q.put((y+dy,x+dx,d+1))
        if q.empty():
            ans = d
            break
    return ans

d = -1
for sy in range(H):
    for sx in range(W):
        if maze[sy][sx] == '#':
            continue
        d = max(d,reach(sy,sx))
                
print(d)

Measured memory_bytes: 3952