akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    int n, k;
    cin >> n >> k;

    vs32 a(n); for (auto& item : a) cin >> item;

    if (k >= 100)
    {
        rep (i, n)
        {
            if (i > 0) cout << " ";
            cout << n;
        }
        cout << "\n";
        return 0;
    }

    vs32 ans(n + 2, 0);
    rep (i, n)
    {
        ++ans[max(0, i + 1 - a[i])];
        --ans[min(n + 1, i + 2 + a[i])];
    }
    for (int i = 0; i <= n; ++i)
    {
        ans[i + 1] += ans[i];
    }

    for (int i = 1; i < k; ++i)
    {
        vs32 temp(n + 2, 0);
        for (int j = 1; j <= n; ++j)
        {
            ++temp[max(0, j - ans[j])];
            --temp[min(n + 1, j + 1 + ans[j])];
        }
        for (int j = 0; j <= n; ++j)
        {
            temp[j + 1] += temp[j];
        }
        ans = temp;
    }

    for (int i = 1; i <= n; ++i)
    {
        if (i > 1) cout << " ";
        cout << ans[i];
    }
    cout << "\n";

    return 0;
}



Measured memory_bytes: 5564
n = int(input())
def f(s):
  if int(s) > n:
    return 0 #再帰終了
  if s.count("3") > 0 and s.count("5") > 0 and s.count("7") > 0:
  	cnt = 1
  else:
  	cnt = 0
  cnt += f(s + "3")
  cnt += f(s + "5")
  cnt += f(s + "7")
  return cnt
  
result = f("0")
print(result)


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

struct Node {
  string name;
  vector<int> child;
};

void print_tree(vector<Node> &tree, int dep, int v) {
  for ( int i = 0; i < dep; i++ ) cout << '.';
  cout << tree[v].name << endl;
  for ( int i = 0; i < (int)tree[v].child.size(); i++ ) {
    print_tree(tree, dep+1, tree[v].child[i]);    
  }
}

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

  vector<Node> tree(n);
  for ( int i = 0; i < n; i++ ) {
    int dep;
    string name;
    cin >> dep >> name;
    tree[i].name = name;
    if ( dep ) tree[dep-1].child.push_back(i);	       
  }

  print_tree(tree, 0, 0);  
  
  return 0;
}



Measured memory_bytes: 3420
//g++ test.cpp -o test.out
//入出力：http://kaitei.net/cpp/iostream/
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
using namespace std;

long long int M1,D1,M2,D2;

int main(){
	cin >> M1 >> D1;
	cin >> M2 >> D2;

	if(M1+1==M2 || (M1==12 && M2==1)){
		cout << 1;
		return 0;
	}


	cout << 0;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>

#include<queue>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
#define INF (1e10)
typedef long long unsigned int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MOD 1000000007

template<typename T>
int vector_finder(std::vector<T> vec, T number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

template<typename T>
T gcd(T a,T b){
	if(b>0){
		return gcd(b, a % b);
	}else{
		return a;
	}
}

template<typename T>
T lcm(T a,T b){
	T g = gcd(a, b);
	return a * b / g;
}

void clear( std::queue<pair<int,int> > &q )
{
   std::queue<pair<int,int> > empty;
   std::swap( q, empty );
}

int N;
vector<vector<pair<int,ll> > > links;
int Q, K;
ll cost[100000];
int visited[100000];
void dfs(ll c, int idx)
{
	cost[idx] = c;
	visited[idx] = 1;	
	REP(i, 0, links[idx].size())
	{
		if(visited[links[idx][i].first]==0){
			dfs(c + links[idx][i].second, links[idx][i].first);
		}
	}
}

int main()
{
	cin >> N;
	links.resize(N);
	
	REP(i,0,N-1){
		int a, b;
		ll c;
		cin >> a >> b >> c;
		a--;
		b--;
		links[a].push_back(make_pair(b, c));
		links[b].push_back(make_pair(a, c));
	}
	
	REP(i,0,N){
		visited[i] = 0;
		cost[i] = 0;
	}
	
	cin >> Q >> K;


	dfs(0, K - 1);
	int x[Q], y[Q];

	REP(i,0,Q){
	
		cin >> x[i] >> y[i];
		x[i]--;
		y[i]--;

	}

	REP(i,0,Q){
		cout << cost[x[i]] + cost[y[i]] << endl;
	}


	return 0;
}

Measured memory_bytes: 13184
#include <stdio.h>
#define bignum 114514
#define th 3
void initArray(int s[], int len);
void init753(int s[]);
void make753(int s[], int start, int end, int disit);
int have(int a, int b[], int len);
int getdisit(int a);
int power(int a, int b);
int sft[bignum];
int check[th];
int main(void)
{
    initArray(sft, bignum);
    init753(sft);
    make753(sft, 0, 3, 0);
    initArray(check, th);
    init753(check);

    int n;
    scanf("%d", &n);
    int i = 0;
    int count = 0;
    while (sft[i] <= n)
    {
        if(have(sft[i], check, th))
        {
            count++;
        }
        i++;
    }
    printf("%d\n", count);

    // debug
    // printf("%d\n",sft[n]);
    // puts(have(sft[n], check,th)?"YES":"NO");
    return 0;
}

void initArray(int s[], int len)
{
    for (int i = 0; i < len; i++)
    {
        s[i] = 0;
    }
}

void init753(int s[])
{
    s[0] = 3;
    s[1] = 5;
    s[2] = 7;
}

void make753(int s[], int start, int end, int disit)
{
    //s[0] = 3, s[1] = 5, s[2] = 7を代入済み前提
    if (disit == 9)
    {
        return;
    }

    int limit = end;
    while (start < limit)
    {
        s[end] = s[start] * 10 + 3;
        s[end + 1] = s[start] * 10 + 5;
        s[end + 2] = s[start] * 10 + 7;
        end += 3;
        start++;
    }
    make753(s, start, end, disit + 1);
}

int have(int a, int b[], int len)
{
    int disit = getdisit(a);
    int num[10];
    initArray(num, 10);
    while (disit > 0)
    {
        int c = a / power(10, disit - 1);
        c %= 10;
        num[c]++;
        disit--;
    }

    int d = 1;
    for (int i = 0; i < len; i++)
    {
        d *= num[b[i]];
    }

    if (d > 0)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

int getdisit(int a)
{
    if (a == 0)
    {
        return 1;
    }

    int disit = 0;
    while (a > 0)
    {
        a /= 10;
        disit++;
    }
    return disit;
}

int power(int a, int b)
{
    int c = 1;
    for (int i = 0; i < b; i++)
    {
        c *= a;
    }
    return c;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int a[999999];
bool zs(int n)
{
	for(int i=2;i*i<=n;++i)
		if(n%i==0)
			return false;
	return true;
}
bool hw(int n)
{
	int m=0,k=n;
	while(k!=0)
	{
		m=m*10+k%10;
		k/=10;
	}
	if(m==n)
		return true;
	return false;
}
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;++i)
		cin>>a[i];
	for(int i=n;i>0;i-=2)
		cout<<a[i]<<" ";
	for(int i=(n%2!=0)+1;i<=n;i+=2)
		cout<<a[i]<<" ";
	return 0;
}

Measured memory_bytes: 2944
/*
 * HowManyDivisors.cpp
 *
 *  Created on: 2014/07/21
 *      Author: WanWan1985
 */
#include <iostream>
#include <vector>
using namespace std;

int main(void) {

	int a, b, c;
	cin >> a >> b >> c;
	vector<int> vecValue;
	int h = (b - a);
	for (int i = 0; i <= h; i++) {
		vecValue.push_back(a + i);
	}

	int iDivisorNum = 0;
	for (unsigned int i = 0; i < vecValue.size(); i++) {
		if (c % vecValue.at(i) == 0) {
			iDivisorNum++;
		}
	}
	cout << iDivisorNum << endl;

	return 0;
}

Measured memory_bytes: 1320
import sys
#input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

#import numpy as np

def main():

	n=II()
	A=LI()

	if A[-1]!=2:
		print(-1)
		exit()

	l=2
	r=2

	for i in range(n-2,-1,-1):
		l=((l-1)//A[i]+1)*A[i]
		r=((r+A[i+1]-1)//A[i])*A[i]
		if l>r:
			print(-1)
			exit()

	print(l,r+A[0]-1)
















if __name__ == "__main__":
	main()


Measured memory_bytes: 84796
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
using namespace std;

void solve(){
  int n, a, b; cin >> n >> a >> b;
  if(a * n < b) cout << a * n << endl;
  else cout << b << endl;
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
s = input()
rs = 0
sz = len(s) - 1
for mask in range(2 ** sz):
    curr, total = 0, 0
    for i in range(sz):
      curr *= 10
      curr += int(s[i])
      if mask & (1 << i):
        total += curr
        curr = 0
    curr *= 10
    curr += int(s[-1])
    rs += total + curr
print(rs)


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

int main(){
	int n;
	cin>>n;
	rep(_,n){
		vector<long long> a(9);
		rep(i,9)cin>>setbase(16)>>a[i];
		long long k=0;
		rep(d,32){
			long long b=0,c=a[8]^k, m=(2ll<<d)-1;
			rep(i,8) b+=(a[i]^k);
			if((b&m) != (c&m))k|=1ll<<d;
		}
		cout<<setbase(16)<<k<<endl;
	}
}


Measured memory_bytes: 3088
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */


ll solve(){
    ll res = 0;
    ll N; cin >> N;
    vector<ll> A(N);
    for(auto& in:A) cin >> in;
    set<ll> s;
    for(int i = 0; i < N;i++){
        if(s.find(A[i]) == s.end()) s.insert(A[i]);
        else s.erase(A[i]);
    }
    res = s.size();
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
//const long long MOD = ;
const long long INF_LL = 1e18+3; const int INF_int = 1e9+3;
#define ll long long
#define rep(i,n) for(int i = 0;i<n;i++)
#define lrep(i,n) for(long long i = 0;i<n;i++)
#define All(a) a.begin(),a.end()
#define Debug_Output_ALL(a) for(auto itr = a.begin();itr!=a.end();itr++) cout << *itr << " ";cout << endl;
int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<ll> m_acc(n+1);
    m_acc[0]=0LL;
    rep(i,n) m_acc[i+1]=m_acc[i]+int(s[i]=='M');
    vector<int> c_suf;
    rep(i,n) if(s[i]=='C') c_suf.push_back(i);
    ll csize = c_suf.size();
    vector<ll> m_in_c(csize);
    if(csize!=0){
        m_in_c[0] = m_acc[c_suf[0]];
        for(int i = 1;i<csize;i++) m_in_c[i]=m_acc[c_suf[i]]-m_acc[c_suf[i-1]];
    }
    vector<ll> m_in_c_acc(csize+1);
    m_in_c_acc[0]=0;
    rep(i,csize) m_in_c_acc[i+1]=m_in_c_acc[i]+m_in_c[i];

    lrep(i,csize) m_in_c[i]*=(csize-i);

    vector<ll> m_in_c_acc2(csize+1);
    m_in_c_acc[0]=0LL;
    rep(i,csize) m_in_c_acc2[i+1]=m_in_c_acc2[i]+m_in_c[i];

    vector<int> d_suf;
    rep(i,n) if(s[i]=='D') d_suf.push_back(i);

    int q;
    cin >> q;
    vector<ll> ansvec;
    /*Debug_Output_ALL(m_acc)
    Debug_Output_ALL(m_in_c)
    Debug_Output_ALL(m_in_c_acc)
    Debug_Output_ALL(m_in_c_acc2)
    Debug_Output_ALL(c_suf);*/
    rep(i,q){
        int dist;
        cin >> dist;
        ll ans = 0;
        rep(j,d_suf.size()){
            int nowd = d_suf[j];
            int f_suf = upper_bound(All(c_suf),nowd) - c_suf.begin();
            if(f_suf==csize) continue;
            vector<int>::iterator itr = lower_bound(All(c_suf),dist+nowd);
            if(itr==c_suf.begin()) continue;
            itr--;
            int l_suf = itr-c_suf.begin();
            if(l_suf<f_suf) continue;
            //if(i==1) cout << f_suf << " " << l_suf << " ";
            ans+=(m_in_c_acc2[l_suf+1]-m_in_c_acc2[f_suf+1]);
            ans-=((csize-l_suf-1)*(m_in_c_acc[l_suf+1]-m_in_c_acc[f_suf+1]));
            ans+=(l_suf-f_suf+1)*(m_acc[c_suf[f_suf]]-m_acc[nowd+1]);
            //if(i==1) cout << ans << endl;
        }
        ansvec.push_back(ans);
    }
    rep(i,ansvec.size()) cout << ansvec[i] << endl;
}

Measured memory_bytes: 36856
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define frfr  freopen("input.text","r",stdin); freopen("output.text","w",stdout)
#define ll long long int
#define wh int T;cin >> T;while(T--)
#define pb push_back
#define loop(i,a,b) for (int i = a; i < n; i++)
int main(){
   int n;
   cin >> n;
   int arr[n+1];
   arr[0] = 0;
   for(int i=1;i<=n;i++){
    cin >> arr[i];
   }
   int count = 0;
   for(int i=1;i<=n;i=i+2){
    if(arr[i]%2 != 0){
      count++;
    }
   }
   cout << count <<  endl;
  return 0;
}

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

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n;
  cin >> n;
  int a[110], b[110];
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  const int INF = 1 << 30;
  int dp[110][110];
  fill_n((int*)dp, 110 * 110, INF);
  for (int w = 0; w < n; w++) {
    for (int i = 0; i + w < n; i++) {
      int j = i + w;
      if (w == 0) {
        dp[i][j] = 0;
      } else {
        for (int k = i; k < j; k++) {
          dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + a[i] * b[k] * a[k + 1] * b[j]);
        }
      }
    }
  }
  cout << dp[0][n - 1] << endl;

  return 0;
}


Measured memory_bytes: 3224
#!/usr/bin/env python3

from numba import njit

def main():
    k = int(input())
    print(getresult(k))

@njit
def getresult(k):
    res = 0
    for a in range(1, k + 1):
        for b in range(1, k + 1):
            for c in range(1, k + 1):
                res += gcd(gcd(a, b), c)
    return res

@njit
def gcd(x, y):
    if x < y:
        x, y = y, x  # x >= y
    while y > 0:
        r = x % y
        x = y
        y = r
    return x

if __name__ == "__main__":
    main()


Measured memory_bytes: 109692
object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val a, b = sc.nextInt
    println(
      if (a == 1 && b == 2) 3
      else if (a == 1 && b == 3) 2
      else if (a == 2 && b == 1) 3
      else if (a == 2 && b == 3) 1
      else if (a == 3 && b == 1) 2
      else 1
    )
  }
}


Measured memory_bytes: 25372
import itertools
import math
N = int(input())
P = tuple(map(int,input().split(" ")))
Q = tuple(map(int,input().split(" ")))
Nk = math.factorial(N)
per = list(itertools.permutations(range(1,N+1)))
for i in range(Nk):
    if P == per[i]:
        p = i
for j in range(Nk):
    if Q == per[j]:
        q = j
print(abs(p-q))

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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORd(i, a, b) for (int i = (a) ; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define sp system("pause")
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
const int N = (int) 1e5 + 10;
void TimeExecution() {
    cout << "\n\n===>> Time Execution: " << clock() / (double)1000 << " sec(s).";
}
int t;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    /*
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    */
    string s;
    cin >> s;
    FOR(i, 0, s.size() - 1)
    {
        if(s[i] == ',') cout << " ";
        else cout << s[i];
    }
    return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def all_bit_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8) 
    x = x + (x >> 16) 
    x = x + (x >> 32) 
    return x & 0x0000007f
  
n = int(readline())
d = [0]*(n+1)
d[1] = 1
for i in range(2,n+1):
  q = all_bit_count(i)
  p = i%q
  d[i] = d[p]+1
  
x = input()
c = x.count('1')

a1 = 0
a0 = 0
C = max(1,c-1)
for i,xi in enumerate(x[::-1]):
  if xi == '1':
    a1 += pow(2,i,C)
    a1 %= C
    a0 += pow(2,i,c+1)
    a0 %= (c+1)
    
for i,xi in enumerate(x):
  if xi == '1':
    if c > 1:
      cc = (a1 - pow(2,n-1-i,C))%C
      print(d[cc]+1)
    else:
      print(0)
  else:
    cc = (a0 + pow(2,n-1-i,c+1))%(c+1)
    print(d[cc]+1)

Measured memory_bytes: 75840
n, m = map(int, input().split())
dp = [0]*(n+2)
dp[0] = 1
for i in range(m):
  dp[int(input())] = -1

for i in range(n):
  if dp[i] >= 0:
    if dp[i+1] >= 0:
      dp[i+1] += dp[i]
    if dp[i+2] >= 0:
      dp[i+2] += dp[i]

print(dp[n] % 1000000007)

Measured memory_bytes: 468392
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

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

vector<vector<int> > succ;
vector<bool> visited;
vector<ll> cnt;
vector<ll> anslst;

void inorder(int id, ll val) {
  if (visited[id]) return;
  visited[id] = true;

  anslst[id] = cnt[id] + val;

  for (size_t i = 0; i < succ[id].size(); i++) {
    inorder(succ[id][i], anslst[id]);
  }

  return;
}

int main() {
  ll N, Q;

  cin >> N >> Q;

  succ = vector<vector<int> >(N + 1);
  visited = vector<bool>(N + 1, false);
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    succ[a].emplace_back(b);
    succ[b].emplace_back(a);
  }

  cnt = vector<ll>(N + 1, 0);
  for (int i = 0; i < Q; i++) {
    ll id, val;
    cin >> id >> val;
    cnt[id] += val;
  }

  anslst = vector<ll>(N + 1, 0);
  inorder(1, 0);

  for (int i = 1; i <= N; i++) {
    cout << anslst[i];
    if (i != N)
      cout << " ";
    else
      cout << endl;
  }

  return 0;
}


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

using namespace std;

const int N = 1e5+7;

int n, k;
int col[N];
vector<pair<int, int>> e[N];
map<int, int> vis[N];

void dfs(int u)
{
    int c = 1;
    for (auto p : e[u]) {
        if (col[p.second]) continue;
        while (vis[u].count(c)) ++c;
        col[p.second] = c;
        vis[u].insert({c, 1});
        vis[p.first].insert({c, 1});
        k = max(k, c);
        dfs(p.first);
    }
}

int main()
{
    cin >> n;
    for (int i = 1, u, v; i < n; ++i) {
        cin >> u >> v;
        e[u].emplace_back(v, i);
        e[v].emplace_back(u, i);
    }
    dfs(1);
    cout << k << endl;
    for (int i = 1; i < n; ++i)
        cout << col[i] << endl;
    return 0;
}


Measured memory_bytes: 20992
#include <cmath>
#include <iostream>
#include <vector>

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

    std::vector<int> v(n, 0);
    bool valid = true;
    for (int i = 1; i <= n; ++i) {
        int a;
        std::cin >> a;
        ++v[a];
        if ((n % 2 == 0 && a % 2 == 0) || (n % 2 == 1 && a % 2 == 1))
            valid = false;
        else if ((a == 0 && v[a] > 1) || v[a] > 2)
            valid = false;
    }

    long long ans = 0;
    if (valid) {
        ans = 1;
        for (int i = 0; i < n / 2; ++i) {
            ans *= 2;
            if (ans > 1000000007)
                ans -= 1000000007;
        }
    }

    std::cout << ans << std::endl;
}


Measured memory_bytes: 640
#include <stdio.h>

#define Mod 100003

typedef struct List {
	struct List *next;
	int v, count;
} list;

int main()
{
	int h, i, N, K, A, sum = 0;
	long long ans = 0;
	list *p, *hash[Mod] = {}, d[200001], *q[200001];
	scanf("%d %d", &N, &K);
	d[0].v = 0;
	d[0].count = 1;
	d[0].next = hash[0];
	hash[0] = &(d[0]);
	q[0] = &(d[0]);
	for (i = 1; i <= N; i++) {
		if (i >= K) q[i-K]->count--;
		
		scanf("%d", &A);
		sum = (sum + A - 1) % K;
		
		h = sum % Mod;
		for (p = hash[h]; p != NULL; p = p->next) if (p->v == sum) break;
		if (p != NULL) {
			ans += p->count++;
			q[i] = p;
		} else {
			d[i].v = sum;
			d[i].count = 1;
			d[i].next = hash[h];
			hash[h] = &(d[i]);
			q[i] = &(d[i]);
		}
	}
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 7160
// Author: getharshkumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll n;
    cin >> n;
    ll s = 0;
    vector<ll> a(n + 1), b(n);
    for (ll &e : a)
        cin >> e, s += e;
    for (ll &e : b)
        cin >> e;
    for (ll i = 0; i < n; i++)
    {
        ll m = min(a[i], b[i]);
        a[i] -= m;
        b[i] -= m;
        a[i + 1] -= min(a[i + 1], b[i]);
    }
    for (ll e : a)
        s -= e;
    cout << s;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<iomanip>
#include<math.h>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18
#define PI 3.1415926535

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    string S; cin >> S;
    vector<int> L(S.size()+1),R(S.size()+1);
    rep(i,S.size()+1){
        if(S[i] == 'R') R[i+1] = R[i]+1;
        if(S[i] == 'L') R[i+1] = 0;
    }
    for(int i = S.size()-1; i >= 0; i--){
        if(S[i] == 'L') L[i] = L[i+1]+1;
        if(S[i] == 'R') L[i] = 0;
    }
    vector<int> ans(S.size());
    rep(i,S.size()){
        if(S[i] == 'R' && S[i+1] == 'L'){
            if(R[i+1] % 2 == 0) ans[i] += R[i+1] / 2;
            else ans[i] += R[i+1] / 2 + 1;

            ans[i] += L[i+1]/2;

            ans[i+1] += R[i+1] + L[i+1] - ans[i];
        }
    }
    rep(i,S.size()){
        cout << ans[i];
        if(i != S.size() - 1) cout << " ";
    }
    cout << endl;
    
    
}
   

Measured memory_bytes: 1792
N = int(input())
A = list(map(int, input().split()))
#L = [0 for i in range(N)]
dict = {}

for i in A:
  if i in dict:
    dict[i] = dict[i] + 1
  else:
    dict[i] = 1

#print(dict)
total = 0;
for i in dict:
#  print("i:" + str(i) + " " + str(dict[i]))
  total += dict[i]*(dict[i]-1) // 2

#print("T:" + str(total))

for i in A:
  print(total - dict[i] + 1)


Measured memory_bytes: 25644
#include <iostream>

int main(){
  int a, b;
  std::cin >> a >> b;
  if (a > b)
    std::cout << "a > b" << std::endl;
  else if (a < b)
    std::cout << "a < b" << std::endl;
  else
    std::cout << "a == b" << std::endl;
  return 0;
}

Measured memory_bytes: 3092
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <stack>
#include <cmath>
#include <cstring>
#include <climits>
using namespace std;

#define FORN(i, j, k) for(int i=j;i<k;i++)
#define FORR(i, j, k) for(int i=j;i>=k;i--)
#define REP(i, n) FORN(i, 0, n)
#define int long long
#define pii pair<int, int>
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define endl '\n'

const int MODO = 1e+9 + 7;
int n;

void solve(){
	int dp[n][3];
	memset(dp, 0, sizeof(dp));
	int h[3];
	cin >> h[0] >> h[1] >> h[2];
	dp[0][0] = h[0];
	dp[0][1] = h[1];
	dp[0][2] = h[2];
	FORN(i, 1, n){
		cin >> h[0] >> h[1] >> h[2];
		REP(m, 3){
			REP(k, 3){
				if(k!=m){
					dp[i][m] = max(dp[i][m], dp[i-1][k]+h[m]);
				}
			}
		}
	}
	cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]}) << endl;
	return;
}

int32_t main(){
		ios_base::sync_with_stdio(false);
		cin.tie(NULL);
		cin >> n;	
		solve();
		return 0;
}



Measured memory_bytes: 6000
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
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;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

void  base_num(ll data,ll base){
    if(data==0) return;
    ll next=abs(data)%abs(base);
    if(data<0) next=(abs(base)-next)%abs(base);
    base_num((data-next)/base,base);
    cout << next;
}



int main(){
    ll n,m,ans=0;
    cin >> n >> m;
    ans=min(n,m/2);
    m-=ans*2;
    ans+=m/4;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define pp pop_back
#define in insert
#define ff first
#define ss second
#define  show for(int j=0;j<v.size();j++) cout<<v[j]<<" ";
#define ld long double
#define e endl
#define bc __builtin_popcount
#define MOD 1000000007
#define INT_SIZE 32
#define me(x) memset(x,0,sizeof(x))
ll fast_expo(ll x,ll p)
{if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
int main()
{
    int n,k,i;
  cin>>n>>k;
  ll h[n],s=0;
  for(i=0;i<n;i++)
    cin>>h[i];
  sort(h,h+n);
  for(i=0;i<n-k;i++)
    s+=h[i];
  cout<<s<<e;

}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

struct UnionFind{
    int n;
    vector<int> data;
    UnionFind(int _n):n(_n),data(_n,-1){}
    int find(int x){return data[x]<0?x:data[x]=find(data[x]);}
    void unite(int x, int y){
        x=find(x);y=find(y);       
        if(x!=y){
            if(data[y]<data[x]) swap(x,y);
            data[x]+=data[y];data[y]=x;
        }
        return;
    } 
    bool same(int x, int y){return (find(x) == find(y));}
    int size(int x){return -data[find(x)];}
};

int n,m,k;
vector<int> bl[100001];
int fr[100001];
int main(){
    cin>>n>>m>>k;
    UnionFind uf(n);
    int ai,bi;
    rep(i,m){
        cin>>ai>>bi;
        --ai,--bi;
        uf.unite(ai,bi);
        ++fr[ai],++fr[bi];
    }
    rep(i,k){
        cin>>ai>>bi;
        --ai,--bi;
        bl[ai].pb(bi);
        bl[bi].pb(ai);
    }
    rep(i,n){
        int ret=uf.size(i);
        ret-=fr[i];
        for(auto it:bl[i])if(uf.same(i,it)) --ret;
        cout<<ret-1<<" ";
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 6784
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int dp[1<<11];

int main(void){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		memset(dp,0,sizeof(dp));
		string str;
		cin >> str;
		int bits=0;
		bool flag=true;
		int v2=-1;
		for(int i=0;i<str.size();i++){
			if(str[i]=='u'){
				bits=0;
				v2=-1;
			}else{
				if(v2==-1){
					v2=str[i]-'0';
					bits=(1<<v2);
					continue;
				}
				int v=str[i]-'0';
				if((bits>>v) & 1)flag=false;
				dp[bits]|=(1<<v);
				bits|=(1<<v);
			}
		}
		for(int i=0;i<(1<<10);i++){
			for(int j=0;j<i;j++){
				if((i&j)==j){
					if(dp[j]==0 || dp[i-j]==0)continue;
					dp[i]=dp[i]|dp[j];
					dp[i]=dp[i]|dp[i-j];
				}
			}
			bool ok=false;
			for(int k=0;k<10;k++){
				if((!(i>>k & 1)) && (dp[i]>>k & 1))ok=true;
			}
			if(!ok && dp[i]>0)flag=false;
		}
		printf("%s\n",flag?"SAFE":"UNSAFE");
	}
	return 0;
}

Measured memory_bytes: 3284
#include <bits/stdc++.h>
#include <numeric>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;

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

    int K, S; cin >> K >> S;

    int res = 0;
    for (int x = 0; x <= K; ++x) {
        for (int y = 0; y <= K; ++y) {
            int z = S-x-y;
            if (z >= 0 and z <= K) ++res;
        }
    }

    cout << res << endl;
}

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

using namespace std;

int main()
{
  int l, r, d, i;
  int ans=0;
  cin >> l >> r >> d;
  for (i=l; i<=r; i++)
    {
      if (i%d==0)
	ans++;
    }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3624
N,K=map(int,input().split())
D=[]
X=[]
Y=[]

for i in range(N):
    x,y=map(int,input().split())
    D.append([x,y])
    X.append(x)
    Y.append(y)
    
X.sort()
Y.sort()
D.sort()
ans=10**20
for a in range(len(X)):
    for b in range(len(X)-a):
        if len(X)-b-a<K:
            break
        for c in range(len(Y)):
            for d in range(len(Y)-c):
                cnt=0
                for e in range(a,len(X)-b):
                    if X[a]<=D[e][0]<=X[len(X)-1-b] and Y[c]<=D[e][1]<=Y[len(Y)-1-d]:
                        cnt+=1
                if cnt>=K and ans>abs(X[a]-X[len(X)-1-b])*abs(Y[c]-Y[len(Y)-1-d]):
                    ans=abs(X[a]-X[len(X)-1-b])*abs(Y[c]-Y[len(Y)-1-d])
print(ans)

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

using namespace std;
typedef long long int ll;

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n;
	string s;
	cin >> n >> s;
	if(n % 2 == 1)
	{
		cout << "No" << endl;
		return 0;
	}
	else
	{
		if(s.substr(0, n / 2) == s.substr(n / 2, n / 2))
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    v.push_back(k);
  }

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

  int count= 0;

  vector<string> memo;
  for (int i = 0; i < n - 2; i++) {
    for (int j = i + 1; j < n - 1; j++) {
      for (int k = j + 1; k < n; k++) {
	if ((v[i] < v[j] + v[k]) && (v[j] < v[i] + v[k]) && (v[k] < v[i] + v[j])) {
	  count++;
	}
      }
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <numeric>

typedef long long ll;
const ll INF = 1e18;

// Greatest Common Divisor
ll gcd(ll a, ll b)
{
  while (b != 0) {
    a = a % b;
    std::swap(a, b);
  }
  return a;
}

int main(int argc, char* argv[])
{
  int X, t;
  std::cin >> X >> t;

  std::cout << std::max(0, X - t) << std::endl;

  return 0;
}


Measured memory_bytes: 256
/*
[ ( ^ _ ^ ) ]
*/

// problem: practice/practice

import java.io.*;
import java.util.*;


public class Main {
    int INF = (int)1e9;
    long MOD = 1000000007;

    boolean go(long n, long v) {
        if(v==1) return false;
        while(n%v==0 && n>=v) {
            n /= v;
        }
        return n%v==1;
    }

    void solve(InputReader in, PrintWriter out) throws IOException {
        long n = in.nextLong();
        HashSet<Long> set = new HashSet<>();

        long r = 1;
        while(r*r<n) r++;

        for(long i=1; i<=r; i++) {
            if(n%i==0) {
                if(go(n, i)) set.add(i);
                if(go(n, n/i)) set.add(n/i);
            }
        }
        n--;
        for(long i=1; i<=r; i++) {
            if(n%i==0) {
                if(1!=i) set.add(i);
                if(n!=i)set.add(n/i);
            }
        }
        // show("set", set);
        out.println(set.size());
    }
    

    public static void main(String[] args) throws IOException {
        if(args.length>0 && args[0].equalsIgnoreCase("d")) {
            DEBUG_FLAG = true;
        }
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int t = 1;//in.nextInt();
        long start = System.nanoTime();
        while(t-- >0) {
            new Main().solve(in, out);
        }
        long end = System.nanoTime();
        debug("\nTime: " + (end-start)/1e6 + " \n\n");
        out.close();
    }
    
    static boolean DEBUG_FLAG = false;
    static void debug(String s) {
        if(DEBUG_FLAG) System.out.print(s);
    }
    
    public static void show(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }
    
    static class InputReader {
        static BufferedReader br;
        static StringTokenizer st;
    
        public InputReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 22612
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    int N;
    string S;
    cin>>N>>S;
    long long int cou[28]={0};
    for(int i=0;i<N;i++)cou[S[i]-'a']++;
    long long int ans=1;
    for(int i=0;i<26;i++){
        ans*=(cou[i]+1);
        ans%=1000000007;
    }
    ans--;
    if(ans==-1)ans=1000000006;
    cout<<ans<<endl;
    return 0;
}


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

int main() {
    int N, M; cin >> N >> M;
    int na = 0;
    vector<bool> V(N, false);
    vector<int> np(N, 0);

    for (int i = 0; i < M; ++i) {
        int p;
        string s; cin >> p >> s;
        --p;
        
        if (V[p]) continue;
        if (s == "AC") {
            V[p] = true;
            na++;
        } else {
            np[p]++;
        }
        
    }

    int sum = 0;
    for (int i = 0; i < N; ++i) {
        sum += np[i] * V[i];
    }

    cout << na << ' ' << sum << endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
# define fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl "\n"
#define all(v) v.begin(),v.end()
typedef long long ll;

void IO()
{
	#ifndef ONLINE_JUDGE
			freopen("input.txt","r",stdin);
			freopen("output.txt","w",stdout);
	#endif 
}


vector<int> used(200000);
vector<int> adj[200000];
vector<int> a,b;

void bfs(int i)
{	
queue<int> q;
	q.push(i);
	used[i] = 1;
	a.push_back(i);
	while(!q.empty())
	{	i = q.front();
		q.pop();
		for(auto vertex:adj[i])
		{	
			if(used[vertex]==-1)
			{
				used[vertex] = used[i]^1;
				if(used[vertex]==1) a.push_back(vertex);
				else b.push_back(vertex);
				q.push(vertex);
			}
			if(used[vertex]==used[i]){
				cout<<-1;
				exit(0);
			}
			
			
		}


	}
}

void solve()
{
int k,n;cin>>n>>k;
int a[n];
for(int i=0;i<n;i++)
	cin>>a[i];
ll dp[n];
for(int i=0;i<n;i++)
dp[i] = INT_MAX;
dp[0] = 0;
dp[1] = abs(a[1] -a[0]);

for(int i = 2;i<n;i++)
{	
	for(int j = 1;j<=k;j++)
	{
	if(i-j < 0 ) break;
	dp[i] = min(dp[i]  ,  dp[i-j] + abs(a[i-j]-a[i]));
	}
}
cout<<dp[n-1];
}


int main()
{
	IO();
	fast;

	// int t;cin>>t;while(t--)
	solve();

				

	return 0;
}





Measured memory_bytes: 9800
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<utility>//pair
#include<cmath>//abs,sqrt
#include<cstring>
#include<map>
#include<string>
#include<cctype>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
const int INF=1e+9;
const ll INFLL=1e+17;
string a,b,c;
string solve(){
  string res="";
  res+=toupper(a[0]);
  res+=toupper(b[0]);
  res+=toupper(c[0]);
  return res;
}
int main(){
  cin>>a>>b>>c;
  prin(solve());
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a, b, c, d, e, f;
	scanf("%d %d %d %d",&a, &b, &c, &d);

		if (a >= b){
		e = b;
	} else {
		e = a;
	}
	if (c >= d){
	f = d;
} else {
	f = c;
}

	printf("%d\n", e + f);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;
int C[1000]; // コンピュータのログイン時間を覚えておく

char T[10000][1260+1];

int main(){
  int N; // PC数(1000)
  int M; // 学生数(10000)
  int r; // 利用記録数
  int q; // 質問数
  int  k,m,t;
  int n, s, ts, te;

  while (1) {
    for (int i = 0; i < 10000; i++) {
      for (int j = 0; j <= 1260; j++) {
	       T[i][j] = 0;
      }
    }
    cin >> N >> M;
    if (N == 0 && M == 0)
      return 0;

    cin >> r; // 利用記録数
    //cout << r << endl;
    for (int i = 0; i < r; i++) {
      cin >> t >> n >> m >> s;
      //cout << t << ","<< n << ","<< m << ","<< s ;
      // t 時刻 (540～1260)
      // n PC番号
      // m 学生番号
      // s (1:ログイン、0:ログアウト)
      if (s == 1) {
	       C[n] = t; // PC番号
      } else if (s == 0) {
	       for ( int j = C[n]; j < t; j++){
	          T[m][j] = 1;
          }
      }
    }
      cin >> q; // 質問数
    for (int i = 0; i < q; i++) {
      cin >> ts >> te  >> m;
      k = 0;

      for (int j = ts; j < te; j++) {
        if (T[m][j] == 1){
          k++;
         }
       }
        cout << k  << endl;

     }
   }
    return 0;
}



Measured memory_bytes: 15412
N,M = [int(i) for i in input().split(" ")]
ans_L = 0
ans_R = 1e5+1

for _ in range(M):
    L,R = [int(i) for i in input().split(" ")]
    if ans_L < L:
        ans_L = L
    if ans_R > R:
        ans_R = R

if (ans_R - ans_L) >= 0:
    print(ans_R - ans_L + 1)
else:
    print(0)

Measured memory_bytes: 3064
import java.util.*;


public class Main {


    public static void main(String[] args) {
       Scanner sc=new Scanner(System.in);
       int n=sc.nextInt();
       String s=sc.next();
       if(s.length()>n)
       {
           for(int i=0;i<n;i++)
           {
               System.out.print(s.charAt(i));

           }
           System.out.print("...");
       }
       else
       System.out.print(s);

}
}


Measured memory_bytes: 35752
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdio>
#include<set>
#include<map>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repn(i, n) for(int i = 1; i <= n; i++) 
#define lint long long
#define all(x) (x).begin(), (x).end()

int main(){
    long N, K; cin >> N >> K;
    long A[N]; long S[N+1];

    rep(i, N) cin >> A[i];

    S[0] = 0;
    repn(i, N) S[i] = S[i-1] + A[i-1];
    repn(i, N) S[i] = (S[i]-i) % K;

    map<long, long> mod;
    int end = min(N, K-1); long ans = 0;
    
    repn(i, end) mod[S[i]]++;
    ans += mod[0];
    repn(i, N-1){
        mod[S[i]]--;
        if(end < N){
            end++;
            mod[S[end]]++;
        }
        ans += mod[S[i]];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 15872
import java.util.*;
import java.io.*;
public class Main{
	static boolean match(String temp,int start,String str){
		if(start + temp.length() > str.length())return false;
		//System.out.println(temp + " " + start + " " + str);
		for(int j =  0;j < temp.length();j++){
			//if(start == 5)System.out.println(temp.charAt(j) + " " + str.charAt(j + start));
			if(temp.charAt(j) != str.charAt(j + start))return false;
		}
		return true;
	}
	public static void main(String[] args) throws Exception{
            String array[] = new String[]{"dreamer","dream","eraser","erase"};
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String str = br.readLine();
            int start = 0;
            int last = -1;
            while(start < str.length() && start >= 0){
            	boolean flag = false;
				for(int j = 0;j < 4;j++){
        			if(match(array[j],start,str)){
        				start += array[j].length();
        				flag = true;
        				last = j;
        				break;
        			}
        		}
        		if(!flag && last == 0){
        			start -= 2;
        			last = -1;
        		}
        		else if(!flag)break;
        		//System.out.println(start + " " + str.length());
            }
            if(start == str.length())System.out.println("YES");
            else System.out.println("NO");
	}
}

Measured memory_bytes: 10960
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    ll n;
    cin >> n;
    if(n % 2 != 0 || n < 10){
        cout << 0 << endl;
        return 0;
    }
    ll ans = 0;
    ll foo = 10;
    while(foo <= n){
        ans += n / foo;
        foo *= 5;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		while (true) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			int max = 0;

			if (a == 0 && b == 0 && c == 0)
				return;

			for (int i = 1; i < c; i++) {
				for (int j = 1; j < c; j++) {
					if (i * (100 + a) / 100 + j * (100 + a) / 100 == c)
						max = Math.max(max, i * (100 + b) / 100 + j * (100 + b) / 100);
				}
			}

			System.out.println(max);
		}

	}
}


Measured memory_bytes: 28988
/* Author : A110011 - 00:19 "CodeIn Hard Way" */

#include<bits/stdc++.h>

#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define sp(x,y)         fixed<<setprecision(y)<<x
typedef long long int ll;

using namespace std;


void dfs(int i,vector<int> &vst,vector<int> &dp,map<int,vector<int>> &mp){
    
    vst[i]=1;
    
    
    
    for(int j=0;j<mp[i].size();j++){
        if(!vst[mp[i][j]]){
            dfs(mp[i][j],vst,dp,mp);
        }
        
        dp[i]=max(dp[i],1+dp[mp[i][j]]);
    }
    
    
}

int main(){

	// For fast I/O.
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    
   /* #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif */
    
   
    int m,n;
    
    cin>>n>>m;
    
    map<int,vector<int>> mp;
    
    for(int i=0;i<m;i++){
        int u,v;
        cin>>u>>v;
        mp[u].push_back(v);
    }
   
    vector<int> dp(n+1,0);
    vector<int> vst(n+1,0);
    
   for(int i=1;i<=n;i++){
        if(!vst[i]){
            int cnt=0;
            dfs(i,vst,dp,mp);
        }
   }

    int mx=dp[1];
for(int i=2;i<n+1;i++){
    if(dp[i]>mx){
        mx=dp[i];
    }
}

cout<<mx<<endl;
return 0; 
}


Measured memory_bytes: 17408
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

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

  vector<long long> c(n - 1), s(n - 1), f(n - 1);
  for (int i = 0; i < n - 1; i++) {
    cin >> c[i] >> s[i] >> f[i];
  }

  for (int i = 0; i < n; i++) {
    long long curr = 0;
    for (int j = i; j < n - 1; j++) {
      curr = max(s[j], (curr + f[j] - 1) / f[j] * f[j]) + c[j];
    }
    cout << curr << endl;
  }
}


Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BC
import Data.Maybe
import Data.List

readIntLines :: IO [Int]
readIntLines = map (fst . fromJust . BC.readInt) . BC.lines <$> BC.getContents

solve :: Int -> [Int] -> Int
solve m [] = 0
solve m (s:ss)
  | m `mod` 10 /= 0 = m
  | otherwise = solve (m - s) ss

main :: IO ()
main = do
  getLine
  ss <- sort <$> readIntLines
  let m = sum ss
  print $ solve m $ filter ((/= 0) . (`mod` 10)) ss

Measured memory_bytes: 508
#include <stdio.h>

int main(void)
{
	int W, H, x, y, r;
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

	if (x + r > W || x - r < 0)
	{
		if (y + r > H || y - r < 0)
		{
			printf("No\n");
		}
		else if (y + r <= H && x - r >= 0)
		{
			printf("No\n");
		}
		else
		{
	        printf("No\n");
		}
	}
	
	else if (x + r <= W && x - r >= 0)
	{
		if (y + r > H || y - r < 0)
		{
			printf("No\n");
		}	
	    else if (y + r <= H && y - r >= 0)
		{
		    printf("Yes\n");
		}
	}
	
	return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if((abs(b-a) <= d && abs(c-b) <= d) || abs(c-a) <= d){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256