akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
 
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
 
constexpr ll MOD = 1000000007;
 
#ifndef ONLINE_JUDGE
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
#else
#define print(...)
#endif


int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    ll n,ans;
    
    cin >> n;

    ans = 1000-(n%1000);
    if(ans == 1000)
        ans = 0;
    
    cout << ans << endl;
 
    return 0;
}



Measured memory_bytes: 3652
//#define TIMER_
#include <bits/stdc++.h>
using namespace std;
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define ALL(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using ll = long long;
using ull = unsigned long long;
int R, C;
int g[30][30];
int dist[30][30];
bool visit[30][30];
int dir[5] = { -1, 0, 1, 0, -1};
pair<int,int> st;

int bfs() {
  int maxi = 0;
  queue<pair<int,int>>q;
  q.push(st);
  memset(visit, false, sizeof(visit));
  memset(dist, false, sizeof(dist));
  while(!q.empty()) {
    int n = q.size();
    for (int i = 0; i < n;i++) {
      auto top = q.front();
      q.pop();
      int r = top.first, c = top.second;
      visit[r][c] = true;
      for (int d = 0; d < 4; d++) {
        int dr = top.first + dir[d];
        int dc = top.second + dir[d + 1];
        if (dr < 0 || dr >= R || dc < 0 || dc >= C || visit[dr][dc] || g[dr][dc] == '#') continue;
        dist[dr][dc] = dist[r][c] + 1;
        visit[dr][dc] = true;
        if (dist[dr][dc] > maxi) {
          maxi = dist[dr][dc];
          st = {dr,dc};
        }
        q.push({dr,dc});
      }
    }
  }
  return maxi;
}

int main() {
  fastio;
  cin >> R >> C;
  memset(g, 0, sizeof(g));
  for (int r = 0; r < R; r++) {
    string row;
    cin >> row;
    for (int c = 0; c < C; c++) {
      g[r][c] = row[c];
      if (g[r][c] == '.') st = {r, c};
    }
  }
  int maxi = 0;
  for (int r = 0; r < R; r++) {
    for (int c = 0; c < C; c++) {
      if (g[r][c] == '.') {
        st = {r,c};
        maxi = max(maxi, bfs());
      }
    }
  }

  cout << maxi << endl;
  
  #ifdef TIMER_
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  #endif
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define N 200000
int n, k;
int cnt[N+5];
vector<pair<int, int>> v;
int in;
int main(int argc, char *argv[])
{
    while(cin >> n >> k && (n||k))
    {
        memset(cnt, 0, sizeof(cnt));
        v.clear();
        //
        for(int i = 0; i < n && cin >> in; i++)
            cnt[in]++;
        for(int i = 0; i <= N; i++)
            if(cnt[i])
                v.push_back(make_pair(cnt[i], i));
        sort(v.begin(), v.end());
        int d = v.size() - k, ans = 0;
        for(int i = 0; i < d; i++)
        {
            ans += v[i].first;
        }
        printf("%d\n", ans);
    }
}

Measured memory_bytes: 5872
#include <array>
#include <iostream>
#include <vector>

int main()
{
    int N, T, A;
    std::cin >> N;
    std::cin >> T >> A;
    std::array<int, 2000> height;
    std::cin >> height.at(0);
    int ans = 0;
    double min = std::abs(T - 0.006 * height.at(0) - A);
    double tmp;
    for (int i = 1; i < N; i++) {
        std::cin >> height.at(i);
        tmp = std::abs(T - 0.006 * height.at(i) - A);
        if (tmp < min) {
            ans = i;
            min = tmp;
        }
    }
    std::cout << ans + 1 << std::endl;
}

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

int main(void) {
    long n;
    cin >> n;
    vector<long> a(n-1);
    for(auto &e: a) cin >> e, e--;

    vector<set<long>> lose(n);
    for(long i=0; i<n-1; i++)
        lose[a[i]].insert(i+1);

    {
        auto dfs = [&](auto dfs, long cur) -> long {
            vector<long> v;
            for(auto &w: lose[cur])
                v.push_back(dfs(dfs, w) + 1);
            sort(v.begin(), v.end(), greater<>());

            long r = 0;
            for(long i=0; i<v.size(); i++)
                r = max(r, v[i] + i);
            return r;
        };
        cout << dfs(dfs, 0) << endl;
    }
}


Measured memory_bytes: 16256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define crep(i) for(char i='a';i<='z';i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define ALL(x) (x).begin(),(x).end()
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

map<pair<char,char>,ll> M;
map<char,ll> H;

int main(){
    ll N;
    string S;
    cin >> N;
    cin >> S;
    ll K=0,na;
    rep(i,N-1){
        M[make_pair(S[i],S[i+1])]++;
        H[S[i]]++;
    }
    H[S[N-1]]++;
    rep(i,N-1){
        if(i>=N-(K+1)*2){
            break;
        }
        if(M[make_pair(S[i],S[i+1])]<2){
            if(H[S[i]]>1){
                K=(max(1LL,K));
            }
            continue;
        }
        for(ll j=i+max(1LL,K);j<N-K;j++){
            na=0;
            rep(k,min(N-j,j-i)){
                if(S[i+k]==S[j+k]){
                    na++;
                }
                else{
                    break;
                }
            }
            K=max(K,na);
        }
    }
    cout << K << endl;
}

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

#define int long long
#define pii pair<int, int>
#define pb push_back
#define vi vector<int>

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n;
    cin >> n;
    vi a(n + 1);
    for(int x = 1; x <= 1e2; x++) {
        for(int y = 1; y <= 1e2; y++) {
            for(int z = 1; z <= 1e2; z++) {
                int val = x * x + y * y + z * z + x * y + y * z + z * x;
                if(val <= n) {
                    a[val]++;
                }
            }
        }
    }
    for(int i = 1; i <= n; i++) {
        cout << a[i] << endl;
    }

    return 0;
}



Measured memory_bytes: 3692
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

int main(){
    int a,b;    cin>>a>>b;
    int max=a+b;
    if(max<a-b) max=a-b;
    if(max<a*b) max=a*b;
    cout<<max<<endl;
}

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

int main()
{
    string s;

    //getchar();
    while(getline(cin, s))
    {
        //getchar();
        int count = 0, findd, finddd;

        for(int i=0; i<s.size(); i++)
        {
            if(s[i]=='A')
            {
                findd=i;
                break;
            }
        }

        for(int i=s.size()-1; i>findd; i--)
        {
            if(s[i]=='Z')
            {
                finddd = i;
                break;
            }
        }

        for(int i=findd; i<=finddd; i++)
        {
            count++;
        }

        /*for(int i=findd; i<s.size(); i++)
        {
            if(s[i]=='Z')
            {
                finddd=i;
                break;
            }
            count++;
        }

        int i = finddd;

        while(s[i]=='Z')
        {
            count++;
            i++;
        }*/

        printf("%d\n", count);
    }

    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD = 1000000007;
ll cnt =0,ans=0;
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理、これも呼ぶ

ll powmod(ll x,ll y){
     ll res = 1;
     for(ll i = 0;i<y;i++){
          res=res*x%MOD;
     }
     return res;
}
int main (){
     ll n;     cin >> n;
     ans = powmod(10,n) - 2*powmod(9,n) + powmod(8,n);
     ans %= MOD;
     ans = (ans+MOD)%MOD;
     cout << ans << endl; 
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define ll long long
#define MAX 1000005
#define MOD (ll)(1e9+7)
#define INF INT32_MAX
#define INFL INT64_MAX
using namespace std;

int gcd(int a, int b, int &x, int &y)	{
	if(b==0)	{
		x=1;
		y=0;
		return a;
	}
	int x1,y1;
	int g = gcd(b,a%b,x1,y1);
	x=y1;
	y=x1-(a/b)*y1;
	return g;
}

void solve()	{
	int a,b,c;
	cin >> a >> b >> c;
	int x,y;
	int g = gcd(a,b,x,y);
	if(c%g==0)	cout << "YES\n";
	else cout << "NO\n";
}

int main()	
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin >> t;
	for(int i=1; i<=t; i++)	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

int main(void)
{
	string r, g, b;
	cin >> r >> g >> b;

	string n = r + g + b;
	string ret;
	if(stoi(n)%4 == 0)
		ret = "YES";
	else
		ret = "NO";

	cout << ret << endl;

	return 0;
}


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

using namespace std;

#define PI 3.14159265358979323846264338327950L

int main(void){

    string S;
    int x=0;

    cin>>S;

    for(int i=0;i<S.size();i++){
        x=x+S[i]-'0';
        x=x%9;
    }

    if(x%9==0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }


    return 0;
}



Measured memory_bytes: 3748
//Allah vorosha
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pb push_back
#define pi acos(-1.0)
#define mod 1000000007

int main() {
    //std::ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    //setbuf(stdout, NULL); //for interactive problem
    ll a,b,c,d,ans;
    scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
    ans=max(a*c,a*d);
    ans=max(ans,b*c);
    ans=max(ans,b*d);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 3824
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const ll inf = 999999999999999999;
const ld pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct S {//辺の情報を入れる変数
	int from, to, cost;
};
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
	int n,ans=1;
	string s1,s2;
	cin>>n>>s1>>s2;
	for(int i=0;i<n;i++){
		if(i==0){
			if(s1[i]==s2[i]) {
				ans*=3;
			}
			else{
				 ans*=6,i++;
			 }
		}
		else{
			if(s1[i]==s2[i]){
				if(s1[i-1]==s2[i-1]) {
					ans*=2;
				}
			}
			else{
				if(s1[i-1]!=s2[i-1]){
					ans*=3;
				}
				else{
					ans*=2;
				}
				i++;
			}
		}
		ans%=1000000007;
	}
	cout<<ans<<endl;
	getchar(); getchar();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>	
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ld long double
#define pii pair <int, int>
#define sz(a) (int)(a.size()) 
#define resize(v) v.resize(unique(all(v)) - v.begin()); 
#define all(a) a.begin(), a.end()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++)

// random_device rd; mt19937 g(rd());    
                                        	
using namespace std;
using namespace __gnu_pbds;
 
void Fast_Read_Out()
{
    ios_base::sync_with_stdio(0);
    cin.tie(), cout.tie();
}
 
void Random()
{
    unsigned int seed;                                                                        
    asm("rdtsc" : "=A" (seed));
    srand(seed);        
}
 
unsigned int Time()
{
     unsigned int time = clock() / 1000.00;                           
     return time;
}

template <typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>; 
 
const int mod = (int)1e9 + 7;
const int N = (int)4e6 + 123;

int fact[N];

int mult(int a, int b)
{
	return 1ll * a * b % mod;
}

int add(int a, int b)
{
	a += b;
	if(a < 0) a += mod;
	if(a >= mod) a %= mod;
	return a;
}

int Binpow(int a, int n)
{
	if(!n) return 1;
	if(n & 1) return mult(Binpow(a, n - 1), a);
	else
	{
		int b = Binpow(a, n / 2);
		return mult(b, b);
	}
}

int C(int n, int k)       
{
	if(k > n) return 0;
	int up = fact[n];
	int down = mult(fact[k], fact[n - k]);
	return mult(up, Binpow(down, mod - 2));
}

int r1, r2, c1, c2;

int Get(int n, int k, int z)
{
	int all = C(n + z + 1, z + k);
	int pre = C(n, k - 1);
	return add(all, -pre);
}

int ans;
int what;
 
int main ()
{
	#ifdef JUDGE
		freopen("input.txt", "r", stdin);
//		freopen("output.txt", "w", stdout);
	#endif	
	Fast_Read_Out();
	Random();   
	fact[0] = 1;
	for(int i = 1; i <= 3000000; i++) fact[i] = mult(fact[i - 1], i);
	cin >> r1 >> c1 >> r2 >> c2;
	what = add(add(C(c2 + 2 + r2, c2 + 1), -C(r1 + c2 + 1, c2 + 1)), -add(C(r2 + c1 + 1, c1), -C(r1 + c1, c1)));
	cout << what;
}                                

Measured memory_bytes: 12544
import java.util.Scanner;

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

	String s = scan.next();

	int ans = 0;
	for(int i = 0; i < s.length(); i++){
	    if(s.charAt(i) == '+'){
		ans++;
	    }else if(s.charAt(i) == '-'){
		ans--;
	    }
	}
	System.out.println(ans);
    }
}


Measured memory_bytes: 21844
#include<iostream>
#include<queue>
#include<algorithm>
#include<utility>

using namespace std;

int W,H,N;

bool w[100][100];
int ix,iy,ox,oy;

struct S{
  int y,x,t;
};

int dst(){
  queue<S> que;
  que.push({iy*2,ix*2,0});
  bool p[100][100]={};
  while(!que.empty()){
    S cs=que.front();
    if(cs.y==oy*2&&cs.x==ox*2)return cs.t;
    que.pop();
    if(p[cs.y][cs.x]++)continue;
    for(int i=0;i<4;i++){
      static int d[]={0,1,0,-1,0};
      int ny=cs.y+d[i]*2;
      int nx=cs.x+d[i+1]*2;
      if(0<=ny&&ny<H*2&&0<=nx&&nx<W*2&&!w[cs.y+d[i]][cs.x+d[i+1]]){
	que.push({ny,nx,cs.t+1});
      }
    }
  }
  return 0;
}

int main(){
  cin>>W>>H>>N;
  while(N--){
    int sx,sy,dx,dy;
    cin>>sx>>sy>>dx>>dy;
    if(sx>dx){
      swap(sx,dx);
    }
    if(sy>dy){
      swap(sy,dy);
    }
    if(sx==dx){
      if(sx)
	for(int i=sy;i<dy;i++){
	  w[i*2][sx*2-1]=true;
	}
    }else{
      if(sy)
      for(int i=sx;i<dx;i++){
	w[sy*2-1][i*2]=true;
      }
    }
  }
  cin>>ix>>iy>>ox>>oy; 
  int b=dst();
  int m=0;
  for(int i=0;i<H*2;i++){
    for(int j=0;j<W*2;j++){
      if(!w[i][j]){
	w[i][j]=true;
	m=max(m,dst()-b);
	w[i][j]=false;
      }
    }
  }
  cout<<m<<endl;
}
	  

Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    int n,count=0,ans=0;
    bool flag=false;
    cin >> n;
    vector<bool> v(9,false);
    for(int i=0;i < n;i++){
        int x;
        cin >> x;
        if(x>=3200){
            v.at(8)=true;
            count++;
        }else{
            v.at(x/400) = true;
            flag = true;
        }
    }//input

    for(int j=0;j < 8;j++){
        if(v.at(j)==true){
            ans++;
        }
    }
    if(flag){
        cout << ans << " " << ans+count << endl;
    }else{
        cout << 1 << " " << count << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
//能符合标准的，只可能是RGB！
int main()
{
    long long int n,ans=0,temp;
    string s;
    cin>>n;
    cin>>s;
    int len = n; //长度已知
    int r[4002]={0},g[4002]={0},b[4002]={0};//表示包括这个下标在内的右边这个字母有几个
    for(int i = n-1;i>=0;i--)
    {
        if(s.at(i)=='R')
            r[i]=r[i+1]+1;
        else
            r[i]=r[i+1];
        if(s.at(i)=='G')
            g[i]=g[i+1]+1;
        else
            g[i]=g[i+1];
        if(s.at(i)=='B')
            b[i]=b[i+1]+1;
        else
            b[i]=b[i+1];
    }
    int tempR=0,tempG=0,tempB=0;
    for(int i = 0;i<n-3;i++)
    {
        if(s.at(i)=='R')
            tempR++;
        else if(s.at(i)=='G')
            tempG++;
        else
            tempB++;
        for(int j = i+1;j<n-1;j++)
        {
            int flag=0;
            if(s.at(j)==s.at(i))
                continue;

            if(s.at(j)=='R')
            {
                tempR++;
                flag=1;
            }
            else if(s.at(j)=='G')
            {
                tempG++;
                flag=2;
            }
            else
            {
                tempB++;
                flag=3;
            }
           // cout<<i<<j<<tempR<<tempG<<tempB<<endl;
           //只需要两层就够了哟
            //i和j的情况先开始各自判断
            if(tempR&&tempB)
            {//加上G的数目，除去等差位
                ans+=g[j+1];
                if(j+(j-i)<n)
                {
                    if(s.at(2*j-i)=='G')
                        ans--;
                }
            }
            else if(tempR&&tempG)
            {//加上B的数目，除去等差位
                ans+=b[j+1];
    
                if(j+(j-i)<n)
                {
                    if(s.at(2*j-i)=='B')
                        ans--;
                }
            }
            else //B&&G
            {//加上R的数目，除去等差位
                ans+=r[j+1];
                if(j+(j-i)<n)
                {
                    if(s.at(2*j-i)=='R')
                        ans--;
                }
            }
            if(flag==1)
                tempR=0;
            else if(flag==2)
                tempG=0;
            else
                tempB=0;
            flag=0;
        }
        tempR=0;
        tempG=0;
        tempB=0;
    }
    cout<<ans<<endl;
    return 0;
}






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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const ll mod = 1e9+7;

void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

vector<pii> r[100005];
bool ok =true;

void rec(int s,  int sm , VI& d){
	if(d[s] !=mod){
		if(d[s] != sm) ok=false;
		return;
	}	else d[s] = sm;
	for(auto z: r[s]){
		rec(z.first, sm + z.second, d);
	}
}


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

	int n,m;
	cin >>n >>m;
	rep(i,m){
		int l,rg,d;
		cin >>l >>rg >>d;
		r[l-1].emplace_back(rg-1, d);
		r[rg-1].emplace_back(l-1, -d);
	}
	
	VI d(n+5, mod);
	rep(i,n) if(d[i] == mod){
		//d[i]=0;
		rec(i, 0, d);
	}
	//for(auto x :d) printf("%d, ",x); puts("");
	cout << (ok? "Yes\n":"No\n");
	return 0;
	
}


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

int main(){
  int fo,o,f;
  int kin;
  int cnt = 0;
  
  cin >> fo >> o >> f >> kin;
  
  for(int i = 0; i <= fo; i++){
    for(int j = 0; j <= o; j++){
      for(int k = 0; k <= f; k++){
        if(500*i + 100*j + 50*k == kin) cnt++;
      }
    }
  }
  
  cout << cnt;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
li = [0]+list(map(int,input().split()))

memo = [-1]*(n+1)
start = 1
syuuki = 0
haji = 0

for i in range(k):
    if memo[start] != -1:
        syuuki = i - memo[start]
        haji = memo[start]
        break
    memo[start] = i
    start = li[start]
else:
    print(start)
    exit()

#print(syuuki,haji)
k-=haji
k%=syuuki
k+=haji

start = 1
for kk in range(k):
    start = li[start]
print(start)

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

int main()
{
    long long  a[5];
   long long  n;
    while(cin>>n)
    {

        for(int i=0;i<5;i++)
        {

            cin>>a[i];
        }
        sort(a,a+5);
        if(n<=a[0])
        {

            cout<<5<<endl;
        }
        else
        {   if(n%a[0]==0)
            cout<<n/a[0]+4<<endl;
            else

            cout<<n/a[0]+5<<endl;

        }

    }
    return 0;
}

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

#define int long long
#define ff first
#define ss second
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())
const int MOD=1e9+7;
int powmod(int a,int l, int md){a%=md; int res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;}
int binpow(int a,int l){int res=1;while(l){if(l&1)res=res*a;l/=2;a=a*a;}return res;}
int invmod(int a, int md){return powmod(a,md-2,md);}
typedef long long ll; typedef unsigned long long ull; typedef long double ld;
typedef vector<int> vi; typedef pair<int, int> ii; typedef vector< ii > vii;
#define pb push_back
int __set(int b, int i) {return b|(1LL<<i);} //set ith bit
int __unset(int b, int i) {return b&(~(1UL<<i));}
int __check(int b, int i) {return b&(1LL<<i);} //returns 0 if ith bit is 0
int mulmod(int a, int b, int md) {return (((a%md)*(b%md))%md+md)%md;}
int addmod(int a, int b, int md) {return ((a%md+b%md)%md+md)%md;}
int submod(int a, int b, int md) {return (((a%md-b%md)%md)+md)%md;}
int divmod(int a, int b, int md) {return mulmod(a, powmod(b, md-2, md), md);} //if md is prime;
const ll inf = 0xFFFFFFFFFFFFFFFL; //very large number
// priority_queue<int, vector<int>, greater<int> > pq; //for min priority_queue
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int x,y;
int n;
// int check(int mid, vii& app) {
// 	int cnt0=0,cnt1=0, cnt2=0;
// 	for(int i = 0; i < mid; i++) {
// 		if(app[i].ss==3)
// 			cnt0++;
// 		if(app[i].ss==2)
// 			cnt1++;
// 		if(app[i].ss==1)
// 			cnt2++;
// 	}
// 	// if(cnt1+cnt2+cnt0 >= x+y) return 1;
// 	return 0;
// }
// int bn(int lo, int hi, vii& app) {
// 	if (lo==hi) {
// 		int pos;
// 		if(check(lo,app)) pos=lo;
// 		else pos=lo+1;
// 		int cnt0=0,cnt1=0, cnt2=0;
// 		for(int i = 0; i <= pos; i++) {
// 			if(app[i].ss==2)
// 				cnt1++;
// 		}
// 		int 
// 	}
// 	int mid=(lo+hi)/2;
// 	if(check(mid, app)) return bn(lo,mid,app);
// 	else return bn(mid+1,hi,app);
// }
signed main(void) {
	IOS;
	cin>>x>>y;
	int a,b,c; cin>>a>>b>>c;
	vii app;
	priority_queue<int, vector<int>, greater<int> > pq0;
	priority_queue<int, vector<int>, greater<int> > pq1;
	for(int i = 0; i < a; i++) {
		int d;
		cin>>d;
		app.pb({d,3});
	}
	for(int i = 0; i < b; i++) {
		int d;
		cin>>d;
		app.pb({d,2});
	}
	for(int i = 0; i < c; i++) {
		int d;
		cin>>d;
		app.pb({d,1});
	}
	// int cnt0=0,cnt1=0;
	int del=0;
	n=sz(app);
	sort(all(app), greater<ii>());
	int cnt0=0,cnt1=0,cnt3=0;
	for(int i = 0; i < n; i++) {
		if(cnt0+cnt1+cnt3>=x+y)
			break;
		if(app[i].ss==3) {
			if(cnt0<x) {
				cnt0++;
				del+=app[i].ff;
			}
		} else if(app[i].ss==2) {
			if(cnt1<y) {
				cnt1++;
				del+=app[i].ff;
			}
		} else {
			cnt3++;
			del += app[i].ff;
		}
	}
	cout<<del<<endl;
	return 0;
}

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

using namespace std;
typedef long long ll;

signed main(signed argc, char *argv[]) {
    string S;
    cin >> S;


    for(int i=0; i < S.size(); i++) {
        int cnt = 0;
        for(int j=0; j < S.size(); j++) {
            if(S[i] == S[j]) cnt++;
        }
        if(cnt != 2) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <assert.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <fstream>

using namespace std;

const int MAXN = 100005;

int n;
int a[MAXN];
int MIN = 1e9,MAX;
int cntmin;
int cntmax;

int main()
{
	ios::sync_with_stdio(0);
	cin >> n;
	for (int i = 1;i <= n;i++)
	{
		cin >> a[i];
		MIN = min(MIN,a[i]);
		MAX = max(MAX,a[i]);
	}
	if (MIN == MAX)
	{
		puts((MIN == n - 1 || MIN * 2 <= n) ? "Yes" : "No");
		return 0;
	}
	for (int i = 1;i <= n;i++)	
		if (a[i] == MIN)
			cntmin++;
		else
			cntmax++;
	MAX -= cntmin;
	if (MAX < 0)
	{
		puts("No");
		return 0;
	}
	if (MAX != cntmax - 1 && MAX * 2 > cntmax)
	{
		puts("No");
		return 0;
	}
	if (MAX == cntmax - 1 && cntmin + cntmax - 1 == MIN)
	{
		puts("Yes");
		return 0;
	}
	if (MAX > 0 && MAX * 2 <= cntmax && cntmin + MAX - 1 == MIN)
	{
		puts("Yes");
		return 0;
	}
	puts("No");
	return 0;
}

Measured memory_bytes: 640
N=int(input())
li = list(map(int,input().split()))

x = ""
count = 1

for i in range(N - 1):
  if li[i] == li[i + 1]:
    continue

  if x == "":
    if li[i] < li[i + 1]:
      x = 'UP'
    
    if li[i] > li[i + 1]:
      x = 'DOWN'

  else:
    if x == 'UP' and li[i] > li[i + 1]:
      x = ""
      count += 1
    elif x == 'DOWN' and li[i] < li[i + 1]:
      x = ""
      count += 1

print(count)

Measured memory_bytes: 14224
#include <stdio.h>

int main(void)
{
	int m, a;
	int i;
	int sum[5];
	int max;
	char c;
	
	while (1){
		
		scanf("%d %d", &m, &a);
		
		if (m + a == 0){
			break;
		}
		max = m + a;
		c = 'A';
		
		for (i = 1; i < 5; i++){
			
			scanf("%d %d", &m, &a);
			sum[i] = m + a;
			
			if (max < sum[i]){
				max = sum[i];
				c = 'A' + i;
			}
		}
		printf("%c %d\n", c, max);
	}
	
	return (0);
}

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

int A, B, C, D;

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

    int ans = 0;
    if (A < C) {
        if (D < B) {
            ans = D - C;
        } else {
            ans = B - C;
        }
    } else {
        if (D < B) {
            ans = D - A;
        } else {
            ans = B - A;
        }
    }

    cout << max(ans, 0) << endl;
}

Measured memory_bytes: 256
s, t = raw_input().strip(), raw_input().strip()
n, m = len(s), len(t)

dp = [[0 for i in xrange(m)] for j in xrange(n)]

dp[0][0] = int(s[0] == t[0])

i = 0
for j in xrange(1, m):
    if s[i] == t[j]: dp[i][j] = 1
    else: dp[i][j] = dp[i][j - 1]

j = 0
for i in xrange(1, n):
    if s[i] == t[j]: dp[i][j] = 1
    else: dp[i][j] = dp[i - 1][j]

for i in xrange(1, n):
    for j in xrange(1, m):
        if i == 0 and j == 0: continue
        if s[i] == t[j]:
            dp[i][j] = dp[i - 1][j - 1] + 1
        else:
            dp[i][j] = max(dp[i][j - 1], dp[i - 1][j])

c = [0 for i in xrange(dp[n - 1][m - 1])]

st = len(c) - 1
i, j = n - 1, m - 1
while st >= 0:
    if s[i] == t[j]:
        c[st] = s[i]
        i -= 1
        j -= 1
        st -= 1
    else:
        if i >= 1 and j >= 1:
            if dp[i][j - 1] < dp[i - 1][j]: i -= 1
            else: j -= 1
        else:
            if i >= 1: i -= 1
            else: j -= 1

print ''.join(c)

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

using namespace std;
typedef long long ll;
typedef long double ld;
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)


// Write From This Line
int main()
{
	double r;
	cin >> r;
	double p = 3.1415926535;
	cout << 2 * r * p << endl;
}


Measured memory_bytes: 3788
import sys 
sys.setrecursionlimit(2*100000) 

def dfs(i,pre,n,a,ans):
    if (pre*2 < a[i]): return -1
    ans[i] += a[i]
    if (i >= n):
        return a[i]

    pre = pre*2 - a[i]
    u = dfs(i+1,pre,n,a,ans);
    if (u<0 or pre*2 < u): return -1;
    ans[i] += min(pre, u)
    return min(pre, u) + a[i]



n = int(input())
a = list(map(int,input().split()))

if (n == 0):
    if (a[0] == 1):
        print(1)
    else:
        print(-1)
    exit()

ans = [1] + [0]*n
u = dfs(1,1,n,a,ans)
if (a[0] != 0): u = -1

if (u >= 0):
    print(sum(ans))
else:
    print(-1)


Measured memory_bytes: 759288
n, blue, red = map(int, input().split())

b_r = blue + red

round = int(n/b_r)

if n - (b_r * round) == 0:
  print(blue * round)
else:
  empty = n - (b_r * round)
  if empty < blue:
    print((blue * round) + empty)
  else:
    print((blue * round) + blue)

Measured memory_bytes: 3060
N = gets.to_i
judges = {AC: 0, WA: 0, TLE: 0, RE: 0}
N.times { 
  judges[gets.chomp.to_sym] += 1
}

# (judges.group_by(&:itself).map { |key, value| [key, value.count] }.to_h).each { |key, value| puts "#{key} x #{value}" }

judges.each { |key, value| puts "#{key} x #{value}"}


Measured memory_bytes: 14232
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i, s, n) for(int i=s; i<n; i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;

int main() {
  int X;
  cin >> X;
  if(X==7 || X==5 || X==3) cout << "YES" << endl;
  else cout << "NO" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)

#define rep(i,n) for(int i = 0; i < n; i++)
#define ENDL "\n"
#define print(i) std::cout << (i) << "\n"

#define int long long // at least int64 > 9*10^18
#define all(v) v.begin(), v.end()

const int MOD = 1e9+7;

signed main() {
	int n,k;
	std::cin >> n >> k;
	std::vector<int> states;
	states.reserve(2*(int)std::sqrt(n)+1);
	for(int i=1;i*i<=n;i++) {
		states.emplace_back(i);
		if(i!=n/i) states.emplace_back(n/i);
	}
	std::sort(all(states));
	int state_count = states.size();
	std::vector<int> a;
	std::vector<int> b;
	a.reserve(state_count);
	b.reserve(state_count);
	for(int i=0;i<state_count;i++) a[i] = states[i];
	for(int i=1;i<k;i++) {
		int last = 0;
		for(int j=0;j<state_count;j++) {
			b[j] = (states[j]-last)*a[state_count-1-j]%MOD;
			if(j!=0) b[j] = (b[j]+b[j-1])%MOD;
			last = states[j];
		}
		std::swap(a,b);
	}
	print(a[state_count-1]);
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h> 
using namespace std; 
const int maxx = 200010; 
set<int> graph[maxx]; 
void dfs(int curr, int& cnt, int*  visited, vector<int>& duringdfs) { 
    visited[curr] = 1;  
    ++cnt; 
    duringdfs.push_back(curr); 
    for (auto& child : graph[curr]) { 
        if (visited[child] == 0) { 
            dfs(child, cnt, visited, duringdfs); 
        } 
    } 
} 

void MaximumVisit(int n) { 
    int visited[maxx]; 
    memset(visited, 0, sizeof visited); 
    int ans[maxx]; 
    memset(ans, 0, sizeof ans); 
    vector<int> duringdfs;  
    for (int i = 1; i <= n; ++i) { 
        duringdfs.clear(); 
        int cnt = 0; 
        if (visited[i] == 0) { 
            cnt = 0; 
            dfs(i, cnt, visited, duringdfs); 
        } 
        for (auto& x : duringdfs) { 
            ans[x] = cnt; 
        } 
    }
    int mx=0;
    for (int i = 1; i <= n; ++i) { 
        mx=max(ans[i],mx);
    } 
    cout <<mx<<endl; 
    return; 
} 

int main() 
{ 
    int N,K;
    cin>>N>>K;
    int m=K;
    while(m--){
        int u,v;
        cin>>u>>v;
        graph[u].insert(v);
        graph[v].insert(u);
    }
    MaximumVisit(N); 
    return 0; 
} 

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

using namespace std;

int main() {
    int N;
    cin>>N;
    int found = 0;
    long long res = 0;
    for(int c=0;c<=N;c++) {
        if(c%3!=0&&c%5!=0) {
                res+=c;
                found++;
        }
    }
    cout<<res;
}


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

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

int main(){
	int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  sort(a.begin(), a.end());

  vector<ll> cumsum(n+1, 0);
  for(int i = 0; i < n; ++i){
    cumsum[i+1] = cumsum[i] + a[i];
  }
  sort(cumsum.rbegin(), cumsum.rend());

  ll ans = 1;
  for(int i = 0; i < n; ++i){
    if(2 * cumsum[i+1] >= cumsum[i] - cumsum[i+1]){
      ans++;
    }
    else{
      break;
    }
  }

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



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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define F first
#define S second
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
const int MOD = 1e9 + 7; 

ll dp[45];
/*
unordered_map<ll, ll> cache; 
ll go(ll n) 
{
	debug(n); 
	if (n==1) return 1;
	//cout << cache[n] << '\n'; 
	if (!cache[n]) return cache[n]; 
	return cache[n] = 2*cache[n/2]; 
}
*/
int main(void) 
{
	
	#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	#endif
	
	ll n; 
	cin >> n; 
	dp[0] = 1;
	for (int i=1; i<45; i++) 
		dp[i] = 2*dp[i-1]+1;
	ll pos=1; 
	int cnt = 0; 
	while (pos < n) {
		pos <<= 1; 
		cnt++; 
	}
	/*
	debug(pos, cnt); 
	cout << "dp[cnt]:"<<dp[cnt]<<'\n';
	for (int i=0; i<45; i++) cout << dp[i] << ' '; 
	cout << '\n'; 
	*/
	if (pos == n) printf("%lld\n", dp[cnt]); 
	else printf("%lld\n", dp[cnt-1]); 

	/*
	ll n; 
	cin >> n; 

	cout << go(n); 
*/
	return false;   


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string st;
long long c;
int main()
{
	cin>>st;
	for(int i=0;i<st.size();i++)
	{
		if(st[i]=='C')c++;
		if(st[i]=='F'&&c>0){cout<<"Yes"<<endl;return 0;}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
import math
a,b,h,m = map(int,input().split())
minutes = 60*h + m
c1 = (minutes /2)%360
c2 = (minutes * 6)%360
if c1==c2:
    print(abs(a-b))
else:
    if c1 > c2:
        p = min(c1-c2, 360-c1+c2)
    else:
        p = min(c2-c1, 360-c2+c1)    
    x = a**2 + b**2 - 2*a*b*math.cos(math.radians(p))
    print(x ** 0.5)

Measured memory_bytes: 9524
s=input()
s_d={}
for c in s:
    if c not in s_d.keys():
        s_d[c] = 0
    s_d[c] += 1

r = 'No'
key = list(s_d.keys())
if len(key) == 2:
    if s_d[key[0]] == 2 and s_d[key[1]] == 2:
        r = "Yes"

print(r)

Measured memory_bytes: 2940
N, K = map(int, input().split())
A = list(map(str, input()))

tmp = A[0]
cnt = 1
for i in range(1,N):
	if A[i] == tmp:
		if i != N-1:
			continue

	else:
		cnt += 1
		tmp = A[i]
		
t = cnt - (2*K)

if t > 0:
	ans = N-t
else:
	ans = N-1

print(ans)

Measured memory_bytes: 4212
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int gcd(int a, int b) {  
  return b != 0 ? gcd(b, a % b) : a;
}//MAX
int lcm(int a, int b) { 
   return a * b / gcd(a, b);
   }
//MIN

 main() {
 int h,w;
 cin >> h >>w;
 vector<string>s(h);
 for(int i=0;i<h;i++){
   cin >> s.at(i);
 }
 int white =0;
 int cost[h][w];
 for(int i=0;i<h;i++ ){
   for(int j=0;j<w;j++){
     cost[i][j]=10e7;
     if(s[i][j]=='.')white++;
   }
 }
 int dy[4]={-1,1,0,0};
 int dx[4]={0,0,-1,1};
 queue<pair<int,int>>que;
 cost[0][0]=1;
 que.push(make_pair(0,0));
 while(!que.empty()){
   int y = que.front().first;
   int x = que.front().second;
   que.pop();
   for(int i=0;i<4;i++){
     if(y+dy[i]<0||y+dy[i]>=h||x+dx[i]<0||x+dx[i]>=w)continue;
     if(s.at(y+dy[i]).at(x+dx[i])=='#')continue;
     // I understand
     if(cost[y+dy[i]][x+dx[i]]>cost[y][x]+1){
       cost[y+dy[i]][x+dx[i]]=cost[y][x]+1;
       que.push(make_pair(y+dy[i],x+dx[i]));
     }
     // 
   }
 }
 if(cost[h-1][w-1]==10e7)cout<< -1 <<endl;
 else cout<< white - cost[h-1][w-1]<<endl;
 }


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::Read;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

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

fn solve() {
    let n = get();
    let mut k: usize = get();
    let mut pool = Vec::new();
    for _ in 0 .. n {
        let a: usize = get();
        let b: usize = get();
        pool.push((a, b));
    }
    pool.sort();
    k -= 1;
    for (a, b) in pool {
        if k >= b {
            k -= b;
        } else {
            println!("{}", a);
            return;
        }
    }
    unreachable!();
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 10620
A,B,C,K= map(int,input().split())
s0m = 0
x = max(0,A-K)
if x == 0 :
    s0m =+ A
    K = K-A
else :
    s0m =+ K
    K=0
if K==0 :
    print (s0m)
else :
    y = max (0 ,B-K)
    if y == 0 :
        K=K-B
    else :
        K = 0
    if K == 0:
        print (s0m)
    else:
        z = max (0,C-K)
        if z== 0 :
            s0m = s0m - C
        else :
            s0m -=K
        print (s0m)


Measured memory_bytes: 9104
import numpy as np
import sys, math

def circle3p(ps):
    A = []
    B = []
    for x, y in ps:
        # eq = sp.Eq(x * a + y * b + c, - x * x - y * y)
        Ai = [x, y, 1]
        A.append(Ai)
        B.append(- x * x - y * y)
    try:
        x = np.linalg.solve(A, B)
        return x[0], x[1], x[2]
    except np.linalg.LinAlgError:
        return None

def circle2p(ps):
    xy0, xy1 = ps
    return [(xy0[0] + xy1[0]) / 2., (xy0[1] + xy1[1]) / 2., ((xy0[0] - xy1[0]) ** 2 + (xy0[1] - xy1[1]) ** 2) / 4.]

eps = 1e-7

def main():
    N = int(sys.stdin.readline())
    ps = []
    for i in range(N):
        x, y = map(int, sys.stdin.readline().split())
        ps.append((x, y))

    n = len(ps)
    ok = False
    res = int(1e9)

    if n == 2:
        x0, y0 = ps[0]
        x1, y1 = ps[1]
        print('%.9f' % (math.sqrt((x0 - x1) ** 2 + (y0 - y1) ** 2) / 2.))
        return

    for i in range(n):
        for j in range(i + 1, n):
            for k in range(j + 1, n):
                circle = circle3p([ps[i], ps[j], ps[k]])
                if circle is None:
                    continue
                a, b, c = circle
                for l in range(n):
                    if l in {i, j, k}:
                        continue
                    x, y = ps[l]
                    if x * x + y * y + a * x + b * y + c > eps:
                        break
                else:
                    res = min(res, a * a / 4 + b * b / 4 - c)

    for i in range(n):
        for j in range(i + 1, n):
            circle = circle2p([ps[i], ps[j]])
            if circle is None:
                continue
            a, b, c = circle
            for l in range(n):
                if l in {i, j}:
                    continue
                x, y = ps[l]
                if (x - a) ** 2 + (y - b) ** 2 > c + eps:
                    break
            else:
                res = min(res, c)

    print('%.9f' % float(math.sqrt(float(res))))


if __name__ == '__main__':
    main()


Measured memory_bytes: 15268
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        String[] param = br.readLine().split(" ");
        int a = Integer.parseInt(param[0]);
        int b = Integer.parseInt(param[1]);

        String[][] array = new String[a][b];
        List<Integer> showColumnsList = new ArrayList<>();

        for (int i = 0; i < a; i++) {
            String line = br.readLine();
            array[i] = line.split("");
        }

        // 縦一列
        for (int i = 0; i < b; i++) {
            boolean allWhite = true;
            for (int j = 0; j < a; j++) {
                if (array[j][i].equals("#")) {
                    allWhite = false;
                    break;
                }
            }
            if (!allWhite) {
                showColumnsList.add(i);
            }
        }

        // 横一列
        for (int i = 0; i < a; i++) {
            boolean allWhite = true;
            for (int j = 0; j < b; j++) {
                if (array[i][j].equals("#")) {
                    allWhite = false;
                    break;
                }
            }
            if (!allWhite) {
            	for (int j: showColumnsList) {
                	out.print(array[i][j]);
            	}
            	out.println();
            }  
        }
        out.close();
    }
}

Measured memory_bytes: 22100
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
using namespace std;

int main() {
	string s;
	int l;
	int count = 0;
	vector<int> num(26,0);

	cin >> s;
	l = s.length();

	for (int j = 0; j < 26; j++) {
		count = 0;
		for (int i = 0; i < l; i++) {
			if (s[i] == char('a' + j)) {
				if (count > num[j]) {
					num[j] = count;
				}
				count = 0;
			}
			else {
				count++;
			}
		}
		if (count > num[j]) {
			num[j] = count;
		}
	}

	sort(num.begin(), num.end());
	

	cout << num[0] << endl;
	

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    long long int arr[n];
    int i;
    long long int sum=0,count=0;
    for(i=0;i<n;i++)
    {cin>>arr[i];
        sum+=arr[i];
    }
    for(i=0;i<n;i++)
    {
        if(arr[i]*4*m>=sum)
        count++;
    }
    if(count>=m)
    cout<<"Yes"<<endl;
    else
    {
        cout<<"No"<<endl;
    }
    

}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,r,d,c=0,f=0;
    cin>>n;
    r=n%100;
    d=n/100;
    if(r>=1 && r<=12 )
    {
        c++;
    }
    if(d>=1 && d<=12 )
    {
        f++;
    }

    if( c>0 && f>0)
    {

        cout<<"AMBIGUOUS"<<endl;

    }
    else if( c>0)
    {
        cout<<"YYMM"<<endl;
    }

    else if( f>0)
    {
        cout<<"MMYY"<<endl;
    }

    else
    {
        cout<<"NA"<<endl;
    }

    return 0;

}


Measured memory_bytes: 3536
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
    int n;
    cin >> n;
    int r = n%10;
    if (r == 2 || r == 4 || r == 5 || r == 7 || r == 9) {
        cout << "hon" << endl;
    } else if (r == 3) {
        cout << "bon" << endl;
    } else {
        cout << "pon" << endl;
    }
}


Measured memory_bytes: 3104
#include<iostream>
#include<vector>
using namespace std;
struct A{
	int x,y,r,c;
};
int n;
bool ok[1<<24];
int over[24];
main()
{
	while(cin>>n,n)
	{
		vector<A>a;
		for(int i=0;i<n;i++)
		{
			int x,y,r,c;cin>>x>>y>>r>>c;
			a.push_back({x,y,r,c});
			over[i]=0;
			for(int j=0;j<i;j++)
			{
				over[i]|=((x-a[j].x)*(x-a[j].x)+(y-a[j].y)*(y-a[j].y)<(r+a[j].r)*(r+a[j].r))<<j;
			}
		}
		for(int i=0;i<1<<n;i++)ok[i]=0;
		ok[(1<<n)-1]=1;
		for(int i=1<<n;i--;)
		{
			if(!ok[i])continue;
			for(int j=0;j<n;j++)
			{
				if(i>>j&1&&!(i&over[j]))
				{
					for(int k=j+1;k<n;k++)
					{
						if(i>>k&1&&!(i&over[k])&&a[j].c==a[k].c)
						{
							ok[i&~(1<<j)&~(1<<k)]=1;
						}
					}
				}
			}
		}
		int ans=n;
		for(int i=0;i<1<<n;i++)
		{
			if(ok[i])
			{
				if(ans>__builtin_popcount(i))ans=__builtin_popcount(i);
			}
		}
		cout<<n-ans<<endl;
	}
}


Measured memory_bytes: 19536