akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int dp[100001][3];

int main()
{
  int n;
  cin >> n;
  vector<int> num[3];
  for (int i = 0; i < n; ++i)
  {
    for (int j = 0; j < 3; ++j)
    {
      int t;
      cin >> t;
      num[j].push_back(t);
    }
  }

  for (int i = 0; i < n; ++i)
  {
    for (int j = 0; j < 3; ++j)
    {
      if (i < 1)
        dp[i][j] = num[j][i];
      else
        dp[i][j] = max(dp[i - 1][(j + 1) % 3], dp[i - 1][(j + 2) % 3]) + num[j][i];
    }
  }

  cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << endl;

  return 0;
}


Measured memory_bytes: 2796
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;

class Main {

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

    void compute() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        LinkedList<Integer> b = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            if (i % 2 == 0) {
                b.addLast(a[i]);
            } else {
                b.addFirst(a[i]);
            }
        }
        if (n % 2 == 1) {
            Collections.reverse(b);
        }
        String S = "";
        for (int i = 0; i < n; i++) {
            System.out.print(b.poll() + " ");
        }
    }
}

Measured memory_bytes: 102148
N=int(input())
s=[input() for _ in range(N)]
M=int(input())
t=[input() for _ in range(M)]
ans=-10**9
for i in range(N):
  a=0
  for j in range(N):
    if s[i]==s[j]:
      a+=1
  for k in range(M):
    if s[i]==t[k]:
      a-=1
  ans=max(ans,a)
if ans<0:
  print(0)
else:
  print(ans)

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

typedef long long ll;

int N;
int a[22][22];
ll dp[22][4200000];
bool v[22][4200000];
ll m = 1000000007;

ll solve(int pref, int subset)
{
    if (pref < 0 || subset < 0) return 0LL;
    if (!pref && !subset) return 1LL;
    if (!v[pref][subset])
    {
        v[pref][subset] = 1;
        for (int i = 1; i <= N; i++)
        {
            if (a[pref][i] && (subset & (1 << (i-1))))
            {
                dp[pref][subset] += solve(pref - 1, subset ^ (1 << (i-1)));
                if (dp[pref][subset] >= m) dp[pref][subset] -= m;
            }
        }
    }
    return dp[pref][subset];
}

int main()
{
    scanf("%d", &N);
    for (int i = 1; i <= N; i++)
    {
        for (int j = 1; j <= N; j++)
        {
            int tmp;
            scanf("%d", &tmp);
            a[i][j] = tmp;
        }
    }
    printf("%lld\n", solve(N,(1 << N) - 1));
    return 0;
}


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

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

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

int main()
{
	fast;
	int n;
	cin>>n;
	if(n%10==2 || n%10==4 || n%10==5 || n%10==7 || n%10==9)
		cout<<"hon";
	else if(n%10==0 || n%10==1 || n%10==6 ||n%10==8)
		cout<<"pon";
	else
		cout<<"bon";
	return 0;
}


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


int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if (a + b >= c) cout << "Yes\n";
  else cout << "No\n";
}


Measured memory_bytes: 256
# import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict
geta = lambda fn: list(map(fn, input().split()))
gete = lambda fn: fn(input())
 
def main():
    N, K = geta(int)
    h = geta(int)
 
    INF = 1 << 60
    dp = [INF]*N
    dp[0], dp[1] = 0, abs(h[0] - h[1])
 
    for i in range(2, N):
        lb = i - K if i > K else 0
        for j in range(lb, i):
            tmp = dp[j] + abs(h[j] - h[i])
            if tmp < dp[i]:
                dp[i] = tmp
 
    print(dp[-1])
 
if __name__ == "__main__":
    main()

Measured memory_bytes: 52448
n = gets.to_i

sumall = n*(n+1)/2

num3 = n / 3
num5 = n / 5
num15 = n / 15

answer = sumall - 3 * num3*(num3+1) / 2 - 5 * num5 * (num5+1) / 2 + 15 * num15*(num15+1)/2

print answer

Measured memory_bytes: 14312
import java.io.IOException;
public class Main{
	public static void main(String args[]) throws IOException{
		byte a[] = new byte[3];
		System.in.read(a);
		a[0] &= 1;
		a[1] &= 1;
		a[2] &= 1;
		System.out.println(a[0]+a[1]+a[2]);
	}
}


Measured memory_bytes: 23252
void main()
{
    long n = rdElem;
    long[] a = rdRow;

    long[] b = new long[n+1];
    long[long] cnt;
    ++cnt[0];
    foreach (i, x; a)
    {
        b[i+1] = b[i] + a[i];
        ++cnt[b[i+1]];
    }

    long result;
    foreach (x; cnt.byValue)
    {
        result += x * (x - 1) / 2;
    }

    result.writeln;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 25484
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
  int n,a[1000];
  cin >> n;
  for(int i=0; i<n; i++) {
      cin >> a[i];
  }
  int q,b,e,t;
  cin >> q;
  for(int i=0; i<q; i++) {
      cin >> b >> e >> t;
      for(int j=0; j<e-b; j++) {
          swap(a[b+j],a[t+j]);
      }
  }
  for(int i=0; i<n-1; i++) {
      cout << a[i] << " ";
  }
  cout << a[n-1] << endl;
}


Measured memory_bytes: 3100
n = int(input())

tasks = [list(map(int, input().split())) for _ in range(n)]

tasks.sort(key=lambda x:x[1])

curr_time = 0

for task, time_limit in tasks:
    curr_time += task
    if curr_time > time_limit:
        print("No")
        exit()

print("Yes")


Measured memory_bytes: 53720
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    int m = 10;
    vector<vi> F(n, vi(m));
    rep(i, n) for(auto& e : F[i]) cin >> e;
    vector<vi> P(n, vi(m+1));
    rep(i, n) for(auto& e : P[i]) cin >> e;

    int res = -inf;
    rep(k, 1, bit(m)){
        int cur = 0;
        rep(i, n){
            int cnt = 0;
            rep(j, m){
                if(((k >> j) & 1) and F[i][j]){
                    cnt++;
                }
            }
            cur += P[i][cnt];
        }
        chmax(res, cur);
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
int main() {
    int N, K, ans = 0;
    cin >> N >> K;
    map<int, int> m;
    for(int i = 0; i < N; i++) {
        int x;
        cin >> x;
        if(!m.count(x)) m[x] = 0;
        m[x]++;
    }
    priority_queue<int, vector<int>, greater<int>> q;
    for(auto x : m) q.push(x.second);
    while(q.size() > K) {
        ans += q.top();
        q.pop();
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10748
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  int h[n];
  
  for(int i=0;i<n;i++){
    cin >> h[i];
  }
  
  int c=0;
  int m=h[0];
  
  for(int i=0;i<n;i++){
    if(m<=h[i]){
      c++;
      m=h[i];
    }
  }
  cout << c <<endl;
}
    

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

int main() {
	int i, j, n, tmp1, tmp2, tmp3;
	int kanribanp, kanriban[1001] = {0};
	char flag;
	long long int kanri[4001] = {0};
	while (true) {
		kanribanp = 0;
		for (i=0; i < 4001 ;i++) {
			if (i < 1001) kanriban[i] = 0;
			kanri[i] = 0;
		}

		scanf("%d", &n);
		if (n == 0) break;
		
		for (i=0; i < n ;i++) {
			scanf("%d%d%d", &tmp1, &tmp2, &tmp3);

			flag = true;
			for (j=0; j < kanribanp ;j++) {
				if (kanriban[j] == tmp1) flag = false;
			}
			if (flag == true) {
				kanriban[kanribanp] = tmp1;
				kanribanp++;
			}

			if (tmp2*tmp3+kanri[tmp1] >= 1000000) kanri[tmp1] = 1000000;
			else kanri[tmp1] = tmp2*tmp3+kanri[tmp1];
		}

		flag = true;
		for (i=0; i < kanribanp ;i++) {
			if (kanri[kanriban[i]] >= 1000000) {
				printf("%d\n", kanriban[i]);
				flag = false;
			}
		}
		if (flag) printf("NA\n");
	}
	return 0;
}

Measured memory_bytes: 656
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD =ll(1e9) +7;

int main() {
    string S;
    cin >> S;
    ll dp[S.size()+1][2] ={};
    dp[0][0] =1;
    for(int i=0;i<S.size();i++){
        dp[i+1][0] = dp[i][0];
        dp[i+1][1] = dp[i][1];
        dp[i+1][1] *=3;
        int t = S[i] -'0';
        for(int d=0;d<2;d++){
            if(d<t){
                dp[i+1][0] *= 2;
                dp[i+1][1]+=dp[i][0];
            }
        }
        dp[i+1][0] %=MOD;
        dp[i+1][1] %=MOD;
    }
    cout << (dp[S.size()][0] + dp[S.size()][1])%MOD << endl;

    return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

bool is_prime[1000010];

int main() {
    int n,x,t,tmp;
    cin >> n >> x >> t;
    tmp = n/x;
    if(n%x != 0) tmp++;
    cout << tmp*t << endl;
    return 0;
}

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

int main(){
  
  int A, B, C, K, k=0;
  cin>>A>>B>>C>>K;
  
  while(A>=B){
    k++;
    B*=2;
    if(k>K){
      cout<<"No"<<endl;
      return 0;
    }
  }

  while(B>=C){
    k++;
    C*=2;
    if(k>K){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i ++)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;


template<int Modulus> 
struct ModInt {
    long long x;
    ModInt(long long x = 0) :x((x%Modulus + Modulus)%Modulus) {}
    constexpr ModInt &operator+=(const ModInt a) {if ((x += a.x) >= Modulus) x -= Modulus; return *this;}
    constexpr ModInt &operator-=(const ModInt a) {if ((x += Modulus - a.x) >= Modulus) x -= Modulus; return *this;}
    constexpr ModInt &operator*=(const ModInt a) {(x *= a.x) %= Modulus; return *this;}
    constexpr ModInt &operator/=(const ModInt a) {return *this *= a.inverse();}

    constexpr ModInt operator+(const ModInt a) const {return ModInt(*this) += a.x;}
    constexpr ModInt operator-(const ModInt a) const {return ModInt(*this) -= a.x;}
    constexpr ModInt operator*(const ModInt a) const {return ModInt(*this) *= a.x;}
    constexpr ModInt operator/(const ModInt a) const {return ModInt(*this) /= a.x;}
    
    friend constexpr ostream& operator<<(ostream& os,const ModInt<Modulus>& a) {return os << a.x;}
    friend constexpr istream& operator>>(istream& is,ModInt<Modulus>& a) {return is >> a.x;}
    
    ModInt inverse() const {// x ^ (-1) 
        long long a = x,b = Modulus,p = 1,q = 0;
        while (b) {long long d = a/b; a -= d*b; swap(a,b); p -= d*q; swap(p,q);}
        return ModInt(p);
    }
    ModInt pow(long long N) {// x ^ N 
        ModInt a = 1;
        while (N) {
            if (N&1) a *= *this;
            *this *= *this;
            N >>= 1;
        }
        return a;
    }
};

using mint = ModInt<1000000007>;
//using mint = ModInt<998244353>;
struct Combination {
    int N;
    //using mint = ModInt<1000000007>;
    //using mint = ModInt<998244353>;
    vector<mint> fact,ifact,invs;
    Combination(int N): N(N),fact(N + 1),ifact(N + 1) {
        fact[0] = fact[1] = 1;
        ifact[0] = ifact[1] = 1;
        for (int i = 2;i < N + 1;++i) {fact[i] = fact[i - 1] * i;}
        ifact[N] = fact[N].inverse();
        for (int i = N;i >= 1;--i) {ifact[i - 1] = ifact[i] * i;}
    }
    void invs_build() {
        invs.resize(N + 1);
        invs[1] = 1;
        for (int i = 2;i < N + 1;++i) invs[i] = fact[i] * ifact[i - 1];
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n - k];
    }
    mint npk(int n,int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[n - k];
    }
};

int main() {
    int K; cin >> K;
    string S; cin >> S;
    int N = S.size();
    Combination comb(N + K + 10);

    mint ans = 0;
    for (int i = N;i <= N + K;++i) {
        ans += mint(25).pow(i - N) * comb(i - 1,N - 1) * mint(26).pow(N + K - i);
    }
    cout << ans << '\n';
    return 0;
}

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

int main()
{
  while(1){
    int n, p;
    cin >> n >> p;
    if(n == 0 && p == 0){
      break;
    }else{
      int c[50] = {};
      int i = 0, b = p;
      while(1){
	if(p){
	  c[i]++;
	  p--;
	}else{
	  p += c[i];
	  c[i] = 0;
	}
	if(c[i] == b){
	  cout << i << endl;
	  break;
	}
	i++;
	if(i > n - 1)
	  i = 0;
      }
    }
  }
}

Measured memory_bytes: 1160
#include <iostream>
#include <stdio.h>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <functional>
#include <utility>
#include <map>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<int, Pii > P1;

#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define mp1(a,b,c) P1(a,P(b,c))
#define get_arsize(a) (sizeof(a)/sizeof(a[0]))
const ll MOD = 1000000007;
const double EPS = 1e-10;
const int MAX = 200000;

struct UnionFind {
  vector<int> parent;
  vector<int> depth;
  vector<int> con;
  // 初めに全てのノードの親は自分自身として初期化される。
  UnionFind(int n) {
    rep(i,n) parent.push_back(i);
    rep(i,n) depth.push_back(0);
    rep(i,n) con.push_back(1);
  };
  // 代表の親を取ってくる関数。その途中で再帰的に親ノードを書き換えていく。
  int root(int i) {
    if (parent[i] == i) return i;
    return parent[i] = root(parent[i]);
  }
  // 二つのノードをくっつける関数。代表の親同じならそのまま、そうでないなら、xを代表としてくっつける
  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) return;
    if (depth[rx] < depth[ry]) {
      parent[rx] = ry;
      con[ry] += con[rx];
    } else {
      parent[ry] = rx;
      con[rx] += con[ry];
      if(depth[rx] == depth[ry]) depth[rx]++;
    }
  }

  // 同じグループに属しているか確認
  bool same (int x, int y) {
    return root(x) == root(y);
  }
};

int main() {
  int n, m, k, a, b;
	cin >> n >> m >> k;
  UnionFind uf(n);
  vector<vector<int>> fr;
  fr.assign(n, vector<int>());
   rep(i, m) {
    cin >> a >> b;
    a--;
    b--;
    fr[a].push_back(b);
    fr[b].push_back(a);
    uf.unite(a,b);
  }
  vector<vector<int>> bl;
  bl.assign(n, vector<int>());
  rep(i, k) {
    cin >> a >> b;
    a--;
    b--;
    if (!uf.same(a, b)) continue;
    bl[a].push_back(b);
    bl[b].push_back(a);
  }
  vector<int> ans;
  ans.assign(n, 0);
  rep(i,n) {
    ans[i] = uf.con[uf.root(i)] - 1;
    ans[i] -= fr[i].size();
    ans[i] -= bl[i].size();
  }
  rep(i,n) {
    cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 13432
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
typedef long long ll;

int main(){
  ll N,T,ans = 0;
  cin >> N >> T;
  ll t;
  ll stopTime = 0;
  ll startTime = 0;
  rep(i,N){
    cin >> t;
    if(t <= stopTime){
      stopTime = t + T;
    }else{
      ans += stopTime - startTime;
      startTime = t;
      stopTime = t + T;
    }
  }
  ans += stopTime - startTime ;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 998244353
#define all(_) _.begin(), _.end()
#define F first
#define S second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    ll n, i, ans = 0;
    cin >> n;
    vector <pll> a(n);
    for(i = 0; i < n; i++)
        cin >> a[i].F >> a[i].S;
    sort(all(a));
    ll d[n];
    for(i = 0; i < n; i++)
        d[i] = a[i].F;
    vll dp(n + 1, 0), R(2 * n, 0);
    dp[n] = 1;
    R[2 * n - 1] = n - 1;
    for(i = n - 1; i > 0; i--)
        R[i] = max(R[i << 1] , R[(i << 1) | 1]);
    for(i = n - 1; i >= 0; i--)
    {
        ll index = lower_bound(d + i, d + n, a[i].F + a[i].S) - d - 1, l, r, res;
        l = i, r = index + 1, res = i;
        for(l += n, r += n; l < r; l >>= 1, r >>= 1)
        {
            if(l & 1)
                res = max(R[l++], res);
            if(r & 1)
                res = max(R[--r], res);
        }
        dp[i] = (dp[i + 1] + dp[res + 1]) % mod;
        index = i;
        for(R[index += n] = res; index > 1; index >>= 1)
            R[index >> 1] = max(R[index], R[index ^ 1]);
        // cout << endl;
    }
    cout << dp[0] << endl;
    return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
struct edge{
    ll p;//点
    ll w;//辺の重み*-1
};
vector<vector<edge> > graph(100000);
vector<ll> res(100000);
ll v,e,r;//vは頂点,eは辺,rは始点
void dijkstra(){
  for(int i = 0;i < v;i++)res[i] = pow(10,16);
    res[r] = 0;
    priority_queue<pair<ll,ll> > que;//重み、頂点
    que.push(make_pair((ll)0,r));
    while(!que.empty()){
        edge now;
        now.p = que.top().second;
        now.w = que.top().first * -1;
        que.pop();
        if(res[now.p] < now.w)continue;
        for(int i = 0;i < graph[now.p].size();i++){
            if(res[graph[now.p][i].p] > now.w + graph[now.p][i].w){
                res[graph[now.p][i].p] = now.w + graph[now.p][i].w;
                que.push(make_pair(res[graph[now.p][i].p] * -1,graph[now.p][i].p));
            }
        }
    }
}
int main(){
  ll goal = 0;
  ll start = 0;
  cin >> v >> e >> start >> goal;
  start--,goal--;
  vector<vector<edge> > memo(100000);
  for(int i = 0;i < e;i++){
    ll u,v,a,b;
    cin >> u >> v >> a >> b;
    u--,v--;
    edge in = {v,a};
    graph[u].push_back(in);
    in = {u,a};
    graph[v].push_back(in);
    in = {v,b};
    memo[u].push_back(in);
    in = {u,b};
    memo[v].push_back(in);
  }
  r = start;
  //cout << r << endl;
  dijkstra();
  vector<ll> yen(100000);
  for(int i = 0;i < yen.size();i++){
    yen[i] = res[i];
  }
  for(int i = 0;i < memo.size();i++){
    for(int j = 0;j < memo[i].size();j++){
      graph[i][j] = memo[i][j];
    }
  }
  r = goal;
  //cout << r << endl;
  dijkstra();
  vector<ll> snuuk(100000);
  for(int i = 0;i < yen.size();i++){
    snuuk[i] = res[i];
  }
  /*for(int i = 0;i < 10;i++){
    cout  << yen[i] << " " << snuuk[i] << endl;
  }*/
  vector<ll> cost(100000);
  for(int i = 0;i < cost.size();i++){
    cost[i] = yen[i] + snuuk[i];
  }
  vector<ll> ans(v);
  ll nowcost = 0;
  nowcost = pow(10,16);
  for(int i = v - 1;i >= 0;i--){
    nowcost = min(cost[i],nowcost);
    ans[i] = (ll)pow(10,15) - nowcost;
  }
  for(auto& i:ans){
    cout << i << endl;
  }
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << min(min(a + b, b + c), c + a) << endl;
}


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

main() {

  int a, b, d, r;
  cin >>a >>b;

  d = a/b;
  r = a%b;
  double  f = 1.0*a/b;

  printf("%d %d %.6lf\n",d, r, f);
  
  return 0;

}

Measured memory_bytes: 1192
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int A = sc.nextInt();
      int i;
      for(i=1;i<=A;i++){
        if(Math.floor(i*1.08)==A){
          System.out.println(i);
          return;
        }
      }
        System.out.print(":(");
    }
}

Measured memory_bytes: 35880
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];

    vector<ll> S(N + 1);
    S[0] = 0;
    rep(i,N) S[i + 1] = S[i] + A[i];
    rep(i, N + 1) S[i] = (S[i] - i + K) % K;

    map<ll, ll> mp;

    ll ans = 0;

    rep(i, min(K,N+1)) mp[S[i]]++;

    ans += mp[S[0]] - 1;
    for (ll i = 1; i <= N; ++i){
        mp[S[i - 1]]--;
        if(i + K - 1 <= N) mp[S[i + K - 1]]++;
        ans += mp[S[i]] - 1;
    }

    print(ans);

    return 0;
}

Measured memory_bytes: 15872
#define _USE_MATH_DEFINES

#include <cmath>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <numeric>

using namespace std;

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

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

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

    int n;
    ll a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    for (int k = 0; k < n; ++k) {
        if (-k * d + c * (n - 1 - k) <= b - a &&
            b - a <= -k * c + d * (n - 1 - k)) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}

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

using namespace std;

int is_prime(int n)
{
    int m=sqrt(n+0.5);
    for(int i=2; i<=m; i++)
        if(n%i==0)
            return 0;
    return 1;
}

int num[20000];
int pr[100];
int main()
{
    int cnt=0;
    for(int i=3; i<55555; i++)
        if(is_prime(i))
            num[cnt++]=i;
    int k=0;
    for(int i=0; i<cnt; i++)
    {
        if((num[i]-1)%5==0)
            pr[k++]=num[i];
        if(k==60)
            break;
    }
    int n;
    cin >> n;

    for(int i=0;i<n;i++)
    {
        if(i!=0)
            cout << ' ';
        cout << pr[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
import numpy as np

ri = lambda: int(sys.stdin.readline())
rl = lambda: list(map(int, sys.stdin.readline().split()))

D = ri()
c = np.array(rl())
s = np.array([np.array(rl()) for _ in range(D)])
t = []
for lis in s:
  tmp_list = lis ** 2 / c**0.2
  max_idx = np.argmax(tmp_list)
  t.append(max_idx)
  print(max_idx + 1)
exit()
t = np.array(t)

score = 0
li = np.zeros(26)
li_one = np.ones(26)
c_sum = sum(c)
d = 0
for i in t:
  li += li_one
  li[i] = 0
  tmp = sum(c*li)
  score += s[d][i] - tmp
  print(int(score))
  d += 1  
  

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  if (v.size() == 0) {
    os << "(empty)";
    return os;
  }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

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

vector<int>f(int n){
  vector<int>r;
  for(;n;n/=10)r.push_back(n%10);
  sort(all(r));
  return r;
}

int g(vector<int>r){
  int n=0;
  for(int x:r)n=n*10+x;
  return n;
}

int main() {

  vector<pair<int,int>> ps;
  int id_max = 0;
  loop {
    int id, x;
    char com;
    cin >> id >> com >> x;
    if (!id&&!x)break;
    id_max = max(id_max, id);
    ps.push_back(cons(-x,id));
  }
  sort(all(ps));

  int ji[id_max + 1];
  int k = 1;
  int last = car(ps[0]);
  rep (i, ps.size()) {
    if (last != car(ps[i])) {
      ++k;
      last = car(ps[i]);
    }
    ji[cdr(ps[i])] = k;
  }

  loop {
    int n; cin >> n;
    if (!cin) break;
    cout << ji[n] << endl;
  }

  return 0;
}

Measured memory_bytes: 1200
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<iostream>
using namespace std;
int main()
{
	int n;	
	while(cin>>n)
	{
		int a,b,sum=0;
		while(n--)
		{
			cin>>a>>b;
			sum+=abs(b-a)+1;
		}
		cout<<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define pr pair<int,int>
#define f first
#define s second
int32_t main(){
    int n,d,a;
    cin>>n>>d>>a;
    pair<int,int>v[n];
    for(int i=0;i<n;i++){
        int u,V;
        cin>>u>>V;
        v[i].f=u;
        v[i].s=V;
    }
    sort(v,v+n);
    int temp[n+1];
    memset(temp,0,sizeof(temp));
    int count=0,j=0;
    for(int i=0;i<n;i++){
        v[i].s-=temp[i];
        while(j<n and v[j].f<=v[i].f+2*d){
            j++;
        }
        if(v[i].s>0){
        int y=ceil(v[i].s/(ld)a);
        count+=y;
        temp[i]+=y*a;
        temp[j]-=y*a;
        }
        temp[i+1]+=temp[i];
    }
    cout<<count<<endl;
}





Measured memory_bytes: 4992
//#include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<numeric>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<ctype.h>
#include <fstream>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}
int dy[4]={0,1,0,-1};
//----------program from here----------

int main(){
  string a,b;
  cin >> a >> b;
  reverse(a.begin(), a.end());
  if(a==b){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		 //sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;
int main() {
    int N;
    cin>>N;
    vector<ll> T(N),A(N);
    ll maxT = 0, maxA = 0;
    rep(i,N){cin>>T[i];maxT = max(maxT, T[i]);}
    rep(i,N){cin>>A[i];maxA  = max(maxA, A[i]);}
    if(maxT!=maxA){
        cout<<0<<endl;
        return 0;
    }
    if(A[0]!=T[N-1]){
        cout<<0<<endl;
        return 0;
    }
    //自由度があるかないか
    vector<int> GL(N),GR(N);
    GL[0] = 0;
    GR[N-1] = 0;
    rep1(i,N){
        if(T[i-1]==T[i]){
            GL[i] = 1;
        }
        else{
            GL[i] = 0;
        }
    }
    for (int i = N-2; i >= 0; --i){
        if(A[i]==A[i+1]){
            GR[i] = 1;
        }
        else{
            GR[i] = 0;
        }
    }
    //print(GL);
    //print(GR);
    ll ans = 1;
    rep(i,N){
        //cerr<<GR[i]<<" "<<GL[i]<<endl;
        //cerr<<T[i]<<" "<<A[i]<<endl;
        if(GR[i]==1&&GL[i]==1){
            ans*=min(T[i],A[i]);
            ans%=MOD;
        }
        else if(GL[i]==1&&GR[i]==0){
            if(T[i]>=A[i]){
                continue;
            }
            else{
                ans*=0;
            }
        }
        else if(GL[i]==0&&GR[i]==1){
            if(T[i]<=A[i]){
                continue;
            }
            else{
                ans*=0;
            }
        }
        //cerr<<ans<<endl;
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

bool comPair(const P &firstElof, const P &secondElof) {
    return firstElof.first < secondElof.first;
}

int main() {
    int i, j, k;
    int n, m;
    int Fmax, Lmin;
    int rst = 1;
    cin >> n >> m;
    vector<P> v;
    for (i = 0; i < m; i++) {
        cin >> j >> k;
        v.push_back(P(j, k));
    }
    sort(v.begin(), v.end(), comPair);
    Fmax = v[0].first;
    Lmin = v[0].second;
    for (i = 0; i < m; i++) {
        if (v[i].first >= Lmin) {
            rst++;
            Fmax = 0;
            Lmin = INT_MAX;
        }
        if (v[i].first > Fmax) Fmax = v[i].first;
        if (v[i].second < Lmin) Lmin = v[i].second;
    }
    cout << rst << endl;
}


Measured memory_bytes: 1400
from queue import deque

n = int(input())
edges = [set() for _ in range(n + 1)]
for _ in range(n - 1):
    a, b, c = map(int, input().split())
    edges[a].add((c, b))
    edges[b].add((c, a))
q, k = map(int, input().split())
stack = deque([(0, k)])
costs = [0] * (n + 1)
visited = set()
while stack:
    c, p = stack.popleft()
    costs[p] = c
    visited.add(p)
    stack.extend((c + c2, p2) for c2, p2 in edges[p] if p2 not in visited)

ans = []
for _ in range(q):
    x, y = map(int, input().split())
    ans.append(costs[x] + costs[y])
print('\n'.join(map(str, ans)))


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

ll n=0;

int main(){
	cin.sync_with_stdio(false);
  cin>>n;
  for(int i=1;i<=n;i++){
    ll x=i*(i+1)/2;
    if(x>=n){
      cout<<i<<endl;
      return 0;
    }
  }
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;

namespace Tutorial
{
    class Program
    {
        static void Main(string[] args)
        {
            int AC = 0;
            int TLE = 0;
            int WA = 0;
            int RE = 0;
            
            string input = Console.ReadLine();
            int rep = int.Parse(input);

            for (var i = 0; i < rep; i++)
            {
                string v = Console.ReadLine();

                switch (v)
                {
                    case "AC":
                        AC++;
                        break;
                    case "TLE":
                        TLE++;
                        break;
                    case "WA":
                        WA++;
                        break;
                    case "RE":
                        RE++;
                        break;
                }
                
            }
            Console.WriteLine("AC " + "x " + AC);
            Console.WriteLine("WA " + "x " + WA);
            Console.WriteLine("TLE " + "x " + TLE);
            Console.WriteLine("RE " + "x " + RE);
        }
    }
}


Measured memory_bytes: 30352
#define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_C"

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

#define call_from_test
#ifndef call_from_test
#include<bits/stdc++.h>
using namespace std;
#endif
//BEGIN CUT HERE
struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;
//END CUT HERE
#ifndef call_from_test
signed main(){
  return 0;
}
#endif

#ifndef call_from_test
#include<bits/stdc++.h>
using namespace std;
#endif
//BEGIN CUT HERE
template<typename T>
struct KDTree{
  static const int NIL = -1;

  class Node{
  public:
    int pos,p,l,r;
    Node(){pos=p=l=r=NIL;}
  };

  class Point{
  public:
    int id;
    T x,y;
    Point(){}
    Point(int id,T x,T y): id(id),x(x),y(y){}
    bool operator<(const Point &p)const{
      return id<p.id;
    }
  };

  vector<Point> ps;
  vector<Node> ts;
  int np;

  void add_point(int i,int x,int y){
    ps.emplace_back(i,x,y);
    ts.emplace_back();
  }

  static bool lessX(const Point &p1,const Point &p2){return p1.x<p2.x;}
  static bool lessY(const Point &p1,const Point &p2){return p1.y<p2.y;}

  int dfs(int l,int r,int depth){
    if(l>=r) return NIL;
    int mid=(l+r)/2;
    int t=np++;
    if(depth%2==0){
      sort(ps.begin()+l,ps.begin()+r,lessX);
    }else{
      sort(ps.begin()+l,ps.begin()+r,lessY);
    }
    ts[t].pos=mid;
    ts[t].l=dfs(l,mid,depth+1);
    ts[t].r=dfs(mid+1,r,depth+1);
    return t;
  }

  int build(){
    np=0;
    return dfs(0,ps.size(),0);
  }

  // [sx, tx] * [sy, ty]
  void find(int v,T sx,T tx,T sy,T ty,int depth,vector<Point> &ans){
    T x=ps[ts[v].pos].x;
    T y=ps[ts[v].pos].y;
    if(sx<=x&&x<=tx&&sy<=y&&y<=ty)
      ans.push_back(ps[ts[v].pos]);

    if(depth%2==0){
      if(ts[v].l!=NIL){
        if(sx<=x) find(ts[v].l,sx,tx,sy,ty,depth+1,ans);
      }
      if(ts[v].r!=NIL){
        if(x<=tx) find(ts[v].r,sx,tx,sy,ty,depth+1,ans);
      }
    }else{
      if(ts[v].l!=NIL){
        if(sy<=y) find(ts[v].l,sx,tx,sy,ty,depth+1,ans);
      }
      if(ts[v].r!=NIL){
        if(y<=ty) find(ts[v].r,sx,tx,sy,ty,depth+1,ans);
      }
    }
  }
};
//END CUT HERE
#ifndef call_from_test
signed main(){
  return 0;
}
#endif

#undef call_from_test

signed main(){
  int n;
  cin>>n;
  KDTree<int> kd;
  for(int i=0;i<n;i++) {
    int x,y;
    cin>>x>>y;
    kd.add_point(i,x,y);
  }
  int root=kd.build();

  int q;
  cin>>q;
  int sx,tx,sy,ty;
  vector<decltype(kd)::Point> ans;
  for(int i=0;i<q;i++){
    cin>>sx>>tx>>sy>>ty;
    ans.clear();
    kd.find(root,sx,tx,sy,ty,0,ans);
    sort(ans.begin(),ans.end());
    for(auto p:ans) cout<<p.id<<"\n";
    cout<<"\n";
  }
  cout<<flush;
  return 0;
}



Measured memory_bytes: 16228
#include <bits/stdc++.h>
using namespace std;
 
#define ff first
#define ss second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define check(x) cout << #x << " : " << (x) << endl
#define all(v) v.begin(),v.end() 
#define allr(v) v.rbegin(),v.rend() 
//#define endl '\n'  
typedef  long long ll; 
typedef  unsigned long long ull; 
typedef vector< ll > edge; 
typedef pair< ll , ll > mypair;
typedef priority_queue <ll> max_heap;
typedef priority_queue <mypair, vector<mypair>, greater<mypair> > min_heap;
const ll mod=1e9+7;
const ll inf=1e15;
const ll N=700+10;

int main()
{
	boost;
	ll n,x;
	cin>>n>>x;
	std::vector<ll> v(n),d(n+1,0);
	for(auto &i:v) cin>>i;
	d[0]=0;
	for(int i=1;i<=n;i++)
	{
		d[i]=d[i-1]+v[i-1];
	}
	ll  ans=0;
	for(auto i:d) if(i<=x) ans++;
	cout<<ans; 
  	return 0;
}

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

int x, y, a, b, c, colorless, red[100005], green[100005];
long long ans;
priority_queue<int> pq;
priority_queue<int, vector<int>, greater<int>> pq2;

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

	cin >> x >> y >> a >> b >> c;
	for (int i = 0; i < a; i++) {
		cin >> red[i];
	}

	for (int i = 0; i < b; i++) {
		cin >> green[i];
	}

	for (int i = 0; i < c; i++) {
		cin >> colorless;
		pq.push(colorless);
	}

	sort(red, red+a, greater<int>());
	sort(green, green+b, greater<int>());
	for (int i = 0; i < x; i++) {
		pq2.push(red[i]);
		ans += red[i];
	}

	for (int i = 0; i < y; i++) {
		pq2.push(green[i]);
		ans += green[i];
	}

	while (!pq.empty()) {
		int u = pq.top();
		pq.pop();

		if (pq2.top() < u) {
			ans -= pq2.top();
			pq2.pop();
			pq2.push(u);
			ans += u;
		}
	}

	cout << ans << '\n';
	
	return 0;
}

Measured memory_bytes: 2552
// atcoder/m-solutions2019/B/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  string s;
  while (cin >> s) {
    while (s.size() < 15) s += 'o';
    cout << (8 <= count(s.begin(), s.end(), 'o') ? "YES" : "NO") << endl;
  }

  return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author win11905
 */

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define long long long
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
const long MOD = 1e9+7, LINF = 1e18 + 1e16;
const int INF = 1e9+1;
const double EPS = 1e-10;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};


class TaskD {
private:
    int n, c3, c5, c15, c25, c75;
    vector<int> prime;
public:
	void solve(istream& cin, ostream& cout) {
	    cin >> n;
        for(int i = 2; i <= 100; ++i) {
            bool st = true;
            for(int j = 2; j < i; ++j) if(i % j == 0) st = false;
            if(st) prime.emplace_back(i);
        }
        for(auto x : prime) {
            int cnt = 0;
            for(int i = 2; i <= n; ++i) {
                int z = i;
                while(z % x == 0) z /= x, cnt++;
            }
            if(cnt >= 2) c3++;
            if(cnt >= 4) c5++;
            if(cnt >= 14) c15++;
            if(cnt >= 24) c25++;
            if(cnt >= 74) c75++;
        }
        int ans = 0;
        ans += c5 * (c5 - 1) / 2 * (c3 - 2);
        ans += c15 * (c5 - 1);
        ans += c25 * (c3 - 1);
        ans += c75;
        cout << ans << endl;
	}
};

class Solver {
public:
	void solve(std::istream& in, std::ostream& out) {
		TaskD *obj = new TaskD();
		obj->solve(in, out);
	}
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	Solver solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

using namespace std;

char a[100][100];
int vis[110][110], m, n;
void dfs(int x, int y, char op)
{
    vis[x][y] = 1;
    int di[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
    for(int i = 0;i < 4;i++)
    {
        int tx = x + di[i][0];
        int ty = y + di[i][1];
        if(a[tx][ty] == op && tx < m && tx >= 0 && ty < n && ty >= 0 && !vis[tx][ty])
            dfs(tx, ty, op);
    }
}
int main()
{
     while(scanf("%d %d", &m, &n), m && n)
     {
         memset(vis, 0, sizeof(vis));
         int ans = 0;
         for(int i = 0;i < m;i++)
            scanf("%s", a[i]);
         for(int i = 0;i < m;i++)
            for(int j = 0;j < n;j++)
            {
                if(!vis[i][j])
                {
                    dfs(i, j, a[i][j]);
                    ans++;
                }
            }
        printf("%d\n", ans);
     }
    return 0;
}

Measured memory_bytes: 4200
#include<bits/stdc++.h>
using namespace std;
int main(){
	
	long long int x,k,d,n,ans;	cin>>x>>k>>d;
	x=abs(x);
	n=x/d;
	if(n>=k)	ans = x-k*d;
	else{
		x-=n*d;
		k-=n;
		if(k%2==0) ans = abs(x);
		else ans = min(abs(x-d),abs(x+d));

	}

	cout<<ans;
return 0;
}

Measured memory_bytes: 3644
/**
 *   Author:  Wasi Ur Rahman
 *   FROM RMSTU
**/
#include <bits/stdc++.h>
#define fast            	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll           		unsigned long long int
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define MOD                 1000000007
#define dourao       		ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define min3(a,b,c)    		min(a,min(b,c))
#define min4(a,b,c,d)  		min(d,min3(a,b,c))
#define max3(a,b,c)    		max(a,max(b,c))
#define max4(a,b,c,d)  		max(d,max3(a,b,c))
#define all(v)         		v.begin(),v.end()
#define revall(v)      		v.rbegin(),v.rend()
#define pb             		push_back
#define eb             		emplace_back
#define setbits(x)     		__builtin_popcountll(x)
#define zrobits(x)     		__builtin_ctzll(x)
#define si(x)               scanf("%d", &x)
#define sii(x, y)           scanf("%d %d", &x, &y)
#define siii(x, y, z)       scanf("%d %d %d", &x, &y, &z)
#define sl(x)               scanf("%lld", &x)
#define sll(x, y)           scanf("%lld %lld", &x, &y)
#define slll(x, y, z)       scanf("%lld %lld %lld", &x, &y, &z)
#define poro                freopen("input.txt","r",stdin)
#define lekho               freopen("output.txt","w",stdout)
#define println()           cout << endl
#define printi(x)           printf("%d\n")
#define printii(x,y)        printf("%d %d\n")
#define printiii(x,y,z)     printf("%d %d %d\n")
#define printl(x)           printf("%lld\n")
#define printll(x,y)        printf("%lld %lld\n")
#define printlll(x,y,z)     printf("%lld %lld %lld\n")
using namespace __gnu_pbds;
using namespace std;
/*************************************
**          A S S E M B L E         **
**************************************/
bool isPrime(ll n){if(n <= 1)return false;for (ll i = 2; i * i < n; i++)if (n % i == 0)return false;return true;}
ll fact(ll n){ll res = 1;for(ll i = n;i>=1;i--)res *= i;return res;}
ll nCr(ll n,ll r){return (fact(n)/(fact(r)*fact(n-r)));}
ll nPr(ll n,ll r){return fact(n)/fact(n-r);}
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;}
const int mod=998244353;
inline int add(int a,int b){if((a+=b)>=mod)a-=mod;return a;}
inline int dec(int a,int b){if((a-=b)<0)a+=mod;return a;}
inline int mult(int a,int b){long long t=1ll*a*b;if(t>=mod)t%=mod;return t;}
ll power(ll a,ll b){ll out=1;while(b){if(b&1)out=mult(out,a);a=mult(a,a);b>>=1;}return out;}
/*************************************
**  E N D    G A M E   S T A R T S  **
**************************************/
int main(){
	dourao;
	int x,y;
	cin >> x >> y;
	for(int i = 0;i<=x;++i){
        int j = x - i;
        if(2*i+4*j == y){
            cout << "Yes" << endl;
            return 0;
        }
	}cout << "No" << endl;
	return 0;
}



Measured memory_bytes: 3592