akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin >> s;

	int sz=s.size(), t=0, ten=1;
	map<int,int> mp;
	mp[0]=1;
	for(int i=1; i<=sz; ++i){
		int a=stoi(s.substr(sz-i,1));
		a = a*ten;
		t = (t+a)%2019;
		++mp[t];
		ten = ten*10%2019;
	}

	int ans=0;
	for(auto i: mp){
		ans += i.second*(i.second-1)/2;
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 3752
#WA aiはbiの親であるとは限らない
#有向グラフかと思ったけど違かった無向グラフ
#訪れたことのあるとこにはフラグをたてる
#グラフの隣接リストによる実装

import collections

class edge:
#    def __init__(self,to,cost):
    def __init__(self,to):
        self.to = to
        #self.cost = cost

#N個の頂点、N-1個の辺、Q操作回数
N,Q = map(int,(input().split()))
 
#添字と入力が1ずれるので注意
#グラフ (iがグラフの頂点、G[i]に隣接するグラフが入っている)
G = [ [] for row in range(N)]
for i in range(N-1):
    #sからtへ辺を張る
    s,t = map(int,input().split())
    #添字調整
    s -= 1
    t -= 1
    G[s].append(edge(t))
    #無向グラフなので逆にも張る
    G[t].append(edge(s))
 
#各頂点以下に加算する重み
ans = [0] * N
for i in range(Q):
    #頂点pにxの重みをつける
    p,x = map(int,input().split())
    #添字調整
    p -= 1
    ans[p] += x

#DFSのスタックによる実装、まずスタックに始点1を積む
q=collections.deque()
q.append(0) 

#訪れたことのあるとこにはいかないようにチェックする
check = [0] * N

while q:
    v=q.pop()
    #頂点を見たかどうかのフラグを更新する
    check[v]=1 
    for i in G[v]:
        #vの子ノードuについて、まだ見ていない頂点であればcount[u]をcount[u]+=count[v]として更新する
        if check[i.to]==1: 
            continue
        ans[i.to]+=ans[v]
        q.append(i.to) #スタックに子ノードuを積む
 
print(" ".join(map(str,ans)))


Measured memory_bytes: 150392
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
#define step b=p[b];d+=c[b];a=max(a,d);

int main(){
	ll n,k,a=(ll)-1e10;
	cin>>n>>k;
	ll p[n+1],c[n+1];
	rep(i,n)cin>>p[i];
	rep(i,n)cin>>c[i];
	rep(i,n){
		ll b=i,d=0,e=0;
		step;e++;
		if(k<n){while(e<k){step;e++;}}
		else{
			while(b!=i){step;e++;}
			d=d*(k/e-1);
			rep(j,e+k%e){step;}
        }
	}
	cout<<a<<endl;
}


Measured memory_bytes: 3720
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main(){
    int n,a,b,acnt=0,bcnt=0;cin>>n>>a>>b;
    string s;cin>>s;
    for(char c:s){
        if(c=='c')cout<<"No"<<endl;
        else if(c=='a'){
            if(acnt+bcnt<a+b){
                acnt++;
                cout<<"Yes"<<endl;
            }
            else cout<<"No"<<endl;
        }
        else{
            if(acnt+bcnt<a+b&&bcnt<b){
                bcnt++;
                cout<<"Yes"<<endl;
            }
            else cout<<"No"<<endl;
        }
    }
}


Measured memory_bytes: 3724
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <set>
#include <map>

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define for_p(i, a, b) for(int i = a; i < b; i++)
#define for_m(i, a, b) for(int i = a - 1; i >= b; i--)

//a = s1.size();
//vector<string> s1;
//string s2 = accumulate( s1.begin(), s1.end(), string() );

using namespace std;

int main()
{
  int a = 0 , b = 0, c = 0, d = 0, e = 0, f = 0;
  int i = 0, j = 0;
  double d1 = 0, d2 = 0, d3 = 0, d4 = 0, d5 = 0, d6 = 0;
  int a1[100000], a2[512], a3[1024];
  char s1[200000], s2[200000], s3[200000];
  
  cin >> a;
  
  for(i = 0; i < a; i++){
    cin >> a1[i];
    b += a1[i];
  }
  if(b % 2 == 0){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}



Measured memory_bytes: 640
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
A = list(map(int,input().split()))
dp0 = [0] * (n+11)
dp1 = [0] * (n+11)
dp2 = [0] * (n+11)
for i,ai in enumerate(A):
  dp2[i+11] = (max(dp0[i+7] + ai, dp1[i+8] + ai, dp2[i+9] + ai) if i >= 2 else 0)
  dp1[i+11] = (max(dp0[i+8] + ai, dp1[i+9] + ai) if i >= 1 else 0)
  dp0[i+11] = dp0[i+9] + ai 
if n % 2 == 0:
  print(max(dp0[n + 9], dp1[n + 10]))
else:
  print(max(dp0[n + 8], dp1[n + 9], dp2[n + 10]))

# debug
# print(dp0,dp1,dp2,sep="\n")




Measured memory_bytes: 50944
# -*- coding: utf-8 -*-

import math

def main():
    n = int(input())
    if n == 0:
        print('0')
        return

    bits = []
    while n != 0:
        qf = n / -2
        q = math.ceil(qf)
        m = n % -2
        bits.append('0' if m == 0 else '1')
        n = q

    print(''.join(reversed(bits)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<stdio.h>
#include<string>
using namespace std;

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

	int X[110];
	for (int i = 0; i < N; ++i)cin >> X[i];
	sort(X, X + N);
	long sum[110] = { 0 };
	int max = X[N-1];
	long sum_min = 1000000000;
	for (int i = 1; i <= max; ++i) {
		for (int j = 0; j < N; ++j) {
			sum[i] += pow(X[j] - i, 2);
		}
		if (sum[i] < sum_min)sum_min = sum[i];
	}
	cout << sum_min << endl;

	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll e5 = 1 << 21;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 62;

ll n;
ll t[e5];
ll v[e5];
ll x;
ll speed;
ll max_speed_l[e5];
ll max_speed_r[e5];
ll max_speed[e5];
ll ans;

int main(){
  cout << setprecision(17);
  cin >> n;
  for(ll i = 1;i <= n;i++) cin >> t[i];
  for(ll i = 1;i <= n;i++) cin >> v[i];
  for(ll i = 1;i <= n;i++) t[i] *= 2;
  for(ll i = 1;i <= n;i++) v[i] *= 2;
  for(ll i = 1;i <= n;i++) t[i] += t[i-1];
  x = 0;
  speed = 0;
  for(ll i = 1;i <= n;i++){
    for(;x < t[i];x++){
      max_speed_l[x] = speed;
      speed = min(speed+1,v[i]);

    }
  }
  x = t[n];
  speed = 0;
  for(ll i = n;i >= 1;i--){
    for(;x > t[i-1];x--){
      max_speed_r[x] = speed;
      speed = min(speed+1,v[i]);
    }
  }
  for(ll x = 0;x <= t[n];x++){
    max_speed[x] = min(max_speed_l[x],max_speed_r[x]);
  }
  for(ll x = 0;x < t[n];x++){
    ans += max_speed[x]+max_speed[x+1];
  }
  printf("%lf\n", ans/8.0);
  // cout << setprecision(17) << ans/8.0 << endl;;

}


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

int main(){
  int n,ans = 0,x = 0;
  string str;
  cin >> n >> str ;
  for(int i = 0; i < n; i++){
    if(str[i] == 'I'){
      x++;
      ans = max(x,ans);
    }else{
      x--;
      ans = max(x,ans);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
use std::io;

fn main() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    let n = s.trim().parse::<usize>().unwrap();
    let mut a = String::new();
    io::stdin().read_line(&mut a).unwrap();
    let mut v = a.trim().split_whitespace().flat_map(str::parse::<i64>).collect::<Vec<_>>();
    for i in 0..n { v[i] -= i as i64 + 1; }
    v.sort();
    let b = v[n / 2];
    println!("{}", v.iter().map(|&x| (x - b).abs()).sum::<i64>());
}

Measured memory_bytes: 10492
import heapq
from collections import defaultdict
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

d = defaultdict(list)
for i in range(N):
    a = A[i]
    b = B[i]
    if a==b:
        d[a].append(i)

h = []
for a in d:
    heapq.heappush(h,(-len(d[a]),a))

while len(h)>=2:
    x,a = heapq.heappop(h)
    y,b = heapq.heappop(h)
    i = d[a].pop()
    j = d[b].pop()
    B[i],B[j] = B[j],B[i]
    x += 1
    y += 1
    if x<0:
        heapq.heappush(h,(x,a))
    if y<0:
        heapq.heappush(h,(y,b))

ans = "Yes"
if h:
    x,a = heapq.heappop(h)
    if len(d[a])*2>N:
        ans = "No"
    else:
        d[a] = d[a][::-1]
        for i in range(N):
            if len(d[a])==0:
                break
            if A[i] != a and B[i] != a:
                j = d[a].pop()
                B[i],B[j] = B[j],B[i]
if len(d[a])>0:
    ans = "No"                
print(ans)
if ans=="Yes":
    print(*B)

Measured memory_bytes: 143704
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt(), a, v, max = Integer.MIN_VALUE, maxNum = Integer.MAX_VALUE;
        for(int i = 0; i < n; i++) {
        	a = sc.nextInt();
        	v = sc.nextInt();
        	
        	
        	if(v > max) {
        		max = v;
        		maxNum = a;
        	}
    		if(v == max)
    			maxNum = Math.min(maxNum, a);
        }
        
        System.out.println(maxNum + " " + max);
    }
}

Measured memory_bytes: 26264
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N; 
  cin >> N;

  int ans = 0;
  REP(i, N){
    int A;
    cin >> A;
    while(A%2 == 0) A /= 2, ans++;
  }

  cout << ans << "\n";

  return 0;
}

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

int main(){
    long long n, a, b;
    cin >> n >> a >> b;
    long long count = n / (a+b);
    long long remainder = n % (a+b);
    long long ans = a * count;
    if(remainder < a) ans += remainder;
    else ans += a;
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
import sys


def solve(lines):
    lines = [int(x) for x in lines]

    a = lines[0]
    e = lines[4]
    k = lines[5]

    if e - a <= k:
        print('Yay!')
    else:
        print(':(')


if __name__ == '__main__':
    lines = sys.stdin.read()
    lines = lines.strip().split('\n')
    solve(lines)


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

using namespace std;

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

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

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int n, l;
	cin >> n >> l;
	vector<int> t(n);
	int sum = 0;
	rep (i, n) {
	  t[i] = l + i;
	  sum += t[i];
	}
	int diff = Inf;
	int res = 0;
	rep (i, n) {
	  int after = sum - t[i];
	  if (abs(sum - after) < diff) {
		diff = abs(sum - after);
		res = after;
	  }
	}
	cout << res << endl;
	
    return 0;
}



Measured memory_bytes: 3580
#include <iostream>
#include <math.h>
using namespace std;
int main(){
int step,turn;
double x=0,y=0,angle=0;
while(1){
scanf("%d,%d",&step,&turn);
if(!step&&!turn)break;
x+=(double)step*sin(angle*M_PI/180);
y+=(double)step*cos(angle*M_PI/180);
angle+=(double)turn;
}
cout << (int)x << endl;
cout << (int)y << endl;
return 0;
}

Measured memory_bytes: 0
n=int(input())
a=list(map(int,input().split()))

d={}
for i in range(n):
    d[a[i]-1] = d.get(a[i]-1,0)+1
    d[a[i]] = d.get(a[i],0)+1
    d[a[i]+1] = d.get(a[i]+1,0)+1
print(max(d.values()))

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

typedef long long ll;
using namespace std;

bool is_prime(int n) {
    for (int i = 2; i * i <= n; i++)
        if (n % i == 0)
            return false;
    return true;
}

vector<int> PRIMES;
void init(int n) {
    for (int i = 2; i <= n; i++) {
        if (is_prime(i))
            PRIMES.push_back(i);
    }
}

vector<int> primes(int n) {
    vector<int> ret;
    for (int p : PRIMES) {
        if (n % p == 0) {
            n /= p;
            ret.push_back(p);
            while (n % p == 0) {
                n /= p;
                ret.push_back(p);
            }
        }
        if (n == 1) {
            break;
        }
    }
    return ret;
}

int main() {
    int n;
    cin >> n;
    init(n);
    map<int, int> mp;
    for (int i = 2; i <= n; i++) {
        vector<int> pr = primes(i);
        for (int p : pr) {
            if (mp.count(p))
                mp[p]++;
            else
                mp[p] = 1;
        }
    }
    int ans = 0;
    // 2 4 4
    int c2 = 0;
    int c4 = 0;
    int c14 = 0;
    int c24 = 0;
    int c74 = 0;
    for (auto m : mp) {
        if (m.second >= 74) {
            c74++;
        }
        if (m.second >= 24) {
            c24++;
        }
        if (m.second >= 14) {
            c14++;
        }
        if (m.second >= 4) {
            c4++;
        }
        if (m.second >= 2) {
            c2++;
        }
    }
    if (c4 >= 2) {
        ans += (c2 - 2) * (c4 - 1) * c4 / 2;
    }
    if (c14 >= 1) {
        ans += (c4 - 1) * c14;
    }
    if (c24 >= 1) {
        ans += (c2 - 1) * c24;
    }
    if (c74 >= 1) {
        ans += c74;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
from itertools import product, groupby
from math import pi
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = 10 ** 10


def main():
    N = int(input())
    ans = 0
    for _ in range(N):
        l, r = map(int, input().split())
        ans += r - l + 1
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
int cul(int i){
  int sum=0;
  while(i>0){
    sum+=i%10;
    i=i/10;
  }
  return sum;
}
int main() {
  int n,a,b;
  cin>>n>>a>>b;
  int total=0;
  repi(i,1,n+1){
    int sum=cul(i);
    if(sum>=a&&sum<=b) total+=i;
  }
  cout<<total<<endl;
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
using large = long long;
constexpr int M = 1'000'000'007;
int main() {
    int n, k;
    cin >> n >> k;

    auto sum_fwd = vector<large>(n + 2);
    auto sum = 0LL;
    for (int i = 0; i <= n; i++) {
        sum += i;
        sum_fwd[i + 1] = sum;
    }

    auto sum_bak = vector<large>(n + 2);
    sum = 0LL;
    for (int i = n; i >= 0; i--) {
        sum += i;
        sum_bak[n - i + 1] = sum;
    }

    auto cases = 0LL;
    for (int cnt = k; cnt <= n + 1; ++cnt) {
        auto first = sum_fwd[cnt];
        auto last = sum_bak[cnt];
        (cases += (last - first + 1)) %= M;
    }
    cout << cases;
    return 0;
}


Measured memory_bytes: 6356
import sys
sys.setrecursionlimit(10000000)
# input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
import functools
import itertools
import math
INF = float('inf')
MOD = 10**9+7

# nCk % mod
# def modCom(n, k, mod):
#     p, q = 1, 1
#     for i in range(n-k+1, n+1):
#         p = (p * i) % mod
#     for i in range(2, k+1):
#         q = (q * i) % mod
#     return p * pow(q, mod-2, mod) % mod
# 
# X, Y = map(int, input().split())
# l, r = -1, X//2
# while l+1 < r:
#     m = (l+r)//2
#     n = X-2*m
#     if 2*n+m > Y:
#         l = m
#     else:
#         r = m
# m = r
# n = X-2*r
# if 2*m+n == X and m+2*n == Y:
#     print(modCom(n+m, n, MOD))
# else:
#     print(0)


N = int(input())
xy = [None]*N
for i in range(N):
    x, y = map(int, input().split())
    xy[i] = (x, y)
ans = 0
for vs in itertools.permutations(xy, N):
    d = 0
    for v1, v2 in zip(vs, vs[1:]):
        d += ((v1[0]-v2[0])**2+(v1[1]-v2[1])**2)**0.5
    ans += d
for i in range(1, N+1):
    ans /= i
print(ans)



# r = int(input())
# print(r*r)

# 
# N = int(input())
# S = input()
# for i in range(N):
#     T = S[:i]
#     if T + T == S:
#         print('Yes')
#         exit()
# print('No')


Measured memory_bytes: 40940
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ in >> p.first >> p.second; return in; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
template <char d = ' ', class T>
ostream& operator << (ostream& out, vector<T>& v){ for(auto& e : v){ out << e << d; } return out; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> as(n), bs(n);
    cin >> as >> bs;
    int ans = 0;
    for(int i = 28; i >= 0; i--){
        for(auto& a : as){ a &= (2 << i) - 1; }
        for(auto& b : bs){ b &= (2 << i) - 1; }
        sort(as.begin(), as.end());
        sort(bs.begin(), bs.end());
        int num = 0;
        for(auto& a : as){
            // auto xx = lower_bound(bs.begin(), bs.end(), (1 << i) - a);
            // auto yy = lower_bound(xx, bs.end(), (2 << i) - a);
            // auto zz = lower_bound(yy, bs.end(), (3 << i) - a);
            // int x = xx - bs.begin();
            // int y = yy - bs.begin();
            // int z = zz - bs.begin();
            int x = lower_bound(bs.begin(), bs.end(), (1 << i) - a) - bs.begin();
            int y = lower_bound(bs.begin(), bs.end(), (2 << i) - a) - bs.begin();
            int z = lower_bound(bs.begin(), bs.end(), (3 << i) - a) - bs.begin();
            num += y - x + n - z;
        }
        ans |= num & 1 ? 1 << i : 0;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 1792
from bisect import bisect_left
import sys
sys.setrecursionlimit(10**7)
# input = sys.stdin.readline

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

INF = 999999999999999999999999

n = int(input())
A = [-INF] + get_nums_l()

log(n)
log(A)

edges = [ [] for _ in range(n+1) ]
for _ in range(n-1):
#for line in map(lambda s: s.strip(), sys.stdin.readlines()):
    line = input()
    log(line)
    u,v = map(int, line.split())
    edges[u].append(v)
    edges[v].append(u)

def dfs(dp, u, p=None):

    # log(u)
    # log(dp)

    # dpの中でA[u]以上の値が入っている最小のindex
    i = bisect_left(dp, A[u])

    old = dp[i]
    dp[i] = A[u]

    # 有効値(INF以外)が入っている最大のindex
    ans[u] = bisect_left(dp, INF) - 1

    for v in edges[u]:
        if v == p:
            continue
        dfs(dp, v, u)

    # 巻き戻し
    dp[i] = old

# ans[i] = ノード1からノードiへの経路中の最長増加部分列長
ans = [0] * (n+1)

# dp[i] = 最長増加部分列長がiの場合の末尾ノード値の最小
# dp[0]は使用しないので負の無限大を入れておく
dp = [INF] * (n+1)
dp[0] = -INF

dfs(dp, 1, None)

for i in range(1, n+1):
    print(ans[i])


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

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

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

    ll N;
    cin >> N;
    Vl A(N), B(N), C(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (ll i = 0; i < N; i++) {
        cin >> B[i];
    }
    for (ll i = 0; i < N; i++) {
        cin >> C[i];
    }
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());

    Vl csum1(N + 1);
    ll idx = 0;
    for (ll i = 0; i < N; i++) {
        while (idx < N && B[i] >= C[idx]) ++idx;
        csum1[i + 1] = csum1[i] + (N - idx);
    }

    ll ans = 0;
    idx = 0;
    for (ll i = 0; i < N; i++) {
        while (idx < N && A[i] >= B[idx]) ++idx;
        ans += csum1[N] - csum1[idx];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
namespace solver{
	int n;
	string s;
	int dp[500010];
	void solve(){
		cin>>n>>s;
		for(int i=3,ls=0;i<=n;++i){
			dp[i]=dp[i-1];
			if(s[i-3]=='1'&&s[i-2]=='0'&&s[i-1]=='1'){
				ls=i;
				for(int j=i-2;s[j-1]!='0'&&j>=1;--j){
					dp[i]=max(dp[i],dp[j-1]+(i-j-1));
				}
			}
			if(s[i-1]=='0')ls=0;
			if(s[i-1]=='1'&&ls){
				dp[i]=max(dp[i],dp[ls-3]+i-ls+1);
			}
		}
		cout<<dp[n]<<endl;
	}
}

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

Measured memory_bytes: 2820
#include <stdio.h>
int main()
{
  int Fib[44],i,n;
 
  Fib[0]=1;
  Fib[1]=1;

  scanf("%d",&n);
  for(i=2; i<=n; i++) {
    Fib[i]=Fib[i-1]+Fib[i-2];
  }
 
  printf("%d\n",Fib[n]);
 
  return 0;
}

Measured memory_bytes: 596
import sys
import math
from collections import Counter
import itertools
import fractions
#from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

# ###########################################

A,B=MI()

if B%A==0:
    print(A+B)
else:
    print(B-A)

Measured memory_bytes: 5048
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;

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

const ll MAX_N = 1e5 + 5;
int n, ans;
vector <pii> G[MAX_N];
int col[MAX_N];
bool mark[MAX_N];

void dfs (int v, int p = 0) {
    int d = G[v].size();
    ans = max(ans, d);
    for (int j = 1; j <= d; j++)
        mark[j] = false;

    for (pii u: G[v])
        mark[col[u.second]] = true;

    int tmp = 1;
    while (mark[tmp])
        tmp++;

    for (pii u: G[v])
        if (!col[u.second]) {
            col[u.second] = tmp;
            
            mark[tmp] = true;
            while (mark[tmp])
                tmp++;
        }

    for (pii u: G[v])
        if (u.first != p)
            dfs(u.first, v);
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int v, u;
        cin >> v >> u;
        v--, u--;

        G[v].push_back({u, i});
        G[u].push_back({v, i});
    }

    dfs(0);
    cout << ans << "\n";
    for (int i = 0; i < n - 1; i++)
        cout << col[i] << "\n";
    return 0;
}

Measured memory_bytes: 8704
#include<stdio.h>

int main(){

    int a, b;

    scanf("%d %d", &a, &b);

    if (a < b) {
        puts ("a < b");
    }else if (a == b) {
        puts ("a == b");
    }else if (a > b) {
        puts ("a > b");
    }

return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
#define ll  long long
#define ull unsigned long long  
using namespace std;
#define  inf 1e9+18
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define  f1(i,n) for(i=1;i<=n;i++)
#define f0(i,n)  for(i=0;i<n;i++)
#define w(x)   while(x--)
const int maxn=105;
#define  pq priority_queue
#define  ff first
#define  ss second 
#define pb  push_back
#define lb lower_bound
#define ub upper_bound
#define pie 3.14159265359
#define mod 1000000007
 ll dp[102][100005],c[100005],b[100005];
int main()
{   // fastio;
	ll  n,k,i,j;
	cin>>n>>k;
	ll  a[n];
	for(i=0;i<n;i++)
   {
   	cin>>a[i];

   }
  
  for(i=0;i<=k;i++)
  {
  	
  	if(i<=a[0]){
  		dp[1][i]=1;
  		c[i]=1;
  	}
  	else{
  		dp[1][i]=0;
  		c[i]=0;
  	}
  	if(i>=1)
  		c[i]=(c[i-1]%mod+c[i]%mod)%mod;

  }
  for(i=2;i<=n;i++)
  {
    
  	for(j=0;j<=k;j++){
  	if(i%2==0)
  	{
  		if(j==0){
  			b[j]=dp[i][j]=dp[i-1][j];

  		}
  		else
  		{
  			ll m=j-a[i-1]-1;
  			if(m<0)
  				b[j]=dp[i][j]=c[j];
  			else
  					b[j]=dp[i][j]=(c[j]-c[m]+mod)%mod;
         if(j>=1)
         	b[j]=(b[j-1]%mod+b[j]%mod)%mod;
  		}

  	}
  	else
  	{
  		if(j==0){
  			c[j]=dp[i][j]=dp[i-1][j];

  		}
  		else
  		{
  			ll m=j-a[i-1]-1;
  			if(m<0)
  				c[j]=dp[i][j]=b[j];
  			else
  					c[j]=dp[i][j]=(b[j]-b[m]+mod)%mod;
         if(j>=1)
         	c[j]=(c[j-1]%mod+c[j]%mod)%mod;
  		}


  	}
  }
  }

cout<<dp[n][k];
 
}


Measured memory_bytes: 80256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define int long long
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, l, t;
    cin >> n >> l >> t;
    vi one, two;
    vi x(n), w(n);
    rep(i, n) {
        cin >> x[i] >> w[i];
        if(w[i] == 1) one.push_back(x[i]);
        else two.push_back(x[i]);
    }

    int kk = one.size();
    rep(i, kk) one.push_back(one[i] - l);
    rep(i, kk) one.push_back(one[i] - l*2);
    kk = two.size();
    rep(i, kk) two.push_back(two[i] + l);
    rep(i, kk) two.push_back(two[i] + l*2);
    sort(all(one));

    vi ans(n);
    rep(i, n) {
        int xx;
        if(w[i] == 1) {
            xx = (t + x[i])%l;
            if(two.size() == 0) {
                ans[i] = xx;
                continue;
            }
            int num = t/l * (two.size()/3);
            num <<= 1;
            int time = t%l;
            auto itr = upper_bound(all(two), x[i]+time*2);
            auto uitr = lower_bound(all(two), x[i]);
            ans[(i + num + (itr - uitr))%n] = xx;
            //cout << (i + num + (itr - uitr))%n << ' ' << xx << endl;
        } else {
            xx = (x[i] - t%l + l)%l;
            if(one.size() == 0) {
                ans[i] = xx;
                continue;
            }
            int num = t/l * (one.size()/3);
            num <<= 1;
            int time = t%l;
            auto itr = lower_bound(all(one), x[i]-time*2);
            auto uitr = upper_bound(all(one), x[i]);
            ans[(i - num%n - (uitr - itr)%n + 2*n)%n] = xx;
            //cout << (i - num%n - (uitr - itr)%n + 2*n)%n << ' ' << xx << endl;
        }
    }

    rep(i, n) {
        cout << ans[i] << '\n';
    }
}

Measured memory_bytes: 8748
import Data.List.Split
main = do
    line <- getContents
    let dataSet = map (map read.splitOn ",").lines $ line
        result = map (\list -> getZone (take 10 list) (list !! 10) (list !! 11)) dataSet
    mapM_ print result


getZone distList v1 v2 = fst.head.filter (\(i,b) -> b).map (fmap (isInRange d)).zoneBound $ distList
    where d = midDistance distList v1 v2

isInRange d (l,r) = d > l && d <= r

zoneBound distList = zip [1..10] boundlist
    where boundlist = zip sumOfDistance (tail sumOfDistance)
          sumOfDistance = scanl (+) 0 distList

midDistance distList v1 v2 = v1*t
    where t =sum distList / (v1+v2)

Measured memory_bytes: 4208
#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <functional>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 1145141919
#define ll long long
//#define scanf scanf_s

struct edge{ int from, to, cost; };
int v, e, r;
edge es[500001];
int s, t, d;

int main()
{
	cin >> v >> e >> r;
	REP(i, e)
	{
		cin >> s >> t >> d;
		es[i] = { s, t, d };
	}
	int d[100001];
	fill(d, d + 100001, INF);
	d[r] = 0;
	while (1)
	{
		bool f = true;
		REP(i, e)
		{
			edge e = es[i];
			if (d[e.from] != INF&&d[e.to] > d[e.from]+e.cost)
			{
				d[e.to] = d[e.from] + e.cost;
				f = false;
			}
		}
		if (f) break;
	}
	REP(i, v)
	{
		if(!(d[i]==INF)) cout << d[i] << endl;
		else cout << "INF" << endl;
	}
	return 0;
}

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

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

const ll INF=LLONG_MAX;
ii cnt[2][100001];
int a[100001];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int n; cin >> n;
	for(int i=0; i<=1e5; i++){
		cnt[0][i].fi=cnt[1][i].fi=n/2;
		cnt[0][i].se=cnt[1][i].se=i;
	}
	for(int i=0; i<n; i++){
		cin >> a[i];
		cnt[i%2][a[i]].fi--;
	}
	sort(begin(cnt[0]),end(cnt[0]));
	sort(begin(cnt[1]),end(cnt[1]));
	if(cnt[0][0].se==cnt[1][0].se){
		cout << min(cnt[0][0].fi+cnt[1][1].fi,cnt[0][1].fi+cnt[1][0].fi) << endl;
	}else{
		cout << cnt[0][0].fi+cnt[1][0].fi << endl;
	}
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN


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

int main() {
	int n, h[21], max[21];
	int ans = 1;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> h[i];
		
	}

	for (int i = 0; i < n; i++) {
		if (i == 0)max[i] = h[i];
		else {
			if (h[i] < max[i - 1]) max[i] = max[i - 1];
			else max[i] = h[i];
		}

	}
	cout << endl;
	for (int i = 1; i < n; i++) {
		if (h[i] >= max[i]) ans++;
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = getInt(sc);
		int[] p = getIntArray(sc);
		int[] q = getIntArray(sc);

		int[] numArray = new int[n];
		for (int i = 0; i < n; i++) {
			numArray[i] = i + 1;
		}
		List<Integer[]> permutation = getPermutation(numArray);

		int pIndex = -1;
		int qIndex = -1;
		for (int i = 0; i < permutation.size(); i++) {
			Integer[] perm = permutation.get(i);
			if (pIndex == -1 && isEqual(perm, p)) {
				pIndex = i;
			}

			if (qIndex == -1 && isEqual(perm, q)) {
				qIndex = i;
			}
		}
		System.out.println(Math.abs(pIndex - qIndex));
	}

	private static boolean isEqual(Integer[] perm, int[] target) {
		for (int i = 0; i < perm.length; i++) {

			if (perm[i].intValue() != target[i]) {

				return false;
			}
		}
		return true;
	}

	private static List<Integer[]> getPermutation(int[] numArray) {
		List<Integer[]> permutation = new ArrayList<>();
		Integer[] ans = new Integer[numArray.length];
		boolean[] used = new boolean[numArray.length];

		return buildPermutaion(permutation, numArray, ans, used, 0);
	}

	private static List<Integer[]> buildPermutaion(List<Integer[]> list, int[] numArray, Integer[] ans, boolean[] used,
			int depth) {

		// 全部使い切った時=>できた順列を返す
		if (depth == numArray.length) {
			list.add(ans.clone());
			return list;
		}
		// 使い切っていない場合

		for (int i = 0; i < numArray.length; i++) {
			if (used[i]) {
				continue;
			}
			ans[depth] = numArray[i];
			used[i] = true;
			list = buildPermutaion(list, numArray, ans, used, depth + 1);

			used[i] = false;
		}

		return list;
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}

}


Measured memory_bytes: 24740
#include <iostream>

using namespace std;

const int NMAX=1000001;

int main()
{
	static int p[200];
	for(int i=0;i<200;i++)
		p[i]=(i+1)*(i+2)*(i+3)/6;
	
	static int a[NMAX],b[NMAX];
	for(int i=0;i<NMAX;i++)
		a[i]=b[i]=i;
	for(int i=0;i<200;i++){
		for(int j=p[i];j<NMAX;j++)
			a[j]=min(a[j],a[j-p[i]]+1);
		if(!(p[i]&1)) continue;
		for(int j=p[i];j<NMAX;j++)
			b[j]=min(b[j],b[j-p[i]]+1);
	}
	
	for(int n;cin>>n,n;)
		cout<<a[n]<<" "<<b[n]<<endl;
	
	return 0;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i=0; i<N; ++i) cin >> a[i];

    ll sum = 0;
    vector<ll> cnt(1e5+1);
    for (int i=0; i<N; ++i) {
        ++cnt[a[i]];
        sum += a[i];
    }
    int Q;
    cin >> Q;
    vector<ll> res(Q);
    for (int i=0; i<Q; ++i) {
        ll b, c;
        cin >> b >> c;
        sum -= b * cnt[b];
        sum += c * cnt[b];
        res[i] = sum;
        cnt[c] += cnt[b];
        cnt[b] = 0;
    }
    for (ll x : res) cout << x << '\n';
}

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

    solve();

    return 0;
}


Measured memory_bytes: 5288
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	string str;
	bool ok;

	while (true) {
		stack<char>st;
		ok = true;
		
		getline(cin, str);

		if (str == ".")break;

		for (char c :str) {
			if (c == '(')st.push('(');
			if (c == '[')st.push('[');

			if (c == ')') {
				if (st.empty() || st.top() != '(') {
					ok = false;
					break;
				}

				st.pop();
			}

			if (c == ']') {
				if (st.empty() || st.top() != '[') {
					ok = false;
					break;
				}

				st.pop();
			}
		}

		if (ok&&st.empty()) {
			cout << "yes" << endl;
		}
		else {
			cout << "no" << endl;
		}

	}
}


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

int s[90001];

int main()
{
  int h, w, d;
  cin >> h >> w >> d;

  int x[90001], y[90001];
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      int a;
      cin >> a;

      x[a] = j;
      y[a] = i;
    }
  }

  for(int i = d+1; i <= h*w; i++){
    s[i] = s[i-d] + abs(x[i] - x[i-d]) + abs(y[i] - y[i-d]);
  }

  int q;
  cin >> q;
  for(int i = 0; i < q; i++){
    int l, r;
    cin >> l >> r;
    cout << s[r] - s[l] << endl;
  }

  return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  if(a%2 == 0 || b%2 ==0){
    cout << "Even" << endl;
  }else{
    cout << "Odd" << endl;
  }
  return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
int main()
{
int a,b,c,d;
  c=1;

scanf("%d %d",&a,&b); 
    d=a;
if(b==1) {printf("0");}
else { while(b>a){
                 a=a+d-1;
                 c=c+1;
                }
     printf("%d",c);
    }
  
return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e9+9
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

string s, table = "ABXYZW", NEXT[] = { "XY@XWB", "YXZ@BY" };

int main(){
	while (cin >> s){
		char pos = 'A';
		if (s == "#")break;
		REP(i, s.size()){
			REP(j, table.size()){
				if (pos == table[j]){
					pos = NEXT[s[i] - '0'][j];
					break;
				}
			}
		}
		if (pos == 'B')cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}

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

#define NDEBUG
#include <cassert>


typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

#define PQ(T) priority_queue<T>
#define RPQ(T) priority_queue<T,vector<T>,greater<T>>

template<class T> inline void amin(T & a, T const & b) { a = min(a, b); }
template<class T> inline void amax(T & a, T const & b) { a = max(a, b); }

inline ll square(ll x) { return x * x; }
inline ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }
template <typename T>
inline T mod(T a, T b) { return ((a % b) + b) % b; }


const ll MOD=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }



void solve(int N, int K){
    int C=N-K+1;
    vector<vll> a(K, vll(C, 0));
    a[0][0] = 1;
    for (int c=1; c<C; ++c) {
        a[1][c] = 1;
        if (c < K) a[c][c] = 1;

        for (int r=2; r<c; ++r) {
            if (r == K) break;
            a[r][c] = (a[r-1][c-1] + a[r][c-1]) % MOD;
        }
    }

    vll nCr(K);
    nCr[0] = nCr[K-1] = 1;
    for (int r=1; r<K-1; ++r) {
        nCr[r] = DIV(MUL(nCr[r-1], K-1-r+1),r);
    }

    for (int c=0; c<C; ++c) {
        for (int r=0; r<=K-1; ++r) {
            (a[r][c] *= C-c) %= MOD;
            (a[r][c] *= nCr[r]) %= MOD;
        }
    }

    for (int r=0; r<=K-1; ++r) {
        cout << accumulate(ALL(a[r]), 0LL) % MOD << endl;
    }
}

int main() {
    int N, K; cin >> N >> K;
    solve(N,K);
    return 0;
}


Measured memory_bytes: 7936
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
    long     aiPnt1[2], aiPnt2[2];
    long     nPnt = 0;
#define ST_MAX (1000)
    long     aiPnt[2*ST_MAX] = {0};
    long     i;
#define  EPS (0.0000001)

    scanf("%ld %ld %ld %ld", &(aiPnt1[0]), &(aiPnt1[1]),  &(aiPnt2[0]), &(aiPnt2[1]));
    scanf("%ld", &nPnt);
    if (nPnt<0 || nPnt>ST_MAX) {
        printf("invalid input (nPoint)\n");
        return 1;
    }
    for(i=0; i<nPnt; i++) {
        scanf("%ld %ld", &(aiPnt[2*i]), &(aiPnt[2*i+1]));
    }
    //printf("input end\n");

    double adVec[2];
    adVec[0] = (double)(aiPnt2[0] - aiPnt1[0]);
    adVec[1] = (double)(aiPnt2[1] - aiPnt1[1]);

    double len = sqrt(adVec[0]*adVec[0] + adVec[1]*adVec[1]);
    if (len < EPS) {
        printf("too near points (p1, p2)\n");
        return 2;
    }
    adVec[0] /= len;
    adVec[1] /= len;

    for(i=0; i<nPnt; i++) {
        double adDiff[2] = {aiPnt[2*i]-aiPnt1[0], aiPnt[2*i+1]-aiPnt1[1]};
        double dSum = adDiff[0] * adVec[0] + adDiff[1] * adVec[1];
        double adPntNew[2] = {aiPnt1[0]+dSum*adVec[0], aiPnt1[1]+dSum*adVec[1]};
        printf("%.10lf %.10lf\n", adPntNew[0], adPntNew[1]);
    }


    return 0;
}

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

int main()
{
    int N;
    string S;

    int AC, WA, TLE, RE;

    cin >> N;

    AC = 0;
    WA = 0;
    TLE = 0;
    RE = 0;

    for(int i = 0; i < N; i++) {
        cin >> S;
        if(S == "AC") {
            AC += 1;
        } else if(S == "WA") {
            WA += 1;
        } else if(S == "TLE") {
            TLE += 1;
        } else if(S == "RE") {
            RE += 1;
        }
    }

    cout << "AC x " << AC << endl;
    cout << "WA x " << WA << endl;
    cout << "TLE x " << TLE << endl;
    cout << "RE x " << RE << endl;

    return 0;
}

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

constexpr int mod = 1e9 + 7;

int main() {
    int n; cin >> n;
    string s, t;
    cin >> s >> t;
    vector<int> dp(26);
    dp[s[0] - 'a'] = 1;
    for(int i = 1; i < n - 1; ++i) {
        (dp[s[i] - 'a'] += dp[t[i] - 'a']) %= mod;
    }
    cout << dp[t.back() - 'a'] << endl;
}



Measured memory_bytes: 3264
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

typedef vector< vector<int> > Graph;

vector<int> ans;
int used[100010];
void dfs(Graph &G, int p) {
    if(!used[p]) ans.push_back(p);
    used[p] = true;
    rep(i,0,G[p].size()) {
        int to = G[p][i];
        if(used[to]) continue;
        dfs(G, to);
        return;
    }
}

int n, m;
signed main() {
    memset(used, false, sizeof(used));
    cin >> n >> m;
    Graph G(n);
    rep(i,0,m) {
        int a, b; cin >> a >> b;
        a--; b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    dfs(G, 0);
    reverse(ans.begin(), ans.end());
    dfs(G, 0);
    cout << ans.size() << endl;
    rep(i,0,ans.size()) {
        if(i == 0) printf("%lld", ans[i]+1);
        else printf(" %lld", ans[i]+1);
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 10868