akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i,a,b) for(int(i)=(a);(i)<(b);++(i))
#define RREP(i,a,b) for(int(i)=(a)-1;(i)>=(b);--(i))
#define ALL(x) (x).begin(),(x).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
using namespace std;
typedef long long ll;

int main()
{
  int N;
  cin >> N;
  vector<tuple<string,int,int>> SP(N);
  REP(i,0,N) {
    string s;
    int p;
    cin >> s >> p;
    // 点数は高い順
    SP[i] = make_tuple(s, -p, i);
  }
  sort(ALL(SP));

  // 1-indexedに治す
  REP(i,0,N) {
    cout << (get<2>(SP[i]) + 1) << endl;
  }

  return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    readLine()!!
    val an = readLine()!!.split(" ").map(String::toInt)

    val flag = BooleanArray(8)
    var freeCount = 0
    an.forEach {
        when {
            it in 1..399 -> flag[0] = true
            it in 400..799 -> flag[1] = true
            it in 800..1199 -> flag[2] = true
            it in 1200..1599 -> flag[3] = true
            it in 1600..1999 -> flag[4] = true
            it in 2000..2399 -> flag[5] = true
            it in 2400..2799 -> flag[6] = true
            it in 2800..3199 -> flag[7] = true
            else -> freeCount++
        }
    }
    val count = flag.count { it }

    val min = when (count) {
        0 -> 1
        else -> count
    }
    val max = count + freeCount

    println("$min $max")
}



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

int main() {
	int m,n;
	cin>>m>>n;
	if (m>n)
		for(int i = 0;i<m;i++)
			cout<<n;
	else
		for(int i = 0;i<n;i++)
			cout<<m;
	return 0;
}

Measured memory_bytes: 256
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_number(A, B) :-
    get_number(A),
    get_number(B).

get_number(A, B, C) :-
    get_number(A, B),
    get_number(C).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n\r\t', '', _, String).

get_chars(Xs) :-
    get_string(S),
    string_chars(S, Xs).

get_numbers(0, []).
get_numbers(N, [X|Xs]) :- 
    get_number(X), 
    N2 is N - 1, 
    get_numbers(N2, Xs).

put_numbers([]).
put_numbers([X|Xs]) :-
    writeln(X),
    put_numbers(Xs).

get_i_to_x_rbtree0(N, T) :-
    rb_empty(T2),
    get_i_to_x_rbtree(N, 0, T2, T).

get_i_to_x_rbtree1(N, T) :-
    rb_empty(T2),
    get_i_to_x_rbtree(N, 1, T2, T).

get_i_to_x_rbtree(0, _, T, T).
get_i_to_x_rbtree(N, I, T2, T) :-
    get_number(X),
    rb_insert(T2, I, X, T3),    
    N2 is N - 1,
    I2 is I + 1,
    get_i_to_x_rbtree(N2, I2, T3, T).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)
    length(S, L),
    sub_string

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==

    between(L,U,X): L <= X <= U
    nth0(I, Xs, Y), nth1(I, Xs, Y): (Xs,Y) -> I, (I, Xs) -> Y 

    sort(Key, Order, List, Sorted): Keyは通常0?, Orderは=なしが重複削除，=は重複保持
    \+ P(X) : not P(X)

    sum_list(Xs, Sum)

    orは!忘れに注意(末尾再帰なら直前)
*/

/* [L,R) */
range_list(L, R, []) :- L >= R, !.
range_list(L, R, [L|Xs]) :- L2 is L + 1, range_list(L2, R, Xs).

diff_count([], [], S, S).
diff_count([X|Xs], [Y|Ys], S, Z) :- X =\= Y, !, S2 is S + 1, diff_count(Xs, Ys, S2, Z).
diff_count([_|Xs], [_|Ys], S, Z) :- diff_count(Xs, Ys, S, Z).

main :-
    get_number(N),
    get_numbers(N, Xs),
    range_list(1, N+1, Ys),
    diff_count(Xs, Ys, 0, Z),
    (Z =< 2 -> writeln("YES") ; writeln("NO")).

    % statistics(inferences, IC), writeln(IC).


Measured memory_bytes: 8144
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <cmath>
#include <tuple>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long ll;

int main(int argc, char *argv[])
{
    int i, n, j;
	ll answer = 0;
	cin >> n;
	vector<int> b(n - 1);
	for (i = 0; i < n - 1; i++)
		cin >> b[i];

	// determine a[0] and a[n - 1]
	answer += (b[0] + b[n - 2]);

	for (i = 1; i < n - 1; i++) {
		// determine and add a[i]
		int small = min(b[i - 1], b[i]);
		answer += small;
	}

	cout << answer << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct P {
  int l,r,d;
}p[10000];

string s;
int k;
map<int,int> ma;
int a[11];

void dfs(int x) {
  while(k<s.size()) {
    if(s[k]=='(') {
      k++;
      p[x].l=x*2;
      dfs(x*2);
    }
    if(s[k]==' ') {
      k++;
      p[x].r=x*2+1;
      dfs(x*2+1);
    }
    if(isdigit(s[k])) {
      int y=0;
      while(k<s.size()&&isdigit(s[k])) {
        y*=10;
        y+=s[k]-'0';
        k++;
      }
      p[x].d=y;
      break;
    }
    if(s[k]==')') {
      k++;
      break;
    }
  }
}

int dfs2(int x) {
  if(p[x].l!=-1) {
    int ll=dfs2(p[x].l);
    int rr=dfs2(p[x].r);
    int r=ma[x];
    if(r==0) return ll&rr;
    else if(r==1) return ll|rr;
    return ll^rr;
  }
  return a[p[x].d-1];
}

int main() {
  while(1) {
    getline(cin,s);
    if(s=="END") break;
    int n;
    cin >> n;
    memset(a,0,sizeof(a));
    for(int i=0; i<n; i++) {
      for(int j=0,c; j<4; j++) {
        cin >> c;
        a[i]|=c<<j;
      }
    }
    for(int i=0; i<10000; i++) p[i]=(P){-1,-1,-1};
    k=0;
    dfs(1);
    vector<int> v;
    for(int i=0; i<10000; i++) {
      if(p[i].l!=-1) v.push_back(i);
    }
    int m=v.size(),ans=0;
    for(int t=0; t<(1<<(2*m)); t++) {
      bool f=1;
      ma.clear();
      for(int i=0; i<m; i++) {
        int b=(t>>(i*2))%4;
        if(b==3) f=0;
        else ma[v[i]]=b;
      }
      if(!f) continue;
      if(dfs2(1)==15) ans++;
    }
    cout << ans << endl;
    getline(cin,s);
  }
  return 0;
}


Measured memory_bytes: 1344
#include<stdio.h>
int a[50];
int main()
{
	int n,k,i,j,sum=0,x;
	scanf("%d%d",&n,&k);
	for(i=0;i<n;i++)
	scanf("%d",&a[i]);
	for(i=0;i<n-1;i++)
	{
		for(j=i+1;j<n;j++)
		{
			if(a[j]>a[i])
			{
			x=a[j];
			a[j]=a[i];
			a[i]=x;
		    }
		}
	}
	for(i=0;i<k;i++)
	sum=sum+a[i];
	printf("%d",sum);
	
}

Measured memory_bytes: 128
#include <cstdio>
using namespace std;
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
#define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
int a[100008];
int main(){
	register int n, k, i, pos1, ans, now;
	scanf("%d %d", &n, &k);
	for (i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
		if (a[i] == 1) pos1 = i;
	}
	ans = n;
	for (i = dmax(pos1 - k + 1, 1); i <= pos1 && i <= n - k + 1; ++i) {
		//fprintf(stderr, "%d\n", i);
		now = (i - 1 + k - 2) / (k - 1) + (n - (i + k - 1) + k - 2) / (k - 1) + 1;
		cmin(ans, now);
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007LL;
const int INF = LLONG_MAX;

signed main(){
    
    map<char, char> m;
    m['A'] = 'T';
    m['T'] = 'A';
    m['C'] = 'G';
    m['G'] = 'C';
    string s; cin >> s;
    s = s + 'Z';
    int ans = 0;
    int cnt = 0;
    for(int i = 0; i < s.size(); i++){
        if(m.find(s[i]) == m.end()){
            ans = max(ans, cnt);
            cnt = 0;
        }else{
            cnt++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 5e5 + 5;
const ll MOD = 1e9 + 7;
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define pis pair<ll,string>
#define F first
#define S second
#define LCM(a,b) ((a*b)/__gcd(a,b))
#define inf 1e15
#define test ll cse;cin>>cse;for(ll _i=1;_i<=cse;_i++)
#define PI 3.14159265
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const double EPS = 1E-9;
typedef vector< vector<double> > matrix;
typedef vector< vector<int> > array_2D;
typedef pair<int, pair<int, int> > ppi;
typedef vector<int> vi;



int main() {


    int n, m;
    cin >> n >> m;


    if(n <= m) cout << "unsafe\n";
    else
        cout << "safe\n";

    return 0;
}

Measured memory_bytes: 3632
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int K = in.nextInt();

            long[][] dp = new long[N][K];
            for (int i = 0; i < K; i++) {
                dp[0][i] = 1;
            }
            for (int i = 1; i < N; i++) {
                for (int j = 0; j < K; j++) {
                    for (int k = 0; k < K; k++) {
                        if (j != k) {
                            dp[i][k] += dp[i - 1][j];
                        }
                    }
                }
            }
            long sum = 0;
            for (int i = 0; i < K; i++) {
                sum += dp[N - 1][i];
            }
            out.println(sum);
        }

    }
}



Measured memory_bytes: 21972
#include "bits/stdc++.h"
using namespace std;
int n,A[50];
int cnt=0;
int solve(int i,int m){
	cnt++;
	if(m==0)return 1;
	if(i>=n)return 0;
	int res=solve(i+1,m)||solve(i+1,m-A[i]);
	return res;
}

int main(){
	int q,M,i;
	scanf("%d",&n);
	for (int i = 0; i < n; ++i) {
		scanf("%d",&A[i]);
	}
	scanf("%d",&q);
	for (int i = 0; i < q; ++i) {
		scanf("%d",&M);
		if(solve(0,M))printf("yes\n");
		else printf("no\n");
	}
	return 0;
}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
using lint = int64_t;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(v)    begin(v), end(v)
#define in        []{lint n; cin>>n; return n;}()

int main() { cin.tie(0); ios::sync_with_stdio(false);
    int N = in, L = in;

    if( L >= 0 ) {
        int sum = 0;
        for( int i=1; i<N; i++ ) {
            sum += i+L;
        }
        cout << sum << "\n";
        return 0;
    }

    if( L + N <= 0 ) {
        int sum = 0;
        for( int i=0; i<N-1; i++ ) {
            sum += i+L;
        }
        cout << sum << "\n";
        return 0;
    }

    int sum = 0;
    for( int i=0; i<N; i++ ) {
        sum += i+L;
    }
    cout << sum << "\n";
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int h[100100];

int main(void){
	int n,i;
	bool ans = true;
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> h[i];
	}
	--h[0];
	for(i=1; i<n; ++i){
		if(h[i-1] < h[i]){
			--h[i];
		}else if(h[i-1] > h[i]){
			ans = false;
		}
	}
	cout << ((ans)?"Yes":"No") << endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
  
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

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

    string s;
    cin >> s;

    if (s.size() < 26) {
        for (int i = 0; i < 26; i++) {
            if (find(all(s), 'a' + i) == s.end()) {
                s.push_back('a' + i);
                break;
            }
        }
    }
    else {
        for (int i = 25; i >= 0; i--) {
            char mn = 'z';
            bool ok = false;
            for (int j = i + 1; j < 26; j++) {
                if (s[i] < s[j]) {
                    ok = true;
                    mn = min(mn, s[j]);
                }
            }
            if (ok) {
                s.erase(s.begin() + i, s.end());
                s.push_back(mn);
                break;
            }
        }
        if (s.size() == 26)
            s = "-1";
    }

    cout << s << "\n";

    return 0;
}

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

using namespace std;

int h[111111];
int main() {
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		scanf("%d", h + i);
	sort(h, h + n);
	int m = 2e9;
	for (int i = 0; i < n - k + 1; i++)
		m = min(m, h[i + k - 1] - h[i]);
	cout << m << endl;
	return 0;
}


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

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

void nie(){
  cout << "No\n";
  exit(0);
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  int n,m;
  cin >> n >> m;
  map<int,int> il;
  R(i,n){
    string z;
    cin >> z;
    R(j,m){
      il[z[j]]++;
    }
  }
  int pom = 0;
  for(auto &el:il){
    if(el.SE & 1){
      el.SE--;
      pom++;
    }
    el.SE/=2;
  }
  if(pom > 1)nie();
  
  int par = 0;
  if(n & 1) par += m / 2;
  if(m & 1) par += n / 2;
  
  pom = 0;
  for(auto &el:il){
    debug(el.SE);
    if(el.SE & 1){
      pom++;
    }
  }
  debug(pom,par);
  if(pom > par){
    nie();
  }
  cout << "Yes\n";
  
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;

typedef long long ll;
const ll maxn=2e3+10,mod=924844033;
ll n,k,dp[maxn][maxn][2],ans;

int main(){
	ios::sync_with_stdio(false);
	cin>>n>>k;
	dp[0][0][0]=1;
	for(ll i=1,cnt=0;i<=2*k;++i)
		for(ll j=i;j<=n;j+=2*k){
			++cnt;
			dp[cnt][0][0]=1;
			for(ll a=1;a<=cnt;++a){
				dp[cnt][a][0]=(dp[cnt-1][a][0]+dp[cnt-1][a][1])%mod;
				if(j>k)
					(dp[cnt][a][0]+=dp[cnt-1][a-1][0])%=mod;
				if(j+2*k<=n)
					(dp[cnt][a][1]+=dp[cnt-1][a-1][0]+dp[cnt-1][a-1][1])%=mod;
				else if(j+k<=n)
					(dp[cnt][a][0]+=dp[cnt-1][a-1][0]+dp[cnt-1][a-1][1])%=mod;
			}
		}
	for(ll i=0;i<=n;++i){
		ll res=i&1?mod-1:1;
		res=res*dp[n][i][0]%mod;
		for(ll j=1;j<=n-i;++j)
			res=res*j%mod;
		(ans+=res)%=mod;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 61312
url = "https://atcoder.jp//contests/abc159/tasks/abc159_b"

def main():
    ans = 'Yes'
    S = input()
    if S != S[::-1]:
        ans = 'No'

    t = S[0:(len(S) - 1) // 2]
    if t[::-1] != t:
        ans = 'No'

    t = S[(len(S) + 2) // 2:len(S)]
    if t[::-1] != t:
        ans = 'No'

    print(ans)

if __name__ == '__main__':
    main()


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



int main(void){
    string S;
    cin >>S;
    bool flag = false;
    string ans ="No";
    for(int i = 0; i < S.length();i++){
        if(S.substr(i,1)=="C")flag = true;
        if(S.substr(i,1)=="F"&&flag == true)ans ="Yes";
    }
    cout <<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
int main()
{
    int n, k;
    cin >> n >> k;
    int v[200001] = {0};
    rep(i, n)
    {
        int tmp;
        cin >> tmp;
        v[tmp]++;
    }

    sort(v, v + (n + 1));
    reverse(v, v + (n + 1));
    int i;
    for (i = 0; v[i] != 0; i++)
        ;

    if (i <= k)
    {
        cout << 0;
    }
    else
    {
        int ans = 0;
        for (int j = i - 1; j >= k; j--)
        {
            ans += v[j];
        }
        cout << ans;
    }

    return 0;
}

Measured memory_bytes: 1024
(function() {
  var cls, fs;

  cls = function(a) {
    switch (false) {
      case !(a <= 48.00):
        return 'light fly';
      case !(48.00 < a && a <= 51.00):
        return 'fly';
      case !(51.00 < a && a <= 54.00):
        return 'bantam';
      case !(54.00 < a && a <= 57.00):
        return 'feather';
      case !(57.00 < a && a <= 60.00):
        return 'light';
      case !(60.00 < a && a <= 64.00):
        return 'light welter';
      case !(64.00 < a && a <= 69.00):
        return 'welter';
      case !(69.00 < a && a <= 75.00):
        return 'light middle';
      case !(75.00 < a && a <= 81.00):
        return 'middle';
      case !(81.00 < a && a <= 91.00):
        return 'light heavy';
      default:
        return 'heavy';
    }
  };

  fs = require('fs');

  fs.readFile('/dev/stdin', 'utf8', function(_, out) {
    return out.split('\n').slice(0, -1).map(function(s) {
      return +s;
    }).forEach(function(s) {
      return console.log(cls(s));
    });
  });

}).call(this);

Measured memory_bytes: 7644
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define EPS (1e-7)
#define INF (1e11 + 10)
#define PI (acos(-1))
#define MOD (1000000007)
#define REP(i,x) for(int i=0;i<(int)(x);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 ALL(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
template<class T>string watch(T &v){string res="";for(auto f:v)res+=(to_string(f)+" ");return res;}
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; }
#define int long long int

main() {
    int A, B, Q; cin >> A >> B >> Q;
    vector<ll> s(A, 0), t(B, 0);
    REP(i, A) {
        cin >> s[i];
    }
    REP(i, B) {
        cin >> t[i];
    }
    vector<ll> s_diff(A, 0), t_diff(B, 0);
    REP(i, A) {
        int ind = lower_bound(ALL(t), s[i]) - t.begin();
        ll sm;
        if (ind == 0){
            sm = INF;
        } else {
            sm = s[i] - t[ind-1];
        }
        ll bi;
        if (ind == B){
            bi = INF;
        } else {
            bi = t[ind] - s[i];
        }
        s_diff[i] = min(sm, bi);
    }
    REP(i, B) {
        int ind = lower_bound(ALL(s), t[i]) - s.begin();
        ll sm;
        if (ind == 0){
            sm = INF;
        } else {
            sm = t[i] - s[ind-1];
        }
        ll bi;
        if (ind == A){
            bi = INF;
        } else {
            bi = s[ind] - t[i];
        }
        t_diff[i] = min(sm, bi);
    }
    REP(i, Q) {
        ll ans;
        int x; cin >> x;
        int ind = lower_bound(ALL(t), x) - t.begin();
        ll sm;
        if (ind == 0){
            sm = INF;
        } else {
            sm = x - t[ind-1] + t_diff[ind-1];
        }
        ll bi;
        if (ind == B){
            bi = INF;
        } else {
            bi = t[ind] - x + t_diff[ind];
        }
        ans = min(sm, bi);
        ind = lower_bound(ALL(s), x) - s.begin();
        if (ind == 0){
            sm = INF;
        } else {
            sm = x - s[ind-1] + s_diff[ind-1];
        }
        if (ind == A){
            bi = INF;
        } else {
            bi = s[ind] - x + s_diff[ind];
        }
        ans = min(ans, min(sm, bi));
        cout << ans << endl;
    }
}

Measured memory_bytes: 4480
import sys
n,k=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[0])
cnt=0
for i in range(n):
    cnt+=ab[i][1]
    if k<=cnt:
        print(ab[i][0])
        sys.exit()



Measured memory_bytes: 29144
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

V<int> operator*(V<int> a,V<int> b){
	int N = a.size();
	V<int> c(N);
	rep(i,N) c[i] = a[b[i]];
	return c;
}
V<int> inv(V<int> a){
	int N = a.size();
	V<int> c(N);
	rep(i,N) c[a[i]] = i;
	return c;
}
V<int> ex(V<int> x,int p){
	int N = x.size();
	V<int> a(N);iota(all(a),0);
	while(p){
		if(p&1) a = a*x;
		x = x*x;
		p /= 2;
	}
	return a;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	int N,K; cin >> N >> K,K--;
	V<int> p(N),q(N);
	rep(i,N) cin >> p[i],p[i]--;
	rep(i,N) cin >> q[i],q[i]--;

	V<int> L = q*inv(p)*inv(q)*p;

	VV<int> pfx(6);
	pfx[0] = p, pfx[1] = q;
	for(int i=2;i<6;i++) pfx[i] = pfx[i-1]*inv(pfx[i-2]);
	int e = K/6;
	L = ex(L,e);
	auto res = L * pfx[K%6] * inv(L);
	rep(i,N) cout << res[i]+1 << " ";
	cout << endl;

}


Measured memory_bytes: 6696
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
long long n;
cin >> n;
long long a,b;
for(int i=1;i<=sqrt(n);i++){
if(n % i == 0){
a = i;
b = n / i;
}
}

cout << a + b - 2 << endl;

return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main() {
  string s;
  cin >> s;
  int CntBC = 0;
  char prev;
  long long score = 0;
  for(int j=0; j < s.size(); j++){
    int i = s.size() - j - 1;
  	char c = s[i];
    if (prev == 'C') {
      if (c == 'B'){
        CntBC++;
      } else {
      	CntBC = 0;
      }
    }
    if (c == 'B' && prev == 'B'){
    	CntBC = 0;
    }
    if (c == 'A') {
      score += CntBC;
    }
    if (prev == 'A' && c == 'B') {
    	CntBC = 0;
    }
    prev = c;
  }
  cout << score << endl;
  return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<map>
#include<string>
using namespace std;
int main()
{
	int a=0,b=0;
	map<int,int> p,n;
	string in;
	while(getline(cin,in))
	{
		if(in=="") break;

		int cnt=0;
		a=0; b=0;
		while(in[cnt]!=',')
		{
			a*=10;
			a+=in[cnt]-'0';
			cnt++;
		}
		cnt++;
		for(int i = cnt; i < in.size(); ++i)
		{
			b*=10;
			b+=in[i]-'0';
		}
		if(p.count(a)==0)
			p.insert(map<int,int>::value_type(a,1));
		else p[a]++;
	}
	while(scanf("%d,%d",&a,&b)!=EOF)
	{
		if(n.count(a)==0)
			n.insert(map<int,int>::value_type(a,1));
		else n[a]++;
	}

	map<int,int>::iterator it=p.begin();
	while(it!=p.end())
	{
		if(n.count((*it).first)==1)
		{
			printf("%d %d\n",(*it).first,(*it).second+n[(*it).first]);
		}
		it++;
	}

  return 0;
}

Measured memory_bytes: 1248
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int main()
{
    int x, a;
    cin >> x >> a;
    if (x < a) cout << 0 << endl;
    else cout << 10 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ld long double
#define int long long
using namespace std;
const int N = 1e5 + 10;
const int mod = 1e9 + 7;
const int inf = 1e17;
int Dx[] = {0, 1, -1, 0, -1, 1, 1, -1};
int Dy[] = {1, 0, 0, -1, -1, 1, -1, 1};
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int a, b;
	cin >> a >> b;
	a = 3 * a + b;
	cout << a / 2;
}

Measured memory_bytes: 256
using System;

namespace _1_3c
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] a=new int [4000], b= new int[4000];
            int piyo = 0;
            string[] hoge;
            for (int i = 0; ; i++)
            {
                hoge = Console.ReadLine().Split(' ');
                a[i] = int.Parse(hoge[0]);
                b[i] = int.Parse(hoge[1]);
                if (a[i] == 0 && b[i] == 0)
                {
                    piyo = i;
                    break;
                }
            }
            for (int j = 0; j < piyo; j++)
            {
                if (a[j] <= b[j])
                {
                    Console.WriteLine("{0} {1}", a[j], b[j]);
                }
                else
                {
                    Console.WriteLine("{0} {1}", b[j], a[j]);
                }
            }
        }
    }
}



Measured memory_bytes: 17924
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
// 素数かどうか判定
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))




signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	vector<int>a(n),b(n),c(n);
	rep(i, n) {
		cin >> a[i]; c[i] = a[i] - (i+1);
	}
	rep(i, n) {
		b[i] = i + 1;
	}
	sort(c.begin(), c.end());
	int tmp = c[n / 2];
	int ans = 0;
	rep(i, n) {
		ans += abs(a[i] - (tmp + b[i]));
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    set<int> mid;
    vector<int> _mid;
    for (int i = 1; i <= m; i++) {
        int x, y;
        scanf("%d%d", &x, &y);
        if (x == 1) mid.insert(y);
        if (y == n) _mid.push_back(x);
    }
    if (mid.count(n)) {
        puts("POSSIBLE");
    } else {
        for (int i : _mid) {
            if (mid.count(i)) {
                puts("POSSIBLE");
                exit(0);
            }
        }
        puts("IMPOSSIBLE");
    }
    return 0;
}

Measured memory_bytes: 5368
#include<string>
#include<iostream>
#include<cstdio>
using namespace std;
struct str {
	int l, r;
};

str train[200002];
int n, m, q, arr[501][501], dp[501][501];
int main() {
	scanf("%d %d %d", &n, &m, &q);
	for (int i = 0; i < m; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		arr[a][b]++;
	}
	for(int i=1;i<=500;i++)
		for (int j = i; j <= 500; j++)
				dp[i][j] = dp[i][j-1]+arr[i][j];
	for (int i = 1; i <= 500; i++)
		for (int j = i; j >= 1; j--)
				dp[j][i] += dp[j+1][i];
		
	for (int i = 0; i < q; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		printf("%d\n", dp[a][b]);
	}
	return 0;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
    
#define ll long long int
#define pb push_back
#define rep(i , j , n) for(ll i = j ; i < n ; i++)
#define per(i , j , n) for(ll i = j ; i >= n ; i--)
#define all(x) x.begin(), x.end()
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vll;
typedef vector<bool>	vb;
ll mod = 1e9 + 7;



int main(){  
    ll a;
    cin >> a;
    cout << a + a*a + (a*a*a);
}

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

int main() {
	int N, K;
	scanf("%d %d", &N, &K);
	int *A;
	A = (int *)malloc(sizeof(int)* N);
	int i = 0, d = 0, a = 0;
	for(i = 0; i < K; i++){
		scanf("%d", &d);
		while(d > 0){
			scanf("%d", &a);
			A[a - 1]++;
			d--;
		}
	}
	int count = 0;
	for(i = 0; i < N; i++){
		if(A[i] == 0){
			count++;
		}
	}
	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 2124
def main():
    N, M = [int(n) for n in input().split()]
    A = [int(n) for n in input().split()]
    B = [0]*(N+1)
    B[0] = 0
    d = {}
    accum = 0
    for i in range(N+1):
        B[i] = accum
        if i != N:
            accum += A[i]
    
    for i, b in enumerate(B):
        x = b % M
        if x in d.keys():
            d[x] += 1
        else:
            d[x] = 1
    # print(B)
    print(sum([i * (i - 1)//2 for i in d.values()]))
        
# import os,sys, time

# current = os.path.abspath(__file__ + "/..")+"/"
# fdr = open(current + "d-case1.txt", "r")
# sys.stdin = fdr
# t = time.time()
# main()
# print(time.time() - t)
if __name__ == "__main__":
    main()

Measured memory_bytes: 17240
h, w = gets.split.map(&:to_i)
ans = []

if h % 3 == 0 || w % 3 == 0
  ans = [0]
else
  # 縦2分割する(1:2)
  hikaeme_left = (w / 3.0).floor # 左小さめ
  rest = w - hikaeme_left
  # -> さらに縦分割
  if rest >= 2
    a = [hikaeme_left * h, (rest / 2.0).floor * h, (rest / 2.0).ceil * h]
    ans << a.max - a.min
  end
  # -> 大きい方を横分割
  if h >= 2
    b = [hikaeme_left * h, rest * (h / 2.0).floor, rest * (h / 2.0).ceil]
    ans << b.max - b.min
  end

  # 同様に
  donyoku_left = (w / 3.0).ceil # 左でかめ
  restx = w - donyoku_left
  if restx >= 2
    c = [donyoku_left * h, (restx / 2.0).floor * h, (restx / 2.0).ceil * h]
    ans << c.max - c.min
  end
  if h >= 2
    d = [donyoku_left * h, restx * (h / 2.0).floor, restx * (h / 2.0).ceil]
    ans << d.max - d.min
  end

  # 縦横逆転して
  w, h = [h, w] # swap

  # 縦2分割する(1:2)
  hikaeme_left = (w / 3.0).floor # 左小さめ
  rest = w - hikaeme_left
  # -> さらに縦分割
  if rest >= 2
    a = [hikaeme_left * h, (rest / 2.0).floor * h, (rest / 2.0).ceil * h]
    ans << a.max - a.min
  end
  # -> 大きい方を横分割
  if h >= 2
    b = [hikaeme_left * h, rest * (h / 2.0).floor, rest * (h / 2.0).ceil]
    ans << b.max - b.min
  end

  # 同様に
  donyoku_left = (w / 3.0).ceil # 左でかめ
  restx = w - donyoku_left
  if restx >= 2
    c = [donyoku_left * h, (restx / 2.0).floor * h, (restx / 2.0).ceil * h]
    ans << c.max - c.min
  end
  if h >= 2
    d = [donyoku_left * h, restx * (h / 2.0).floor, restx * (h / 2.0).ceil]
    ans << d.max - d.min
  end

end

puts ans.min


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

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

	int n,t;
	vector <int> v;

	cin >> n;

	for(int i=0;i<n;i++)
	{
		cin >> t;
		v.push_back(t);
	}

	int res = 0;

	while(1)
	{
		bool ok = true;
		for(int i=0;i<n;i++)
		{
			if(v[i]!=0)
			{
				ok = false;
				break;
			}
		}
		if(ok)
		{
			break;
		}

		int idx = 0;
		int h = 100000;

		for(int i=0;i<n;i++)
		{
			if(v[i]==0)
			{
				continue;	
			}
			if(v[i]<h)
			{
				h = v[i];
				idx = i;
			}
		}

		int idx2 = idx;
		idx-=1;
		while(1)
		{
			if(idx<0 || v[idx]<h)
			{
				break;
			}
			v[idx]-=h;
			idx--;
		}

		idx = idx2;
		while(1)
		{
			if(idx>=n || v[idx]<h)
			{
				break;
			}
			v[idx]-=h;
			idx++;
		}

		res+=h;
	}

	cout << res << '\n';
	return 0;
}

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

int main()
{
  int W,H,N;
  cin >> W >> H >> N;
  
  int ans;
  ans=0;
  if(W<H)
  {
    if((N%H)!=0)
    {
      ans=N/H+1;
    }
    else
    {
      ans=N/H;
    }
  }
  else 
  {
    if((N%W)!=0)
    {
      ans=N/W+1;
    }
    else
    {
      ans=N/W;
    }
  }
  
  cout << ans;
  return 0;
  
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define FT() int t; scanf("%d",&t); while(t--)
#define pb push_back
#define nl printf("\n")
#define fi(i,start,end) for(int i=start; i < (int)end ; ++i)
#define ip(n)   scanf("%d",&n)
#define mz(a)   memset(a,0,sizeof(a))
#define inpArr(A,n) fi(i,0,n)   ip(A[i]);
#define print(a)  for(auto i : a)   cout<<i<<" "; nl;
#define Fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
ll max(ll a,ll b)   {return a>b?a:b;}
ll min(ll a,ll b)   {return a<b?a:b;}

int main() {
    #ifndef ONLINE_JUDGE
    freopen("D:/Sublime/Rough/input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #endif
    //std::cout << std::fixed;
    //std::cout << std::setprecision(6);
    Fastio;
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll a1 = a*c, a2 = a*d, a3 = b*c, a4 = b*d;
    cout<<(max(a1,max(a2,max(a3,a4))));

    
    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s";
    #endif
    
    return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
int i,j,k,n,len1,len2;
string s1,s2;
int main()
{
	getline(cin,s1);len1=s1.length();
    getline(cin,s2);len2=s2.length();
    sort(s1.begin(),s1.end() );
    sort(s2.begin(),s2.end());
	reverse(s2.begin(),s2.end());
   // cout<<s1<<' '<<s2<<endl;
	  if(s1<s2)cout<<"Yes\n";
	  else cout<<"No\n";
	return 0;
}

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

using namespace std;
#define ll long long

int main(){
	int n,m;
	cin>>n>>m;
	vector<int> a(n);
	int sum = 0;
	for(int i=0;i<n;++i){
	cin>>a[i];
    sum+=a[i];
	}
	int minVotes = ceil( sum/(4.0*m) );
	int count = 0; 
  
	for(auto i : a)
		if(i >= minVotes) count+=1;

	if(count >= m) cout<<"Yes";
	else           cout<<"No";
  
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>   
using namespace std;
long long n,a,b,i,j,ans,m;
int main() {
cin>>n;
for(i=1;i*i<=n;i++)
{
if(n%i!=0) 
{continue;}
a=i;
b=n/i;
m=max(a,b);
j=0;
while(m!=0){
m=m/10; j++;} 
m=j;}
cout<<m;
return 0;
}  	


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstring>
#include <iostream>
#include <algorithm>
#define foror(i,a,b) for(i=a;i<b;i++)
#define foror2(i,a,b) for(i=a;i>b;i--)
#define EPS 1.0e-6
#define PI acos(-1.0)
#define INF 3000000000
#define MOD 1000000009
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define lson o<<1, l, m
#define rson o<<1|1, m+1, r
//using ll = long long;
//using ull= unsigned long long;
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que;
typedef long long ll;
const int MAXN=1e5+5;
vector<int> E[MAXN];
int co[MAXN],sv[MAXN],cnt[3];
int mx=0,n;
bool flag=false;
void dfs1(int now,int fa,int dp)
{
	sv[dp]=now;
	if(now==n)
	{
		flag=true;
		mx=dp;
		return ;
	}
	for(int i=0;i<E[now].size()&&!flag;i++)
	{
		int v=E[now][i];
		if(v==fa)
			continue;
		dfs1(v,now,dp+1);
	}
}
void dfs2(int now,int fa,int color)
{
	co[now]=color;
	cnt[color]++;
	for(auto v:E[now])
	{
		if(v==fa||co[v])
			continue;
		dfs2(v,now,color);
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		E[u].push_back(v);
		E[v].push_back(u);
	}
	dfs1(1,0,0);
	int l=0,r=mx;
	while(l<=r)
	{
		co[sv[l++]]=1;
		if(l>r)
			break;
		co[sv[r--]]=2;
	}
	for(int i=0;i<=mx;i++)
	{
		dfs2(sv[i],0,co[sv[i]]);
	}
	if(cnt[1]>cnt[2])
	{
		puts("Fennec");
	}
	else
	{
		puts("Snuke");
	}
	return 0;
}



Measured memory_bytes: 12800
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    a , b = input().split()
    if a == 'H':
        print(b)
    else:
        if b == 'D':
            print('H')
        else:
            print('D')

solve()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
	using namespace std;
	#define FAST  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
	#define ll long long int


	int main()
	{
		FAST;
		//ll testcase;
		//cin>>testcase;
		//for(ll t=0;t<testcase;t++)
		{
			//use long long
			//donot memeset other than 0 or 1 or -1
			//segmentation fault-> check for uninitialized global variable or out of bounds
			//always check for bottle neck (whether original constraints can be reduced by introducing some condition)
			//dont rush to writing code think through the logic	
			int x,n;
			cin>>x>>n;
			int a[n];
			for(int i=0;i<n;i++)
				cin>>a[i];
			int ans=106,diff=107;
			for(int i=0;i<=105;i++)
			{
				bool found=false;
				for(int j=0;j<n;j++)
				{
					if(a[j]==i)
					{
						found=true;
					}
				}
				if(!found)
				{
					if(abs(x-i)<diff)
					{
						diff=abs(x-i);
						ans=i;
					}
				}
			}
			cout<<ans<<'\n';
		}
		return 0;
	}



































Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N;
    cin >> N;
    pii p[N], q[N];
    rep(i, N) cin >> p[i].first >> p[i].second;
    rep(i, N) cin >> q[i].first >> q[i].second;
    sort(p, p+N), sort(q, q+N);
    int cnt[2*N];
    fill(cnt, cnt+2*N, 0);
    int now = 0, ans = 0;
    rep(i, N){
        while(now < N && p[now].first < q[i].first){
            cnt[p[now++].second]++;
        }
        rep3(j, q[i].second-1, 0){
            if(cnt[j]){
                cnt[j]--, ans++;
                break;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3612
// finish date: 2018/2/09

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>>
        vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


int main() {
    int in;
    vi v(4,0);
    rep(i, 6){
        cin >> in;
        v[in-1]++;
    }
    rep(i,4){
        if(v[i]==3){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}

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

using namespace std;

int main(void) {

	int N, K; cin >> N >> K;
	vector<vector<unsigned long long> > fishrange;
	vector<unsigned long long> x, y, d;

	unsigned long long volume = 0;

	for (int i = 0; i < N; i++) {
		vector<unsigned long long> range;
		int x1, y1, d1, x2, y2, d2; cin >> x1 >> y1 >> d1 >> x2 >> y2 >> d2;

		range.push_back(x1); range.push_back(y1); range.push_back(d1);
		range.push_back(x2); range.push_back(y2); range.push_back(d2);

		x.push_back(x1); x.push_back(x2);
		y.push_back(y1); y.push_back(y2);
		d.push_back(d1); d.push_back(d2);

		fishrange.push_back(range);
	}

	sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
	sort(y.begin(), y.end()); y.erase(unique(y.begin(), y.end()), y.end());
	sort(d.begin(), d.end()); d.erase(unique(d.begin(), d.end()), d.end());

	for (int i = 0; i < (x.size() - 1); i++) {
		for (int j = 0; j < (y.size() - 1); j++) {

			for (int t = 0; t < (d.size() - 1); t++) {

				int count = 0;

				for (int s = 0; s < N; s++) {
					if (x[i] >= fishrange[s][0] && x[i + 1] <= fishrange[s][3] &&
						y[j] >= fishrange[s][1] && y[j + 1] <= fishrange[s][4] &&
						d[t] >= fishrange[s][2] && d[t + 1] <= fishrange[s][5])

						count++;
				}

				if (count >= K) volume += (x[i + 1] - x[i])*(y[j + 1] - y[j])*(d[t + 1] - d[t]);

			}
		}
	}

	cout << volume << endl;

	return 0;

}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long a, ans;
  string b;
  cin >> a >> b;
  b.erase(b.begin() + 1);
  int B = stoi(b);
  ans = 0;

ans = a*B;
ans =ans/100;
cout << ans << endl;
} 

Measured memory_bytes: 3632
#include<stdio.h>
#include<utility>
#include<algorithm>
#include<iostream>
using namespace std;
int W,H,la;
pair<int,int> a[222222];
long long int curW,curH;
long long int res;
int main(){
	int x;
	scanf("%d%d",&W,&H);
	for(int i=0; i<W; i++){
		scanf("%d",&x);
		a[la++]=make_pair(x,-1);
	}
	for(int i=0; i<H; i++){
		scanf("%d",&x);
		a[la++]=make_pair(x,1);
	}
	sort(a,a+la);
	curW = H+1;
	curH = W+1;
	res=0;
	for(int i=0; i<la; i++)
		if(a[i].second == -1){
			res += a[i].first * curW;
			curH --;
		}else{
			res += a[i].first * curH;
			curW --;
		}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);

		long x = sc.nextLong();
		long k = sc.nextLong();
		long d = sc.nextLong();

		long a = Math.abs(x / d);

		if (a >= k) {
			if (x > 0){
				System.out.println(Math.abs(x - (k * d)));
			} else {
				System.out.println(Math.abs(x + (k * d)));
			}
		} else {
			long ans = 0;
			if (x > 0) {
				if (Math.abs(x - (a * d)) > Math.abs(x - (a+1) * d)){
					a++;
				}
				ans = x - (a * d);
				if ((k - a) % 2 == 1){
					if (ans > 0){
						ans -= d;
					} else {
						ans += d;
					}
				}
			} else {
				if (Math.abs(x - (a * d)) > Math.abs(x - (a+1) * d)){
					a++;
				}
				ans = x + (a * d);
				if ((k - a) % 2 == 1){
					if (ans > 0){
						ans -= d;
					} else {
						ans += d;
					}
				}
			}
			System.out.println(Math.abs(ans));
		}
	}


}

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

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define square(x) (x) * (x)
#define cube(x) (x) * (x) * (x)

const int INF = 1e9;

using namespace std;

vector<tuple<int, char, int> > a;
bool stable = true;

int partition(int l, int r){
    int pivot = get<0>(a[r]);
    int i = l-1;
    for (int j = l; j < r; j++){
        if(get<0>(a[j]) <= pivot){
            i++;
            swap(a[i], a[j]);
        }
    }
    swap(a[i+1], a[r]);
    return i+1;
}

void q_sort(int l, int r) {
    if(l < r){
        int q = partition(l, r);
        q_sort(l, q-1);
        q_sort(q+1, r);
    }
    return;
}

int main() {
    int n;
    int num;
    char c;
    cin >> n;
    REP(i, n) {
        cin >> c >> num;
        a.push_back(tie(num, c, i));
    }
    q_sort(0, n-1);
    int i = 0;

    while(i < n){
        int j = 1;
        while (i+j < n && get<0>(a[i]) == get<0>(a[i+j]) ){
            if(get<2>(a[i+j]) < get<2>(a[i]) ){
                stable = false;
                break;
            } else {
                j++;
                continue;
            }
        }
        i += j;
    }

    if(stable)
        cout << "Stable" << endl;
    else
        cout << "Not stable" << endl;
    REP(i, n) cout << get<1>(a[i]) << " " << get<0>(a[i]) << endl;

    return 0;
}

Measured memory_bytes: 2700
import java.util.*;

public class Main {

  static Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {
    int A = sc.nextInt();
    int B = sc.nextInt();
    int K = sc.nextInt();

    ArrayList divs = new ArrayList();

    for (int i=1; i<=A*B; i++) {
      if (A % i == 0 && B % i == 0) {
        divs.add(i);
      }
    }

    System.out.println(divs.get(divs.size() - K));

  }
}

Measured memory_bytes: 23124
A, B, C = map(int, input().split())


def check(A, B, C):
    if A & 1 or B & 1 or C & 1:
        return 0
    if A == B == C:
        return -1
    return 1 + check((A + B) // 2, (B + C) // 2, (C + A) // 2)


answer = check(A, B, C)
print(answer)


Measured memory_bytes: 2940
n, max_w = gets.chomp.split(' ').map(&:to_i)
strs = n.times.map { gets.chomp.split(' ').map(&:to_i) }

dp = Array.new(max_w + 10, 0)
dp[0] = 0
ans = 0
strs.each do |w, v|
  (max_w - w).downto(0) do |idx|
    nv = dp[idx] + v
    nw = idx + w
    dp[nw] = nv if dp[nw] < nv
  end
end
print dp[max_w]


Measured memory_bytes: 2556