akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){
    int n;
    cin >> n;
    int l[n];
    inrep(n,l);
    sort(l,l+n);

    int sum = 0;
    rep(i,0,n-1)sum+=l[i];
    if(l[n-1] < sum)Yes;
    else No;
    
	return  0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[100000];
int main(){
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    cin>>a[i];
    sort(a+1,a+n+1);
    int sum=0;
    for(int i=n;i>=n-m+1;i--)
    sum+=a[i];
    cout<<sum;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

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

    long long ans = a[0] - 1;
    int b = 1;
    for(int i=1; i<n; ++i){
        int x = (a[i] - 1) / (b + 1);
        ans += x;
        if(x == 0)
            b = max(b, a[i]);
    }
    cout << ans << endl;

    return 0;
}

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

#define _USE_MATH_DEFINES
//BIAR MANTAB LAH YA
#define Willy using
#define Indrayana namespace
#define Komara std
 
Willy Indrayana Komara;

using ll = long long int;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    cout << setprecision(12) << 2 * M_PI * n << '\n';
}

Measured memory_bytes: 3800
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,m,i,x,y,mx,a[1000010];
int main(){
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		a[x]^=1;a[y]^=1;
	}
	for(i=1;i<=n;i++)if(a[i])return puts("NO"),0;
	puts("YES");
}

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

lmax = 0
rmin = N
for i in range(M):
    l, r = map(int, input().split())
    if l > lmax:
        lmax = l
    if r < rmin:
        rmin = r

if lmax > rmin:
    print(0)
else:
    print(rmin-lmax+1)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
const int IINF = 1000000000;
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; }
using Graph = vector<vector<int>>;


int main(){
    int N; cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];

    int Q; cin >> Q;
    vector<int> B(Q), C(Q);
    rep(i,Q) cin >> B[i] >> C[i];

    map<int, ll> counter;
    ll total = 0;
    rep(i,N){
        counter[A[i]]++;
        total += A[i];
    }

    rep(i,Q){
        ll b_count = counter[B[i]];
        counter[B[i]] = 0;
        counter[C[i]] += b_count;
        total -= b_count*B[i];
        total += b_count*C[i];

        cout << total << endl;
    }
} 

Measured memory_bytes: 10300
#include "bits/stdc++.h"
#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int

using namespace std;


int main() {
	speed;
	int n, m;
	int l, r;
	vector<int>L;
	vector<int>R;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> l;
		cin >> r;
		L.push_back(l);
		R.push_back(r);
	}
	sort(L.begin(), L.end());
	sort(R.begin(), R.end());

	int ans=R.at(0)- L.at(m-1) ;
	if (ans < 0)ans = -1;
	cout << ans+1;
	ed;
	return 0;
}


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

int N;

int main(){
  cin >> N;

  int max = 0;  int sum = 0;
  for(int i = 0; i < N; i++){
    int p;
    cin >> p;
    if(max < p)  max = p;
    sum += p;
  }

  cout << sum - max/2 << endl;
  return 0;
    

}

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


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; }
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define COUT(x) cout << x << endl;
#define PB(x) push_back(x)
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int INF = 1e9;
const int MOD = 1e9+7;

int main(){
    int r; cin >> r;
    cout << fixed << setprecision(10) << (double)r*2*3.14159265358979 << endl;
}

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

int main(){
	int n;
    cin >> n;
    string s;
    cin >> s;
    char a = s.at(0);
    ll ans = 1;
    for(int i=1; i<n; i++){
      if(s.at(i) != a) ans++;
      a = s.at(i);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main() {
  vector<int> A;
  A.reserve(100000);

  int N;
  cin >> N;
  A.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  int M;
  int key;
  int sum = 0;

  cin >> M;
  for (int i = 0; i < M; i++) {
    cin >> key;
    //if (*lower_bound(A.begin(), A.end(), key) == key) {
    if (binary_search(A.begin(), A.end(), key)) {

      sum++;
    }
  }
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
int main(){
    ll N;
    cin >> N;
    vi A(N - 1);
    for(int i = 0; i < N - 1; i++){
        cin >> A.at(i);
    }
    vi ans(N);
    for(int i = 0; i < N; i++){
        ans.at(i) = 0;
    }
    for(int i = 0; i < N - 1; i++){
        ans.at(A.at(i) - 1)++;
    }
    for(int i = 0; i < N; i++){
        cout << ans.at(i) << endl;
    }
    return 0;
}

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

int n,m;
int a[100001];

int main(void){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		scanf("%d",&a[i]);
	}
	int ans=max(a[0]-1,n-a[m-1]);
	for(int i=0;i<m-1;i++){
		ans=max(ans,(a[i+1]-a[i])/2);
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 3316
import heapq


class UnionFind:
    def __init__(self, size: int):
        self.__size = size
        self.__root = [-1] * size

    def find(self, x: int)->int:
        if self.__root[x] < 0:
            return x

        root = self.find(self.__root[x])
        self.__root[x] = root

        return root

    def same(self, x: int, y: int)->bool:
        return self.find(x) == self.find(y)

    def union(self, x: int, y: int):
        rx, ry = self.find(x), self.find(y)

        if rx == ry:
            return

        if self.__root[ry] < self.__root[rx]:
            rx, ry = ry, rx

        self.__root[rx] += self.__root[ry]
        self.__root[ry] = rx


class PriorityQueue:
    def __init__(self):
        self.__heap = []
        self.__count = 0

    def empty(self) -> bool:
        return self.__count == 0

    def dequeue(self):
        if self.empty():
            raise Exception('empty')
        self.__count -= 1
        return heapq.heappop(self.__heap)

    def enqueue(self, v):
        self.__count += 1
        heapq.heappush(self.__heap, v)

    def __len__(self):
        return self.__count


def kruskal(edges: list, size: int)->list:
    q = PriorityQueue()
    for c, u, v in edges:
        q.enqueue((c, u, v))
    uf = UnionFind(size)

    min_tree = []
    while not q.empty():
        c, u, v = q.dequeue()

        if not uf.same(u, v):
            uf.union(u, v)
            min_tree.append((c, u, v))

    return min_tree


def built(N: int, points: list)->int:
    edges = []
    points = [(i, x, y) for i, (x, y) in enumerate(points)]
    sorted_x = sorted(points, key=lambda p: p[1])
    sorted_y = sorted(points, key=lambda p: p[2])

    for i in range(N-1):
        u, ux, _ = sorted_x[i]
        v, vx, _ = sorted_x[i+1]
        edges.append((vx-ux, u, v))

        u, _, uy = sorted_y[i]
        v, _, vy = sorted_y[i+1]
        edges.append((vy-uy, u, v))

    tree = kruskal(edges, 2*(N-1))

    return sum(c for c, _, _ in tree)


if __name__ == "__main__":
    N = int(input())
    points = [tuple(map(int, input().split())) for _ in range(N)]
    ans = built(N, points)
    print(ans)


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


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

    // 余裕持って50行分作っている
    string board[50];

    for (int i = 0; i < h; i++) cin >> board[i];
    
    const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
    const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
    
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            if(board[i][j] == '#') continue;
            
            int num = 0;
            // 周囲の検査
            for (int d = 0; d < 8; d++){
                const int ni = i + dy[d];
                const int nj = j + dx[d];
                
                if (ni < 0 or h <= ni) continue;
                if (nj < 0 or w <= nj) continue;
                if (board[ni][nj] == '#') num++;
            }
            
            board[i][j] = char(num + '0');
        }
    }
    for (int i = 0; i < h; i++) cout << board[i] << endl;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll n, ans, rem;
    cin >> n;
    ans = floorl(n / 11) * 2;
    rem = n % 11;
    if (rem != 0 and rem <= 6)
    {
        ans++;
    }
    else if (rem != 0 and rem < 11)
    {
        ans += 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int r,D,x,i;
    scanf("%d %d %d", &r, &D, &x);
    
    for (i = 0; i < 10; i++)
    {
        x = r * x - D;
        printf("%d\n", x);
    }
    
    return 0;
}

Measured memory_bytes: 1680
n = int(input())
a = [0] + list(map(int, input().split())) #index alliginment
b = [0] + list(map(int, input().split()))
c = [0] + list(map(int, input().split()))
a.sort()
b.sort()
c.sort()
bp, cp = 1, 1
cana, canb = [0], [0] # a[i]に対して条件を満たすbの要素数と
                      # b[i]に対して条件を満たすcの要素数を保管
sumb = [0] # canbの末尾からn個の累積和
ans = 0
for i in range(1,n+1): # aの1~nまで
    if bp != n+1:
        while b[bp] <= a[i] and bp != n+1:
            bp += 1
            if bp == n+1:
                break
    appending = n+1-bp if bp != n+1 else 0
    cana.append(appending)
for i in range(1,n+1):
    if cp != n+1:
        while c[cp] <= b[i] and cp != n+1:
            cp += 1
            if cp == n+1:
                break
    appending = n+1-cp if cp != n+1 else 0
    canb.append(appending)
for i in range(1,n+1):
    sumb.append(sumb[-1]+canb[-i])
for i in range(1,n+1):
    ans += sumb[cana[i]]
print(ans)

Measured memory_bytes: 27840
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int a,b,c,d;
  cin>>a>>b>>c>>d;
  int e= max(a,c);
  int f=min(b,d);
  if(f-e>=0){
    cout<<f-e<<endl;
  }
  else{
    cout<<0<<endl;
  }
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    return

#B
def B():
    r, d, x = LI()
    for i in range(10):
        print(x * r - d)
        x = x * r - d
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    B()


Measured memory_bytes: 39024
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+5;
char s[N];
int a,b,c,ans;
signed main(){
	cin>>(s+1);int n=strlen(s+1);
	for(int i=1;i<=n;++i)
		if(s[i]=='0') ++b;
	for(int i=1;i<=n;++i)
		if(s[i]=='0') ++a,--b;
		else{
			++c;
			if(s[i+1]=='1'){
				ans+=1+a+b;++c;++i;continue;
			}
			if(i&1) ans+=1+(a/2)+b;
			else ans+=(a+1)/2+b; 
		}
	while(c) ans+=(c/2),--c;
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 3812
/*  -*- coding: utf-8 -*-
 *
 * 2801.cc: Suntan
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_M = MAX_N * 2;

/* typedef */

typedef long long ll;

/* global variables */

ll as[MAX_N], bs[MAX_N], ss[MAX_N + 1];

/* subroutines */


/* main */

int main() {
  ll t;
  int n;
  scanf("%lld%d", &t, &n);

  for (int i = 0; i < n; i++) {
    scanf("%lld%lld", as + i, bs + i);
    ss[i + 1] = ss[i] + (bs[i] - as[i]);
  }

  ll maxl = 0;
  for (int i = 0; i < n; i++) {
    ll ti = as[i] + t;
    int k = upper_bound(bs, bs + n, ti) - bs;
    //printf("k=%d\n", k);

    ll l = ss[k] - ss[i];
    if (k < n && as[k] < ti) l += ti - as[k];
    if (maxl < l) maxl = l;
  }

  printf("%lld\n", maxl);
  return 0;
}



Measured memory_bytes: 5556
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define FOR(i,n) for(size_t i=0;i<(n);i++)
#define REP(n) FOR(i,n)
#define cinv(v,n) for(size_t i=0;i<(n);i++){cin>>(v)[i];}
#define nvec(type,v,n) vector<type> v(n);cinv(v,n)
#define npairs(type1,type2,v,n) vector<pair<type1,type2>> v(n);for(size_t i=0;i<(n);i++){cin>>v[i].first>>v[i].second;}
#define npairs(type1,type2,v,n) vector<pair<type1,type2>> v(n);for(size_t i=0;i<(n);i++){cin>>v[i].first>>v[i].second;}
#define ntuples(type1,type2,type3,v,n) vector<tuple<type1,type2,type3>> v(n);for(size_t i=0;i<(n);i++){cin>>get<0>(v[i])>>get<1>(v[i])>>get<2>(v[i]);}

#define min_index(v) size_t(min_element(all(v))-(v).begin())
#define max_index(v) size_t(max_element(all(v))-(v).begin())
#define min_e(v) *min_element(all(v))
#define max_e(v) *max_element(all(v))

#define count_le(v,a) size_t(upper_bound(all(v),a)-(v).begin())
#define count_lt(v,a) size_t(lower_bound(all(v),a)-(v).begin())
#define count_ge(v,a) size_t((v).end()-lower_bound(all(v),a))
#define count_gt(v,a) size_t((v).end()-upper_bound(all(v),a))

#define order(neq_sl) [](const auto s, const auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}

#define acm accumulate
#define SUM(v) accumulate(all(v),0l)

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


int main() {
  long long a,b;
  cin>>a>>b;
  cout<<a*b/gcd(a,b);
}

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

int main()
{
    long test;
    test=1;
    // cin>>test;
    while(test--){
    long i,j,a,b,n,x,ans,most,index,c,maxi=0;
    cin>>n>>c;
    cout<<(n+c)%24;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ck cout<<" xxx  "<<endl
typedef long long ll;
const int maxn=1e3+100;
const int maxc=26;
const int inf=0x3f3f3f3f;
ll n,k;
ll f(ll x){
    ll d=x/k;
    x=x-d*k;
    //cout<<x<<endl;
    return min(x,k-x);
}
map<ll,bool>mp;
int main()
{
    scanf("%lld%lld",&n,&k);
    //ck;
    printf("%lld\n",f(n));
    return 0;
}
/*

*/


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

template <class T>
struct SegmentTree {
  typedef function<T(T, T)> F;
  int n;
  F f;
  T unit;
  vector<T> dat;
  SegmentTree(){};
  SegmentTree(int newn, F f, T t) : f(f), unit(t) {
    init(newn);
  }
  void init(int newn) {
    n = 1;
    while(n < newn) n <<= 1;
    dat.assign(n << 1, unit);
  }

  // "go up" process
  void update(int k, T newdata) {
    dat[k += n] = newdata;
    while(k >>= 1) {
      dat[k] = f(dat[(k << 1) | 0], dat[(k << 1) | 1]);
    }
  }
  // [a,b)
  T query(int a, int b) {
    T vl = unit, vr = unit;
    for(int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) {
      if(l & 1) vl = f(vl, dat[l++]);
      if(r & 1) vr = f(dat[--r], vr);
    }
    return f(vl, vr);
  }
};

long long n, q;

int main() {
  cin >> n >> q;
  SegmentTree<long long> rmq(
      n, [](int l, int r) { return min(l, r); },
      (long long)(2147483647));
  for(int i = 0; i < q; ++i) {
    int c, x, y;
    cin >> c >> x >> y;
    if(c == 0)
      rmq.update(x, y);
    else
      cout << rmq.query(x, y + 1) << endl;
  }
  return 0;
}


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

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

  bool flag = true;
  for(int i = 0; i < N; i++){
    int x;
    cin >> x;
    if(x % 2 == 0){
      if(x % 3 != 0 && x % 5 != 0){
        flag = false;
      }
    }
  }
  if(flag){
    cout << "APPROVED" << endl;
  }else{
    cout << "DENIED" << endl;
  }
}

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

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();

        Map<Integer, List<NodeAndDistance>> distanceMap = new HashMap<>();

        for (int i = 0; i < n - 1; i++) {
            final int x = scanner.nextInt();
            final int y = scanner.nextInt();
            final int distance = scanner.nextInt();

            distanceMap.computeIfAbsent(x, e -> new ArrayList<>())
                    .add(new NodeAndDistance(y, distance));
            distanceMap.computeIfAbsent(y, e -> new ArrayList<>())
                    .add(new NodeAndDistance(x, distance));
        }

        final int[] array = new int[n];
        final boolean[] checked = new boolean[n];
        recursive(distanceMap, distanceMap.get(1), 0, array, checked);

        for (final int i : array) {
            System.out.println(i);
        }
    }

    private static void recursive(final Map<Integer, List<NodeAndDistance>> distanceMap, final List<NodeAndDistance> nodeAndDistanceList, final int distanceFormParent, final int[] array, final boolean[] checked) {
        for (final NodeAndDistance nodeAndDistance : nodeAndDistanceList) {
            final int node = nodeAndDistance.getNode();
            if (node == 1 || checked[node - 1]) {
                continue;
            }

            final int distance = nodeAndDistance.getDistance() + distanceFormParent;
            array[node - 1] = distance % 2;
            checked[node - 1] = true;
            recursive(distanceMap, distanceMap.get(node), distance, array, checked);
        }
    }

    static class NodeAndDistance {
        private final int node;
        private final int distance;

        NodeAndDistance(final int node, final int distance) {
            this.node = node;
            this.distance = distance % 2;
        }

        int getNode() {
            return node;
        }

        int getDistance() {
            return distance;
        }
    }
}


Measured memory_bytes: 120204
DBG = !true
DBG2 = !true
DBG3 = !true
require 'pp'

def accinit(a)
  b = Array.new(a.size, 0)
  b[0] = a[0]
  for i in 1...a.size
    b[i] = b[i-1] + a[i]
  end
  $b = b
end

def acc(x)
  return $b[x]
end

def sum(a,i,j)
  if DBG3 && false
    puts "in sum i #{i} j #{j}"
    return a[i..j].inject(:+)
  else
    return acc(j) - (i==0 ? 0 : acc(i-1))
  end
end

def wsum(a,k,d,r,y,n)
  puts "wsum call k #{k} d #{d} r #{r}" if DBG3
  s = 5*sum(a,r+(d-1)*k,r+d*k-1) + (n+k)*y
  for i in 1...d
    z = (2*i+3)*sum(a,r+(d-1-i)*k,r+(d-i)*k-1)
    s += z
    puts "wsum i #{i} add #{z}" if DBG3
  end
  if r>0
    z = (2*d+3)*sum(a,0,r-1)
    s += z
    puts "wsum d #{d} add #{z}" if DBG3
  end
  puts "wsum rtn #{s}" if DBG3
  return s
end

n,y = gets.split.map{|x| x.to_i}
a = gets.split.map{|x| x.to_i}

accinit(a)
mn = 9999999999999999999999999
q = Math.sqrt(n).to_i
for i in 1..(q)
  break if i>n
  d = i
  k = n / d
  r = n % d
  while r >= k
    k += 1
    r -= k
  end
  if r == 0
    s = wsum(a,k,d,r,y,n)
    puts "d0)d #{d} k #{k} r #{r} s #{s}" if DBG
    mn = s if s < mn
  end
  next if d == 1
  if r < d - 1
    r = k - d + r + 1
    k += 1
  else
    r = k
    k += 1
  end
  d -= 1
  while r >= 0
      s = wsum(a,k,d,r,y,n)
      puts "d)d #{d} k #{k} r #{r} s #{s}" if DBG
      mn = s if s < mn
      k += 1
      r -= d
  end
end

for i in 1..(q+2)
  break if i>n
  k = i
  d = n / k
  r = n % k
  s = wsum(a,k,d,r,y,n)
  puts "k)d #{d} k #{k} r #{r} s #{s}" if DBG
  mn = s if s < mn
end

print mn


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

int main(){
	int n;
	cin >> n;
	for(int t=0 ; t < n ; t++ ){
		string order, s;
		cin >> order >> s;
		reverse(order.begin(), order.end());
		for(int i=0 ; i < order.size() ; i++ ){
			char ch = order[i];
			
			if( ch == 'J' ){
				rotate( s.begin() , s.begin()+s.size()-1 , s.end() );
			}else if( ch == 'C' ){
				rotate( s.begin() , s.begin()+1 , s.end() );
			}else if( ch == 'E' ){
				string a, b, c;
				for(int k=0 ; k < s.size()/2 ; k++ ){
					a.push_back(s[k]);
				}
				if( s.size() % 2 == 1 ) b.push_back( s[s.size()/2] );
				for(int k = s.size()/2+(s.size()%2?1:0) ; k < s.size() ; k++ ){
					c.push_back(s[k]);
				}
				s = c + b + a;
			}else if( ch == 'A' ){
				reverse(s.begin(), s.end());
			}else if( ch == 'P' ){
				for(int k=0 ; k < s.size() ; k++ ){
					if( '1' <= s[k] && s[k] <= '9' ) s[k] -= 1;
					else if( s[k] == '0' ) s[k] = '9';
				}
			}else if( ch == 'M' ){
				for(int k=0 ; k < s.size() ; k++ ){
					if( '0' <= s[k] && s[k] <= '8' ) s[k] += 1;
					else if( s[k] == '9' ) s[k] = '0';
				}
			}
		}
		cout << s << endl;
	}
}

Measured memory_bytes: 1224
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t x,y;
    cin >> x >> y;
    vi v1={4,6,9,11};
    vi v2={1,3,5,7,8,10,12};
    string res = "No";
    if(find(v1.begin(), v1.end(), x)!=v1.end()){
        if(find(v1.begin(), v1.end(), y)!=v1.end()){
            res = "Yes";
        }
    }
    if(find(v2.begin(), v2.end(), x)!=v2.end()){
        if(find(v2.begin(), v2.end(), y)!=v2.end()){
            res = "Yes";
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<map>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  vector<int> c(M, 0);
  for(int i=0; i<N; i++){
    int ki;
    cin >> ki;
    for(int j=0; j<ki; j++){
      int aij;
      cin >> aij;
      c[aij-1]++;
    }
  }
  cout << count(c.begin(), c.end(), N) << endl;
  return 0;
}

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

int top, S[1000];

int pop(){
  top--;
  return S[top+1];
}

void push(int x){
  S[++top] = x;
}



int main(int argc, char const *argv[]) {
  int a, b;
  top = 0;
  char s[100];
  while (scanf("%s", s) != EOF) {
    if (s[0] == '+') {
      a = pop();
      b = pop();
      push(a+b);
    }else if (s[0] == '-') {
      b = pop();
      a = pop();
      push(a-b);
    }else if (s[0] == '*') {
      a = pop();
      b = pop();
      push(a*b);
    }else{
      push(atoi(s));
    }
  }

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

  return 0;
}

Measured memory_bytes: 2720
#18:37
n,k = map(int,input().split())
a = list(map(int,input().split()))
now = 2 ** len(bin(k)[2:])
can = 0
while now:
  tmp = 0
  for i in range(n):
    if a[i] ^ now > a[i]:
      tmp += 1
  if tmp * 2 > n:
    can += now
    if can > k:
      can -= now
  now //= 2
ans = 0
for i in range(n):
  ans += a[i] ^ can
#print(can)
print(ans)

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

#define rep(i,n) for (int i=0; i<(n); i++)
const int INF =1001001001;
const ll BIG = 1000000007;

int main(){
    int n;
    ll k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> d(n+1,0), s;
    int now = 1;
    while(d[now]==0){
        s.push_back(now);
        d[now] += 1;
        now = a[now-1];
    }
    int i = 0;
    while(s[i]!=now){
        i++;
    }
    if(k<i) cout << s[k] << endl;
    else {
        int x = (k-i) % (s.size()-i);
        cout << s[i+x] << endl;
    }
    return 0;
}

/*
int solve(vector<bool>reach, vector<int>a_v, ll k){
    vector<int> city(1,1);
    int rep = 1;//移動回数
    int now = 1;
    int next = a_v[now-1];
    while(!reach[next-1]){
        now = next;
        city.push_back(now);
        reach[now-1] = true;
        next = a_v[now-1];
        rep++;
    }
    int i=0;
    while(city[i]!=next) i++;
    int j;
    if(i>k) j = city[i];
    else {
        k = k-i;
        int num;
        num = (k-i)%(rep-i);
        j = city[i+num];
    }
    return j;
}


int solve(vector<bool>reach, vector<int>a_v, ll k){
    vector<int> city(1,1);
    int now = 1;
    int next = a_v[now-1];
    while (!reach[next-1])
    {
        now = next;
        next = a_v[now-1];
        reach[now-1] = true;
        city.push_back(now);
    }
    int i=0;
    while(city[i]!=next) i++;
    int j;
    if(i>k) j = city[k];
    else {
        k = k-i;
        int num;
        num = (k)%(city.size()-i);
        j = city[i+num];
    }
    return j;    
}

int main(){
    int n;
    ll k;
    cin >> n >> k;
    vector<bool> reach(n, false);
    vector<int> a_v(n);
    rep(i,n) {
        cin >> a_v[i];
    }
    reach[0] = true;
    int a;
    a = solve(reach, a_v, k);
    cout << a <<endl;
}
*/

Measured memory_bytes: 5872
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#include <cmath>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define uid uniform_int_distribution<lli>
#define lli long long int
#define ff first
#define ss second
#define pb push_back
#define popf pop_front()
#define popb pop_back()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define forr(x,arr) for(auto& x:arr)
#define sz(x) (x.size())
#define mod 1000000007
#define INF 1000000000000000010
#define vi vector<int>
#define vlli vector<lli>
#define endl "\n"
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

template<class my>
inline my aabs (const my& a)   { return (a > 0)  ? a : -a;         }
inline lli gcd(lli a, lli b)   { return (b == 0) ? a : gcd(b,a%b); }
inline lli LSOne(lli k)        { return (k&(-k));                  }

inline int inv(lli o, int m = mod) {
  int b = m, u = 0, v = 1, t, a=o%m;
  while (a) {
    t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  if (u < 0) u += m;
  return u;
}
inline int add(const int &a, const int &b) { return a + b >= mod ? a + b - mod : a + b; }
inline int sub(const int &a, const int &b) { return a - b < 0 ? a - b + mod : a - b; }
inline int mul(const int &a, const int &b) { return int(a * 1ll * b % mod); }
inline int _div(const int &a, const int &b) { return mul(a, inv(b)); }
inline int pow(int a, int b) {
    int ans = 1;
    while (b) {
        if (b & 1) ans = mul(ans, a);
        a = mul(a, a);
        b >>= 1;
    }
    return ans;
}
int xo, around=0, value=mod;

void solve()
{
    lli n=0, m=0, k=0, q=0, temp=0, u=0, v=0, ans=0, ans1=0, ans2=0, val=0, mini=INF, maxi=-INF;
    cin>>n>>m;
    vector<vi> adj(n+5);
    vi depth(n+5,0);
    vector<vector<int>> visited(3,vector<int>(n+5, 0));
    fol(i,0,m)
    {
        cin>>u>>v;
        adj[u].pb(v);
    }
    cin>>u>>xo;
    queue<pair<int,int>> qu;
    qu.push({u,0});
    pair<int,int> s;
    while(!qu.empty())
    {
        s = qu.front();
        if(s.ff==xo&&s.ss%3==0) break;
        s.ss++;
        qu.pop();
        forr(i,adj[s.ff])
        {
            if (!visited[s.ss%3][i])
            {
                visited[s.ss%3][i] = 1;
                qu.push({i,s.ss});
            }
        }
    }
    if(visited[0][xo]) cout<<s.ss/3<<endl;
    else cout<<-1<<endl;

}

int main()
{
    //fastio cout<<endl;
    int t=1;
    //cin>>t;
    while(t--)
        solve();
}


Measured memory_bytes: 7288
// ABC 86 A

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

typedef long long ll;

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 long INF = 1LL<<60;

int main()
{
  int a, b;
  cin >> a >> b;
  if (a * b % 2 == 0) {
    cout << "Even";
  } else {
    cout << "Odd";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <fstream>
#define inputtxt() std::ifstream in("input.txt"); std::cin.rdbuf(in.rdbuf())
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define foreach(e, v) for (auto e : v)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define collect(arr, size) rep(i,size) cin >> arr[i];

#define pushall(queue, size) rep(i,size){int tmp; cin >> tmp; queue.push(tmp);}
#define int long long
using intpair = pair<int,int>;
vector<intpair> arr;

signed main(){
    int x, y, z, k;
    cin >> x >> y >> z >> k;
    vector<int> A(x), B(y), C(z);
    collect(A, x); collect(B, y); collect(C, z);
    sort(rall(A)); sort(rall(B)); sort(rall(C));
    
    vector<int> rank;
    rep(a,x)rep(b,y)rep(c,z){
        if((a+1)*(b+1)*(c+1)>k) continue;
        rank.push_back(A[a]+B[b]+C[c]);
    }
    sort(rall(rank));
    rep(i,k){
        cout << rank[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 1404
L = [0, 0, 0, 0]
for i in range(3):
	a, b = list(map(int, input().split()))
	L[a - 1] += 1
	L[b - 1] += 1

L = sorted(L)
if L[0] == 1 and L[-1] == 2:
	print("YES")
else:
	print("NO")

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

int main() {
  int N, T;
  cin >> N >> T;
  
  vector<int> c(N), t(N);
  for(int i = 0; i < N; i++) {
    cin >> c.at(i) >> t.at(i);
  }
  
  vector<int> f(N);
  for(int i = 0; i < N; i++) {
    if(t.at(i) <= T) {
      f.at(i) = c.at(i);
    } else {
      f.at(i) = 1001;
    }
  }
  
  sort(f.begin(), f.end());
  
  if(f.at(0) <= 1000) {
    cout << f.at(0) << endl;
  } else {
    cout << "TLE" << endl;
  }
}

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

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

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

typedef long long INTEGER;
typedef double FLOAT;

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

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

void swap(int*a, int*b) {
  int t = *b;
  *b = *a;
  *a = t;
}

int digit (long a) {
  if (a == 0) return 1;
  int r = 0;
  while (a > 0) {
    ++r;
    a /= 10;
  }
  return r;
}

int main() {

  int a, b;
  for (; scanf("%d", &a) != EOF; ) {
    scanf("%d", &b);
    cout << digit(a + b) << endl;
  }

  return 0;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
#define int long long
#define ld long double
#define ri register int
#define il inline
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define all(x) x.begin(),x.end() 
#define rep(i,a,b) for(ri i=(a);i<=(b);++i)
#define per(i,a,b) for(ri i=(a);i>=(b);--i)
#define ls (x<<1)
#define rs (x<<1|1)
#define mid (l+r>>1)
#define db(x) cout << "#x:" << x << endl
#define dd() cout << "Out put!\n"
const int mod=1e9+7,maxn=1000010;
const double eps=1e-8,pi=acos(-1.0);
const int inf=0x7f7f7f7f;
using namespace std;
il int qpow(int base,int m)
{
	int res = 1; 
	while(m)
	{
		if(m&1)
			(res*=base)%=mod;
		(base*=base)%=mod;
		m >>= 1;
	}
	return res%mod;
}
int f[maxn];
int inv[maxn];
il int C(int n,int m)
{
	return f[n]*inv[m]%mod*inv[n-m]%mod; //组合数 
} 
signed main()
{
	ios::sync_with_stdio(0);
	int n,m;
	cin >> n >> m;
	f[0] = inv[0]= 1;
	rep(i,1,maxn-1)
		f[i]=f[i-1]*i%mod,inv[i] = qpow(f[i],mod-2);
	int ans = C(m,n) * C(m,n)%mod * f[n] % mod * f[n] % mod;
//	cout << ans << endl;
	rep(i,1,n)
	{
		if(i&1) 
			ans = (ans - C(n,i)*C(m,i)%mod* f[i] % mod * f[n - i] % mod* f[n - i] % mod * C(m-i,n-i) % mod * C(m-i,n-i) % mod + mod) % mod;
		else 
			ans = (ans + C(n,i) * C(m,i) % mod * f[i] % mod * f[n - i] % mod* f[n - i] % mod * C(m - i, n - i) % mod * C(m - i, n - i) % mod) % mod; 
		//cout << ans << endl;
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  set<int> owner;
  for (int i = 0; i < k; i++) {
    int d; cin >> d;
    for (int j = 0; j < d; j++) {
      int a; cin >> a; owner.insert(a);
    }
  }
  cout << n - owner.size() << endl;
  return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include <numeric>
using namespace std;
int const M = 100000;
int odd[M];
int even[M];
#define REP(a,b) for(int i = a; i < b; i++)

vector<size_t> sort_index(int *arr){
    vector<size_t> idx(M);
    iota(idx.begin(), idx.end(), 0);

    sort(idx.begin(), idx.end(),
        [arr](size_t i1, size_t i2){return arr[i1] > arr[i2];});
    return idx;
}

int main(){
    REP(0,M){
        odd[i] = 0;
        even[i] = 0;
    }
    int N;
    cin >> N;
    int A[N];
    REP(0,N){
        int tmp;
        cin >> tmp;
        if(i % 2 == 0) even[tmp]++;
        else odd[tmp]++;
    }
    int max_odd = 0, max_even = 0;
    int idx_odd, idx_even;
    int smax_odd = 0, smax_even = 0;
    vector<size_t> odd_idx = sort_index(odd);
    vector<size_t> even_idx = sort_index(even);
    if (odd_idx[0] != even_idx[0])
    cout << N - odd[odd_idx[0]] - even[even_idx[0]] << "\n";
    else {
        int min_out = N - max(odd[odd_idx[0]] + even[even_idx[1]], odd[odd_idx[1]] + even[even_idx[0]]);
        cout << min_out << '\n';
    }


}


Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <sstream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
using namespace std;
int i,j,k,n,m;
string s;

int main() {
  cin>>n;
  int out=0;
  for(i=0;i<n;++i) {
    int t;cin>>t;
    out += t-1;
  }
  cout << out << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mo 1000000007
#define maxn 1000000000000000000LL
#define pi 3.1415926535898
#define eps 1e-9 
using namespace std;
long long read(){
    long long xx=0,flagg=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
long long t,i,a,b,c,d,l,r,mid,flag,flag2,max1,x,y;
int main(){
  	//freopen(".in","r",stdin);
  	//freopen(".out","w",stdout);
  	t=read();
  	while(t--){
  		a=read();b=read();c=read();d=read();
  		l=0;r=a+b+1;mid=(l+r)/2;flag=(max(a,b)-1)/(min(a,b)+1)+1;max1=maxn;
		while(l<=r){
  			x=a-mid/(flag+1)*flag-mid%(flag+1);
  			y=b-mid/(flag+1);
  			if(y<=x*flag)
  				l=mid+1;
  			else{
  				r=mid-1;
  				max1=min(max1,mid);
  			}
  			mid=(l+r)/2;
  		}
  		x=a-max1/(flag+1)*flag-max1%(flag+1);
  		y=b-max1/(flag+1);
  		flag2=max1+y-x*flag+1;
  		for(i=c;i<=min(d,max1);i++)
  			if(i%(flag+1)!=0)
  				putchar('A');
  			else
  				putchar('B');
  		for(i=max(c,max1+1);i<=d;i++)
  			if((i-flag2)%(flag+1)!=0)
  				putchar('B');
  			else
  				putchar('A');
  		putchar('\n');
	}
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
typedef pair<int,int> P;
int smp[35][35],n,SUM,W,H,used[35][35][35][35];
P mem[35][35][35][35];

int cal(int x1,int y1,int x2,int y2){
  return smp[y2][x2]-(smp[y1-1][x2]+smp[y2][x1-1])+smp[y1-1][x1-1];
}

P dfs(int x,int y,int w,int h){
  if(used[x][y][w][h]++) return mem[x][y][w][h];

  P res=P(1,n-(SUM-cal(x,y,w,h)));
  for(int i=x;i!=w;i++){
    int m=max(SUM-cal(x,y,i,h),SUM-cal(i+1,y,w,h));
    if(m<=n){
      P a=dfs(x,y,i,h);
      P b=dfs(i+1,y,w,h);
      res=max(res,P((a.f+b.f),min(a.s,b.s)));
    }
  }

  for(int i=y;i!=h;i++){
    int m=max(SUM-cal(x,y,w,i),SUM-cal(x,i+1,w,h));
    if(m<=n){
      P a=dfs(x,y,w,i);
      P b=dfs(x,i+1,w,h);
      res=max(res,P((a.f+b.f),min(a.s,b.s)));
    }
  }
  return mem[x][y][w][h]=res;
}

int main(){
  while(1){
  cin>>H>>W>>n;
  if(!H&&!W&&!n)break;
  memset(used,0,sizeof(used)),memset(mem,0,sizeof(mem));

  for(int i=1;i<=H;i++)
    for(int j=1;j<=W;j++)cin>>smp[i][j];

  for(int i=1;i<=H;i++)for(int j=1;j<=W;j++) smp[i][j+1]+=smp[i][j];
  for(int i=1;i<=H;i++)for(int j=1;j<=W;j++) smp[i+1][j]+=smp[i][j];
  SUM=smp[H][W];
  P ans=dfs(1,1,W,H);
  cout <<ans.f<<" "<<ans.s<<endl;
  }
  return 0;
}

Measured memory_bytes: 18772
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
int mod = 1000000007;
const int N = 1e6+10;
char s[222][222];
int main() 
{
  //  freopen("in.txt", "r", stdin);
    int n, m;
    int dir[9][2] = {-1, -1, -1, 0, -1, 1, 0, -1, 0, 0, 0, 1, 1, -1, 1, 0, 1, 1};
    const char* mp = "0123456789";
    while (~scanf("%d%d", &n, &m))
    {
        for (int i = 0; i < n; i++)
            scanf("%s", s[i]);
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++) if (s[i][j] == '.')
            {
                int cnt = 0;
                for (int k = 0; k < 9; k++)
                {
                    int x = i + dir[k][0];
                    int y = j + dir[k][1];
                    if (x >= 0 && x < n && y >= 0 && y < m)
                    {
                        cnt += s[x][y] == '#';
                    }
                }
                s[i][j] = mp[cnt];
            }
        for (int i = 0; i < n; i++)
            puts(s[i]);
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>

int get() {
    int x = 0; char s = getchar();
    while (s < '0' || s > '9') s = getchar();
    while (s >= '0' && s <= '9') x = (x << 3) + (x << 1) + (s ^ 48), s = getchar();
    return x;
}

int main() {
    int k, a, b;
    scanf("%d%d%d", &k, &a, &b);
    if(ceil(1.0 * a / k) * k <= b) printf("OK");
    else printf("NG");
    return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int H = 11;
const int W = 1001;

int a[H][W],h,w,k;

int daj(int i1,int j1,int i2,int j2){
    return a[i2][j2]-a[i2][j1-1]-a[i1-1][j2]+a[i1-1][j1-1];
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> h >> w >> k;
    for(int i = 1; i <= h; i++){
        string s;
        cin >> s;
        for(int j = 0; j < w; j++){
            a[i][j+1] = s[j]-'0';
        }
    }
    for(int i = 2; i <= h; i++){
        a[i][1] += a[i-1][1];
    }
    for(int i = 2; i <= w; i ++){
        a[1][i] += a[1][i-1];
    }
    for(int i = 2; i <= h; i++){
        for(int j = 2; j <= w; j++){
            a[i][j] = a[i-1][j]+a[i][j-1]-a[i-1][j-1]+a[i][j];
        }
    }
    ll sol = 1000000000;
    for(int mask = 0; mask < (1 << (h-1)); mask++){
        ll sum = 0;
        vector <int> v;
        v.push_back(0);
        for(int i = 0; i < h-1; i++){
            if(mask&(1<<i)){
                v.push_back(i+1);
            }
        }
        v.push_back(h);
        ll s = __builtin_popcount(mask);
        ll lst = 1;
        bool moze = 1;
        for(int i = 1; i <= w; i++){
            bool uzmi = 0;
            for(int j = 0; j < v.size()-1; j++){
                int ima = daj(v[j]+1,lst,v[j+1],i);
                if(ima > k){
                    s++;
                    uzmi = 1;
                    break;
                }
            }
            if(uzmi){
                for(int j = 0; j < v.size()-1; j++){
                    int ima = daj(v[j]+1,lst,v[j+1],i-1);
                    if(ima > k){
                        moze = 0;
                        break;
                    }
                }
                if(!moze){
                    break;
                }
                //cout << mask << " stavljam na " << i << endl;
                lst = i;
            }
        }
        if(moze){
           sol = min(sol,s);
        }
    }
    cout << sol << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

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

    int i = 1;
    while (++i <= n) {
        int x = i;
        if (x % 3 == 0) {
            cout << ' ' << i;
        }
        else{
            while (x > 0) {
                if (x % 10 == 3) {
                    cout << ' ' << i;
                    break;
                }
                x /= 10;
            }
        }
    }
    cout << endl;
}


Measured memory_bytes: 3128
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

typedef long long ll;
typedef pair<int, int> pint;

const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };



int main()
{
    int w, h;
    while (scanf("%d%d", &w, &h), w | h)
    {
	char tile[32][32];
	memset(tile, '#', sizeof(tile));
	for (int i = 1; i <= h; ++i)
	{
	    scanf("%s", tile[i] + 1);
	    tile[i][w + 1] = '#';
	}

	int sx, sy;
	for (int y = 1; y <= h; ++y)
	    for (int x = 1; x <= w; ++x)
		if (tile[y][x] == '@')
		    sx = x, sy = y;

	int res = 0;
	queue<pint> q;
	q.push(pint(sx, sy));
	while (!q.empty())
	{
	    pint t = q.front(); q.pop();
	    int x = t.first, y = t.second;

	    if (tile[y][x] == '#')
		continue;

	    ++res;
	    tile[y][x] = '#';

	    for (int i = 0; i < 4; ++i)
		q.push(pint(x + dx[i], y + dy[i]));
	}
	printf("%d\n", res);
    }
}

Measured memory_bytes: 0
#include<stdio.h>
int main(void){
	int st[31];
	for(int i=1; i<=28; i++){
		int x;
		scanf("%d",&x);
		st[x]=1;
	}
	for(int i=1; i<=30; i++){
		if(st[i]!=1){
			printf("%d\n",i);
		}
	}
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>
double pythagoreanProposition(double xi, double yi, double xz, double yz)
{
    double x, y, z;
    x = xi - xz;
    if(x <= 0)
        x = x * -1;
    y = yi - yz;
    if(y <= 0)
        y = y * -1;
    z = (x * x) + (y * y);
    return z;
}

/*double root()
{
}
*/

int main(void){
    char text[100];
    double xi, yi, xz, yz;
    double zz;
    //double distance;
    fgets(text, 100, stdin);
    sscanf(text, "%lf %lf %lf %lf", &xi, &yi, &xz, &yz);
    zz = pythagoreanProposition(xi, yi, xz, yz);
    //printf("%d\n", zz);
    //distance = zz
    //sqrt(distance);
    printf("%lf\n", sqrt(zz));
    return 0;
}


Measured memory_bytes: 2048