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

int main(){
    long long int n, x, d;
    cin >> n >> x >> d;

    if(d == 0){
        if(x == 0) cout << 1 << endl;
        if(x != 0) cout << n+1 << endl;
        return 0;
    }

    map<long long int, vector<pair<long long int, long long int>>> rem;
    for(long long int i=0; i<=n; i++){
        long long int common = i * x;
        long long int r      = ((common % d) + d) % d;
        long long int least  = (0 + (i-1))   * i / 2;
        long long int most   = (n + (n-i-1)) * i / 2;

        long long int from = (common - r) / d + least;
        long long int to   = from + (most - least);
        rem[r].push_back({from, to});
    }

    long long int ans = 0;
    for(auto r : rem){
        vector<pair<long long int, int>> event;
        for(int i=0; i<r.second.size(); i++){
            long long int from = r.second[i].first;
            long long int to   = r.second[i].second;
            event.push_back({from, +1});
            event.push_back({to+1, -1});
        }
        sort(event.begin(), event.end());

        long long int count   = 0;
        long long int current = -1e18;
        for(auto ev : event){
            long long int length = ev.first - current;
            if(count > 0) ans += length;
            count += ev.second;
            current = ev.first;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 25508
import java.util.*;
import java.util.Map.*;
import java.util.function.*;
import java.util.stream.*;

public class Main{
	Scanner s=new Scanner(System.in);

	long mod=1000000007;

	public long modpow(long n,long p){
		if(p==0)
			return 1;
		if(p%2==1)
			return n*modpow(n,p-1)%mod;
		long d=modpow(n,p/2);
		return d*d%mod;
	}

	void solve(){
		int n=gInt();
		int[]a=INTS(n).toArray();

		HashMap<Integer,Integer>factor=new HashMap<>();
		for(int o:a) {
			for(int i=2;i*i<=o;++i) {
				if(o%i==0) {
					int c=0;
					while(o%i==0) {
						o/=i;
						++c;
					}
					factor.merge(i,c,Integer::max);
				}
			}
			if(o!=1)
				factor.merge(o,1,Integer::max);
		}

		long lcm=1;
		for(Entry<Integer,Integer> e:factor.entrySet()) {
			for(int q:rep(e.getValue())) {
				lcm*=e.getKey();
				lcm%=mod;
			}
		}

		long r=0;
		for(int o:a) {
			r+=lcm*modpow(o,mod-2);
			r%=mod;
		}
		System.out.println(r);
	}

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

	int gInt(){
		return Integer.parseInt(s.next());
	}
	long gLong(){
		return Long.parseLong(s.next());
	}
	double gDouble(){
		return Double.parseDouble(s.next());
	}

	SupplyingIterator<Integer> ints(int n){
		return new SupplyingIterator<>(n,this::gInt);
	}
	SupplyingIterator<Long> longs(int n){
		return new SupplyingIterator<>(n,this::gLong);
	}
	SupplyingIterator<Double> doubles(int n){
		return new SupplyingIterator<>(n,this::gDouble);
	}
	SupplyingIterator<String> strs(int n){
		return new SupplyingIterator<>(n,s::next);
	}

	Range rep(int i){
		return Range.rep(i);
	}
	Range rep(int f,int t,int d){
		return Range.rep(f,t,d);
	}
	Range rep(int f,int t){
		return rep(f,t,1);
	}
	Range rrep(int f,int t){
		return rep(t,f,-1);
	}

	IntStream REP(int v){
		return IntStream.range(0,v);
	}
	IntStream REP(int l,int r){
		return IntStream.rangeClosed(l,r);
	}

	IntStream INTS(int n){
		return IntStream.generate(this::gInt).limit(n);
	}
	Stream<String> STRS(int n){
		return Stream.generate(s::next).limit(n);
	}

}

class SupplyingIterator<T> implements Iterable<T>,Iterator<T>{
	int			t;
	Supplier<T>	supplier;

	SupplyingIterator(int t,Supplier<T> supplier){
		this.t=t;
		this.supplier=supplier;
	}

	@Override
	public Iterator<T> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return t>0;
	}

	@Override
	public T next(){
		--t;
		return supplier.get();
	}

}

class Range implements Iterable<Integer>,PrimitiveIterator.OfInt{
	int to,cur,d;

	Range(int from,int to,int d){
		this.cur=from-d;
		this.to=to;
		this.d=d;
	}

	Range(int n){
		this(0,n-1,1);
	}

	@Override
	public Iterator<Integer> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return cur+d==to||(cur!=to&&(cur<to==cur+d<to));
	}

	@Override
	public int nextInt(){
		return cur+=d;
	}
	static Range rep(int i){
		return new Range(i);
	}
	static Range rep(int f,int t,int d){
		return new Range(f,t,d);
	}
	static Range rep(int f,int t){
		return rep(f,t,1);
	}
	static Range rrep(int f,int t){
		return rep(f,t,-1);
	}
}

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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

const long long INF=1LL<<61;

int main(){
	int n;
	lint cost; scanf("%d%lld",&n,&cost);
	vector<lint> x(n);
	rep(i,n) scanf("%lld",&x[i]);

	vector<lint> cum(n+1);
	rep(i,n) cum[i+1]=cum[i]+x[i];

	lint ans=INF;
	for(int i=1;i<=n;i++){
		long double res=(n+i)*cost+(cum[n]-cum[n-i]);
		int idx=n-1;
		for(int k=1;idx>=0;k++){
			lint dsum=(cum[idx+1]-cum[max(idx+1-i,0)])
					 -(cum[max(idx+1-i,0)]-cum[max(idx+1-2*i,0)]);
			res+=(long double)(dsum)*(k+1)*(k+1);
			idx-=i;
		}
		if(res<INF) ans=min(ans,lint(res));
	}
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <utility>

int n, t;
std::pair<int, int> data[110];
int main()
{
    std::cin >> n >> t;
    for (int i = 0; i < n; ++i)
        std::cin >> data[i].first >> data[i].second;

    std::sort(data, data + n);
    for (int i = 0; i < n; ++i)
        if (data[i].second <= t)
        {
            std::cout << data[i].first;
            return 0;
        }
    std::cout << "TLE" << std::endl;
    return 0;
}


Measured memory_bytes: 256
//don't go gentle into
// the goodnight.

#include<bits/stdc++.h>
using namespace std;

#define int       long long
#define ll        long long
#define fr        first
#define sec       second
#define pi        3.141592653589793
#define M         1000000007
#define mod       998244353
#define maxint    2147483647
#define minint    -2147483648
#define maxll     9223372036854775807
#define minll     -9223372036854775808
#define meme0(a)  memset(a,0,sizeof(a));
#define meme1(a)  memset(a,-1,sizeof(a));
#define i_m_speed ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define open      freopen("input.txt","r",stdin);
#define close     freopen("output.txt","w",stdout);
#define v_int     vector<int >
#define v_ll      vector<long long >
#define pb        push_back
#define mk        make_pair
//upper_bound(begin(),end(),key)
//lower_bound(begin(),.end(),key);

ll expo(ll x , ll n , ll m){
    if(n==0)
        return 1;
    else if(n%2==0)
        return expo((x*x)%m , n/2 , m);
    else
        return (x*expo((x*x)%m,(n-1)/2,m))%m;

}
string toBinary(ll n)
{
    std::string r;
    while(n!=0){
        r=(n%2==0 ?"0":"1")+r;
        n/=2;
    }
    return r;
}


void solve(){
    int n,k;
    cin >> n >> k;
    int p[n];
    for(int i=0;i<n;i++){
        cin >>  p[i];
        p[i]++;
    }
    int ans = 0;
    for(int i=0;i<k;i++)
        ans += p[i];
    int count = ans;
    for(int i=0;i<n;i++){
        if(i+k>=n)
            break;
        count = count - p[i] + p[i+k];
        ans = max(count,ans);
    }
    //cout << ans << endl;
    cout << setprecision(20) << fixed;
    cout << double(ans/(double(2))) << endl;
    return;
}
int32_t main(){
    i_m_speed
    int t=1;
    //cin >> t;
    while(t--){
        solve();
    }

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

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

	int buyBnum = (x - a)/b;

	int ans  = x - a - b*buyBnum;

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repp(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;

signed main(){
    string s;
    cin >> s;
    int ans = 0;
    if(s.find("N") != string::npos) ans++;
    if(s.find("S") != string::npos) ans--;
    if(s.find("W") != string::npos) ans += 2;
    if(s.find("E") != string::npos) ans -= 2;
    cout << (ans == 0 ? "Yes" : "No") << endl;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll K, S;
  cin >> K >> S;
  ll ans = 0;
  rep(X, K+1){
    rep(Y, K+1){
      ll Z = S - X - Y;
      if(Z>=0 and Z<=K){
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <string>
#include <map>
#include <set>

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

ll n, h;
ll di[100010];
ll hi[100010];

int main() {
  while (scanf("%lld %lld", &n, &h) > 0) {
    REP(i, n - 1) {
      scanf("%lld %lld", &di[i], &hi[i]);
    }
    ll ans = 0;
    ll hhp = h;
    ll thp = h;
    int head = 0;
    int tail = 0;
    multiset<int> spring;
    spring.insert(-hi[0]);
    spring.insert(0);
    bool down = true;
    while (head < n - 1) {
      if (hhp > di[head]) {
        hhp -= di[head];
        head++;
        spring.insert(-hi[head]);
        continue;
      }
      if (down || hi[tail] != -*spring.begin()) {
        thp -= di[tail];
        spring.erase(spring.find(-hi[tail]));
        tail++;
        down = false;
        continue;
      }
      ll rest = h - thp;
      ll need = min(rest, di[head] - hhp + 1);
      ll cnt = (need + hi[tail] - 1) / hi[tail];
      if (cnt * hi[tail] > rest) { cnt--; }
      ans += cnt;
      hhp += cnt * hi[tail];
      thp += cnt * hi[tail];
      if (hhp > di[head]) { continue; }
      ll up = h - thp;
      assert(thp <= h);
      down = true;
      set<int>::iterator it = spring.begin();
      it++;
      if (-*it < up || head == tail) {
        ans++;
        hhp += up;
        thp += up;
      }
    }
    printf("%lld\n", ans);
  }
}

Measured memory_bytes: 2748
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
#define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
	while(ch=getchar(),ch<33);
	if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
	while(ch=getchar(),ch>33)x=x*10+ch-48;
	if(fs)x=-x;	
}
using namespace std;
int n,m;
struct node
{
	int x,y;
	bool operator < (const node& i)const 
	{
		return y<i.y;
	}
}po[233];
LL ans=1ll<<62;
int main()
{
	re(n),re(m);
	for(int i=1;i<=n;++i)
		re(po[i].x),re(po[i].y);
	sort(po+1,po+n+1);
	for(int i=1;i<=n;++i)
		for(int j=i;j<=n;++j)
			for(int k=i;k<=n;++k)	
			{
				int have=0,g=po[i].y,h=max(po[j].y,po[k].y),l=po[j].x,r=po[k].x;
				for(int e=i;e<=max(j,k);++e)	
					if(po[e].x>=l && po[e].x<=r)
						++have;
				for(int e=max(j,k)+1;e<=n;++e)
				{
					if(have>=m)break;
					h=po[e].y;
					if(po[e].x>=l && po[e].x<=r)++have;
				}
				if(have>=m)
					ans=min(ans,1ll*(r-l)*(h-g));
			}
	printf("%lld\n",ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
//#include <function>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)


int main() {


  int N, M, C;
  cin >> N >> M >> C;

  vector<int> B(M);
  int A[N][M];
  REP(i, M) cin >> B[i];
  REP(i, N) REP(j, M) cin >> A[i][j];

  int ans = 0;
  int tmp;
  REP(i, N){
    tmp = C;
    REP(j, M){
      tmp += A[i][j] * B[j];
    }
    if (tmp > 0) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4;
  cin >> x_1 >> y_1 >> x_2 >> y_2;
  x_3 = x_2-y_2+y_1;
  y_3 = y_2+x_2-x_1;
  x_4 = x_3-y_3+y_2;
  y_4 = y_3+x_3-x_2;
  cout << x_3 <<" "<< y_3 <<" "<< x_4 <<" "<< y_4 << endl;
}

Measured memory_bytes: 256
import itertools

def check(lst, n, x):
    for i in range(2, n+1):
        B = list(itertools.combinations(lst,i))
        for C in B:
            if x == sum(C):
                return True
    return False

n = int(input())
A = [int(i) for i in input().split()]
q = int(input())
m = [int(i) for i in input().split()]

for x in m:
    if x > sum(A):
        print("no")
    elif (x in A) or check(A, n, x):
        print("yes")
    else:
        print("no")



Measured memory_bytes: 58708
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>

#define ll long long
#define ull unsigned long long

using namespace std;

typedef pair<ull,ull> P;

int main() {
	ull N;
	cin >> N;
	vector <ull> u(N-1, 0);
	vector <ull> v(N-1, 0);
	vector <ull> w(N-1, 0);
	for (int ii = 0; ii < N - 1; ++ii){
		cin >> u[ii] >> v[ii] >> w[ii];
	}

	//頂点毎に，（繋がっている頂点番号，距離）を登録していく
	vector<vector<ull>> vlist(N, vector<ull>());
	vector<vector<ull>> elist(N, vector<ull>());
	for (int ii = 0; ii < N - 1; ++ii){
		ull v1 = u[ii] - 1;
		ull v2 = v[ii] - 1;
		ull len = w[ii];
		vlist[v1].push_back(v2);
		vlist[v2].push_back(v1);
		elist[v1].push_back(len);
		elist[v2].push_back(len);
	}

	vector<ull> isBlack(N, 0);
	vector<bool> isDone(N, false);

	//スタート地点を登録
	ull initVertex = 0;
	queue<ull> q;
	q.push(initVertex);
	isDone[initVertex] = true;

	while (!q.empty()) {
		ull vertex = q.front();
		q.pop();
		for (int ii = 0; ii < vlist[vertex].size(); ++ii){
			ull adVertex = vlist[vertex][ii];
			ull edgeLen = elist[vertex][ii];
			//まだ訪れていない頂点のとき，隣の頂点の色と距離を見て白か黒か決める
			if (!isDone[adVertex]){
				if (edgeLen % 2 == 0){
					isBlack[adVertex] = isBlack[vertex];
				} else {
					isBlack[adVertex] = (1 + isBlack[vertex]) % 2;
				}
				q.push(adVertex);
				isDone[adVertex] = true;
			}
		}
	}

	for (int ii = 0; ii < N; ++ii){
		cout << isBlack[ii] << endl;
	}

	return 0;
}


Measured memory_bytes: 15616
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

import itertools

n = int(readline())
s = [[] for i in range(n)]
u = [[] for j in range(n)]
for j in range(n):
    a = int(readline())
    for k in range(a):
        x, y = map(int, readline().split())
        if y == 1:
            s[j].append(x)
        else:
            u[j].append(x)
bit = list(itertools.product([0, 1], repeat=n))
ans = 0
for i in range(2 ** n):
    flag = True
    memo = []
    check_s = []
    check_u = []
    for j in range(n):
        if bit[i][j] == 1:
            memo.append(j + 1)
            check_s += s[j]
            check_u += u[j]
    if len(set(check_u) & set(memo)) == 0:
        for j in range(len(check_s)):
            if (check_s[j]) not in memo:
                flag = False
        if flag:
            ans = max(ans, len(memo))
print(ans)


Measured memory_bytes: 50668
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;

bool findHarshad(int n) {

    int sum = 0;
    int x;
    x = n;

    while (x > 0) {
        sum += x % 10;
        x /= 10;
    }

    if (n % sum == 0) return 1;
    else return 0;

}

int main() {

    int n;
    cin >> n;

    cout << ((findHarshad(n)) ? "Yes" : "No") << endl;

    return 0;

}


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

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int my_gcd(int a, int b) {
    if (a < b)
        swap(a, b);
    while (b != 0) {
        a %= b;
        swap(a, b);
    }
    return a;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N) { cin >> A.at(i); }

    vector<int> L(N + 1, 0), R(N + 2, 0);
    REP(i, N) { L[i + 1] = my_gcd(A[i], L[i]); }
    for (int i = N; i > 0; i--) {
        R[i] = my_gcd(R[i + 1], A[i - 1]);
    }
    int ans = 1;
    for (int i = 1; i < N + 1; i++) {
        ans = max(ans, my_gcd(L[i - 1], R[i + 1]));
    }
    cout << ans << "\n";
}

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

int main()
{
	int N,m,n,i,j,l;
	char S[102],a[60],b[60];
	while(cin>>N>>S)
	{
		if(N%2==1){
			cout<<"No"<<endl;
		}
		else 
		{
			l=N/2;
			for(i=0,j=l;i<l;i++,j++)
			{
				if(S[i]!=S[j]){
					cout<<"No"<<endl;
					break;
				}
				else if(i==l-1&&j==N-1){
					if(S[i]==S[j]){
						cout<<"Yes"<<endl;
					}
				}
			}
		}
	}
}

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

struct Node{
	int v, id;
};

const int N = 1e5 + 10;

int a[N];
Node cnt0[N], cnt1[N];

bool cmp(const Node& x, const Node& y){
	return x.v > y.v;
}

int main(){
	int n;
	scanf("%d",&n);
	for (int i = 1; i <= 100000; i++){
		cnt0[i].v = cnt1[i].v = 0;
		cnt0[i].id = cnt1[i].id = i;
	}
	for (int i = 1; i <= n; i++){
		scanf("%d",&a[i]);
		if (i & 1) cnt1[a[i]].v++;
		else cnt0[a[i]].v++;
	}
	sort(cnt0 + 1, cnt0 + 100000 + 1, cmp);
	sort(cnt1 + 1, cnt1 + 100000 + 1, cmp);
	if (cnt0[1].id == cnt1[1].id)
		printf("%d\n", n - max(cnt0[1].v + cnt1[2].v, cnt0[2].v + cnt1[1].v));
	else
		printf("%d\n", n - cnt0[1].v - cnt1[1].v);
	return 0;
}

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

using ll = long long;

#define REP(i,n) for(int i=0; i<n; i++)
#define FOR(i,a,b) for(int i=a; i<b; i++)
#define FORR(i,a,b) for(int i=b-1;i>=a;i--)

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl

#define ALL(v) (v).begin(),(v).end()

int main(){
    while(true){
        string s;
        cin>>s;
        if(s=="#")break;
        vector<string> po[26];
        po[0].push_back(s);
        REP(i,25){
            char to = 'z'-i;
            char fr = 'z'-i-1;
            for(string s : po[i]){
                if(count(ALL(s),to)==0){
                    REP(j,s.size()){
                        if(s[j]==fr){
                            string t = s;
                            t[j] = to;
                            po[i+1].push_back(t);
                        }
                    }
                    po[i+1].push_back(s);
                }else{
                    REP(j,s.size()){
                        if(s[j]==fr){
                            string t = s;
                            t[j] = to;
                            po[i+1].push_back(t);
                        }else if(s[j]==to){
                            break;
                        }
                    }
                }
            }
        }
        printf("%d\n",(int)po[25].size());
        sort(ALL(po[25]));
        if(po[25].size() <= 10){
            REP(i,po[25].size()){
                printf("%s\n",po[25][i].c_str());
            }
        }else{
            REP(i,5)cout<<po[25][i]<<endl;
            REP(i,5)cout<<po[25][po[25].size()-5+i]<<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 7880
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <cmath>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair
#define EPS 1e-8
#define equals(a,b) fabs((a) - (b)) < EPS

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int compress(vector<int>& v, map<int, int>& zip, map<int, int>& unzip) {
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(),v.end()),v.end());

	rep(i, v.size()) {
		zip[v[i]] = i;
		unzip[i] = v[i];
	}

	return v.size();
}

int d[55 * 3][55 * 3][55 * 5];

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

	vector<int> x, y, z;
	vector<int> x1(n), y1(n), z1(n), x2(n), y2(n), z2(n);

	rep(i, n) {
		cin >> x1[i] >> y1[i] >> z1[i] >> x2[i] >> y2[i] >> z2[i];
		x.push_back(x1[i]);
		x.push_back(x2[i]);

		y.push_back(y1[i]);
		y.push_back(y2[i]);

		z.push_back(z1[i]);
		z.push_back(z2[i]);
	}

	map<int, int> xzip, yzip, zzip;
	map<int, int> xunzip, yunzip, zunzip;

	int X = compress(x, xzip, xunzip);
	int Y = compress(y, yzip, yunzip);
	int Z = compress(z, zzip, zunzip);

	memset(d, 0, sizeof(d));

	rep(i, n) {
		REP(j, xzip[x1[i]], xzip[x2[i]]) {
			REP(k, yzip[y1[i]], yzip[y2[i]]) {
				REP(l, zzip[z1[i]], zzip[z2[i]]) {
					d[j][k][l]++;
				}
			}
		}
	}

	ll ans = 0;
	rep(i, X) {
		rep(j, Y) {
			rep(k, Z) {
				if(d[i][j][k] >= K) {
					ans += ll(xunzip[i+1] - xunzip[i]) * ll(yunzip[j+1] - yunzip[j]) * ll(zunzip[k+1] - zunzip[k]);
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 30492
#include <bits/stdc++.h>
#include <string.h>
#define rep(i, n) for(int i = 0; i<(n); i++)
using namespace std;
typedef long long ll;
static const int MAX = 200000; 
//pi = 3.14159265358979323846

int main() {

    int a, b, c;
    cin >> a >> b >> c;
    int mizu = c - (a - b);
    if(c - (a - b ) < 0) mizu = 0;
    cout << mizu << endl;

}




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

int rui(int a, int b) {
    int c = 1;
    rep(i,b) {
        c *= a;
    }
    
    return c;
}

int main() {
    int n, m;
    cin >> n >> m;
    
    vector<int> s(m);
    vector<char> c(m);
    rep(i,m) {
        cin >> s[i] >> c[i];
    }
    
    string ans;
    rep(i,n) {
        ans.push_back('a');
    }
    
    bool tf = true;
    rep(i,m) {
        if(ans[s[i]-1] == 'a' || ans[s[i]-1] == c[i])
            ans[s[i]-1] = c[i];
        else {
            tf = false;
            break;
        }
    }
    
    if(n == 1) {
        if(ans == "a")
            ans = "0";
    }
    else {
        rep(i,n) {
            if(i == 0) {
                if(ans[i] == 'a')
                    ans[i] = '1';
                else if(ans[i] == '0')
                    tf = false;
            }
            else if (ans[i] == 'a'){
                ans[i] = '0';
            }
        }
    }
    
    if(!tf)
        cout << -1 << endl;
    else
        cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,s,g1,g2;
  while(cin>>n>>m>>s>>g1>>g2,n){
    int d[1001][1001]={};
    for(int i=1;i<=n;i++)
      for(int j=1;j<=n;j++)if(i!=j)d[i][j]=1e8;
    for(int i=0,a,b,c;i<m;i++)
      cin>>a>>b>>c,d[a][b]=c;
    for(int i=1;i<=n;i++)
      for(int j=1;j<=n;j++)
	for(int k=1;k<=n;k++)
	  d[j][k]=min(d[j][k],d[j][i]+d[i][k]);
    int ans=1e9;
    for(int i=1;i<=n;i++)ans=min(ans,d[s][i]+d[i][g1]+d[i][g2]);
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 6892
#include<stdio.h>
#include<string.h>
#include<utility>
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)


int main()
{
    int n;
    int max=0;
    int sum=0;
    int l[15]={};
    scanf("%d",&n);
    REP(i,n){
        scanf("%d",&l[i]);
        if(max<l[i])max=l[i];
        sum+=l[i];
    }
    if(sum-max>max)printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long 
#define M 1000000007
#define P pair<int,int>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) FOR(i,0,n)
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265

ll h,w,a,b,fact[210000],inv[210000],ans;

ll c(ll n,ll m){
  return (ll)(fact[n+m-2])*inv[n-1]%M*inv[m-1]%M;
}

int main(){

  cin>>h>>w>>a>>b;
  fact[0]=fact[1]=inv[0]=inv[1]=1;

  FOR(i,2,h+w+1){
    inv[i]=(ll)(M-M/i)*inv[M%i]%M;
  }
  FOR(i,2,h+w+1){
    fact[i]=(ll)(fact[i-1])*i%M;
    inv[i]=(ll)(inv[i-1])*inv[i]%M;
  }
  FOR(i,b+1,w+1){
    ans=(ans+(ll)(c(h-a,(ll)i))*c(a,w-i+1))%M;
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 3328
# ABC172a


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    def dump(*args):
        sys.stderr.write(str(args))

    a = int(input())
    print(a+a**2+a**3)


if __name__ == '__main__':
    main()


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

const ll INF = 1LL<<60;

int main(){
	ll N;
	cin >> N;
	
	ll ans = INF;
	
	for (ll i = 1; i*i <= N; ++i) {
		if(N % i == 0){
			ans = min(ans, N/i + i - 2);
		}
	}
	
	cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define INF (ll)(1e18)
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }


// youtube editorial
// ゾロ目を列挙

void solve() {
    int s;
    cin >> s;
    
    for (int t = 111; t <= 999; t += 111) {
        if (t >= s) {
            cout << t << endl;
            return;
        }
    }
    
}



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int T;
    // cin >> T;
    T = 1;
    
    while (T--) {
        solve();
    }
}




Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
lim = 10**18

if 0 in A:
  print(0)
  exit()

  
ans = 1
A.sort(reverse = True)
for i in range(len(A)):
  ans = ans * A[i] 
  if ans > lim:
    print(-1)
    exit()

if ans > lim:
  print(-1)
else:
  print(ans)

Measured memory_bytes: 21696
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>

using namespace std;
typedef long long ll;

int main()
{
  ll n, m;
  cin >> n >> m;
  
  ll s = min(n, m / 2);
  m -= s * 2;

  s+= m / 4;
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
// ABC118_C
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <tuple>  // std::tuple std::get
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define REPN(i, n) for (ll i=1; i <= n; i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0LL)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)

typedef long long ll;

const ll MOD7 = 1000000007;  // 1 000 000 007
const ll MOD9 = 1000000009;  // 1 000 000 009

template <typename T>
T gcd(T a, T b) {
    if (a <= 0 || b <= 0) {
        // どちらかが 0 以下であれば -1 を返す
        return -1;
    } else if (a == 1 || b == 1) {
        // どちらかが 1 であれば，最小公約数は 1
        return 1;
    } else {
        if (a < b) swap(a, b);
        if (a%b == 0) return b;
        return gcd(b, a%b);
    }
}

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

    // input
    ll N;
    cin >> N;
    vector<ll> vec(N);
    REP(i, N) cin >> vec[i];
    
    // calculation
    sort(vec.begin(), vec.end(), greater<>());  // int big -> small
    ll res, g = vec[0];
    for (ll i = 1; i < N; ++i) {
        g = gcd(g, vec[i]);
    }
    
    cout << g << "\n";
    
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i++)

using namespace std;

const int MOD = 1000000007; // 10^9 + 7
struct mint{int x;mint(int x=0):x((x%MOD+MOD)%MOD){}
mint operator-()const{return mint(-x);}
mint& operator+=(const mint a){if((x+=a.x)>=MOD)x-=MOD;return*this;}
mint& operator-=(const mint a){if((x+=MOD-a.x)>=MOD)x-=MOD;return*this;}
mint& operator*=(const mint a){(x*=a.x)%=MOD;return*this;}
mint operator+(const mint a)const{return mint(*this)+=a;}
mint operator-(const mint a)const{return mint(*this)-=a;}
mint operator*(const mint a)const{return mint(*this)*=a;}
mint pow(int t)const{if(!t)return 1;mint a=pow(t>>1);a*=a;if(t&1)a*=*this;return a;}
mint inv()const{return pow(MOD-2);}
mint& operator/=(const mint a){return*this*=a.inv();}
mint operator/(const mint a)const{return mint(*this)/=a;}};
ostream& operator<<(ostream& os, const mint& a) {return os << a.x;}

/****************************** START ******************************/

signed main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
  
  int n;cin >> n;
  vector<int> a(n);
  rep(i,0,n) cin >> a.at(i);
  
  mint sum = 0,sqsum = 0; // intの代わりにmintを宣言
  
  rep(i,0,n){
    sum += a[i];
    sqsum += a[i]*a[i];
  }
  
  mint ans;
  ans = sum;
  ans *= sum;
  ans -= sqsum;
  ans /= 2;
  
  cout << ans << endl;
  
  return 0;
}

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

int main(){

    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    
    int cnt = 1;
    int next = a[0];
    for(int i=0;i<100000;i++){
        if(next==2){
            cout << cnt << endl;
            return 0;
        }
        next = a[next-1];
        cnt++;
    }
    
    cout << -1 << endl;
    return 0;

}

Measured memory_bytes: 640
x, n = map(int, input().split())
p = set()
if n:
  p = set(map(int, input().split()))
d = 0
while True:
  if x - d not in p:
    ans = x - d
    break
  if x + d not in p:
    ans = x + d
    break
  d += 1
print(ans)

Measured memory_bytes: 9180
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <list>
#include <cctype>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)

locale l = locale::classic();

int main(){
    int a,b;
    cin >> a >>b ;
    if(a>=13) cout << b << endl;
    else if(a>=6) cout << b/2 << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define SZ(i) int(i.size())
#ifdef tmd
#define IOS()
#define debug(...) fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define debug(...)
#endif

const int MAXN = 500005;
const ll MOD = 1000000007;

int a, b, c, d, e, f;

bool bt (pair<int,int> org, pair<int,int> nw) {
    if (org.second == 0) {
        return true;
    }
    return org.first * (nw.second + nw.first) <= (org.second + org.first) * nw.first;
}
/*********************GoodLuck***********************/
int main () {
    IOS();

    cin >> a >> b >> c >> d >> e >> f;

    pair<int,int> ans;
    for (int i=0; i*100*a<=f; i++) {
        for (int j=0; j*100*b+i*100*a<=f; j++) {
            int rem = f - (i*100*a+j*100*b);
            rem = min(rem, (i*a+j*b) * e);
            int lf = rem % (c*d);
            int mx = 0;
            for (int x=0;x*c<=lf; x++) {
                for(int y=0; x*c+y*d<=lf; y++) {
                    mx = max(x*c+y*d, mx);
                }
            }

            pair<int,int> nw = {mx+rem/(c*d)*(c*d), 100*(i*a+j*b)};
            debug(i, j, f, rem, nw.first, nw.second);
            if (bt(ans, nw)) {
                ans = nw;
            }
        }
    }

    cout << ans.second+ans.first << " " << ans.first << endl;
}


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

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);

    long long N, a, b;
    cin >> N >> a >> b;

    if(a % 2 == b % 2)
        cout << (b - a) / 2 << "\n";
    else
    {
        long long ans1 = 0, ans2 = 0;

        ans1 = a - 1 + b - 1 + 1;
        ans2 = N - a + N - b + 1;

        cout << min(ans1 / 2, ans2 / 2) << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
52min 40sec
"""
# グラフの最短経路問題っぽい。
# 光ったボタンを後になってから押すことは、
# 最短経路においてはなさそう。
# 幅優先探索で書けばよさそう。
# よく考えると1回ボタンを押すと、
# 次のボタンが必ず1個だけ光るから、分岐しない。

import queue

N_INF = pow(10, 6)

N = int(input())
a_list = []
for i in range(N):
    a_list.append(int(input())-1)

min_cost_list = [N_INF for i in range(N)]
lightened_botton_queue = queue.Queue()

def press_botton(botton_no):
    now_cost = min_cost_list[botton_no]
    if min_cost_list[a_list[botton_no]] == N_INF:
        min_cost_list[a_list[botton_no]] = now_cost+1
        lightened_botton_queue.put(a_list[botton_no])
    return

def main():
    lightened_botton_queue.put(0)
    min_cost_list[0] = 0
    while not lightened_botton_queue.empty():
        press_botton(lightened_botton_queue.get())
    answer = int()
    if min_cost_list[1] != N_INF:
        answer = min_cost_list[1]
    else:
        answer = -1
    print(answer)

if __name__ == "__main__":
    main()



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

using namespace std;

using i64 = int64_t;

const i64 INF = 1e18 + 7;
const i64 MOD = 1e9 + 7;

struct BIT{
    vector<i64> elm;
    BIT(i64 n) : elm(n + 1, 0){};
    i64 sum(i64 x){
        i64 val = 0;
        for(; x > 0; x -= x & -x)
            val += elm[x];
        return val;
    }
    void add(i64 x, i64 val){
        for(++x; x < elm.size(); x += x & -x)
            elm[x] += val;
    }
};

signed main(){
    i64 n, q;
    cin >> n >> q;
    struct data{
        i64 type, t, p, m;
        // t: 0-indexed
        // m: 1-indexed
        data(i64 t, i64 p) : type(0), t(t), p(p), m(-1){}
        data(i64 m) : type(1), t(-1), p(-1), m(m){}
    };

    vector<data> query;

    vector<i64> poi64s(n, 0);
    set<pair<i64,i64>> v;
    for(i64 i = 0; i < n; ++i)
        v.emplace(0, i);

    for(i64 i = 0; i < q; ++i){
        i64 type;
        cin >> type;
        if(type == 0){
            i64 t, p;
            cin >> t >> p;
            --t;
            p *= -1;
            query.emplace_back(t, p);
            poi64s[t] += p;
            v.emplace(poi64s[t], t);
        }else{
            i64 m;
            cin >> m;
            query.emplace_back(m);
        }
    }
    poi64s.assign(n, 0);
    BIT bit(v.size());

    map<pair<i64,i64>,i64> ma;
    i64 cnt = 0;
    vector<pair<i64,i64>> v2;
    for(auto& x : v){
        v2.emplace_back(x);
        ma[x] = cnt++;
    }

    for(i64 i = 0; i < n; ++i)
        bit.add(ma[make_pair(0, i)], 1);
    for(auto& d : query){
        if(d.type == 0){
            bit.add(ma[make_pair(poi64s[d.t], d.t)], -1);
            poi64s[d.t] += d.p;
            bit.add(ma[make_pair(poi64s[d.t], d.t)], 1);
        }else{
            i64 ng = 0, ok = v.size();
            while(abs(ng - ok) > 1){
                i64 mid = (ok + ng) >> 1;
                (bit.sum(mid) >= d.m ? ok : ng) = mid;
            }
            i64 idx = ng;
            auto p = v2[idx];
            cout << p.second + 1 << " " << -1 * p.first << endl;
        }
    }
}



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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve() {
  int x;
  cin >> x;
  rep(f, 20) {
    rep(e, 25) {
      rep(d, 100) {
        rep(c, 50) {
          rep(b, 100) {
            int r = x;
            r -= 105 * f;
            r -= 104 * e;
            r -= 103 * d;
            r -= 102 * c;
            r -= 101 * b;
            if (r < 0) continue;
            if (r % 100 == 0) {
              cout << 1 << endl;
              return;
            }
          }
        }
      }
    }
  }
  cout << 0 << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int k= 1;
        HashMap<String,Integer> hashMap = new HashMap<>();
        hashMap.put("SUN",7);
        hashMap.put("MON",6);
        hashMap.put("TUE",5);
        hashMap.put("WED",4);
        hashMap.put("THU",3);
        hashMap.put("FRI",2);
        hashMap.put("SAT",1);
        String s1;
        String s2;
        int a,b;
        double n;
        while(k-->0){
            a=s.nextInt();
            b=s.nextInt();
            System.out.println(Math.max(a*b,Math.max(a+b,a-b)));
        }
    }

    private static int binary_search(
            int arr[], int l,
            int h, int x)
    {
        while (l <= h) {
            int mid = (l + h) / 2;
            if (arr[mid] <= x)
                l = mid + 1;
            else
                h = mid - 1;
        }
        return h;
    }
    static int gcd(int a, int b)
    {
        if(b==0) {
            return a;
        }
        return gcd(b,a%b);
    }
    private static boolean isPrime(int n) {
        if (n == 2)
            return true;
        else if ((n % 2 == 0 && n > 2) || n < 2)
            return false;
        else {
            for (int i = 3; i <= (int) Math.sqrt(n); i += 2) {
                if (n % i == 0)
                    return false;
            }
            return true;
        }


    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}

Measured memory_bytes: 27036
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;



signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<vector<P> > d(n);
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        d[i].resize(a);
        for(int j = 0; j < a; j++){
            cin >> d[i][j].first >> d[i][j].second;
            d[i][j].first--;
        }
    }
    int ans = 0;
    for(int mask = 0; mask < (1LL << n); mask++){
        bool f = true;
        for(int i = 0; i < n; i++){
            if(mask & (1LL << i)){
                for(auto j : d[i]){
                    if(!!(mask & (1LL << j.first)) != j.second){
                        f = false;
                        i = n;
                        break;
                    }
                }
            }
        }
        int num = __builtin_popcountll(mask);
        if(f){
            ans = max(ans, num);
        }
    }
    cout << ans << endl;
}

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

int n,n2,m1,m2,m;
char s[MAXN];
int p1[MAXN],p2[MAXN],id[MAXN];
int s1[MAXN];
int a[MAXN],b[MAXN];
int h[MAXN][MAXN],len[MAXN];
int ans[MAXN];
bool visit[MAXN];

int getS1(int l,int r){ return s1[r]-s1[l-1]; }
int getS2(int l,int r){ return r-l+1-s1[r]+s1[l-1]; }

bool cmp(int x,int y){
	for(int i=1;i<=len[x] && i<=len[y];i++)
		if(h[x][i]^h[y][i]) return h[x][i]<h[y][i];
	return len[x]<len[y];
}

int main(){
#ifdef DEBUG
	freopen("E.in","r",stdin);
#endif
	scanf("%d",&n);
	scanf("%s",s+1);
	n2=n<<1;
	for(int i=1;i<=n2;i++)
		if(s[i]=='a') p1[++m1]=i,id[i]=m1;
		else p2[++m2]=i,id[i]=m2;
	for(int i=1;i<=n2;i++) s1[i]=s1[i-1]+(s[i]=='a'?1:0);
	for(int i=1;i<=n;i++)
		if(p2[i]<p1[i])
			a[p2[i]]=getS2(p2[i],p1[i]);
	bool flag=0;
	int last=n2+1,lastp=n2+1;
	for(int i=n2;i>=1;i--)
		if(getS1(i,n2)==getS2(i,n2)){
			if(s[i]=='b'){
				flag=1;
				len[last]=m;
				for(int j=1;j<=m;j++) h[last][j]=b[m-j+1];
				for(int j=last-1;j>=i;j--)
					if(s[j]=='b'){
						for(int k=j;k<last;k++)
							if(s[k]=='b')
								h[j][++len[j]]=a[k];
						for(int k=m;k>=1;k--)
							h[j][++len[j]]=b[k];
					}
				int res=last;
				for(int j=i;j<last;j++)
					if(s[j]=='b' && cmp(res,j))
						res=j;
				for(int j=last-1;j>=res;j--)
					if(s[j]=='b'){
						b[++m]=a[j];
						ans[m]=id[j];
					}
			}else{
				if(!flag) lastp=i;
			}
			last=i;
		}
	for(int i=1;i<=m;i++) visit[p1[ans[i]]]=visit[p2[ans[i]]]=1;
	for(int i=1;i<=n2;i++) if(visit[i]) putchar(s[i]);
	int j=lastp-1;
	for(int i=lastp;i<=n2;i++)
		if(s[i]=='a' && i>j){
			putchar('a'); putchar('b');
			j=p2[id[i]];
		}
}


Measured memory_bytes: 138496
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#define endl "\n"
using namespace std;

int main()
{

  char c;
  scanf("%s", &c);
  if (c == 97 || c == 105 || c == 117 || c == 101 || c == 111)
  {
    printf("%s\n", "vowel");
  }
  else
  {
    printf("%s\n", "consonant");
  }
  return 0;
}


Measured memory_bytes: 256
N = [int(i) for i in input()]

dp = [0, float('inf')]
# dp = [桁上げしてない, 桁上げあった]
for n in N :
  ndp = [0] * 2
  ndp[0] = min(dp[0] + n, dp[1] + n)
  ndp[1] = min(dp[0] + 11 - n, dp[1] + 9 - n)
  dp = ndp

print(min(dp[0], dp[1]))

Measured memory_bytes: 117284
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#define rep(i,n) for (int i=0;i<(n);i++)

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	int ans = 0;
	if (n >= 2)ans += n * (n - 1) / 2;
	if (m >= 2)ans += m * (m - 1) / 2;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3648