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

int main() {
    int W, H, N;
    cin >> W >> H >> N;

    vector<int> x(N);
    vector<int> y(N);
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> x.at(i) >> y.at(i) >> a.at(i);
    }

    int WH[2][2] = {{0, W}, {0, H}};
    for (int i = 0; i < N; i++) {
        if (a.at(i) == 1) {
            WH[0][0] = max(x.at(i), WH[0][0]);
        }
        else if (a.at(i) == 2) {
            WH[0][1] = min(x.at(i), WH[0][1]);
        }
        else if (a.at(i) == 3) {
            WH[1][0] = max(y.at(i), WH[1][0]);
        }
        else {
            WH[1][1] = min(y.at(i), WH[1][1]);
        }
    }

    int W1 = WH[0][1] - WH[0][0];
    int H1 = WH[1][1] - WH[1][0];
    if (W1 >= 0 && H1 >= 0) {
        cout << W1 * H1 << endl;
    }
    else {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const double PI=3.14159265358979323846;
const int64_t waru = 1000000007;
using in = int64_t;

bool prime(int x){
  bool y;
   if(x==1) y=false;
  else if(x==2) y=true;
  else if(x%2==0){y=false;}
  else if(x==3) y=true;
  else if(x==5) y=true;
  else if(x==7) y=true;
  else if(x<=10) y=false;
  else{
     for(int i=3;i<=sqrt(x);i+=2){
        if(x%i==0){
           y=false;
          break;
        }
       else y=true;
     }
    
  }
  return y;
}

int main(){
   int x;
  cin>>x;
  
  if(x<3){ cout<<2; return 0;}
   if(x%2==0) x ++;
  if(prime(x)){cout<<x; return 0;}
 
  
  for(int i=x+2;true;i+=2){
     if(prime(i)){
       cout<<i;
       break;
     }
  }
}

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

int main(){
    int x, n;
    int min, k, l; 
    
    min = 200;
    l = 100;

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

    int p[n+1];

    for(int i=1; i<n+1; i++){
         scanf("%d", &p[i]);
    }   
    
    
    for(int i=-1; i<=101; i++){

        int f = 0;
        
            for(int j=1; j<n+1; j++){
                if(i == p[j]){
                    f = 1;
                    continue;    
                }
            }

            if(f == 0){
                k = abs(i - x);
                if(min > k){
                     min = k;
                     l = i;
                }
            }
        
    }   

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

return 0;

}

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

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

    int cnt[26] = {0};
    rep(i, n) {
        string s;
        cin >> s;

        int tmp[26] = {0};
        rep(j, s.size()) {
            ++tmp[s[j] - 'a'];
        }
        if (i == 0)
            rep(j, 26) cnt[j] = tmp[j];
        else
            rep(j, 26) cnt[j] = min(cnt[j], tmp[j]);
    }

    rep(i,26){
        rep(j,cnt[i]){
            cout << char('a' + i);
        }
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i, v.size()){ cout << v[i] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;}
#define pb push_back
#define int long long
#define INF 1000000000000000000

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

template<typename T> void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }

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

int mod = 1000000007;
//int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod
#define AddMult(x, y, z) x = (x + (y) * (z)) % mod



signed main(){

    string S; cin >> S;
    bool f = false;
    REP(i, SZ(S) - 1) if(S.substr(i, 2) == "AC") f = true;
    Ans(f, "Yes", "No");

    return 0;
}


Measured memory_bytes: 636
// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
map<ll, int> factorize(ll x)
{
    ll n = x;
    map<ll, int> m;
    for (ll i = 2; i * i <= n && x > 1; ++i)
        while (x % i == 0)
            m[i]++, x /= i;
    if (x > 1)
        m[x]++;
    return m;
}
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll n, ans = 0;
    cin >> n;
    auto f = factorize(n);
    for (auto p : f)
    {
        ll e = p.second;
        ll x = (-1 + sqrtl(1 + 8 * e)) / 2;
        ans += x;
    }
    cout << ans;
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int n, a[maxn][3], dp[maxn][3];
int solve() {
    int i, cur, last;
    int res = 0;
    for(i = 0; i < 3; i++) {
        dp[0][i] = a[0][i];
        res = max(res, dp[0][i]);
    }
    for(i = 1; i < n; i++) {
        for(cur = 0; cur < 3; cur++) {
            dp[i][cur] = 0;
            for(last = 0; last < 3; last++) {
                if(last != cur)
                    dp[i][cur] = max(dp[i][cur], dp[i - 1][last] + a[i][cur]);
            }
            if(i == n - 1)
                res = max(res, dp[i][cur]);
        }
    }
    return res;
}
int main() {
    int i;
    scanf("%d", &n);
    for(i = 0; i < n; i++)
        scanf("%d %d %d", &a[i][0], &a[i][1], &a[i][2]);
    printf("%d\n", solve());
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>

using namespace std;

int n;
int s;
vector<int> v;
int f;
int b;
int sum = 0;
int ans = 0;

int main() {

	while (cin >> n) {
		if (n == 0) break;
		for (int i = 0; i < n; i++) {
			cin >> s;
			v.push_back(s);
		}

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

		f = v[0];
		b = v[v.size() - 1];

		for (int i = 0; i != v.size(); ++i) {
			sum += v[i];
		}
		sum = sum - f - b;
		ans = sum / (v.size() - 2);

		cout << ans << endl;

		v.clear();
		sum = 0;
		ans = 0;

	}
}

Measured memory_bytes: 1220
/* ex4_2
  sachiyan */

#include <stdio.h>
#include <math.h>


int main(void){
    int len_hour, len_minute, hour, minute; //長針、短針、時刻を定義
    double degree, difference, radian, answer;//ある時刻における針同士の角度、その絶対値、ラジアン角、答えを置く
    double pi = acos(-1); //πをdouble型で算出
    scanf("%d %d %d %d", &len_hour, &len_minute, &hour, &minute);//入力値を読み取る
    degree = 0.5*(60*hour + minute) - 6*minute;//針同士の角度を求める
    difference = fabs(degree);//角度の絶対値を求める
    radian = difference*(pi/180); //角度をラジアンに直す
    answer = sqrt(len_hour*len_hour + len_minute*len_minute - 2*len_hour*len_minute*cos(radian)); //余弦定理を使う
    printf("%.20lf\n", answer); //答えを小数点以下20位まで出力

    return 0;
}

Measured memory_bytes: 2532
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] inputArr = sc.nextLine().split(" ");
		sc.close();
		char input1 = inputArr[0].charAt(0);
		char input2 = inputArr[1].charAt(0);
		      
		if(input1 < input2) {
			System.out.println("<");
		}else if(input1 > input2) {
			System.out.println(">");
		}else {
			System.out.println("=");
		}
	}

}

Measured memory_bytes: 23380
#include<iostream>
using namespace std;
int main(){
    int x,h,m,s;
    cin >> x;
    s = x % 60;
    x = x / 60;
    m = x % 60;
    h = x / 60;
    cout << h << ":" << m << ":" << s << endl;
    return 0;
}


Measured memory_bytes: 3048
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    double l;
    cin >> l;
    cout << setprecision(15) << fixed << l * l * l / 27;
}


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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define INF 2000000000

#ifdef LOCAL
  #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
  #define eprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

int main() {
  int n;
  scanf("%d", &n);

  vector<int> nums;
  REP(i, n) {
    int l, r;
    scanf("%d %d", &l, &r);
    nums.push_back(r - l + 1);
  }

  int ans = accumulate(nums.begin(), nums.end(), 0);

  cout << ans;

  return 0;
}


Measured memory_bytes: 256
if __name__ == '__main__':
    A = []
    for i in range(3):
        row = list(map(int, input().split()))
        A.append(row)
    
    N = int(input())
    B = []

    for i in range(N):
        B.append(int(input())) 
    
    for i in range(3):
        cnt = 0
        for j in range(3):
            if A[i][j] in B:
                cnt += 1
        if cnt==3:
            print('Yes')
            quit()
            
    for i in range(3):
        cnt = 0
        for j in range(3):
            if A[j][i] in B:
                cnt += 1
        if cnt==3:
            print('Yes')
            quit()

    if A[0][0] in B and A[1][1] in B and A[2][2] in B:
        print('Yes')
        quit()
    
    if A[0][2] in B and A[1][1] in B and A[2][0] in B:
        print('Yes')
        quit()
    
    print('No')

Measured memory_bytes: 9124
#include <bits/stdc++.h>
typedef long long ll;

inline void up(int &x, int y) { x < y ? x = y : 0; }
inline void down(int &x, int y) { x > y ? x = y : 0; }
std::set < int > s;
int main() {
	int n, m, k, x;
	std::cin >> m >> n;
	for (int i = 1; i <= n; ++i) {
		std::cin >> k;
		while (k--) std::cin >> x, s.insert(x);
	}
	std::cout << m - s.size() << '\n';
}










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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) { a = b; return true; } return false;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) { a = b; return true; } return false;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 l;
  cin >> l;
  int32 n = 1;
  while(l >= (1<<(n-1)))++n;
  ANS(n-1);
  vector<tuple<int32,int32,int32>> edges;
  REP(i,n-2){
    edges.emplace_back(i+1,i+2,0);
  }
  REP(i,n-2){
    edges.emplace_back(i+1,i+2,1<<i);
  }
  int32 cur = 1<<(n-2);
  FORR(i,n-3,0){
    if(l>>i&1){
      edges.emplace_back(i+1,n-1,cur);
      cur += (1<<i);
    }
  }
  ANS(edges.size());
  for(auto [u,v,w] : edges){
    cout << u << " " << v << " " << w << endl;
  }
  return 0;
}

Measured memory_bytes: 3516
#include <iostream>
#include <vector>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

int main() {
	int n, m;
	cin >> n >> m;
	scc_graph sccg(n);
	for (int i = 0; i < m; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		sccg.add_edge(a, b);
	}
	vector<vector<int>> scc = sccg.scc();
	cout << scc.size() << endl;
	for (int i = 0; i < scc.size(); i++) {
		int l = scc[i].size();
		printf("%d", l);
		for (int j = 0; j < l; j++) {
			printf(" %d", scc[i][j]);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 40128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,cnt[100000]={},a;
  long long mod=1e9+7;
  cin>>n;
  for(int i=0;i<n;i++)cin>>a,cnt[(n-a)/2]++;
  int f=0;
  for(int i=0;i<n/2;i++)if(cnt[i]!=2)f=1;
  if(n%2==1&&cnt[n/2]!=1)f=1;
  long long ans=1;
  for(int i=0;i<n/2;i++){
    ans*=2;ans%=mod;
  }
  cout<<(f?0:ans)<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

int main(){
	int N;
	cin >> N;
	string S;
	cin >> S;

	for(int i=0; i<S.size(); i++) S[i] = ((S[i]-'A')+N)%26 + 'A';
	cout << S << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
	private static void solve(){
	//Implement solution here.
		int n = ni();
		int[] h = new int[n];
		for(int i = 0; i < n; i++){
			h[i] = ni();
		}
		int result = 0;
		int i = 0;
		while(i < n){
			if(h[i] == 0){
				i++;
				continue;
			}else{
				result++;
				for(int j = i; j < n; j++){
					if(h[j] == 0){
						break;
					}else{
						h[j]--;
					}
				}
			}
			if(h[i] == 0){
				i++;
			}
		}
		System.out.println(result);
	}

    //Switch input source (stdin/file)
	private static Scanner scanner = new Scanner(System.in);
	public static void main(String[] args){
        String debugDataPath = System.getenv("DD_PATH");        
        if(debugDataPath != null){
            try{
                scanner = new Scanner(new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath)))));
            }catch(Exception e){
                throw new RuntimeException(e);
            }
        }
        solve();
	}

    //Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(scanner.nextLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
    //Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
    //Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
    //Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
    //Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
    //Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

Measured memory_bytes: 23252
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9 + 7;
int cnt[100000];
int used[100000];
int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	ll ans = 1;
	for (int i = 0; i < N; i++) {
		if (A[i] == 0) {
			cnt[0]++;
		}
		else {
			(ans *= cnt[A[i] - 1] - used[A[i] - 1]) %= MOD;
			cnt[A[i]]++;
			used[A[i] - 1]++;
		}
		if (cnt[A[i]] > 3) {
			ans = 0;
			break;
		}
	}
	if (cnt[0] == 1) (ans *= 3) %= MOD;
	else (ans *= 6) %= MOD;
	cout << ans << endl;
}


Measured memory_bytes: 1408
N=int(input())
h=list(map(int,input().split()))

inf=float("inf")
dp=[inf]*N
dp[0]=0

for i in range(N-1):
    if i!=N-2:
        dp[i+2]=min(dp[i+2],dp[i]+abs(h[i+2]-h[i]))
    dp[i+1]=min(dp[i+1],dp[i]+abs(h[i+1]-h[i]))

print(dp[N-1])

Measured memory_bytes: 13928
#include<cstdio>
typedef long long ll;
ll a[55],b[55];
ll work(int n,ll k){
	if(!k)return 0;
	if(!n)return 1;
	if(k==b[n])return a[n];
	k--;
	if(k<=b[n-1])return work(n-1,k);
	else return a[n-1]+1+work(n-1,k-b[n-1]-1);
}
int main(){
	int n,i;
	ll k;
	scanf("%d%lld",&n,&k);
	a[0]=b[0]=1;
	for(i=1;i<=n;i++){
		a[i]=a[i-1]*2+1;
		b[i]=b[i-1]*2+3;
	}
	printf("%lld\n",work(n,k));
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <numeric>
#include <algorithm>
#include <utility>


using std::cout;
using std::cin;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;


ll gcd(ll a, ll b) {
    while (b != 0) {
        auto tmp = a;
        a = b;
        b = tmp % a;
    }
    return a;
}

ll lcm(ll a, ll b) {
    return (a * b) / gcd(a, b);
}

int isPrime(int a) {
    for (int i = 2; i * i <= a; ++i) {
        if (a % i == 0) {
            return 0;
        }
    }
    return 1;
}





void oneCase () {
    int n;
    cin  >> n;
    vector<int> id(9);
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        if (a >= 3200) {
            ++id[8];
        } else {
            id[a / 400] = 1;
        }
    }
    if (id.back() == 0) {
        auto a =  accumulate(id.begin(), id.end(), 0);
        cout << a << " "<< a << "\n";
    } else {
        auto a = accumulate(id.begin(), id.end(), 0) - id.back();

        cout << max(a, int(id.back() > 0)) << " " << a  + id.back() << "\n";
    }

}




int main() {
    int t = 1;
//    cin >> t;
    while (t > 0) {
        oneCase();
        --t;
    }

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int>P;

#define INF 1<<30
#define F first
#define S second
#define MOD 1000000007

int main(){
  ll l,r;
  ll ans=2018;
  cin>>l>>r;
  
  if(r-l>=2019) printf("0\n");
  else{
    for(ll i=l;i<r;i++){
      for(ll j=i+1;j<=r;j++){
	ans=min(ans,(i*j)%2019);
      }
    }
    cout<<ans<<endl;
  }
	
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=10000+10;
int a[maxn];
int main(){
	int i,j,k,m,n;
	cin>>n;
	for(register int i=1;i<=n-1;i++)cin>>a[i];
	int ans=a[1]+a[n-1];
	for(register int i=2;i<=n-1;i++)ans+=min(a[i],a[i-1]);
	cout<<ans<<endl;
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
typedef long long ll;

int main() {
    int n; cin >> n;
    vector<int> d(n);
    rep(i,n) cin >> d[i];
    sort(d.begin(),d.end());
    int k = n / 2;
    cout << d[k] - d[k - 1] << endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define int long long int
constexpr int INF = std::numeric_limits<int>::max();
constexpr int NINF = std::numeric_limits<int>::min();
using namespace std;

void solve() {
  int N;
  cin >> N;

  int ans = 0;
  for (int i = 2; i*i <= N; i++) {
    if (N%i != 0) {
      continue;
    }

    int cnt = 0;
    while (N%i == 0) {
      N /= i;
      cnt++;
    }

    for (int p = 1; p <= cnt; p++) {
      ans++;
      cnt -= p;
    }
  }

  if (N > 1) {
    ans++;
  }

  cout << ans << endl;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>  // ver1.9
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define mp make_pair
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
#define PAI 3.14159265358979
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  cout << fixed << setprecision(14);
  int n;
  cin>>n;
  Vi a(26);
  char c;
  rep(i,0,n){
    cin>>c;
    a[c-'a']++;
  }
  int ans=1;
  rep(i,0,26){
    ans *= a[i]+1;
    ans %= MOD;
  }
  ans--;
  cout << ans << endl;
  return 0;
}


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

int main(){
  string str;
  cin >> str;
  int str_len=str.size();
  for(int i=0;i<=str_len;i++){
    if(i%2==0){
      if(str[i] == 'L'){
        cout << "No" << endl;
        return 0;
      }
    }
    else{
      if(str[i] == 'R'){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.math.BigDecimal;
public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int x = in.nextInt();
    int y = in.nextInt();
    System.out.print(x / y + " "+ x % y);
    System.out.printf(" %5.8f\n", (double) x / y);
  }
}

Measured memory_bytes: 17324
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll LINF = 1e18;
const int INF = 1e9;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    string S;
    cin>>S;
    int K; cin>>K;
    vector<string> dic;
    int l = S.length();
    rep(i,min(5,l)){
        rep(j,l-i){
            if(find(dic.begin(),dic.end(),S.substr(j,i+1))==dic.end())dic.push_back(S.substr(j,i+1));
        }
    }
    sort(dic.begin(),dic.end());
    cout<<dic[K-1]<<endl;
    return 0;
}

Measured memory_bytes: 3956
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<stdio.h>

int main()
{   int a,b,c,n,m,k,i,x,y;
    char s[101],t[101];
    scanf("%d",&a);
    if(a==3||a==5||a==7)
    printf("YES");
    else printf("NO");

    return 0;
}


Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int size = Integer.parseInt(sc.next());
		ArrayList<Integer> heightList = new ArrayList<>();

		for (int i = 0; i < size; i++) {
			heightList.add(Integer.parseInt(sc.next()));
		}

		StringBuilder isHeightThanRightString = new StringBuilder();
		for (int i = 0; i < size - 1; i++) {

			if (0 <= heightList.get(i) - heightList.get(i + 1)) {
				isHeightThanRightString.append("t");
			} else {
				isHeightThanRightString.append("f");
			}
		}

		String[] tfArr = isHeightThanRightString.toString().split("f");
		int result = Stream.of(tfArr).max(Comparator.comparingInt(String::length)).orElse("").length();
		System.out.println(result);

	}
}


Measured memory_bytes: 48956
#include<bits/stdc++.h>
#define N 1010
using namespace std;
int n;
double ansx,ansy,ans;
double totx=0,toty=0;
double t;
double delta=0.999;
struct node{
	double x,y,w;
};node f[N];
double check(double x,double y) {
	double dx,dy,ret=0;
	for(int i=1;i<=n;i++) {
		dx=x-f[i].x;
		dy=y-f[i].y;
		ret=max(sqrt(dx*dx+dy*dy),ret);
	}
	return ret;
}
void sa() {
	t=45000;
	while(t>1e-18) {
		double tx=ansx+(rand()*2-RAND_MAX)*t;
		double ty=ansy+(rand()*2-RAND_MAX)*t;
		double a=check(tx,ty);
		double an=a-ans;
//		printf("%lf %lf %lf\n",tx,ty,a);
		if(an<0) ansx=tx,ansy=ty,ans=a;
		else if(exp(-an/t)*RAND_MAX>rand()) ansx=tx,ansy=ty;
		t*=delta;
	}
}
int main() {
	srand(1960);
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		cin>>f[i].x>>f[i].y;
		totx+=f[i].x;
		toty+=f[i].y; 
	}
	ansx=totx/n;
	ansy=toty/n;
	ans=check(ansx,ansy);
	for(int i=1;i<=10;i++) sa();
	double dx,dy,ret;
	for(int i=1;i<=n;i++) {
		dx=ansx-f[i].x;
		dy=ansy-f[i].y;
		ret=max(sqrt(dx*dx+dy*dy),ret);
	}
	cout<<fixed<<setprecision(7)<<ret;
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int main(int argc, char* argv[])
{
    int n,Q;
    scanf("%d%d", &n, &Q);

    vector<pair<pair<int, int>, int> > z;   // x, type(0:left, 1:right, 2:que), id

    vector<int> s(n), t(n), x(n); 
    int i;
    for(i=0; i<n; i++) {
        scanf("%d%d%d", &s[i], &t[i], &x[i]);
        z.push_back( make_pair(make_pair(s[i]-x[i], 0), i));
        z.push_back( make_pair(make_pair(t[i]-x[i], 1), i));
    }
    vector<int> d(Q);
    for(i=0; i<Q; i++) {
        scanf("%d", &d[i]);
        z.push_back( make_pair(make_pair(d[i], 2), i));
    }
    sort(z.begin(), z.end());
    
    vector<int> ans(Q);
    set<pair<int, int> > ss;
    for(i=0; i<(int)z.size(); i++) {
        int type = z[i].first.second;
        int id=z[i].second;
        if(type==0) {            
            ss.insert(make_pair(x[id], id));
        }
        else if(type==1) {
            ss.erase(make_pair(x[id], id));
        }
        else {
            if(ss.empty()) {
                ans[id]=-1;
            }
            else {
                ans[id]=(*ss.begin()).first;
            }
        }
    }
    for(i=0; i<Q; i++) {
        printf("%d\n", ans[i]);
    }

    return 0;
}


Measured memory_bytes: 23400
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll n,d;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>n>>d;
    d*=2;
    d++;
    ll ans = n/d;
    if(n%d!=0)ans++;
    print(ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
  #define debug(...) printf(__VA_ARGS__)
#else
  #define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

void no_sol() {
  puts("-1");
  exit(0);
}

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  if (A + B - 1 > N)
    no_sol();
  if (1ll * A * B < N)
    no_sol();
  VI ans;
  for (int i = B; i >= 1; i--)
    ans.PB(i);
  int ed = B;
  for (int i = A - 1; i > 0; i--) {
    int num = B;
    if (ed + num + i - 1 > N)
      num = N + 1 - i - ed;
    for (int j = ed + num; j > ed; j--)
      ans.PB(j);
    ed += num;
  }
  for (int i = 0; i < SZ(ans); i++)
    printf("%d%c", ans[i], " \n"[i == SZ(ans) - 1]);
  return 0;
}


Measured memory_bytes: 4336
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: ident) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    let mut it = s.split_whitespace();
    let (n, k): (usize, usize) = parse!(it, 2);
    let mut a: Vec<usize> = parse!(it, n);
    let mut f: Vec<usize> = parse!(it, n);
    a.sort();
    f.sort();
    f.reverse();
    let check = |x: usize| -> bool {
        let mut k = k;
        for i in 0..n {
            let ai = a[i];
            let fi = f[i];
            if ai * fi > x {
                let y = ai - x / fi;
                if y > k || y > ai {
                    return false;
                }
                k -= y;
            }
        }
        true
    };
    let mut ok = 1000000000000000000isize;
    let mut ng = -1isize;
    while ok - ng > 1 {
        let m = (ok + ng) / 2;
        if check(m as usize) {
            ok = m;
        } else {
            ng = m;
        }
    }
    println!("{}", ok);
}


Measured memory_bytes: 14584
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<stdio.h>
#include<deque>
#include<map>
#include<queue>

typedef long long ll;

#define debug(x) cout << #x << "=" << x << endl;
#define debug_arr(a, n) for(ll i = 0; i < n; i++)cout << a[i] << " "
#define inf 100000000000
#define loop(i,n) for(ll i = 0; i < n; i++)
#define graph vector<vector<ll>>
#define P pair<ll,ll>

using namespace std;

int main(){
    ll n;
    cin >>n;
    vector<ll> a(n);
    loop(i,n) cin >>a[i]; 

    ll currentNum = 1;
    ll ans = 0;

    loop(i,n){
        if(a[i] == currentNum) currentNum++;
        else ans++;
    }

    if(ans == 0 && a[0] == 1){
        cout << 0 << endl;
        return 0;
    }

    if(ans == 0 || ans == n){
        cout << -1 << endl;
        return 0;
    }

    cout << ans << endl;

}

Measured memory_bytes: 1792
#include <iostream>
//#include <iomanip>
#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

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

int main(){
	string s ; cin >> s ;
	ll n = s.size() ;
	vll q(n+1,0),b(n+1,0),c(n+1,0) ;
	for(int i=n-1;i>=0;i--){
		q.at(i) += q.at(i+1)+(s.at(i)=='?') ;
		b.at(i) += b.at(i+1)+(s.at(i)=='B') ;
		c.at(i) += c.at(i+1)+(s.at(i)=='C') ;
	}
	vll bc(n+1,0),bq(n+1,0),qc(n+1,0),qq(n+1,0) ;
	for(int i=n-1;i>=0;i--){
		bc.at(i) += bc.at(i+1) ;
		bq.at(i) += bq.at(i+1) ;
		qc.at(i) += qc.at(i+1) ;
		qq.at(i) += qq.at(i+1) ;
		if(s.at(i)=='?'){
			qc.at(i) += c.at(i+1) ;
			qq.at(i) += q.at(i+1) ;
		}
		if(s.at(i)=='B'){
			bc.at(i) += c.at(i+1) ;
			bq.at(i) += q.at(i+1) ;
		}
	}
	ll ans = 0 ;
	for(int i=0;i<n;i++){
//		cout << ans << endl ;
		ll h = 0 ;
		if(s.at(i)=='A'||s.at(i)=='?'){
			if(s.at(i)=='?') h = 1 ;
			ans += bc.at(i+1)*modpow(3,q.at(0)-h)%mod ;
			ans += bq.at(i+1)*modpow(3,q.at(0)-1-h)%mod ;
			ans += qc.at(i+1)*modpow(3,q.at(0)-1-h)%mod ;
			ans += qq.at(i+1)*modpow(3,q.at(0)-2-h)%mod ;
			ans %= mod ;
		}
	}
	cout << ans << endl ;
//	for(auto i:bc) cout << i << " " ; cout << endl ;
//	for(auto i:bq) cout << i << " " ; cout << endl ;
//	for(auto i:qc) cout << i << " " ; cout << endl ;
//	for(auto i:qq) cout << i << " " ; cout << endl ;
//	for(auto i:q)  cout << i << " " ; cout << endl ;
}


Measured memory_bytes: 6016
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
static const int INF = 2000000000;


int main(){
  int n, m;
  cin >> n >> m;
  ll ans = ((n-m) * 100 + 1900 * m) * pow(2, m);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int64_t modpow(int64_t a, int64_t b, int64_t MOD) {
	int64_t ret = 1;
	while (b > 0) {
		if (b & 1) { (ret *= a) %= MOD; }
		(a *= a) %= MOD;
		b >>= 1;
	}
	return ret % MOD;
}

int main() {
	const Int MOD = 998244353;
	int N;
	cin >> N;
	vector<Int> D(N);
	vector<Int> c(100010, 0);
	for (int i = 0; i < N; ++i) {
		cin >> D[i];
		++c[D[i]];
	}

	Int ans = 0;
	if (D[0] == 0 && c[0] == 1) { ans = 1; }
	int max_d = 0;
	for (int i = 0; i < N; ++i) { max_d = max(max_d, (int)D[i]); }
	for (int i = 1; i <= max_d; ++i) {
		if (c[i - 1] <= 0 || c[i] <= 0) {
			ans = 0;
			break;
		}
		(ans *= modpow(c[i - 1], c[i], MOD)) %= MOD;
	}
	cout << ans % MOD << endl;

	return 0;
}


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

int main(){
  int n,a;
  ll sum=1;
  bool flag=true;
  cin >> n;
  map<int,int> mp;
  r(i,n){
    cin>> a;
    mp[a]++;
  }
  if(n%2==0){
    r(i,n/2){
      if(mp[2*i+1]!=2)flag=false;
    }
  }
  else{
    r(i,(n+1)/2){
      if(i==0&&mp[0]!=1)flag=false;
      else if(i>0&&mp[2*i]!=2)flag=false;
    }
  }
  if(!flag)cout << 0 << endl;
  else{
      r(i,n/2){
        sum*=2; sum%=1000000007;
      }
    cout << sum << endl;
  }
}

Measured memory_bytes: 4096
import java.util.Scanner;

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

        for (int i = 1 ; i <= 5 ; i++) {
            int x = scanner.nextInt();
            if (x == 0) {
                System.out.println(i);
                return;
            }
        }
    }
}


Measured memory_bytes: 35760
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector<LL> VI;
typedef vector<VI> VVI;
typedef pair<LL, LL> PII;
typedef vector<string> VS;
inline LL toInt(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(x,c) for(auto x: (c))
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define REVERSE(c) reverse((c).begin(), (c).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define STABLE_SORT(c) stable_sort((c).begin(),(c).end())
#define STABLE_RSORT(c) stable_sort((c).rbegin(),(c).rend())
#define UNIQUE(c) SORT(c); (c).erase(unique((c).begin(), (c).end()), (c).end());
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
const double INF = 1e7;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define dump(x)  cerr << #x << " = " << (x) << endl;


int main() {
	LL N, A, B;
	cin >> N >> A >> B;

	LL MM = A + B - N;
	LL NN = 0;
	cout << min(A, B) << " " << max(NN, MM) << endl;
	
    return 0;
}


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

ll max(ll a, ll b){
    if(a > b) return a;
    else return b;
}
int main(){
  ll N,x; cin >> N >> x;
  vector<ll> a(N,0); for(int i = 0; i < N; i++) cin >> a.at(i);
  
  ll ans = 0;
  if(x == 0){
      for(int i = 0; i < N; i++)
        ans += a.at(i);
  }else{
      for(int i = 0; i < N - 1; i++){
          ll sum = a[i] + a[i+1];
          if(sum > x){
              ans += sum - x;
              a[i+1] = max(0,a[i+1]-(sum-x));
          }
      }
  }
  cout << ans << endl;
}



Measured memory_bytes: 1024
#include<iostream>

using namespace std;

int main()
{
	int n,a,b,c,x,i;
	int y[100];
	int flame;
	
	for(;;)
	{
		cin >> n >> a >> b >> c >> x ;
		if(n==0 && a==0 && b==0 && c==0 && x==0)
			break;
		
		for(i=0;i<n;i++)
		{
			cin >> y[i] ;
		}
		
		flame=0;
		int flag=1;
		
//		cout << y[0] << endl;
		for(i=0;;)
		{
			if(flame==10001)
			{
				flag=0;
				break;
			}
			if(y[i]==x)
			{
				i++;
//				cout << "in_x:" << x  << endl;
				x=(a*x+b)%c;
				if(i==n)
					break;
				flame++;
			}
			else
			{
//				cout << "out_x:" << x  << endl;
				flame++;
				x=(a*x+b)%c;
			}
		}
		if(flag==1)
			cout << flame << endl;
		else
			cout << "-1" << endl;
	}
}

Measured memory_bytes: 0
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> X(100000,0);
    long long sum = 0;
    for (int i = 0; i < N; i++){
        int A;
        cin >> A;
        sum += A;
        X[A]++;
    }
    int Q;
    cin >> Q;
    for (int i = 0; i < Q; i++){
        int B, C;
        cin >> B >> C;
        sum += -(B * X[B]) + (C * X[B]);
        X[C] += X[B];
        X[B] = 0;
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;

class Seg_Tree{
public:
	vector< pair<int,int> > dat;
	// first  -> min value
	// second -> min index
	int n;
	void initsize(int n0){
		int k=1;
		while(1){
			if(n0<=k){
				n=k;
				dat.resize(2*n-1);
				for(int i=0;i<2*n-1;i++){
					dat[i].first=INT_MAX;
					dat[i].second = i-n+1;
				}
				break;
			}
			k*=2;
		}
	}
	//i banme wo x nisuru
	void update(int i,int x){
		i += n-1;
		dat[i].first = x;
		while(i>0){
			i = (i-1) / 2;
			if(dat[i*2+1].first<=dat[i*2+2].first)
				dat[i] = dat[i*2+1];
			else
				dat[i] = dat[i*2+2];
		}
	}
	//[a,b)
	pair<int,int> query0(int a,int b,int k,int l,int r){
		if(r<=a || b<=l)return {INT_MAX,-1};
		if(a<=l && r<=b)return dat[k];
		else{
			pair<int,int> vl = query0(a,b,k*2+1,l,(l+r)/2);
			pair<int,int> vr = query0(a,b,k*2+2,(l+r)/2,r);
			if(vl.first<=vr.first)return vl;
			else return vr;
		}
	}
	//return min [a,b)
	pair<int,int> query(int a,int b){
		return query0(a,b,0,0,n);
	}
};



struct LCA{
	// This struct uses class Seg_Tree
	vector< vector<ll> > G;
	ll root;
	vector<ll> vs,depth,id;
	Seg_Tree se;

	LCA(ll v){
		G.resize(v);
		vs.resize(v*2-1);
		depth.resize(v*2-1);
		id.resize(v);
		root = 0;
	}
	void dfs(ll v,ll p,ll d,ll &k){
		id[v] = k;
		vs[k] = v;
		depth[k++] = d;
		for(ll i=0;i<G[v].size();i++){
			if(G[v][i] != p){
				dfs(G[v][i],v,d+1,k);
				vs[k] = v;
				depth[k++] = d;
			}
		}
	}
	void init(){
		ll V = id.size();
		ll k = 0;
		dfs(root,-1,0,k);
		se.initsize(V*2-1);
		for(int i=0;i<depth.size();i++){
			se.update(i,depth[i]);
		}
	}
	//[u,v]
	int lca(ll u,ll v){
		return vs[se.query(min(id[u],id[v]),max(id[u],id[v])+1).second];
	}
	int length_from_root(int v){
		return depth[id[v]];
	}
};




// ant p.294
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin >> n;
	LCA g(n);
	FOR(i,0,n){
		ll k,c;
		cin >> k;
		FOR(j,0,k){
			cin >> c;
			g.G[i].push_back(c);
		}
	}
	g.init();
	ll q;
	cin >> q;
	FOR(i,0,q){
		ll x,y;
		cin >> x >> y;
		cout << g.lca(x,y) << endl;
	}
}



Measured memory_bytes: 19988
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;


class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int a = sc.nextInt();
    	int b = sc.nextInt();
    	int c = sc.nextInt();
    	int d = sc.nextInt();

    	if(Math.abs(c - a) <= d) System.out.print("Yes");
    	else if(Math.abs(b - a) <= d && Math.abs(c - b) <= d) System.out.print("Yes");
    	else System.out.print("No");
    }
}

Measured memory_bytes: 25044
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする


def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N=len(v)
    size=len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def main():
    mod = 10**9+7
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    count=0

    ab=0
    a=0
    b=0
    for i in range(N):
        s=input()
        ls=len(s)
        for j in range(ls-1):
            if s[j:j+2]=='AB':
                count+=1
        if s[0]=='B' and s[-1]=='A':
            ab+=1
        elif s[-1]=='A':
            a+=1
        elif s[0]=='B':
            b+=1
    if a==0 and b==0:
        print(count+max(ab-1,0))
        exit()
    ans=min(a,b)+count
    ret=abs(a-b)
    if ret<=ab:
        ans+=ab
    else:
        ans+=ab
    print(ans)
    

    


if __name__ == "__main__":
    main()

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

int main()
{
  int i = 1;
  int j;
  int key;
  int length;
  int *arrow;

  // Input
  scanf("%d", &length);
  arrow = (int *)malloc(sizeof(int) * length);
  for(i = 0; i < length; i++) scanf("%d", &arrow[i]);
  for(i = 0; i < length - 1; i++)
    {
      printf("%d ", arrow[i]);
    }
  printf("%d\n", arrow[length - 1]);


  for(i = 1; i < length; i++)
    {
    // sort 
      key = arrow[i];
      j = i - 1;
      while(i > 0 && arrow[j] > key)
	{
	  arrow[j+1] = arrow[j];
	  j = j - 1;
	}
      arrow[j+1] = key;

      // Output
      for(j = 0; j < length - 1; j++)
	{
	  printf("%d ", arrow[j]);
	}
      printf("%d\n", arrow[length - 1]);
    }

  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
#define int long
#define mod (1000000007)
int mul(int a,int b){
  return (a%mod*b%mod)%mod;
}
main(){
  int n,k,r=0,d=0,K,K_1,B=0;
  cin>>n>>k;
  vector<int> a(n),b(n),c,dt;
  for(auto& i:a)cin>>i;
  c=a;
  sort(c.begin(),c.end());
  for(int i=0;i<n;++i){
    b[i]=i;
    if(i&&c[i-1]==c[i])b[i]=b[i-1];
  }
  sort(b.begin(),b.end(),[&](int p,int q){return a[p]<a[q];});
  for(int i=0;i<n;++i)B=(B%mod+b[i]%mod)%mod;
  for(int i=n-1;i>=0;--i){
    auto itr=lower_bound(dt.begin(),dt.end(),a[i]);
    d+=itr-dt.begin();
    dt.insert(itr,a[i]);
  }
  if(k%2)K=k,K_1=(k-1)/2;
  else K=k/2,K_1=k-1;
  r=(mul(B,mul(K,K_1))+mul(k,d))%mod;
  cout<<r%mod;
}

Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>
#include <vector> 
#include <math.h> 
using namespace std;

int main(void) {
    int n; cin >> n;
    if (n == 1) {
        cout << "Hello World" << endl;
        return 0;
    } else {
        int a,b; cin >> a >> b;
        cout << a + b << endl;
        return 0;
    }
}



Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>

using namespace std;


int main(){
  int a,b,k;
  cin>>a>>b>>k;
  for(int i=a;i>0;i--){
     if(a%i==0 && b%i==0){
        k--;
     }
     if(k==0){
        cout<<i<<endl;
        return 0;
     }
  }
}

Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def prime_numbers(n):
    if n < 2:
        return []

    m = (n + 1) // 2
    p = [1] * m
    for i in range(1, int((n ** 0.5 - 1) / 2) + 1):
        if p[i]:
            p[2 * i * (i + 1) :: 2 * i + 1] = [0] * (((m - 1) - 2 * i * (i + 1)) // (2 * i + 1) + 1)

    a = [2 * i + 1 for i in range(m) if p[i]]
    a[0] = 2
    return a


def main():
    N = int(readline())

    primes = prime_numbers(55555)
    ans = []
    for p in primes:
        if p % 5 == 1:
            ans.append(p)
        if len(ans) == N:
            break

    print(*ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9760
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int h, a;
	cin >> h >> a;
	cout << (h + a - 1) / a << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 256