akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter};
use std::io::*;
use std::ops::*;
use std::*;

// -----------------------------------------------
// Framework
// -----------------------------------------------

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($arg:expr),*) => {
        #[cfg(debug_assertions)]
        {
            let entries = [$(&stringify!([$arg]:), &$arg as &Debug),*];
            stderr().write_fmt(format_args!("{:#?}\n", entries)).unwrap();
        }
    };
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

// -----------------------------------------------
// Solution
// -----------------------------------------------

pub fn main() {
    let S = rl();
    let S = S.as_bytes();
    let w = read!(usize);
    let mut i = 0;
    let mut T = Vec::new();
    while i < S.len() {
        T.push(S[i]);
        i += w;
    }
    println!("{}", String::from_utf8(T).unwrap());
    return;
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define PI 3.141592653589793

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
  int n; cin >> n; ll a[n]; ll sum = 0;
  rep(i, n){
    cin >> a[i]; sum+=a[i]; sum%=mod;
  }
  sum*=sum; sum%=mod;
  rep(i, n){
    ll hiku = a[i]*a[i]%mod;
    sum-=hiku; if(sum<0) sum+=mod; sum%=mod;
  }
  sum*=modinv(2, mod); sum%=mod;
  cout << sum << endl;
}

Measured memory_bytes: 5148
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define INF 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define req(i, j, n) for(int i = j; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
  ll n;
  cin>>n;
  
  ll com[10][10];

  for(int i=0;i<=9;i++){
    for(int j=0;j<=9;j++){
    
      com[i][j]=0;}
  }
  
  for(int i=1;i<=n;i++){
    if(i<=9){
      com[i][i]++;
    continue;}
    if(i%10==0){
      continue;}
  ll b=i%10;
      ll s;
    ll sub=i;
    ll cnt=-1;
    while(sub>=1){
      sub/=10;
      cnt++;
      if(sub<=9&&sub>=1){
        s=sub;}
    }
  
  com[b][s]++;  
    
  }
  
    ll ans=0;
  
  for(int i=0;i<=9;i++){
    for(int j=0;j<=9;j++){
     ans+=com[i][j]*com[j][i];
    }
  }


  
  cout<<ans<<endl;
    
  


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B;
  cin >> A >> B;
  int S,M;
  if (A<B){
    S=B;
    M=A;
  }
  else {
    S=A;
    M=B;
  }
  if (S-1<M){
    S+=M;
  }
  else{
    S+=S-1;
  }
  cout << S << endl;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
PY=[list(map(int,input().split())) for _ in range(m)]
for i in range(m):
    PY[i].append(i)
py=sorted(PY)
ans=[None]*m
#print(py,PY)
tmp_y=1
for i in range(m):
    if i>0:
        if py[i][0]!=py[i-1][0]:
            tmp_y=1
        else:
            tmp_y+=1
    ans_l="0"*(6-len(str(py[i][0])))+str(py[i][0])
    ans_r="0"*(6-len(str(tmp_y)))+str(tmp_y)
    #print(ans_l+ans_r)
    ans[py[i][2]]=ans_l+ans_r
[print(i) for i in ans]

Measured memory_bytes: 39668
#include <stdio.h>
#include <string.h>

int main(void){
    char s[100000];
    int a=0,b=0;
    
    scanf("%s",s);
    
    for(int i=0;i<strlen(s);i++){
        if(i%2==0 && s[i]=='1'){
            a++;
        }
        else if(i%2==1 && s[i]=='0'){
            a++;
        }
        else b++;
    }
    
    printf("%d",(a<b)?a:b);
    return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())

P = 0

if N >= 2:
    for i in range(N - 1):
        for j in range(N - 1 - i):
            P = P + 1

if M >= 2:
    for i in range(M - 1):
        for j in range(M - 1 - i):
            P = P + 1

print(P)


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

int main(){
  string s;
  cin>>s;
  int l=0;
  int r=0;
  vector<pair<ll,ll>> p;
  rep(i,s.size()){
    if(i!=0 && s[i-1]=='>' && s[i]=='<'){
      p.push_back(make_pair(l,r));
      l=0; r=0;
    }
    if(s[i]=='<')l++;
    if(s[i]=='>')r++;
  }
  p.push_back(make_pair(l,r));
  ll ans=0;
  for(auto x : p){
    ll big=max(x.first,x.second);
    ll small=min(x.first,x.second);
    if(small==0)ans+=big*(big+1)/2;
    else ans+=big*(big+1)/2+(small)*(small-1)/2;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 6060
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

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

    int k;
    cin >> k;
    int n = (k + 3) / 4 * 2;

    if(k == 1) {
        cout << "1\n1\n";
        return 0;
    }

    cout << n << endl;

    rep(i, n) rep(j, n) {
        int a = (i + j) % n + i % 2 * n + 1;
        if(a > k) a -= n;
        cout << a << " \n"[j == n - 1];
    }

    return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ld long double
#define dd double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;
typedef vector<pll> vplll;
ll mod = 1e9+7;
const ld PI = 2 * acos(0.0);
const vector<ll> dx = {1, -1, 0, 0};
const vector<ll> dy = {0, 0, 1, -1};
#define round(x, y) ((x + y - 1) / y)
#define ce(x, y) ((x + y - 1) / y)
#define amax(x, y) \
    if (y > x)     \
        x = y;
#define amin(x, y) \
    if (y < x)     \
        x = y;
#define lcm(x, y) ((x) * (y) / __gcd(x, y))
#define len(x) (ll) x.length()
#define sq(x) ((x) * (x))
#define cb(x) ((x) * (x) * (x))
vector <int> v[100001];
bool vis[100001];
int dp[100001];
// int cnt = 0;
void dfs(int root)
{
	vis[root] = true;
	for(auto j: v[root])
	{
		if(!vis[j])
			dfs(j);
		dp[root] = max(dp[root],1+dp[j]);
	}
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,c,t,n,m,k,q; 
    t = 1;
    // cin>>t;
    while(t--)
    {
    	cin>>n>>m;
    	for(int i=0;i<m;i++)
    	{
    		cin>>a>>b;
    		v[a].pb(b);
    	}
    	for(int i=1;i<=n;i++)
    	{
    		if(!vis[i])
    			dfs(i);
    	}
    	int ans = 0;
    	for(int i=1;i<=n;i++)
    		ans = max(ans,dp[i]);
    	cout<<ans<<endl;
    }
    return 0;
}

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

using std::make_pair;
using std::pair;

using std::max;
using std::min;
using std::sort;

using std::cin;
using std::cout;

using std::vector;

int main() {
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;
    if (a == 0) cout << "1\n";
    if (b == 0) cout << "2\n";
    if (c == 0) cout << "3\n";
    if (d == 0) cout << "4\n";
    if (e == 0) cout << "5\n";

    return 0;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define repi_(i,a,b) for(int i=(a), i##_len=(b); i<=i##_len; ++i)
#define rep_(i,n) repi_(i,0,n)
#define all(x) (x).begin(),(x).end()
#define vsort(v) sort((v).begin(), (v).end())
#define gsort(v) tsort(v); reverse((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define cnt(v, n) count(all(v), n)
#define vmin(v) *min_element(v.begin(), v.end())
#define vmax(v) *max_element(v.begin(), v.end())
#define el "\n"
#define co(x) cout<<(x)<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define cosp(x) cout<<(x)<<' '
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#define inf INT_MAX
#ifdef tqktmp_2
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif
typedef long long lint;

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

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


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

	lint a, b, c; cin >> a >> b >> c;
	YES(b - a == c - b);
	gc();
}

Measured memory_bytes: 256
n = int(input())
a, b = list(map(int, input().split()))
plist = list(map(int, input().split()))
f = 0
m = 0
l = 0
for p in plist:
    if p <= a:
        f += 1
    elif a < p <= b:
        m += 1
    else:
        l += 1
print(min(f, min(m, l)))

Measured memory_bytes: 3060
#include <stdio.h>

int main(void) {
  double height[50] = {0}, max, min;
  int i = 0, n;

  while (scanf("%lf", &height[i]) != EOF) {
    i++;
  }

  n = i;
  
  max = height[0];
  min = height[0];
  for (i = 1; i < n; i++) {
    if (height[i] > max) max = height[i];
    else if (height[i] < min) min = height[i];
  }

  printf("%lf", max - min);

  return 0;
}

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

using namespace std;

int main() {
    int n,in;
    vector<int> v;

    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> in;
        v.push_back(in);
    }
    reverse(v.begin(), v.end());

    for (int i = 0; i < n; i++) {
        cout << v[i];
        if (i < n - 1)
            cout << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 1216
(let ((n (read)) (x 1) a c)
  (loop for i below n
        do (push (read) a))
  (if (some #'zerop a)
      (princ 0)
      (progn
       (setq c a)
      (loop for i below n
            until (> x 1000000000000000000)
            do (setq x (* x (car c)))
            (setq c (cdr c)))
      (princ (if (> x 1000000000000000000) -1 x)))))

Measured memory_bytes: 78476
#include<stdio.h>

int main(void){
  int i;
  int j;
  double a;
  double b[51];
  double c;
  double d;
  double tmp;
 
  scanf("%lf", &a);
  
  for(i = 0; i < a; i++){
    scanf("%lf", &b[i]);
  }
  for(i = 0; i < a; ++i){
    for(j = i + 1; j < a; ++j){
      if(b[i] > b[j]){
        tmp = b[i];
        b[i] = b[j];
        b[j] = tmp;
      }
    }
  }
  
  for(i = 0; i < a - 1; i++){
    if(i == 0){
      c = (b[i] + b[i + 1]) / 2;  
    }else{
      c = (c + b[i + 1]) / 2;
    }
  }
  printf("%lf", c);
  return 0;
}
  
  

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

using namespace std;

typedef long long ll;

int main(){
  ll A, B, C, D, begin_C, begin_D, begin_CD;
  cin >> A >> B >> C >> D;
  ll gcd_CD = C*D/__gcd(C, D);
  ll not_ans = (B/C-(A-1)/C)+(B/D-(A-1)/D)-(B/gcd_CD-(A-1)/gcd_CD);
  cout << (B-A+1)-not_ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define pi pair<int,int>
#define ff first
#define ss second


int32_t main() { 
	int n;
	cin>>n;
	string s;
	vector<array<int,3>>v1,v2;
	int cnt = 0,c = 0;
	vector<int>op,cl;
	for(int i=0;i<n;i++){
		cin>>s;
		int open = 0,close = 0;
		for(char &c:s){
			if(c == '(')
				open++;
			else{
				if(open>0)
					open--;
				else
					close++;
			}
		}
		if(open>0 && close>0){
			if(open>=close)
				v1.push_back({close,open,i});
			else
				v2.push_back({open,close,i});
		}
		else if(open>0){
			cnt+=open;
			op.push_back(i);
		}
		else{
			c+=close;
			cl.push_back(i);
		}
	}

	sort(v1.begin(),v1.end());
	sort(v2.rbegin(),v2.rend());

	for(array<int,3> &p:v1){
		cnt-=p[0];
		if(cnt<0)
			break;
		cnt+=p[1];
		op.push_back(p[2]);
	}

	for(array<int,3> &p:v2){
		cnt-=p[1];
		if(cnt<0)
			break;
		cnt+=p[0];
		op.push_back(p[2]);
	}

	cnt -=c;
	if(cnt == 0){
		cout<<"Yes"<<endl;
/*		for(int &i:op)
			cout<<i+1<<" ";
		for(int &i:cl)
			cout<<i+1<<" ";
		cout<<endl;
*/	}
	else
		cout<<"No"<<endl;
}

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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

typedef long long ll;

int n, m;
vector<vector<int> > bulb;
vector<int> switches, mod;
int ans = 0;

bool isValid(){
    bool isvalid = true;
    for (int i=0;i<m;++i){
        int cnt = 0;
        for (int j=0;j<(int)bulb[i].size();++j){
            if (switches[bulb[i][j]] == 1)
                cnt++;
        }
        if (cnt%2 != mod[i]){
            isvalid = false;
            break;
        }
    }
    return isvalid;
}

void backtrack(int idx){
    if (idx == n){
        if (isValid()) ans++;
        return;
    }
    switches[idx] = 0;
    backtrack(idx + 1);

    switches[idx] = 1;
    backtrack(idx + 1);
    return;
}

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin>>n>>m;
    bulb.assign(m, vector<int>());
    switches.resize(n);
    mod.resize(m);

    int k, s;
    for (int i=0;i<m;++i){
        cin>>k;
        while (k--){
            cin>>s;
            s--;
            bulb[i].emplace_back(s);
        }
    }

    for (int i=0;i<m;++i) cin>>mod[i];
    backtrack(0);
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
def c_triangular_relationship():
    N, K = [int(i) for i in input().split()]

    count = [0] * K  # [x]: K で割って x 余る数が 1 以上 N 以下に何個あるか
    for i in range(1, N + 1):
        count[i % K] += 1

    ans = 0
    for a in range(K):
        b = (K - a) % K
        c = (K - a) % K
        if (b + c) % K == 0:
            ans += count[a] * count[b] * count[c]
    return ans

print(c_triangular_relationship())

Measured memory_bytes: 4596
#include <iostream>

using namespace std;

int
main()
{
  int N,M;
  int s[5], c[5];
  
  int v = 0;
  
  cin >> N >> M;
  
  for ( int i = 0 ; i < M ; i++ ) {
    cin >> s[i] >> c[i];
  }
  
  for ( int i = 0 ; i < N ; i++ ) {
    int tmp = -1;
    for ( int j = 0 ; j < M ; j++ ) {
      if ( s[j] != i + 1 ) continue;
      if ( i == 0 && c[j] == 0 && 1 < N ) { v = -1; break; }
      if ( tmp == -1 ) { tmp = c[j]; continue; }
      if ( tmp != c[j] ) { v = -1; break; }
    }
    
    if ( v == -1 ) break;
    if ( tmp == -1 ) {
      if ( i == 0 && 1 < N ) tmp = 1;
      else tmp = 0;
    }
    v = v * 10 + tmp;
  }
  
  cout << v << endl;
}

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

const int MOD = 1000000007;
vector<bool> prime;

int main(){
  int N;
  cin >> N;
  prime.resize(N+1, true);
  prime[0] = prime[1] = false;
  vector<int> p;
  for(int i = 2; i <= N; i++){
    if(prime[i] == true){
      p.push_back(i);
      for(int j = 2; i * j <= N; j++){
	prime[i * j] = false;
      }
    }
  }
  ll res = 1;
  for(auto x: p){
    int cnt = 0;
    int tmp = x;
    while(tmp <= N){
      cnt += N / tmp;
      tmp *= x;
    }
    res = res * (cnt + 1) % MOD;
  }
  cout << res << endl;
}


Measured memory_bytes: 256
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter, deque
import itertools
#from scipy.misc import comb

H,W,N = map(int, input().split())

L = []
for _ in range(N):
    a,b = map(int, input().split())
    for i in range(3):
        if a+i-1 <= 1 or a+i-1 >= H: continue
        for j in range(3):
            if b+j-1 <= 1 or b+j-1 >= W: continue
            L.append((a+i-1, b+j-1))
L.sort()
C = Counter(L)

ans = [0]*10
for value in C.values():
    ans[value] += 1
ans[0] = (H-2)*(W-2) - sum(ans[1:])

print('\n'.join(map(str, ans)))

Measured memory_bytes: 213212
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <numeric>
#include <type_traits>
#include <limits>
#include <random>

using namespace std;

using ll = long long;

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

string N;
int n[100];

int ans = 10000;

int main() {
	cin >> N;
	for (int i = 0; i < N.length() - 2; i++) {
		ans = min(ans, abs(stoi(N.substr(i, 3)) - 753));
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <utility>

using namespace std;

int a[100000];

int main() {
	int n, k;
	
	while (cin >> n >> k && n != 0) {
		for (int i = 0; i < n; ++i) {
			cin >> a[i];
		}
		int sum = 0, ans = 1 << 31;
		for (int l = 0, r = 0; r < n; ++r) {
			if (r - l == k) {
				ans = max(ans, sum);
				sum -= a[l++];
			}
			sum += a[r];
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 3444
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

class BIT {
public:
  vector <ll> bit;
  int N;

  BIT(int n) {
    N = n;

    for (int i = 0; i <= N; ++i) {
      bit.push_back(0);
    }
  }

  ll sum(int i) {
    ll ret = 0;

    while (i > 0) {
      ret += bit[i];
      i -= i & -i;
    }

    return ret;
  }

  void add(int i, ll x) {
    while (i <= N) {
      bit[i] += x;
      i += i & -i;
    }
  }
};

int main() {
  int N;
  string S;

  cin >> N;
  cin >> S;

  vector<BIT> bit_list;

  for (int i = 0; i <= 25; ++i) {
    BIT bit(N);
    bit_list.push_back(bit);
  }

  for (int i = 0; i < S.size(); ++i) {
    char c = S[i];
    int id = c - 'a';

    bit_list[id].add(i + 1, 1);
  }

  int Q;
  cin >> Q;

  int type;
  int i, l, r;
  char c;

  for (int q = 0; q < Q; ++q) {
    cin >> type;

    if (type == 1) {
      cin >> i >> c;

      int bid = S[i - 1] - 'a';
      int nid = c - 'a';

      bit_list[bid].add(i, -1);
      bit_list[nid].add(i, 1);

      S[i - 1] = c;
    } else {
      cin >> l >> r;

      int cnt = 0;

      for (int id = 0; id < 26; ++id) {
        if (bit_list[id].sum(r) - bit_list[id].sum(l - 1) > 0) {
          cnt++;
        }
      }

      cout << cnt << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 106544
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    var sum = 0.0
    repeat(n) {
        val x = sc.nextDouble()
        val u = sc.next()
        when (u) {
            "JPY" -> sum += x
            "BTC" -> sum += x * 380000.0
        }
    }
    println(sum)
}

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

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class CGoToSchool {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int N;
        in>>N;
        vc<int> ids(N+1, 0);
        REP(i, N){
            int a;
            in>>a;
            ids[a] = i + 1;
        }
        REP(i, N) out<<ids[i+1]<<' ';
        out<<'\n';
    }
};


int main() {
	CGoToSchool solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3676
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
int dp[100010];
int square(int x) {
	return (x * x) % mod;
}

int power(int x, int y) {
	if (y == 0) return 1;
	else if (y == 1) return x % mod;
	else if (y % 2 == 0) return square(power(x, y / 2)) % mod;
	else return square(power(x, y / 2)) * x % mod;
}
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string L; cin >> L;
    int len = L.length();
    dp[0] = 1;
    rep(i, len) {
        if (L[len - i - 1] == '0') dp[i + 1] = dp[i];
        else dp[i + 1] = (dp[i] * 2 + power(3, i)) % mod;
    }
    cout << dp[len] << endl;

    return 0;
}


Measured memory_bytes: 1232
#include<stdio.h>

int main(){
int x,y,z;
int N=0,W=0;
while(scanf("%d,%d,%d",&x,&y,&z)!=EOF){
if(z*z==x*x+y*y)N++;
else if(x==y)W++;
}
printf("%d\n%d\n",N,W);
return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

struct UnionFind{
	vector<int> p;
	UnionFind(int n){
		p.resize(n, -1);
	}

	int find(int x){
		if(p[x] == -1)return x;
		else return p[x] = find(p[x]);
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y)return;
		p[x] = y;
	}
};

int main(){
  int n, k, l;
  cin >> n >> k >> l;
  UnionFind uf(n);
  UnionFind uf2(n);
  for(int i = 0; i < k; ++i){
  	int p, q;
  	cin >> p >> q;
  	--p;
  	--q;
  	uf.unite(p, q);
  }
  for(int i = 0; i < l; ++i){
  	int r, s;
  	cin >> r >> s;
  	--r;
  	--s;
  	uf2.unite(r, s);
  }

  vector<P> reps(n);
  map<P, int> cnt;
  for(int i = 0; i < n; ++i){
    reps[i] = {uf.find(i), uf2.find(i)};
    ++cnt[reps[i]];
  }

  for(int i = 0; i < n; ++i){
    cout << cnt[reps[i]] << " ";
  }
  return 0;
}


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

const int limit = 50;

int n, m;
int a[limit], b[limit];

bool graph[limit][limit];
bool visited[limit];

void dfs(int v) {
    visited[v] = true;
    for (int v2 = 0; v2 < n; ++v2) {
        if (graph[v][v2] == false) continue;
        if (visited[v2] == true) continue;
        dfs(v2);
    }
}

int main() {
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        graph[ a[i] ][ b[i] ] = graph[ b[i] ][ a[i] ] = true;
    }

    int ans = 0;

    for (int i = 0; i < m; i++) {
        graph[ a[i] ][ b[i] ] = graph[ b[i] ][ a[i] ] = false;

        for (int j = 0; j < n; j++) visited[j]  = false;

        dfs(0);

        bool bridge = false;
        for (int j = 0; j < n; j++) {
            if (visited[j] == false) bridge = true;
        }
        if (bridge) ans++;

        graph[ a[i] ][ b[i] ] = graph[ b[i] ][ a[i] ] = true;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef pair<int, int> p;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    string s; cin >> s;
    int w = 0;
    long ans = 0;
    for(int i = s.size() - 1; i >= 0; i--)
    {
        if(s[i] == 'W') w++;
        else ans += w;
    }

    cout << ans << endl;
}

Measured memory_bytes: 720
#include <cstdio>
#include <algorithm>
#include <map>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <cstring>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <stack>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int maxn = 1000050;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const ll linf = 2e18;
ll power(ll x, ll y)
{
    ll ans = 1;
    while (y)
    {
        if (y & 1)
            ans = ans * x % mod;
        x = x * x % mod;
        y >>= 1;
    }
    return ans;
}

ll gcd(ll x, ll y)
{
    if (x % y == 0)
        return y;
    return gcd(y, x % y);
}

char a[maxn];

int main()
{
    int i, j, k, m, t, n;
    scanf("%d %s", &k, a);
    n = strlen(a);
    if (n > k)
    {
        for (i = 0; i < k; i++)
            printf("%c", a[i]);
        printf("...\n");
    }
    else
        printf("%s\n", a);
    return 0;
}


Measured memory_bytes: 3680
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		
		int x=sc.nextInt();		//動物の総数
		int y=sc.nextInt();		//足の総数
				
		if(y%2==1||x*4<y||x*2>y) {
			System.out.println("No");
		}else {
			System.out.println("Yes");
		}
		sc.close();
	}

}


Measured memory_bytes: 27080
#include<stdio.h>

int main(){
    int a,b,div,res;

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

    div = b % a;

    if(div == 0)
    res = a + b;
    else
    {
        res= b - a;
    }
    printf("%d",res);
    return 0;
}

Measured memory_bytes: 1736
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;


void main() {
    int n, k;
    scan(n, k);
    auto a = readln.split.to!(int[]);

    auto cnt = new int[](n + 1);
    foreach (ai ; a) {
        cnt[ai]++;
    }
    auto c = cnt.filter!"a > 0".array.sort();

    debug {
        writeln(c);
    }

    int m = c.length.to!int - k;
    int ans;

    foreach (i ; 0 .. m) {
        ans += c[i];
    }

    writeln(ans);
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 11276
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  string S;
  cin>>S;
  int pnum=0, gnum=0;
  int ans = 0;
  for(int i=0;i<S.size();++i) {
    if(pnum+1>gnum){
      if(S[i]=='p') ans--;
      gnum++;
    }
    else {
      if(S[i]=='g') ans++;
      pnum++;
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3760
#include <stdio.h>
#include <string.h>


int main()
{
    int a,b,c,d;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    int s,e;
    if(a>c)s=a;
    else s=c;
    if(b>d)e=d;
    else e=b;
    if(e-s>0)printf("%d\n",e-s);
    else printf("0\n");


    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <array>
#include <algorithm>
#include <map>
#include <vector>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <climits>
#include <string.h>
#include <cctype>
#include <set>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using namespace std;

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

// a と b の最大公約数を返す関数
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

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

long long lcm(long long a, long long b)
{
	return a * b / gcd(a, b);
}

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
	mint operator+(const mint a) const { return mint(*this) += a; }
	mint operator-(const mint a) const { return mint(*this) -= a; }
	mint operator*(const mint a) const { return mint(*this) *= a; }
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const { return pow(mod - 2); }
	mint& operator/=(const mint a) { return *this *= a.inv(); }
	mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
} comb(2000005);

mint g(int r, int c) {
	return comb(r + c + 2, r + 1) - 1;
}

bool comp(int i, int j) {
	return i > j;
}

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
	return a.second < b.second;
}

// h, w
int tate[2000][2000];
int yoko[2000][2000];
bool rigi[2000][2000];

int main()
{
	int s, w;
	cin >> s >> w;
	cout << (w >= s ? "unsafe" : "safe");
}



Measured memory_bytes: 34220
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	map<int, int> cnt;
	int a;
	rep(i,n){
		cin >> a;
		cnt[a]++;
	}
	if(cnt.size() <= k){
		cout << 0 << endl;
		return 0;
	}
	vector<int> v;
	for(auto p : cnt){
		v.push_back(p.second);
	}
	sort(v.begin(), v.end());
	int ans = 0;
	rep(i,v.size()-k) ans += v[i];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 10744
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

const int MAX = 1e5 + 10;
int N;
int A[MAX];
VI graph[MAX];
VI v;

int dfs(int now) {
    int res = graph[now].size();
    VI vv;
    FORE(e, graph[now]) {
        vv.EB(dfs(e));
    }
    RSORT(vv);
    REP(i, vv.size()) vv[i] += i + 1;
    FORE(e, vv) chmax(res, e);
    return res;
}

int main(void) {
    scanf("%d", &N);
    A[0] = -1;
    FOR(i, 1, N) {
        scanf("%d", &A[i]);
        A[i]--;
        if (A[i] == 0) v.EB(i);
        graph[A[i]].EB(i);
    }
    cout << dfs(0) << endl;
}


Measured memory_bytes: 17024
#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(false);
      std::cin.tie(NULL);
      long long int n;
      std::cin >>n;
      std::cout << n+(n*n)+(n*n*n) << '\n';
return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;

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

	int n;
	cin >> n;

	string str;
	cin >> str;

	ll res = 1;
	ll as = 0;
	for (int i = 0; res && i < 2*n; ++i) {
		int c = 2*n-i; // Number of flips assuming it's a B
		if ((c & 1) == (str[i] == 'B')) {
			// It's a B
			res = (res * as) % MOD;
			--as;
		} else {
			// It's a A
			++as;
		}
	}
	if (as != 0) res = 0;
	for (int i = 1; i <= n; ++i) res = (res * i) % MOD; // order of operations
	cout << res << '\n';

}


Measured memory_bytes: 720
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
int A,B;
int main()
{
	scanf("%d%d",&A,&B);
	if(A>0&&B>0)
	{
		if(B>A)
		{
			printf("%d",B-A);
		}
		else
		{
			printf("%d",A-B+2);
		}
	}
	if(A>0&&B<0)
	{
		if(abs(A)>abs(B))
		{
			printf("%d",abs(A)-abs(B)+1);
		}
		if(abs(A)<abs(B))
		{
			printf("%d",abs(B)-abs(A)+1);
		}
		if(abs(A)==abs(B))
		{
			printf("1");
		}
	}
	if(A<0&&B>0)
	{
		if(abs(A)>abs(B))
		{
			printf("%d",abs(A)-B+1);
		}
		if(abs(A)<B)
		{
			printf("%d",B-abs(A)+1);
		}
		if(abs(A)==B)
		{
			printf("1");
		}
	}
	if(A==0)
	{
		if(B>=0)
		{
			printf("%d",B-A);
		}
		else
		{
			printf("%d",A-B+1);
		}
	}
	if(B==0)
	{
		if(A>0)
		{
			printf("%d",A+1);
		}
		if(A<0)
		{
			printf("%d",abs(A));
		}
	}
	if(A<0&&B<0)
	{
		if(abs(A)>abs(B))
		{
			printf("%d",abs(abs(A)-abs(B)));
		}
		else if(abs(A)<abs(B))
		{
			printf("%d",abs(abs(A)-abs(B))+2);
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

class Node {
 public:
  int value = -1;
  int left = -1;
  int right = -1;
  explicit Node(int value)
    :value{value} {}
};

void print_inorder(vector<Node>&, int);
void print_preorder(vector<Node>&, int);

int main() {
  vector<Node> tree;
  cin.ignore(numeric_limits<streamsize>::max(), '\n');
  string line;
 nextinp:
  while (getline(cin, line)) {
    if (line == "print") {
      if (!tree.size()) {
        cout << endl;
      } else {
        print_inorder(tree, 0); cout << endl;
        print_preorder(tree, 0); cout << endl;
      }
    } else if (line.substr(0, 4) == "find") {
      if (!tree.size()) {
        cout << "no\n";
        continue;
      } else {
        int curr = 0;
        int value = stoi(line.substr(5));
        while (curr != -1) {
          if (value == tree[curr].value) {
            cout << "yes\n";
            goto nextinp; 
          } else if (value < tree[curr].value) {
            curr = tree[curr].left;
          } else {
            curr = tree[curr].right;
          }
        }
        cout << "no\n";
      }
    } else { // insert
      int value = stoi(line.substr(7));
      tree.push_back(Node(value));
      if (tree.size() == 1) continue;
      int curr = 0;
      int prev = 0;
      while (curr != -1) {
        if (value < tree[curr].value) {
          prev = curr;
          curr = tree[curr].left;
        } else if (value > tree[curr].value) {
          prev = curr;
          curr = tree[curr].right;
        }
      }
      if (value < tree[prev].value) {
        tree[prev].left = tree.size() - 1;
      } else {
        tree[prev].right = tree.size() - 1;
      }
    }
  }
}

void print_inorder(vector<Node>& tree, int curr) {
  if (tree[curr].left != -1) print_inorder(tree, tree[curr].left);
  cout << ' ' << tree[curr].value;
  if (tree[curr].right != -1) print_inorder(tree, tree[curr].right);
}

void print_preorder(vector<Node>& tree, int curr) {
  cout << ' ' << tree[curr].value;
  if (tree[curr].left != -1) print_preorder(tree, tree[curr].left);
  if (tree[curr].right != -1) print_preorder(tree, tree[curr].right);
}


Measured memory_bytes: 8996
import math
N, D = map(int, input().split())
li = []
for i in range(N):
    li.append(list(map(int, input().split())))

count = 0
for i in range(N):
    if D >= math.sqrt(li[i][0] ** 2 + li[i][1] ** 2):
        count += 1
print(count)

Measured memory_bytes: 102500
use std::io::Read;

pub fn read_stdin() -> String {
    let mut s = String::new();
    ::std::io::stdin().read_to_string(&mut s).unwrap();
    s
}

pub trait Parse {
    fn to<T>(&mut self) -> T
    where
        T: std::str::FromStr;
}

impl<'a> Parse for std::str::SplitWhitespace<'a> {
    fn to<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let word = self.next().unwrap();
        word.parse().ok().unwrap()
    }
}

fn main() {
    let source = read_stdin();
    let mut iter = source.split_whitespace();
    let _: usize = iter.to();
    let m = iter.to();
    let mut v = (0..m)
        .map(|i| (iter.to::<usize>(), iter.to::<u32>(), i))
        .collect::<Vec<_>>();
    v.sort();

    let mut ans = vec![String::new(); m];
    let mut count = 1;
    for w in v.windows(2) {
        ans[w[0].2] = format!("{:>06}{:>06}", w[0].0, count);
        if w[0].0 != w[1].0 {
            count = 1;
        } else {
            count += 1;
        }
    }
    {
        let last = v.last().unwrap();
        ans[last.2] = format!("{:>06}{:>06}", last.0, count);
    }

    println!("{}", ans.join("\n"));
}

Measured memory_bytes: 17912
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second > b.second; }

signed main() {
    ll N,A,B,a,b;
    cin>>N;
    a=b=1;
    rep(i,N){
        cin>>A>>B;
        ll k=max((a-1)/A,(b-1)/B)+1;
        debug(k)
        a=k*A;
        b=k*B;
    }
    cout<<a+b<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 100000

int main(){

  int S[N],T[N];
  int n,q,i,count=0,mid=0,left,right;
  
  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }

  scanf("%d",&q);

  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }

  

  for(i=0;i<=q-1;i++){

    left=0;
    right=n;

    while(left<right){

      mid=(left+right)/2;

      if(S[mid]==T[i]){
	count++;
	break;
      }else if(T[i]<S[mid]){
	right=mid;
      }else{
	left=mid+1;
      }

    }//while1

  }//for

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

  return 0;

}



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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<long long, long long> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<pair<ll,ll> > vii;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pair<long long,long long> > vpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;

#define PI 3.141592653589793
#define mod 1000000007
#define N 100005
# define M 5001
//int N;
//# define N 2003
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
# define INF (ll)1e18
# define A 1000000

ll dist1[N],dist2[N],tcal1[N],tcal2[N],x[N],cal[N];
ll fans1[N],fans2[N],tfans1[N],tfans2[N];

int main()
{
  ll n,c;
  cin >> n >> c;
  for(int i=1;i<=n;i++)
  {
    cin >> x[i]>> cal[i];
  }
  ll ans=0;
  for(int i=1;i<=n;i++)
  {
     dist1[i]=x[i];
     tcal1[i]+=tcal1[i-1];
     tcal1[i]+=cal[i];
     fans1[i]=(fans1[i-1],tcal1[i]-dist1[i]);
     tfans1[i]=max(tfans1[i-1],tcal1[i]-(2*dist1[i]));
  }
  for(int i=1;i<=n;i++)
   {
     ans=max(ans,tcal1[i]-dist1[i]);
     //trace2(i,ans);
   }

 
  for(int i=n;i>=1;i--)
  {
     //dist2[i]+=dist2[i+1];
     dist2[i]=(c-x[i]);
     tcal2[i]+=tcal2[i+1];
     tcal2[i]+=cal[i];
     //fans2[i]=(tcal2[i]-dist2[i]);
     //tfans2[i]=(tcal2[i]-2*dist2[i]);
     tfans2[i]=max(tfans2[i+1],tcal2[i]-2*dist2[i]);
     fans2[i]=max(fans2[i+1],tcal2[i]-dist2[i]);
  }
  
  for(int i=n;i>=1;i--)
  {
    ans=max(ans,fans2[i]);
  }
  for(int i=1;i<=n;i++)
  {
    ll temp=0;
     temp+=tfans1[i];
     temp+=fans2[i+1];
     ans=max(ans,temp);
  }
  for(int i=n;i>=1;i--)
  {
    ll temp=0;
    temp+=tfans2[i];
    temp+=fans1[i-1];
    ans=max(ans,temp);
  }
  cout << ans;
  
}

Measured memory_bytes: 8064
#include <stdio.h>

int main(void) {

  long k,a,b;
  scanf("%ld %ld %ld", &k, &a, &b);
  long biscuit = 1;
  for (long operation = 1; operation <= k; operation++) {
    if (biscuit < a) {
      biscuit++;
    } else {
      if (b > a+2 && operation < k) {
        biscuit += b-a;
        operation++;
      } else {
        biscuit++;
      }
    }
  }
  printf("%ld\n", biscuit);

  return 0;
}

Measured memory_bytes: 128
def solve():
    n,m,a,b,p,q = map(int,input().split())
    if a==1 and b==1:
        if (p+q)*n <= m:
            return m - (p+q)*n
        else:
            k = m//(p+q)
            return min(m-k*(p+q),(k+1)*(p+q)-m)
    else:
        ans = m
        for i in range(min(n-1,40),-1,-1):
            f = p*(a**i) + q*(b**i)
            if m < f:
                ans = min(ans, f-m)
            else:
                m -= f
            ans = min(ans,m)
        return ans

def main():
    print(solve())

if __name__ == '__main__':
    main()

Measured memory_bytes: 7812
#include <bits/stdc++.h>
using namespace std;
const int mod=1000000007;
const int N=700;
int i,j,k,n,m,x,y,t,ans,dp[N][N],cant[N][N],w[N][N],R[N][N],Y[N][N],g[N],p[N];
int main(){
	scanf("%d%d",&n,&m);
	for (k=1;k<=n*2;k+=2)for (i=1;i<=n*2;i++)if (i+k-1<=n*2)cant[i][i+k-1]=1;
	for (k=1;k<=m;k++){
		scanf("%d%d",&x,&y);
		p[x]=y;p[y]=x;
	}
	g[0]=1;for (i=2;i<=n*2;i+=2)g[i]=1ll*(i-1)*g[i-2]%mod;
	for (i=1;i<=n*2;i++)
		for (j=i+1;j<=n*2;j++)
			if (j-i&1){
				for (k=i;k<=j;k++)
					if (p[k]&&(p[k]<i||p[k]>j)){
						cant[i][j]=1;break;
					}
					else if (p[k])w[i][j]++;
			}
	for (i=1;i<=n*2;i++)
		for (j=i+1;j<=n*2;j++)
			if (!cant[i][j])
				R[i][j]=j-i+1-w[i][j],
				Y[i][j]=n*2-(2*m-w[i][j])-(j-i+1);
	for (t=2;t<=n*2;t+=2)
		for (i=1;i<=n*2-t+1;i++){
			j=i+t-1;
			if (!cant[i][j]){				
				dp[i][j]=1ll*g[R[i][j]]%mod;
				for (k=i+1;k<j;k++)dp[i][j]=(dp[i][j]-1ll*dp[i][k]*g[R[k+1][j]]%mod+mod)%mod;
				ans=(ans+1ll*dp[i][j]*g[Y[i][j]]%mod)%mod;
//				printf("%d %d %d %d\n",i,j,dp[i][j],w[i][j]);
			}
		}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 9216
import java.util.*;

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

        int[] time = new int[3];
        for(int i = 0; i < 3; i++){
            time[i] = sc.nextInt();
        }
        Arrays.sort(time);

        System.out.println(time[0] + time[1]);
    }
}

Measured memory_bytes: 21972