akhauriyash/Code-Regression huggingface dataset:
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Contest.D
{
	class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			Scanner cin = new Scanner();

			int n = cin.nextInt();
			var a = new List<int>(cin.ArrayInt(n));
			int maxa = a.Max();
			int mina = a.Min();
			var q = new Queue<pair<int, int>>();

			if (maxa > 0 && mina < 0)
			{
				if (maxa >= (-1) * mina)
				{
					int index = a.IndexOf(maxa);
					for (int i = 0; i < n; i++)
					{
						if (i != index) q.Enqueue(make_pair(index + 1, i + 1));
					}
					mina = 0;
				}
				else
				{
					int index = a.IndexOf(mina);
					for (int i = 0; i < n; i++)
					{
						if (i != index) q.Enqueue(make_pair(index + 1, i + 1));
					}
					maxa = 0;
				}
			}
			if (maxa > 0)
			{
				for (int i = 0; i < n - 1; i++)
				{
					q.Enqueue(make_pair(i + 1, i + 1 + 1));
				}
			}
			else
			{
				for (int i = n - 1; i > 0; i--)
				{
					q.Enqueue(make_pair(i + 1, i - 1 + 1));
				}
			}

			Console.WriteLine(q.Count);
			foreach (var item in q)
			{
				Console.WriteLine(item.ToString());
			}

			Console.Out.Flush();
		}

		public static pair<T, U> make_pair<T, U>(T v1, U v2) where T : IComparable<T> where U : IComparable<U> => new pair<T, U>(v1, v2);
	}

	class pair<T, U> : IComparable<pair<T, U>> where T : IComparable<T> where U : IComparable<U>
	{
		public T v1;
		public U v2;
		public pair(T v1, U v2)
		{
			this.v1 = v1;
			this.v2 = v2;
		}
		public int CompareTo(pair<T, U> a) => v1.CompareTo(a.v1) != 0 ? v1.CompareTo(a.v1) : v2.CompareTo(a.v2);
		public override string ToString() => v1 + " " + v2;
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return next();
			i = 0;
			return s[i++];
		}

		public int nextInt()
		{
			return int.Parse(next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = nextInt() + add;
			}
			return Array;
		}

		public long nextLong()
		{
			return long.Parse(next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = nextLong() + add;
			}
			return Array;
		}

		public double nextDouble()
		{
			return double.Parse(next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = nextDouble() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 13524
#include <bits/stdc++.h>
using namespace std;
//T+N
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod || x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

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

struct Frac {
    ll a, b;
    Frac() {}
    Frac(ll _a, ll _b) {
        a = _a;
        b = _b;
        ll g = gcd(abs(a), abs(b));
        a /= g;
        b /= g;
        if(b < 0) {
            a *= -1;
            b *= -1;
        }
    }
    bool operator <(const Frac &other) const {
        if(a == other.a) {
            return b < other.b;
        }
        return a < other.a;
    }
    bool operator ==(const Frac &other) const {
        return a == other.a && b == other.b;
    }
    bool operator !=(const Frac &other) const {
        return a != other.a || b != other.b;
    }
};

map<Frac, ll> cnt;

ll fpow(ll x, ll p) {
    if(p == 0) {return 1;}
    ll ans = fpow(x, p / 2ll);
    ans = (ans * ans) % mod;
    if(p & 1) {
        return (ans * x) % mod;
    } else {
        return ans;
    }
}

const ll MAX_N = 2e5 + 10;
Frac arr[MAX_N];

Frac inv(Frac a) {
    return Frac(-a.b, a.a);
}

ll cnt1, cnt2;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll n;
    cin >> n;
    int bcnt = 0;
    ll cnta = 0, cntb = 0;
    ll fake = 0;
    for(ll i = 0; i < n; i ++) {
        ll a, b;
        cin >> a >> b;
        if(a == b && b == 0) {fake ++; continue;}
        if(a == 0) {
            cnta ++;
        } else if(b == 0) {
            cntb ++;
        } else {
            arr[bcnt ++] = Frac(a, b);
            cnt[arr[bcnt - 1]] ++;
        }
    }
    ll ans = 1;
    sort(arr, arr + bcnt);
    for(ll i = 0; i < bcnt; i ++) {
        assert(arr[i].a != 0 && arr[i].b != 0);
        assert(arr[i] != inv(arr[i]));
        if(i == 0 || arr[i] != arr[i - 1]) {
            ll now = fpow(2, cnt[arr[i]]) + fpow(2, cnt[inv(arr[i])]) - 1;
            fix(now);
            cnt[arr[i]] = 0;
            cnt[inv(arr[i])] = 0;
            ans = (ans * now) % mod;

            fix(ans);
        }
    }
    ll now = fpow(2, cnta) + fpow(2, cntb) - 1;
    fix(now);
    ans = (ans * now);
    fix(ans);
    ans --;
    fix(ans);
    ans += fake;
    fix(ans);
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 31744
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>
#include<unordered_map>
#define P pair<int,int>
using namespace std;

int a;
int l;
P b[100];
int d[93][40320];
vector<int>V;
bool e[8];
int sum;
bool S;
unordered_map<int, int>U;
int memo[40320][8];
int Hash(vector<int>c) {
	int e = 0;
	int f = 1;
	for (int d = 0; d < 8; d++, f *= 10) {
		e += c[d] * f;
	}
	return e;
}
void R() {
	for (int i = 0; i<8; i++) {
		int JJJ = 0;
		vector<int>o;
		for (int w = 0; w<8; w++) {
			if (V[w] != 0) { o.push_back(V[w] - 1); }
		}
		vector<int>copy;
		for (int x = 0; x<i; x++) {
			copy.push_back(o[x]);
			if (7 - o[x] <= b[l + 1 + o[x]].first) {
				JJJ += b[l + 1 + o[x]].second;
			}
		}
		copy.push_back(7);
		P t = b[l + 8];
		int q = b[l + 8].first, w = b[l + 8].second;
		for (int y = i; y<7; y++) {
			copy.push_back(o[y]);
			if (7 - o[y] <= q) {
				JJJ += w;
			}
		}
		if (l == 0) {
			int z = U[Hash(copy)];
			d[l + 1][z] = max(d[l + 1][z], JJJ + d[l][sum]);
			memo[sum][i] = z;
		}
		else {
			int z = memo[sum][i];
			d[l + 1][z] = max(d[l + 1][z], JJJ + d[l][sum]);
		}
	}
}
void K() {
	int h = 0;
	U[Hash(V)] = sum;
	for (int i = 0; i< 7; i++) {
		for (int j = i + 1; j<8; j++) {
			if (abs(V[i] - V[j]) <= b[V[i]].first) {
				h += b[V[i]].second;
			}
		}
	}
	d[0][sum] = h;
}
void saiki(int f) {
	if (f == 8) {
		if (S) { R(); }
		else { K(); }
		sum++;
	}
	else {
		for (int i = 0; i<8; i++) {
			if (!e[i]) {
				V.push_back(i);
				e[i] = true;
				saiki(f + 1);
				e[i] = false;
				V.pop_back();
			}
		}
	}
}
signed main() {
	cin >> a;
	for (int c = 0; c<a; c++) {
		scanf("%d", &b[c].first);
	}
	for (int c = 0; c<a; c++) {
		scanf("%d", &b[c].second);
	}
	saiki(0);
	S = true;
	for (; l<a - 8; l++) {
		sum = 0;
		saiki(0);
	}
	int MAX = 0;
	for (int kk = 0; kk<40320; kk++) {
		MAX = max(MAX, d[max(a - 8, 0)][kk]);
	}
	cout << MAX << endl;
}

Measured memory_bytes: 20648
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
 
int main(int argc, const char * argv[]) {
     
    double r;
    cin >> r;
     
    printf("%.5f %.5f",M_PI * r * r,2 * M_PI * r);
     
    return 0;
}

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

int main(){
    int K,S;
    cin >> K >> S;
    int count;

    count=0;
    for(int i=0; i<=K; i++){
        if( i+2*K < S ){
            continue;
        }
        for(int j=i; j<=K; j++){
            if( i+j+K < S){
                continue;
            }
            for(int k=j; k<=K; k++){
                if( i+j+k == S){
                    //cout << "i j k = " << i << " " << j << " " << k << endl;
                    if( i==j && i==k ){
                        count=count+1;
                    }else if( (i!=j && j==k ) || (i==j && j!=k ) ){
                        count=count+3;
                    }else{
                        count=count+6;
                    }
                    break;
                }
            }
        }
    }

    cout << count << endl;


    return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> P;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
	ll cost;
};
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 2.0 * asin(1.0);
const ll INF = 1L<<60;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = 10000000;
/****** define constant end ********/
/****** define variable start ******/
ll n;
vl a;
/******* define variable end *******/
int solve() {
	cin >> n;
	a.resize(n);
	ll total = 0;
	REP(i, n){
		cin >> a[i];
		total^=a[i];
	}
	REP(i, n){
		ll ans = total^a[i];
		cout << ans << " ";
	}
	cout << endl;
	return 0;
}

int main() {
	//clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


Measured memory_bytes: 4696
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  int ans = 0;
  for (int i = a; i <= b; i++) {
    int s = i % 10, t = i / 10 % 10, u = i / 1000 % 10, v = i / 10000;
    if (s == v && t == u) ans ++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    v = [int(_) for _ in input().split()]
    sort_v = sorted(v)

    while len(sort_v) > 1:
        temp_a = sort_v[0]
        temp_b = sort_v[1]
        sort_v.pop(0)
        sort_v[0] = (temp_a + temp_b)/2
        sort_v = sorted(sort_v)

    print(sort_v[0])


if __name__ == "__main__":
    main()


Measured memory_bytes: 61900
#include<iostream>
using namespace std;
int main()
{
    int k,s;
    cin >> k >> s;
    int icount = 0;
    for(int x = 0;x <= k;x++)
    {
        for(int y=0;y<=k;y++)
        {
            int z = s - x - y;
            if((0 <= z) && (z <= k))
            {
                icount++;
            }
        }
    }
    cout << icount << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll ans=0;
int n,x,y,z;
struct node
{ll a,b,c;
}p[100005],q[100005],nt[100005];
inline bool cmp1(node a,node b)
{return a.b-a.a>b.b-b.a;}
multiset <pair<ll,int> > q1,q2,q3;
int main (){
	int i,j;
	scanf ("%d%d%d",&x,&y,&z);
	n=x+y+z;
	for (i=1;i<=n;i++)
	{scanf ("%lld%lld%lld",&p[i].a,&p[i].b,&p[i].c);
	ans+=p[i].a;
	}
	sort(p+1,p+n+1,cmp1);
	for (i=1;i<=y;i++) 
	{ans+=p[i].b-p[i].a;
	q1.insert(make_pair(p[i].c-p[i].b,i));
	}
	for (i=y+1;i<=n;i++)
	{q2.insert(make_pair(p[i].b-p[i].a,i));
	q3.insert(make_pair(p[i].c-p[i].a,i));
	}
	for (i=1;i<=z;i++)
	{ll tp1,tp2;
	tp1=((*q1.rbegin()).first)+((*q2.rbegin()).first);
	tp2=((*q3.rbegin()).first);
	if (tp1>=tp2)
	{ans+=tp1;
	int pos=(*q2.rbegin()).second;
	q1.insert(make_pair(p[pos].c-p[pos].b,pos));
	q3.erase(q3.lower_bound(make_pair(p[pos].c-p[pos].a,pos)));
	q1.erase(q1.lower_bound(*q1.rbegin()));
	q2.erase(q2.lower_bound(*q2.rbegin()));
	}
	else 
	{ans+=tp2;
	int pos=(*q3.rbegin()).second;
	q3.erase(q3.lower_bound(*q3.rbegin()));
	q2.erase(q2.lower_bound(make_pair(p[pos].b-p[pos].a,pos)));
	}
	}
	printf ("%lld\n",ans);
	return 0;
}
	
	

Measured memory_bytes: 15616
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INI(n) scanf("%d",&n)
#define INL(n) scanf("%lld",&n)
#define INS(s) scanf("%s",s)
#define INF 10000000000
#define mod 1000000007
#define X 1000000
typedef long long int ll;
ll finv[X];
ll fac[X];
ll inv[X];
ll usort(const void *a, const void *b){return *(ll*)a-*(ll*)b;}
ll dsort(const void *a, const void *b){return *(ll*)b-*(ll*)a;}
ll ssort(const void *a, const void *b){return strcmp((char*)a,(char*)b);}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll z(ll a){return max(a,-a);}
ll gcd(ll a,ll b){if(!b){return a;}else{return gcd(b,a%b);}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll kt(ll a){
  if(!a)return 1;
  ll sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
ll ks(ll a){
  ll sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
void nCrReady(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for (int i=2;i<X;i++){
    fac[i]=fac[i-1]*i%mod;
    inv[i]=mod-inv[mod%i]*(mod/i)%mod;
    finv[i]=finv[i-1]*inv[i]%mod;
  }
}
ll nCr(ll n,ll k){return fac[n]*(finv[k]*finv[n-k]%mod)%mod;}
ll modpow(ll a,ll b) {
  ll ret=1;
  for(;b>0;b>>=1,a=(ll)a*a%mod)if(b%2==1)ret=ret*a%mod;
  return ret;
}

int b[9];
int main(void){
  int n,m;
  INI(n);
  INI(m);
  int s,c;
  int x[n];
  FOR(n)x[i]=-1;
  FOR(m){
    INI(s);
    s--;
    INI(c);
    if(x[s]!=-1&&x[s]!=c){
      PRN(-1);
      return 0;
    }
    x[s]=c;
  }
  int ans=0;
  FOR(n){
    ans*=10;
    if(x[i]!=-1)ans+=x[i];
  }
  if(kt(ans)!=n){
    if(x[0]==-1){
      PRN((int)pow(10,n-1)+ans);
      return 0;
    }
    PRN(-1);
    return 0;
  }
  PRN(ans);
  return 0;
}

Measured memory_bytes: 128
#include<queue>
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn=222222;
const int mod=1000000007;
int N,dp[maxn],g[maxn];
int read()
{
	int s=0,c=getchar(),f=1;
	while(c<48||c>57)
	{
		if(c==45) f=-1;
		c=getchar();
	}
	while(c>=48&&c<=57) s=(s<<3)+(s<<1)+(c^48),c=getchar();
	return s*f;
} 
void write(int x)
{
	if(x>=10) write(x/10);
	putchar(x%10+48);
}
void W(int x)
{
	if(x<0) x=-x,putchar(45);
	write(x);
}
int main()
{
	N=read();
	dp[0]=1;
	int b=0;
	for(int i=1;i<=N;++i)
	{
		int a=read();
		if(a!=b)
		{
			g[a]+=dp[i-1];
			if(g[a]>=mod) g[a]-=mod;
		}
		dp[i]=g[a];
		b=a;
	}
	write(dp[N]);
	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main()
{
    int n,i;
    scanf("%d",&n);
    int arr[n];

    for(i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
    }
    for(i=n-1;i>=0;i--)
    {   if(i==0){printf("%d",arr[i]);}
        else printf("%d ",arr[i]);
    }
    printf("\n");

    return 0;
}



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

// 小数点以下桁数
// fixed << setprecision(i)

int64_t gcd(int64_t a,int64_t b){return (a%b==0?b:gcd(b, a%b));}
int64_t lcm(int64_t a,int64_t b){return a/gcd(a, b)*b;}
int factorial(int a){int b=1;while(a){b*=a--;}return b;} //13以下対応
bool is_prime(int a){if(a<=1)return false;for(int i=2;(int64_t)i*i<=a;i++){if(a%i==0)return false;}return true;}
int get_adp(double x, int n){return (int)round((x-(int)x)*pow(10,n))%10;} // 小数点以下の指定桁の値を取得
int64_t sigma(int64_t s, int64_t n){return n*(2*s+n-1)/2;}

//順列の全列挙
// vector<int> v(N);
// iota(v.begin(), v.end(), 1);       // v に 1, 2, ... N を設定
// do {
//	for(auto x : v) cout << x << " "; cout << "\n";     // v の要素を表示
// } while( next_permutation(v.begin(), v.end()) ); 

//bit全探索
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//	bitset<ビット数> s(tmp);
//	// (ビット列sに対する処理)
// }

int main()
{
	int x, ans = 1, tmp = 1;
	// queue<pair<int, int>> q;

	cin >> x;
	while (1)
	{
		if (x <= tmp)
			break;
		ans++;
		tmp += ans;
	}
	cout << ans << endl;
	// q.push(make_pair(0, 0));
	// while (!q.empty())
	// {
	// 	int tmp = q.front().first;
	// 	int c = q.front().second + 1;
	// 	if (tmp + c == x || tmp - c == x)
	// 		break;
	// 	q.pop();
	// 	q.push(make_pair(tmp + c, c));
	// 	q.push(make_pair(tmp, c));
	// 	if (tmp - c >= 0)
	// 		q.push(make_pair(tmp - c, c));
	// }
	// cout << q.front().second + 1 << endl;
}


Measured memory_bytes: 3644
#include<stdio.h>
int main(void){
	int i,j,a,b;
	while(1){
		scanf("%d %d",&a,&b);
		if(a == 0 && b == 0){
					break;
				}
		for(i = 0;i < a;i++){
			for(j = 0;j < b;j++){
				if((i+j)%2 == 1){ 
					printf(".");
				}else{
					printf("#");
			}
		
			}printf("\n");
	}
		printf("\n");
	}
	return 0;
}

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

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	vector<int> vi;

	for(int i = 0; i < n; ++i) {
		int t;
		cin >> t;
		vi.push_back(t);
	}

	int lo = 0, hi = 1000000000;
	while(lo != hi) {
		int mi = (lo + hi) / 2;
		long long int todo = 0;
		for(int i = 0; i < n; ++i) 
			if((long long int)b*mi < vi[i]) 
				todo += ((vi[i] - b * mi - 1) / (a-b)) + 1; // how much extra attack we need for following monster

		if(todo <= mi)
			hi = mi;
		else
			lo = mi + 1;
	}	

	cout << lo << endl;
	

	return 0;
}

Measured memory_bytes: 892
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

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

    int count = 0;
    for(int i = 0; i < s.size()/2 ; i++){
        if(s[i] != s[s.size()-i-1]){
            count++;
        }
    }

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

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll N; cin >> N;
    vector<ll> A(N);
    for(auto& in:A){ cin >> in; in = abs(in);}
    ll odd_cnt,even_cnt;
    odd_cnt = even_cnt = 0;
    for(auto a:A){
        if(a%2 == 0){
            even_cnt++;
        }else{
            odd_cnt++;
        }
    }
    if(odd_cnt%2 == 1){
        cout << "NO" << endl;
        return 0;
    }
    cout << "YES" << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int N;
  scanf("%d", &N);
  vector<int> C(N, 0), S(N, 0), F(N, 0);
  vector<int> ans(N, 0);
  for (int i = 0; i < N - 1; ++i) {
    scanf("%d %d %d", &C[i], &S[i], &F[i]);
  }

  for (int start = 0; start < N - 1; ++start) {
    int now = S[start] + C[start];
    for (int cur = start + 1; cur < N - 1; ++cur) {
      if (now >= S[cur]) {
        int wait = 0;
        // trains are running
        if (now % F[cur] != 0) { wait = F[cur] - (now % F[cur]); }
        now += wait + C[cur];
      }
      else {
        // trains are not running
        now += (S[cur] - now) + C[cur];
      }
    }
    ans[start] = now;
  }
  for (int i = 0; i < N; ++i) {
    printf("%d\n", ans[i]);
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N), S(N+1);
    rep(i,N){
        cin >> A[i];
    }
    rep(i,N){
        S[i+1] = S[i] + A[i];
    }
    map<ll,ll> mp;
    rep(i,N){
        mp[S[i+1]]++;
    }
    ll sum = 0;
    for(auto& e:mp){
        sum += e.second*(e.second-1)/2;
    }
    sum += mp[0];
    cout << sum << endl; 
}


Measured memory_bytes: 15872
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    static class CLowElements
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var pList = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
                        
            int successCount = 0;
            int min = pList[0];
            for (int i = 0; i < pList.Count; i++)
            {
                if (pList[i] <= min)
                {
                    successCount++;
                    min = pList[i];
                }                
            }

            Console.WriteLine(successCount);
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 35548
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())

#define pb emplace_back
#define fi first
#define se second

using namespace std;

using ld = long double;
using ll = long long int;

const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> void UNIQUE(vector<T> &a){ a.erase(unique(a.begin(), a.end()), a.end()); }

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

ll in(){long long int x; assert(scanf("%lld", &x) == 1); return x;}
ld fin(){double x; assert(scanf("%lf", &x) == 1); return x;}
char yuyushiki[1000010]; string stin(){assert(scanf("%s", yuyushiki) == 1); return yuyushiki;}

// head

int main(){

  int n = in();
  vector<vector<int>> a(n, vector<int>(3));
  REP(i, n){
    REP(j, 3){
      a[i][j] = in();
    }
  }
  vector<vector<int>> dp(n + 1, vector<int>(3, -INF));
  REP(j, 3){
    dp[0][j] = 0;
  }
  REP(i, n){
    REP(j, 3){
      REP(k, 3){
        if(j != k){
          chmax(dp[i+1][k], dp[i][j] + a[i][k]);
        }
      }
    }
  }
  int ans = -INF;
  REP(j, 3){
    chmax(ans, dp[n][j]);
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define pq priority_queue
#define mp make_pair
#define cauto const auto &

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#define clr(ar, val) memset(ar, val, sizeof(ar))

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

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

using namespace std;

typedef long long int64;
typedef long long lint;
typedef long long lli;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;

int n, x, mx1, mx2, x1, x2;
int cnt1[100003], cnt2[100003];
int main() {
    cin >> n;
    REP(i, n) {
        cin >> x;
        if (i % 2 == 0) {
            cnt1[x]++;
            if (cnt1[x] > mx1) {
                mx1 = cnt1[x];
                x1 = x;
            }
        } else {
            cnt2[x]++;
            if (cnt2[x] > mx2) {
                mx2 = cnt2[x];
                x2 = x;
            }
        }
    }

    sort(cnt1, cnt1 + 100003);
    sort(cnt2, cnt2 + 100003);

    if (x1 == x2)
        cout << n - max(mx1 + cnt2[100001], mx2 + cnt1[100001]) << endl;
    else
        cout << n - mx1 - mx2 << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <cstdio>

int main() {
  int n;
  while (scanf("%d", &n) != EOF && n) {
    char C[200];
    for (auto i=0; i<200; i++) {
      C[i] = (char)i;
    }
    for (auto i=0; i<n; i++) {
      char a, b;
      scanf(" %c %c", &a, &b);
      C[(int)a] = b;
    }
    int m;
    scanf("%d", &m);
    for (auto j=0; j<m; j++) {
      char d;
      scanf(" %c", &d);
      printf("%c", C[(int)d]);
    }
    printf("\n");
  }
}

Measured memory_bytes: 992
n,k = gets.split.map(&:to_i)
s = gets.chomp

count = 0
(n-1).times do |i|
  count += 1 if s[i] == s[i+1]
end

if (n - 1 - count) / 2 >= k
  count += 2 * k
else
  count += n - 1 - count
end

puts count

Measured memory_bytes: 1916
l = [ 2,3,4,5,6,7,8,9,10,11,12,13,1 ]
n = input().split()
m = list(map(int,n))
a = l.index(m[0])
b = l.index(m[1])
if int(a) < int(b):
  print("Bob")
elif int(a) > int(b):
  print("Alice")
else:
  print("Draw")

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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

void solve() {
    int n, x;
    cin >> n >> x;

    int m[n];
    rep(0, n) cin >> m[i];

    int sum = accumulate(m, m+n, 0);
    sort(m, m+n);

    int cnt = n;
    x -= sum;
    while (m[0] <= x) {
        cnt++;
        x -= m[0];
    }

    cout << cnt << endl;
}

int main() {
    solve();

    return 0;
}


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

int main(){

    string s;
    cin >> s;
    int x, y;
    cin >> x >> y;

    int count_f = 0, count_t = 0;
    vector<int> dx, dy;
    for(int i = 0; i < s.length(); i++){
        if(s[i] == 'F'){
            count_f++;
        }else{
            if(count_t % 2 == 0){
                dx.push_back(count_f);
            }else{
                dy.push_back(count_f);
            }
            count_t++;
            count_f = 0;
        }
    }

    if(count_f > 0){
        if(count_t % 2 == 0){
            dx.push_back(count_f);
        }else{
            dy.push_back(count_f);
        }
    }

    vector<vector<bool>> dpx(dx.size() + 1, vector<bool>(2 * s.length() + 1, false));
    dpx[1][s.length() + dx[0]] = true;
    for(int i = 1; i < dx.size(); i++){
        for(int j = 0; j < 2 * s.length() + 1; j++){
            if(dpx[i][j]){
                dpx[i + 1][j + dx[i]] = true;
                dpx[i + 1][j - dx[i]] = true;
            }
        }
    }

    vector<vector<bool>> dpy(dy.size() + 1, vector<bool>(2 * s.length() + 1, false));
    dpy[0][s.length()] = true;
    for(int i = 0; i < dy.size(); i++){
        for(int j = 0; j < 2 * s.length() + 1; j++){
            if(dpy[i][j]){
                dpy[i + 1][j + dy[i]] = true;
                dpy[i + 1][j - dy[i]] = true;
            }
        }
    }

    if(dpx[dx.size()][x + s.length()] && dpy[dy.size()][y + s.length()]) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 16128
#include<bits/stdc++.h>
using namespace std;
 typedef long long ll;
int main() {
	ll ans=1;
	set<int>s;
	set<int>::iterator it;
	int n;
	cin>>n;
	int a[n+3];
	map<int,int>m;
	for(int i=0;i<n;i++)
	{
	  cin>>a[i];
	  m[a[i]]++;
	}
	sort(a,a+n,greater<int>());
	for(int i=0;i<n;i++)
	{
		if(m[a[i]]>=4)
		{
			s.insert(a[i]);
			if(s.size()==2)
			{
			 for(it=s.begin();it!=s.end();it++)
			 ans=ans*(*it);
			 cout<<ans;
			 return 0;
			}
			else
			{
			  cout<<1LL*a[i]*a[i];
			  return 0;
			}
		}
		if(m[a[i]]>=2)
		{
			s.insert(a[i]);
			if(s.size()==2)
			{
			 for(it=s.begin();it!=s.end();it++)
			 ans=ans*(*it);
			 cout<<ans;
			 return 0;
			}
	    }
	}
	cout<<"0";
	return 0;
}

Measured memory_bytes: 5376
//  Copyright © 2020 Diego Garcia Rodriguez del Campo. All rights reserved.
#include<bits/stdc++.h>
#define MAX 200005
#define optimiza_io cin.tie(0); ios_base::sync_with_stdio(0);
#define what_is(x) cerr << #x << " is " << x << endl;
#define pii pair < int , int >
#define fi first
#define se second
using namespace std;
typedef long long ll;

string s;

int main()
{
    optimiza_io
    cin >> s;
    for(auto x : s)
        cout << (x == 'P' ? 'P' : 'D');
    cout << "\n";
    return 0;
}

// CHECAR LIMITES 

Measured memory_bytes: 3772
// Problem : D - Div Game
// Contest : AtCoder - AtCoder Beginner Contest 169
// URL : https://atcoder.jp/contests/abc169/tasks/abc169_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

// Mere bas ka nahi hai
// still i'm trying
// apna time aayega
//
//        .--------------.  
//        | Try First One|
//        '--------------'
//                |     .--------------.
//                |     |              |
//                V     V              |
//              .--------------.       |
//              |      AC.     |<---.  |  
//              '--------------'    |  |
//              (True)|  |(False)   |  |
//           .--------'  |          |  |
//           |           V          |  |
//           |  .--------------.    |  |
//           |  |   Try Again  |----'  |
//           |  '--------------'       |
//           |                         |
//           |  .--------------.       |
//           '->| Try Next One |-------'
//              '--------------'                          		  
//
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll power(ll x,ll y,ll m){if(y==0)return 1;ll p=power(x,y/2,m)%m;p=(p*p)%m;return (y%2==0)?p:(x*p)%m;}
ll nCr(ll n,ll r,ll m){if(r>n)return 0;ll a=1,b=1,i;for(i=0;i<r;i++){a=(a*n)%m;--n;}while(r){b=(b*r)%m;--r;}return (a*power(b,m-2,m))%m;}
#define Test int t;cin>>t;while(t--)
#define endl '\n'
void solve()
{
	ll n;
	cin >> n;
	int cnt=0;
	ll a=n;
	if(n==1)
	{
		cout << 0 << endl;
		return;
	}
	for(ll i=2;i*i<=a;++i)
	{
		int c=0;
		while(n%i==0)
		{
			c++;
			n=n/i;
		}
		int temp=1;
		while(1)
		{
			if(c>=temp)
			{
				c-=temp;
				cnt++;
				temp++;
			}
			else
			{
				break;
			}
		}
	}
	//if(n==a)
	//cnt++;
	if(n!=1)
	cnt++;
	cout << cnt << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//Test
	solve();
	return 0;
}


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

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

int main() {
	int a, b;
	cin >> a >> b;
	if (a <= 8 && b <= 8)cout << "Yay!" << endl;
	else cout << ":("<< endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int i,j,n,m,c,d,a,b,e,k;
map<int,int> ans;
int main(){
  for(cin>>n>>m;i<m;i++){
    cin>>b>>c;
    if(b>n)return cout<<-1,0;
    if(n!=1&&b==1&&c==0)return cout<<-1,0;
    if(ans[b]==0||ans[b]==c)ans[b]=c;
    else return cout<<-1, 0;
  }
  if(n==3){
    if(ans[1]==0)ans[1]=1;
    cout<<ans[1]*100+ans[2]*10+ans[3];
  }else if(n==2){
    if(ans[1]==0)ans[1]=1;
    cout<<ans[1]*10+ans[2];
  }else{
    cout<<ans[1];
  }
}

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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';
#define N 1000000007 // prime modulo value 

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e9 + 7;


// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x, k,  m, y, q ;
string s, t;
ld w;

// <------------- Implement Functions Here ----------> //


// <------------- Start of main() -------------------> //

void MAIN() {
	cin >> n ;
	vll a(n+1);
	vll b(n+1);
	for(ll i=1;i<=n;i++) cin>>a[i], b[i] = a[i]-(i);
	sort(b.begin()+1,b.end());
	ll ans1 = b[n/2];
	ll ans2 = b[n/2+1];
	//DISP(b);

	ll mini1 = 0, mini2 = 0;

	for(ll i=1;i<=n;i++) {
		mini1 += abs(b[i] - (ans1));
		mini2 += abs(b[i] - (ans2));
	}

	cout<<min(mini1, mini2);
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}

Measured memory_bytes: 6408
#include <iostream>

using namespace std;

int P[10010];
int root(int a);
int is_same_set(int a,int b);
void unite(int a,int b);

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

	int com,x,y;
	for (int i=0;i<N;i++) P[i] = i;

	for (int i=0;i<Q;i++) {
		cin >> com;
		cin >> x >> y;
		if (com == 0) {
			unite(x,y);
		} else {
			cout << is_same_set(x,y) << endl;;
		}

	}
}

int root(int a) { // a ??? root(??£??¨???) ????±???????
	if (P[a] == a) return a; // a ??? root
	return (P[a] = root(P[a])); // a ????????? root ????±???????a ????????¨??????
}
int is_same_set(int a, int b) { // a ??¨ b ???????????°?????????????±???????????
	if(root(a) == root(b)) {
		return 1;
	} else {
		return 0;
	}
}
void unite(int a, int b) { // a ??¨ b ???????????°?????????????????¨??????
	P[root(a)] = root(b);
}

Measured memory_bytes: 3236
class BIT:
    def __init__(self, n):
        self.n = n
        self.dat = [0]*n

    def add(self, k, a):
        while k < self.n:
            self.dat[k] += a
            k |= k+1
 
    def sum(self, k):
        s = 0
        while k >= 0:
            s += self.dat[k]
            k = (k & (k+1)) - 1
        return s

N = int(input())
P = [int(x) for x in input().split()]

pos = [0]*(N+1)
for i in range(N):
    pos[P[i]] = i

bit = BIT(N)
ans = 0
for i in range(N, 0, -1):
    bit.add(pos[i], 1)
    s = bit.sum(pos[i])
    bound = []
    for s2 in [s-2, s-1, s+1, s+2]:
        if s2 <= 0:
            bound.append(-1)
            continue
        
        ok, ng = N, -1
        while ok-ng>1:
            mid = (ok+ng)>>1
            if bit.sum(mid) >= s2:
                ok = mid
            else:
                ng = mid
        bound.append(ok)
    res = (bound[1]-bound[0])*(bound[2]-pos[i]) + (pos[i]-bound[1])*(bound[3]-bound[2])
    ans += i*res

print(ans)

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

int main(){
  string c;
  ll n,i,r,ans;
  cin >> n >> c;
  r=0;
  ans=0;
  for(i=0;i<n;i++){
    if(c.substr(i,1)=="R"){
      r+=1;
    }
  }
  for(i=0;i<r;i++){
    if(c.substr(i,1)=="W"){
      ans+=1;
    }
  }
  cout << ans;
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
#define int long long int
#define pb push_back
#define MAX 100005
#define mod (int)(1e18+7)
#define sp fixed<<setprecision(12)
using namespace std;

/*
vector<int> primes;
bool is_prime[MAX];
void sieve(){
    is_prime[0]=is_prime[1]=true;
    for(int i=4;i<MAX;i+=2){
        is_prime[i]=true;
    }
    for(int i=3;i*i<MAX;i+=2){
        if(!is_prime[i]){
            for(int j=i*i;j<MAX;j+=i){
                is_prime[j]=true;
            }
        }
    }
    
}

int power(int a,int n,int p){
    int res=1;
    while(n){
        if(n&1){
            res=(res*a)%p;
            n--;
        }else{
            a=(a*a)%p;
            n/=2;
        }
    }
    return res;
}

const int N=(1e4)+7;
vector<int> graph[N];
bool vis[N];
bool col[N];
bool dfs(int cur,int c){
    vis[cur]=1;
    col[cur]=c;
    for(auto x:graph[cur]){
        if(!vis[x]){
            if(dfs(x,c^1)==false)
                return false;
        }else if(col[x]==col[cur]) return false;
    }
    return true;
}
*/


int32_t main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    //double    pi=3.14159265358979323846;

    int t=1;
    cin>>t;
    //int it=1;
    int freq[4]={0};
    while(t--){
        string s;
        cin>>s;
        if(s=="AC") freq[0]++;
        else if(s=="WA") freq[1]++;
        else if(s=="TLE") freq[2]++;
        else if(s=="RE") freq[3]++;
    }
    cout<<"AC x "<<freq[0]<<"\n";
    cout<<"WA x "<<freq[1]<<"\n";
    cout<<"TLE x "<<freq[2]<<"\n";
    cout<<"RE x "<<freq[3]<<"\n";

    return 0;
    
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
int seg[524288]; 
void update(int k, int a){
	k += 262143; 
	seg[k] = a; 
	while(k > 0){
		k = (k - 1) / 2; 
		seg[k] = max(seg[k * 2 + 1], seg[k * 2 + 2]); 
	}
}
long long query(int a, int b, int k, int l, int r){
	if(r <= a || b <= l) return 0; 
	if(a <= l && b >= r) return seg[k]; 
	else{
		long long vl = query(a, b, k * 2 + 1, l, (l + r) / 2); 
		long long vr = query(a, b, k * 2 + 2, (l + r) / 2, r); 
		return max(vl, vr); 
	}
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0); 
	int N; cin >> N; 
	pair<int, int> R[200010] = {}; 
	for(int i = 0; i < N; i++){
		cin >> R[i].first >> R[i].second; 
		R[i].second += R[i].first; 
	}
	R[N].first = 2145141919; R[N].second = 2145141919; 
	sort(R, R+N); 
	int P = 998244353; 
	int dp[200010] = {}; // そのロボットより右(inclusive)だけの場合の数
	dp[N] = 1; 
	for(int i = 0; i <= N; i++) update(i, i+1); 
	for(int i = N-1; i >= 0; i--){
		int a = lower_bound(R, R+N+1, make_pair(R[i].second, -2145141919)) - R; 
		int it = query(i, a, 0, 0, 262144); 
		update(i, it); 
		dp[i] = dp[i+1] + dp[it];
		if(dp[i] >= P) dp[i] -= P; 
	}
	cout << dp[0] << endl; 	
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define INF 1e18
#define MOD 1000000007
#define N 1000005
#define BB(V) V[V.size()-2]
#define ex(V) return printf(V),0
using namespace std;
int a[10005],b[10005];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",a+i);
	for(int i=1;i<=n;i++)scanf("%d",b+i);
	ll cnta=0,cntb=0;
	for(int i=1;i<=n;i++){
		if(a[i]>b[i])cntb+=a[i]-b[i];
		else if(a[i]<b[i]){
			if(a[i]%2!=b[i]%2){
				cntb++;
				b[i]++;
			}
			cnta+=(b[i]-a[i])/2;
		}
	}
	printf("%s",cnta>=cntb?"Yes":"No");
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;

string solve() {
    ll n; cin >> n;
    string s = "";
    while (n > 0) {
        n -= 1;
        s += n % 26 + 'a';
        n /= 26;
    };
    reverse(s.begin(), s.end());

    return s;
}

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

    cout << solve() << endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define rint register int
using namespace std;
// by piano
template<typename tp> inline void read(tp &x) {
  x = 0;char c = getchar();bool f = 0;
  for(; c < '0' || c > '9'; f |= (c == '-'), c = getchar());
  for(; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if(f) x = -x;
}

namespace {
  const int mo = 924844033;
  inline int add(int x, int y) {
    if((x += y) >= mo) x -= mo;
    return x;
  }
  inline int sub(int x, int y) {
    if((x -= y) < 0) x += mo;
    return x;
  }
  inline int mul(int x, int y) {
    return 1LL * x * y % mo;
  }
}
const int N = 2333;
int n, K, tot = 0;
int att[2 * N], dp[N * 2][N][2], ans[N], fac[N];

main(void) {
  read(n); read(K);
  for(int i = 1; i <= K; i ++) {
    for(int k = i; k <= n; k += K) {
      ++ tot;
      if(k != i)
        att[tot] = true;
    }
    for(int k = i; k <= n; k += K) {
      ++ tot;
      if(k != i)
        att[tot] = true;
    }
  }
  // for(int i = 1; i <= tot; i ++)
  //   cout << att[i] << " "; puts("");
  dp[0][0][0] = 1;
  for(int i = 1; i <= 2 * n; i ++) {
    for(int k = 0; k <= n; k ++) {
      dp[i][k][0] = add(dp[i - 1][k][1], dp[i - 1][k][0]);
      if(att[i] && k)
        dp[i][k][1] = dp[i - 1][k - 1][0];
    }
  }
  // for(int i = 1; i <= 2 * n; i ++)
  //   for(int k = 0; k <= n; k ++)
  //     for(int t = 0; t < 2; t ++)
  //       printf("dp[%d][%d][%d] = %d\n", i, k, t, dp[i][k][t]);
  fac[0] = 1;
  for(int i = 1; i <= n; i ++)
    fac[i] = mul(fac[i - 1], i);
  for(int i = 0; i <= n; i ++)
    ans[i] = mul(add(dp[2 * n][i][0], dp[2 * n][i][1]), fac[n - i]);
  // for(int i = 0; i <= n; i ++)
  //   cout << ans[i] << " "; puts("");
  int t = 0;
  for(int i = n; i >= 0; i --) {
    t = add(t, (i & 1 ? -1 : 1) * ans[i]);
    t = add(t, mo);
  }
  cout << t << "\n";
}


Measured memory_bytes: 73984
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (chunk)
{
  var x = chunk.split(" ");
  x[0] = Number(x[0])
  x[1] = Number(x[1])
  var op = "=="
  if (x[0] < x[1]) {
    op = "<"
  }else if (x[0] > x[1]) {
    op = ">"
  }
  console.log("a " + op + " b");
});

Measured memory_bytes: 7644
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        int[] num = new int[3000000];
        int count = 0;
        for (int i = 0; i < n; i++) {
            num[a[i]]++;
            if (num[a[i]] == 1) {
                count++;
            }
        }
        int[] shurui = new int[count];
        Arrays.sort(num);
        for (int i = 0; i < count; i++) {
            shurui[i] = num[3000000 - 1 - i];
        }
        Arrays.sort(shurui);
        int ansnum = count - k;
        int ans = 0;
        for (int i = 0; i < ansnum; i++) {
            ans += shurui[i];
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 87100
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 998244353;//1000000000 + 7;// ;//1000000000 + 7 998244353 924844033 1000000000 + 9;
constexpr long long INF = numeric_limits<LL>::max() / 100;
constexpr long long DINF = 1000000000000;
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Edge { LL to, acost, bcost; };
struct edge {
	LL from, to, cost;
};
vector<vector<LL>>g;
vector<edge>ed;
vector<Pll>pv;
map<Pll, LL>ma;
set<LL>st;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
LL n, m, k, p, q, w, h, s, t, ans, cnt, sum, a[310000], b[310000];
string str;
bool f;
char c[1100][1100];
int main() {
	cin >> n>>k;
	rep(i, n) {
		cin >> a[i];
		sum += a[i];
	}
	vector<LL>v;
	for (int i = 1; i*i <= sum; i++) {
		if (sum%i==0) {
			v.push_back(i);
			v.push_back(sum / i);
		}
	}
	sort(v.begin(), v.end());
	rep(i, v.size()) {
		vector<LL>cur;
		rep(j, n) {
			cur.push_back(a[j] % v[i]);
		}
		sort(cur.begin(), cur.end());
		LL  r = n - 1;
		cnt = 0, s = 0;
		for (LL l = 0; l < r; l++) {
			cnt += cur[l]; s += cur[l];
			while (l < r&&s - (v[i] - cur[r]) >= 0) {
				s -= (v[i] - cur[r]);
				r--;
			}
		}
		if (s == 0 && cnt <= k) {
			ans = max(v[i], ans);
			//cout << v[i] <<" "<<cnt<< endl;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define il inline
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define mid ((l+r)>>1)
#define MAXN 
#define MAXM 
#define mod
#define inf (1<<30)
#define eps (1e-6)
#define alpha 0.75
#define rep(i, x, y) for(register int i = x; i <= y; ++i)
#define repd(i, x, y) for(register int i = x; i >= y; --i)
#define file(s) freopen(s".in", "r", stdin), freopen(s".my", "w", stdout)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, int> pli;
typedef pair <int, ll> pil;
typedef pair <ll, ll> pll;
template <typename T> il bool chkmin(T &x, T y) {return x > y ? x = y, 1 : 0;}
template <typename T> il bool chkmax(T &x, T y) {return x < y ? x = y, 1 : 0;}
template <typename T> il void read(T &x) {
	char ch = getchar(); int f = 1; x = 0;
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') x = x*10+ch-'0', ch = getchar();
	x *= f;
}
template <typename T, typename... Args> il void read(T &x, Args &...args) {
	read(x), read(args...);
}
int n, Ch;
vector <int> x[2];
vector <pii> op;
int main() {
	read(n); int a;
	rep(i, 1, n) {
		read(a);
		x[a >= 0].pb(a);
	}
	int ans = 0;
	if(!x[0].size()) {
		sort(x[1].begin(), x[1].end());
		auto it = ++x[1].begin(); int last = *x[1].begin();
		while(it != --x[1].end()) {
			op.pb(mp(last, *it)), last -= *it, ++it;
		}
		op.pb(mp(*it, last)), ans = *it - last;
	}
	else if(!x[1].size()) {
		sort(x[0].begin(), x[0].end());
		reverse(x[0].begin(), x[0].end());
		auto it = ++x[0].begin(); int last = *x[0].begin();
		while(it != x[0].end()) op.pb(mp(last, *it)), last -= *it, ++it;
		ans = last;
	}
	else {
		int last = *x[0].begin();
		auto it = x[1].begin();
		while(it != --x[1].end()) {
			op.pb(mp(last, *it)), last -= *it, ++it;
		}
		op.pb(mp(*it, last)), last = *it - last;
		it = ++x[0].begin();
		while(it != x[0].end()) {
			op.pb(mp(last, *it)), last -= *it, ++it;
		}
		ans = last;
	}
	cout << ans << endl;
	assert(op.size() == n-1);
	for(auto v: op) cout << v.fir << ' ' << v.sec << endl;
	return 0;
}

Measured memory_bytes: 3444
#include <iostream>

using namespace std;

int main(){
    while(0==0){
    int n;
    cin >> n;
    if(n==0) break;
    int pointA=0,pointB=0;
    for(int i=0;i<n;i++){
        int a,b;
        cin >> a >> b;
        if(a<b){
            pointB += a+b;
        }
        if(a>b){
            pointA += a+b;
        }
        if(a==b){
            pointA += a;
            pointB += a;
        }
    }
    cout << pointA <<  " " << pointB << endl;
    }
}

Measured memory_bytes: 1160