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

#define M 1000003
#define h 13

char H[M][h];


int getvalue(char ch) {
    if ( ch == 'A' ) return 1;
    else if ( ch == 'C' ) return 2;
    else if ( ch == 'G' ) return 3;
    else if ( ch == 'T' ) return 4;
    else return 0;
}

long long getstring(char ch[]) {
    long long  p = 1, sum = 0;
    for ( int i = 0; i < strlen(ch); i++ ) {
        sum = sum + p*(getvalue(ch[i]));
        p *= 5;
    }

    return sum;
}

int h1(long long key){
    return key % M;
}

int h2(long long key){
    return 1 + key % (M-1);
}

int insertstr(char ch[]){
    long long key;
    long long value, value1, value2;
    key = getstring(ch);
    value1 = h1(key);
    value2 = h2(key);
    for ( int i = 0;; i++ ) {
        value = (value1 + i * value2) % M;
        if ( strcmp(H[value], ch) == 0 ) return 1;
        else if ( strlen(H[value]) == 0 ) {
            strcpy(H[value], ch);
            return 1;
        }
    }
    return 0;
}

int searchstr(char ch[]){
    long long key;
    long long value,value1, value2;
    key = getstring(ch);
    value1 = h1(key);
    value2 = h2(key);
    for ( int i = 0;; i++ ) {
        value = (value1 + i * value2) % M;
        if ( strlen(H[value]) == 0 ) return 0;
        else if ( strcmp(H[value], ch) == 0 ) return 1;
    }
    return 0;
}

int main(){
    int n;
    scanf("%d", &n);
    
    char str[h], com[9];

    for ( int i = 0; i < n; i++ ) {
        scanf("%s %s",  com, str);
        if ( com[0] == 'i' ) insertstr(str);
        else if ( com[0] == 'f' ) {
            if ( searchstr(str) ) {
                printf("yes\n");
            } else {
                printf("no\n");
            }
        }
    }

    return 0;
}





Measured memory_bytes: 15236
import kotlin.math.*
import java.util.*

const val y = 2019

fun main(args: Array<String>) {
  val s = readLine()!!.reversed()
  if (s.length < 4) {
    println(0)
    return
  }
  val t = IntArray(s.length + 1)
  t[0] = s[0] - '0'
  var d = 10
  for (i in 1 until s.length) {
    t[i] = (t[i - 1] + (s[i] - '0') * d) % y
    d = (10 * d) % y
  }
  val u = IntArray(y)
  t.forEach { u[it]++ }
  println(u.map { it * (it - 1) / 2 }.sum())
}


Measured memory_bytes: 42568
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int s = sc.nextInt();
        ArrayList<Number> list = new ArrayList<Number>();
        list.add(s);
        int count = 0;
        while(true){
            
            if(s%2 == 0){
                s = s/2;
            }else{
                s = 3*s + 1;
            }
            count++;
            if(list.contains(s)){
                System.out.println(count+1);
                return;
            }else{
                list.add(s);
            }
        }
    }
}


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

h, w = map(int,input().split())
C = [input() for i in range(h)]
mod = 10**9 + 7

D = [[0] * w for i in range(h)]
D[0][0] = 1
for i in range(h):
    for j in range(w):
        if (i!=0 or j!=0) and C[i][j]==".":
            if i-1 >= 0:
                D[i][j] += D[i-1][j]
            if j-1 >= 0:
                D[i][j] += D[i][j-1]
            D[i][j] %= mod
print(D[-1][-1])

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

int main() {
  string S;
  long long K;
  cin >> S >> K;
  
  char ans;
  int count =0;
  for(int i=0; i<S.size(); i++){
    if(S.at(i)=='1')count ++;
    else break;
  }
  
  if(K<=count)ans ='1';
  else ans = S.at(count);
  
  cout << ans << endl;
    
}


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

using namespace std;
int main()
{
     int n,l;
     cin>>n>>l;
     string a[1001];
     for(int i=0;i<n;++i)
        cin>>a[i];
     sort(a,a+n);
     for(int i=0;i<n;++i) cout<<a[i];
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int numc = num;
		int sum = 0;
		for(int i = 0; i < String.valueOf(num).length(); i++) {
			sum = sum + numc % 10;
			numc = numc / 10;
		}
		if(num % sum == 0)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}


Measured memory_bytes: 23380
n = int(input().rstrip())
passed = set()

from sys import exit
cnt = 1
tmp = 7
while 1:
    if tmp % n == 0:
        print(cnt)
        exit()
    elif tmp not in passed:
        passed.add(tmp)
        cnt += 1
        tmp = (tmp*10+7) % n
    else:
        print(-1)
        exit()

Measured memory_bytes: 77960
program main
 implicit none
 integer*8 n,s1,s2,ans,tmp,i
 integer*8, allocatable :: w(:)
 read(*,*) n
 allocate(w(1:n))
 read(*,*)w
 s1=0
 s2=0
 do i=1,n
  s1 = s1 + w(i)
 end do
 ans = s1
 tmp = ans
 do i=1,n
  s2 = s2 + w(i)
  s1 = s1 - w(i)
  tmp = s1 - s2
  if (tmp < 0) then
   if(abs(tmp) < ans) then
    ans = abs(tmp)
   end if
   exit
  end if
  ans = tmp
 end do
 write(*,*) ans
end program main

Measured memory_bytes: 768
#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?"":"\n");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() {
    while (1) {
        int N, M, C;
        cin >> N >> M >> C;
        if (!N && !M && !C) break;
        vector<tuple<int, int, int>> E(M);
        REP(i, M) {
            int a, b, c;
            cin >> a >> b >> c;
            a--, b--;
            E[i] = make_tuple(c, a, b);
        }
        sort(RALL(E));
        vector<vector<pii>> g(N);
        REP(i, M) {
            int c, a, b;
            tie(c, a, b) = E[i];
            g[a].push_back({b, i});
        }

        int ans = INF;
        vector<vector<int>> dist(N, vector<int>(N + 1, INF));
        heap<vi> hp;
        hp.push({0, 0, 0});
        dist[0][0] = 0;
        while (!hp.empty()) {
            int v = hp.top()[1];
            int cnt = hp.top()[2]; hp.pop();
            FORE(e, g[v]) {
                int w = e.first;
                int idx = e.second;
                int cost = get<0>(E[idx]);
                if (chmin(dist[w][cnt], dist[v][cnt] + cost)) {
                    hp.push({dist[w][cnt], w, cnt});
                }
                if (cnt + 1 > N) continue;
                if (chmin(dist[w][cnt + 1], dist[v][cnt])) {
                    hp.push({dist[w][cnt + 1], w, cnt + 1});
                }
            }
        }
        REP(i, M + 1) {
            if (dist[N - 1][i] <= C) {
                chmin(ans, i);
                break;
            }
        }
        cout << ans << endl;
    }
    return (0^_^0);
}




Measured memory_bytes: 3728
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
const int M = 1e9 + 7;
const ll MLL = 1e18L + 9;
#pragma unused(M)
#pragma unused(MLL)
#ifdef LOCAL
#include"rprint.hpp"
#else
template <ostream& out = cout, class... T> void prints(T&&...){ }
template <ostream& out = cout, class... T> void printd(T&&...){ }
template <ostream& out = cout, class... T> void printde(T&&...){ }
template <ostream& out = cout, class... T> void printb(T&&...){ }
template <ostream& out = cout, class... T> void printArr(T&&...){ }
#endif

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string a; cin >> a;
    int n = a.size();
    ll ans = 1;
    unordered_map<int, int> mp;
    for(int i = 0; i < n; i++){
        ans += i - mp[a[i]];
        mp[a[i]]++;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 720
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
#include <iomanip>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,(n))
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 2;
const int MOD = 1000000007;
typedef vector<ll> vl;
typedef vector<vl> vvl;

int main() {
	int N, M, a;
	cin >> N >> M;
	vi dp(N+1);
	REP(i, M) {
		cin >> a;
		dp[a] = -1;
	}
	
	dp[0] = 1;
	FOR(i, 0, N) {
		if (dp[i] == -1) {
			continue;
		}
		if (dp[i+1] != -1) {
			dp[i+1] = (dp[i] + dp[i+1]) % MOD;
		}
		if (i+2 <= N && dp[i+2] != -1) {
			dp[i+2] = (dp[i] + dp[i+2]) % MOD;
		}
	}

	cout << dp[N] << endl;
	return 0;
}

Measured memory_bytes: 640
import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		Set<String> s = new HashSet<String>();
		int N = sc.nextInt();
		while (N-->0) s.add(sc.next());
		System.out.println(s.size()==4 ? "Four" : "Three");
		sc.close();		
	}

	public static void main(String args[]) {
		solve();
	}

}

Measured memory_bytes: 35920
import sys
dic={}
for alp in [chr(i) for i in range(ord('a'), ord('z')+1)]:
    dic[alp]=0
s=sys.stdin.read()
for m in s:
    if m.isalpha():
        if m.isupper()==True:
            m_=m.lower()
            dic[m_]+=1
        else:
            dic[m]+=1
for k in dic:
    print("{} : {}".format(k,dic[k]))


Measured memory_bytes: 5564
#include <bits/stdc++.h>
using namespace std;
int main(){
	int k, a, b;
	cin >> k >> a >> b;
	if (a/k!=b/k||a%k==0||b%k==0){
		cout << "OK" << endl;
		return 0;
	}
	cout << "NG" << endl;
	return 0;
}

Measured memory_bytes: 3636
/* *****fireice**** */

#include<bits/stdc++.h>

#define ll long long int
#define ld long double
#define vi vector<int>
#define vc vector<char>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define pii pair<int,int>
#define pb push_back
#define eb emplace_back
#define el '\n'
#define N 1000000007
#define re return
#define F first
#define S second
#define L length
#define deb(x) cout<<#x<<" "<<x<<el;
#define mp make_pair
#define PI 3.14159265
#define all(a) (a).begin(),(a).end()
#define forup(i,n) for(int i=0;i<n;i++)
#define forf(i,x,n) for(int i=x;i<n;i++)
#define ford(i,n) for(int (i)=(n)-1;i>=0;(i)--)
#define take(a,n) forup(i,n) cin>>a[i];
using namespace std;

int gcdExtended(int a, int b, int *x, int *y)
{
    // Base Case
    if (a == 0)
    {
        *x = 0, *y = 1;
        return b;
    }

    int x1, y1; // To store results of recursive call
    int gcd = gcdExtended(b%a, a, &x1, &y1);

    // Update x and y using results of recursive
    // call
    *x = y1 - (b/a) * x1;
    *y = x1;

    return gcd;
}

ll modInverse(int a, int m)
{
    int x, y;
    int g = gcdExtended(a, m, &x, &y);
        // m is added to handle negative x
    ll res = ((ll)x%m + (ll)m) % m;

    return res;
}

ll poww(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n==1) return x;
    else if(n%2 == 0)        //n is even
        return poww(x*x,n/2);
    else                              //n is odd
        return x*poww(x*x,(n-1)/2);
}

ll modularExponentiation(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}

template<typename T>
T maxx(T a,T b)
{
  if(a<b) re b;
  re b;
}
template<typename T, typename... Args>
T maxx(T a,T b, Args... args)
{
    re(maxx(maxx(a,b),args...));
}

template<typename T>
T minn(T a,T b)
{
  if(a<b) re a;
  re b;
}
template<typename T, typename... Args>
T minn(T a,T b, Args... args)
{
    re(minn(minn(a,b),args...));
}

template<typename T>
void read(T& a)
{
  cin>>a;
}
template<typename T, typename... Args>
void read(T& a,Args&... args)
{
  cin>>a; read(args...);
}

template<typename T>
void write(T a)
{
  cout<<a<<' ';
}
template<typename T, typename... Args>
void write(T a,Args... args)
{
  cout<<a<<' '; write(args...);
}

inline ll min(ll a,ll b)
{
  if(a<b) re a;
  else re b;
}
inline ll max(ll a,ll b)
{
  if(a<b) re b;
  else re a;
}

ll gcd(ll a, ll b)
{
    if (a == 0)
       return b;
    if (b == 0)
       return a;

    if (a == b)
        return a;

    if (a > b)
        return gcd(a-b, b);
    else return gcd(a, b-a);
}

ll ncr(int n,int r)
{
  ll ans=1;
  r=min(r,n-r);
  forup(i,r)
  {
    ans=((ans*((n-i)%N))%N*modInverse(i+1,N))%N;
  }
  re ans;
}

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

  int t=1;
  //cin>>t;
  while(t--)
  {
    ll n,m,k,a,b;
    read(n,a,b);
    m=modularExponentiation(2,n,N)-1;
    // deb(m);deb(ncr(n,a));deb(ncr(n,b));
    cout<<(m-ncr(n,a)-ncr(n,b)+(5LL)*N)%N;

  }


  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN];
int head, tail,n;

void enqueue(P x){
  Q[tail] = x;
  tail = (tail + 1) % LEN;

}

P dequeue(){
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}

int min(int a,int b){
  return a<b ? a:b;
}

int main(){
  int elaps = 0, c;
  int i, q;
  P u;

  scanf("%d %d",&n, &q);

  for(i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }

  tail = n+1;
  head = 1;

  while(head != tail){
    u = dequeue();
    c = min(q,u.t);

    elaps += c;
    u.t -= c;

    if(u.t>0) enqueue(u);
    else{
      printf("%s %d\n", u.name, elaps);
    }

  }
  return 0;
}



Measured memory_bytes: 11896
// 解き直し.
// https://img.atcoder.jp/abc166/editorial.pdf
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define pb push_back
const string ABC[] = {"AB", "BC", "CA"};
vector<string> v;


int main(){
    
    // 1. 入力情報.
    int N;
    LL A, B, C;
    map<char, LL> m;
    scanf("%d %lld %lld %lld", &N, &A, &B, &C);
    m['A'] = A;
    m['B'] = B;
    m['C'] = C;
    rep(i, N){
        char c[11];
        scanf("%s", c);
        string s(c);
        if(s == "AC") v.pb("CA");
        else          v.pb(s);
    }
    
    // 2. A, B, C が 負にならないように操作できるか？
    bool ok = true;
    queue<char> q;
    
    // 2-1. A + B + C = 0.
    if(A + B + C == 0) ok = false;
    
    // 2-2. A + B + C = 1.
    if(A + B + C == 1){
        rep(i, N){
            // "AB", "AC", "BC" の いずれに等しいか確認.
            rep(j, 3){
                if(ABC[j] == v[i]){
                    char x = ABC[j][0], y = ABC[j][1];
                    if(m[x] > m[y]) m[x]--, m[y]++, q.push(y);
                    else            m[x]++, m[y]--, q.push(x);
                    if(m[x] < 0 || m[y] < 0) ok = false;
                    break;
                }
            }
            if(!ok) break;
        }
    }
    
    // 2-3. A + B + C >= 2.
    if(A + B + C >= 2){
        rep(i, N){
            // "AB", "AC", "BC" の いずれに等しいか確認.
            rep(j, 3){
                if(ABC[j] == v[i]){
                    char x = ABC[j][0], y = ABC[j][1];
                    if(m[x] > m[y]){
                        m[x]--, m[y]++, q.push(y);
                    }else{
                        if(m[x] == 1 && m[y] == 1){
                            if(i < N - 1 && v[i] != v[i + 1]){
                                // 次の要素.
                                char nx = v[i + 1][0], ny = v[i + 1][1];
                                if(x == nx || x == ny) m[x]++, m[y]--, q.push(x);
                                else                   m[x]--, m[y]++, q.push(y);
                            }else{
                                m[x]++, m[y]--, q.push(x);
                            }
                        }else{
                            m[x]++, m[y]--, q.push(x);
                        }
                    }
                    if(m[x] < 0 || m[y] < 0) ok = false;
                    break;
                }
            }
            if(!ok) break;
        }
    }
    
    // 3. 出力.
    printf("%s\n", ok ? "Yes" : "No");
    if(ok){
        while(!q.empty()){
            char ans = q.front();
            q.pop();
            printf("%c\n", ans);
        }
    }
    return 0;
    
}

Measured memory_bytes: 7468
INF = 10 ** 9 + 10
MAX_V = 1010

N, W = map(int, input().split())
MAX_SUM_V = N * MAX_V

w = [0] * N
v = [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())

dp = [[INF] * MAX_SUM_V for _ in range(N + 1)]
dp[0][0] = 0
for i in range(N):
    for sum_v in range(MAX_SUM_V):
        if sum_v - v[i] >= 0:
            dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v - v[i]] + w[i])
        dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v])

for sum_v in range(MAX_SUM_V):
    if(dp[N][sum_v] <= W):
        res = sum_v
print(res)

Measured memory_bytes: 120428
#include <algorithm>
#include <iostream>
#include <vector>
#define MAX_N 100000
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) { cin >> A[i]; }
  sort(A.begin(), A.end());
  vector<int> B(N);
  rep(i, N) { cin >> B[i]; }
  // sort(B.begin(), B.end());
  vector<int> C(N);
  rep(i, N) { cin >> C[i]; }
  sort(C.begin(), C.end());

  int64_t Ans = 0;
  rep(bi, N) {
    auto ai = lower_bound(A.begin(), A.end(), B[bi]);
    auto ci = upper_bound(C.begin(), C.end(), B[bi]);
    Ans += (ai - A.begin()) * (C.end() - ci);
  }
  cout << Ans << endl;
  return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<queue>
#include<numeric>
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<vector<int>> v(n, vector<int>(n-1));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n-1; j++){
            cin >> v[i][j];
            v[i][j]--;
        }
    }
    vector<vector<int>> num(n, vector<int>(n));
    int k = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            num[i][j] = num[j][i] = k++;
        }
    }
    vector<int> edge[k], indeg(k, 0);
    for(int i = 0; i < n; i++){
        for(int j = 0; j+1 < n-1; j++){
            int ida = num[i][v[i][j]], idb = num[i][v[i][j+1]];
            edge[ida].push_back(idb);
            indeg[idb]++;
        }
    }
    queue<pair<int,int>> q;
    for(int i = 0; i < k; i++){
        if(indeg[i] == 0)   q.push({i, 1});
    }
    int ans;
    while(!q.empty()){
        auto p = q.front(); q.pop();
        ans = p.second;
        for(int next : edge[p.first]){
            indeg[next]--;
            if(indeg[next] == 0){
                q.push({next, ans+1});
            }
        }
    }
    cout << (accumulate(indeg.begin(), indeg.end(), 0ll) == 0 ? ans : -1) << endl;
    return 0;
}


Measured memory_bytes: 37376
// She is Pretty pretty!
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ff first
#define ss second
#define mp make_pair
#define pb push_back

// bitmask dp,bf
const int N = 1e3 + 100;
int a[15][N], sum[15][N], n, m, k, b[15];
char s[15][N];
int cnt;
int get(int l1, int r1, int l2, int r2) {
    return sum[l2][r2] - sum[l1 - 1][r2] - sum[l2][r1 - 1] +
           sum[l1 - 1][r1 - 1];
}
pair<int, int> pr[N];
int work() {
    int r1 = 1, r2 = 1, t = 0;
    for (int i = 1; i <= m; i++) {
        int fl = 1;
        for (int j = 1; j <= cnt && fl; j++) {
            if (get(pr[j].ff, r1, pr[j].ss, r2) <= k) {
                continue;
            } else {
                fl = 0;
            }
        }
        if (!fl) {
            if (r1 == r2) return INT_MAX/2;
            t++;
            r1 = r2;
            r2++;
        } else
            r2++;
    }
    return t;
}   
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> s[i][j];
            a[i][j] = s[i][j] - '0';
            sum[i][j] =
                sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + a[i][j];
        }
    }
    int end = (1 << n) - 1;
    int ans = INT_MAX;
    for (int j = 0; j <= end; j++) {
        vector<int> b(n + 1, 0);
        for (int k = 0; k < n; k++) {
            if ((j >> k) & 1) b[k + 1] = 1;
        }
        int t = 0;
        cnt = 0;
        int pre = b[1], l2 = 1, l1 = 1;
        for (int k = 2; k <= n; k++) {
            if (b[k] == pre)
                l2++;
            else {
                t++;
                pr[++cnt] = {l1, l2};
                l1 = k, l2 = k;
                pre = b[k];
            }
        }
        pr[++cnt] = {l1, l2};
        t += work();
        ans = min(ans, t);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

C=[a-b for a,b in zip(A,B)]

plus=[i for i in C if i>=0]
minus=[i for i in C if i<0]
plus.sort(reverse=True)

sum_minus=sum(minus)
ans=len(minus)

for i in plus:
    if sum_minus>=0:
        break
    sum_minus+=i
    ans+=1

if sum_minus<0:
    ans=-1

print(ans)

Measured memory_bytes: 18356
#include <bits/stdc++.h>
using namespace std;
const int maxn = 123456, lg = 20;
int a[maxn], p[lg][maxn];
int main(){
	int n; cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	int L; cin >> L;
	int j = 0;
	for(int i = 0; i < n; i++){
		while(j + 1 < n && a[j + 1] - a[i] <= L) j++;
		p[0][i] = j;
	}
	for(int i = 1; i < lg; i++){
		for(int j = 0; j < n; j++){
			p[i][j] = p[i - 1][p[i - 1][j]];
		}
	}
	int q; cin >> q;
	while(q--){
		int l, r; cin >> l >> r;
		if(l > r) swap(l, r);
		l--; r--;
		int ans = 0;
		for(int i = lg - 1; i >= 0; i--) if(p[i][l] < r) l = p[i][l], ans |= 1<<i;
		ans++;
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 10240
#include <stdio.h>

int main(void){
  int N, K; char S[60];
  scanf("%d %d", &N, &K);
  scanf("%s", &S);
  if(S[K-1]=='A'){
    S[K-1]='a';
  }
  else if(S[K-1]=='B'){
    S[K-1]='b';
  }
  else{
    S[K-1]='c';
  }
  printf("%s", S);
  return(0);
}


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

using namespace std;

typedef long long ll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

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

	string s, t;
	cin >> s >> t;

	int n = s.size();
	if(t.substr(0, n) == s){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}

}


Measured memory_bytes: 3616
import itertools
n,k = map(int,input().split())

ab = [0]*n

for i in range(n):
  ab[i] = input().split()
a = []
b = []
for i in range(n):
  tmp1 = int(ab[i][0])
  tmp2 = int(ab[i][1])
  a.append(tmp1)
  b.append(tmp2)
ab = zip(a,b)
ab = sorted(ab)
a,b = zip(*ab)

s = 0
for i in range(n):
  s += int(b[i])
  if s >= k:
    print(int(ab[i][0]))
    exit()

Measured memory_bytes: 108472
n, k = map(int, input().split())
alst = list(map(int, input().split()))

total_1 = 0
total_2 = 0
for i in range(k):
    total_1 += min(0, alst[i])
    total_2 += max(0, alst[i])
t_max = total_1
t_min = total_2
max_pos = 0
min_pos = 0
for i in range(n - k):
    total_1 += min(alst[i + k], 0) - min(alst[i], 0)
    total_2 += max(alst[i + k], 0) - max(alst[i], 0)
    if total_1 > t_max:
        t_max = total_1
        max_pos = i + 1
    if total_2 < t_min:
        t_min = total_2
        min_pos = i + 1
ans = 0
ans2 = 0

for i, num in enumerate(alst):
    if max_pos <= i < max_pos + k:
        ans += num
    else:
        ans += max(num, 0)
        
    if min_pos <= i < min_pos + k:
        pass
    else:
        ans2 += max(num, 0)

print(max(ans, ans2))

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

int main()
{
    int N;
    cin >> N;
    vector<int> P(N);
    vector<int> Q(N);
    for (int i=0; i<N; i++) cin >> P[i];
    for (int i=0; i<N; i++) cin >> Q[i];
    vector<int> tmp(N);
    for (int i=1; i<=N; i++) tmp[i-1] = i;

    int p=-1;
    int q=-1;
    int id=0;
    do
    {
        id++;
        if (P==tmp) p=id;
        if (Q==tmp) q=id;
    }while(next_permutation(tmp.begin(), tmp.end()));
    cout << abs(p-q) << endl;
}

Measured memory_bytes: 3636
mounten_num, bridge_num = map(int, input().split())
mounten_higests = [0] + list(map(int, input().split()))
not_bad_mountens = ['x'] + ['o'] * mounten_num


# inputをさばく. 橋の架かっている展望台のうち、低いほうはgood_mountenではない
for i in range(bridge_num):
    a, b = map(int, input().split())
    if mounten_higests[a] <= mounten_higests[b]:
        not_bad_mountens[a] = 'x'
    if mounten_higests[a] >= mounten_higests[b]:
        not_bad_mountens[b] = 'x'

print(not_bad_mountens.count('o'))

Measured memory_bytes: 20112
#include<bits/stdc++.h>
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 Would
#define you
#define please


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

	
	ll A, B;
	cin >> A >> B;

	if (A > 0) A--;

	ll A2 = 0;
	rep(i, 41) {
		if (i == 0) {
			int kari = A % 4;
			if (kari == 1 || kari == 2) A2++;
		}
		else {
			ll kari = A % (1ll << (i + 1));
			if (kari >= (1ll << i) && kari % 2 == 0) A2 += (1ll << i);
		}
	}

	ll B2 = 0;
	rep(i, 41) {
		if (i == 0) {
			int kari = B % 4;
			if (kari == 1 || kari == 2) B2++;
		}
		else {
			ll kari = B % (1ll << (i + 1));
			if (kari >= (1ll << i) && kari % 2 == 0) B2 += (1ll << i);
		}
	}

	co(A2 ^ B2);

	Would you please return 0;
}

Measured memory_bytes: 256
dataset = []

while True:
    data = list(map(int,input().split()))
    dataset.append(data)
    if data == [-1,-1,-1]:
        break
    
for i in range(len(dataset)-1):
    if dataset[i][0] == -1 or dataset[i][1] == -1:
        print('F')
    else:
        if dataset[i][0]+dataset[i][1] >= 80:
            print('A')
        elif dataset[i][0]+dataset[i][1] >= 65:
            print('B')
        elif dataset[i][0]+dataset[i][1] >= 50:
            print('C')
        elif dataset[i][0]+dataset[i][1] >= 30:
            if dataset[i][2] >= 50:
                print('C')
            else:
                print('D')
        elif dataset[i][0]+dataset[i][1] < 30:
            print('F')
            
    


Measured memory_bytes: 5608
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <iomanip>
#include <cmath>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;

int main()
{
    // 整数の入力
    ll N,A,B;
    cin >> N >> A >> B;

    cout << min(B , N * A) <<endl;
    return 0;
}

Measured memory_bytes: 256
//------------------------------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//                                                                              NEVER GIVE UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first 
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define LINF 98765432123456789
#define testcases() ll t; cin>>t; while(t--)
#define debug cout<<"Hello\n";
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define debug4(w,x,y,z) cout<<#w<<" "<<w<<" "<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define rep(i,start,end) for(ll i=start;i<end;i++)
#define sz(x) (ll)((x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
//----------------------------------------------------------------------------------------------------------------------------------------------------

int main()
{
	fast;
	ll n,x,y;
	cin>>n;
	vector<pii> v;
	for(ll i=0;i<n;i++)
	{
		cin>>x>>y;
		v.pb({x,1});
		v.pb({y,-1});
	}
	sort(all(v));
	ll pos_sum,neg_sum;
	pos_sum=neg_sum=0;
	ll l,r,ans;
	l=r=-1;
    ll l2,r2;
    l2=r2=-1;
	if(n%2==1)
	{
		for(auto it: v)
		{
			if(it.se==1)
				pos_sum++;
			else
				neg_sum++;
			if(l==-1 && pos_sum==n/2+1)
				l=it.fi;
			if(r==-1 && neg_sum==n/2+1)
				r=it.fi;
		}
	}
	else
	{
		for(auto it: v)
		{
			if(it.se==1)
				pos_sum++;
			else
				neg_sum++;
			if(l==-1 && pos_sum==n/2)
				l=it.fi;
			if(r==-1 && neg_sum==n/2+1)
				r=it.fi;
            if(l2==-1 && pos_sum==n/2+1)
                l2=it.fi;
            if(r2==-1 && neg_sum==n/2)
                r2=it.fi;
		}
        l+=l2;
        r+=r2;
	}
    //debug2(l,r)
	ans = r-l+1;
	cout<<ans;
	return 0;
}


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

#define nn 2000008
int n,m;vector<int> v[nn];int vis[nn];
int q[nn],ql,qr;
void bfsl(int x){
	q[--ql]=x;vis[x]=1;int flg=0;
	for(int i=0;i<v[x].size() and !flg;i++) if(!vis[v[x][i]]) flg=1,bfsl(v[x][i]);
}
void bfsr(int x){
	q[++qr]=x;vis[x]=1;int flg=0;
	for(int i=0;i<v[x].size() and !flg;i++) if(!vis[v[x][i]]) flg=1,bfsr(v[x][i]);
}
signed main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		int x,y;scanf("%d%d",&x,&y);
		v[x].push_back(y);v[y].push_back(x);
	}
	
	int x=1,y=v[x][0];
	ql=nn/2+1,qr=nn/2;vis[y]=1;
	bfsl(x);bfsr(y);
	
	printf("%d\n",qr-ql+1);for(int i=ql;i<=qr;i++) printf("%d ",q[i]);
	return 0;
}

Measured memory_bytes: 60288
#include <bits/stdc++.h>
using namespace std;
const int MAX=3e5+1;
int tree[2*MAX];
void update(int p, int val){
	p+=MAX;
	tree[p]=val;
	for(p/=2; p>=1; p/=2){
		tree[p]=max(tree[p*2], tree[p*2+1]);
	}
}
int get(int l, int r){
	int res=0;
	l+=MAX, r+=MAX;
	while(l<=r){
		if(!(r&1)) res=max(res, tree[r--]);
		if(l&1) res=max(res, tree[l++]);
		r=(r>>1), l=(l>>1);
	}
	return res;
}
int main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n, k;
	cin >> n >> k;
	int a[n];
	int res=0;
	for(int i=0; i<n; i++){
		cin >> a[i];
		int temp=get(max(0, a[i]-k), min(a[i]+k, MAX));
		res=max(res, temp+1);
		update(a[i], temp+1);
	} 
	cout << res;
}

Measured memory_bytes: 7052
#include<bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define mat vector<vec>

using namespace std;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

vector<vector<ll>> bunkai(ll a){
  if(a<=0) return {};
  if(a==1) return {{1,1}};
  vector<ll> f;
  for(ll j=2;j<=a;j++){
    ll b=j;
    for(ll i=2;i*i<=a;i++){
      if(b%i==0){
        f.push_back(i);
        b=b/i;
        i--;
      }
    if(b==1)break;
    }
    if(b!=1)f.push_back(b);
  }

  sort(f.begin(),f.end());
  vector<vector<ll>> u;
  ll p=f[0];
  ll c=1;
  for(ll i=1;i<f.size();i++){
    if(f[i]==p)c++;
    else{
      u.push_back({p,c});
      p=f[i];
      c=1;
    }
  }
  u.push_back({p,c});

  return u;
}

int main(){

  ll n;
  cin >> n;
  mat G=bunkai(n);
  vec a(150);
  for(ll i=0;i<G.size();i++){
    if(G[i][0]!=1)a[G[i][1]]++;
  }

  for(ll i=148;i>=0;i--){
    a[i]+=a[i+1];
  }

  ll ans=0;
  ans+=a[74];//75=75
  ans+=a[24]*(a[2]-1);//75=(2+1)*(24+1)
  ans+=a[14]*(a[4]-1);//75=(4+1)*(14+1)
  ans+=(a[4])*(a[4]-1)/2*(a[2]-2); //75=(2+1)*(4+1)*(4+1)

  cout << ans << endl;




}

Measured memory_bytes: 3612
def selectionSort(A, N):
    s = 0
    for i in range(N):
        minj = i
        for j in range(i,N):
            if A[j] < A[minj]:
                minj = j
        A[i], A[minj] = A[minj], A[i]
        if i != minj:
            s += 1
    t = str(A[0])
    for i in range(1,N):
        t = t + " " + str(A[i])
    print(t)
    print(s)

n = int(input())
a = [int(i) for i in input().split()]

selectionSort(a, n)

Measured memory_bytes: 5604
from collections import deque
from itertools import chain

H, W = map(int, input().split())
maze = [list(input()) for _ in range(H)]
directions = [(1, 0), (0, 1), (-1, 0), (0, -1)]
max_d = 400


def bfs(start):
    queue = deque()
    queue.append(start)

    distance = [[max_d] * W for _ in range(H)]
    sx, sy = start
    distance[sx][sy] = 0

    while len(queue) > 0:
        x, y = queue.popleft()
        for dx, dy in directions:
            nx = x + dx
            ny = y + dy
            if nx >= 0 and nx < H and ny >= 0 and ny < W and maze[nx][ny] == '.' and distance[nx][ny] == max_d:
                queue.append((nx, ny))
                distance[nx][ny] = distance[x][y] + 1

    return max(filter(lambda d: d != max_d, chain.from_iterable(distance)))


ans = 0
for i in range(H):
    for j in range(W):
        if maze[i][j] == '.':
            ans = max(ans, bfs((i, j)))

print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)


int main(){
	int q,k,x;
	cin >> q;
	set<int> se;
	while(q--){
		cin >> k >> x;
		if(k){
			cout << se.count(x) << "\n";
		}else{
			se.insert(x);
			cout << se.size() << "\n";
		}
	}
}


Measured memory_bytes: 12396
//16-4 JOI国のお散歩事情
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<math.h>
#include<time.h>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<set>
#include<stack>
#include<queue>
#include<cstdlib>
#include<algorithm>
#include<random>
#include<cassert>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
using namespace std;
#define LL long long
#define segment_size 65536
#define ROOP() while(true)

LL N,T,Q;
pair<mp::cpp_int,int> A[100000];
set<mp::cpp_int> stop;
LL X[1000];

int main(){
    cin >> N >> T >> Q;
    for(LL i=0; i<N; i++){
        mp::cpp_int a;
        int b;
        cin >> a >> b;
        A[i] = make_pair(a,b);
    }
    for(LL i=0; i<Q; i++){
        cin >> X[i];
        X[i]--;
    }

    int before = 2;
    for(LL i=0; i<N; i++){
        if(before==1 && A[i].second==2){
            stop.insert((A[i].first + A[i-1].first) /2);
        }
        before = A[i].second;
    }

    for(LL i=0; i<Q; i++){
        mp::cpp_int now = A[X[i]].first;
        if(A[X[i]].second == 1){
            auto itr = stop.upper_bound(now);
            if(itr == stop.end()) cout << now+T << endl;
            else{
                mp::cpp_int st = *itr;
                if(now+T > st) cout << st << endl;
                else cout << now+T << endl;
            }
        }
        else{
            auto itr = stop.upper_bound(now);
            if(itr == stop.begin()) cout << now-T << endl;
            else{
                itr--;
                mp::cpp_int st = *itr;
                if(now-T < st) cout << st << endl;
                else cout << now-T << endl;
            }
        }
    }
    
    return 0;
}



Measured memory_bytes: 9776
#include <stdio.h>
#include <math.h>

int isPrime(x){
  int i=3;
  if(x == 2) return 1;

  if(x < 2 || x % 2 == 0) return 0;

  while(i <= sqrt(x)){
    if(x % i == 0) return 0;
    i += 2;
  }

  return 1;
}

int main(){
  int x, n, i, count=0;

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf("%d", &x);
    if(isPrime(x)) count++;
  }

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

  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1<<30;
const ll LINF = 1LL<<58;
const ll mod = 1000000007;

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> H(n);
    int cnt = 0;
    for(int i = 0; i < n; i++) cin >> H[i];
    for(int i = 0; i < n; i++) if(H[i] >= k) cnt++;
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  string s,t;cin >> s >> t;
  vector<int> ns(s.length());
  vector<int> nt(t.length());
  rep(i,s.length()) ns[i] = s[i] - 'a';
  vector<vector<int> > pos(26);
  rep(i,s.length()) pos[ns[i]].push_back(i);
  bool issat = true;
  rep(i,t.length()){
    nt[i] = t[i] - 'a';
    if(pos[nt[i]].size()==0){
      issat = false;
      break;
    }
  }
  if(!issat){
    cout << -1 << endl;
    return 0;
  }

  ll index = 0;
  ll n = 0;
  rep(i,t.length()){
    auto it = lower_bound(all(pos[nt[i]]),index);
    if(it == pos[nt[i]].end()){
      index = pos[nt[i]][0]+1;
      ++n;
    }else{
      index = *it + 1;
    }
  }
  cout << (ll) n*s.length() + index << endl;
  return 0;
}


Measured memory_bytes: 1996
#include <iostream>
#include <string>

bool flag[26];

int main(){
    std::string s;
    std::cin >> s;
    for(int i = 0; i < s.length(); i++){
        flag[s[i] - 'a'] = true;
    }
    for(int i = 0; i < 26; i++){
        if(!flag[i]){
            std::cout << static_cast<char>('a'+i) << std::endl;
            return 0;
        }
    }
    std::cout << "None" << std::endl;
    return 0;
}


Measured memory_bytes: 512
#include<iostream>

using namespace std;
int main()
{int H,A;
 cin>>H>>A;
 if(H/A==0)
    cout<<1;
 else if(H%A==0)
    cout<<H/A;
 else if(H%A!=0)
    cout<<H/A+1;
    

return 0;
}


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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

ll gcd(ll a, ll b){
  ll r = a%b;
  if(r==0) return b;
  else return gcd(b, a%b);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

struct UnionFind{
  ll N;
  llvec p;
  llvec cnt;
  UnionFind(ll n){
    N = n;
    p=llvec(N);
    cnt=llvec(N, 0);
    rep(i, N){
      p[i] = i;
      cnt[i] = 1;
    }
  }

  void con(ll a, ll b){
    P at = root(a);
    P bt = root(b);
    if(at.second!=bt.second){
      if(at.first>bt.first){
        swap(at, bt);
        swap(a, b);
      }
      p[at.second] = bt.second;
      cnt[bt.second]+=cnt[at.second];
      p[a]=bt.second;
    }
  }

  P root(ll a){
    ll atmp = a;
    ll c=0;
    while(atmp!=p[atmp]){
      atmp = p[atmp];
      c++;
    }
    p[a] = atmp;
    return {c, atmp};
  }

  bool is_con(ll a, ll b){
    P at=root(a);
    P bt=root(b);
    return at.second == bt.second;
  }
  
};

struct dijkstra{
  ll N;
  llvec d;
  vector<vector<edge>> e;
  dijkstra(ll n){
    N = n;
    //d = llvec(N, 1e18);
    e = vector<vector<edge>>(N);
  }

  void add_edge(ll from, ll to, ll cost){
    e[from].push_back({to, cost});
  }

  void run(ll start){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    d = llvec(N, 1e18);
    d[start]=0;
    while(!que.empty()){
      P q = que.top();que.pop();
      ll dc = q.first;
      ll x = q.second;
      if(dc>d[x]){
        continue;
      }else{
        for(auto ip: e[x]){
          if(d[ip.x]<=d[x]+ip.c){
            continue;
          }else{
            d[ip.x]= d[x]+ip.c;
            que.push({d[ip.x], ip.x});
          }
        }
      }
    }
  }  
};


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N, L;
  cin >> N >> L;
  ll cnt = L * N + (N-1)*N/2;
  ll m=1e18;
  rep(i, N){
    if(abs(m)>abs(L+i))m = L+i;
  }
  cout << cnt - m;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll rm[2000005]={0},rc[2000005]={0},rmc[2000005]={0};
ll n;
string s;
ll solve(ll k){
  ll res=0;
  for(int i=1;i<=n;i++){
    if(s[i]=='D'){
      res+=rmc[i+k-1]-rmc[i];
      res-=rm[i]*(rc[i+k-1]-rc[i]);
    }
  }
  return res;
}
int main(){
  cin>>n;
  s.push_back('A');
  string ks;
  cin>>ks;
  s+=ks;

  for(int i=1;i<=n;i++){
    rm[i]=rm[i-1];
    rc[i]=rc[i-1];
    rmc[i]=rmc[i-1];
    if(s[i]=='M') rm[i]++;
    if(s[i]=='C') {
      rc[i]++;
      rmc[i]+=rm[i];
    }
  }
  for(int i=n+1;i<=n*2;i++){
    rm[i]=rm[i-1];
    rc[i]=rc[i-1];
    rmc[i]=rmc[i-1];
  }
  ll q;
  cin>>q;
  for(int i=0;i<q;i++){
    ll k;
    cin>>k;
    cout<<solve(k)<<endl;
  }
}


Measured memory_bytes: 49156
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations

N = int(input())

a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

def solve(N, a):
    return a[N-1]

print(solve(N, a))

Measured memory_bytes: 5684
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    priority_queue<int> pq;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        pq.push(a);
    }
    for(int i=0;i<(n*0.5-1);i++){
        pq.pop();
    }
    int b=pq.top();
    pq.pop();
    int c=pq.top();
    cout<<b-c<<endl;
}

Measured memory_bytes: 892
#include<stdio.h>
#include<iostream>
#include<cmath>
using namespace std;

int N;
int main(){
    cin >> N;
    int t = 1;
    for(int i=0; i<N; i++){
        int x;
        cin >> x;
        t *= ( x % 2 ? 1 : 2);
    }
    cout << pow(3,N) - t << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
int Max(int(a), int(b), int(c)) {
	return max(max(a, b), c);
}
int Min(int(a), int(b), int(c)) {
	return min(min(a, b), c);
}

int main() {
	int N;
	cin >> N;
	vector<int> h(N);
	vector<int> co(N);
	
	for (int i = 0; i <N; i++) {
		cin >> h.at(i);
	}
	co.at(0) = 0;
	co.at(1) = abs(h.at(1) - h.at(0));
	for (int i = 2; i < N; i++) {
		co.at(i) = min(co.at(i - 1) + abs(h.at(i) - h.at(i - 1)), co.at(i - 2) + abs(h.at(i) - h.at(i - 2)));
	}
	cout << co.at(N - 1) << endl;
}


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

int main()
{
  int X, N;
  cin >> X >> N;

  vector<int> p(N, 0);
  for (int i = 0; i < N; i++)
  {
    cin >> p[i];
  }
  for (int delta = 0;; delta++)
  {
    bool is_m_min = true;
    bool is_p_min = true;
    for (int i = 0; i < N; i++)
    {
      if (X - delta == p[i])
      {
        is_m_min = false;
      }
      if (X + delta == p[i])
      {
        is_p_min = false;
      }
    }
    if (is_m_min)
    {
      cout << X - delta;
      return 0;
    }
    else if (is_p_min)
    {
      cout << X + delta;
      return 0;
    }
  }
}

Measured memory_bytes: 3628
#include<stdio.h>
#include<math.h>

int main(void)
{
int n,x,i;
int a[100],b[100];

scanf("%d %d",&n,&x);

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

b[0]=0;

for(i=1;i<=n;i++)
{

b[i]=b[i-1]+a[i-1];

if(b[i]>x)
{break;}
}

printf("%d",i);

return 0;
}


Measured memory_bytes: 128