akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

int linearSearch(int*,int);

  int n;
  
int main(){
  int i,q,*S,*T,C=0;
  scanf("%d",&n);
  S=(int*)malloc(sizeof(int)*n);
  for(i=0;i<n;i++)
    scanf("%d",&S[i]);
  scanf("%d",&q);
  T=(int*)malloc(sizeof(int)*(q+1));
  for(i=0;i<q;i++)
    scanf("%d",&T[i]);
  for(i=0;i<q;i++){
    C+=linearSearch(S,T[i]);
  }
  printf("%d\n",C);
  return 0;
}

int linearSearch(int *S,int key){
  int i=0;
  S[n]=key;
  while(S[i]!=key){
    i++;
  }
  if(i==n){
    return 0;
  }
  else
    return 1;
}

Measured memory_bytes: 636
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <utility>
using namespace std;


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

Measured memory_bytes: 512
# -*- coding: utf-8 -*-
"""
Created on Tue Feb  4 00:34:00 2020

@author: yama
"""

n, y = map(int, input().split())

f = False
for i in range(n+1):
    for j in range(n-i+1):
        k = (y - (i*10000 + j*5000))//1000
        if i + j + k == n and i*10000 + j*5000 + k*1000 == y:
            f = True
            break
    if f == True:
        break
    
if f == True:
    print(i, j, k)
else:
    print("-1 -1 -1")
        

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

class Main {
	public static void main(String[] args)
	{
		FastScanner in=new FastScanner();
		int d=in.nextInt();
		int t=in.nextInt();
		int s=in.nextInt();
		if((t*s)>=d)
			System.out.println("Yes");
		else
			System.out.println("No");
	}

static final Random random=new Random();
	
	static void ruffleSort(int[] a) {
		int n=a.length;//shuffle, then sort 
		for (int i=0; i<n; i++) {
			int oi=random.nextInt(n), temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}
	
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 32704
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vvl = vector<vector<ll>>;
using vl  = vector<ll>;
#define _GLIBCXX_DEBUG
#define acc_io cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(ll i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
#define DBG(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
const ll MOD = 1000000007;
const double PI = acos(-1);  
//name[i]   -> vl  name(i)
//name[i][j]-> vvl name(i,vl(j))
//or-> ||
//map<int,int>mp

signed main(){
	acc_io;
	int h,w;
	cin>>h>>w;
	string s;
	rep(i,0,h){
		cin>>s;
		cout<<s<<endl;
		cout<<s<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
    
    int n;
    cin>>n;
    vector<int>values;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        values.push_back(x);
    }
    int min_sum = 1000000;
    for(int i=1;i<150;i++){
        int sum1=0;
        int sum2=0;
        for(int j=0;j<n;j++){
            if(j>i){
                sum1+=values[j];
            }else{
                sum2+=values[j];
            }
        }
        min_sum=min(min_sum,abs(sum1-sum2));
    }
    cout<<min_sum<<endl;
    return 0;
}


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

typedef int64_t i64;
typedef uint64_t ui64;

const int inf=1073741823;
const i64 llinf=4611686018427387903LL;

int main(void){
    int a,b;
    scanf("%i%i",&a,&b);
    printf("a %s b\n",a<b?"<":(a>b?">":"=="));
    return 0;
}



Measured memory_bytes: 3184
n = int( input() )
a = list( map( int, input().split() ) )

for x in a:
    if x % 2 == 0:
        if x % 3 == 0:
            continue
        if x % 5 == 0:
            continue
        print( "DENIED" )
        break
else:
    print( "APPROVED" )

Measured memory_bytes: 9176
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, m;
    cin >> n >> m;
    long long dp[n + 5][m + 5];
    long long mod = 1e9 + 7;
    char s[n + 5][m + 5];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> s[i][j];
        }
    }
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= m; j++){
            if(i == 0 || j == 0){
                dp[i][j] = 0;
            }
            else if(i == 1 && j == 1){
                dp[i][j] = 1;
            }
            else if(s[i - 1][j - 1] == '#'){
                dp[i][j] = 0;
            }
            else{
                dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
            }
        }
    }
    cout << dp[n][m];
    return 0;
}

Measured memory_bytes: 9088
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n;
  int sum_x = 0;
  cin >> n;
  vector<int> x(n);
  for (int i = 0; i < n; ++i) {
    int x_i;
    cin >> x_i;
    sum_x += x_i;
    x.at(i) = x_i;
  }
  int p = sum_x / (double)n + 0.5;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    ans += (x.at(i) - p) * (x.at(i) - p);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef vector<double> dvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
#define fs first
#define sc second
int main()	{
  char c;
  cin>>c;
  if(c=='A'||c=='B'||c=='C'||c=='D'||c=='E'||c=='F'||c=='G'||c=='H'||c=='I'||c=='J'||c=='K'||c=='L'||c=='M'||c=='N'||c=='O'||c=='P'||c=='Q'||c=='R'||c=='S'||c=='T'||c=='U'||c=='V'||c=='W'||c=='X'||c=='Y'||c=='Z')
    cout<<'A'<<endl;
  else
    cout<<'a'<<endl;
}

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

int main() {
	long long n,k, sum=0;
	cin>>n>>k;
	vector <long long> h(n);
	for(long long i=0; i<n; i++)
	{
		cin>>h[i];
	}
	sort(h.begin(),h.end());
	for(long long i=0; i<n-k; i++)
	{
		sum+=h[i];
	}
	cout<<sum;
}

Measured memory_bytes: 1792
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws java.io.IOException {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		Integer[] cal = new Integer[n];
		for (int i = 0; i < n; i++) {
			cal[i] = sc.nextInt();
		}Arrays.sort(cal, new Comparator<Integer>() {
            public int compare(Integer a, Integer b) {
                return b-a;
            }});

		double max = 0;
		for (int i = 0; i <= n; i++) {
			int sum = c;
			for (int j = 0; j < i; j++) {
				sum += cal[j];
			}
			max = Math.max(max, 1.0 * sum / (a + i * b));
		}
		System.out.println((int)max);
	}
}

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

using namespace std;

typedef long long ll;
// const ll mod = 1000000007;

int main() {
  int n,m;
  cin>>n>>m;
  vector<vector<ll>> v(8);
  for (int i = 0; i < n; i++) {
    ll x,y,z;
    cin>>x>>y>>z;
    for (int i = 0; i < 1 << 3; i++) {
      ll res = (((i >> 2) & 1) ? x : -x);
      res += (((i >> 1) & 1) ? y : -y);
      res += (((i >> 0) & 1) ? z : -z); 
      v[i].push_back(res);
    }
  }
  for (int i = 0; i < 8; i++) sort(v[i].rbegin(),v[i].rend());
  ll ans = 0;
  for (int i = 0; i < 8; i++) {
    ll tmp = 0;
    for (int j = 0; j < m; j++) tmp += v[i][j];
    ans = max(ans, tmp);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
using namespace std;
int dp[11111];
int W,w[222],n,M=1e9+7;
main()
{
	cin>>n>>W;
	for(int i=0;i<n;i++)
	{
		cin>>w[i];
		W-=w[i];
	}
	sort(w,w+n,greater<int>());
	int ans=0;
	dp[0]=1;
	for(int i=0;i<n;i++)
	{
		W+=w[i];
		for(int j=10000-w[i];j>=0;j--)dp[j+w[i]]=(dp[j+w[i]]+dp[j])%M;
		for(int j=W-w[i+1];j>=0&&j>W-w[i];j--)ans=(ans+dp[j])%M;
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
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; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = 1'000'000'007;
// const ll MOD = 998244353;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

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

    ll ans = 0;
    ll maxx = -1;
    rep(i,N){
        ans += max(0LL, maxx  - A[i]);
        chmax(maxx, A[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 4776
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Main {
	
	public static void main(String[] args) throws IOException {
		try(Scanner sc = new Scanner(System.in)){
			final long N = sc.nextLong();
			final long A = sc.nextLong();
			final long B = sc.nextLong();
			
			if(N == 1 && A == B){
				System.out.println(1);
			}else if(A > B){
				System.out.println(0);
			}else if(N == 1){
				System.out.println(0);
			}else if(N == 2){
				System.out.println(1);
			}else{
				System.out.println(1 + (B - A) * (N - 2));
			}
		}
	}
	
	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;
 
		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}
 
		private void getLine() throws IOException {
			while (!hasNext()) {
				tok = new StringTokenizer(br.readLine());
			}
		}
 
		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}
 
		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
		
		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}
		
		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}
 
		public void close() throws IOException {
			br.close();
		}
	}
}

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

int main(void){
    int n;
    int ans;
    
    cin >> n;
    
    ans = n*n*n;
    
    cout << ans ;
    
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct node{int parent,left,right;};

struct node Tree[MAX];
int n,D[MAX],H[MAX];

void print(int);
void Depth(int,int);
int Height(int);
int Sibling(int);


int main()
{
  int i,id,left,right,root=0;
  scanf("%d",&n);

   for(i=0;i<n;i++){
    Tree[i].parent=NIL;}
   
  for(i=0;i<n;i++){
    scanf("%d%d%d",&id,&left,&right);
    Tree[id].left = left;
    Tree[id].right = right;
    if(left != NIL)Tree[left].parent=id;
    if(right != NIL)Tree[right].parent=id;
                  }
  for(i=0;i<n;i++)
    {if(Tree[i].parent==NIL)root=i;  }

  Depth(root,0);
  Height(root);
  
  for(i=0;i<n;i++) print(i);
  return 0;
}

void Depth(int u,int d)
{
  if(u==NIL)return;
  D[u]=d;

  Depth(Tree[u].left,d+1);
  Depth(Tree[u].right,d+1);
}

int Height(int u)
{
  int h1=0,h2=0;
  if(Tree[u].left != NIL)
    h1=Height(Tree[u].left)+1;
  if(Tree[u].right != NIL)
    h2=Height(Tree[u].right)+1;
  if(h1>h2)H[u]=h1;
  else H[u]=h2;

  return H[u];
}

int Sibling(int u)
{
  if(Tree[u].parent == NIL)return NIL;
  if(Tree[Tree[u].parent].left !=u &&Tree[Tree[u].parent].left != NIL)
    return Tree[Tree[u].parent].left;
  if(Tree[Tree[u].parent].right !=u &&Tree[Tree[u].parent].right != NIL)
    return Tree[Tree[u].parent].right;
  return NIL;
}

void print(int u)
{
  printf("node %d: ",u);
  printf("parent = %d, ",Tree[u].parent);
  printf("sibling = %d, ",Sibling(u));
  int deg=0;
  if(Tree[u].left!=NIL)deg++;
  if(Tree[u].right!=NIL)deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);

  if(Tree[u].parent==NIL)printf("root\n");
  else if(Tree[u].left == NIL && Tree[u].right == NIL)printf("leaf\n");
  else  printf("internal node\n");
}



Measured memory_bytes: 2148
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        
        int d = a + b;
        int e = a + c;
        int f = b + c;
        
        if (d >= e) {
            if (e >= f) {
                System.out.println(f);
            } else {
                System.out.println(e);
            }
        } else {
            if (d >= f)
                System.out.println(f);
            else {
                System.out.println(d);
            }
        }
        
    }
    
}


Measured memory_bytes: 21204
#include <iostream>

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

    for(int i = 1; i < 10; i++) {
        for(int j = 1; j < 10; j++) {
            if(N == i * j) {
                std::cout << "Yes" << std::endl;
                return 0;
            }
        }
    }

    std::cout << "No" << std::endl;
    return 0;
}

Measured memory_bytes: 888
#include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define FOR(i, n) for (int i = 0; i < n; i++)
int main() {
  ll n, k;
  cin >> n >> k;
  // ll a,b,c;
  // string s;
  vector<ll> h(n);
  FOR(i, n) cin >> h[i];
  sort(h.begin(), h.end());
  ll ans = 1000000000; 
  for(int i =0; i+k-1<n;i++){
    ans = min(ans,h[i+k-1]-h[i]);
  }

  //  cout << ((  )? "YES" : "NO) <<endl;
  //  cout << ((  )? "Yes" : "No) <<endl;
    cout << ans <<endl;
  return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++) a[i] = sc.nextInt();
		int[] ary = new int[500000];
		int left = 250000;
		int right = left + 1;
		for(int i = 0 ; i < n ; i++) {
			if((n + 1) % 2 == i % 2) {
				ary[left--] = a[i];
			} else {
				ary[right++] = a[i];
			}
		}
		for(int i = 0 ; i < n ; i++) {
			System.out.print(ary[left + i + 1] + " ");
		}
	}
}


Measured memory_bytes: 99228
n = int(input())
a = [int(input()) for i in range(n)]
#print(a)
s = sorted(a)[::-1]
#print(s)
n1 = s[0]
n2 = s[1]
#n1 = nの最大値  n2 = 二番目
for i in a:
  if i == n1 and n2 != n1:
    print(n2)
  else:
    print(n1)


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll N, A, B; cin >> N >> A >> B;
  if ((A + B) % 2 == 0) {
    cout << (B - A) / 2 << endl;
  } else {
    ll ans = 8e18;
    ll x = (B - (A - 1) - 1 - 1) / 2 + (A - 1) + 1;
    ll y = (N - (A + (N - B) + 1)) / 2 + (N - B) + 1;
    cout << min(x, y) << endl;
  }
}


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



int main(){
    int h, w;   cin >> h >> w;
    vector<vector<char>> g(h, vector<char>(w));
    vector<vector<int>> cost(h, vector<int>(w, -1));
    queue<pair<int, int>> que;

    for(int i=0; i<h; i++)
        for(int j=0; j<w; j++){
            cin >> g.at(i).at(j);
            if(g.at(i).at(j)=='#'){
                que.push({i, j}); cost[i][j]=0;
            }
        }


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

    
    while(!que.empty()){
        int x = que.front().first, y = que.front().second;
        que.pop();
        for(int i=0; i<4; i++){
            int nx = x+dx[i], ny = y+dy[i];
            if(nx<0 || ny<0 || h<=nx || w<=ny) continue;
            if(cost[nx][ny]!=-1) continue;
            cost[nx][ny] = cost[x][y] + 1;
            que.push({nx, ny});
        }
    }
    int res=0;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            res = max(res, cost[i][j]);
        }
    }

    cout << res << endl;
    
}




Measured memory_bytes: 13328
import std.stdio, std.conv, std.string, std.math, std.algorithm;

void main(){
	auto ip = readln.split.to!(int[]);
	if(ip[0] + ip[1] < 24) (ip[0] + ip[1]).writeln;
	else (ip[0] + ip[1] - 24).writeln;
}

Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, x = list(map(int, readline().split()))
    l = [0] * (n + 1)
    b = [0] * (n + 1)

    l[0] = 1
    b[0] = 1

    for i in range(1, n + 1):
        l[i] = 2 * l[i - 1] + 3
        b[i] = 2 * b[i - 1] + 1

    ans = 0
    rem = x
    level = n

    while rem and level > 0:
        if rem >= l[level - 1] + 2:
            ans += b[level - 1] + 1
            rem -= (l[level - 1] + 2)
            level -= 1
        elif rem == l[level - 1] + 1:
            rem -= (l[level - 1] + 1)
            ans += b[level - 1]
        else:
            rem -= 1
            level -= 1

    if level == 0 and rem:
        ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
int main(){
	ll L,R;
	cin>>L>>R;
	if(R-L>=2019){
		cout<<0<<endl;
		return 0;
	}
	vector<ll> mv;
	for(int i=L;i<=R;i++)mv.push_back(i);
	ll ans=INF;
	for(int i=0;i<(int)mv.size();i++)
		for(int j=i+1;j<(int)mv.size();j++){
			ll tmp=mv[i]*mv[j]%2019;
			ans=min(tmp,ans);
		}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <queue>
#include <iostream>
#include <algorithm>
#define ll long long
#define INF 100000000000000
using namespace std;
int main(){
  ios_base::sync_with_stdio(false);
  ll V, E, r;
  cin >> V >> E >> r;
  vector< vector< pair<ll,ll> > > edges(V);
  ll dist[V];
  for(ll i = 0; i < V; i++){
    dist[i] = INF;
  }
  for(ll i = 0; i < E; i++){
    ll s,t,d;
    cin >> s >> t >> d;
    edges[s].push_back(make_pair(t,d));
  }

  dist[r] = 0;

  for(ll i = 0; i < E; i++){
    for(ll k = 0; k < V; k++){
      if(dist[k] != INF){
	for(pair<ll,ll> edge: edges[k]){
	  if(dist[edge.first] > dist[k] + edge.second){
	    if(i == E - 1){
	      cout << "NEGATIVE CYCLE" << endl;
	      return 0;
	    }
	    dist[edge.first] = dist[k] + edge.second;
	  }
	}
      }
    }
  }
  for(ll i = 0; i < V; i++){
    if(dist[i] == INF)
      cout << "INF" << endl;
    else
      cout << dist[i] << endl;
  }
}

Measured memory_bytes: 3304
//agc039_a.cpp
//Sun Dec  1 10:50:16 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	string s;
	cin >> s;
	ll k;
	cin >> k;

	ll temp = 0;
	ll rep = 1;
	int flag = 1;
	for (int i=1;i<s.length();i++){
		if (s[i]!=s[i-1]){
			flag = 0;
			temp += rep/2;
			rep=1;
		}else {
			rep++;
		}
	}
	temp += rep/2;

	if (flag){
		cout << s.length()*k/2 << endl;
		return 0;
	}

	ll bordercount = 0;
	if (s[s.length()-1] == s[0]){
		int topcount = 1;
		while (s[0]==s[topcount]){
			topcount++;
		}
		int bottomcount = 1;
		while (s[s.length()-1]==s[s.length()-1-bottomcount]){
			bottomcount++;
		}
		bordercount = topcount/2+bottomcount/2-(topcount+bottomcount)/2;
	}


	ll ans = temp*k-bordercount*(k-1);


	cout << ans << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<numeric>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
int abc[300000];
bool yabai = 0;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; yabai = 1; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int X = 0, Y = 0, A = 0, B = 0, C = 0;
	while ((ct = getchar_unlocked()) >= '0') X = X * 10 + ct - '0';
	while ((ct = getchar_unlocked()) >= '0') Y = Y * 10 + ct - '0';
	while ((ct = getchar_unlocked()) >= '0') A = A * 10 + ct - '0';
	while ((ct = getchar_unlocked()) >= '0') B = B * 10 + ct - '0';
	while ((ct = getchar_unlocked()) >= '0') C = C * 10 + ct - '0';

	auto a = abc;
	auto b = abc + A;
	auto c = abc + A + B;

	int k = 0;
	int M = A + B + C;
	while (k < M) {
		int yoyuu = (cm - (ci - cn)) / 11;
		chmin(yoyuu, M - k);
		if (yoyuu > 100) {
			rep(i, yoyuu) {
				while ((ct = *ci++) >= '0') abc[k] = abc[k] * 10 + ct - '0';
				k++;
			}
		}
		else {
			auto tmp = ci;
			while (k < M) {
				abc[k++] = getint();
				if (yabai) break;
			}
			yabai = 0;
		}
	}

	nth_element(a, b - X, b);
	nth_element(b, c - Y, c);
	if (X + Y > B) memcpy(b, b - X, (B - Y) * sizeof(int));
	else memcpy(c - X - Y, b - X, X * sizeof(int));
	nth_element(c - X - Y, c + C - X - Y, c + C);

	ll kotae = accumulate(c + C - X - Y, c + C, 0ll);
	//for (auto kari = c + C - X - Y; kari < c + C; kari++) kotae += *kari;
	printf("%lld", kotae);

	Would you please return 0;
}

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

signed main() {
  int N, M; cin >> N >> M;
  vector<int> vec(N+1, 0);
  rep(i, M) {
    int a, b; cin >> a >> b;
    vec[a]++; vec[b]++;
  }

  rep(i, N+1) {
    if(vec[i]%2 == 1) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <cstdio>
#include <cstdlib>

#ifdef _MSC_VER
#include <Windows.h>
#else
#include <unistd.h>
#endif

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD=(LL)1e9+7;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

#define INF 1LL << 50

vector<PLL>pi[500003];
int main(){
    LL N,A,B,C,D;
    cin>>N>>A>>B>>C>>D;
    bool flag=false;
    LL ld=A+C*(N-1LL);
    LL rd=A+D*(N-1LL);
    REP(i,N-1){
        if(ld<=B&&B<=rd){
            flag=true;break;
        }
        ld-=(D+C);
        rd-=(D+C);
    }
    if(flag)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 11904
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define rep(i,a,b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int inf = 2e9;



int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s, t; cin >> s >> t;
	int q; cin >> q;
	vector<int> sums(s.size()+1, 0), sumt(t.size()+1, 0);
	rep(i, 0, s.size()){
		sums[i + 1] = (sums[i] + (s[i] == 'A' ? 1 : 2)) % 3;
	}
	rep(i, 0, t.size()) {
		sumt[i + 1] = (sumt[i] + (t[i] == 'A' ? 1 : 2)) % 3;
	}
	rep(i, 0, q) {
		int a, b, c, d; cin >> a >> b >> c >> d;
		if ((sums[b] - sums[a-1]+3)%3 == (sumt[d] - sumt[c-1]+3)%3) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}


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

const ll mod = 1000000007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	char c; cin >> c;
	c++;
	cout << c << endl;
} 

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<59;
const double pi=acos(-1);
const double eps=1e-7;
const ll mod=1e5;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n;
vpll a;

int main(){
	cin>>n;
	a=vpll(n);
	for(int i=0;i<n;i++){
		ll h,p;
		cin>>h>>p;
		a[i]={h+p,p};
	}
	sort(a.begin(),a.end());
	vl dp(n+2,INF),DP(n+2,INF);
	dp[0]=DP[0]=0;
	for(int i=0;i<n;i++){
		for(int j=1;j<=i+1;j++){
			DP[j]=min(dp[j],dp[j-1]+a[i].second);
			if(DP[j]>a[i].first) DP[j]=INF;
		}
		dp=DP;
	}
	for(int i=0;i<=n+1;i++) if(dp[i]==INF){
		cout<<i-1<<endl;
		break;
	}
}

Measured memory_bytes: 384
import math

N = int(input())

xy_dict = {}
tmp =[0]
for i in range(N):
    x, y = map(float, input().split())
    #print(x)
    #print(y)

    xy_dict[i] = (x,y)
#print(xy_dict)
#print(xy_dict[0][0])
#print(xy_dict[0][1])

distance_list = []

for i in range(N):
    for j in range(i+1, N):
        x1 = xy_dict[i][0]
        y1 = xy_dict[i][1]
        x2 = xy_dict[j][0]
        y2 = xy_dict[j][1]
        a = math.sqrt((x1 - x2)**2 + (y1 - y2)**2)
        distance_list.append(a)
        #print("i,j is ", i,j)

sum = 0
for i in range(len(distance_list)):
    sum += distance_list[i]
        
print(math.factorial(N-1) * 2* sum/(math.factorial(N)))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
 
using namespace std;
 
//container util
//------------------------------------------
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
 
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define REACH(i,c) for(typeof((c).end()) i=(c).end(); i!=(c).begin(); --i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).begin(),(c).end(),greater<int>())
 
#define PB(a) push_back(a)
#define PF(a) pop_front(a)
 
#define MP(a,b) make_pair(a,b)
 
#define FS first
#define SE second
 
#define ALL(x) (x).begin(),(x).end()
#define MAX_EL(c) *max_element((c).begin(),(c).end())
#define MIN_EL(c) *min_element((c).begin(),(c).end())
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef string str;
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 
int max3(int a,int b, int c){
  int max = a;
  if(max < b){
    max = b;
  }
  if(max < c){
    max = c;
  }
  return max;
}

//grobal var
//------------------------------------------
LL dp[100002];

int main(){
// magic spell------------------------------
  cin.tie(0);
  ios::sync_with_stdio(false);
//------------------------------------------
  int N;
  while(cin >> N){
    VI p;
    int ans = 0;
    REP(i,N){
      int tmp;
      cin >> tmp;
      p.PB(tmp);
    }
    FOR(i,1,N-1){
      debug(max3(p[i+1],p[i],p[i-1]))
      if(max3(p[i+1],p[i],p[i-1])!=p[i]&&max3(-p[i+1],-p[i],-p[i-1])!=-p[i]) ans++;
    }
    cout << ans << endl;
  }

  return 0;
}

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

int main(){
  int n;
  cin >> n;
  int a[n];
  long long sum = 0, ans = 0, ans_2 = 0;
  bool isPlus = true;
  for ( int i = 0; i < n; i++){
    cin >> a[i];
    sum += a[i];
    isPlus = !isPlus;
    if ( isPlus ){
      if ( sum <= 0){
        ans += abs(1 - sum);
        sum = 1;
      }
    } else {
      if ( sum >= 0){
        ans += abs(sum + 1);
        sum = -1;
      }
    }
  }

  sum = 0;
  isPlus = false;
  for ( int i = 0; i < n; i++){
    sum += a[i];
    isPlus = !isPlus;
    if ( isPlus ){
      if ( sum <= 0){
        ans_2 += abs(1 - sum);
        sum = 1;
      }
    } else {
      if ( sum >= 0){
        ans_2 += abs(sum + 1);
        sum = -1;
      }
    }
  }

  cout << min(ans, ans_2) << endl;

  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <limits>

using namespace std;

int main() {
    long long N; cin >> N;
    long long ans=0;
    vector<long long> vec;

    for(long long i=1; i*i <= N; i++) {
        if((N-i) % i == 0 && (N-i)/i > i) ans += (N-i)/i;
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

int main(){
    int N, M, Q;
    cin >> N >> M >> Q;
    int sta[N][N];
    for(int i=0; i<N; i++) fill(sta[i], sta[i] + N, 0);
    for(int i=0; i<M; i++){
        int l, r;
        cin >> l >> r;
        l--; r--;
        sta[l][r] ++;
    }    
    int p[Q], q[Q];
    for(int i=0; i<Q; i++){
        cin >> p[i] >> q[i];
        p[i]--; q[i]--;
    }
    int sum[N][N];
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            if(i==0) {
                sum[i][j] = sta[i][j];
                if(j != 0) sum[i][j] += sum[i][j-1];
            }
            else{
                if(j==0) sum[i][j] = sum[i-1][j] + sta[i][j];
                else sum[i][j] = sum[i-1][j] + sum[i][j-1] -sum[i-1][j-1] + sta[i][j];
            }
        }
    }
    for(int i=0; i<Q; i++){
        int ans = sum[q[i]][q[i]];
        if(p[i] != 0) ans -= sum[p[i] - 1][q[i]] - sum[q[i]][p[i] - 1] + sum[p[i]-1][p[i]-1];
        cout << ans << endl;
    }
    return 0;
}

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

string s;
int res;

int main()
{
    cin >> s;
    int l = 0, r = int(s.length()) - 1;
    while (l < r) {
        res += s[l] != s[r];
        l++; r--;
    }
    printf("%d\n", res);
    return 0;
}


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

int main() {
  int a;
  string s;
  cin >> a >> s;
  if (a>=3200) {
    cout << s << endl;
  }
  else {
    cout << "red" << endl;
  }
}

Measured memory_bytes: 3572
a,b = map(int,input().split())
a -= 1
if a % 4 == 0:
  ans = a
elif a % 4 == 1:
  ans = 1
elif a % 4 == 2:
  ans = a + 1
else:
  ans = 0
if b % 4 == 0:
  ans ^= b
elif b % 4 == 1:
  ans ^= 1
elif b % 4 == 2:
  ans ^= b + 1
print(ans)

Measured memory_bytes: 3064
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
a,b = map(decimal.Decimal,input().split())
print(int(a*b))


Measured memory_bytes: 10524
##入力は以下の形式で標準入力から与えられる。
##A B
a, b = gets.chomp.split(" ").map(&:to_i)

##A以上 B以下の整数のうち、回文数となるものの個数を求めてください。 
##回文数とは、先頭に 0をつけない 10進表記を文字列として見たとき、
##前から読んでも後ろから読んでも同じ文字列となるような正の整数のことを指します。
num = 0
(a..b).each do |v|
  s = v.to_s
  r_s = s.split("").reverse.join
  
  if s == r_s
    num += 1
    # p v
  end
end

##制約
##10000 ≤ A ≤ B ≤ 99999
##入力はすべて整数である

##A 以上 B 以下の整数のうち、回文数となるものの個数を出力せよ。
p num

Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &&x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define INSEG(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void PSUM(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(false);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int t, x;
    cin >> t >> x;
    cout << t / (double)x << endl;
    return (0^_^0);
}



Measured memory_bytes: 764
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
c_cnt = [1 for i in range(N)]

def count(A, B, b_cnt):
    B.append(-1)
    a_cnt = [0 for i in range(N)]
    i, j = 0, 0
    while i < N:
        if A[i] < B[j]:
            a_cnt[i] += b_cnt[j]
            j += 1
        else:
            i += 1
            if 1 <= i < N:
                a_cnt[i] = a_cnt[i-1]
    return a_cnt

b_cnt = count(B, C, c_cnt)
a_cnt = count(A, B, b_cnt)
print(sum(a_cnt))

Measured memory_bytes: 110180
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

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; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

ll mod = 1000000007;


// 文字列 s に含まれる 'AB' の数を数える
int count_ab(const string& s) {
  int count = 0;
  string find_word("AB");
  auto pos = s.find(find_word);
  while (pos != string::npos) {
    count++;
    pos = s.find(find_word, pos + find_word.size());
  }
  return count;
}

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

  ll n, h;
  cin >> n >> h;
  vector<ll> a(n);
  vector<ll> b(n);

  rep(i, n){
    ll aa, bb;
    cin >> aa >> bb;
    a[i] = aa;
    b[i] = bb;
  }

  sort(ALL(a));
  sort(ALL(b));

  ll ans = 0;
  auto itra = a.rbegin();
  auto itrb = b.rbegin();
  while (h > 0) {
    if (itrb == b.rend() || *itra >= *itrb) {
      // a を使い続ければOK
      ans += h / *itra;
      if (h % *itra != 0) ans++;
      break;
    } else {
      h -= *itrb;
      itrb++;
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
n,k=map(int,input().split())
A = list(map(int,input().split()))

C=[0]*n
C[0]=1
c=0
loopc=0
i=0
io=0
while c<k :
    newi = A[i]-1
    C[newi]+=1
    if C[newi]>=3 :
        rs=newi
        break
    elif C[newi]==2 :
        loopc+=1
    io=i
    i=newi
    c+=1

if (k-c)<0 or loopc==0 :
    print(i+1)
    exit()
mod = (k-c)%(loopc)
# print( k, c, loopc, i, mod)


# i=rs
while mod>0 :
    newi = A[i]-1
    i=newi
    mod-=1

print( i+1 )


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

int main(){
  int N,M;
  cin >> N;
  int T[N+10];
  for(int i=0;i<N;++i) cin >> T[i];
  cin >> M;
  int P[M+10];
  int X[M+10];
  for(int i=0;i<M;++i) cin >> P[i] >> X[i];
  int sum=0;
  for(int i=0;i<N;++i) sum+=T[i];
  for(int i=0;i<M;++i){
    int ans=0;
    ans=sum+X[i]-T[P[i]-1];
    cout << ans << endl; 
  } 
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"

struct food {
	int id;
	int p, q, r;
	int k;
};

int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		vector<food>mp;
		vector<int>anss;
		for (int i = 0; i < N; ++i) {
			int n, p, q, r; cin >> n >> p >> q >> r;
			food afood{ n,p,q,r,p * 4 + q * 9 + r *4 };
			mp.emplace_back(afood);
			
		}
		int limp, limq, limr, limk; cin >> limp >> limq >> limr >> limk;
		for (int i = 0; i < N; ++i) {
			food afood(mp[i]);
			if (limp >= afood.p&&limq >= afood.q&&limr >= afood.r&&limk >= afood.k) {
				anss.emplace_back(afood.id);

			}
		}
		
		if (anss.empty())cout << "NA" << endl;
		else {
			for (auto ans : anss)cout << ans << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

typedef pair<int, int> ii;
typedef long long int64;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
    int n, d, ans = 1;
    cin >> n >> d;
    d *= 2;
    d++;
    while (d * ans < n) {
	++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
d = []
for i in range(n):
  d.append(list(map(int, input().split())))
flag = "No"
for i in range(n - 2):
  if d[i][0] == d[i][1] and d[i+1][0] == d[i+1][1] and d[i+2][0] == d[i+2][1]:
    flag = "Yes"
    break
print(flag)

Measured memory_bytes: 9188
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main
{
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    public static void main(String args[])
    {
        FastReader obj = new FastReader();
        int n = obj.nextInt();
        Map<String,Integer> map = new HashMap<>();
        int max = 1;
        for(int i=0;i<n;i++)
        {
            String str = obj.next();
            if(!map.containsKey(str))
                map.put(str,1);
            else
            {
                int k = map.get(str);
                map.replace(str,k+1);
                k++;
                if(k>=max)
                    max = k;
            }
        }
        ArrayList<String> arr = new ArrayList<>();
        for(Map.Entry<String,Integer>m:map.entrySet())
            if(m.getValue()==max)
                arr.add(m.getKey());
        Collections.sort(arr);
        for(int i=0;i<arr.size();i++)
            System.out.println(arr.get(i));
    }
}


Measured memory_bytes: 71436
#include "bits/stdc++.h"
using namespace std;

using ll = long long;
using P = pair<ll,ll>;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD = 1e9 + 7;

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

    ll n,m;cin>>n>>m;
    if(n>1 && m>1) cout<<(n-2)*(m-2)<<endl;
    else{
        if(n==1 && m==1) cout<<1<<endl;
        else cout<<n*m-2<<endl;
    }
}


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

typedef long long ll;

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

    int n,m;
    cin >> n >> m;
    if(m==n) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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() {
  int n, m;
  cin >> n >> m;
  priority_queue<int> q;
  rep(i,n) {
    int a;
    cin >> a;
    q.push(a);
  }
  rep(i,m) {
    int a = q.top(); q.pop();
    q.push(a/2);
  }
  ll ans = 0;
  rep(i,n) {
    ans += q.top(); q.pop();
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<n; i++)
#define pb push_back
#define int long long
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int a, b, h;

signed main() {
    //cin.tie(0); ios::sync_with_stdio(false);
    cin >> a >> b >> h;
    cout << (a+b)*h/2 << endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    ll n, c, k; cin >> n >> c >> k;
    vector<ll> v;
    REP(i, n) {
        ll tmp;
        cin >> tmp;
        v.push_back(tmp);
    }
    sort(ALL(v));

    ll res = 0;
    queue<ll> q;
    REP(i, n) {
        // 方針
        // 到着時刻の小さいものから順にqueueに突っ込んでいき、
        // (1) queueのサイズがcになるか
        // (2) 次の到着時刻がqueueの先頭+kよりも遅いか
        // を満たしたら出発させてqueueを空にしてresインクリメント
        if (q.empty()) {
            q.push(v[i]);
        } else {
            if ((q.size() == c) || (q.front() + k < v[i])) {
                q = queue<ll>();
                res++;
            }
            q.push(v[i]);
        }
    }
    if (!q.empty()) {
        res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 4224