akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);

int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll N; cin>>N;
    vector<ll> A(N);
    set<ll> se;
    rep(i,N){
        cin>>A[i];
        se.insert(A[i]);
    }
    
    bool ans=false;
    
    if(sz(se)==1){
        for(auto x:se){
            if(x==0) ans=true;
        }
    }
    else if(sz(se)==2){
        if(N%3==0){
            ll cnt0=0;
            rep(i,N){
                if(A[i]==0) cnt0++;
            }
            if(cnt0==0){}
            else if(cnt0==N/3) ans=true;
        }
    }
    else if(sz(se)==3){
        ll X[3];
        ll cnt=0;
        for(auto x:se){
            X[cnt]=x;
            cnt++;
        }
        
        if((X[0]^X[1])==X[2] && (X[0]^X[2])==X[1] && (X[2]^X[1])==X[0]){
            ll cnt0=0,cnt1=0,cnt2=0;
            rep(i,N){
                if(A[i]==X[0]) cnt0++;
                else if(A[i]==X[1]) cnt1++;
                else cnt2++;
            }
            
            if((cnt0 == cnt1) && (cnt1==cnt2) && (cnt2==cnt0)) ans=true;
        }
    }
    
    if(ans) cout<<"Yes";
    else cout<<"No";
}



Measured memory_bytes: 7460
import collections
N = int(input())
S = [input() for _ in range(N)]
c = collections.Counter(S)
C=c.most_common()
result = []
for i in range(len(C)):
  if C[i][1] == C[0][1]:
    result.append(C[i][0])
  else:
    break
result.sort()
for j in range(len(result)):
  print(result[j])

Measured memory_bytes: 47640
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <cstdio>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

signed main() {
    int n;
    int t, a;
    int h[1002];

    cin >> n;
    cin >> t >> a;
    rep (i, n) {
        cin >> h[i];
    }
    double m = abs(a - (t - h[0] * 0.006));
    int ans = 1;
    for (int i = 1; i < n; i++) {
        if (m > abs(a - (t - h[i] * 0.006))) {
            ans = i + 1;
            m = abs(a - (t - h[i] * 0.006));
        }
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,x;
  cin>>n>>m>>x;
  int cost[12]={0},a[12][12]={0},ans=INT_MAX;
  for(int i=0;i<n;i++){
    cin>>cost[i];
    for(int j=0;j<m;j++)
      cin>>a[i][j];
  }
  for(int bit=0;bit<(1<<n);bit++){
    int sum=0;
    vector<int> s(m);
    for(int i=0;i<n;i++)
      if(bit & (1<<i)){
        sum+=cost[i];
        for(int j=0;j<m;j++)s[j]+=a[i][j];
      }
    bool is_ok=true;
    for(int i=0;i<m;i++)if(s[i]<x) is_ok=false;
    if(is_ok)ans=min(sum,ans);
  }
  if(ans==INT_MAX)ans=-1;
  cout<<ans<<endl;
  return 0;
}


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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(int x,int suc=1){
	printf("%lld",x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

const int inf=LLONG_MAX/3;

struct Pos{
	ld x,y;
	Pos operator+(const Pos&rhs)const{
		return Pos{x+rhs.x,y+rhs.y};
	}
	Pos operator-(const Pos&rhs)const{
		return Pos{x-rhs.x,y-rhs.y};
	}
	Pos operator*(const ld v)const{
		return Pos{x*v,y*v};
	}
};
ld Cross(const Pos&l,const Pos&r){
	return l.x*r.y-l.y*r.x;
}
signed main(){
	int n=read(),l=read();
	vector<Pos> ps(n+2);
	ps[0]=Pos{-1,0};
	ps[1]=Pos{0,0};
	int i=0,j=2;
	REP(_,n){
		ld ti=read(),v=read();
		ld x=ps[j-1].x+v,y=ps[j-1].y-v*ti;
		Pos w{x,y};
		while(ps[i].x<x-l)i++;
		{
			ld s=x-l-ps[i-1].x,t=ps[i].x-(x-l),d=ld(1)/(ps[i].x-ps[i-1].x);
			ps[i-1]=(ps[i]*s+ps[i-1]*t)*d;
			printf("%.10lf\n",double((ps[i-1].y-y)/l));
			i--;
		}
		while(j-i>=2)
			if(Cross(w-ps[j-1],ps[j-2]-ps[j-1])>0)j--;
			else break;
		ps[j++]=w;
	}
}


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

const int maxn = 45 + 15;
const int INF = 1e7;
int n, dis[maxn][maxn], cns;
map<int, int> cache;
vector<int> Find;
void init(){
	cache.clear(), Find.clear(), cns = 0;
	Find.push_back(0);
	for(int i = 1; i < maxn; i++)
	for(int j = 1; j < maxn; j++){
		if(i == j) dis[i][j] = 0;
		else dis[i][j] = dis[j][i] = INF;
	}
}
int ID(int x){
	if(cache.count(x)) return cache[x];
	Find.push_back(x);
	return cache[x] = ++cns;
} 
void floyd_warshall(){
	for(int k = 1; k <= cns; k++)
	for(int i = 1; i <= cns; i++)
	for(int j=1;j<=cns;j++) dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
}

int main(){
	while(scanf("%d", &n) == 1&& n){
		init();
		int ori, fin, val;
		while(n--){
			scanf("%d %d %d", &ori, &fin, &val);
			int xx = ID(ori), yy = ID(fin);
			dis[xx][yy] = dis[yy][xx] = val;
		}
		floyd_warshall();
		int ans = INF, index = -1;
		for(int i = 1; i <= cns; i++){
			int tem = 0;
			for(int j=1;j<=cns;j++) tem+=dis[i][j];
			if(tem < ans) ans = tem, index = i;
		} 
		printf("%d %d\n", Find[index], ans);
	}
	return 0;
}

Measured memory_bytes: 3140
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    vv<ll> costa = vvec(51, 51, LINF);
    rep(i, 51) costa[0][i] = 1LL << i;
    rep(k, 1, 51) {
        rep(i, 51) {
            costa[k][i] = costa[k - 1][i];
            rep(j, 0, 51) {
                costa[k][i] |= (costa[k][i] >> (j % k) & 1) << j;
            }
        }
    }
    vector<ll> costb(51);
    rep(i, 51) {
        costb[i] = 1LL << i;
    }

    int N;
    cin >> N;
    vector<int> A(N), B(N);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];

    ll ans = 0;
    for (int b = 50, c; b > 0; ) {
        for (c = 0; c < b; ++c) {
            bool ok = true;
            rep(i, N) {
                if ((costb[A[i]] & costa[c][B[i]]) == 0) {
                    ok = false;
                }
            }
            if (ok) break;
        }
        if (c == b) {
            write(-1);
            return 0;
        }
        else if (c > 0) {
            ans |= 1LL << c;
            b = c;
            rep(i, 51) {
                rep(k, 51) {
                    costb[i] |= (costb[i] >> k & 1) << (k % c);
                }
            }
        }
        else {
            break;
        }
    }
    write(ans);
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AOJ1_6_B
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] str = new string[n];
            string[] Cards = new string[52];
            for (int i = 0; i < n; i++)
            {
                str[i] = Console.ReadLine();
            }
            for (int i = 0; i < n; i++)//ｎ枚のカードに対してCardsにつめる
            {
                if (str[i].Contains("S"))//スペードなら
                {
                    for (int s = 0; s < 13; s++)
                    {
                        if (str[i] == ("S " + (s + 1).ToString()))
                        {
                            Cards[s] = str[i];
                        }
                    }
                }
                else if (str[i].Contains("H"))//ハートなら
                {
                    for (int h = 13; h < 26; h++)
                    {
                        if (str[i] == ("H " + (h + 1 - 13).ToString()))
                        {
                            Cards[h] = str[i];
                        }
                    }
                }
                else if (str[i].Contains("C"))//クラブなら
                {
                    for (int c = 26; c < 39; c++)
                    {
                        if (str[i] == ("C " + (c + 1 - 26).ToString()))
                        {
                            Cards[c] = str[i];
                        }
                    }
                }
                else if (str[i].Contains("D"))//ダイアなら
                {
                    for (int d = 39; d < 52; d++)
                    {
                        if (str[i] == ("D " + (d + 1 - 39).ToString()))
                        {
                            Cards[d] = str[i];
                        }
                    }
                }
            }
            for (int t = 0; t < 52; t++)
            {
                if (Cards[t] == null)
                {
                    if (0 <= t && t < 13)
                    {
                        Console.WriteLine("S " + (t + 1).ToString());
                    }
                    else if (13 <= t && t < 26)
                    {
                        Console.WriteLine("H " + (t + 1 - 13).ToString());
                    }
                    else if (26 <= t && t < 39)
                    {
                        Console.WriteLine("C " + (t + 1 - 26).ToString());
                    }
                    else if (39 <= t && t < 52)
                    {
                        Console.WriteLine("D " + (t + 1 - 39).ToString());
                    }
                }
            }
        }
    }
}



Measured memory_bytes: 15928
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep3(i, n) for (int i = 1; i < (int)(n+1); i++)
#define rep4(i, s, n) for (int i = (s); i < (int)(n+1); i++)
#define repr(i,n) for (int i = (n-1); i>=0;i--)
#define repr2(i,s,n) for (int i = (n-1); i>=(int)(s);i--)
#define repr3(i,n) for(int i = (n);i>0;i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Grid = vector<vector<int>>;
const ll INF = 10011032323450010;
const ld PI = 3.14159265358979323846;



int main() {
     
     // 入力
    int N; // 都市数
    cin >> N;
    string Pstr="",Qstr="";
    vector<int> P(N),Q(N);
    rep(i,N){
        cin>>P[i];
        Pstr+=P[i];

    }
    rep(i,N){
        cin>>Q[i];
        Qstr+=Q[i];


    }
    int count=0;
    sort(all(P));
    sort(all(Q));
    string S;
    // 初期順列
    vector<int> order(N);
    rep(i,N) order[i] = i;
    int a,b;

    // 探索
    
    do {
        count++;
        S="";
        rep(i,N){
            S+=P[order[i]];
        }
        if(S==Pstr){
            a=count;

        }
        S="";
        rep(i,N){
            S+=Q[order[i]];
        }
        if(S==Qstr){
            b=count;
        }


        
        
    } while (next_permutation(order.begin(), order.end()));

    // 答えを出力
    cout << abs(a-b) << endl;
return 0;
}


Measured memory_bytes: 256
n,m=list(map(int,input().split()))
l=[]
for i in range(n):
    k=list(map(int,input().split()))
    l.append(k[1:])

sum=0
for i in range(1,m+1):
    flg=True
    for j in range(n):
        if i not in l[j]:
            flg=False
            break
    if flg==True:
        sum+=1
print(sum)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<math.h>
#include<map>
#include<unordered_map> 
#include<vector>
#include<queue>
#include<set>
//#include<bits/stdc++.h>
#include<deque> 
#include<bitset>
#include <cmath>
#include<string>
#define N 40
#define K 300005
#define MOD 1e9+7
#define int long long 
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#define pi 3.14159265358979323846


int max(int a, int b){
    if(a > b)
        return a;
    return b;
}
int min(int a, int b){
    if(a < b)
        return a;
    return b;
}


int32_t main(){
    fastio
    int n, s;
    cin>>n>>s;
    int po[s + 5];
    int a[n];
    int mod = 998244353;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int dp[n][s + 1];
    for(int i=0;i<n;i++){
        for(int j=0;j<=s; j++){
            dp[i][j] = 0;
            if(j == 0){
                dp[i][0] = 1;
            }
        }
    }
    //cout<<dp[0][0]<<endl;
    dp[0][a[0]] = 1;
    dp[0][0] = 2;
    int ans= 0;
    for(int i=1;i<n;i++){
        for(int j = 0; j<=s; j++){
            dp[i][j] = dp[i-1][j] * 2;
            if(dp[i][j] >= mod){
                dp[i][j] %= mod;
            }
            if(j >= a[i]){
                
                //cout<<"Second "<<i-1<<" "<<j -a[i]<<" "<<dp[i-1][j-a[i]]<<endl;
                dp[i][j] += dp[i-1][j - a[i]];
                if(dp[i][j] >= mod){
                    dp[i][j] %= mod;
                }
            }
            //cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
        }


    }
    cout<<dp[n-1][s]<<endl;


    
    
    



    
  

    




    
   
    
}

Measured memory_bytes: 73940
#include <stdio.h>

/*関数*/
//配列を初期化する
int InitArray(void);
//挿入ソート
void InsertionSort(int* a, int n);
//結果を表示する
void print(int a[], int n);

//データの数の最大値
#define nMax 100

int main(void)
{
	int a[nMax];	//データを入れる配列
	int n;			//データの個数
	int i;

	//データの数を入力する
	scanf("%d", &n);

	//配列にデータを入力する
	for (i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
	}

	//挿入ソートを行う
	InsertionSort(a, n);

	return 0;
}

//配列を初期化する
int InitArray(void)
{
	int a[nMax];
	int i;

	for (i = 0; i < nMax; i++)
	{
		a[i] = 0;
	}
}

//挿入ソート
void InsertionSort(int* a, int n)
{
	int i;
	int j;
	int v;

	print(a, n);

	for (i = 1; i < n; i++)
	{
		v = a[i];
		j = i - 1;
		while ((j >= 0) && (a[j] > v))
		{
			a[j + 1] = a[j];
			j--;
		}
		a[j + 1] = v;
		print(a, n);
	}
}

//結果を表示する
void print(int a[], int n)
{
	int i;
	for (i = 0; i < n; i++)
	{
		if (i + 1 < n)
		{
			printf("%d ", a[i]);
		}
		else
		{
			printf("%d\n", a[i]);
		}
	}
}


Measured memory_bytes: 2072
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pie 3.142857143
#define ll long long int
#define fr(i,a,n) for(ll i=a;i<n;i++)
#define vi vector<int>
#define vlli vector<ll>
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fv(i,a) for(auto i:a)
#define sz(a) int((a).size())
#define all(c) (c).begin(),(c).end()
#define frv(i,c) for(auto i = c.begin(); i != c.end(); i++)

void solve()
{
	int n;
	cin >> n;
	int a[n][3];
	fr(i, 0, n)
	{
		cin >> a[i][0] >> a[i][1] >> a[i][2];
	}
	int d[n][3];
	memset(d,  0, sizeof(d));
	d[0][0] = a[0][0];
	d[0][1] = a[0][1];
	d[0][2] = a[0][2];
	fr(i, 1, n)
	{
		fr(j, 0, 3)
		{
			int x = 0;
			fr(k, 0, 3)
			{
				if (k != j)
				{
					x = max(x, d[i - 1][k]);
				}
			}
			d[i][j] = a[i][j] + x;

		}
	}
	int x = 0;
	fr(i, 0, 3)
	{
		x = max(x, d[n - 1][i]);
	}
	cout << x << endl;


}


int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen ("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	//cin>>t;
	t = 1;
	while (t--)
	{
		solve();
	}


	return 0;
}

Measured memory_bytes: 5976
import java.util.*;

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

        int N = sc.nextInt();
        String[] s = new String[N];
        int[] ns = new int[N];

        for(int i=0; i<N; i++){
            s[i] = sc.next();
        }
        for(int i=0; i<N; i++){
            for(int j=0; j<N; j++){
                if(s[i].equals(s[j])){
                    ns[i] += 1;
                }
            }
        }

        int M = sc.nextInt();
        String[] t = new String[M];
        int[] nt = new int[M];

        for(int i=0; i<M; i++){
            t[i] = sc.next();
        }
        for(int i=0; i<M; i++){    
            for(int j=0; j<M; j++){
                if(t[i].equals(t[j])){
                    nt[i] += 1;
                }
            }
        }

        int max = -100;
        int x = 0;
        for(int i=0; i<N; i++){
            for(int j=0; j<M; j++){
                if(s[i].equals(t[j])){
                    max = Math.max(max, ns[i]-nt[j]);
                }
                else{
                    x += 1;                }
            }
            if(x==M){
                max = Math.max(max, ns[i]);
            }
            x = 0;
        }
        if(max>=0){
            System.out.println(max);
        }
        else{
            System.out.println(0);
        }
    } 
}

Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <set>

using ll = long long;

using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    set<int> s{a, b, c};
    cout << (s.size() == 2 ? "Yes" : "No") << '\n';
    return 0;
}

Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))
ans = []
pos, neg = 0, 0
for i in range(n):
    if i % 2 == 0:
        pos += A[i]
    else:
        neg += A[i]

ans.append(pos - neg)
for i in range(1, n):
    temp = pos
    pos = neg + A[i-1]
    neg = temp - A[i-1]
    ans.append(pos - neg)
print(*ans)

Measured memory_bytes: 14092
#include<stdio.h>
int main(){
	int x;
    int y;
    int a;
    for(;;){
        scanf("%d%d", &x, &y);
		if(x == 0 && y == 0) {
			break;	
	}
    if(y < x){
        printf("%d %d\n", y, x);
    }
	else{
        printf("%d %d\n", x, y);
    }
    }
    return 0;
}


Measured memory_bytes: 1976
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

ll n, m, q;
Vec a, b, c, d;

ll dfs(Vec x, ll r){
	//co(x);
	ll res = 0;
	rep(i, q){
		if(x[b[i]] - x[a[i]] == c[i]) res += d[i];
	}

	rep(i, r) if((i == n - 1 || x[i] < x[i + 1]) && x[i] < m){
		x[i]++;
		chmax(res, dfs(x, i + 1));
		x[i]--;
	}
	return res;
}

int main(void){
	cin >> n >> m >> q;
	a.resize(q);
	b.resize(q);
	c.resize(q);
	d.resize(q);
	rep(i, q) cin >> a[i] >> b[i] >> c[i] >> d[i];
	rep(i, q) a[i]--, b[i]--;

	Vec x(n, 1);
	ll ans = dfs(x, n);
	co(ans);

	return 0;
}


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

int main(){
    int N;
    cin >> N;
    int a[N];
    for(int i = 0; i < N; ++i){
        cin >> a[i];
    }
    vector<int> a_result;
    a_result.assign(&a[0], &a[N]);
    sort(a_result.begin(), a_result.end());
    reverse(a_result.begin(), a_result.end());
    bool flag = true;
    int point_Alice= 0, point_Bob = 0;
    for(int i = 0; i < a_result.size(); ++i){
        if(flag == true){
            point_Alice += a_result.at(i);
            flag = false;
        }else{
            point_Bob += a_result.at(i);
            flag = true;
        }
    }
    cout << point_Alice - point_Bob << endl;
}



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

namespace AC {
#define ll long long
#define PLL pair<ll, ll>
#define PDD pair<double, double>
#define PDPLL pair<double, PLL>
#define PLPLL pair<ll, PLL>
#define pb push_back
#define fi first
#define se second
#define ls rt << 1
#define rs rt << 1 | 1

    const ll N = 1e5 + 66;

    ll BUGS = 1;

    inline ll read(){
        ll x = 0;    bool flag = 1;   char ch = getchar();
        while(ch < '0' || ch > '9') { if(ch == '-') flag = 0; ch = getchar(); }
        while(ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + ch - '0'; ch = getchar(); }
        if(flag) return x;  return (~(x - 1));
    }

    inline void read(ll arr[], ll s, ll e) { for(ll i = s; i <= e; ++i) arr[i] = read(); }

    inline void write(ll x){
        if(x < 0) { x = ~(x - 1); putchar('-'); }
        if(x > 9) write(x / 10); putchar(x % 10 + '0');
    }

    inline void print(ll x) { write(x); puts(""); }

    inline void print(ll arr[], ll s, ll e) {
        for(ll i = s; i <= e - 1; ++i) write(arr[i]), putchar(' ');
        write(arr[e]); puts("");
    }

    inline ll max3(ll a, ll b, ll c) { return max(a, max(b, c)); }

    inline ll min3(ll a, ll b, ll c) { return min(a, min(b, c)); }

    inline void debugNum(ll num, string ss) { cout << "BUGS" << BUGS++ << " : " << ss << " : " << num << endl; }

    inline void debugArr(ll arr[], ll s, ll e, string ss) {
        cout << "BUGS" << BUGS++ << " : " << ss << " : " << endl;
        for(ll i = s; i <= e; ++i) cout << "i : " << i << " val : " << arr[i] << endl;
    }

    inline void IO() {
        //ios::sync_with_stdio(false), cout.tie(0), cin.tie(0);
        //cout << setiosflags(ios::fixed) << setprecision(1); //保留小数点后1位
        //cout << setprecision(1); //保留1位有效数字
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    }
}using namespace AC;

ll n;

int main() {
    //IO();
    while(~scanf("%lld", &n)) {
        vector<char> ans;
        while(n) {
            ll mod = n % 26;
            if(mod == 0) mod = 26;
            n /= 26;
            if(mod == 26) n--;
            ans.pb('a' + mod - 1);
        }
        reverse(ans.begin(), ans.end());
        for(auto it : ans) cout << it;
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
int N, W, w[100];
long long v[100], dp[100][100001];
int main(){
    scanf("%d%d", &N, &W);
    for(int i=0; i<N; i++) scanf("%d%d", w+i, v+i);
    for(int i=0; i<N; i++){
        for(int j=0; j<=W; j++){
            dp[i][j] = max(i!=0 ? dp[i-1][j] : 0LL, j>=w[i] ? (i!=0 ? dp[i-1][j-w[i]] : 0LL)+v[i] : 0LL);
        }
    }
    long long ans = 0;
    for(int i=0; i<=W; i++) ans = max(ans, dp[N-1][i]);
    printf("%lld\n", ans);
}

Measured memory_bytes: 78464
import java.util.*;
public class Main {

	public static void main(String[] args) {
		int m, f, r;
		Scanner sc = new Scanner(System.in);
		while(true){
			m = sc.nextInt();
			f = sc.nextInt();
			r = sc.nextInt();
			if(m == -1 && f == -1 && r == -1)
				break;
			else if(m == -1 || f == -1)
				System.out.println("F");
			else if(m + f >= 80)
				System.out.println("A");
			else if(m + f >= 65)
				System.out.println("B");
			else if(m + f >= 50)
				System.out.println("C");
			else if(m + f >= 30){
				if(r >= 50)
					System.out.println("C");
				else
					System.out.println("D");
			}
			else
				System.out.println("F");
		}
	}

}

Measured memory_bytes: 19232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    string s[n];
    rep(i, 0, n) cin >> s[i];

    string ans;
    for (char c = 'a'; c <= 'z'; c++) {
        int mn = 100;
        rep(i, 0, n) {
            int cnt = 0;
            rep(j, 0, (int)s[i].size()) {
                if (s[i][j] == c) cnt++;
            }
            mn = min(mn, cnt);
        }
        rep(i, 0, mn) ans += c;
    }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,ans=0;cin>>n;
  string s;
  map<string,ll> mp;
  rep(i,n) {
    cin>>s;sort(ALL(s));
    mp[s]++;
  }
  for(auto p:mp) ans+=(p.second-1)*p.second/2;
  print(ans);
  return 0;
}

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

int main(){
    ll a, b, k;
    cin >> a >> b >> k;

    if(k <= a) cout << a - k << " " << b << endl;
    else if(k <= a + b) cout << 0 << " " << b - (k - a) << endl;
    else cout << 0 << " " << 0 << endl;
   return 0;
}

Measured memory_bytes: 3580
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    int N, X;
    cin >> N >> X;

    int cur = 0;
    int ans = 1;
    rep(i, N) {
        int l; cin >> l;
        cur += l;
        if (cur <= X) ++ans;
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
ab = []
for n in range(N):
    a,b = map(int,input().split())
    ab.append((a,b))
ab.sort()
coin = 0
cnt = 0
for n in range(N):
    cnt += ab[n][1]
    coin += ab[n][1] * ab[n][0]
    if cnt >= M:
        coin -= (cnt - M) * ab[n][0]
        print(coin)
        exit()

Measured memory_bytes: 16908
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n,p=map(int,input().split())
A=list(map(int, input().split()))
AA = [0]*n
for i in range(n):
    if A[i]%2:
        AA[i]=1
sumA = sum(AA)
res1 = 0
for i in range(p,sumA+1,2):
    res1 += comb(sumA,i)
res0 = 2**(n-sumA)

print(res1*res0)


Measured memory_bytes: 9128
N,L = map(int,input().split())
A = list(map(int,input().split()))

#(方針)ロープの和がある2か所でL以上ならPossible,それ以外ならImposible
#→Possibleな理由はその2か所以外から1つずつほどいていけば必ずL以上の部分ができるから
#→端からほどくとわかりやすい(?)
#→両端から行かないとL以上の部分が存在しなくなることがある

judge = 0
p1,p2 = -1,-1 #2か所で和がL以上になるところ
for i in range(N):
  if(i != N-1):
    if(A[i]+A[i+1] >= L):
      judge = 1
      p1,p2 = i,i+1
      break
point = p1+1 #p1とp2の結び目(index→問題文の数)

if(judge == 0): print('Impossible')
else:
 print('Possible')
 for i in range(1,N):
  if(i == point): break
  else: print(i)
 for i in range(1,N):
  j = N-i
  if(j == point): break
  else: print(j) 
 print(point)     

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

int main() {
    long long i,j,n, ans = 0, cnt,start, sofar, sum;
    scanf("%lld", &n);
    vector<long long> arr(n, 0);
    for(i = 0; i < n; i++){
        scanf("%lld", &arr[i]);
    }
    cnt = 1;
    start = 0;
    sofar = arr[0];
    sum = arr[0];
    if(n)
        ans++;
    for(i = 1; i < n; i++){
        while(start < i && (sofar ^ arr[i]) != (sum + arr[i])){
            // printf("    In %lld %lld %lld\n", i, sofar, sum);
            cnt--;
            sofar ^= arr[start];
            sum -= arr[start];
            start++;
        }
        cnt++;
        sofar ^= arr[i];
        sum += arr[i];
        ans += cnt;
        // printf("%lld %lld %lld\n", i, start, cnt);
    }
    printf("%lld", ans);
	return 0;
}


Measured memory_bytes: 1792
<?php
// D
class UnionFind
{
    private $par; // par[$i]:$iの親 自分が根の場合は自身のindexとなる
    private $size;

    function __construct($n)
    {
        for ($i = 0; $i < $n; $i++) {
            $this->par[$i] = $i; // 最初は全てが根
            $this->size[$i] = 1;
        }
    }

    function root($x)
    { // 根を返す
        if ($this->par[$x] === $x) return $x; // 根の場合
        return $this->par[$x] = $this->root($this->par[$x]); // 全ての枝の親を根にしながら再帰処理
    }

    function unite($x, $y)
    { // $xと$yの木を併合
        $ix = $this->root($x);
        $iy = $this->root($y);
        if ($ix === $iy) return;
        if ($this->size[$ix] < $this->size[$iy]) list($ix, $iy) = [$iy, $ix];
        $this->size[$ix] += $this->size[$iy];
        $this->par[$iy] = $ix; // $yの根を$xの根に付ける
    }

    function isSame($x, $y)
    { // $xと$yの根が同じか
        return $this->root($x) === $this->root($y);
    }

    function size($x)
    {
        return $this->size[$this->root($x)];
    }
}

fscanf(STDIN, '%d %d', $n, $m);
$p = array_map('intval', explode(' ', trim(fgets(STDIN))));

$tree = new UnionFind($n);

for ($i  = 0; $i < $m; $i++) {
    fscanf(STDIN, '%d %d', $x, $y);
    $x--;
    $y--; // 0 ~ $n-1に合わせる
    $tree->unite($x, $y);
}

$cnt = 0;
for ($i = 0; $i < $n; $i++) {
    if ($i === $p[$i] - 1 || $tree->isSame($i, $p[$i] - 1)) $cnt++;
}

echo $cnt . PHP_EOL;

Measured memory_bytes: 20980
# C - Vacation AC
import sys
sys.setrecursionlimit(10**6)
N = int(input())
A = []
for _ in range(N):
    a,b,c = map(int,input().split())
    A.append((a,b,c))

# 無限大の値
INF = 10**10

# DP テーブル
dp = [[0]*3 for _ in range(100010)]

# DP テーブル全体を初期化
for i in range(5):
    for j in range(3):
        dp[i][j] = 0# 最大化問題

def rec(v):
    # v-1 日目の活動 (本当は v)
    for w in range(3):
        
        if dp[v][w] > 0:
       
            return dp[v]
        if v == 0:
            dp[v][w] = 0
         
            return dp[v]
        res = 0
        # v 日目の活動 (本当は v-1)
        for k in range(3):
            if w == k:
               
                continue
            res = max(res,rec(v-1)[k] + A[v-1][w]) # v-1日の活動のところに記録している？
            dp[v][w] = res # ここで kを記録しているのに w を呼び出していた
            
    return dp[v]

rec(N)
ans = max(dp[N])
print(ans)
# w がずっと 0
# w と k の扱いが逆

Measured memory_bytes: 132916
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 998244353;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };

int r, g, b,n;
ll d[3001][3];
ll go(int N, int c)
{
	if (c == 3)return 0;
	if (N == n)return 1;
	if (N > n)return 0;
	ll &ret = d[N][c];
	if (ret != -1)return ret;
	ret = 0;
	ret += go(N, c + 1);
	if (c == 0)ret += go(N + r, c);
	if (c == 1)ret += go(N + g, c);
	if (c == 2)ret += go(N + b, c);
	return ret;
}
int main() {
	MEM_1(d);
	scanf("%d%d%d%d", &r, &g, &b,&n);
	printf("%lld", go(0, 0));
}

Measured memory_bytes: 512
//#include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

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


    int a, b;

    cin >> a >> b;

    int x = a - b * 2;

    if(x < 0) {
        x = 0;
    }

    cout << x << endl;
}

Measured memory_bytes: 256
def main():
    import math
    import collections
    N = int(input())

    mod = 10**9+7
    AB = [tuple(map(int, input().split())) for i in range(N)]

    d = collections.defaultdict(set)
    i = 0
    ans2 = 0
    for a, b in AB:
        if a == 0 and b == 0:
            N -= 1
            ans2 += 1
            continue
        g = math.gcd(a, b)
        if g != 0:
            a = a // g
            b = b // g

        d[(a, b)].add(i)
        i += 1

    ans = 0
    r = set()

    dd = [1]
    for i in range(1, N+1):
        dd.append(dd[i-1]*2 % mod)

    r = set()
    ans = 1
    for a, b in d:
        if (a, b) in r:
            continue
        s1 = d[(a, b)]
        if (-a, -b) in d:
            s1 |= d[(-a, -b)]
        l1 = len(s1)
        r.add((-a, -b))
        if l1:
            s2 = set()
            if (-b, a) in d:
                s2 |= d[(-b, a)]
            if (b, -a) in d:
                s2 |= d[(b, -a)]
            s2 -= s1
            l2 = len(s2)
            if l2:
                ans *= dd[l1] + dd[l2] - 1
                N -= l1 + l2
                ans %= mod
                r.add((-b, a))
                r.add((b, -a))
            else:
                continue
    if N:
        ans *= dd[N]
    ans += ans2
    ans -= 1
    print(ans % mod)


main()


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

int main(){
    int n;
    cin >> n;
    vector<int> L(n);
    for(int i=0; i<n; i++){
        cin >> L.at(i);
    }
    sort(L.begin(), L.end());
    int ans=0;
    for(int i=0; i<n-1; i++){
        for(int j=i+1; j<n; j++){
            int sum = L.at(i) + L.at(j);
            int l = j;
            int r = n;
            while(l+1<r){
                int mid = (l+r)/2;
                if(sum > L.at(mid)){
                    l=mid;
                }
                else r=mid;
            }
            ans += (l-j);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
      int d; long long int g;
        cin >> d >> g;
        int p[d]; int c[d];
        for(int i=0;i<d;i++){
          cin >> p[i]>> c[i];
        }
        long long res=1<<29;
      for(int i=0;i<(1<<d);i++){//2^d回のループ(d桁の2進数全列挙)
        long long int sum=0;//得点
        long long int num=0;//解いた数
        for(int j=0;j<d;j++){//(j+1)*100点の問題を全部解く
            if(i&(1<<j)) sum+=c[j]+p[j]*100*(j+1),num+=p[j];
            //iのj-1桁目が1であれば全完予定にする
        }//全完問題を決めたら
        if(sum>=g) res=min(res,num);//全完だけでsumがgを超えてたらresを更新
        else{//sumがgを超えてないとき
          for(int j=d-1;j>=0;j--){//点数の高い問題から解いていく
            if(i&(1<<j)) continue;//全完する予定の問題は飛ばす
            for(int k=0;k<p[j];k++){//(j+1)*100点問題の数分だけ回す
              if(sum>=g) break;//sumがg以上なら抜ける
              sum+=100*(j+1);//sumに空きがあるなら1問ずつ加える
              num++;//解答数を1増やす
            }
          }
          res=min(res,num);//sumがgを超えたら解答数の更新
        }
      }
      cout <<res<<endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"

	"github.com/emirpasic/gods/maps/treemap"
)

func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var n, k int
	fmt.Fscan(r, &n, &k)

	treeMap := treemap.NewWithIntComparator()

	var a, b int
	for i := 0; i < n; i++ {
		fmt.Fscan(r, &a, &b)
		old, exist := treeMap.Get(a)
		if exist {
			b += old.(int)
		}
		treeMap.Put(a, b)
	}

	var result int
	it := treeMap.Iterator()
	for it.Next() {
		k -= it.Value().(int)
		if k <= 0 {
			result = it.Key().(int)
			break
		}
	}

	fmt.Fprintln(w, result)

}


Measured memory_bytes: 9652
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            int iN = int.Parse(sS[0]);
            int iD = int.Parse(sS[1]);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            int iOut = 0;
            while (true)
            {
                iN -= iD * 2 + 1;
                iOut += 1;
                if (iN <= 0) { break; }
            }

            // 出力
            System.Console.WriteLine("{0}", iOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 13268
# -*- coding: UTF-8 -*-

n = int(input())
l = []

for i in range(n):
    l.append("".join(sorted(str(input()))))

l.sort()

p = 0
s = 1
f = 0

for i in range(n-1):
    if l[i] == l[i+1] and i != n-2:
        s += 1
        f = 1

    elif l[i] != l[i+1] and f == 1:
        f = 0
        p += int(s * (s-1) / 2)
        s = 1

    elif l[i] == l[i+1] and i == n-2:
        s += 1
        f = 0
        p += int(s * (s-1) / 2)


print(p)


Measured memory_bytes: 10640
n = input()
k = int(input())
l = len(n)
dp = [[[0] * (k + 1) for j in range(2)] for i in range(l + 1)]
dp[0][0][0] = 1
for i in range(l):
    for j in range(2):
        for o in range(k + 1):
            for m in range(10):
                if not j and m > int(n[i]):
                    continue
                f = j or m < int(n[i])
                o2 = o + (m != 0)
                if o2 > k:
                    continue
                dp[i + 1][f][o2] += dp[i][j][o]
print(dp[-1][0][k] + dp[-1][1][k])

Measured memory_bytes: 9152
N = int(input())
usa = list(map(int, input().split()))
flag = [0 for x in range(N)]
count = 0
for i, ai in enumerate(usa):
    if(flag[i]):
        continue
    if(usa[ai-1]-1 == i):
        count+=1
        flag[ai - 1] = 1

print (count)


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

using namespace std;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVS vector<vector<string>>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)
typedef long long ll;
const int  INF = 2147483647;
const ll INFL = 9223372036854775807;
const ll mod = 1000000007;




int main() {
	int n;
	cin >> n;
	VI v(n);
	REP(i, n) {
		int a;
		cin >> a;
		v[a - 1] = i;
	}
	int ans = 1, res = 1;
	FOR(i, 1, n) {
		if (v[i] > v[i - 1]) {
			res++;
			ans = max(ans, res);
		}
		else res = 1;
	}
	cout << n - ans << endl;
	return 0;
}

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

int main()
{

        int A, B;
        cin >> A >> B;

        int eight = A / 0.08;
        int ten = B / 0.1;

        for (int i = 1; i < 1250; ++i) {

                int e = i * 0.08;
                int t = i * 0.1;

                if (e == A && t == B) {
                        cout << i << endl;
                        return 0;
                }
        }
        cout << -1 << endl;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_N = 105;
int w[MAX_N];
int v[MAX_N];

const int MAX_W = 112345;
ll dp[MAX_W];

int main2() {
  int N = nextInt();
  int W = nextInt();
  REP(i, N) {
    w[i] = nextInt();
    v[i] = nextInt();
  }
  const int INF = 1001001001;
  REP(i, MAX_W) dp[i] = -INF;
  dp[0] = 0;
  REP(i, N) {
    for (int ww = W; ww - w[i] >= 0; ww--) {
      chmax(dp[ww], dp[ww - w[i]] + v[i]);
    }
  }
  ll ans = 0;
  REP(ww, W+1) chmax(ans, dp[ww]);
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 1152
#include <stdio.h>
#include <string.h>

#define M 1000000
#define L 14

char H[M][L];

int getChar(char ch) {
  if(ch == 'A') return 1;
  else if(ch == 'C') return 2;
  else if(ch == 'G') return 3;
  else if(ch == 'T') return 4;
}

long long getkey(char str[]) {
  long long sum = 0, p = 1, i;
  for(i = 0; i < strlen(str); i++) {
    sum = sum + p * (getChar(str[i]));
    p = p * 5;
  }
  return sum;
}

int h1(int key) {
  key = key % M;
  return key;
}
int h2(int key) {
  key = 1 + key % (M - 1);
  return key;
}

int find(char str[]) {
  int key, nextkey, i = 0;
  key = h1(getkey(str));
  nextkey = h2(getkey(str));

  while(H[key][0] != NULL) {
    if(strcmp(H[key], str) == 0) {
      return 1;
    }
    else {
      key = key + nextkey;
      if(key > M) {
	key = key - M;
      }
    }
    i++;
    if(i == M) {
      break;
    }
  }
  return 0;
}

int insert(char str[]) {
  int key, nextkey, i = 0;
  key = h1(getkey(str));
  nextkey = h2(getkey(str));

  while(1) {
    if(H[key][0] == NULL || strcmp(H[key], str) == 0) {
      strcpy(H[key], str);
      break;
    }
    else {
      key = key + nextkey;
      if(key > M) {
	key = key - M;
      }
    }
    i++;
    if(i == M) {
      break;
    }
  }
  return 1;
}

main() {
  int i, n, h;
  char str[L], com[9];

  scanf("%d", &n);

  for(i = 0; i < n; i++) {
    scanf("%s %s", com, str);

    if(com[0] == 'i') {
      insert(str);
    }
    else {
      if(find(str)) {
	printf("yes\n");
      }
      else {
	printf("no\n");
      }
    }
  }
  return 0;
}

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

using namespace std;

#define ll long long

void solve() {
	int a, b, c;
	cin >> a >> b >> c;
	a -= c;
	cout << a/(b+c);
}

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

	int t = 1, i = 1;
	//cin >> t;
	while(t--) {
		//cout << "Case #" << i << ": ";
		solve();
		//i++;
	}
	return 0;
}



Measured memory_bytes: 3652