akhauriyash/Code-Regression huggingface dataset:
n, q = map(int, input().split())

answer = []
# create segtree
size = 1

while size < n :
    size *= 2
    
size = size * 2 - 1

segtree = [0 for x in range(size)]

# print(size)

# update query
def update(i, x) :
    ind = size // 2 + i
    segtree[ind] += x
    
    while ind :
        ind = (ind - 1) // 2 # parent
        ch1 = segtree[ind * 2 + 1]
        ch2 = segtree[ind * 2 + 2]
        segtree[ind] = ch1 + ch2
    
def query(s, t, l, r, p) :
    if s > r or t < l :
        return 0
    if s <= l and t >= r :
        return segtree[p]
    else :
        vl = query(s, t, l, (l + r) // 2, p * 2 + 1)
        vr = query(s, t, (l + r) // 2 + 1, r, p * 2 + 2)
        
        return vl + vr
    
for i in range(q) :
    # print("DBG : ", segtree)
    com, x, y = map(int, input().split())
     
    if com == 0 :
        update(x - 1, y)
    else :
        answer.append(query(x - 1, y - 1, 0, size // 2, 0))

for a in answer :
    print(a)
    



Measured memory_bytes: 13044
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/
struct edge{
	ll s,t,c;
	edge(){}
	edge(ll S,ll T,ll C):s(S),t(T),c(C){}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,m;
	cin>>n>>m;
	vl dp(n+1,LINF);
	dp[0]=dp[1]=0;
	vector<edge> e(m);
	rep(i,m){
		ll s,t,c;
		cin>>s>>t>>c;
		e[i]=edge(s,t,c);
	}
	sort(all(e),[](edge a,edge b){return a.s<b.s or (a.s==b.s and a.c>b.c);});
	// rep(i,m)puta(e[i].s, e[i].t, e[i].c);


	for(auto&u:e){
		ll cur=dp[u.s];
		ll nxt=cur+u.c;
		// 0-t までで、
		ll p = upper_bound(all(dp),nxt)-dp.begin();
		range(i,p,u.t+1)dp[i]=nxt;
		// puta(p,u.t,":",dp);
	}
	if(dp[n]==LINF)dp[n]=-1;
	puta(dp[n]);
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
 
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

int main() {
    string s, t;
    cin >> s >> t;
    int g = s.length();
    int l = t.length();
    int b = 0;
    for(int i = 0; i < g; i++){
        if(s[i] == t[i] && (g + 1) == l){
            b++;
        }
    }
    if(b == g){
        cout << "Yes";
    } else{
        cout << "No";
    }
    return 0;
}

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

int main(){
    int w,h,x,y,r;
    cin>>w>>h>>x>>y>>r;
    if(x+r<=w&&x-r>=0&&y+r<=h&&y-r>=0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pint;
typedef pair<pint,int> ipint;
#define NUM_MAX 2147483647
#define N_MAX (1 << 17)

bool cmp(ipint &a, ipint &b) {
    return make_pair(a.first.second, a.second) < make_pair(b.first.second, b.second);
}

int n;
int dat[2*N_MAX-1]; //segment tree

// n_ elements
//initialize segment tree
void init(int n_) {
    n = 1;
    while(n < n_) n *= 2;
    for(int i=0; i < 2 * n - 1; ++i) dat[i] = 0;
}

// add num to kth element
void add(int k, int num) {
    k += n - 1;
    dat[k] += num;
    while(k > 0) {
        k = (k - 1) / 2;
        dat[k] += num;
    }
}

// return sum in [a,b)
int query(int a, int b, int k=0, int l=0, int r=-1) {
    if(r < 0) r = n;

    if(r <= a || l >= b) return 0;

    if(a <= l && r <= b) return dat[k];
    
    int vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
    int vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
    return vl + vr;
}

int main() {
    cin >> n;
    int M,Q;
    cin >> M >> Q;
    vector<ipint> A(M+Q);
    for(int i=0; i<M+Q; ++i) {
        cin >> A[i].first.first >> A[i].first.second;
        --A[i].first.first;
        if(i < M) A[i].second = -1;
        else A[i].second = i-M;
    }
    sort(A.begin(), A.end(), cmp);

    init(n);
    vector<int> res(Q);
    for(int i=0; i<M+Q; ++i) {
        if(A[i].second < 0) {
            add(A[i].first.first, 1);
        } else {
            res[A[i].second] = query(A[i].first.first, A[i].first.second);
        }
    }

    for(int i=0; i<Q; ++i) cout << res[i] << endl;
    return 0;
}

Measured memory_bytes: 4864
n=int(input())
#a,b=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

def prime_factorize(n):
    n_origin=n+0
    primelist=[]
    a=2
    while a*a<=n_origin:
        if n%a!=0:
            a+=1
            continue
        ex=0
        while n%a==0:
            ex+=1
            n=n//a
        primelist.append([a,ex])
        a+=1
    if n!=1:
        primelist.append([n,1])
    return primelist

def countf(e):
    v=0
    count=0
    while True:
        if v+(count+1)>e:
            break
        count+=1
        v+=count
    return count

primel=prime_factorize(n)
ans=0

for l in primel:
    p,e=l
    ans+=countf(e)

print(ans)

Measured memory_bytes: 9168
#include <iostream>

int main(void) {
  int a, b; //a->月, b->日
  int count=0;
  std::cin >> a >> b;

  for(int i=1; i<=a; i++) {
    if(i==a) {
      for(int j=1; j<=b; j++) {  
        if(i==j) {
          count++;
          break;
        }
      }
    } else {
      for(int j=1; j<=31; j++) {  
        if(i==j) {
          count++;
          break;
        }
      }
    }
  }

  std::cout << count << std::endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0,(i##_len)=(n);(i)<(i##_len);(i)++)
#define rep2(i,a,b) for(ll (i)=(a),(i##_len)=(b);(i)<=(i##_len);(i++))
#define Yes(n) cout<<((n)?"Yes\n":"No\n")
#define vll vector<ll>
#define pb push_back
using namespace std;
using ll = long long;

template<class T> bool chmax(T&a,const T&b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T&a,const T&b){if(a>b){a=b;return true;}return false;}
template<class T> T abs(T x){return max(x,-x);}
template<class T> T gcd_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=gcd(r,v.at(i));return r;}
template<class T> T lcm(T m,T n) {return m*n/gcd(m,n);}
template<class T> T lcm_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=lcm<T>(r,v.at(i));return r;}
template<class T> T factorial(T n){if(n==0)return 1;T r=1;for(T i=2;i<=n;i++)r*=i;return r;}
template<class T> T nCr(T n,T k){return factorial<T>(n)/(factorial<T>(k)*factorial<T>(n-k));}
template<class T> T dot_product(vector<T>u,vector<T>v){T r=0;for(T i=0;i<u.size();i++)r+=u.at(i)*v.at(i);return r;}
template<class T> T sum(vector<T>v){return reduce(all(v),0LL);}

// Template ends here

void solve(ll N, vector<ll> A){
    vll R(N); rep(i, N) R.at(A.at(i) - 1) = i + 1;
    rep(i, N) cout << R.at(i) << " ";
}

int main() {
    ll N;
    (void)scanf("%lld",&N);
    vector<ll> A(N);
    for(int i = 0 ; i < N ; i++){
        (void)scanf("%lld",&A[i]);
    }
    solve(N, move(A));
    return 0;
}

Measured memory_bytes: 2432
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;

void main() {
    int Q = readln.chomp.to!int;
    foreach(int i; 0..Q) {
        int[] input = readln.split.to!(int[]);
        int c = input[0];
        int b = input[1];
        int n = input[2];
        int N = 0;
        for (; n>0; n--) {
            if (c>0 && b>0) {
                N++;
                c--;
                b--;
            } else {
                break;
            }
        }
        for (; b>0; b--) {
            if (c>1) {
                N++;
                c-=2;
            }
        }
        N += c/3;
        N.writeln;
    }
}

Measured memory_bytes: 2504
fn main() {
    let v = read_vec::<u64>();
    let n = v[0];
    let m = v[1];
    if n >= 2 && m >= 2 {
        println!("{}", (n - 2) * (m - 2));
    } else if n == 1 && m >= 2 {
        println!("{}", m - 2);
    } else if m == 1 && n >= 2 {
        println!("{}", n - 2);
    } else {
        // 1x1
        println!("{}", 1);
    }
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4476
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class countdict(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x):
        self.setdefault(x,0)
        self[x] += 1        

N,A = ilint()
S = countdict()
L = list()
for a in A:
    S.add(a)
    if S[a]>=2:
        L.append(a)
        S[a] -= 2
L.sort(reverse=True)
print(0 if len(L)<2 else L[0]*L[1])

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

// Problem https://atcoder.jp/contests/abc088/tasks/abc088_b

int solver(int aN,vector<int> cNum){
    int result;
    result = 0;
    int AScore,BScore;
    AScore = BScore = 0;
    sort(cNum.begin(),cNum.end(),greater<int>());
    for(int j=0;j<aN;j++){
        if( j%2 == 0){
            AScore = AScore+cNum.at(j);
        }
        else{
            BScore = BScore+cNum.at(j);
        }
    }
    // cout << "Alice Score: " << AScore << " Bob Score: " << BScore << endl;
    result = AScore - BScore;
    return result;
}

int main(void){
    int answer;
    int N;
    cin >> N;
    vector<int> A(N);
    for(int j=0;j<N;j++){
        cin >> A.at(j);
    }
    answer = solver(N,A);
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <ctype.h>
 
int main(void)
{
    char str[200];
    int i;
    int len;
     
    fgets(str, 200, stdin);
     
    len = strlen(str);
     
    for (i = 0; i < len; i++){
        str[i] = toupper(str[i]);
    }
     
    printf("%s", str);
     
    return (0);
}

Measured memory_bytes: 524
#pragma comment(linker, "/stack:247474112")
#pragma GCC optimize("Ofast")
#include"bits/stdc++.h"
using namespace std;
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define int long long
#define ends ' '
#define endl '\n'
#define pb emplace_back
#define x first
#define y second
#define pii pair<int, int>
#define sz(x) (int)(x).size()

int32_t main()
{
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt", "r", stdin);
	// 	freopen("output.txt", "w", stdout);
	// #endif
	IOS;

	int n;
	cin >> n;

	int a[n+1], b[n];

	int count = 0;

	for(int i = 0; i <= n; ++i)
		cin >> a[i];

	for(int j = 0; j < n; ++j)
		cin >> b[j];

	for(int i = 0; i < n; ++i)
	{
		int temp = min(a[i], b[i]);
		a[i] -= temp;
		count += temp;
		b[i] -= temp;

		if(b[i] and a[i+1])
		{
			int temp = min(a[i+1], b[i]);
			a[i+1] -= temp;
			count += temp;
			b[i] -= temp;
		}
	}

	cout << count;

	return 0;
}

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

int main() {
  string s;
  ll k;
  cin>>s>>k;
  char ans;
  int cnt=0;
  for (int i=0; i<s.size(); i++) {
    if (s[i]=='1') cnt++;
    else break;
  }
  if (s[0]=='1') {
    if (k<=cnt) ans='1';
    else ans=s[cnt];
  }
  else ans=s[0];
  cout<<ans<<endl;     
  return 0;
}

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

int		main()
{
	int		N, i;
	char	*S;
	char	*T;

	i = 0;
	scanf("%d\n", &N);
	S = (char *)malloc(sizeof(char) * (N + 1));
	T = (char *)malloc(sizeof(char) * (N + 1));
	scanf("%s %s", S, T);
	while (i < N)
	{
		printf("%c%c", S[i], T[i]);
		i++;
	}
	printf("\n");
	return (0);
}


Measured memory_bytes: 128
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

ll a[110];
int main()
{
  ll n, tmp = 0;
  scanf("%lld", &n);
  for (int i = 0; i < n; i++)
  {
    scanf("%lld", &a[i]);
  }
  sortdown(a, n);
  for (int i = 1; i < n; i++)
  {
    tmp += a[i];
  }
  puts(a[0] < tmp ? "Yes" : "No");
  return 0;
}


Measured memory_bytes: 128
X, K, D = (int(x) for x in input().split())
X = abs(X) #X<0のときでも正数から0に近づけるアルゴリズムにするため
L = X//D #0に近づけるだけの移動回数(A//Bは整数の商)
if K <= L:
    Min = X - (K*D)
else:
    Min = X - (L*D)
    temp = K - L #残りの移動回数
    if temp % 2 == 1:
        Min = abs(Min) - D
print(abs(Min))

Measured memory_bytes: 9124
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
#define all(x) (x).begin(),(x).end()
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
// 素数かどうか判定
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	vector<int>b(n - 1); rep(i, n - 1)cin >> b[i];
	vector<int>a(n);
	a[0] = b[0];
	a[n - 1] = b[n - 2];
	rep(i, n - 2) {
		if (b[i] <= b[i + 1]) {
			a[i+1] = b[i];
		}
		else {
			a[i+1] = b[i + 1];
		}
	}
	int ans = 0;
	rep(i, n) {
		ans += a[i];
	}
	cout << ans << endl;
	return 0;
}

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

#define ll long long
#define mod 1000000007
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=a-1;i>=b;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define mem(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sz(x) (int)x.size()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI 3.1415926535
#define lb lower_bound
#define ub upper_bound
#define bs binary_search

int main()
{
    string s,t;
    cin>>s>>t;
    vector<ll> v[26];
    ffor(i,0,sz(s)) v[s[i]-'a'].pb(i);
    ll prev=-1;
    ll ans=1;
    ffor(i,0,sz(t))
    {
        int x=t[i]-'a';
        if(ub(all(v[x]),prev)!=v[x].end())
        {
            prev=v[x][ub(all(v[x]),prev)-v[x].begin()];
        }
        else
        {
            ans++;
            if(sz(v[x])==0)
            {
                cout<<"-1";
                return 0;
            }
            prev=v[x][0];
        }
    }
    ans--;
    cout<<ans*sz(s)+prev+1;
    return 0;
}


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

using namespace std;

#define inf 1<<30
#define llong long long
#define usd unsigned
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef pair<int, int> P;
typedef struct data{
	int now;
	int cost;
}data;
int nw[9] = {0, 1, 0, -1, -1, 1, 1, -1, 0};
int nh[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
int a,b,c,d, A[100], B[100], C[100][100], D[100][100][100];
string s, t, r;




int main(){
	cin >> a >> b >> c;
	if(a+b >= c){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int N, M;
    cin >> N >> M;
    vector<pair<pair<int, int>, int>> v;
    vector<int> vp(M);
    REP(i, M) {
        int p, y;
        cin >> p >> y;
        vp[i] = p;
        v.push_back({{p, y}, i});
    }
    sort(v.begin(), v.end());

    map<int, int> order;
    int o = 1;
    int prev = v[0].first.first;
    REP(i, v.size()) {
        auto vv = v[i];
        if (vv.first.first != prev) {
            o = 1;
        }
        order[vv.second] = o;
        o++;
        prev = vv.first.first;
    }

    REP(i, M) {
        printf("%06lld", vp[i]);
        printf("%06lld", order[i]);
        cout << endl;
    }

    return 0;
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define np string::npos
#define X real()
#define Y imag()
#define value(x,y,w,h) (x >= 0 && x < w && y >= 0 && y < h)
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define repc(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

typedef long long ll ;
typedef deque<int> di ;
typedef deque<ll> dl ;
typedef map<string,int> dict;
typedef complex<double> comd;
typedef pair<int,int> pii;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

double CalcDist(comd p1, comd p2){
  return sqrt(pow(p1.X - p2.X,2.0) + pow(p1.Y -p2.Y,2.0));
}

template <typename T>
void out(deque < T > d)
{
  for(size_t i = 0; i < d.size(); i++)
  {
    debug(d[i]);
  }
}

template<typename T>
T ston(string& str, T& n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<vector<int>> table;
  int n,w,vn,wn;
  cin >> n >> w;
  table.resize(w+1);
  rep(i,w+1){
    table[i].resize(n+1,0);
  }
  rep(i,n){
    cin >> vn >> wn;
    rep(j,w+1){
      if(wn <= j ){
        int v = table[j][i] ;
        if(v < table[j-wn][i]+vn){
          v = table[j-wn][i]+vn ;
        }
        if(v < table[j-wn][i+1]+vn){
          v = table[j-wn][i+1]+vn;
        }
        table[j][i+1] = v;
      }
      else{
        table[j][i+1] = table[j][i];
      }
    }
  }
  /*rep(i,n+1){
    rep(j,w+1){
      cout << table[j][i] << " " ;
    }
    cout << endl;
  }*/
  cout << table[w][n] << endl;
  return 0;

}

Measured memory_bytes: 7020
import java.util.Scanner;

//Greatest Common Divisor: Euclidean Algorithm
public class Main{

	static long gcd(long a, long b){
		c = 0;
		if(a < b){
			long tmp = a;
			a = b;
			b = tmp;
		}
		while(b!=0){
			long r = a%b;
			a = b;
			b = r;
			c++;
		}
		return a;
	}

	static int c;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int a = sc.nextInt();
			int b = sc.nextInt();
			if((a|b)==0)break;
			System.out.println(gcd(a,b)+" "+c);
		}
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e7,p=998244353;
int n,v[N],o[N],c[N],z[N],bi[N];
#define C(x,y) (o[x]*c[y]%p*c[x-y]%p)
main()
{v[1]=o[1]=c[1]=1;z[0]=bi[0]=c[0]=1;
for(int i=2;i<=1e7;i++)v[i]=p-v[p%i]*(p/i)%p,o[i]=o[i-1]*i%p,c[i]=c[i-1]*v[i]%p;
for(int i=1;i<=1e7;i++)bi[i]=bi[i-1]*3%p,z[i]=z[i-1]*2%p;
	cin>>n;int ans=bi[n];
	for(int i=n/2+1;i<=n;i++)ans=(ans-C(n,i)*z[n-i+1]%p)%p;cout<<(ans+p)%p;
}


Measured memory_bytes: 401664
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<deque>
#include<queue>
#include<cassert>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<28
#define F first
#define S second
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;
static const int dx[7] = {0,0,1,1,0,-1,-1};
static const int dy[2][7] = {{0,1,0,-1,-1,-1,0},{0,1,1,0,-1,0,1}};//even,odd
static const int dif = 150;

int main(){
  int d[400][400][7];
  bool bmap[400][400];
  rep(i,400){
    rep(j,400){
      rep(k,7){
	d[i][j][k] = INF;
      }
      bmap[i][j] = false; 
    }
  }

  P s,g,l;
  int n,ans = INF;
  scanf("%d %d %d %d",&s.F,&s.S,&g.F,&g.S);
  scanf("%d",&n);
  rep(i,n){
    int x,y;
    scanf("%d %d",&x,&y);
    x += dif; y += dif;
    bmap[y][x] = true;
  }
  scanf("%d %d",&l.F,&l.S);
  queue<PP> que;
 
  que.push(PP(s,P(0,0)));
  d[s.S+dif][s.F+dif][0] = 0;

  /*
  deque<PP> deq;
  deq.push_front(PP(s,P(0,0)));
   
 while(!deq.empty() ){
    PP p = deq.front(); deq.pop_front();
    if(p.F == g){
      ans = p.S.S;
      break;
    }
    int burden = abs(p.F.F*p.F.S*p.S.F)%6,dir = (p.S.F+1)%6;
    rep(i,7){
      int nx = p.F.F+dx[i],ny = p.F.S+dy[p.F.F&1][i];
      if(bmap[ny+dif][nx+dif])continue;
      if(ny<-l.S || nx<-l.F || l.S<ny || l.F<nx)continue;
      
      if(i == burden){
	if(d[ny+dif][nx+dif][dir] > p.S.S){
	  d[ny+dif][nx+dif][dir] = p.S.S;
	  deq.push_front(PP(P(nx,ny),P(dir,p.S.S)));
	}
      }
      else{
	if(d[ny+dif][nx+dif][dir] > p.S.S+1){
	  d[ny+dif][nx+dif][dir] = p.S.S+1;
	  deq.push_back(PP(P(nx,ny),P(dir,p.S.S+1)));
	}
      }
    }
  }
  
  */


  
  
  while(!que.empty()){
    PP pp = que.front();que.pop();
    if(pp.F == g){
      ans = min(ans,pp.S.S);
      continue;
    }
 
    int burden = abs(pp.F.F*pp.F.S*pp.S.F)%6,dir = (pp.S.F+1)%6;
    
    rep(i,7){
      int nx = pp.F.F+dx[i],ny = pp.F.S+dy[pp.F.F&1][i];
      int Dcost = i==burden+1? pp.S.S:pp.S.S+1;
      //if(ny<-l.S || nx<-l.F || l.S<ny || l.F<nx)continue;
      if(!(nx*nx <= l.F*l.F && ny*ny <= l.S*l.S))continue;
      if( !bmap[ny+dif][nx+dif] && (ans > pp.S.S) && d[ny+dif][nx+dif][dir] > Dcost){
	//cout << "in! nx = " << nx-dif << ",ny = " << ny-dif  << ", Dcost = " << Dcost<< endl;
	d[ny+dif][nx+dif][dir] = Dcost;
	que.push(PP(P(nx,ny),P(dir,Dcost)));
      }
    }
    
  }
  
  //cout << ans << endl;
  if(ans != INF)printf("%d\n",ans);
  else printf("-1\n");
  return 0;
}

Measured memory_bytes: 8440
class Array
	def accum
		inject([0]){|a, x| a + [a[-1] + x]}
	end

	def accum!
		(1..size-1).each{|i|
			self[i] += self[i-1]
		}
		self.unshift(0)
	end

	def accum_2d
		ac = map{|r| r.accum}
		(1..size-1).each{|i|
			(1..ac[0].size-1).each{|j|
				ac[i][j] += ac[i-1][j]
			}
		}
		ac.unshift([0] * ac[0].size)
		ac
	end

	def accum_2d!
		each{|r| r.accum!}
		(1..size-1).each{|i|
			(1..self[0].size-1).each{|j|
				self[i][j] += self[i-1][j]
			}
		}
		unshift([0] * self[0].size)
	end
		
	def bsearch_first_index(l = 0, r = size - 1, &pred)
		return nil if l > r
		c = (l + r) / 2 
		if pred[self[c]]
			bsearch_first_index(l, c-1, &pred) || c
		else
			bsearch_first_index(c+1, r, &pred)
		end
	end

	def bsearch_first_item(l = 0, r = size - 1, &pred)
		i = bsearch_first_index(l, r, &pred)
		i ? self[i] : nil
	end

	def bsearch_last_index(l = 0, r = size - 1, &pred)
		return nil if l > r
		c = (l + r) / 2 
		if pred[self[c]]
			bsearch_last_index(c+1, r, &pred) || c
		else
			bsearch_last_index(l, c-1, &pred)
		end
	end

	def bsearch_last_item(l = 0, r = size - 1, &pred)
		i = bsearch_last_index(l, r, &pred)
		i ? self[i] : nil
	end
end

accum = (1..1000).to_a.accum

loop {
	n = gets.to_i
	break if n == 0
	count = 0
	(1..n-1).each{|i|
		x = accum[i-1]
		y = accum.bsearch_first_item{|y| y - x >= n}
		count += 1 if y && y - x == n
	}
	p count
}

Measured memory_bytes: 9376
import sys
#import numpy as np
import math
#from fractions import Fraction
#import itertools
#from collections import deque
#import heapq
#from fractions  import gcd
input=sys.stdin.readline
n=int(input())
xl=[list(map(int,input().split())) for _ in range(n)]
xl.sort(key=lambda x:x[0])
xb=xl[0][0]
lb=xl[0][1]
c=0
for i in range(1,n):
    x=xl[i][0]
    l=xl[i][1]
    if x-l<xb+lb:
        c+=1
        if x+l<xb+lb:
            xb=x
            lb=l
    else:
        xb=x
        lb=l
print(n-c)

Measured memory_bytes: 29096
import java.util.*

val r = Array<ArrayList<Int>>(2001) { ArrayList<Int>() }

fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(' ').map(String::toInt)
    for (i in 1..n - 1) {
        val (a, b) = readLine()!!.split(' ').map(String::toInt)
        r[a].add(b)
        r[b].add(a)
    }
    var ans = 0
    for (i in 1..n) {
        if (k % 2 == 1) {
            for (rr in r[i]) {
                ans = Math.max(ans, dfs(rr, i, k / 2) + dfs(i, rr, k / 2))
            }
        } else {
            ans = Math.max(ans, dfs(i, -1, k / 2))
        }
    }
    println(n - ans)
}

fun dfs(v : Int, p : Int, q : Int) : Int {
    if (q < 0) return 0
    var res = 1
    for (rr in r[v]) if (rr != p) {
        res += dfs(rr, v, q - 1)
    }
    return res
}

Measured memory_bytes: 26500
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
    static void Main(string[] args){
    var ans=0;
    var vals= Console.ReadLine().Split().Select(x => int.Parse(x)).ToList();
    int N=vals[0];
    int M=vals[1];
    var L=new List<int>();
    var R=new List<int>();
    int[] cards=new int[N];
    for(int i=1;i<=M;i++){
        var val = Console.ReadLine().Split().Select(y => int.Parse(y)).ToList();
        L.Add(val[0]);
        R.Add(val[1]);
    }
    var l=L.Max();
    var r=R.Min();
    if(l<=r)
    Console.WriteLine(r-l+1);
    else
    Console.WriteLine(0);
    }
}

Measured memory_bytes: 19644
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;

int main()
 {
 	int n,k,i,s=0;
 	cin>>n>>k;
 	int a[n];
 	for(i=0;i<n;i++)
 	cin>>a[i];
 	sort(a,a+n);
 	for(i=0;i<k;i++)
 		s=s+a[i];
 	cout<<s<<endl;

 	return 0;
}
 	
 					

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
ll mod=1000000007;

int main(){
    std::ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    ll ar[m];
    //ll ma=0;
    for(int i=0;i<m;i++){
        cin>>ar[i];
        //ma=max(ma,ar[i]);
    }
    if(n>=m){
        cout<<0;return 0;
    }
    sort(ar,ar+m);
    ll br[m-1];
    for(int i=1;i<m;i++)br[i-1]=ar[i]-ar[i-1];
    sort(br,br+m-1);
    int in=0;
    ll ans=0;
    for(int i=0;i<m-n;i++){
        ans+=br[i];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;
#define N 100010

ll inv[N],fac[N],ifac[N];

int main(){
  int n;
  cin>>n;
  int a[n+1]={};
  int left,right;
  for(int i=1;i<=n+1;i++){
    ll d;
    cin>>d;
    if(a[d]>0){
      left=a[d]-1;
      right=i;
    }
    a[d]=i;
  }

  inv[0]=1;inv[1]=1;fac[1]=1;ifac[1]=1;fac[0]=1;ifac[0]=1;
  for(int i=2;i<=n+10;i++){
    inv[i]=(-MOD/i)*inv[MOD%i]%MOD;
    fac[i]=fac[i-1]*i%MOD;
    ifac[i]=ifac[i-1]*inv[i]%MOD;
    //cout<<inv[i]<<" "<<fac[i]<<" "<<ifac[i]<<endl;
  }

  int z=left+n+1-right;
  //cout<<z<<endl;
  for(int k=1;k<=n+1;k++){
    ll tmp=fac[n+1]*ifac[k]%MOD*ifac[n+1-k]%MOD;
    ll dif=0;
    if(z>=k-1){
      dif=(dif+fac[z]*ifac[k-1]%MOD*ifac[z-k+1]%MOD)%MOD;
      //cout<<fac[z]<<" "<<ifac[k-1]<<" "<<ifac[z-k+1]<<endl;
    }
    tmp=(tmp+MOD)%MOD;
    dif=(dif+MOD)%MOD;
    cout<<(tmp-dif+MOD)%MOD<<endl;
  }

  return 0;
}


Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
long long dfs(long long x, long long y)
{
    if(y%x == 0)
        return y/x*x*2-x;
    else
        return y/x*x*2+dfs(y%x, x);
}
int main()
{
    long long n, x;
    cin>>n>>x;
    cout<<n+dfs(x, n-x)<<endl;
    return 0;
}

Measured memory_bytes: 3600
def main():
	_, t, *L = map(int, open(0).read().split())
	d = [0] * t
	cand = 0
	for w, v in sorted((x, y) for x, y in zip(*[iter(L)] * 2)):
		if cand < d[-1] + v:
			cand = d[-1] + v
		for i in range(t - 1, w - 1, -1):
			if d[i - w] + v > d[i]:
				d[i] = d[i - w] + v
	print(max(cand, max(d)))

if __name__=="__main__":
	main()


Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,b) FOR(i,0,b)
#define BE(c) c.begin(),c.end()
#define PB push_back
#define F first
#define S second
#define BEB(s) s
using namespace std;
int main(){
	string s;
	int j=0;
	while(cin>>s){
		int k=0;
		string ans;
		while(k<s.size()){
			if(s[k]=='@'){
				REP(i,(s[k+1]-'0')){
					ans+=s[k+2];
				}
				k+=3;
			}else{
				ans+=s[k];
				k++;
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1184
import java.io.*;
import java.util.*;

class Main{
    public static void main(String[] args){
	BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
	try {
	    String st;
	    TreeMap<String, TreeSet<Integer>> map = new TreeMap<String, TreeSet<Integer>>();
	    while((st=sc.readLine())!=null){
		String[] sp = st.split(" ");
		if(!map.containsKey(sp[0]))
		    map.put(sp[0], new TreeSet<Integer>());
		map.get(sp[0]).add(Integer.valueOf(sp[1]));
	    }
	    while(!map.isEmpty()){
		String word = map.firstKey();
		System.out.println(word);
		System.out.print(map.get(word).pollFirst());
		while(!map.get(word).isEmpty()){
		    System.out.print(" ");
		    System.out.print(map.get(word).pollFirst());
		}
		System.out.println();
		map.remove(word);
	    }
    	}catch(Exception e){
	    System.out.println("Error");
	}
    }
}

Measured memory_bytes: 11000
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Stack;

/*
 * @author Tanzim Ibn Patowary
 * Created  May 29, 2020 9:22:05 PM
 */
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		for (int i = 0; i < 5; i++) {
			int x = in.nextInt();
			if (x==0) {
				System.out.println(i+1);
				break;
			}
		}
	}
}

Measured memory_bytes: 27012
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
    return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long  
#define f80 __float128
#define pii pair<int,int>
/////////////
int a[200001];
int ans[200001];
set<int> s;
int in[200001];
int re[200001];
void dfs(int i,int pr,vector<int> gr[])
{
	if(s.lower_bound(a[i])==s.end())
	{
		in[i]=-1;
		re[i]=a[i];
		s.insert(a[i]);
	}
	else
	{
		re[i]=a[i];
		in[i]=*s.lower_bound(a[i]);
		s.erase(s.lower_bound(a[i]));
		s.insert(a[i]);
	}
	ans[i]=s.size();
	for(auto r:gr[i])
	{
		if(r!=pr)
			dfs(r,i,gr);
	}
	if(re[i]!=-1)
		s.erase(re[i]);
	if(in[i]!=-1)
		s.insert(in[i]);
}
signed main()
{
	fastio;
	#ifdef ANIKET_GOYAL
		freopen("inputf.in","r",stdin);
		freopen("outputf.in","w",stdout);
	#endif
	int n;
	cin>>n;
	for(int i=1;i<=n;++i)
	{
		cin>>a[i];
	}
	vector<int> gr[n+1];
	for(int i=1;i<n;++i)
	{
		int x,y;
		cin>>x>>y;
		gr[x].push_back(y);
		gr[y].push_back(x);
	}
	dfs(1,-1,gr);
	for(int i=1;i<=n;++i)
	{
		cout<<ans[i]<<"\n";
	}
	#ifdef ANIKET_GOYAL
		cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
	#endif
} 

Measured memory_bytes: 35088
#include <bits/stdc++.h>
using namespace std;
class finite_field {
	const int md;
	const int sz;
	vector<int> fct, fnv;
	public :
		finite_field(
				const int md,
				const int init_factorial_size = 0
			) :
			md(md), sz(init_factorial_size),
			fct(sz), fnv(sz)
			{
				if (sz) {
					fct[0] = 1;
					for (int i = 1; i < sz; i++) fct[i] = prod(fct[i - 1], i);
					fnv[sz - 1] = inv(fct[sz - 1]);
					for (int i = sz - 1; i >= 1; i--) fnv[i - 1] = prod(fnv[i], i);
				}
			}
		inline void add (int& a, const int b) const {
			a += b;
			if (a >= md) a -= md;
		}
		inline void sub (int& a, const int b) const {
			a -= b;
			if (a < 0) a += md;
		}
		template<class... A> int sum (A... args) const {
			int ret = 0;
			for (int a : initializer_list<int>{args...}) {
				add(ret, a);
			}
			return ret;
		}
		template<class... A> int prod (A... args) const {
			long long ret = 1;
			for (int a : initializer_list<int>{args...}) {
				ret *= a;
				ret %= md;
			}
			return (int)ret;
		}
		void mul (int& a, int b) const {
			a = prod(a, b);
		}
		inline int inv (int a) const {
			a %= md; if (a < 0) a += md;
			int b = md, u = 0, v = 1;
			while (a) {
				int t = b / a;
				b -= a * t; swap(a, b);
				u -= v * t; swap(u, v);
			}
			assert(b == 1);
			if(u < 0) u += md;
			return u;
		}
		inline int quat (int a, int b) const {
			return prod(a, inv(b));
		}
		void div (int& a, int b) const {
			a = quat(a, b);
		}
		inline int binom (int n, int k) const {
			assert(0 <= n && n < sz);
			if (k < 0 || n < k) return 0;
			return prod(fct[n], fnv[k], fnv[n - k]);
		}
};
int main() {
	cin.tie(0); cin.sync_with_stdio(false);
	int n, m; string s;
	cin >> n >> m >> s;
	finite_field fld(1e9 + 7);
	if (s == string(m, s[0])) {
		int ans = 0;
		for (int first = 0; first < 2; first++) {
			vector<int> dp(2, 0);
			dp[first] = 1;
			for (int i = 1; i < n; i++) {
				vector<int> new_dp(2, 0);
				for (int j = 0; j < 2; j++) {
					for (int x = 0; x < 2; x++) {
						if (j + x < 2) {
							fld.add(new_dp[j], dp[x]);
						}
					}
				}
				swap(dp, new_dp);
			}
			for (int j = 0; j < 2; j++) {
				if (j + first < 2) {
					fld.add(ans, dp[j]);
				}
			}
		}
		cout << ans << endl;
		return 0;
	}
	if (n & 1) {
		cout << 0 << endl;
		return 0;
	}
	vector<int> seqs;
	int t = 0;
	for (int i = 0; i < m; i++) {
		if (s[i] == s[0]) {
			++t;
		} else {
			seqs.push_back(t);
			t = 0;
		}
	}
	int bound = seqs[0];
	if (!(bound & 1)) {
		++bound;
	}
	for (int it = 1; it < (int) seqs.size(); it++) {
		if (seqs[it] % 2 == 1) {
			bound = min(bound, seqs[it]);
		}
	}
	n /= 2;
	bound /= 2;
	int ans = 0;
	if (bound == 0) {
		ans = 1;
	} else {
		vector<int> dp(n);
		vector<int> pref(n + 1);
		dp[0] = 1;
		pref[1] = 1;
		for (int i = 1; i < n; i++) {
			dp[i] = pref[i];
			if (i - bound - 1 >= 0) {
				fld.sub(dp[i], pref[i - bound - 1]);
			}
			pref[i + 1] = fld.sum(pref[i], dp[i]);
		}
		for (int i = n - 1 - bound; i < n; i++) {
			fld.add(ans, fld.prod(dp[i], n - i));
		}
	}
	cout << fld.prod(2, ans) << endl;
	return 0;
}

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

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

// 無限大の値
const long long INF = 1LL << 60;

// 入力
int N;
long long a[100010][3];

// DP テーブル
long long dp[100010][3];
long long res;

int main()
{
    res = 0;
    // input
    cin >> N;
    for (int i = 0; i < N; ++i)
        for (int j = 0; j < 3; ++j)
            cin >> a[i][j];

    // DP テーブル全体を初期化 (最小化問題なので INF に初期化)
    for (int i = 0; i < N; ++i)
        for (int j = 0; j < 3; ++j)
            dp[i][j] = 0;

    // 初期条件
    dp[0][0] = dp[0][1] = dp[0][2] = 0;

    // ループ
    for (int i = 0; i < N; ++i)
        for (int j = 0; j < 3; ++j)
            for (int k = 0; k < 3; ++k)
                if (j != k)
                    chmax(dp[i + 1][j], dp[i][k] + a[i][j]);
    for (int j = 0; j < 3; ++j)
        chmax(res, dp[N][j]);

    // 解を得て出力
    cout << res << endl;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
pair<int,int> book[maxn];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>book[i].first,book[i].second=i;
	sort(book+1,book+1+n);
	for(int i=1;i<=n;i++) cout<<book[i].second<<(i==n?'\n':' '); 
	return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;
int N;
vector<int> event;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    event.resize(100003);
    for(int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        event[a]++;
        event[b+1]--;
    }
    int ans = 1;
    int now = 0;
    for(int i = 1; i <= 1e5 + 2; i++) {
        now += event[i];
        if(now >= i - 1) ans = i - 1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3368
import math

n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()

def h(x):
    if x=="r":
        return p
    if x=="p":
        return s
    return r

ans=0
for i in range(k):
    l = [t[j] for j in range(i,n,k)]
    #print(l)
    m = len(l)
    tmp = 0
    cnt=1
    for j in range(m-1):
        if l[j]==l[j+1]:
            cnt+=1
        else:
            tmp+=math.ceil(cnt/2)*h(l[j])
            cnt=1
    tmp+=math.ceil(cnt/2)*h(l[m-1])
    #print(tmp)
    ans+=tmp
print(ans)

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

using namespace std;


int n, a[200005];
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	n -= 1;
	for (int i = 0; i < n; i++) {
		if (a[i] == a[i + 1]) {
			cout << "NO";
			break;
		}
		if (i == n - 1) cout << "YES";
	}
	return 0;
}


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

using namespace std;
typedef long long ll; 
 
int main(void){
	
	ll L, R, ans = 10000000;
	
	cin >> L >> R;
	
	if(R-L >= 2019){
		cout << 0;
		return 0;
	}
	
	for(ll i=L; i<R; i++){
		for(ll j=i+1; j<=R; j++){
			ans = min(ans, (i*j)%2019);
			if(ans == 0){
				cout << ans;
				return 0;
			}
		}
	}
	
	cout << ans;
	
	return 0;
}

Measured memory_bytes: 256
/*
問題文
長さ N の数列 A1,A2,…,AN があります．最初，この数列の要素は 1,2,…,N を並び替えたものになっています．

スヌケ君は，この数列に対して次の操作を行うことができます．

数列のうち，連続した K 個の要素を選ぶ．その後，選んだ要素それぞれの値を，選んだ要素の中の最小値で置き換える．
スヌケ君は，上の操作を何回か繰り返すことで，この数列の要素をすべて等しくしたいです． 必要な操作の回数の最小値を求めてください． この問題の制約の下，このようなことは必ず可能であることが証明できます．

制約
2≤K≤N≤100000
A1,A2,…,AN は 1,2,…,N の並び替え
*/


#include <iostream>


using namespace std;


int main()
{
	int n, k;

	int* a = new int[n];

	cin >> n >> k;

	for (int i = 0 ; i < n ; i++)	cin >> a[i];

	int count = 0;

	while (n > k){
		n = n-k+1;	count++;
	}

	cout << count + 1 << "\n";
}


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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector <int> a(n);
    map <int,int> m;
    for(int i=0;i<n;i++){
        cin >> a[i];
        m[a[i]]++;
    }
    int ans=0;
    for(auto x:m){
        if(x.first>x.second){
            ans+=x.second;
        }
        else{
            ans+=x.second-x.first;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5120
R, G, B, n = map(int, input().split())
ans = 0
for r in range(n // R + 1):
    Rr = R * r
    for g in range((n - Rr) // G + 1):
        tmp = Rr + G * g
        if (n - tmp) % B == 0:
            ans += 1
print(ans)


Measured memory_bytes: 2940
import java.util.Scanner;
import java.math.BigDecimal;

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

    BigDecimal N = new BigDecimal(str_scan);
    var ans = "No";
    double amari = 0;
    double sum = 0;
    int keta = 0;

    keta = N.precision();
    char[] work = new char[keta];

    for(var i = 0; i < keta; i++){
      sum += Double.parseDouble(String.valueOf(str_scan.charAt(i)));
    }

    if ( (sum % 9) == 0 ) {
      ans = "Yes";
    }

    System.out.println(ans);
    scan.close();
  }
}

Measured memory_bytes: 61264
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<cmath>
#include<set>
#include<stack>
#define ll long long
#define pb push_back
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)>(y)?(y):(x))
#define cls(name,x) memset(name,x,sizeof(name))
using namespace std;
const int inf=1e9+10;
const ll llinf=1e16+10;
const int maxn=1e6+10;
const int maxm=2e5+10;
const int mod=1e9+7;
const double pi=acos(-1.0);
int n;
ll sum,k;
ll f[maxn];
struct node
{
    ll *num;
    int len;
}tree[maxn*4];
void build(int l,int r,int rt)
{
    tree[rt].len=r-l+1;
    tree[rt].num=new ll[tree[rt].len];
    if(l==r)
    {
        tree[rt].num[0]=f[l];
        return ;
    }
    int mid=(l+r)/2;
    build(l,mid,rt*2);
    build(mid+1,r,rt*2+1);
    int i=0,j=0,k=0;
    while(i<tree[rt*2].len&&j<tree[rt*2+1].len)
    {
        if(tree[rt*2].num[i]<tree[rt*2+1].num[j])
            tree[rt].num[k++]=tree[rt*2].num[i++];
        else
            tree[rt].num[k++]=tree[rt*2+1].num[j++];
    }
    while(i<tree[rt*2].len)
        tree[rt].num[k++]=tree[rt*2].num[i++];
    while(j<tree[rt*2+1].len)
        tree[rt].num[k++]=tree[rt*2+1].num[j++];
}
int querry(int ql,int qr,ll key,int l,int r,int rt)
{
    if(ql==l&&qr==r)
    {
        int c=lower_bound(tree[rt].num,tree[rt].num+tree[rt].len,key)-tree[rt].num;
        return tree[rt].len-c;
    }
    int mid=(l+r)/2;
    if(qr<=mid)
        return querry(ql,qr,key,l,mid,rt*2);
    else if(ql>=mid+1)
        return querry(ql,qr,key,mid+1,r,rt*2+1);
    else
        return querry(ql,mid,key,l,mid,rt*2)+querry(mid+1,qr,key,mid+1,r,rt*2+1);
}
int main()
{
    //freopen("in.txt","r",stdin);
    while(~scanf("%d %lld",&n,&k))
    {
        sum=0;
        f[0]=sum-k*(0+1);
        for(int i=1;i<=n;i++)
        {
            int t;
            scanf("%d",&t);
            sum=sum+t;
            f[i]=sum-k*(i+1);
        }
        build(1,n,1);
        ll ans=0;
        for(int i=0;i<=n-1;i++)
        {
            ans+=querry(i+1,n,f[i],1,n,1);
        }
        printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 50944
#include<iostream>
using namespace std;
int main()
{
    int N;
    cin>>N;
    N=N%10;
    if(N==2||N==4||N==5||N==7||N==9)
        cout<<"hon"<<endl;
    else if(N==0||N==1||N==6||N==8)
        cout<<"pon"<<endl;
    else if(N==3)
        cout<<"bon"<<endl;
}


Measured memory_bytes: 3128