akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define repC3(vari,varj,vark,n)  for(int vari=0;vari<(n)-2;++vari)for(int varj=vari+1;varj<(n)-1;++varj)for(int vark=varj+1;vark<(n);++vark)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
using namespace std;
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }


int main() {
    int B,C,D,N,K,Q;
    int ans;
    cin>>N>>K>>Q;
    int A[N]={};
    rep(i,N){
        A[i]=K-Q;
    }
    rep(i,Q){
        cin>>C;
        A[C-1]++;
    }
    rep(i,N){
        if(A[i]>0){
            Out("Yes");
        }else{
            Out("No");
        }
    }
    return 0;
}

Measured memory_bytes: 1024
from itertools import product

def upd(line, fix):
  for i, v in enumerate(fix):
   if v:
     if i == 0:
       line[i] = not line[i]
       line[i + 1] = not line[i + 1]
     elif i == 9:
       line[i - 1] = not line[i - 1]
       line[i] = not line[i]
     else:
       line[i - 1] = not line[i - 1]
       line[i] = not line[i]
       line[i + 1] = not line[i + 1]
  return list(map(int, line))

def upd2(line, fix):
  return [int(i != j) for i, j in zip(line, fix)]

n = int(input())
for _ in range(n):
  base_mp = [list(map(int, input().split())) for _ in range(10)]
  for first_row in product([0, 1], repeat=10):
    mp = [list(first_row)] + [[i for i in base_mp[j]] for j in range(10)]
    save = []
    for i in range(10):
      save.append(mp[i])
      mp[i + 1] = upd(mp[i + 1], mp[i])
      if i == 9:continue
      mp[i + 2] = upd2(mp[i + 2], mp[i])
    
    if not any(mp[10]):
      for line in save:
        print(*line)
      break



Measured memory_bytes: 5676
n = int(input())
lst = list(map(int, input().split()))
nums = [0] * int(1e5 + 10)
sum = 0
for i in lst:
    nums[i] += 1
    sum += i

q = int(input())
ans = []
for i in range(q):
    b, c = map(int, input().split())
    sum += (c - b) * nums[b]
    nums[c] += nums[b]
    nums[b] = 0
    print(sum)


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

int main(){
  int a,b=0;
  cin >> a >> b;
  if((a+b)%2==0){
    cout << (a+b)/2 << endl;
  }else{
    cout << (a+b)/2+1 << endl;
  }
  return 0;
}

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

void solve()
{
	int n,l;
	cin >> n >> l;
	string val[n];
	string ans = "";
	
	for(int i=0;i<n;++i){
		cin >> val[i];
	}

	sort(val,val+n);

	for(int i=0;i<n;++i){
		ans += val[i];
	}
	cout<<ans<<'\n';
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	solve();
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;

const ll M = 1e9+7;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}

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

    //大した量ではないので，先にfax[i]とifax[i]を全て計算しておく
    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<300000; i++){
        fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }


    ll ans = 0;
    ll ans1, ans2;
    for(int i = b+1; i <= w; i++){
        ans1 = comb(i-1+h-a-1, h-a-1)%M;
        ans2 = comb(w-i-1+a, a-1)%M;
        ans += ans1*ans2 % M;
    }
    cout << ans % M << endl;
    return 0;
}

Measured memory_bytes: 6656
// clang-format off
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using G = vector<vector<ll>>;
#define G(i, j) i, vector<ll>(j)
#define Gv(i, j, k) i, vector<ll>(j, k)
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define SORT_DESC(x) sort((x).rbegin(),(x).rend())
#define pb push_back
#define mp make_pair
#define coutl cout<<fixed<<setprecision(10)
#define ANS(ans) cout<<ans<<endl
#define END(ans) ANS(ans); return
const ll LINF = (1LL << 62) - 1;
const int INF = (1 << 30) - 1;
template<class T>inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if (b<a){a=b;return 1;}return 0;}
// clang-format on

void solve(long long a) {
  ANS(a + pow(a, 2) + pow(a, 3));
}

// clang-format off
int main() {
  long long a;
  scanf("%lld",&a);
  solve(a);
  return 0;
}


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

template <typename T>
vector<T> dijkstra(Int s,vector<vector<pair<Int, T> > > & G,T INF){
  using P = pair<T, Int>;
  Int n=G.size();
  vector<T> d(n,INF);
  vector<Int> b(n,-1);
  priority_queue<P,vector<P>,greater<P> > q;
  d[s]=0;
  q.emplace(d[s],s);
  while(!q.empty()){
    P p=q.top();q.pop();
    Int v=p.second;
    if(d[v]<p.first) continue;
    for(auto& e:G[v]){
      Int u=e.first;
      T c=e.second;
      if(d[u]>d[v]+c){
	d[u]=d[v]+c;
	b[u]=v;
	q.emplace(d[u],u);
      }
    }
  }
  return d;
}

signed main(){
  Int n,m,s,t;
  cin>>n>>m>>s>>t;
  s--;t--;
  using P = pair<Int, Int>;
  vector<vector<P> > G(n);
  for(Int i=0;i<m;i++){
    Int u,v,d;
    cin>>u>>v>>d;
    u--;v--;
    G[u].emplace_back(v,d);
    G[v].emplace_back(u,d);
  }
  const Int INF = 1e17;
  auto X=dijkstra(s,G,INF);
  auto Y=dijkstra(t,G,INF);
  Int L=X[t];
  //cout<<L<<endl;
  
  const Int MOD = 1e9+7;
  auto calc=[&](Int st,vector<Int> &Z,vector<Int> &dp){
    priority_queue<P,vector<P>,greater<P> > pq;
    vector<Int> used(n,0);
    dp[st]=1;
    used[st]=1;
    pq.emplace(Z[st],st);
    while(!pq.empty()){
      Int v;
      tie(ignore,v)=pq.top();pq.pop();
      for(auto e:G[v]){
	Int u,c;
	tie(u,c)=e;
	if(Z[v]+c!=Z[u]) continue;
	if(X[u]+Y[u]!=L) continue;
	
	dp[u]+=dp[v];
	dp[u]%=MOD;
	
	if(used[u]) continue;
	used[u]=1;
	pq.emplace(Z[u],u);
      }
    }
  };
  vector<Int> dp(n,0),dp2(n,0);
  calc(s,X,dp);
  calc(t,Y,dp2);
  
  Int ans=dp[t]*dp[t]%MOD;
  for(Int v=0;v<n;v++){
    if(X[v]+Y[v]!=L||X[v]!=Y[v]) continue;
    Int tmp=dp[v]*dp2[v]%MOD;
    tmp=tmp*tmp%MOD;
    ans+=MOD-tmp;
    ans%=MOD;
  }
  
  for(Int v=0;v<n;v++){
    if(X[v]+Y[v]!=L||X[v]*2>=L) continue;
    for(auto e:G[v]){
      Int u,c;
      tie(u,c)=e;
      if(X[v]+c!=X[u]||X[u]*2<=L) continue;
      Int tmp=dp[v]*dp2[u]%MOD;
      tmp=tmp*tmp%MOD;
      ans+=MOD-tmp;
      ans%=MOD;
    }
  }
  ans%=MOD;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 18004
#include <bits/stdc++.h>
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF (1e9)
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;

void Main(){

  string S;
  cin>>S;

  ll ct=0;

  ll cta=-1;

  rep(i,S.length()){
    if(S[i]=='A' and cta==-1) cta=i;
    if(S[i]=='Z') ct=i;
  }

  cout << ct-cta+1<<"\n";

}
//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define sc(x) scanf("%d", &x)
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define ALL(x) x.begin(), x.end()
#define SZ(x) ((int)x.size())
#define sqr(x) ((x)*(x))
#define ABS(x) ((x)>=0?(x):(-(x)))
#define fastio ios::sync_with_stdio(0),cin.tie(0)
template<class T>T gcd(T a, T b){return b?gcd(b, a%b):a;}

int main()
{
    int n, m;
    sc(m); sc(n);
    vector<int> vec(n, 0);
    for(auto &u : vec)sc(u);
    sort(ALL(vec));
    vector<int> num;
    long long ans = 0;
    for(int i = 0; i < (int)vec.size()-1; i++){
        num.pb(vec[i+1]-vec[i]);
        ans += vec[i+1]-vec[i];
    }
    sort(ALL(num), greater<int>());
    for(int i = 0; i < min(m-1, (int)num.size()); i++){
        ans -= num[i];
    }
    printf("%lld\n", ans);
    return 0;
}



Measured memory_bytes: 1276
import java.io.BufferedReader;
import java.io.InputStreamReader;


public class Main {

	public static void main(String[] args) throws Exception {
		// TODO ?????????????????????????????????????????????
		BufferedReader breader = getReader();

		int n = getInt(breader);
		int[] ary = new int[n];
		int ofs = 0;
		for( int i = 0 ; i < n ; i++) {
			int num = getInt(breader);
			if ( isPrime(num) == true) {
				ary[ofs++] = num;
			}
		}
		System.out.println(ofs);
	}
	public static BufferedReader getReader() {
		return( new BufferedReader(new InputStreamReader(System.in)));
	}
	public static int getInt(BufferedReader br)throws Exception {
		String line = br.readLine();
		return Integer.valueOf(line);
	}
	public static int[] getAry(BufferedReader br)throws Exception {
		String line = br.readLine();
		String[] nstr = line.split(" ");
		int[] n = new int[nstr.length];
		for( int i=0 ; i < nstr.length ; i++ ) {
			n[i] = Integer.valueOf(nstr[i]);
		}
		return n;
	}
	public static void putAry(int[] ary, int num) {
		for( int i = 0; i < num ; i++ ) {
			System.out.print(ary[i]);
			if ( i < num-1) {
				System.out.print(" ");
			}
		}
		System.out.println("");
	}
	public static void putAry(int[] ary) {
		putAry(ary, ary.length ) ;
	}
	public static boolean isPrime(int n) {
		int r = (int)Math.sqrt((double)n)+1;
		for( int j = 2 ; j < r ; j += 1) {
			if ( n%j == 0 ) {
				return false;
			}
		}
		return true;
	}

}

Measured memory_bytes: 21016
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a;i<n;i++)
#define ve vector
#define ss second 
#define ff first
#define pf pop_front
#define pob pop_back
#define psf push_front
#define res(x) cout<<x<<'\n'
#define read(t) ll t;cin>>t

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
read(k);
read(r);
if(k<10){
    cout<<100*(10-k)+r<<endl;
}
    else{
        cout<<r<<endl;
    }
    


   

}

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

int main()
{
  int A,B,C,D;
  string result;
  cin >> A >> B >> C >> D;

  while(true){
    C -= B;
    if(C<=0){
      result = "Yes";
      break;
    }
    A -= D;
    if(A<=0){
      result = "No";
      break;
    }
  }

  cout << result << endl;
}

Measured memory_bytes: 3592
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define LB(c, x) lower_bound(c.begin(), c.end(), x)
#define UB(c, x) upper_bound(c.begin(), c.end(), x)
#define LI(c, x) distance(c.begin(), LB(c, x))
#define UI(c, x) distance(c.begin(), UB(c, x))

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T> bool amax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
ll modpow(ll x, ll n, ll m) {
    if (n == 0) {
        return 1;
    } else if (n % 2 == 0) {
        ll h = modpow(x, n / 2, m);
        return h * h % m;
    } else {
        return x * modpow(x, n - 1, m) % m;
    }
}
ll comb(ll a, ll b, ll m) {
    if (b > a - b) {
        return comb(a, a - b, m);
    }
    ll c = 1, d = 1;
    REP(i, b) {
        c *= (a - i);
        d *= (b - i);
        c %= m;
        d %= m;
    }
    return c * modpow(d, m - 2, m) % m;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    const int MOD = 1000000007;
    ll N, M, K;
    cin >> N >> M >> K;
    ll res = 0;
    REP(i, M) {
        res += N * N * i * (M - i);
        res %= MOD;
    }
    REP(j, N) {
        res += M * M * j * (N - j);
        res %= MOD;
    }
    cout << res * comb(N * M - 2, K - 2, MOD) % MOD << endl;
    return 0;
}


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

using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define Pair vector<pair<ll,ll>>
#define vec vector <ll> 
#define all(a) a.begin(),a.end()
#define mo 1000000007
#define decimal(i,n) fixed << setprecision(i) << n
#define show(a) for(auto xyz:a)cout<<xyz<<" ";cout<<endl;
#define show_nl(a) for(auto xyz:a)cout<<xyz<<endl;


void eea(ll a,ll b,ll &x,ll &y)
{
    if (a == 1)
    {
        x = 1; y = 0;
        return;
    }
    ll x1, y1;
    eea(b%a,a,x1,y1);
    x=y1-(b/a)*x1;
    y=x1;
}
ll mi(ll a,ll m)
{
    ll x,y;
    eea(a,m,x,y);
    x= (x%m+m)%m;
    return x;
}

/*
Enter the test case


Some helpful points
1.) Calm yourself
2.) check for semicolon or data type mismatch
*/


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);    
    ll t=1;
    // cin>>t;
    while(t--)
    {
       int n,k;
       cin>>n>>k;
       double a[n];
       double s=0;
       double ans=0;
       for(int i=0;i<n;i++)
       {
           cin>>a[i];
           a[i]=a[i]+1;
       }
       for(int i=0;i<k;i++)
       s=s+a[i];
       for(int i=k;i<n;i++)
       {   
           if(ans<s)
           ans=s;
           s=s-a[i-k]+a[i];
       }
       if(ans<s)
           ans=s;
       cout<<decimal(9,ans/2)<<"\n";
    }
}



Measured memory_bytes: 5204
#include<iostream>

int main(){

    int n;
    int cnt = 0;

    std::cin >> n;

    for(int i = 0; i < n; i++){
        char s;
        std::cin >> s;
        if(s == 'Y'){
            cnt++;
        }
    }

    if(cnt > 0){
        std::cout << "Four" << std::endl;
    }else{
        std::cout << "Three" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define max(a, b) ((a) > (b) ? (a) : (b))

typedef struct
{
    int w;
    int v;
} goods;

long long dp[110][100100] = {0};

int main(void)
{
    int n, w;
    goods g[110];
    scanf("%d%d", &n, &w);
    rep(i, n)
        scanf("%d%d", &g[i].w, &g[i].v);

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= w; j++)
            if (j - g[i - 1].w >= 0)
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - g[i - 1].w] + g[i - 1].v);
            else
                dp[i][j] = dp[i - 1][j];
    /*rep(i, n + 1)
    {
        rep(j, w + 1)
            printf("%2lld ", dp[i][j]);
        putchar('\n');
    }*/

    printf("%lld", dp[n][w]);
    return 0;
}

Measured memory_bytes: 79232
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(V) V.begin(), V.end()
#define PB push_back
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    map<string,int> map;
    map["AC"]= 0;
    map["WA"]= 0;
    map["TLE"]= 0;
    map["RE"]= 0;
    rep(i,n){
        string s;
        cin >> s;
        map[s]++;
    }
    cout << "AC " << "x "<< map.at("AC") <<endl;
    cout << "WA " << "x "<< map.at("WA") <<endl;
    cout << "TLE " << "x "<< map.at("TLE") <<endl;
    cout << "RE " << "x "<< map.at("RE") <<endl;
}

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

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

    int N;
    cin >> N;
    vector<int> A(N), V(N + 1, 0);
    for (auto &x : A) {
        cin >> x;
        V.at(x)++;
    }
    ll sum = 0;
    for (auto &x : V) {
        sum += 1LL * x * (x - 1) / 2;
    }

    for (auto &x : A) {
        ll n = 1LL * V.at(x);
        cout << sum - n * (n - 1) / 2 + (n - 1) * (n - 2) / 2 << endl;
    }

    return 0;
}

Measured memory_bytes: 4224
from itertools import product

A, B, C, D = map(int, list(input()))


def sign(x):
    if x == -1:
        return '-'
    else:
        return '+'


for i, j, k in product([-1, 1], [-1, 1], [-1, 1]):
    x = A + i * B + j * C + k * D
    if x == 7:
        print('{}{}{}{}{}{}{}=7'.format(A, sign(i), B, sign(j), C, sign(k), D))
        break


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

int main(){

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

    long long ans = 0;
    for(int i = 0; i < N; i++){
        int temp = B[i];
        if(A[i] > 0){
            int plus = min(A[i], B[i]);
            ans += plus;
            A[i] -= plus;
            B[i] -= plus;
        }
        if(A[i + 1] > 0){
            int plus = min(A[i + 1], B[i]);
            ans += plus;
            A[i + 1] -= plus;
            B[i] -= plus;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    set<int>x;
    for(int i=0;i<n;i++)
    {
        int c;
        cin>>c;
        x.insert(c);
    }
    cout<<x.size()<<endl;
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  ll T1, T2, A1, A2, B1, B2;
  cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;
  if(A1 < B1) {
    swap(A1, B1);
    swap(A2, B2);
  }
  ll d = (A1-B1)*T1 + (A2-B2)*T2;
  if(d == 0) cout << "infinity" << endl;
  else if(d > 0) cout << 0 << endl;
  else {
    ll d1 = (A1-B1)*T1;
    d = abs(d);
    ll cnt = d1/d+1;
    cout << (d1%d ? cnt*2 : cnt*2-1)-1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)
#define INF 999999999
typedef long long ll;
using namespace std;
int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int ans = 0;
    if(C<A) {
        swap(A, C);
        swap(B, D);
    }
    if(C>B) {
        cout << ans << "\n";
        return 0;
    }
    if(B<D) {
        ans = B - C;
    }else{
        ans = D - C;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)
for x in a:
    d[x] += 1
b = [i for i in range(n)[::-1]]
e = all(d[i] == 2 if n % 2 == 0 else d[i] ==
        1 if i == 0 else d[i] == 2 for i in b[::2])
if not e:
    print(0)
    exit()
ans = 1
for v in d.values():
    ans = ans * v % (10**9+7)
print(ans)


Measured memory_bytes: 15200
#include <iostream>
#include <map>
#define _ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;

const int mod = 2019;

int main()
{_
    string s; cin >> s;
    map <long, long> f;
    f[0] = 1;
    long long suf = 0;
    long long ans = 0;
    long long multi = 1;
    for (int i = s.size() - 1; i >= 0; --i)
    {
        int d = s[i] - '0';
        suf = (suf + d * multi) % mod;
        multi = 10 * multi % mod;
        ans += f[suf];
        f[suf]++;
    }
    cout << ans;
}


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

int main(){
	int N, Y;
	cin >> N >> Y;
	int res10000 = -1, res5000 = -1, res1000 = -1;

	for (int a = 0; a <= N; a++){
		for (int b = 0; b + a <= N; b++){
			int c = N - a - b;
			int total = 10000*a + 5000*b + 1000*c;
			if(total == Y) {
				res10000 = a;
				res5000 = b;
				res1000 = c;
			}

		}
	}

	cout << res10000 << " " << res5000 << " " << res1000 << endl;
}


Measured memory_bytes: 256
N,*A=map(int,open(0))
x=0
B=[]
for a in A:
	x^=a
	B+=a^a-1,
z=0
k=2**30
for b in sorted(B)[::-1]:
	while k and not(x&k):
		k//=2
	if b&k and b<2*k:
		x^=b
		z+=1
print(-1if x else z)

Measured memory_bytes: 12572
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;

int main() {
	string S ; int a = 0;
	cin >> S;
	a = S.size();
	for (int i = 0; i < S.size(); i++) {
		if (i == 0 && S[i] == 'B') { S.erase(S.begin() + i); i = -1; }
		else if (S[i] == 'B') { S.erase(S.begin()+i); S.erase(S.begin()+i - 1); i=-1; }
	}

	cout << S << "\n";
	cin >> a;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int samecount(string S){
    int A = 0;
    for(int i = 0;i < S.size();i++){
        int QA = 1;
        for(int j = i ;j < S.size() - 1;j++){
           if(S.at(j) == S.at(j + 1)){
               QA++ ;
           }
           if(S.at(j) != S.at(j + 1)){
               break;
           }
           
        }
        A = max(QA,A);
    }
    return A;
}

int64_t minn(int64_t a,int64_t b){
    if(a >= b) return b;
    else return a;
}
int main(){
    int N,K;
    cin >>N>>K;
    vector<int> L(N);
    for(int i = 0;i < N;i++){
        cin >> L[i];
    }
    sort(L.begin(),L.end());
    int ans = 0;
    for(int i = 1;i < K + 1;i++){
        ans += L[N-i];
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;


ll get_mod(string s, int pp) {
    if (pp == 0) return 0;
    mp::cpp_int i = 0;
    rep(j, s.size()) {
        i *= 2;
        i += s[j] == '1';
    }

    mp::cpp_int g = i % pp;
    ll f = static_cast<ll>(g);

//    cout << bitset<23>(f) << endl;

    return f;

}

ll f(ll n) {
    int ans = 1;
    while (n > 0) {
        ll pp = __builtin_popcountll(n);
        n %= pp;
        ans++;
    }
    return ans;
}

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

    int pp = count(s.begin(), s.end(), '1');
    
    ll um = get_mod(s, pp + 1);
    ll dm = get_mod(s, pp - 1);


    auto create_md = [](int n, int pp) {
        vector<ll> md(n);
        if (pp == 0)return md;

        ll prev = 1;
        rep(i, n) {
            md[i] = prev % pp;
            prev *= 2;
            prev %= pp;
        }
        reverse(md.begin(), md.end());
        return md;
    };


    vector<ll> mdu = create_md(n, pp + 1);
    vector<ll> mdd = create_md(n, pp - 1);

    vector<ll> ans;

    rep(i, n) {
        if (s[i] == '0') {
            ll prev = (um + (pp + 1) + mdu[i]) % (pp + 1);
            ll now = f(prev);
            ans.push_back(now);
        } else {
            if (pp == 1) {
                ans.push_back(0);
                continue;
            }
            ll prev = (dm + (pp - 1) - mdd[i]) % (pp - 1);
            ll now = f(prev);
            ans.push_back(now);
        }
    }

//    sort(ans.begin(), ans.end());

    for (ll l : ans) cout << l << endl;

}


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

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);

template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dbg(x) true
#endif

const string YES = "Yes";
const string NO = "No";

void solve(long long N, std::vector<std::vector<long long>> D) {
  vector<bool> v(N);
  REP(i, N) {
    if (D[i][0] == D[i][1]) {
      v[i] = true;
    } else {
      v[i] = false;
    }
  }
  ll count = 0;
  REP(i, N) {
    if (v[i]) {
      count++;
    } else {
      count = 0;
    }
    if (count >= 3) {
      cout << YES << endl;
      return;
    }
  }
  cout << NO << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<std::vector<long long>> D(N, std::vector<long long>(2));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 2; j++) {
      scanf("%lld", &D[i][j]);
    }
  }
  solve(N, std::move(D));
  return 0;
}


Measured memory_bytes: 3696
"use strict";
function Main(input) {
    let lines = input.split("\n");
    let N = lines.shift() - 0;
    let Vc = lines[0].split(/\s/).map((v) => v - 0);
    let a = [{}, {}], sw = 0;
    for (let v of Vc) {
        let b = a[sw][v] || 0;
        a[sw][v] = b + 1;
        sw = (sw + 1) % 2;
    }
    let c = [[], []];
    for (let m = 0; m < 2; m++) {
        for (let v in a[m]) {
            c[m].push({value:v, count:a[m][v]});
        }
    }
    c[0].sort((a, b) => b.count - a.count);
    c[1].sort((a, b) => b.count - a.count);

    let ans = 0;
    let n = N / 2;
    let e0 = c[0][0], e1 = c[0][1] || {value:0, count:0};
    let o0 = c[1][0], o1 = c[1][1] || {value:0, count:0};
    if (e0.value == o0.value) {
        if (e0.count > o0.count) {
            ans += n - e0.count;
            ans += n - o1.count;
        } else if (e0.count < o0.count) {
            ans += n - e1.count;
            ans += n - o0.count;
        } else {
            let ans0 = n - e0.count + n - o1.count;
            let ans1 = n - e1.count + n - o0.count;
            ans = Math.min(ans0, ans1);
        }
    } else {
        ans += n - e0.count;
        ans += n - o0.count;
    }

    console.log(ans);//74371
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 35236
#include<iostream>
#include<vector>

using namespace std;
const int INF = 1<<30;
typedef long long int ll;

int main(){
  ll n, a, b;cin>>n>>a>>b;
  if(a>b)cout<<0<<endl;
  else if(n==1)cout<<(a==b?1:0)<<endl;
  else cout<<(n-2)*(b-a)+1<<endl;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
a.sort()
ans=0
b=list()
for i in range(10**6+1):
    b.append(0)
for i in range(n):
    if b[a[i]]==0:
        j=1
        while j*a[i]<=10**6:
            b[j*a[i]]=1
            j+=1
        if (i==n-1 or a[i+1]!=a[i]):
            ans+=1
print(ans)

Measured memory_bytes: 32056
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main() {
	string s;
	cin >> s;
	ll sum = 0;
	for (int i = 0; i < (int) s.size(); i++) {
		sum += (s[i] - '0');
	}
	if (sum % 9 == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, d; cin >> n;
	unordered_map <int,int> mp;
	for (int i = 0; i < n; ++i){
		cin >> d;
		mp[d]++;
	}
	priority_queue <long long int> pq;
	for (auto it = mp.begin(); it != mp.end(); ++it){
		if (it->second >= 2) pq.push(it->first);
		if (it->second >= 4) pq.push(it->first);
	}
	pq.push(0);
	pq.push(0);
	long long int first = pq.top();
	pq.pop();
	long long int second = pq.top();
	cout << first * second << "\n";	
	return 0;
}


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

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] p = new int[n];
        int[] sorted = new int[n];
        int count = 0;
        for (int i = 0; i < n; i++) {
            p[i]= scanner.nextInt();
            sorted[i]= p[i];
        }
        Arrays.sort(sorted);
        for (int i = 0; i < n; i++) {
            if(p[i] != sorted[i]){
                count++;
            }
        }
        if(count <= 2){
            System.out.println("YES");
        } else{
            System.out.println("NO");
        }
    }

}



Measured memory_bytes: 23252
#include <iostream>
#include <algorithm>
using namespace std;
int n, q, x, s[300003]; bool a[300003];
int sum(int l, int r) {
	return s[r - 1] - s[l - 1];
}
int main() {
	scanf("%d%d", &n, &q);
	for(int i = 0; i < n; i++) scanf("%d", &x), a[x] = true;
	for(int i = 1; i <= 300000; i++) s[i] = s[i - 1] + (a[i] ? 1 : 0);
	for(int i = 0; i < q; i++) {
		scanf("%d", &x);
		int ret = 0;
		for(int j = x; j <= 300000; j += x) {
			if(sum(j - x, j) == 0) continue;
			int l = j - x, r = j;
			while(r - l > 1) {
				int m = (l + r) / 2;
				if(sum(m, j) != 0) l = m;
				else r = m;
			}
			ret = max(ret, l - (j - x));
		}
		printf("%d\n", ret);
	}
}

Measured memory_bytes: 4684
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size() 

const ll M=2e5+5;
ll segtree[4*M],H[M],h[M],a[M];

void build(ll st,ll en,ll idx)
{
	if(st==en)
		segtree[idx]=H[st];
	else
	{
		ll md=(st+en)/2;
		build(st,md,2*idx+1);
		build(md+1,en,2*idx+2);
		segtree[idx]=max(segtree[2*idx+1],segtree[2*idx+2]);
	}
}

void update(ll st,ll en,ll idx,ll l,ll x)
{
	if(st==en)
	{
		H[l]=x;
		segtree[idx]=x;
	}
	else
	{
		ll md=(st+en)/2;
		if(st<=l && l<=md)
			update(st,md,2*idx+1,l,x);
		else
			update(md+1,en,2*idx+2,l,x);
		segtree[idx]=max(segtree[2*idx+1],segtree[2*idx+2]);
	}
}

ll query(ll st,ll en,ll idx,ll l,ll r)
{
	
	if(st>r || en<l)return 0;

	if(st>=l && en<=r)return segtree[idx];
	
	ll md=(st+en)/2;
	return max(query(st,md,2*idx+1,l,r),query(md+1,en,2*idx+2,l,r));
}


int main()
{
    ios_base::sync_with_stdio(false);
	ll n,i,j,k,x,y,t,m;

	vector<pll>v;
	cin >> n;
	for(i=0;i<n;i++)
	{
		cin >> h[i];
		v.pb(mp(h[i],i));
	}
	for(i=0;i<n;i++)
		cin >> a[i];

	sort(all(v));

	x=0,i=0;
	ll mx=0;
	while(i<sz(v))
	{
		j=i;
		while(j<sz(v) && v[j].ff==v[i].ff)
		{
			h[v[j].ss]=x;
			mx=max(mx,x);
			j++;
		}
		x++;
		i=j;
	}

	// for(i=0;i<n;i++)
	// 	cout<<h[i]<<" ";
	// cout<<endl;

	build(0,mx,0);
	for(i=n-1;i>=0;i--)
	{
		x=a[i]+query(0,mx,0,h[i],mx);
		// if(i==0)
		// 	cout<<x<<endl;
		if(x>H[h[i]])
			update(0,mx,0,h[i],x);
	}
	ll ans=0;
	for(i=0;i<=mx;i++)
		ans=max(ans,H[h[i]]);
	cout<<ans<<endl;
}

Measured memory_bytes: 14572
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

int n;

int main()
{
  cin >> n;
  ll minimum = INF;
  ll ans;
  REP(i, n)
  {
    ll in;
    cin >> in;
    if (in <= minimum)
    {
      minimum = min(minimum, in);
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

#define INF (INT64_MAX/2)
#define MAX 100000
#define MOD (1000000000+7)

int a[26];

int main() {
	long long N;
	string S;

	cin >> N >> S;

	for( int i = 0; i < N; i++ ) {
		a[ S[i] - 'a' ]++;
	}
	long long ans = 1;
	for( int i = 0; i < 26; i++ ) {
		ans = ( ans * ( a[i] + 1 ) % MOD ) % MOD;
	}
	ans = (ans + MOD - 1) % MOD;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 512
(defun solve (n monsters warriors)
  (let ((all-monsters (reduce #'+ monsters)))
    (loop for i from 0 below n
          for power = (aref warriors i)
          do (cond
               ((<= (aref monsters i) (aref warriors i))
                (psetf (aref monsters i) 0
                       (aref warriors i) (- (aref warriors i) (aref monsters i)))
                (setf (aref monsters (1+ i))
                      (max 0 (- (aref monsters (1+ i))
                                (aref warriors i)))))
               (t
                (psetf (aref warriors i) 0
                       (aref monsters i) (- (aref monsters i) (aref warriors i))))))
    (- all-monsters (reduce #'+ monsters))))

#-swank
(let* ((n (read))
       (monsters (make-array (1+ n) :element-type 'fixnum))
       (warriors (make-array n :element-type 'fixnum)))
  (loop for i from 0 to n
        do (setf (aref monsters i) (read)))
  (loop for i from 0 below n
        do (setf (aref warriors i) (read)))
  (format t "~A~%" (solve n monsters warriors)))


Measured memory_bytes: 60000
import java.util.Scanner

import scala.annotation.tailrec
import scala.collection.mutable

object Main {
  def main(args: Array[String]): Unit = {
    //nextLineとnextを同時に使ったら死ぬ
    val sc = new Scanner(System.in)

    val n, m = sc.nextInt()
    val arr = Array.fill(n)(Vector.empty[Int])

    for (_ <- 0 until m) {
      val a, b = sc.nextInt()
      arr(a - 1) = arr(a - 1) :+ (b - 1)
      arr(b - 1) = arr(b - 1) :+ (a - 1)
    }

    println("Yes")

    val visited = Array.fill(n)(false)
    val ans = Array.fill(n)(-1)
    val queue = mutable.Queue(0)

    while (queue.nonEmpty) {
      val q = queue.dequeue()
      visited(q) = true
      arr(q)
        .filter(m => !visited(m))
        .foreach(i => {
          if (ans(i) == -1) {
            ans(i) = q
            queue.enqueue(i)
          }
        })
    }

    ans.tail.foreach(j => println(j + 1))
  }

  //region

  def debug(args: Any*): Unit = {
    Console.err.println(args.mkString(" "))
    Console.err.flush()
  }

  def printExecTime(process: => Unit): Unit = {
    val start = System.currentTimeMillis
    process
    debug("処理時間： " + (System.currentTimeMillis - start) + " ミリ秒")
  }

  def bitSearch[T](n: Int, choice: Vector[T]): Vector[Vector[T]] = {
    @tailrec
    def bitSearchLogic(n: Int,
                       choice: Vector[T],
                       acc: Vector[Vector[T]]): Vector[Vector[T]] = {
      if (n == 0) acc
      else {
        val newAcc =
          acc.flatMap(vec => {
            choice.map(c => vec :+ c)
          })
        bitSearchLogic(n - 1, choice, newAcc)
      }
    }

    val firstAcc = choice.map(i => Vector(i))
    bitSearchLogic(n - 1, choice, firstAcc)
  }
  //endregion
}


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

int main()
{
        vector<int> i;
        for (int j=0; j < 3; ++j) {
                int tmp;
                cin >> tmp;
                i.push_back(tmp);
        }
        sort(i.begin(), i.end());
        for (int j= 0; j < 3; ++j) {
                cout << i[j];
                if (j != 2) {
                        cout << " ";
                }
        }
        cout << endl;
}



Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
bool chmin(ll & a, ll  b) { if (b < a) { a = b; return 1; } return 0; }
bool chmax(ll & a, ll b) { if (b > a) { a = b; return 1; } return 0; }
const ll INF = 999999999999999;
const ll MOD = 998244353;
const ll MAX_N=500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
struct segtree {
	ll N;
	vl dat;
	void init(ll n) {
		N = 1;
		while (N < n) N *= 2;
		dat = vl(N * 2);
		for (ll i = 0; i < 2 * N - 1; i++)
			dat[i] = INF;
	}
	// update k th element
	void update(ll k, ll a) {
		k += N - 1; // leaf
		dat[k] = a;
		while (k > 0) {
			k = (k - 1) / 2;
			dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
		}
	}
	// min [a, b)
	ll query(ll a, ll b) { return query(a, b, 0, 0, N); }
	ll query(ll a, ll b, ll k, ll l, ll r) {
		if (r <= a or b <= l) return INF;
		if (a <= l and r <= b) return dat[k];
		ll m = (l + r) / 2;
		return min(query(a, b, k * 2 + 1, l, m), query(a, b, k * 2 + 2, m, r));
	}
};
int main() {
  vector<PP> VP;
  vl A;
    cin >> n;
    rep(i,n){
      cin>>x>>y;
      VP.push_back({x,y});
    }

    sort(all(VP));
    vl DP(300000,0);
    
    rep(i,n){
      x=upper_bound(all(VP),make_pair(VP[i].first+VP[i].second,-INF))-VP.begin();
      A.push_back(x);
    }

    segtree SEG;
    vl B;
    SEG.init(n);

    rep(i,n){
      SEG.update(i,-A[i]);
    }

    rep(i,n){
      k=n-1-i;
      B.push_back(-SEG.query(k,A[k]));
      SEG.update(k,-B[i]);
    }

    reverse(all(B));
    
    
    
    DP[0]=1;
    rep(i,n){
      DP[i+1]=(DP[i+1]+DP[i])%MOD;
      DP[B[i]]=(DP[B[i]]+DP[i])%MOD;
    }

    cout<<DP[n]<<endl;
}

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

int main() {
  int A, B;
  char op;
  cin >> A >> op >> B;
  
  if (op == '+'){
    cout << A + B << endl;
  }
  else if (op == '-'){
    cout << A - B << endl;
  }
    
}

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

using namespace std;

int main(void){
  int X;
  cin >> X;
  if(X == 7 || X == 5 || X == 3) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int N,c=0,t,i;
    scanf("%d",&N);
    for(i=1;i<=N;i++){
        t=N%i;
        if(t==0&&N/i<10&&i<10){
            printf("Yes\n");
            c=1;
            break;
        }
     }
    if(c==0){
        printf("No\n");
    }
    return 0;
}

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

struct node
{
  unsigned int key; //0以上の整数値
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key)
{
  NodePointer n;

  for( n = nil->next; n != nil; n = n->next)
    {
      if(n->key == key) return n;
    }
  return NULL;
}

void init()
{
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList()
{
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t)
{
  free(t);
}

void delete(int key)
{
  NodePointer x;
  if((x = listSearch(key)) == NULL)return;

  x->next->prev = x->prev;
  x->prev->next = x->next;
  deleteNode(x);
}


void deleteFirst()
{
  NodePointer t = nil->next;
  if ( t == nil ) return;
  nil->next = t->next;
  t->next->prev = nil;
  deleteNode(t);
}

void deleteLast()
{
  NodePointer t = nil->prev;
   if ( t == nil ) return;
  t->prev->next = nil;
  nil->prev = t->prev;
  deleteNode(t);
}

void insert(int okey)
{
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = okey;

  x->next = nil->next;
  nil->next = x;
  x->prev = nil;
  x->next->prev = x;

}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ )
    {
      scanf("%s", com);
      
      if ( com[0] == 'i' )
	{
	  scanf("%d", &key);
	  insert(key); np++; size++;
	}
      else if ( com[0] == 'd' )
	{
	  if (strlen(com) > 6)
	    {
	      if ( com[6] == 'F' ) deleteFirst();
	      else if ( com[6] == 'L' ) deleteLast();
	    }
	  else
	    {
	      scanf("%d",&key);
	      delete(key); nd++; 
	    }
	  size--;
	}
    }
  
  printList();
  
  return 0;
}



Measured memory_bytes: 32996
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n,ans;
	cin>>n;
	for(int i=1;;i++){
		if(1000*i>=n){
			ans=1000*i-n;
			break;
		}
	}
	cout<<ans;
	return 0;;
} 

Measured memory_bytes: 3620
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<algorithm>
#include<set>
#include <stdexcept>
#include<queue>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
int ceil(int a,int b){// a以上bの倍数の最小値//
     return (a+b-1)/b*b;
 }
int stoii(string s){//stoi関数の代用 文字列⇒int型//
    return atoi(s.c_str());
}

char maze[51][51];
int n,m;
int sx,sy,gx,gy;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
int d[51][51];
int bfs(){
	queue<P> que;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			d[i][j]=inf;
		}
	}
	que.push(P(sx,sy));
	d[sx][sy]=0;

	while(que.size()){
		P p=que.front();
		que.pop();
		if(p.first==gx && p.second==gy) break;
		for(int i=0;i<4;i++){
			int nx=p.first+dx[i],ny=p.second+dy[i];

			if(0<=nx && nx<n && 0<=ny && ny<m && maze[nx][ny]!='#'&&d[nx][ny]==inf){
				que.push(P(nx,ny));
				d[nx][ny]=d[p.first][p.second]+1;
			}
		}
	}
	return d[gx][gy];
}
int main(){
	vector<int> a(3,0);
	int min;
	rep(i,3) cin>>a[i];
	min=abs(a[0]-a[1])+abs(a[1]-a[2]);
	if(abs(a[0]-a[2])+abs(a[2]-a[1])<min){
		min=abs(a[0]-a[2])+abs(a[2]-a[1]);
	}
	if(abs(a[1]-a[0])+abs(a[0]-a[2])<min){
		min=abs(a[1]-a[0])+abs(a[0]-a[2]);
	}
	if(abs(a[1]-a[2])+abs(a[2]-a[0])<min){
		min=abs(a[1]-a[2])+abs(a[0]-a[2]);
	}
	if(abs(a[2]-a[1])+abs(a[1]-a[0])<min){
		min=abs(a[1]-a[2])+abs(a[0]-a[1]);
	}
	if(abs(a[2]-a[0])+abs(a[1]-a[0])<min){
		min=abs(a[2]-a[0])+abs(a[0]-a[1]);
	}
	
	cout<<min<<endl;

	return 0;
}


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

#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);

typedef long long int lli;

int main()
{
	fio;
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	int ans=1;
	int count=k;
	while(count<n)
	{
		count+=k-1;
		ans++;
	}
	cout<<ans<<endl;
	cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
	return 0;
}

Measured memory_bytes: 640
--{-# LANGUAGE StandaloneDeriving #-}
--{-# LANGUAGE BangPatterns #-}

module Main where

import Debug.Trace
--import Data.List
--import Data.Char
import qualified Data.Set as Set
--import qualified Data.Map.Strict as Map

main :: IO ()
main = do
  [h, w, k] <- map read . words <$> getLine
  s <- toSet h w . lines <$> getContents
  --a `traceShow`
  print . length $ solve h w k s

toSet :: Int -> Int -> [String] -> Set.Set Int
toSet h w s = foldr build Set.empty . zip [0..h] $ s
  where
    build (hi, l) st = foldr (b hi) st . zip [0..w] $ l
    b hi (wi, c) st = if c == '#' then Set.insert (hi * w + wi) st else st

solve :: Int -> Int -> Int -> Set.Set Int -> [Set.Set Int]
solve h w k st = filter (\s -> Set.size s == k) $ sts'
  where
    sts = delRows h w k [0 .. h - 1] [st]
    sts' = delCols h w k [0 .. w - 1] sts

delRows :: Int -> Int -> Int -> [Int] -> [Set.Set Int] -> [Set.Set Int]
delRows _ _ _ [] sts = sts
delRows h w k (hq:hs) sts = delRows h w k hs $ concatMap (delRow h w k hq) sts

delCols :: Int -> Int -> Int -> [Int] -> [Set.Set Int] -> [Set.Set Int]
delCols _ _ _ [] sts = sts
delCols h w k (wq:ws) sts = delCols h w k ws $ concatMap (delCol h w k wq) sts


delRow :: Int -> Int -> Int -> Int -> Set.Set Int -> [Set.Set Int]
delRow h w k q st = if Set.size st' < k then [st] else [st, st']
  where
    st' = foldr (\i s -> Set.delete (w * q + i) s) st [0 .. w - 1]

delCol :: Int -> Int -> Int -> Int -> Set.Set Int -> [Set.Set Int]
delCol h w k q st = if Set.size st' < k then [st] else [st, st']
  where
    st' = foldr (\i s -> Set.delete (w * i + q) s) st [0 .. h - 1]


Measured memory_bytes: 4740
k,t = map(int,input().split())
a_list = list(map(int,input().split()))
a_max = a_list.pop(a_list.index(max(a_list)))

if t == 1:
  print(k-1)
  
else:
  if a_max - 1 >= sum(a_list):
    print(a_max - 1 - sum(a_list))
  else:
    print(0)

Measured memory_bytes: 3060
n = int(input())
new_B = list(map(int, input().split()))
ans = []
cnt = 0

while (cnt < 100000) & (new_B != []):
    B = new_B
    length = len(B)
    new_B = []
    for i in range(1, length + 1):
        if B[-i] < (len(B) - i + 1):
            new_B = [B[-i]] + new_B
        elif B[-i] == (len(B) - i + 1):
            ans.append(B[-i])
            new_B = B[:-i] + new_B
            break
        else:
            print(-1)
            exit()
    cnt += 1


if cnt == 100000:
    print(-1)
else:
    for i in ans[::-1]:
        print(i)


Measured memory_bytes: 9224