akhauriyash/Code-Regression huggingface dataset:
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;
const int M = 41;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, l, r;
	cin >> n >> l >> r;
	int cnt = 0;
	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		if (x >= l && x < r) cnt++;
	}
	cout << n - cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
using Graph = vector<vector<int>>;

// 深さ優先探索
vector<bool> seen;
void dfs(const Graph &G, int v) {
    seen[v] = true;
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue;
        dfs(G, next_v); // 再帰的に探索
    }
}

int main() {
    // 頂点数と辺数
    int N, M; cin >> N >> M;

    // グラフ入力受取
    Graph G(N);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }

    // 全頂点が訪問済みになるまで探索
    int count = 0;
    seen.assign(N, false);
    for (int v = 0; v < N; ++v) {
        if (seen[v]) continue; // v が探索済みだったらスルー
        dfs(G, v); // v が未探索なら v を始点とした DFS を行う
        ++count;
    }
    cout << count-1;
}

Measured memory_bytes: 9544
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

string N;
int cnt=1,i;
inline void solve(){
  IN(N);
  REP(i,3){
    if(N[i]==N[i+1]){
      cnt++;
      if(cnt==3){
        OUT("Yes");
        return;
      }
    }else cnt=1;
  }
  OUT("No");
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};

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

struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};


void solve(){
    ll a,b;
    cin>>a>>b;
    ll ans=0;
    rep2(i,a,b+1){
        string s=to_string(i);
        string t=s;
        reverse(all(t));
        if(s==t) ans++;
    }
    cout<<ans<<endl;
}




signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;
    
    solve();

    return 0;
}


Measured memory_bytes: 256
residence_data = [[[0] * 10 for i in range(3)] for j in range(4)]

n = int(input())
newcomer_list = [input() for _ in range(n)]

for newcomer in newcomer_list:
    b, f, r, v = map(int, newcomer.split())
    residence_data[b - 1][f - 1][r - 1] += v

for i in range(4):
    for j in range(3):
        print('', *residence_data[i][j])
    if i == 3:
        break
    print('#' * 20)



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

#define db(x) cout<<#x<<"="<<(x)<<" "
#define el cout<<endl
using namespace std;

typedef long long ll;
const int MXN = 610;
const int MOD = 998244353, inv2 = MOD - MOD / 2;

int n, m;
char str[MXN][MXN];
int g[MXN][MXN] = {};
long long ans;

void solve(int n, int m) {
    //db(g[3][3]), el;
    for (int t = 0; t < n + m - 1; ++t) {
        int o = 0;
        for (int i = t; i >= 0; --i) {
            o += g[i][t - i];
            //db(i), db(o), el;
            int oo = o;
            for (int j = 0; j <= t - i; j++) {
                oo -= g[t - j][j];
                //db(oo), el;
                if (j + j + i - t >= 0)
                    if (i + i + j - t >= 0)
                        if (g[i][j + j + i - t] && g[i + i + j - t][j])
                            ans += oo;
            }
        }
    }
    memset(g, 0, sizeof(g));
}
int main() {
    scanf("%d %d\n", &n, &m);
    for (int i = 0; i < n; ++i)
        scanf("%s\n", str[i]);
    //n = m = max(n, m);
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j) {
            g[i][j] = str[i][j] == '#';
        }
    solve(n, m);
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
            g[j][n - i - 1] = str[i][j] == '#';
    solve(m, n);
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
            g[n - i - 1][m - j - 1] = str[i][j] == '#';
    solve(n, m);
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
            g[m - j - 1][i] = str[i][j] == '#';
    solve(m, n);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1920
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <iomanip>

using namespace std;

int main(void) {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed;
	cout << setprecision(20);
	int N, K;
	int p;
	cin >> N >> K;
	vector<int>v(N);
	vector<double>li(N);
	vector<double>result(N+1,0);
	double ans;
	for (int i = 0; i < N; i++) {
		cin >> p;
		v[i] = p;
	}
	for (int i = 0; i < N; i++) {
		li[i] = ((double)v[i] + 1) / 2.0;
	}
	for (int i = 1; i <=N; i++) {
		result[i] = result[i - 1] + li[i - 1];
	}
	ans = 0.;
	for (int i = K; i <= N; i++) {
		ans = max(ans, result[i] - result[i - K]);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 4224
#include <iostream>
using namespace std;
int main(void){
    long a,b,k;
    cin >> a >> b >> k;
    long temp = min(a,k);
    a -= temp;
    k -= temp;
    temp = min(b,k);
    b -= temp;
    k -= temp;
    cout << a << " " << b << endl;
}


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

int main() {
	
	string s;
	cin >> s;
	
	int ans = 100001;
	for(char p = '0'; p <= '1'; p++){
		char k = p;
		int tmp = 0;
		for(int i = 0; i < s.size(); i++){
			if(s[i] != k) tmp++;
			(k == '0') ? k = '1' : k = '0';
		}
		ans = min(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> P(N), Q(N);
    rep(i,0,N) cin >> P[i];
    rep(i,0,N) cin >> Q[i];
    vector<int> vec(N);
    rep(i,0,N) vec[i] = i+1;
    int a,b;
    int i = 0;
    do {
        i += 1;
        if (vec == P) a = i;
        if (vec == Q) b = i;
    } while (next_permutation(all(vec)));
    cout << abs(a-b) << endl;
}

Measured memory_bytes: 256
/**
 *    author:  tourist
 *    created: 17.12.2019 17:40:31       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> dp(3, 0);
  while (n--) {
    vector<int> a(3);
    for (int i = 0; i < 3; i++) {
      cin >> a[i];
    }
    vector<int> new_dp(3, 0);
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        if (i != j) {
          new_dp[i] = max(new_dp[i], dp[j] + a[i]);
        }
      }
    }
    swap(dp, new_dp);
  }
  cout << *max_element(dp.begin(), dp.end()) << '\n';
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;
const int INF = 1 << 30;
const long long MOD = 1000000000 + 7;
const double PI = 3.14159265358979323846;

int main() {
	int A, B; cin >> A >> B;
	int H, M; cin >> H >> M;
	double a = 0;
	a = 2 * PI * abs(((double)M / 60) - ((H + (double)M / 60) / 12));
	a = min(a, 2 * PI - a);
	//cout << a << endl;
	if (a == 0) {
		double ans = abs(A - B);
		cout << fixed << setprecision(15) << ans << endl;
	}
	else if (a == PI) {
		double ans = A + B;
		cout << fixed << setprecision(15) << ans << endl;
	}
	else {
		double ans = (double)A * A + (double)B * B - (double)2 * A * B * cos(a);
		ans = sqrt(ans);
		cout << fixed << setprecision(15) << ans << endl;
	}
}

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

using namespace std;
typedef long long ll;
const ll mx = 10000007;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
#define    ss   second
#define    ff   first
#define    pb   push_back
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
#define FIO ios_base::sync_with_stdio(false);  cin.tie(NULL);


int main() {
    FIO;
    ll n;
    cin >> n;
    map<ll, ll>m;
    for (ll i = 0; i < n; i++) {
        ll x;
        cin >> x;
        m[x]++;
    }

    ll ans = 0;
    for (ll i = 2; i <= 100001; i++) {
       ll tmp = 0;
        tmp += m[i] + m[i - 1] + m[i - 2];
        ans = max(ans , tmp);
    }

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


Measured memory_bytes: 9896
#include <iostream>
using namespace std;
 
int main() {
    int p, q, r;
    cin >> p >> q >> r;
    int ans;
    if (p >= q && p >= r) {
        ans = q + r;
    } else if (q >= p && q >= r) {
        ans = p + r;
    } else  {
        ans = p + q;
    }
 
    cout << ans << endl;
}

Measured memory_bytes: 256
from bisect import bisect_left,bisect_right
def main():
    N = int(input())
    A = sorted(list(map(int,input().split())))
    B = sorted(list(map(int,input().split())))
    C = sorted(list(map(int,input().split())))
    ans = 0
    for b in B:
        a = bisect_left(A,b)
        c = bisect_right(C,b)
        ans += a*(N-c)
    print(ans)

if __name__ == "__main__":
    main()

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

int main() {
	int n; cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; ++i) cin >> v[i];
	int cnt = 0;
	int b = 0;
	while(true) {
		b = v[b] - 1;
		++cnt;
		if(b == 1) break;
		if(cnt > n) 
		{
			cnt = -1;
			break;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
    int numof0=0, numof1=0;
    string input;
    cin >> input;
    for(int i=0; i<input.length(); i++){
        if(input.at(i)=='0') numof0++;
        else if(input.at(i)=='1') numof1++;
    }
    printf("%d", min(numof0,numof1)*2);
    return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long k = sc.nextLong(), a = sc.nextLong(), b = sc.nextLong();
        long now = 1;
        if (k >= (a-1)) {
            k -= (a-1);
            now += (a-1);
        } else {
            System.out.println(k + 1);
            return;
        }
        if (b - a >= 2) {
            now += (b-a)*(k/2);
            now += k % 2 == 1 ? 1 : 0;
        } else {
            now += k;
        }
        System.out.println(now);
    }
}


Measured memory_bytes: 21844
n, k = map(int, input().split())
h = [0] + list(map(int, input().split())) + [float("inf")]*(k+1)
dp = [float("inf")]*(n+k+1)
dp[0], dp[1] = 0, 0
for i in range(1,n):
    for j in range(1, k+1):
        dp[i+j] = min(dp[i+j], dp[i] + abs(h[i+j]-h[i]))
print(dp[n])


Measured memory_bytes: 58464
n, k = map(int, input().split())
s = input()
res = []
for i in s:
  res.append(i)
if res[k-1] == 'A':
  res[k-1] = 'a'
elif res[k-1] == 'B':
  res[k-1] = 'b'
else:
  res[k-1] = 'c'
print(*res, sep='')

Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
#define FAST                     \
    ios::sync_with_stdio(false); \
    cin.tie(NULL);               \
    cout.tie(NULL);
const int INF = 1e9 + 7 ;
int frogBU(vector<int> &v, int n)
{
	vector<int> dp(n,INF);
	dp[0] = 0 ;
	for ( int i = 1 ; i < n ; i ++)
	{
		int a = abs(v[i] - v[i - 1]) + dp[i - 1];
		int b = (i == 1) ? INT_MAX : abs(v[i] - v[i - 2]) + dp[i - 2];
		dp[i] = min(a, b);
	}
	return dp[n - 1];
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	// cout << INF << endl;
	
	FAST
	int n ; cin >> n ;
	vector<int> v(n) ;
	for (auto &p : v) cin >> p ;
	cout << frogBU(v, n) << endl;
	return 0 ;
}

Measured memory_bytes: 3952
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a = read::<String>().chars().collect::<Vec<char>>();
    let b = read::<String>().chars().collect::<Vec<char>>();
    let mut c = 0;
    for i in 0..3 {
        if a[i] == b[i] {
            c += 1;
        }
    }
    println!("{}", c)
}

Measured memory_bytes: 4352
N=int(raw_input())
T,A=map(int, raw_input().split())
array=map(int, raw_input().split())

#print T, A, array

temp_t = T -0.006*array[0]
temp_n = 0
for i in range(len(array)):
    temp_i = T-0.006*array[i]
    if abs(temp_t - A) > abs(temp_i -A):
        temp_t = temp_i
        temp_n = i
#        print array[i]

print temp_n+1


Measured memory_bytes: 2692
package main

import "fmt"

func main() {
	var a, b, c, k int
	fmt.Scan(&a, &b, &c, &k)
	sum := 0
	if a >= k {
		sum += k
		fmt.Println(sum)
		return
	} else {
		sum += a
		k -= a
	}

	if b >= k {
		fmt.Println(sum)
		return
	} else {
		k -= b
	}

	if c >= k {
		sum -= k
		fmt.Println(sum)
		return
	} else {
		sum -= c
	}

	fmt.Println(sum)
}


Measured memory_bytes: 1752
#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;

int main(){
  int n, s[1000];
  double sum=0, ave;

  while(1){
    cin >> n;
    if(n == 0){ break; }
    for(int i = 0; i < n; i++){
      cin >> s[i];
      sum += s[i];
    }
    ave = sum / n;
    sum = 0.0;
    for(int i = 0; i < n; i++){
      sum += pow(s[i]-ave, 2);
    }
    printf("%.8f\n", sqrt(sum / n));
    sum = 0.0;
  }

  return 0;
}



Measured memory_bytes: 3116
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
s = p[:x] + q[:y] + r
s.sort(reverse=True)
print(sum(s[:x+y]))

Measured memory_bytes: 22560
#include<stdio.h>

main(){
	int a, b, c;
	
	scanf("%d %d %d", &a, &b, &c);
	
	if(a < b){
		if(b < c)
			printf("Yes\n");
		
		else
			printf("No\n");
	}
		
	else
		printf("No\n");
	
	return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef list<ll> listl;
typedef string str;

#define min(A, B) min(static_cast<ll>(A), static_cast<ll>(B))
#define max(A, B) max(static_cast<ll>(A), static_cast<ll>(B))

#define rep(i, max) for(ll i = 0, i_max = max; i < i_max; i++)

void in(ll& I)
{
	cin >> I;
}

void in(vl& I)
{
	for (auto& i : I)
	{
		cin >> i;
	}
}

void in(listl& I)
{
	for (auto& i : I)
	{
		cin >> i;
	}
}

void in(str& s)
{
	cin >> s;
}

void out(ll& O)
{
	cout << O;
}

void out(ll O)
{
	cout << O;
}

void out(vl& O)
{
	for (auto& o : O)
	{
		cout << o;
	}
}

int main()
{
	str S;

	in(S);

	bool b = true;

	for (int i = 0; i < S.length() - 1; i++)
	{
		if (S[i] == S[i + 1])
		{
			b = false;
			break;
		}
	}

	if (b)
	{
		cout << "Good";
	}
	else
	{
		cout << "Bad";
	}
	return 0;
}

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

using namespace std;

int main()
{
	string S; 
  	cin >> S;
  	string words[4] = {"dream", "dreamer", "erase", "eraser"};
  
  	reverse(S.begin(), S.end());
  	for (int i = 0; i < 4; i++){
    	reverse(words[i].begin(), words[i].end());
    }
  
  	bool can = true;
  	for (int i = 0; i < S.size();){
    	bool can2 = false;
      	for (int j = 0; j < 4; j++){
        	string w = words[j];
          	if (S.substr(i, w.size()) == w){
            	can2 = true;
              	i += w.size();
            }
        }
    	if (!can2){
        	can = false;
          	break;
        }
    }
  	if (can) {
    	cout << "YES" << endl;
    } else {
    	cout << "NO" << endl;
    }
}


Measured memory_bytes: 512
#include <stdio.h>


struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL)x=x->left;
  return x;
}
/*
Node treeMaximum(Node x){


}
*/
Node treeSearch(Node u, int k){
  while(u!=NIL && k!=u->key){
    if(k<u->key)u=u->left;
    else u=u->right;
    
  }
  return u;

}

Node treeSuccessor(Node x){
  if(x->right != NIL)return treeMinimum(x->right);
  Node y=x->parent;
  while(y != NIL && x == y->right){
    x=y;
    y=y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left == NIL || z->right == NIL)y=z;
  else y=treeSuccessor(z);

  if(y->left != NIL)x=y->left;
  else x=y->right;

  if(x!=NIL)x->parent=y->parent;

  if(y->parent==NIL)root=x;
  else {
    if(y==y->parent->left)y->parent->left=x;
    else y->parent->right=x;
  }

  if(y != z)z->key=y->key;
  free(y);

}



void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key)x=x->left;
    else x=x->right;
  }
  z->parent=y;

  if(y==NIL)root=z;
  else if(z->key<y->key)y->left=z;
  else y->right=z;

}

void inorder(Node u){
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
     if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
     }  else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
      }
  }

  return 0;
}



Measured memory_bytes: 20448
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std;
// dfmt on

void main()
{
    auto S = sread();
    auto T = sread();
    bool eq(string s, string t)
    {
        foreach (i; 0 .. s.length)
        {
            if (s[i] == '?' || t[i] == '?' || s[i] == t[i])
                continue;
            return false;
        }
        return true;
    }

    foreach_reverse (i; 0 .. S.length - T.length + 1)
    {
        dprint(S[i .. i + T.length], T);
        if (eq(S[i .. i + T.length], T))
        {
            char[] U = new char[](S.length);
            foreach (j; 0 .. S.length)
            {
                if (i <= j && j < i + T.length)
                {
                    U[j] = T[j - i];
                    continue;
                }
                if (S[j] == '?')
                {
                    U[j] = 'a';
                    continue;
                }
                U[j] = S[j];
            }
            writeln(U);
            return;
        }
    }
    writeln("UNRESTORABLE");
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;


int main(){
    int n,m;
    cin >> n >> m;
    vector<ll> key(m);
    vector<ll> cost(m);
    rep(i,m){
        ll a,b;
        cin >> a >> b;
        ll res = 0;
        rep(i,b){
            ll c;
            cin >> c;
            res += 1<<(c-1);
        }
        key[i] = res;
        cost[i] = a;
    }
    vector<ll> dp(1<<n,LINF);
    dp[0] = 0;
    rep(bit,1<<n){
        rep(i,m){
            dp[bit|key[i]] = min(dp[bit|key[i]],dp[bit] + cost[i]);
        }
    }
    if(dp[(1<<n) -1] ==LINF) cout << -1 << endl;
    else cout << dp[(1<<n)-1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;

int H;
int c[10][5];

int main() {

  while(true) {
    cin >> H;
    if(H == 0) break;
    rep(i, H) {
      rep(j, 5) {
        cin >> c[i][j];
      }
    }

    int ans = 0;

    while(true) {
      vector<pair<pair<int, int>, int>> mem;
      rep(i, H) {
        rep(j, 3) {
          if(c[i][j] == 0) continue;
          bool ff = false;
          for(int k = 5 - j; k >= 3; k--) {
            bool f = true;
            rep(l, k - 1) {
              if(c[i][j+l] != c[i][j+l+1]) {
                f = false;
              }
            }
            if(f) {
              mem.push_back({{i, j}, k});
              ans += k * c[i][j];
              ff = true;
            }
            if(ff) {
              j = j + k - 1;
              break;
            }
          }
          if(ff) break;
        }
      }

      if(mem.size() == 0) {
        cout << ans << endl;
        break;
      }

      rep(i, mem.size()) {
        // cout << mem[i].first.first << " " << mem[i].first.second << " " << mem[i].second << endl;
        int sx, sy, k;
        sx = mem[i].first.first;
        sy = mem[i].first.second;
        k = mem[i].second;
        // cout << sx << " " << sy << " " << k << endl;
        if(sx == 0) {
          rep(j, k) {
            c[sx][sy+j] = 0;
        }
        } else {
          for(int j = 1; j <= sx; j++) {
            rep(l, k) {
              swap(c[0][sy+l], c[j][sy+l]);
            }
          }
          rep(j, k) {
            c[0][sy+j] = 0;
          }
        }
      }

    }

    // rep(i, H) {
    //   rep(j, 5) {
    //     cout << c[i][j] << " ";
    //   }
    //   cout << endl;
    // }

  }

  return 0;
}


Measured memory_bytes: 3088
#include <stdio.h>

int main(void) {
	int i,j;
	char mozi[21];
	scanf("%s",mozi);
	for(i=0;mozi[i]!=0;i++);
	for(j=i-1;j>=0;j--)printf("%c",mozi[j]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;

	public static void Main(string[] args)
	{
		var o = Input().ToInt();
		var n = o[0];
		var x = o[1];
		int wa = 0;
		int min = 99999;
		for(int i = 0; i < n; i++)
		{
			var m = Console.ReadLine().ToInt();
			wa += m;
			min = Math.Min(m, min);
		}
		Console.WriteLine(n+((x - wa) / min));
	}

	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}


Measured memory_bytes: 11220
s=input()
q=int(input())
queries = []
rev = [0]*q
flag=0
for i in range(q):
    query = list( input().split() )
    queries.append( query )
    if query==["1"]:
        flag+=1
    rev[i]=flag

n_rev = flag
from collections import deque
left=deque([])
right=deque([])
for r,query in zip(rev,queries):
    if query!=["1"]:
        q1 = query[1]
        q2 = query[2]
        if (r+n_rev)%2==0:
            if q1=="1":
                left.appendleft(q2)
            else:
                right.append(q2)
        else:
            if q1=="1":
                right.append(q2)
            else:
                left.appendleft(q2) 
#     print(i,left,s,right)
if n_rev%2==1:
    s=s[::-1]
print("".join(["".join(left),s,"".join(right)]) )

Measured memory_bytes: 110936
import java.util.*;
public class Main{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int a,b,c;
		int output = 0;
		for(a = 1;a<=num;a++)
			for(b = 1;b<=num;b++)
				for(c = 1;c<=num;c++)
					output += gcd(gcd(a,b),c);
		System.out.println(output);
	}
	
	public static int gcd(int p, int q)
	{
		if(q == 0)
		{
			return p;
		}
		return gcd(q,p%q);
	}

}

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

#define ll unsigned long long
#define rep(i, a, n) for (ll i = a; i < n; i++)
#define repm(i, a, n) for (ll i = a; i >= n; i--)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define mod (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vd vector<double>
#define vb vector<bool>
#define vs vector<string>
#define vii vector<vector<int>>
#define vllll vector<vector<ll>>
#define ALL(a) (a).begin(), (a).end()

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

void print(bool f)
{
    cout << (f ? "Yes" : "No") << endl;
}

void Print(bool f)
{
    cout << (f ? "YES" : "NO") << endl;
}

int main(void)
{
    ll a, k;
    double b;
    cin >> a >> b;
    if (a != 0 && b != 0)
    {
        k = b * 1000;
        a *= k;
        a /= 1000;
        cout << a << endl;
    }
    else
    {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 3728
def solve():
    N,X = map(int, input().split())
    L = list(map(int, input().split()))
    D = [0]
    for i in range(N):
        D.append(D[i]+L[i])
    print(len([x for x in D if x<=X]))

if __name__ == '__main__':
    solve()

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



int main(){
    int n;
    cin >> n;
    map<int, int> mp;
    for (int i = 0; i < n; i++){
        int a;
        cin >> a;
        mp[a]++;
    }

    int ans = 0;
    for (auto i : mp){
        if (i.second % 2) ans++;
    }

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

Measured memory_bytes: 4864
n,X=map(int,input().split())
x=list(map(int,input().split()))
def gcd(x,y):
    if x%y==0:
        return y
    else:
        return gcd(y,x%y) 
ans=abs(x[0]-X)        
for i in range(1,n):
    ans=gcd(ans,abs(x[i]-X))
print(ans)

Measured memory_bytes: 15020
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int N;
	cin >> N;
  	int64_t sum=0;
	for(int i = 0;i<N;i++){
      if(((i+1)%3 != 0)&&((i+1)%5 != 0)){
      	sum = sum + i +1;
      }
    }
  	
  cout << sum << endl;
}

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

int main()
{
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i = 0;i < N;i++){
        cin >> a[i];
    }
    vector<pair<int, int>> all;
    for(int i = 0;i < N;i++){
        all.emplace_back(-a[i], i);
    }
    sort(all.begin(), all.end());
    vector<bool> used(N);
    int cnt = 0, res = 0;
    for(int i = 0;i < N;){
        int v = all[i].first;
        if(v == 0) break;
        while(all[i].first == v){
            int id = all[i].second;
            ++i;
            ++cnt;
            cnt -= (id + 1 < N && used[id + 1]);
            cnt -= (0 <= id - 1 && used[id - 1]);
            used[id] = true;
        }
        res = max(res, cnt);
    }
    cout << res << endl;
    return 0;
}



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

using namespace std;

using ll = long long;

#define ALL(A) A.begin(),A.end()

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

    double ans = (double)(L * L * L) / 27.0;

    printf("%11.9f\n",ans);

    return 0;
}

Measured memory_bytes: 256
const main = (input) => {
  var a = input[0]-0;
  var b = input[1].split(" ").map(v=>v-0).sort((a,b)=>a-b);
  var ans = 0;
  for(var i=0;i<a-1;i++){
    b[i+1] = (b[i] + b[i+1])/2;
  }
  console.log(b[a-1]);
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8').trim().split("\n"));


Measured memory_bytes: 21064
<?php

$n = fgets(STDIN);
$as = trim(fgets(STDIN));
$as = explode(' ', $as);
foreach ($as as $i => $a) {
    $as[$i] = (int) $a;
}

$xor = 0;
$fs = [];
for ($i = 0; $i < count($as); $i++) {
    $xor ^= $as[$i];
    $fs[$i] = $xor;
}

$xor = 0;
$bs = [];
for ($i = count($as) - 1; $i >= 0; $i--) {
    $xor ^= $as[$i];
    $bs[$i] = $xor;
}

$rs = [];
for ($i = 0; $i < count($as); $i++) {
    $f = $fs[$i - 1] ?? 0;
    $b = $bs[$i + 1] ?? 0;
    $rs[] = $f ^ $b;
}

print implode(' ', $rs);


Measured memory_bytes: 57448
#include<iostream>
#include<algorithm>

int main(){
  int N;
  long long C;
  std::cin >> N >> C;

  const int maxCntSushi = 100050;
  long long x[maxCntSushi] = {0};
  long long v[maxCntSushi] = {0};
  for (int i=1;i<=N;i++) std::cin >> x[i] >> v[i];

  long long totalCal;
  //時計回りに動いた際に始点～各xの範囲で得られる最大カロリー
  long long getCalA[maxCntSushi] = {0};
  long long getCal2A[maxCntSushi] = {0};
  getCalA[0] = 0;
  getCal2A[0] = 0;
  totalCal = 0;
  for (int i=1;i<=N;i++) {
    getCalA[i]  = std::max(getCalA[i-1],v[i]+totalCal-x[i]);   //始点へ引き返さない場合
    getCal2A[i] = std::max(getCal2A[i-1],v[i]+totalCal-x[i]*2); //始点へ引き返す場合
    totalCal += v[i];
  }

  //半時計周りに動いた際に始点～各xの範囲で得られる最大カロリー
  long long getCalB[maxCntSushi] = {0};
  long long getCal2B[maxCntSushi] = {0};
  getCalB[N] = 0;
  getCal2B[N] = 0;
  totalCal = 0;
  for (int i=N-1;i>=0;i--) {
    getCalB[i]  = std::max(getCalB[i+1],v[i+1]+totalCal-(C-x[i+1]));
    getCal2B[i] = std::max(getCal2B[i+1],v[i+1]+totalCal-(C-x[i+1])*2);
    totalCal += v[i+1];
  }

  long long maxCal = 0;
  for (int i=0;i<=N;i++) {
    //std::cout << "i=" << i << ": A:" << getCalA[i] << " 2A:" << getCal2A[i] << " B:" << getCalB[i] << " 2B:" << getCal2B[i] << std::endl;
    maxCal = std::max(maxCal,getCalA[i] +getCal2B[i]);
    maxCal = std::max(maxCal,getCal2A[i]+getCalB[i] );
  }

  std::cout << maxCal << std::endl;

  return 0;
}


Measured memory_bytes: 4992
/*/ Author:amar1503/*/
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("Ofast")
#define fio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ull unsigned long long
#define ll long long
#define inf INT_MAX
#define mninf INT_MIN
#define Mod 1000000007
#define endl "\n"
#define cp(x) cout<<(x)<<" "
#define cl(x) cout<<(x)<<endl
#define ct(x,y) cout<<(x)<<" "<<(y)<<endl;
#define nl   cout<<endl
//const double PI=3.1415926535897932384626433832;
//looping
#define For(i,a,b) for(int i=a;i<b;i++)
#define test(t)  int (t); cin>>(t); while((t)--)
#define array(a,n) int (n); cin>>(n); int a[n]; for(int i=0;i<(n);i++) cin>>a[i];
#define trace(x) clog<<#x<<": "<<x<<" "<<endl
#define trace2(x,y) clog<<#x<<": "<<x<<"     "<<#y<<" "<<y<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define printa(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define printv(v)  for(int i=0;i<(v).size();i++) cout<<v[i]<<" "
//containers
#define F first
#define S second
#define pb emplace_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define all(v) (v).begin(),(v).end()
#define mp make_pair
#define itr(it, a) for(auto it = (a).begin(); it != (a).end(); it++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ers(v)   sort(all(v)); (v).erase(unique(all(v)),(v).end())
#define printmatrix(a,n,m) for(int i=0;i<n;i++){ for(int j=0;j<m;j++) cout<<a[i][j]<<" "; cout<<endl;}
typedef vector<int> vi;
typedef vector< vector< int > > vvi;
typedef pair <int, int> pii;
typedef vector < pair <int, int> > vpii;
// cout<<"\nTime Elapsed : " << 1.0*clock() /CLOCKS_PER_SEC << " s\n";
#define int long long
/*/-----------------------------Code begins----------------------------------/*/
int32_t main(){
fio;
array(a,n);
int mean=accumulate(a,a+n,0)/n;
int sum=0,sum1=0;
For(i,0,n){
sum+=(a[i]-mean)*(a[i]-mean);
sum1+=(a[i]-(mean+1))*(a[i]-(mean+1));}
cout<<min(sum,sum1);}




















Measured memory_bytes: 256
import sys
input = sys.stdin.readline

import heapq as hp

N, M, S, G = map(int, input().split())
graph_y = [[] for _ in range(N)]
graph_s = [[] for _ in range(N)]
for _ in range(M):
    a, b, c, d = map(int, input().split())
    graph_y[a-1].append((c, b-1))
    graph_y[b-1].append((c, a-1))
    graph_s[a-1].append((d, b-1))
    graph_s[b-1].append((d, a-1))

INF = 10**18

def dijkstra(graph, s):
    D = [INF for _ in range(N)] # 頂点iへの最短距離がD[i]
    D[s] = 0 
    q = [] # しまっていく優先度付きキュー
    hp.heappush(q, (0, s))

    while q:
        nd, np = hp.heappop(q) # 一番距離が近いものを取ってくる
        if D[np] < nd: # 追加した後の残骸は見ない
            continue
        for d, p in graph[np]:
            if D[p] > D[np] + d: # 隣接するやつの中で今よりも近くなれるなら更新
                D[p] = D[np] + d
                hp.heappush(q, (D[p], p))
    
    return D

Ds = dijkstra(graph_y, S-1)
Dg = dijkstra(graph_s, G-1)

ans = [None]*N
ans[N-1] = Ds[N-1] + Dg[N-1]
for n in reversed(range(N-1)):
    ans[n] = min(ans[n+1], Ds[n]+Dg[n])

for a in ans:
    print(10**15-a)

Measured memory_bytes: 107644
N, x = map(int, raw_input().split())
A = map(int, raw_input().split())

ans = 0
for i in xrange(N):
    if A[i] > x:
        ans += A[i] - x
        A[i] = x

for i in xrange(N-1):
    if A[i] + A[i+1] > x:
        ans += A[i] + A[i+1] - x
        A[i+1] -= A[i] + A[i+1] - x
    #print A, ans

print ans


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

#define STR_MAX 1000

int mat[STR_MAX+1][STR_MAX+1];

int common_subsequence(int len1, int len2, string str1, string str2){
  int i, j;

  for(i=1; i<=len1; i++){
    for(j=1; j<=len2; j++){
      if(str1[i-1] == str2[j-1]) mat[i][j]=mat[i-1][j-1]+1;
      else mat[i][j]=max(mat[i-1][j], mat[i][j-1]);
    }
  }

  return mat[len1][len2];
}

int main(void){
  int i, n;
  string str1, str2;

  scanf("%d", &n);
  for(i=0; i<n; i++){
    cin >> str1 >> str2;

    int len1=str1.size(), len2=str2.size();
    printf("%d\n", common_subsequence(len1, len2, str1, str2));
  }
  
  return 0;
}



Measured memory_bytes: 7060
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}


int main(){
  int n,m;
  cin>>n>>m;
  vector<int> v;
  for(int i = sqrt(m); i >= 1; i--){
    if(m%i==0){
      v.push_back(i);
      if(i*i!=m){
      v.push_back(m/i);
    }
  }
    }
    
  sort(v.begin(),v.end());
  for(auto a: v){
    if(a>=n){
      cout<<m/a<<endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <set>

using namespace std;
using ll = long long;

typedef pair<ll, ll> P;

const int MOD = 1000000007;
const ll INF = 1LL << 60;


// LRUD
const int dx[4] = {-1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
// const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
// const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

vector<vector<int> > vvi;
vector<vector<vector<int> > > vvvi;

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }


int main(int argc, char**argv){
    ll n;
    cin >> n;
    vector<pair<ll, ll> > ba;
    for (int i = 0; i < n; i++){
        ll a, b;
        cin >> a >> b;
        ba.push_back(make_pair(b, a));
    }

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

    ll elapsed_time = 0;
    for (int i = 0; i < n; i++){
        ll a = ba[i].second;
        ll b = ba[i].first;
        elapsed_time += a;
        if (elapsed_time <= b) continue;
        else {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}





















Measured memory_bytes: 6512
while True:
    try:
        n = input()
        if n == 0:
            break
        else:
            before = []
            after = []
            for i in range(n):
                lst = raw_input().split(' ')
                before.append(lst[0])
                after.append(lst[1])
            m = input()
            ans = ''
            for i in range(m):
                value = raw_input()[0]
                try:
                    ans += after[before.index(value)]
                except ValueError:
                    ans += value
            print ans
    except EOFError:
        break


Measured memory_bytes: 7368
N  = int(input())
x = map(int,input().split())
count=0
check = 0
NEW_x=[]

def roop(N,x):
    global check
    global NEW_x
    for i in x:
        s = i//2
        if i%2==0:
            check +=1
            
            NEW_x.append(s)


        else:
            NEW_x.append(s)

roop(N,x)

while True:
  
    x = NEW_x
    NEW_x = []
    if check ==N:
        check=0
        count+=1
        roop(N,x)
    else:
        break

print(count)

Measured memory_bytes: 9212
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
inline int read(){
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=(x<<3)+(x<<1)+c-'0';
        c=getchar();
    }
    return x*f;
}
char s[10];
int main(){
	scanf("%s",s+1);
	if(s[3]==s[4]&&s[5]==s[6]){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mid (tl+tr)/2
#define mod 1000000007
#define fain(arr) for(int i=0;i<n;i++)cin>>arr[i];
#define all(x) x.begin(),x.end()
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define bugv(n1) if(DEBUG)cout<<#n1<<" is "<<n1<<'\n';
#define buga(A) cout<<#A<<" is :"<<endl ; for(auto x:A)cout<<x<<" "; cout<<endl;
#define FILE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define endl '\n'
#define ll long long 
#define pii pair<int,int>
#define pll pair<long long ,long long >
#define pi acos(-1)
#define sz(x) ((int)x.size())
#define clr(x) memset(x, 0, sizeof(x))
#define init(x, a) memset(x, a, sizeof(x))
#define DEBUG true
using namespace std;

int main(){
	// FILE;
	SPEED;
	int n;
	cin>>n;

	bool p = false;

	while(n){
		if(n%10==7)p=true;
		n/=10;
	}

	if(p){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}


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

int main() {
 int A, B, C;
 cin >> A >> B >> C;
 if (A<C && C<B){
   cout << "Yes" << endl;
 }
 else if (B<C && C<A){
   cout << "Yes" << endl;
 }
 else {
   cout << "No" << endl;
 }
}

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

using namespace std;

using ll = long long;
constexpr ll MOD = 1e9 + 7;

struct RangeSumQuery
{
    using type = ll;
    static type id() { return 0; }
    static type op(const type &l, const type &r) { return (l + r) % MOD; }
};

template <typename M>
class SegmentTree
{
    using T = typename M::type;
    int n;
    std::vector<T> node;

public:
    // v を基に初期化
    SegmentTree(const std::vector<T> &v)
    {
        // n は v.size() 以上の最小の2冪
        n = 1;
        while (n < int(v.size()))
            n *= 2;
        node.resize(2 * n, M::id());

        // i の子 -> 2*i+1, 2*i+2 , 親 -> (i-1)/2
        for (int i = 0; i < int(v.size()); i++)
            node[i + n] = v[i];
        for (int i = n - 1; i >= 0; i--)
            node[i] = M::op(node[2 * i], node[2 * i + 1]);
    }
    // Monoid::id 初期化
    SegmentTree(int _n)
    {
        // n は v.size() 以上の最小の2冪
        n = 1;
        while (n < _n)
            n *= 2;
        node.resize(2 * n, M::id());
    }
    // x 番目を val に更新
    void update(int x, T val)
    {
        x += n;
        node[x] = val;
        while (x >>= 1)
        {
            node[x] = M::op(node[2 * x], node[2 * x + 1]);
        }
    }
    // v[x] を M::op(v[x], val) に更新
    void operation(int x, T val)
    {
        x += n;
        node[x] = M::op(node[x], val);
        while (x >>= 1)
        {
            node[x] = M::op(node[2 * x], node[2 * x + 1]);
        }
    }
    // [a, b) の op
    T query(int l, int r)
    {
        l += n;
        r += n;
        T retl = M::id(), retr = M::id();
        while (l < r)
        {
            if (l & 1)
                retl = M::op(retl, node[l++]);
            if (r & 1)
                retr = M::op(node[--r], retr);
            l >>= 1;
            r >>= 1;
        }
        return M::op(retl, retr);
    }
};

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

    int n, k;
    cin >> n >> k;
    int sq = (int)floor(sqrt(n));
    vector<ll> cnt(2 * sq + 1, 1);
    cnt[0] = 0;
    for (int i = 1; i <= sq; i++)
    {
        cnt[2 * sq - i + 1] = n / i % MOD;
        if (i != 1)
            cnt[2 * sq - i + 2] = (cnt[2 * sq - i + 2] + MOD - n / i) % MOD;
    }
    cnt[sq + 1] = (cnt[sq + 1] + MOD - sq) % MOD;
    SegmentTree<RangeSumQuery> st(2 * sq + 1);
    vector<SegmentTree<RangeSumQuery>> dp(k, st);
    dp[0] = SegmentTree<RangeSumQuery>(cnt);
    for (int i = 1; i < k; i++)
    {
        for (int j = 1; j <= 2 * sq; j++)
        {
            dp[i].update(j, cnt[j] * dp[i - 1].query(1, 2 * sq + 2 - j) % MOD);
        }
    }
    cout << dp[k - 1].query(1, 2 * sq + 1) << endl;
}


Measured memory_bytes: 105600
#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int e = 1e6;
const ll mod = 1e9 + 7;
ll a[e];

int main()
{
    int n;
    cin >> n;
    ll s = 0;
    for(int i=1; i<=n; i++){
        cin >> a[i];
    }
    sort(a+1, a+n+1, greater<ll>());
    priority_queue<ll>pq;
    ll ans = a[1];
    for(int i=3; i<=n; i++){
        int hs = i / 2;
        if (i % 2 != 0) ++ hs;
        ans += a[hs];
    }
    cout << ans;
}


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

const int inf = 1e9;
const ll linf = 1e18;

bool is_prime(int x) 
{
    if (x < 2) return false;
    if (x == 2) return true;
    if (x % 2 == 0) return false;

    for (int i = 3; i * i <= x; i += 2) {
        if (x % i == 0) return false;
    }
    return true;
}

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

    int x; cin >> x;
    while (!is_prime(x)) x++;
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 256
from itertools import accumulate
import bisect
N = int(input())
A= list(map(int,input().split()))
B= list(map(int,input().split()))
diff = [i-j for i,j in zip(B,A)]
p = [i for i in diff if i > 0]
m = sorted([-i for i in diff if i < 0],reverse=1)
msum = list(accumulate(m))
if sum(A) < sum(B):
    print(-1)
elif not p:
    print(0)
else:
    count = len(p)
    rem = sum(p)
    count += bisect.bisect_left(msum,rem)+1
    print(count)

Measured memory_bytes: 20596
#include<bits/stdc++.h>
using namespace std;
#define w(t) int t;cin>>t;while(t--)
#define pb   push_back
#define mk   make_pair
typedef long long ll;
const ll mod=1e9+7;
char grid[1002][1002];

int solve(int n,int m){
   int dp[n+1][m+1];
   dp[n][m]=1;
   for(int i=n;i>=1;i--){
   	for(int j=m;j>=1;j--){
   		if(i==n && j==m)continue;
   		if(grid[i][j]=='#'){
   			dp[i][j]=0;
   			continue;
   		}
   		dp[i][j]=( ( (i==n)? 0:dp[i+1][j])+ ((j==m) ? 0 :dp[i][j+1]) )%mod;
   		
   	}
   }
   return dp[1][1];
}


int main()
{

	ios_base::sync_with_stdio(false); 
	cin.tie(nullptr); 
	cout.tie(nullptr);
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
    	for(int j=1;j<=m;j++){
    		cin>>grid[i][j];
    	}
    }
    cout<<solve(n,m);
   
    return 0; 
}




Measured memory_bytes: 5120