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

typedef long long LL;
typedef vector<int> VI;

#define REP(x, n) for (int x = 0; x < (n); ++x)
#define INF (1e9 + 1)
#define EPS 1e-9

int main() {
    int n;
    scanf("%d", &n);
    int result = 0;
    for (int i = 1; i <= n; ++i) {
        if (to_string(i).length() % 2 != 0) {
            ++result;
        }
    }
    printf("%d\n", result);
    return 0;
}

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

int main() {
  int n, a[100];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = n - 1; i >= 0; i--) {
    cout << a[i];
    if (i != 0) {
      cout << " ";
    }
  }
  cout << endl;
}

Measured memory_bytes: 3076
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <cmath>
#include <stdio.h>
#include <sstream>
#define int_inf 1000000000 //1e9
#define ll_inf  1000000000000000000 //1e18
using namespace std;
template <typename T> std::string to_string(const T& t){
	std::ostringstream os; os<<t; return os.str();
}




int main(){
	string s;
	int a, b;
	cin >> a >> b >> s;
	
	for(int i=0; i<s.size(); i++){
		if(i<a || i>a){
			if(s[i]<'0' || s[i]>'9'){
				cout << "No" << endl;
				return 0;
			}
		}
		else {
			if(s[i]!='-'){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	
	cout << "Yes" << endl;
	
	
	return 0;
}




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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;

int main(){

  int a,b;cin>>a>>b;
  out(6-a-b);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	char number[200002];
	scanf("%s", number);
	int i = 0, sum = 0;
	while(number[i]!='\0'){
		int num = number[i] - 48;
		sum+=num;
		i++;
	}
	if(sum % 9 == 0){
		cout << "Yes";
	}
	else{
		cout << "No";
	}
}


Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef long long ll;


int main(){
    ll x;cin>>x;
    for(ll i=-1000;i<=1000;i++){
        for(ll j=-1000;j<=1000;j++){
            if(i*i*i*i*i-j*j*j*j*j==x){
                cout<<i<<" "<<j<<endl;
                return 0;
            }
        }
    }
}
    









Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int main() {
 
  int N;
  cin >> N ;
  map<string , int> num;
  
  for(int i = 0 ; i < N ; i++){
    string str;
    cin >> str;
    
    sort(str.begin() , str.end() );
    
    if(num.count(str)){
      
      num[str] ++;
      
    }else{
      
      num[str] = 1;
      
    }
  }
  
  int64_t result = 0; 
  
  for(auto p : num){
    int64_t mmm = p.second;
    result += ( (mmm)*(mmm - 1) )/2;
    
  }
  
  cout << result << endl;
}

Measured memory_bytes: 11136
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let N: usize = sc.get();
    let S: Vec<char> = sc.chars();
    let mut dp = vec![vec![0; N]; N];
    let mut ans = 0;
    for i in (0..N).rev() {
        for j in (0..N).rev() {
            if S[i] == S[j] {
                dp[i][j] = if j == N - 1 || i == N - 1 {
                    1
                } else {
                    1 + dp[i+1][j+1]
                };
            }
            if i < j {
                ans = max(ans, min(j - i, dp[i][j]));
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 197552
#include <bits/stdc++.h>
using namespace std;
int arr[100009];
int dp[100009];
int main(){
    int n;
    cin >>n;
    for(int i=0;i<n;i++){
        cin >>arr[i];
    }
    dp[1]=abs(arr[1]-arr[0]);
    for(int i=2;i<n;i++){
        dp[i] = min(dp[i-2]+abs(arr[i]-arr[i-2]),dp[i-1]+abs(arr[i]-arr[i-1]));
    }
    cout<<dp[n-1];
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
"""
A - +-x
https://atcoder.jp/contests/abc137/tasks/abc137_a

"""
import sys


def solve(A, B):
    return max(A + B, A - B, A * B)


def main(args):
    A, B = map(int, input().split())
    ans = solve(A, B)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>


long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;


int main(){
long long  N;
cin>>N;
long long ans=N*(N-1)/2;

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

Measured memory_bytes: 256
n=int(input())
a=[int(i) for i in input().split()]
q=int(input())
l=[0]*(10**5+1)
s=sum(a)
for i in a:
  l[i]+=1
for i in range(q):
  b,c=map(int,input().split())
  s+=(c-b)*l[b]
  print(s)
  l[c]+=l[b]
  l[b]=0

Measured memory_bytes: 84176
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <cmath>
#include <algorithm>
#include <vector>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>func(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p;
}

int main(){
  string s;
  cin>>s;
  for(int i=0;i<s.size();i++){
    s[i]='x';
  }
  cout<<s<<endl;
  return 0;
}

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

#define INF 1e9+5
#define ll long long
#define lb lower_bound
#define ub upper_bound
#define pushf push_front
#define pushb push_back
#define popf pop_front
#define popb pop_back

string n;

int main(){
        cin>>n;
        for(int i=0; i<3; ++i) if(n[i]=='7'){
                printf("Yes");
                return 0;
        }

        printf("No");

        return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const ldouble pi = acos(-1), eps = 1e-10;
const ldouble pi2 = acos(-1) / 2;
ldouble a, b, x, v, h, needs;

ldouble radToDeg(ldouble angle)
{
  return (ldouble) 180 / pi * angle;
}

ldouble volume(ldouble angle)
{
  ldouble other = pi2 - angle;
  ldouble hh = b * tan(angle);
  // printf("kk %Lf\n", 90 - radToDeg(angle));
  // printf("## %Lf\n", hh);
  if (hh <= a)
    return a * b * hh / 2;
  ldouble hhh = tan(other) * (hh - a);
  // printf("-- %Lf\n", hhh);
  return a * a * hhh + a * (b - hhh) * a / 2;
}

ldouble binarySearch()
{
  ldouble lo = 0, hi = pi2;
  while ((hi - lo) >= eps)
  {
    ldouble mid = (lo + hi) / 2;
    if (volume(mid) <= x) lo = mid;
    else hi = mid;
  }
  return lo;
}

int main()
{
  scanf("%Lf %Lf %Lf", &a, &b, &x);
  h = x / (a * a);
  needs = b - h;
  // printf("%Lf %Lf %Lf %Lf\n", needs, h, 1 / h, 1 / needs);
  printf("%.12Lf\n", 90 - radToDeg(binarySearch()));
  // printf("%Lf\n", volume(pi2 - 0.07393));
  return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;
int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};

 
int main(){
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a, a+3);
  int ans = a[0] + a[1] + a[2]*10;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import numpy as np
k,n=map(int,input().split())
a=list(map(int,input().split()))
a=np.array(a)
if max(abs(a[1:]-a[:-1])) < k-abs(a[0]-a[-1]):b=k-abs(a[0]-a[-1])
else:b= max(abs(a[1:]-a[:-1]))
print(k-b)

Measured memory_bytes: 34168
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define INF int(1e9)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = int(1e5);
ll N, a[MAX_N];
unordered_map<ll, ll> mp;

void solve() {
    ll ans = 0;
    EACH(m, mp) {
        if (m.first == m.second) continue;
        if (m.second - m.first > 0)ans += m.second - m.first;
        else ans += m.second;
    }
    cout << ans << endl;
}

int main() {
    cin >> N;
    REP(i, N) {
        cin >> a[i];
        mp[a[i]]++;
    }
    solve();
    return 0;
}

Measured memory_bytes: 5028
s = input()
if s[-2] == s[-1]:
    print(len(s)-1, len(s))
    exit()

for i in range(len(s) - 2):
    if s[i] == s[i+1] or s[i] == s[i+2]:
        print(i+1, i+3)
        exit()
print(-1, -1)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin>>N;
    string s[N];
    int p[N];
    for(int i=0;i<N;i++){
        cin>>s[i]>>p[i];
    }
    vector<tuple<int,string,int>> data;
    for(int i=0;i<N;i++){
        data.push_back(make_tuple(p[i],s[i],i));
    }
    sort(data.begin(),data.end());
    for(int i=0;i<N;i++){
        get<0>(data.at(i))=-i;
    }
    vector<tuple<string,int,int>> ans;
    for(int i=0;i<N;i++){
        ans.push_back(make_tuple(get<1>(data.at(i)),get<0>(data.at(i)),get<2>(data.at(i))));
    } 
    sort(ans.begin(),ans.end());
    for(int i=0;i<N;i++)
        cout<<get<2>(ans.at(i))+1<<endl;
}

Measured memory_bytes: 764
//#include"pch.h"
//#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;

int main() {
	int A, B;
	cin >> A >> B;
	if (A == B)cout << A + B << endl;
	else cout << max(A, B) * 2 - 1 << endl;


	return(0);
}

Measured memory_bytes: 256
//ダイクストラ法
#include "bits/stdc++.h"
#include <queue>
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

const int N = 1e5;
vector<vector<pair<int, int>>> g;
vector<double> leng(N,4503599627370496.0); //ある点を始点として、全体nodeへの最短距離
// 小さいほうが先頭にくるよう。ダイクストラ法などで使用を想定
auto compare = [](pair<double, int> a, pair<double, int> b) {
  return a.first > b.first;
};
priority_queue<int,vector<pair<double, int>>,decltype(compare) > que {compare};


void pushg(int nodeid,double len){
  pair<double, int> aaa;
  for(auto to : g[nodeid]) {
    aaa.second=to.first;//node id
    aaa.first=(double)to.second+len;//length
    que.push(aaa);
  }
}

void djk(int first_node){
  //初期値をプライオリティーキューにいれる
  leng[first_node]=0.0;
  pushg(first_node,0.0);
  //キューがなくなるまでやる
  pair<double, int> aaa;
  while (!que.empty()) {
    aaa=que.top();
    if (leng[aaa.second]>aaa.first){
      leng[aaa.second]=aaa.first;
      pushg(aaa.second,aaa.first);
    }
    que.pop();
  }
  return;
}


ll n,h,w;
int main() {

  cin>>h>>w;
  vvi data(w, vi(h));  // N * M の2次元配列
  string s;
  REP(i,h){
    cin>>s;
    REP(j,w){
      if (s[j]=='.'){
        data[j][i]=1;
      }
    }
  }

  n=h*w;
  g.resize(n);
  int a,b;

  REP(i,h){
    REP(j,w){
      if (data[j][i]==1){
        if (j+1<w){
          if (data[j+1][i]==1){
            a=j+i*w;b=j+1+i*w;
            g[a].emplace_back(b, 1);
            g[b].emplace_back(a, 1);
          }
        }
        if (j-1>=0){
          if (data[j-1][i]==1){
            a=j+i*w;b=j-1+i*w;
            g[a].emplace_back(b, 1);
            g[b].emplace_back(a, 1);
          }
        }

        if (i+1<h){
          if (data[j][i+1]==1){
            a=j+i*w;b=j+i*w+w;
            g[a].emplace_back(b, 1);
            g[b].emplace_back(a, 1);
          }
        }

        if (i-1>=0){
          if (data[j][i-1]==1){
            a=j+i*w;b=j+i*w-w;
            g[a].emplace_back(b, 1);
            g[b].emplace_back(a, 1);
          }
        }

      }
    }
  }




/*  
  for(int i = 0; i < n-1; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    g[a].emplace_back(b, c);
    g[b].emplace_back(a, c);
  }
  */
 double dans=0.0;
 REP(i,n)
 {
   
  REP(i,n){
    leng[i]=4503599627370496.0;
  }

  djk(i);
  REP(i,n){
    if (leng[i]!=4503599627370496.0){
      dans=max(dans,leng[i]);
    }
  }

 }
  

  cout<<(int )dans<<endl;

}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(int I=X;I<Y;I++)
#define REP(I,X,Y) for(int I=Y-1;I>=X;I--)
#define INF 1000000007
using namespace std;

int main(){
  long long K;
  cin >> K;
  long long mod = K%50,s = 49+K/50;
  cout << 50 << endl;
  FOR(i,0,50-mod)cout << s-mod << " ";
  FOR(i,0,mod)cout << s+50-mod+1 << " ";
  cout << endl;
}


Measured memory_bytes: 256
N=int(input())
H=list(map(int, input().split()))
import numpy as np

H=np.array(H)
ans=0
while H.max()>0:
    prezero=True
    count=0
    for i in range(N):
        if prezero:
            if H[i]>0:
                count+=1
                prezero=False
        else:
            if H[i]<=0:
                prezero=True
    ans+=count
    H-=1
print(ans)

Measured memory_bytes: 12488
//Love and Freedom.
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#define ll long long
#define inf 20021225
#define N 110
#define pa pair<int,int>
#define mdn 1000000007
using namespace std;
int read()
{
	int s=0,t=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')	t=-1; ch=getchar();}
	while(ch>='0' && ch<='9')	s=s*10+ch-'0',ch=getchar();
	return s*t;
}
int a[N],n;
int ksm(int bs,int mi)
{
	int ans=1;
	while(mi)
	{
		if(mi&1)	ans=1ll*ans*bs%mdn;
		bs=1ll*bs*bs%mdn; mi>>=1;
	}
	return ans;
}
pa solve(int l,int r,int lim)
{
	int mn=a[min_element(a+l,a+r+1)-a],w1=1,w2=1,num=0;
	for(int i=l,j;i<=r;i++)
	{
		if(a[i]!=mn)
		{
			j=i; while(j+1<=r&&a[j+1]!=mn)	j++;
			pa cur=solve(i,j,mn); i=j;
			w1=1ll*cur.first*w1%mdn;
			w2=1ll*(cur.first+cur.second)%mdn*w2%mdn;
		}
		else	num++;
	}
	return make_pair(1ll*w1*ksm(2,mn-lim)%mdn,(1ll*w2*ksm(2,num)%mdn+1ll*w1*(ksm(2,mn-lim)-2)%mdn)%mdn);
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)	a[i]=read();
	printf("%d\n",solve(1,n,0).second);
	return 0;
}


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

int main()
{
    int n;
    cin>>n;
    int a[n+1]={0};
    for(int i=0; i<n; i++)cin>>a[i];
    int cur=0,mx=0,pmax=0;

    for(int i=0; i<n-1; i++)
    {
        if(a[i+1]<=a[i])mx++;
        else
        {
            pmax=max(mx,pmax);
            mx=0;
        }
    }
    pmax=max(pmax,mx);
    cout<<pmax<<endl;


    return 0;
}


Measured memory_bytes: 640
// By Debajit Chakraborty
#include<bits/stdc++.h>
using namespace std;
 
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define MP make_pair
#define pb push_back
#define ff first
#define ss second
#define sz(x) x.size()
#define all(c) c.begin(),c.end()
#define int long long
#define fr(i,j,x) for(int i=j;i<x;i++)
#define rep(i,j,x) for(int i=j;i<=x;i++)
#define rev(i,j,x) for(int i=j;i>=x;i--)
#define mem(x,val) memset(x,val,sizeof(x))
#define endl '\n'
#define vi vector<int>
#define pii pair<int,int>
 
const int mod=1e9+7;
const int N=2e5+10;
const int INF=1e12;



void solve(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    int cnt=0;
    for(int i=0;i<n;i++){
        if(s[i]=='R'){
            cnt++;
        }
    }
    int cut=0;
    for(int i=0;i<cnt;i++){
        if(s[i]=='R'){
            cut++;
        }
    }
    cout<<cnt-cut<<endl;
}


int32_t main()
{
    SPEED;
    int T=1;
    //cin>>T;
    int t1=1;
    while(true)
    {  
        //cout<<"Case #"<<t1<<": ";
        //cout<<endl;
        solve();
        t1++;
        if(t1>T)
            break;
    }
}   


Measured memory_bytes: 3764
#include <iostream>

int main(){
    long N, A, B;
    std::cin >> N >> A >>B;

    long ans = N / (A + B) * A;
    if(N % (A + B) < A){
        ans += N % (A + B);
    }
    else{
        ans += A;
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")
#define FOR(i,j,n) for (int i=(j);i<(n);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define REPN(i,n) for (int i=(n);i>=0;i--)
#define I(n) scanf("%d", &(n))
#define pb(n) push_back((n))
#define mp(i,j) make_pair((i),(j))
#include <bits/stdc++.h>
using namespace std;

//------------------------------typedef集
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<vvi> vvvi;
typedef long long ll;

ll n,k;

int main(){
    cin >> n >> k;
    ll ret = 0;
    FOR(b,k+1,n+1){
        ret += (b-k)*(n/b);
        ll a = b*(n/b)+k;
        FOR(ai,a,n+1){
            ret++;
        }
        if (k == 0) ret--;
    }
    cout << ret << endl;
}


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

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

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

    vector<vector<int> > graph(n);
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    vector<int> dist(n, -1);
    queue<int> que;
    vector<int> pre(n, -1);

    dist[0] = 0;
    que.push(0);

    while (!que.empty()) {
        int v = que.front();
        que.pop();

        for (int nv : graph[v]) {
            if (dist[nv] != -1)
                continue ;
            dist[nv] = dist[v] + 1;
            que.push(nv);
            pre[nv] = v;
        }
    }

    cout << "Yes" << endl;
    for (int i = 1; i < n; ++i)
        cout << pre[i] + 1 << endl;
    return 0;
}

Measured memory_bytes: 10576
#include <stdio.h>

#define sqr(x) ((x)*(x))

void swap(int *a,int *b) {
	int t = *a;
	*a = *b;
	*b = t;
}

int main(void) {
	int i,s[3],n,r;

	while (1) {
		scanf("%d %d %d",&s[0],&s[1],&s[2]);
		if (!s[0]&&!s[1]&&!s[2]) break;

		if (s[0]>s[1]) swap(&s[0],&s[1]);
		if (s[1]>s[2]) swap(&s[1],&s[2]);
		if (s[0]>s[1]) swap(&s[0],&s[1]);

		scanf("%d",&n);
		for (i=0;i<n;i++) {
			scanf("%d",&r);
			if (sqr(s[0])+sqr(s[1])<sqr(2*r)) {
				puts("OK");
			} else {
				puts("NA");
			}
		}
	}

	return 0;
}

Measured memory_bytes: 580
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))

s1=a[0]
s2=a[-1]
su=[s1]
sd=[s2]
for i in range(1,n-1):
    s1=gcd(s1,a[i])
    s2=gcd(s2,a[(i+1)*(-1)])
    su+=[s1]
    sd+=[s2]
sd.reverse()

ans=[su[-1],sd[0]]
for i in range(n-2):
    ans+=[gcd(su[i],sd[i+1])]
print(max(ans))

Measured memory_bytes: 16148
#include <iostream>
#include <cstdio>
#include <map>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
    int n, m;
    
    while (1) {
        scanf("%d %d", &n, &m);
        if (!(n || m)) break;
        
        vector<pair<int, int>> scores(m, pair<int, int>(0, 0));
        
        for(int i = 0; i < n; ++i) {
            for(int j = 0; j < m; ++j) {
                int s; scanf("%d", &s);
                scores[j].first  -= s;
                scores[j].second =  j+1;
            }
        }
        
        sort(scores.begin(), scores.end());
        
        for(int i = 0; i < m; ++i) {
            cout << scores[i].second;
            if (i != m-1) {
                cout << " ";
            } else {
                cout << "\n";
            }
        }
    }
}

Measured memory_bytes: 1200
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
using namespace std;
typedef long long ll;
#define rst(A) memset(A, 0, sizeof(A))
#define rep(I, S, T) for (int I = S; I <= T; I++)
const int inf = 1<<30;
const int maxn = 1e5+7;
char s[maxn];
int n;
int res[maxn][2];
int main()
{
    scanf("%s", s+1);
    n = strlen(s+1);
    if (s[1] == '0' || s[n-1] == '0' || s[n] == '1')  {
        puts("-1");
        return 0;
    }
    int cur = n;
    for (int i = n-2; i >= 1; i--) {
        if (s[i] == '1') {
            if (s[n-i] == '0') {
                puts("-1");
                return 0;
            }
            for (; cur > i+1; cur--) {
                res[cur-1][0] = i+1;
                res[cur-1][1] = cur;
            }
        }
    }
    res[1][0] = 1; res[1][1] = 2;
    for (int i = 1; i < n; i++) printf("%d %d\n", res[i][0], res[i][1]);
    return 0;
}

Measured memory_bytes: 2304
//package solution;

import java.io.*;
import java.util.*;
import java.math.*;
import java.awt.Point;

public final class Main {
    BufferedReader br;
    StringTokenizer stk;

    public static void main(String[] args) throws Exception {
        new Main().run();
    }
    
    {
        stk = null;
        br = new BufferedReader(new InputStreamReader(System.in));
    }
    
    void run() throws Exception {
        int n = ni(); long w = ni();
        long[][] dp = new long[n + 1][100000 + 10];
        long[][] wv = new long[n + 1][];
        for(int i=1; i<wv.length; i++) wv[i] = new long[] {ni(), ni()};
        wv[0] = new long[] {0, 0};
        
        for(int i=0; i<dp.length; i++)
            for(int j=0; j<dp[0].length; j++)
                dp[i][j] = Integer.MAX_VALUE;
        
        dp[0][0] = 0; //this value can be synthesized
        for(int i=1; i<=n; i++) {
            long weight = wv[i][0], value = wv[i][1];
            for(int j=0; j<dp[0].length; j++) {
                if(j < value) {
                    dp[i][j] = dp[i-1][j];
                } else {
                    dp[i][j] = Math.min(dp[i-1][j], dp[i-1][j-(int)value] + weight);
                }
            }
        }
        
        int ans = 0;
        for(int i=dp[0].length-1; i>=0; i--) {
            if(dp[dp.length-1][i] <= w) {
                ans = i; break;
            }
        }
        
        //for(long[] a : dp) pl(Arrays.toString(a));
        
        pl(ans);
    }
    
    //Reader & Writer
    String nextToken() throws Exception {
        if (stk == null || !stk.hasMoreTokens()) {
            stk = new StringTokenizer(br.readLine(), " ");
        }
        return stk.nextToken();
    }

    String nt() throws Exception {
        return nextToken();
    }

    String ns() throws Exception {
        return br.readLine();
    }

    int ni() throws Exception {
        return Integer.parseInt(nextToken());
    }

    long nl() throws Exception {
        return Long.parseLong(nextToken());
    }

    double nd() throws Exception {
        return Double.parseDouble(nextToken());
    }

    void p(Object o) {
        System.out.print(o);
    }

    void pl(Object o) {
        System.out.println(o);
    }
    
    void selector() {
        Random rd = new Random();
        String[] s = new String[] {"Strings", "Sorting", "Search"
                , "Graph theory", "Greedy", "Dynamic programming"
                , "Constructive algos", "Bit manipulation", "Recursion"};
        pl(s[rd.nextInt(s.length)] + " " + (rd.nextInt(5)+1));
    }
}

Measured memory_bytes: 126156
n = int(input())
h = list(map(int,input().split()))

index = 0
max_num = 0
count = 0
while index < n-1:
  index += 1
  if h[index-1] < h[index]:
    max_num = max(max_num, count)
    count = 0
    continue
  
  count += 1
  
max_num = max(max_num, count)

print(max_num)

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

int main(){
    int n, k; cin >> n >> k;
    set <int> have;
    for(int i=0; i<k; i++){
        int d; cin >> d;
        for (int j=0; j<d; j++){
            int now; cin >> now;
            have.insert(now);
        }
    }
    cout << n-have.size() << endl;
    return 0;
}

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

int main(){
    int N,M,K;
    cin >> N >> M >> K;
    long long A[N+10]; //Aの上からの累積和。
    A[0] = 0;
    for(int i = 1; i <= N; i++){
        cin >> A[i];
        A[i] += A[i-1];
    }
    long long B[M + 10];
    B[0] = 0;
    for(int i = 1; i <= M; i++){
        cin >> B[i];
        B[i] += B[i-1];
    }
    int b = M;//Bから何冊目まで読むか？
    long long ans = 0;
    for(int a = 0; a <= N; a++){ //aごとにbを決める
        while(A[a] + B[b] > K && b > 0){
            b--;
        }
        if(A[a] + B[b] <= K && a + b > ans){
            ans = a + b; //最小になっていたら更新
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 6696
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 5LL << 60;
const ll mod = 1e9 + 7;

struct UnionFind {
	vector<int> par;  // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) {	 //最初は全てが根であるとして初期化
		for(int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) {  // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if(par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) {	// xとyの木を併合
		int rx = root(x);		// xの根をrx
		int ry = root(y);		// yの根をry
		if(rx == ry) return;	// xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry;			// xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) {  // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

int main() {
	int N, M;
	cin >> N >> M;
	UnionFind tree(N);
	for(int i = 0; i < M; i++) {
		int X, Y, Z;
		cin >> X >> Y >> Z;
		tree.unite(X - 1, Y - 1);
	}
	set<int> s;
	for(int i = 0; i < N; i++) s.insert(tree.root(i));
	cout << s.size() << "\n";
	return 0;
}


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

#define INF ((1<<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)

// dp[i][r] := l以上r未満のスライムを1体にするときのコストの最小値
// dp[i][i+1] = 0
// dp[l][r] = min(dp[l][m], dp[m][r] + [l, m)スライムと[m, r)スライムを合致させるコスト)
// (r-l)の小さい順からやればいい

ll dp[410][410];
ll sum[410][410];

int main() {
    int n;
    cin >> n;
    vector<ll> a(n+1);
    rep(i, n) cin >> a[i];
    rep(l, n) {
        sum[l][l+1] = a[l];
        for (int r = l+2; r <= n; ++r) {
            sum[l][r] = sum[l][r-1] + a[r-1];
        }
    }

    for (int len = 2; len <= n; ++len) {
        for (int l = 0; l + len <= n; ++l) {
            int r = l + len;
            dp[l][r] = LLINF;
            for (int m = l + 1; m < r; ++m) {
                dp[l][r] = min(dp[l][r], dp[l][m] + dp[m][r] + sum[l][r]);
            }
        }
    }

    cout << dp[0][n] << endl;
}


Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
int n;
string s;
int main(){
  cin >> n >> s;
  for(int i=0;i<s.length();i++){
    s[i] = (s[i]-'A'+n)%26+'A';
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, BinaryHeap, VecDeque, BTreeSet, BTreeMap};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
                   ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
                   ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let n = get!(usize);
    let a: Vec<u64> = get!(u64;n);

    let mut set = HashSet::new();

    for &x in &a {
        if set.contains(&x) {
            set.remove(&x);
        } else {
            set.insert(x);
        }
    }

    println!("{}", set.len());
}


Measured memory_bytes: 8444
#include <iostream>
#include <vector>
using namespace std;
#define MAX (int)1e5

int A[MAX];
int x[MAX];
int main(void){
  int N;
  cin >> N;
  for(int i=0;i<N;i++){
    int tmp;
    cin >> tmp;
    A[i] = tmp;
  }
  int x1 = 0;
  for(int i=0;i<N;i++){
    if(i%2 == 0){
      x1 = x1 + A[i];
    }else{
      x1 = x1 - A[i];
    }
  }
  x[0] = x1;
  for(int i=1;i<N;i++){
    x[i] = 2*A[i-1] - x[i-1];
  }
  x[N-1] = 2*A[N-1] - x[0];
  for(int i=0;i<N;i++){
    cout << x[i] << " ";
  }
  cout << endl;

  return 0;
  
}


Measured memory_bytes: 2048
# AOJ 0027 What day is today?
# Python3 2018.6.11 bal4u

def Zeller(y, m, d):
    if m == 1 or  m == 2:
        y -= 1
        m += 12
    return (y + y//4 - y//100 + y//400 + (13*m + 8)//5 + d) % 7

import sys
week = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
for line in sys.stdin:
    m, d = list(map(int, line.split()))
    if m >= 1:
        print(week[Zeller(2004, m, d)])
    else:
        break


Measured memory_bytes: 5604
#include <stdio.h>

int main(){
    int cards[4][13], i, j, n, x;
    char ch;
    for(i=0; i<4; i++) for(j=0; j<13; j++) cards[i][j] = 0;
    scanf("%d", &n);
    for(i=0; i<n; i++){
        scanf(" %c %d", &ch, &x);
        switch(ch){
            case 'S': cards[0][x-1] = 1; break;
            case 'H': cards[1][x-1] = 1; break;
            case 'C': cards[2][x-1] = 1; break;
            case 'D': cards[3][x-1] = 1; break;
        }
    }
    for(i=0; i<4; i++){
        for(j=0; j<13; j++){
            if(cards[i][j] == 0){
                switch(i){
                    case 0: printf("S "); break;
                    case 1: printf("H "); break;
                    case 2: printf("C "); break;
                    case 3: printf("D "); break;
                }
                printf("%d\n", j+1);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std ;
using ll=long long;
ll gcd(ll a,ll b){
    if(b==0){
        return(a);
    }else{
        return gcd(b,a%b);
    }
}
ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}
int main(){
    ll  N;
    cin >> N;
    ll T[N];
    for(ll i=0;i<N;i++)cin>>T[i];
    ll Ans =T[0];
    for(ll i=1;i<N;i++){
        Ans=lcm(Ans,T[i]);
    }
    cout << Ans << endl;
}

Measured memory_bytes: 3600
fn main() {
    let s = read::<String>().chars().collect::<Vec<_>>();
    let len = s.len();
    let mut n = 0;
    let mut m = len;
    for i in 0..len {
        if s[i] == 'A' {
            n = i;
            break;
        }
    }
    for j in (0..len).rev() {
        if s[j] == 'Z' {
            m = j;
            break;
        }
    }
    println!("{}", m - n + 1);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
import java.util.*;
import java.util.stream.IntStream;

public class Main {

    public static boolean found = false;

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

        int h = sc.nextInt();
        int w = sc.nextInt();

        char[][] board = new char[h][w];

        for (int i = 0; i < h; i++) {
            String line = sc.next();
            board[i] = line.toCharArray();
        }

        int[][] dt =  new int[][] {
                new int[] {1, 0},
                new int[] {-1, 0},
                new int[] {0, 1},
                new int[] {0, -1},
        };

        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (board[i][j] == '#') {
                    boolean ok = false;
                    for (int k = 0; k < dt.length; k++) {
                        int x = i + dt[k][0];
                        int y = j + dt[k][1];
                        if ((0 <= x && x < h) && (0 <= y && y < w)) {
                            if (board[x][y] == '#') {
                                ok = true;
                            }
                        }
                    }
                    if (!ok) {
                        System.out.println("No");
                        return;
                    }
                }
            }
        }
        System.out.println("Yes");
    }

}

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

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		int max = A*B;
		if(max < C*D)max=C*D;
		System.out.println(max);
		}
		
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
 using namespace std;
 typedef long long ll;
 #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
 const ll MOD = 1000000007;

 int main() {
     ll N, K;
     cin >> N >> K;
     if (K % 2 == 1) cout << (N / K) * (N / K) * (N / K) << endl;
     else cout << (N / (K / 2) - N / K) * (N / (K / 2) - N / K) * (N / (K / 2) - N / K) + (N / K) * (N / K) * (N / K) << endl;
 }


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

using namespace std;

int main() {
    int a,b,c,d, ans=0;
    cin >> a >> b >> c;
    if(a==b&&b==c)cout << 1 << endl;
    else if((a==b||b==c)||a==c)cout << 2 << endl;
    else cout << 3 << endl;
    return 0;
}

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

int main(int argc, const char * argv[])
{
    int N;
    std::vector<int> p(10);
    int answer = 0;

    std::cin >> N;

    for (int i=0;i < N;i++)
        std::cin >> p[i];

    std::sort(p.begin(), p.end(), std::greater<int>());

    p[0] /= 2;

    for (int i : p)
        answer += i;

    std::cout << answer << std::endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
cs = []
t1, x1, y1 = 0, 0, 0
ans = 'Yes'
for i in range(N):
  t2, x2, y2 = map(int, input().split())
  d = abs(x1-x2) + abs(y1-y2)
  if d == 0 or d > (t2 - t1) or d % 2 != (t2 - t1) % 2:
    ans = 'No'
    break
  t1, x1, y1 = t2, x2, y2
print(ans)

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

//スイッチの状態を全通り試す 2の１０乗通り


int main(void){
    int n, m;
    cin >> n >> m;
    
    vector<int> k(m), p(m);
    vector<vector<int>> s(m, vector<int>(n));
    
    rep(i, m){
       // int a;
        cin >> k[i];
        
        rep(j, k[i]){
            cin >> s[i][j];
            s[i][j]--;
        } 
    }
    
    rep(i, m) cin >> p[i];
    
    int number_of_ans = 0;
    
    //スイッチの状態を全て試す
    for (int temp = 0; temp < (1<<n); temp++){
        
        bool check = true;
        
        //それぞれの電球について条件を満たすかどうか調べる
        rep(i, m){
            
            //電球1は条件を満たすか？？
            //電球1につながったスイッチの個数は？？
            
            int swi = 0;
            
            rep(j, k[i]){
                if (temp & (1<<s[i][j])) swi++;
            }
            
            if(swi % 2 != p[i]) check = false;
            
            if (!check) break;
        } 
        
        if (check) number_of_ans++;
    }
    cout << number_of_ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;
const int INF=1e9;
using namespace std;

int main(){
    string s, t;
    cin>>s;
    for(int i=0; i<s.size(); i++){
        if(i%2==0) t.push_back(s[i]);
    }
    cout<<t<<endl;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int[][] c = new int[3][3];
		boolean b = true;

		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				c[i][j] = s.nextInt();
			}
		}

		for (int i = 0; i < 2; i++) {
			for (int j = 0; j < 2; j++) {
				if (b) {
					b = c[i][j] - c[i][j + 1] == c[i + 1][j] - c[i + 1][j + 1];
				}
			}

		}

		String str = b ? "Yes" : "No";
		System.out.println(str);
	}
}


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

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

using LL = long long int;
using LD = long double;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

const int dy[] = { 0, 1, 0, -1 };
const int dx[] = { 1, 0, -1, 0 };

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
LL gcd(LL x, LL y) { return y ? gcd(y, x % y) : x; }

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

	LL n, k;
	cin >> n >> k;

	vector<pll> vec(n);
	for (int i = 0; i < n; i++) {
		LL a, b;
		cin >> vec[i].first >> vec[i].second;
	}

	SORT(vec);
	for (int i = 0; i < n; i++) {
		k -= vec[i].second;
		if (k <= 0) {
			cout << vec[i].first << endl;
			break;
		}
	}
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(all(a));
    double x = a[n-1]*1.0000/2;
    double mn = 1e9;
    int ans = a[0];
    rep(i,n-1) {
        if(abs(x-a[i]) < mn){ 
            mn = abs(x-a[i]);
            ans = a[i];
        }
    }
    cout << a[n-1] << " " << ans << endl;
    return 0;
}

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

using namespace std;

#define sqr(x) ((x) * (x))
#define pb push_back
#define mp make_pair
#define ins insert
#define X first
#define Y second
#define fin(name) freopen(name, "r", stdin)
#define fout(name) freopen(name, "w", stdout)
#define files(name) fin(name".in"); fout(name".out")
#define endl "\n"
#define fi(st,n) for (int i = (st); i <= (int)(n); ++i)
#define fj(st,n) for (int j = (st); j <= (int)(n); ++j)
#define fk(st,n) for (int k = (st); k <= (int)(n); ++k)
#define fq(st,n) for (int q = (st); q <= (int)(n); ++q)
#define fw(st,n) for (int w = (st); w <= (int)(n); ++w)
#define ff(i, st, n) for (int (i) = (st); (i) <= (int)(n); ++(i))
#define ei(st,n) for (int i = (st); i >= (int)(n); --i)
#define ej(st,n) for (int j = (st); j >= (int)(n); --j)
#define ek(st,n) for (int k = (st); k >= (int)(n); --k)
#define ef(i, st, n) for (int (i) = (st); (i) >= (int)(n); --(i))
#define ri(st,n) for (int i = (st); i < (int)(n); ++i)
#define rj(st,n) for (int j = (st); j < (int)(n); ++j)
#define rk(st,n) for (int k = (st); k < (int)(n); ++k)
#define rq(st,n) for (int q = (st); q < (int)(n); ++q)
#define rf(i, st, n) for (int (i) = (st); (i) < (int)(n); ++(i))
#define clean(a) memset((a),0,sizeof (a))
#define sync ios_base::sync_with_stdio(0);cin.tie(0)
#define y1 dsklmlvmd

typedef long long ll;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ldbl;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const dbl eps = (dbl) 1e-8;
const int mod = (int) 1e9 + 7;
const int maxn = (int) 1e5 + 5;
//const dbl M_PI = (dbl)2 * (dbl)acos(0);

//cout<<fixed<<setprecision(10);
//srand(time(0));

int n, d[maxn];
vector <int> a[maxn];

void dfs(int v, int pr)
{
	d[v] = 0;
	ri(0, a[v].size())
	{
		if (a[v][i] == pr)
			continue;
		dfs(a[v][i], v);
		d[v] = d[v] ^ (d[a[v][i]] + 1);
	}
	return;
}

int main()
{
//    fin("t.in");
    sync;
    cin >> n;
    fi(1, n - 1)
    {
    	int x, y;
    	cin >> x >> y;
    	a[x].pb(y);
    	a[y].pb(x);
    }
    dfs(1, 0);
    if (d[1])
		cout << "Alice" << endl;
	else
		cout << "Bob" << endl;
    return 0;
}

Measured memory_bytes: 13952
#include<bits/stdc++.h>
#define INF 9223372036854775807LL
#define mod 1000000007
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
int N;//一番下の葉の数
struct Sgument{
  vector<int> value;

  Sgument(int n): value(n*2){
    for(int i=0;i<=n*2;i++) value[i] = 0;//初期化
  }
  void update(int i,int x){//iの位置をxに変える
    i+=N-1;
    value[i]=x;
    while(i>0){
      i=(i-1)/2;
      value[i]=(value[i*2+1]|value[i*2+2]);//ここで最小
    }
  }
  int get(int a,int b,int k,int l,int r){
    //   0から0を知りたいときは(0,1,0,0,N)で呼び出す。
    if(r<=a||b<=l) return 0;         //初期値を返す
    if(a<=l&&r<=b) return value[k];
    else{
      int c1=get(a,b,2*k+1,l,(l+r)/2);
      int c2=get(a,b,2*k+2,(l+r)/2,r);
      return (c1|c2);             //ここも最小
    }
  }
};
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  string s;
  cin >>n;
  N=1;
  while(N<n) N*=2;
  Sgument st(N);
  cin >>s;
  for(int i=0;i<n;i++){
    int x=1<<(s[i]-'a');
    st.update(i,x);
  }
  int q;
  cin >>q;
  for(int i=0;i<q;i++){
    int e;
    cin >>e;
    if(e==1){
      int ii;
      char c;
      cin >>ii>>c;
      int x=1<<(c-'a');
      st.update(ii-1,x);
    }else{
      int r,l;
      cin >>l>>r;
      int x=st.get(l-1,r,0,0,N);
      int ans=0;
      for(int i=0;i<30;i++){
        if(x&(1<<i)) ans++;
      }
      cout <<ans<<'\n';
    }
  }
  return (0);
}


Measured memory_bytes: 5268
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
cb=[]
for i in range(m):
    b, c = map(int, input().split())
    cb.append([c,b])
cb.sort(reverse=True)
k=0
for i in range(m):
    j=0
    while j<cb[i][1] and k+j<n and a[k+j]<cb[i][0]:
        a[k+j] = cb[i][0]
        j+=1
    k+=j
    if k==n:
        break
print(sum(a))


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

int main(){
	int N;
	scanf("%d",&N);
	int four=0;
	int not_two=0;
	int i;
	int a;
	for (i=0;i<N;i++){
		scanf("%d",&a);
		if (a%4==0){
			four++;
		}
		else if (a%2!=0){
			not_two++;
		}
	}
	if (four+not_two==N){
		if (not_two==four+1||not_two==0){
			printf("Yes\n");
		}
		else{
			printf("No\n");
		}
	}
	else{
		if (not_two<=four){
			printf("Yes\n");
		}
		else{
			printf("No\n");
		}
	}
	return 0;
}



Measured memory_bytes: 128
//Heaplax
//别让自己后悔
#include<bits/stdc++.h>
#define N 100005
#define INF 0x3f3f3f3f
#define LL long long
#define LOG(x) cerr<<#x<<" = "<<x<<endl
#define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
	while(ch=getchar(),ch<33);
	if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
	while(ch=getchar(),ch>33)x=x*10+ch-48;
	if(fs)x=-x;
}
using namespace std;
vector<pair<int,int>> s[N];
bool used[N];
int n,a[N],b[N],c[N],f[N],g[N],ans[N];
void add(int l,int r,int x)
{
	if(l>r)return;
	f[r]+=x;f[l-1]-=x;
}
int main()
{
	re(n);
	for(int i=1;i<=n;++i)
		re(a[i]),re(b[i]);
	for(int i=1;i<=n+1;++i)
		re(c[i]);
	sort(c+1,c+n+2);
	for(int i=1;i<=n;++i)
	{
		a[i]=lower_bound(c+1,c+n+2,a[i])-c,
		b[i]=lower_bound(c+1,c+n+2,b[i])-c;
		if(b[i]<a[i])
			s[a[i]-1].push_back(make_pair(b[i],i));
		add(a[i],n+1,1);
	}
	for(int i=1;i<=n+1;++i)
		add(i,n+1,-1);
	priority_queue<int,vector<pair<int,int>>,greater<pair<int,int>>> que;
	bool gg=0;
	int base=0;
	for(int i=n+1;i;--i)
	{
		f[i]+=f[i+1];
		for(auto j:s[i])que.push(j);
		s[i].clear();
		while(f[i]<-1)
		{
			if(que.empty()||que.top().first>i)
			{
				gg=1;
				break;
			}
			add(que.top().first,i,1);
			used[que.top().second]=1;
			que.pop();
			++base;
		}
	}
	memset(f,0,sizeof f);
	for(int i=1;i<=n;++i)
		add(used[i]?b[i]:a[i],n+1,1);
	for(int i=1;i<=n+1;++i)
		add(i,n+1,-1);
	for(int i=n+1;i;--i)f[i]+=f[i+1];
	for(int i=1;i<=n;++i)
		if(!used[i] && b[i]<a[i])
			s[b[i]].push_back(make_pair(a[i]-1,i));
	priority_queue<int> quee;
	for(int i=1;;++i)
	{
		if(gg)ans[i]=-INF;
		else ans[i]=n-base;
		if(i==n+2)break;
		for(auto j:s[i])
			quee.push(j.first);
		g[i]+=g[i-1];
		f[i]+=g[i];
		if(f[i]==-1)
		{
			if(quee.empty() || quee.top()<i)gg=1;
			else
			{
				++base;
				++g[i];
				--g[quee.top()+1];
				quee.pop();
			}
		}
	}
	int q;re(q);
	for(int a,b;q--;)
	{
		re(a),re(b);
		a=lower_bound(c+1,c+n+2,a)-c;
		b=lower_bound(c+1,c+n+2,b)-c;
		printf("%d\n",max(-1,max(ans[a]+1,ans[b])));
	}
}


Measured memory_bytes: 10864