akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
#define INF (1 << 29)
using namespace std;

int main(){
    char inp;
    stack<char> s;
    while( cin >> inp){
        if(not s.empty()){
            if(s.top() == 'S' && inp == 'T'){
                s.pop();
            }else{
                s.push(inp);
            }
        }else{
            s.push(inp);
        }
    }
    cout << s.size() << endl;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  ll h, w, m, hin, win;
  cin >> h >> w >> m;
  vector<ll> ah(h + 1, 0);
  vector<ll> aw(w + 1, 0);
  set<ll> hash;
  for(int i = 0; i < m; ++i)
  {
    cin >> hin >> win;
    ah[hin]++;
    aw[win]++;
    hash.insert((hin << 32LL) + win);
  }
  ll ah_max_ind = distance(ah.begin(), max_element(ah.begin(), ah.end()));
  ll aw_max_ind = distance(aw.begin(), max_element(aw.begin(), aw.end()));

  vector<ll> ah_ind;
  vector<ll> aw_ind;
  for(int i = 0; i <= h; ++i)
  {
    if (ah[i] == ah[ah_max_ind])
    {
      ah_ind.emplace_back(i);
    }
  }
  for(int i = 0; i <= w; ++i)
  {
    if (aw[i] == aw[aw_max_ind])
    {
      aw_ind.emplace_back(i);
    }
  }

  ll ans = ah[ah_max_ind] + aw[aw_max_ind];
  for(const auto& ih : ah_ind) for(const auto& iw : aw_ind)
  {
    if (hash.find( (ih << 32LL) + iw ) == hash.end())
    {
      cout << ans;
      return;
    }
  }

  if (hash.find( (ah_max_ind << 32LL) + aw_max_ind ) != hash.end()) ans--;
  if (m - ah[ah_max_ind] == 1) ans = m;
  if (m - aw[aw_max_ind] == 1) ans = m;

  cout << ans << endl;
}

int main()
{
  fastio;
  solve();

  return 0;
}

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

int main()
{
    ll n;
    cin >> n;
    ll a[n];
    for(ll i=0; i<n; i++)
    {
        cin >> a[i];
    }
    if(n==1)
    {
        cout << "Yes" << endl;
        return 0;
    }
    if(a[0]-a[1]>1)
    {
        cout << "No" << endl;
        return 0;
    }
    if(a[0]-a[1]==1)
    {
        a[0]--;
    }
    for(ll i=1; i<n; i++)
    {
        if(a[i]-a[i-1]<0)
        {
            cout << "No" << endl;
            return 0;
        }
        else if(a[i]-a[i-1]>0)
        {
            a[i]--;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {
public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int x=sc.nextInt();
		if(x==7 || x==5 || x==3){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}

	}
}


Measured memory_bytes: 21844
#include <iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<string>
#include<queue>
#include<set>
#include<vector>
#include<cmath>
#include<stack>
#include<map>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
double na,nb;
char s[105][105];
int dp[105][105];
int h,w;
int main()
{
    cin>>h>>w;
    for(int i=1;i<=h;i++)cin>>(s[i]+1);
    memset(dp,inf,sizeof(dp));
    if(s[1][1]=='#')dp[1][1]=1;
    else dp[1][1]=0;
    for(int i=1;i<=h;i++)
    for(int j=1;j<=w;j++)
    {
        if(s[i][j+1]=='#')
        {
            int a=dp[i][j];
            if(s[i][j]=='.')a++;
            dp[i][j+1]=min(a,dp[i][j+1]);
        }
        else dp[i][j+1]=min(dp[i][j+1],dp[i][j]);
        if(s[i+1][j]=='#')
        {
            int a=dp[i][j];
            if(s[i][j]=='.')a++;
            dp[i+1][j]=min(a,dp[i+1][j]);
        }
        else dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
    }
    cout<<dp[h][w]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ECHO(x) cout<<x<<endl;
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;


int main(){
  int n;
  cin>>n;
  LL a[n];
  REP(i, n) cin>>a[i];
  sort(a, a+n);
  LL sum=0;
  int ans=0;
  REP(i, n-1){
    if(2*(sum+a[i])>=a[i+1]) ++ans;
    else ans=0;
    sum+=a[i];

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


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

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n, x;
    cin >> n;

    rep(i, n+1) {
        x = i;
        if(x % 3 == 0){
            cout << " " << i;
            continue;
        }

        while(x){
            if(x % 10 == 3) {
                cout << " " << i;
                break;
            }
            x /= 10;
        }
    }
    cout << endl;
}


Measured memory_bytes: 3184
while True:
    a,op,b = input().split()
    a=int(a)
    b=int(b)
    if op == "?": break
    elif op =="+":
        print(a+b)
    elif op =="-":
        print(a-b)
    elif op =="*":
        print(a*b)
    else:
        print(a//b)


Measured memory_bytes: 5592
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

if N % 2 == 1:
    print(0)
    exit()

def r(n):
    ans = 0
    p = 10
    while p <= n:
        ans += n // p
        p *= 5
    return ans

print(r(N))

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
   string S;
   cin>>S;
   if(S>"2019/04/30"){
       cout<<"TBD"<<endl;
   }
   else{
       cout<<"Heisei"<<endl;
   }
    
}

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

int main(){
    int n; cin >> n;
    int ans = 1;
    int big; cin >> big;

    for(int i=1; i<n; i++){
        int high; cin >> high;
        if(big <= high){
            big = high;
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Lim 9999991
#define Jmp 100003

int dic[Lim];

int toint(string s) {
    int ret = 0;
    for (int i = 0; i < s.size(); ++i) {
        ret *= 5;
        switch (s[i]) {
            case 'A':
                ret += 1;
                break;
            case 'T':
                ret += 2;
                break;
            case 'G':
                ret += 3;
                break;
            case 'C':
                ret += 4;
                break;
        }
    }
    return ret;
}

void push(string s) {
    int a = toint(s);
    int i = a % Lim;
    while (true) {
        if (!dic[i]) {
            dic[i] = a;
            return;
        }
        i = (i + Jmp) % Lim;
    }
}

int find(string s) {
    int a = toint(s);
    int i = a % Lim;
    while (true) {
        if (!dic[i])
            return 0;
        if (dic[i] == a)
            return 1;

        i = (i + Jmp) % Lim;
    }
}

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string s, t;
        cin >> s >> t;
        if (s == "insert")
            push(t);
        else
            printf(find(t) ? "yes\n" : "no\n");
    }
    return 0;
}

Measured memory_bytes: 31136
#include <stdio.h>

int linerSearch(int n, int *s, int key) {
    int i;
    for(i = 0; i < n; i ++) {
        if(s[i] == key) return 1;
    }
    return 0;
}

int main(){
    int cou = 0;
    int n;
    int i,s[10010];

    scanf("%d",&n);
    for(i = 0;i < n;i++ ) {
        scanf("%d",&s[i]);
    }

    int q;
    int t;

    scanf("%d",&q);
    for(i = 0; i < q; i++) {
        scanf("%d",&t);
        cou += linerSearch(n,s,t);
    }

    printf("%d\n",cou);
    return 0;
}



Measured memory_bytes: 2108
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int N;

int main(void) {
    cin>>N;
    vector<int> D(N+1);

    for(int i = 0;i < N;i++) {
        cin>>D[i+1];
    }

    sort(D.begin()+1,D.end());
   
    int left = D[N/2];
    int right = D[N/2+1];

    cout<<right-left<<endl;

    return 0;
}





Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<char> vchar;
typedef vector<vector<char>> vvchar;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef priority_queue<long long> prque;
#define ain(i,n,a) for(long long i=0;i<(long long)(n);i++){cin>>a[i];}
#define aout(i,n,a) for(long long i=0;i<(long long)(n);i++){if(i){cout<<" ";}cout<<a[i];if(i==n-1){cout<<endl;}}
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define vsort(v) sort((v).begin(),(v).end())
#define vrsort(v) sort((v).rbegin(),(v).rend())
#define vreverse(v) reverse((v).begin(),(v).end())
#define pf(a) push_front(a)
#define pb(a) push_back(a)
#define INF 1998021900
#define MOD 1000000007
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  //input
  ll n,i;cin>>n;vll a(n),ai(n);ain(i,n,a);rep(i,n){ai[i]=a[i];}
  //caricurate
  ll m,j;vsort(ai);m=ai[n-1];j=ai[n-2];
  //output
  for(i=0;i<n;i++){
   if(a[i]==m){cout<<j<<endl;}
    else{cout<<m<<endl;}
  }
}

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

using namespace std;

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

template <typename T>
void printv(const vector<T> &v, int idx)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        if (i == idx)
        {
            cout << "[" << v[i] << "]"
                 << " \n"[i == sz - 1];
            continue;
        }
        cout << v[i] << " \n"[i == sz - 1];
    }
}

using Graph = vector<P>;

void preorder(const Graph &g, int cur)
{
    cout << " " << cur;
    int l = g[cur].first, r = g[cur].second;
    if (l != -1)
        preorder(g, l);
    if (r != -1)
        preorder(g, r);
}

void inorder(const Graph &g, int cur)
{
    int l = g[cur].first, r = g[cur].second;
    if (l != -1)
        inorder(g, l);
    cout << " " << cur;
    if (r != -1)
        inorder(g, r);
}

void postorder(const Graph &g, int cur)
{
    int l = g[cur].first, r = g[cur].second;
    if (l != -1)
        postorder(g, l);
    if (r != -1)
        postorder(g, r);
    cout << " " << cur;
}

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

    int n;
    cin >> n;
    Graph g(n);
    vector<int> in(n, 0);
    for (int i = 0; i < n; i++)
    {
        int id, l, r;
        cin >> id >> l >> r;
        g[id] = P(l, r);
        if (l != -1)
            in[l]++;
        if (r != -1)
            in[r]++;
    }
    int st=-1;
    for(int i=0;i<n;i++) if(in[i]==0) st = i;
    cout << "Preorder" << endl;
    preorder(g, st);
    cout << endl;
    cout << "Inorder" << endl;
    inorder(g, st);
    cout << endl;
    cout << "Postorder" << endl;
    postorder(g, st);
    cout << endl;
}


Measured memory_bytes: 3176
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Joy
 */

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

struct UnionFind {
    vector<ll> data;
    UnionFind(ll size) : data(size, -1) {}

    ll root(ll x) {
        if (data[x] < 0)
            return x;
        else
            return data[x] = root(data[x]);
    }

    ll size(ll x) { return -data[root(x)]; }

    bool isConnect(ll x, ll y) { return root(x) == root(y); }

    bool connect(ll x, ll y) {
        x = root(x);
        y = root(y);

        if (x == y)
            return false;

        if (data[x] > data[y]) {
            x ^= y;
            y ^= x;
            x ^= y;
        }

        data[x] = data[x] + data[y]; // membersize++
        data[y] = x;
        return true;
    }
};

#define REP(i, N) for (ll i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

class DDecayedBridges {
public:
	void solve(std::istream& in, std::ostream& out) {
        ll N, M;
        in >> N >> M;
        vector<ll> a(M);
        vector<ll> b(M);
        REP(i, M) {
            in >> a[i] >> b[i];
            a[i]--; b[i]--;
        }
        ll ans[M];
        ans[M-1] = (N * (N - 1)) / 2;
        UnionFind U(N);
        for (ll i = M - 1; i >= 1; i--) {
            ll node1 = a[i], node2 = b[i];
            if (U.isConnect(node1, node2)) {
                ans[i - 1] = ans[i];
            } else {
                ans[i - 1] = ans[i] - U.size(node1) * U.size(node2);
                U.connect(node1, node2);
            }
        }
        REP(i, M) out << ans[i] << '\n';
	}
};


int main() {
	DDecayedBridges solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 4480
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>pi;
const int MAXN=1005;
const int MOD=1000000007;
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DEC(i,a,b) for(int i=(a);i>=(b);i--)
#define fst first
#define snd second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define db(x) cerr<<#x<<" = "<<x<<"\n"
#define LOW(v,x) (lower_bound(all(v),(x))-(v).begin())

int H,W,N,X0,Y0,X1,Y1,X2,Y2;
string S,T;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	cin>>H>>W>>N>>X0>>Y0>>S>>T;
	X1=1;X2=H;Y1=1;Y2=W;
	DEC(i,N-1,0){
		if(T[i]=='D')X1--;
		if(T[i]=='U')X2++;
		if(T[i]=='L')Y2++;
		if(T[i]=='R')Y1--;
		X1=max(X1,1);
		X2=min(X2,H);
		Y1=max(Y1,1);
		Y2=min(Y2,W);
		if(S[i]=='U')X1++;
		if(S[i]=='D')X2--;
		if(S[i]=='R')Y2--;
		if(S[i]=='L')Y1++;
		if(X1>X2||Y1>Y2){
			cout<<"NO\n";
			return 0;
		}
		X1=max(X1,1);
		X2=min(X2,H);
		Y1=max(Y1,1);
		Y2=min(Y2,W);
	}
	if(X1<=X0&&X0<=X2&&Y1<=Y0&&Y0<=Y2)cout<<"YES\n";
	else cout<<"NO\n";
}
/*
3
2 5
6 1
3 7
Ans:6

4
3 7
2 9
8 16
10 8
Ans:9
*/


Measured memory_bytes: 920
N,M = gets.chomp.split.map(&:to_i)

if N >= 2
  if M >= 2
    puts N * (N-1) / 2 + (M * (M-1) / 2)
  else
    puts N * (N-1) / 2
  end
else
  if M >= 2
    puts M * (M-1) / 2
  else
    puts 0
  end
end

Measured memory_bytes: 1788
<?php
$N = fgets(STDIN);
$result = 0;
$yakusu = 0;
for($i = 1;$i <= $N;$i++){
 for($ii = 1;$ii <= 200;$ii++){
     if($i%$ii == 0 && $i >= $ii && $i%2 != 0){
         $yakusu = $yakusu + 1;
     }
 }
  if($yakusu == 8){
    $result = $result + 1;
   $yakusu = 0;
  }else{
    $yakusu = 0;
  }
}
echo $result;
?>

Measured memory_bytes: 3576
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LINT long long

int main(){
    int A, B;
    cin >> A >> B;
    cout << ((A*B%2) ? "Yes" : "No" ) << endl;



  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a, b;
	int n, i;

	scanf("%d %d%*c", &a, &b);

	if(b >= 100)
		n = a * 1000 + b;
	else if(b >= 10)
		n = a * 100 + b;
	else
		n = a * 10 + b;

	for(i=1;i<400;i++) {
		if(n / (float)i == (float)i) {
			printf("Yes");
			return 0;
		}
	}

	printf("No");
	
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(long long (i)=0, i_bound = (long long)(n); (i)<i_bound; ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
int main(){
    cin.tie(0);
    cout.sync_with_stdio(false);
    int s, t;
    cin >> s >> t;
    string res;
    if(s<t) REP(i, t) res = res + to_string(s);
    else REP(i, s) res = res + to_string(t);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

int main(){
    int N, M;
    cin >> N >> M;
    int cnt[N];
    fill(cnt, cnt+N, 0);
    rep(i, M){
        int a, b; cin >> a >> b; a--, b--;
        cnt[a]++, cnt[b]++;
    }
    rep(i, N){
        if(cnt[i]&1) {cout << "NO" << endl; return 0;}
    }
    cout << "YES" << endl;
}

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

void optimize() {
    std::ios::sync_with_stdio(false);
    std::cout.tie(NULL);
    std::cin.tie(NULL);
}

int main() {
    optimize();
    int a, b, c;
    std::cin >> a >> b >> c;
    if(a == b && b != c) {
        std::cout << "Yes";
    } else if(a == c && c != b) {
        std::cout << "Yes";
    } else if(b == c && c != a) {
        std::cout << "Yes";
    } else {
        std::cout << "No";
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = ll(1e9 + 7);

string b[1000];
ll dp[1010][1010];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	int H, W;
	cin >> H >> W;
	for(int i = 0; i < H; i++){
		cin >> b[i];
	}

	dp[0][0] = 1;
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if(i + 1 < H && b[i + 1][j] == '.'){
				dp[i + 1][j] += dp[i][j];
				dp[i + 1][j] %= MOD;
			}
			if(j + 1 < W && b[i][j + 1] == '.'){
				dp[i][j + 1] += dp[i][j];
				dp[i][j + 1] %= MOD;
			}
		}
	}
	cout << dp[H - 1][W - 1] << endl;
}


Measured memory_bytes: 9216
#include <iostream>

using namespace std;

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

int main()
{

  int a,d,n;

  cin >> a >> d >> n;
  while (a!=0 || d!= 0 || n!= 0) {
    int i = 0;
    int cur, ret;

    while (n > 0) {
      if (prime(a + (i*d)))
	{
	ret = a + i*d;
	n--;
	}
      i++;
    }
    
    cout << ret << "\n";
    cin >> a >> d >> n;
  }
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

template<class V, int ME> class BIT {
public:
    V bit[1<<ME];
    V total(int e) {V s=0;e++;while(e) s+=bit[e-1],e-=e&-e; return s;}
    void add(int e, V val) {e++; while(e<=1<<ME) bit[e-1]+=val,e+=e&-e;}
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> col(2*N), num(2*N);
    REP(i, 2*N){
    	char c;
    	cin >> c >> num[i];
    	num[i]--;
    	if(c == 'B') col[i] = 0;
    	else col[i] = 1;
    }
    vector<ll> b_b(N, 0), w_w(N, 0);
    ll w_b[N+1][N+1], b_w[N+1][N+1];
    BIT<ll, 12> bitb;
    BIT<ll, 12> bitw;
    REP(i, (1<<10)-1){
    	bitb.bit[i] = 0;
    	bitw.bit[i] = 0;
    }
    REP(i,  2*N){
    	if(col[i] == 0){
    		REP(j, N+1){
    			if(j>0) w_b[num[i]][j] = bitw.total(N-1) - bitw.total(j-1);
    			else w_b[num[i]][j] = bitw.total(N-1);
    		}
    		b_b[num[i]] = bitb.total(N-1) - bitb.total(num[i]-1);
    		bitb.add(num[i], 1);
    	}else{
    		REP(j, N+1){
    			if(j>0)b_w[num[i]][j] = bitb.total(N-1) - bitb.total(j-1);
    			else b_w[num[i]][j] = bitb.total(N-1);
    		}
    		w_w[num[i]] = bitw.total(N-1) - bitw.total(num[i]-1);
    		bitw.add(num[i], 1);
    	}
    }
    ll ma = 2010;
    ll dp[ma][ma];
    const ll INF = 1ll << 60;
    dump(INF)
    REP(i, ma)REP(j, ma) dp[i][j] = INF;
    dp[0][0] = 0;
    REP(i, N+1){
    	REP(j, N+1){
    		if(i < N) dp[i+1][j] = min(dp[i+1][j], dp[i][j] + w_b[i][j] + b_b[i]);
    		if(j < N) dp[i][j+1] = min(dp[i][j+1], dp[i][j] + b_w[j][i] + w_w[j]);
    	}
    }
    cout << dp[N][N] << endl;
    /*
    REP(i, N+1){
    	REP(j, N+1){
    		cout << dp[i][j] << " ";
    	}
    	cout << endl;
    }
    cout << col << endl;
    cout << num << endl;
    cout << b_b << endl;
    cout << w_w << endl;
    */
    return 0;
}

Measured memory_bytes: 94464
#include <iostream>
#include <vector>
using namespace std;
const int MAX = 100000;

int main() {
	int n, m;
	cin >> n >> m;
	vector<pair<int,int>> v;
	v.reserve(2*MAX);
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		v.emplace_back(a, 1);
	}
	for (int i = 0; i < m; i++) {
		int b, c;
		cin >> b >> c;
		v.emplace_back(c, b);
	}
	sort(v.begin(), v.end(), greater<pair<int,int>>());
	long long ans = 0;
	for (auto e : v) {
		int val = e.first, num = e.second;
		if (n > num) {
			n -= num;
			ans += (long long) num * val;
		} else {
			ans += (long long) n * val;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4428
//include,using,define等
#pragma region header
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#include <cstring>

// ===============================================================
//using系
#pragma region header
using namespace std;
using ll = long long;
using lint = long long;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;
using ui = unsigned int;
using qul = queue<ll>;
using pql = priority_queue<ll>;
const int dx[] = { 1,0,-1,0 };
const int dy[] = { 0,1,0,-1 };
constexpr ll mod = 1e9 + 7;
constexpr long double pi = 3.141592653589793238462643383279;
#pragma endregion
// ========================================================================
//define
#pragma region header
//#define int long long
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i <= n; i++)
#define INF (ll)10000000000000000
#define mod (ll)1000000007
#define P pair<lint,lint>
template <class T>
bool chmax(T & a, const T & b) {
	if (a < b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}
template <class T>
bool chmin(T& a, const T& b) {
	if (a > b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion
lint n, x;
lint pat[55];
lint bag[55];
void r() {
	pat[0] = 1;
	bag[0] = 1;
	for (int i = 1; i < 52; i++) {
		bag[i] = bag[i - 1] * 2 + 3;
		pat[i] = pat[i - 1] * 2 + 1;
	}
	return;
}
lint solve(lint a, lint b) {
	if (a == 1 && b == 2)
		return 1;

	if (a == 1 && b == 3)
		return 2;

	if (a == 1 && b == 4)
		return 3;

	if (a == 1 && b == 5)
		return 3;

	if (b == 1) 
		return 0;
	
	if (b <= 1 + bag[a - 1]) 
		return solve(a - 1, b - 1);
	
	if (b == 2 + bag[a - 1]) 
		return pat[a - 1] + 1;
	
	if (b <= 2 + bag[a - 1] * 2) 
		return pat[a - 1] + 1 + solve(a - 1, b - 2 - bag[a - 1]);
	
	if (b == 3 + bag[a - 1] * 2)
		return pat[a];
	
}


int main(void) {
	cin >> n >> x;
	r();
	printf("%lld\n", solve(n, x));

	return 0;
}

Measured memory_bytes: 3764
#include<bits/stdc++.h>
//#define int long long
#define endl '\n'
#define mod 1000000007
#define inf 1e18
#define PI 3.14159265358979323846264338327950L
#define w(x) int x; cin>>x; while(x--)
using namespace std;
bool sieve[2000006];
void sieve_make() 
{
	memset(sieve,true,sizeof(sieve));
	sieve[0]=sieve[1]=false;
	for(int i=2;i*i<2000006;i++)
	{
		if(sieve[i])
		{
			for(int j=i*i;j<2000006;j+=i)
				sieve[j]=false;
		}
	}
}

int max(int a,int b)
{
	if(a>b)
		return a;
	return b;
}
int min(int a,int b)
{
	if(a<b)
		return a;
	return b;
}
int modexp(int a,int b,int c)
{
	if(a==0) return 0;
	if(b==0) return 1;

	int ans;
	if(b%2==0)
	{
		int small=modexp(a,b/2,c);
		ans=(small*small)%c;
	}
	else
	{
		int small=modexp(a,b-1,c);
		ans=(a%c);
		ans=(small*ans)%c;
	}
	return (ans+c)%c;
}
bool sign(int x)
{
	if(x>0)
		return true;
	return false;
}
int kadane(int* a,int n)
{
	int loc=a[0],glo=a[0];
	for(int i=1;i<n;i++)
	{
		loc=max(a[i],loc+a[i]);
		glo=max(glo,loc);
	}
	return glo;
}

vector<vector<double>>dp(3001,vector<double>(3001,-1));

double solve(vector<double>& a,int i,int cnt)
{
	double ans=1;
	if(i==a.size())
	{
		if(cnt>=a.size()/2+1)
			return ans;
		else
			return 0;
	}

	if(dp[i][cnt]!=-1) return dp[i][cnt];
	ans=a[i]*solve(a,i+1,cnt+1)+(1-a[i])*solve(a,i+1,cnt);
	return dp[i][cnt]=ans;

}
int32_t main()
{
	ios::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
	
	
	
	
	
	int n;
	cin>>n;
	vector<double>a(n);

	for(int i=0;i<n;i++) cin>>a[i];


	double ans=solve(a,0,0);
	printf("%.10f",ans);
}



Measured memory_bytes: 74484
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String N = sc.next();
    String S;
    if(N.charAt(0)=='7' || N.charAt(1)=='7' || N.charAt(2)=='7'){
      S = "Yes";
    } else {
      S = "No";
    }
    System.out.println(S);
  }
}

Measured memory_bytes: 35704
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long int
#define pb push_back
#define mp make_pair
#define ip pair<int, int>
#define it pair<int, pair<int, int>>
#define F first
#define S second
#define fori(p, n) for(int i = p; i < n; i++)
#define forj(q, m) for(int j = q; j < m; j++)
#define fork(r, l) for(int k = r; k < l; k++)
#define revi(h) for(int i = h; i >= 0; i--)
#define all(v) v.begin(), v.end()
#define PI 3.14159265358
#define debug(x) cout<<"DEBUGGING --- "<<x<<endl;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define input_from_file  freopen("input.txt", "r", stdin);
#define output_to_file freopen("output.txt", "w", stdout);

signed main(){
    fastio;
    //input_from_file; 
    //output_to_file;
    int n, W;
    cin>>n>>W;
    vector<ip>V(n);
    int sum = 0;
    fori(0, n){
        int v, w; cin>>w>>v;
        sum += v;
        V[i] = {v, w}; 
    }
    sort(all(V));
    vector<vector<int>>dp(n + 1, vector<int>(sum + 1, 0));
    fori(1, n + 1)
        forj(1, sum + 1){
            int w1 = V[i - 1].S;
            int v1 = V[i - 1].F;
            if(v1 <= j && (dp[i - 1][j - v1] != 0 || j - v1 == 0) && w1 + dp[i -1][j - v1] <= W) dp[i][j] = min(dp[i - 1][j] ? dp[i - 1][j] : INT_MAX, w1 + dp[i - 1][j - v1]); 
            else dp[i][j] = dp[i - 1][j];
        }
    // fori(1, n + 1){
    //     forj(1, sum + 1) cout<<dp[i][j]<<" ";
    //     cout<<endl;    
    // }
    int ans = INT_MIN;
    fori(1, n + 1)
        forj(1, sum + 1) if(dp[i][j] != 0) ans = max(ans, j);
    cout<<ans<<endl;            
}

Measured memory_bytes: 80256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;

class _Class
{
  void _Do()
  {
    var N = Split.ints()[0];
    var tmp = Split.ints();
    var A = tmp[0];
    var B = tmp[1];
    var p = Split.ints();

    Array.Sort(p);

    int i = 0;
    for(i=0;i<N ;i++)
    {
      if (p[i] > A)
        break;
    }
    var ret = Math.Min(int.MaxValue, i);

    var b = i;
    for (;i<N ;i++ )
    {
      if (p[i] > B)
        break;
    }
    ret = Math.Min(ret,i-b);
    ret = Math.Min(ret, N-i);
    Console.WriteLine(ret);
  }

  static void Main(string[] args)
  {
    _(args);
    new _Class()._Do();
  }

  [Conditional("DEBUG")]
  static void _(string[] args)
  {
    if (args.Length != 0 && File.Exists(args[0]))
      Console.SetIn(new StreamReader(args[0]));
    else
      Console.Error.WriteLine("in");
  }
}

static class Split
{ 

  // 1
  public static string[] strings()
  {
    return Console.ReadLine().Split();
  }


  // [2.1] -2,147,483,648 ~ +2,147,483,647
  public static int[] ints()
  {
    var _s = Console.ReadLine().Split();

    var x = new int[_s.Length];
    for (var i = 0; i < _s.Length; i++)
      x[i] = int.Parse(_s[i]);

    return x;
  }

  // [2.2] 
  // -9,223,372,036,854,775,808 ~ 
  // +9,223,372,036,854,775,807
  public static long[] longs()
  {
    var _s = Console.ReadLine().Split();

    var x = new long[_s.Length];
    for (var i = 0; i < _s.Length; i++)
      x[i] = long.Parse(_s[i]);

    return x;
  }

  public static double[] doubles()
  {
    var _s = Console.ReadLine().Split();

    var x = new double[_s.Length];
    for (var i = 0; i < _s.Length; i++)
      x[i] = double.Parse(_s[i]);

    return x;
  }

  public static BigInteger[] bigs()
  {
    var _s = Console.ReadLine().Split();

    var x = new BigInteger[_s.Length];
    for (var i = 0; i < _s.Length; i++)
      x[i] = BigInteger.Parse(_s[i]);

    return x;
  }
}









Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define mod 1000000007
using namespace std;

int main()
{
    int n;
    cin>>n;
    
    vector<int> arr(n);
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
    }
    
    vector<int> dp(n);
    dp[0] = 0;
    for(int i=1; i<n; i++)
    {
        if(i == 1)
        {
            dp[i] = dp[i-1]+abs(arr[i]-arr[i-1]);
            continue;
        }
        dp[i] = min(dp[i-1]+abs(arr[i]-arr[i-1]), dp[i-2]+abs(arr[i]-arr[i-2]));
    }
    
    cout<<dp[n-1]<<endl;
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> A;
  for(int i=0; i<N; ++i){
    int temp;
    cin >> temp;
    A.push_back(temp);
  }
  sort(A.begin(), A.end());
  vector<int>::iterator itr = unique(A.begin(), A.end());
  if(itr == A.end()){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 1400
import java.util.Scanner;

/**
 * Created by sonetsuyoshi on 2016/07/31.
 */
public class Main {

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

        long count = 0;

        for(long x = 0; x <= k; x++) {
            long s1 = s - x;
            if(s1 < 0) break;
            else if(s1 >= 0 && s1 <= k) {
                count += s1 + 1;
            } else if(k < s1 && s1 <= 2 * k) {
                count += 2 * k - s1 + 1;
            }
        }
        System.out.println(count);
    }
}

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

void _129() {
    int p, q, r;
    cin >> p >> q >> r;

    cout << min(p + q, min(q + r, p + r)) << endl;
}

void _128() {
    int a, p;
    cin >> a >> p;
    cout << (a * 3 + p) / 2 << endl;
}

int main()
{
    _128();
    return 0;
}



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

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

    if (a >= 13)
    {
        cout << b << endl;
    }
    else if (a >= 6 && a <= 12)
    {
        cout << b / 2 << endl;
    }

    else if (a <= 5)
    {
        cout << "0" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
typedef vector<ll> vi;
#define fi first
#define se second
#define show(x) cout << #x << " is " << x << "\n";
const ll inf = 9e18;
const ll mod = 1e9 + 7;
const ld pi = 3.141592653589793238462643383279502884;

void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}
ll power(ll x, ll y, ll M = inf){
	if(y<=0) return 1;
    ll ans = 1;
    x %= M;
    while(y){
        if(y&1)
            ans = (x * ans) % M;

        x = (x * x) % M;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {return power(n, mod-2, mod);}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

//------------------------------------------------------------------------------------------

//const ll N = 1e5 + 1;
//vector<ll> adj[N];
//bool visited[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cout<<fixed<<setprecision(10);


	ll n, d;
	cin>>n>>d;
	cout<<(n+2*d)/(2*d+1);

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;



int main(){
  ios_base::sync_with_stdio(false);

  int c[11][11];

  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin >> c[i][j];
    }
  }

  for(int i=0;i<3;i++){
    int num = (1 << 23);
    for(int j=0;j<3;j++){
      num = min(num, c[i][j]);
    }
    for(int j=0;j<3;j++){
      c[i][j] -= num;
    }
  }

  for(int i=0;i<3;i++){
    int num = (1 << 23);
    for(int j=0;j<3;j++){
      num = min(num, c[j][i]);
    }
    for(int j=0;j<3;j++){
      c[j][i] -= num;
    }
  }

  int f = 0;
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      if(c[i][j]){
        f=1;
        break;
      }
    }
  }

  if(f)cout << "No" << endl;
  else cout << "Yes" << endl;
  
  /*
  cout << endl;
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cout << c[i][j];
    }
    cout << endl;
  }
  */

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n, k;
    cin >> n >> k;
    
    int count = 0;
    for(int i = 0; i < n; i++) {
        int h;
        cin >> h;
        
        if(h >= k) count++;
    }
    
    cout << count << endl;
}


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

using namespace std;
typedef long long ll;
//typedef pair<int, int> P;
//static const int dx[4] = {1, -1, 0, 0};
//static const int dy[4] = {0, 0, 1, -1};

//static const ll MOD = 1e+9 + 7;
//static const int MAX = 10001;


int main() {
    int N; cin >> N;
    vector<ll> a(N+1), b(N);
    for (int i = 0; i <= N; i++)
        cin >> a[i];
    for (int i = 0; i < N; i++)
        cin >> b[i];
   
    ll ans = accumulate(a.begin(), a.end(), 0LL);
    for (int i = N-1; i >= 0; i--) {
        ll temp1 = a[i+1];
        a[i+1] = max(a[i+1] - b[i], 0LL);
        b[i] = max(b[i] - temp1, 0LL);

        /*
    for (int i = 0; i <= N; i++)
    cout << a[i] << ' ';
    cout << '\n';
    for (int i = 0; i < N; i++)
    cout << b[i] << ' ';
    cout << '\n';
    */
 
        ll temp2 = a[i];
        a[i] = max(a[i] - b[i], 0LL);
        b[i] = max(b[i] - temp2, 0LL);
        /*
    for (int i = 0; i <= N; i++)
    cout << a[i] << ' ';
    cout << '\n';
    for (int i = 0; i < N; i++)
    cout << b[i] << ' ';
    cout << '\n';
    */
 
    }

    ans -= accumulate(a.begin(), a.end(), 0LL);

    /*
    for (int i = 0; i <= N; i++)
    cout << a[i] << ' ';
    cout << '\n';
    for (int i = 0; i < N; i++)
    cout << b[i] << ' ';
    cout << '\n';
    */
 
    cout << ans << '\n';

}


Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int main(){
  int N;
  cin >> N;
  int ans;
  if(N<105) ans=0;
  if(N>=105 && N<135) ans = 1;
  if(N>=135 && N<165) ans = 2;
  if(N>=165 && N<189) ans = 3;
  if(N>=189 && N<195) ans = 4;
  if(N>=195) ans = 5;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;

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



    while(true){
    int n = sc.nextInt();
    if(n==0){
        break;
    }
    int sum=0;
    int ave;
    int[] score;
    score =new int[n];

    

    for(int i=0;i<score.length;i++){
        score[i]=sc.nextInt();
    }

    Arrays.sort(score);

    for(int i=1;i<score.length-1;i++){
        sum =sum+score[i];
    }

    ave=sum/(score.length-2);

    System.out.printf("%d\n",ave);



}

sc.close();
}

}


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

int main() {
    int n, k, x = 1, sum = 0;
    cin >> n >> k;

    for (int i = 0; i < n; i++) {
        if (x * 2 > (x + k)) x += k;
        else x *= 2;
    }
    cout << x << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.PrintWriter
import kotlin.comparisons.compareByDescending
import kotlin.comparisons.thenByDescending

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    var (N, H) = nextLongList()
    val AB = Array(N.toInt()) {
        val (a, b) = nextLongList()
        P(a, b)
    }.sortedWith(compareByDescending(P::a).thenByDescending(P::b))
    val (amax, b) = AB.first()
    var ans = 0L
    for (p in AB.filter { it.b > amax }.sortedByDescending { it.b }) {
        H -= p.b
        ans++
        if (H <= 0L) break
    }
    if (H > 0L) {
        ans += (H + amax - 1) / amax
    }
    println(ans)
}

data class P(val a: Long, val b: Long)

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

int main() {
  int n,p = 0;
  cin >> n;
  for(int c = 0;c < 26;c++){
    for(int d = 0;d < 15;d++){
      if(c*4+d*7 == n){
        p = 1;
        break;
      }
    }
  }
  if(p == 0){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val xs = Array.fill(n)(sc.nextInt())

  val ans = Array.fill(n)(-1)
  val (l, r) = xs.zipWithIndex.sortBy(_._1).splitAt(n/2)
  val ml = l.last._1
  val mr = r.head._1
  for ((_, idx) <- l) {
    ans(idx) = mr
  }

  for ((_, idx) <- r) {
    ans(idx) = ml
  }

  val pw = new java.io.PrintWriter(Console.out)
  ans.foreach(pw.println)
  pw.flush()
}


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

signed main(){

  int n;
  cin>>n;
  vector<int64_t> a(n);
  for(auto& ai:a)cin>>ai;

  int64_t s = 0;
  int64_t x = 0;
  int64_t ans = 0;
  int l,r=0;
  for(l=0;l<n;++l){
    while(r<n&&s+a[r]==(x^a[r])){
      s+=a[r];x^=a[r];r++;
    }
    ans+=r-l;s-=a[l];x^=a[l];
  }
  cout<<(ans)<<endl;

}

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

using namespace std;

#define pq priority_queue
#define MZ 1000000007

map <long long,int> mp;
long long sum[200005];

int main()
{
    int n;
    long long ans=0;
    scanf("%d",&n);
    mp[0]=1;
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&sum[i]);
        sum[i]+=sum[i-1];
        ans+=mp[sum[i]];
        mp[sum[i]]++;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 14336
#include <iostream>
using namespace std;
int main(){
	int a[4],b[4];
	while(cin>>a[0]>>a[1]>>a[2]>>a[3]>>b[0]>>b[1]>>b[2]>>b[3]){
		int h=0,bl=0;
		for(int i=0;i<4;i++){
			if(a[i]==b[i]){
				h++;
				continue;
			}
			for(int j=0;j<4;j++){
				if(a[i]==b[j]){
					bl++;
					break;
				}
			}
		}
		cout<<h<<" "<<bl<<endl;
	}
}


Measured memory_bytes: 1156
#include <cstdio>
#include <cmath>

using namespace std;

int n,sx,sy,mx,my;
int xi[22],yi[22];
bool used[22];
const double eps = 1e-8;
inline double sc(double a){return a*a;}
#define R(a,b) (sqrt(sc(a)+sc(b)))

bool solve(int a,int p,double t,double x,double y)
{
  //printf("%d %f %f %f\n",a,t,x,y);
  if( a == n ) return true;
  for(int i = 0; i < n; i++) {
    if(!used[i]) {
      if( R(xi[i]-mx,yi[i]-my) < t+R(x-xi[i],y-yi[i])+eps ) {
        return false;
      }
    }
  }
  for(int i = 0; i < n; i++) {
    if(!used[i]) {
      used[i]=true;
      if(solve(a+1,i,t+R(x-xi[i],y-yi[i]),xi[i],yi[i]))return true;
      used[i]=false;
    }
  }
  return false;
}

int main(void)
{
  for(;;) {
    scanf("%d%d%d%d%d",&n,&sx,&sy,&mx,&my); if(!n)break;
    for(int i = 0; i < n; i++) {
      used[i] = false;
      scanf("%d%d",xi+i,yi+i);
    }
    bool res = solve(0,-1,0,sx,sy);
    puts(res ? "YES" : "NO");
  }
  return 0;
}

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

int main(){
    int n;
    char ans[100];
    char s[1100];
    int value;
    int h = 0,w,cnt;
    bool judge;
    char tmp[9][6] = {{".,!? "},{"abc"},{"def"},{"ghi"},{"jkl"},{"mno"},{"pqrs"},{"tuv"},
        {"wxyz"}};
    cin >> n;
    while(n--){
        value = 0;
        memset(ans,0,sizeof(ans));
        memset(s,0,sizeof(s));
        cin >> s;
        for(int i=0;i<strlen(s);i++){
            cnt = 0;
            h = 0;
            while(1){
                if(s[i] == '0') break;
                h = s[i]%'0';
                cnt++;  
                i++;
            }
            w = cnt-1;
            judge = false;
            switch (h-1){
                case 1:
                case 2:
                case 3:
                case 4:
                case 5:
                case 7:
                    ans[value] = tmp[h-1][w%3];
                    judge = true;
                    break;
                case 6:
                case 8:
                    ans[value] = tmp[h-1][w%4];
                    judge = true;
                    break;
                case 0:
                    ans[value] = tmp[h-1][w%5];
                    judge = true;
            }
            if(judge) value++;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1160
unittest
{
	assert( [ "4 3", "3553" ].parse.expand.solve == 2 );		// 追加ケース
	assert( [ "4 2", "1221" ].parse.expand.solve == 5 );		// 追加ケース
	
	assert( [ "4 3", "3543" ].parse.expand.solve == 6 );
	assert( [ "4 2", "2020" ].parse.expand.solve == 10 );
	assert( [ "20 11", "33883322005544116655" ].parse.expand.solve == 68 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto np = input.front.split.to!( long[] );
	input.popFront;
	auto ss = input.front.map!( ( a ) => ( a - '0' ).to!long ).array;
	return tuple( np[ 1 ], ss );
}

auto solve( long p, long[] ss )
{
	auto ans = 0L;
	if( 10 % p == 0 )
	{
		// 10 が p で割り切れる場合、10の位以上は絶対に p で割り切れるので、1の位だけ見て判定する
		foreach( i, s; ss )
		{
			if( s % p == 0 ) ans += i + 1;
		}
	}
	else
	{
		// 10 と p が互いに素である場合、以下が成り立つ l と r のペアの数を計算する
		// ( ss[ l .. $ ] - ss[ r .. $ ] ) / 10 ^^ ( $ - 1 - r ) ≡ 0 ( mod p ) ( l < r )
		// ss[ l .. $ ] ≡ ss[ r .. $ ] ( mod p ) ( l < r )
		auto ts = new long[ p ];
		auto m = 0L;		// ss[ i .. $ ] ( mod p )
		auto f = 1L;		// 10 ^^ ( $ - 1 - i ) ( mod p )
		ts[ 0 ]++;			// ss[ $ .. $ ] の分のカウント
		foreach_reverse( i, s; ss )
		{
			m = ( m + s * f ) % p;
			f = ( f * 10 ) % p;
			ts[ m ]++;
		}
		foreach( t; ts )
		{
			ans += t * ( t - 1 ) / 2;
		}
	}
	return ans;
}


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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rept(i,k,n) for(ll i = (k); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<long long,long long> Pll;
typedef tuple<int,int,int> Tii;

template <typename T>
ostream& operator<<(ostream& s, const vector<T> &vec){
    for(int i=0;i<vec.size();i++){
        if(i) s << ',';
        else s << '{';
        s <<setw(2)<< vec[i];
    }
    s << '}' << endl;
    return s;
}


int main(){
    ll n;
    cin>>n;
    vector<ll> cnt(1e5,0);
    ll sum=0;
    rep(i,n){
        ll a;
        cin>>a;
        cnt[a]++;
        sum+=a;
    }
    ll q;cin>>q;
    rep(i,q){
        int b,c;
        cin>>b>>c;
        cnt[c]+=cnt[b];
        sum+=(c-b)*cnt[b];
        cnt[b]=0;
        cout<<sum<<endl;
    }
    return 0;
}

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

int main() {
	int n,t;
	cin >> n >> t;
	ll ans = 0;
	bool on = false;
	ll start = 0;
	ll end = 0;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		if (on == false) {
			on = true;
			start = x;
			end = x + t;
		}
		else if (on == true && x <= end) end = x + t;
		else {
			ans += end - start;
			start = x;
			end = x + t;
		}
	}
	ans += end - start;
	cout << ans << endl;
}

Measured memory_bytes: 256