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

use std::cmp;
use std::cmp::{max, min, Ordering};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::io::stdin;
use std::ops::*;
use std::process::exit;
use std::str::FromStr;

#[macro_export]
macro_rules! minimum {
    ($($e:expr),+) => {
        {
            let mut res = Vec::new();
            $(
                res.push($e);
            )+
            res.into_iter().min().unwrap()
        }
    };
}

pub const MOD: usize = 1000000007;

fn main() {
    let s: Vec<char> = input::<String>().chars().collect();
    let mut ans = "No";
    for w in s.windows(2) {
        if w == &['A', 'C'] {
            ans = "Yes";
            break;
        }
    }
    println!("{}", ans);
}

pub fn input<T: FromStr>() -> T {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().ok().unwrap()
}

pub fn input_vec<T: FromStr>() -> Vec<T> {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim()
        .split_whitespace()
        .map(|x| x.parse().ok().unwrap())
        .collect::<Vec<_>>()
}

pub fn input_lines<T: FromStr>(l: usize) -> Vec<T> {
    let mut res = Vec::new();
    for _i in 0..l {
        res.push(input());
    }
    res
}

pub fn input_lines_two<T: FromStr, U: FromStr>(l: usize) -> Vec<(T, U)> {
    let mut res = Vec::new();
    for _i in 0..l {
        res.push(input_two());
    }
    res
}

pub fn input_lines_three<T: FromStr, U: FromStr, V: FromStr>(l: usize) -> Vec<(T, U, V)> {
    let mut res = Vec::new();
    for _i in 0..l {
        res.push(input_three());
    }
    res
}

pub fn input_two<T: FromStr, U: FromStr>() -> (T, U) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let s: Vec<&str> = buf.split_whitespace().collect();
    (
        s[0].parse::<T>().ok().unwrap(),
        s[1].parse::<U>().ok().unwrap(),
    )
}

pub fn input_three<T: FromStr, U: FromStr, V: FromStr>() -> (T, U, V) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let s: Vec<&str> = buf.split_whitespace().collect();
    (
        s[0].parse::<T>().ok().unwrap(),
        s[1].parse::<U>().ok().unwrap(),
        s[2].parse::<V>().ok().unwrap(),
    )
}

pub fn input_four<T: FromStr, U: FromStr, V: FromStr, W: FromStr>() -> (T, U, V, W) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let s: Vec<&str> = buf.split_whitespace().collect();
    (
        s[0].parse().ok().unwrap(),
        s[1].parse().ok().unwrap(),
        s[2].parse().ok().unwrap(),
        s[3].parse().ok().unwrap(),
    )
}

pub fn input_matrix<T: FromStr + Clone>(h: usize) -> Vec<Vec<T>> {
    let mut res = vec![Vec::new(); h];
    for i in 0..h {
        res[i] = input_vec();
    }
    res
}


Measured memory_bytes: 4352
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int asc(const void* a, const void* b) {
	return *(int*)a- *(int*)b;
}

int main()
{
	int n;
	int ans = 3;
	char s[105];
	cin >> n;
	rep(i, n) {
		cin >> s[i];
		if (s[i] == 'Y') {
			ans = 4;
			break;
		}
	}
	if (ans == 4) cout << "Four" << endl;
	else cout << "Three" << endl;
}

Measured memory_bytes: 256
use std::io;
fn main() {
    let mut l1 = String::new();
    let stdin = io::stdin();
    stdin.read_line(&mut l1).unwrap();
    let trimed = l1.trim_end();
    let mut itr = trimed.split_ascii_whitespace();
    let r = itr.next().unwrap().parse::<f64>().unwrap();
    println!("{}", 2_f64 * std::f64::consts::PI * r);
}

Measured memory_bytes: 2196
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

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

int n;
ll t[100];

int main() {
    fastio();

    cin >> n;
    forn(i, n) cin >> t[i];

    ll lcm = t[0];
    forn1(i, n - 1) {
        ll g = gcd(lcm, t[i]);
        lcm = lcm * (t[i] / g);
    }

    cout << lcm << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5 << 28, MOD = 1e9 + 7;

int N, M, K;

vector<pii> A;
vi V[200002];
void input() {
  int x, y, z;
  cin >> N >> M;
  A.resize(M);
  rep(i, 0, M - 1) {
    cin >> x >> y;
    A[i] = pii(x - 1, y - 1);
    V[x].push_back(y);
    V[y].push_back(x);
  }
}
void solve() {
  vi vn = V[N];
  for (auto x : vn) {
    for (auto y : V[x]) {
      if (y == 1) {
        cout << "POSSIBLE" << endl;
        return;
      }
    }
  }
  cout << "IMPOSSIBLE" << endl;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

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

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

    ll ans = 0;
    ll now = 1;
    if(n % 2 == 0){
        ll k = pow(5,now) * 2;
        while(1){
            if(n / k == 0){
                break;
            }else{
                ans += n / k;
                now++;
                k = pow(5, now) * 2;
            }
        }
    }

    cout << ans << endl;
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD (ll)998244353

ll N;
char X[202020];
ll mk[202020];
ll pow2[202020];
ll i, j, k,ans;



int main(){
    scanf("%lld%s", &N,X);
    j = 1;
    ans = 1;
    pow2[0] = 1;
    fornum(i,0,N){
        if(X[N-i-1]=='1'){
            ans = (ans + j) % MOD;
        }
        j = j * 2 % MOD;
        pow2[i + 1] = j;
    }
    //printf("%lld %lld\n", ans,ans*2*N%MOD);
    ans = ans * 2 * N % MOD;
    //printf("%lld\n", ans);
    fornum(i,1,N){
        
        if(N%i||N/i%2==0)
            continue;
        k = N / i;
        ll aa = (MOD - mk[i]) % MOD;
        fornum(j,0,i){
            if(X[j]=='1'){
                aa = (aa + pow2[i - j - 1]) % MOD;
            }
        }
        
        fornum(j,0,N){
            if((X[j%i]=='1')^(j/i%2)!=('1'==X[j])){
                if(X[j]=='1')
                    aa++;
                break;
            }
        }
        if(j==N)
            aa++;
        ans = (ans + (MOD - 2 * N + i*2)*aa) % MOD;
        for (j = i*2; j <= N;j+=i){
            mk[j] = (mk[j] + aa) % MOD;
        }
    }
    printf("%lld", ans);

    return 0;
}

Measured memory_bytes: 3584
N, P = map(int, input().split())
num = input().strip()
ans = 0
if P == 2:
    for idx, nu in enumerate(num):
        if nu in '24680':
            ans += idx + 1
elif P == 5:
    for idx, nu in enumerate(num):
        if nu in '50':
            ans += idx + 1
else:
    nnum = [0] * N
    base = 1
    for i in range(N-1, -1, -1):
        nnum[i] = (int(num[i]) * base) % P
        base = (base * 10) % P
    for i in range(1, N):
        nnum[i] = (nnum[i] + nnum[i-1]) % P
    dp = [0] * P
    for i in range(N):
        if nnum[i] == 0:
            ans += 1 + dp[nnum[i]]
        else:
            ans += dp[nnum[i]]
        dp[nnum[i]] += 1
print(ans)


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

// べき乗mod計算
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    ll MOD = 1000000007;
    int n;
    cin >> n;
    vector<ll> c(n);
    rep(i, n) cin >> c[i];
    
    sort(c.begin(), c.end(), greater<int>());
    
    ll p = modpow(4, n-1, MOD);
    ll ans = 0;
    rep(i, n)
        ans = (ans + c[i]*(i+2) % MOD) % MOD;
    cout << ans * p % MOD << endl;
}

Measured memory_bytes: 1792
/**
  *    █████╗  ██████╗       ██████╗ ██╗     ███████╗
  *   ██╔══██╗██╔════╝       ██╔══██╗██║     ╚══███╔╝
  *   ███████║██║            ██████╔╝██║       ███╔╝
  *   ██╔══██║██║            ██╔═══╝ ██║      ███╔╝
  *   ██║  ██║╚██████╗▄█╗    ██║     ███████╗███████╗
  *   ╚═╝  ╚═╝ ╚═════╝╚═╝    ╚═╝     ╚══════╝╚══════╝
  *
  *  @Author: TieWay59
  *  @Created: 2019/11/24 20:36
  *  @Link: https://atcoder.jp/contests/abc146/tasks/abc146_a
  *  @Tags:
  *
  *******************************************************/


#include <bits/stdc++.h>

#ifdef DEBUG
//#define debug(x)  cerr <<#x << " = "<<x<<endl;
#include "libs59/debugers.h"

#else
#define endl '\n'
#define debug(...)  59
#endif

#define STOPSYNC ios::sync_with_stdio(false);cin.tie(nullptr)
#define MULTIKASE int Kase=0;cin>>Kase;for(int kase=1;kase<=Kase;kase++)
typedef long long ll;
const int MAXN = 2e5 + 59;
const int MOD = 1e9 + 7;
const int INF = 0x3F3F3F3F;
const ll llINF = 0x3F3F3F3F3F3F3F3F;
using namespace std;


int n;

void solve(int kaseId = -1) {
    string t;
    cin >> n;
    cin >> t;

    for (auto &si:t) {
        int id = si - 'A';
        id = (id + n) % 26;
        si = 'A' + id;
    }
    cout << t << endl;
}

void solves() {
    MULTIKASE {
        solve(kase);
    }
}

int main() {
    STOPSYNC;
    solve();
    return 0;
}
/*

 */

Measured memory_bytes: 256
N = int(input())

if N in range(1,10):
  print(N)
elif N in range(10, 100):
  print(9)
elif N in range(100, 1000):
  print(9+(N-100+1))
elif N in range(1000, 10000):
  print(9+900)
elif N in range(10000, 100000):
  print(9+900+(N-10000+1))
elif N == 100000:
  print(9+900+90000)


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

int INF=2000000007;
 
int main() {
  int N;
  cin >> N;
  vector<tuple<int,int,int>> posx(N);
  vector<tuple<int,int,int>> posy(N);
  for (int i=0;i<N;i++){
    int x,y;
    cin >> x >> y;
    posx[i]=make_tuple(x,y,i);
    posy[i]=make_tuple(y,x,i);
  }
  sort(posx.begin(),posx.end());
  sort(posy.begin(),posy.end());
  map<int,int> mx,my;
  for (int i=0;i<N;i++){
    mx[get<2>(posx[i])]=i;
    my[get<2>(posy[i])]=i;
  }
  priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
  vector<bool> used(N,false);
  long long ans=0;
  pq.push(make_pair(0,0));
  int cnt=0;
  while (!pq.empty()){
    pair<int,int> p=pq.top();
    pq.pop();
    int nv=p.second;
    if (used[nv]){
      continue;
    }
    used[nv]=true;
    ans+=p.first;
    if (cnt==N-1){
      break;
    }
    if (mx[nv]>0&&!used[get<2>(posx[mx[nv]-1])]){
      pq.push(make_pair(min(abs(get<0>(posx[mx[nv]])-get<0>(posx[mx[nv]-1])),abs(get<1>(posx[mx[nv]])-get<1>(posx[mx[nv]-1]))),get<2>(posx[mx[nv]-1])));
    }
    if (mx[nv]<N-1&&!used[get<2>(posx[mx[nv]+1])]){
      pq.push(make_pair(min(abs(get<0>(posx[mx[nv]])-get<0>(posx[mx[nv]+1])),abs(get<1>(posx[mx[nv]])-get<1>(posx[mx[nv]+1]))),get<2>(posx[mx[nv]+1])));
    }
    if (my[nv]>0&&!used[get<2>(posy[my[nv]-1])]){
      pq.push(make_pair(min(abs(get<0>(posy[my[nv]])-get<0>(posy[my[nv]-1])),abs(get<1>(posy[my[nv]])-get<1>(posy[my[nv]-1]))),get<2>(posy[my[nv]-1])));
    }
    if (my[nv]<N-1&&!used[get<2>(posy[my[nv]+1])]){
      pq.push(make_pair(min(abs(get<0>(posy[my[nv]])-get<0>(posy[my[nv]+1])),abs(get<1>(posy[my[nv]])-get<1>(posy[my[nv]+1]))),get<2>(posy[my[nv]+1])));
    }
    cnt++;
  }
  cout << ans << endl;
}    

Measured memory_bytes: 13180
#include<iostream>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<algorithm>

using namespace std;

int main(){
  int a,b;
  cin>>a>>b;
  string s[100];
  for(int i=0;i<50;i++){
    for(int j=0;j<100;j++)s[i]+='#';
  }
  for(int i=0;i<50;i++){
    for(int j=0;j<100;j++)s[i+50]+='.';
  }

  int tx = 1;
  int ty = 1;
  for(int i=0;i<a-1;i++){
    s[ty][tx] = '.';
    tx += 2;
    ty += 2*(tx/100);
    tx %= 100;
  }

  tx = 1;
  ty = 51;
  for(int i=0;i<b-1;i++){
    s[ty][tx] = '#';
    tx += 2;
    ty += 2*(tx/100);
    tx %= 100;
  }

  cout<<"100 100"<<endl;
  for(int i=0;i<100;i++)cout<<s[i]<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	char str[21],stra[21];
	int i,c=0;
	scanf("%s",&str);
	while(1) {
		stra[c] = str[c];
		if (str[c]=='\0') {
			break;
		}
		c++;
	}
	for(i=0;i<c;i++) {
		str[i]=stra[c-1-i];
	}
	stra[c]='\0';
	printf("%s\n",str);
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
int main()
{
    long long int a,ans1=1000000000000000000,ans2=1,flag=0;
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        if(a!=0)
        {
         ans1/=a;
        }
        if(a==0)
        {
          flag=1;
        }
        ans2*=a;
    }
    if(flag)
    {
        cout<<"0";
    }
    else if(ans1==0)
    {
        cout<<"-1";
    }
    else
    {
        cout<<ans2;
    }
   return 0;
}




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

int main(){
    long long A, B, N, num;
    cin >> A >> B >> N;
    if (N < B) {
        num = N;
    }
    else if (N % B == B - 1) {
        num = N;
    }
    else {
        num = N / B * B - 1;
    }
    cout << A * num / B - A  * (num / B);
} 

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

int main(){
    int N, L;
    cin >> N >> L;
    string S[N];
    string str="";
    
    for(int i = 0; i < N; i++){
        cin >> S[i];
    }
    sort(S, S + N);
    for(int i = 0; i < N; i++){
        str += S[i];
    }
    cout << str << endl;
}


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

if a[0] != 0:
    if n == 0 and a[0] == 1:
        print(1)
    else:
        print(-1)
    exit()

ruiseki = a[::-1]
for i in range(1, n+1):
    ruiseki[i] += ruiseki[i-1]
ruiseki = ruiseki[::-1]

node = [1]
komoti = [1]
for i in range(1, n+1):
    ai = a[i]
    if komoti[-1]*2 >= ai:
        node.append(min(ruiseki[i], komoti[-1]*2))
        komoti.append(node[-1]-ai)
    else:
        print(-1)
        exit()

print(sum(node))

Measured memory_bytes: 90164
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)
constexpr ll MOD = 998244353;

class Enumeration {
public:
  explicit Enumeration(int n, uint64_t mod)
    : fact(n), inv(n), finv(n), mod(mod) {
    fact[0] = finv[0] = inv[1] = 1;
    for (int i = 2; i < n; ++i) inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    for (int i = 1; i < n; ++i) {
      fact[i] = fact[i - 1] * i % mod;
      finv[i] = finv[i - 1] * inv[i] % mod;
    }
  }
  uint64_t operator()(int n, int k) {
    if (n < k || n < 0 || k < 0) return 0;
    return fact[n] * finv[n - k] % mod * finv[k] % mod;
  }
  uint64_t modpow(uint64_t x, uint64_t e) {
    uint64_t res = 1;
    while (e > 0) {
      if (e & 1) res = res * x % mod;
      x = x * x % mod;
      e >>= 1;
    }
    return res;
  }

private:
  uint64_t mod;
  vector<uint64_t> fact, inv, finv;
};

int main() {
  ll n, a, b, k;
  cin >> n >> a >> b >> k;

  // 赤、緑、青いずれか2つが求まれば場合の数の計算。
  // でもO(n ^ 2)はむり。。。
  // 特典が2種類なのでこれを固定しよう

  Enumeration e(n + 1, MOD);
  ll ans = 0;
  for (ll anum = 0; anum <= n; ++anum) {
    if (k < a * anum) break;
    ll rem = k - a * anum;
    if (rem % b != 0) continue;
    ll bnum = rem / b;
    ans = (ans + e(n, anum) * e(n, bnum) % MOD) % MOD;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 10320
#include <stdio.h>

/*not clear*/

int main(){
  char A[100000];
  scanf("%s",&A);

  int n=0;int y=0;int z=0;
  int Check;
  while (A[n] != '\0') {
    Check = A[n]-'0';
    if (Check == n%2) {
      y++;
    } else {
      z++;
    }
    n++;
  }

  int ans = 0;
  if (y > z) {
    ans = z;
  } else {
    ans = y;
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


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


	if(n<1200)printf("ABC\n");
	else if (n<2800)printf("ARC\n");
	else printf("AGC\n");


	return 0;
}

Measured memory_bytes: 128
#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;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define int ll
#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

void solve() {
    int x;
    cin>>x;
    for(int i = -200; i <= 200; i++) {
        for(int j = -200; j <= 200; j++) {
            int ff = power(i, 5, LLONG_MAX);
            int ss = power(j, 5, LLONG_MAX);
            if(ff - ss == x) {
                cout<<i<<' '<<j;
                return;
            }
        }
    }
} 


int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    int t = 1;
    //cin>>t;
    for(int test = 1; test <= t; test++) {
        //cout<<"Case #"<<test<<": ";
        solve();
    }
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>

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

    int n, m;

    while (std::cin >> n, n) {
        int cnt_two = 0, cnt_five = 0;

        while (n) {
            m = n;
            for (; (m % 2) == 0;) {
                ++cnt_two;
                m /= 2;
            }
            for (; (m % 5) == 0;) {
                ++cnt_five;
                m /= 5;
            }

            --n;
        }

        std::cout << (cnt_two < cnt_five ? cnt_two : cnt_five)
                  << std::endl;
    }

    return 0;
}

Measured memory_bytes: 1192
n,a,b,c=map(int,input().split())
S=[]
for i in range(n):
  S.append(input())
if a==0 and b==0:
  if S[0]=="AB":
    print("No")
    exit()
if a==0 and c==0:
  if S[0]=="AC":
    print("No")
    exit()
if c==0 and b==0:
  if S[0]=="BC":
    print("No")
    exit()
ans=[]
for i in range(n):
  if [a,b,c]==[1,1,0] and S[i]=="AB":
    if i+1<n:
      if S[i+1]=="AB":
        ans.append("A")
        a=a+1
        b=b-1
      elif S[i+1]=="AC":
        ans.append("A")
        a=a+1
        b=b-1
      else:
        ans.append("B")
        a=a-1
        b=b+1
    else:
      ans.append("A")
      a=a+1
      b=b-1
  elif [a,b,c]==[1,0,1] and S[i]=="AC":
    if i+1<n:
      if S[i+1]=="AC":
        ans.append("A")
        a=a+1
        c=c-1
      elif S[i+1]=="AB":
        ans.append("A")
        a=a+1
        c=c-1
      else:
        ans.append("C")
        a=a-1
        c=c+1
    else:
      ans.append("A")
      a=a+1
      c=c-1
  elif [a,b,c]==[0,1,1] and S[i]=="BC":
    if i+1<n:
      if S[i+1]=="BC":
        ans.append("C")
        c=c+1
        b=b-1
      elif S[i+1]=="AC":
        ans.append("C")
        c=c+1
        b=b-1
      else:
        ans.append("B")
        b=b+1
        c=c-1
    else:
      ans.append("C")
      c=c+1
      b=b-1
  elif S[i]=="AB":
    if [a,b]==[0,0]:
      print("No")
      exit()
    if a>=b:
      ans.append("B")
      a=a-1
      b=b+1
    else:
      ans.append("A")
      a=a+1
      b=b-1
  elif S[i]=="AC":
    if [a,c]==[0,0]:
      print("No")
      exit()
    if a>=c:
      ans.append("C")
      a=a-1
      c=c+1
    else:
      ans.append("A")
      a=a+1
      c=c-1
  elif S[i]=="BC":
    if [b,c]==[0,0]:
      print("No")
      exit()
    if c>=b:
      ans.append("B")
      c=c-1
      b=b+1
    else:
      ans.append("C")
      c=c+1
      b=b-1
print("Yes")
for i in range(n):
  print(ans[i])

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

using namespace std;

typedef long long ll;
#define fi first
#define se second
#define pb push_back

const int N = 100005;
vector <pair <int, int> > v[N];
int res[N];

void dfs(int x, int par, ll col) {
    res[x] = col & 1;
    for (auto y : v[x]) {
        if (y.fi != par) {
            dfs(y.fi, x, col + y.se);
        }
    }
}

int main() {
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    scanf("%d", &n);
    for (int i = 1; i < n; i++) {
        int x, y, w;
        scanf("%d %d %d", &x, &y, &w);
        v[x].pb({y, w});
        v[y].pb({x, w});
    }
    dfs(1, 1, 0);
    for (int i = 1; i <= n; i++) {
        printf("%d\n", res[i]);
    }
    return 0;
}


Measured memory_bytes: 11528
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<functional>
#include<iostream>
#include<vector>
#include<cmath>
using namespace __gnu_pbds;
using namespace std;
typedef  tree<int, null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
  PBDS;
int main()
{ int n ,k;
 cin>>n>>k;
  vector<int > height(n+1);
   for(int a=1;a<=n;a++)
   { cin>>height[a];
   }
   vector<long long int > dp(n+1,0);
    dp[1]=0;
     for(int a=2;a<=n;a++)
     {  
         long long int minim = 1000000000+9;
        int count=1;
         while(count<=k &&  (a-count)>=1)
          {   long long int take =  min(minim,dp[a-count]+abs(height[a]-height[a-count]));
              minim = take;
                count++;
		  }
		   dp[a]=minim;
	 }
	 cout<<dp[n]<<endl;
return 0;
}


Measured memory_bytes: 1408
import math
import random
import sys
import heapq
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, UserString
from functools import lru_cache, cmp_to_key
from itertools import (chain, combinations, combinations_with_replacement,
                       permutations, product)

sys.setrecursionlimit(10**7)
input = sys.stdin.readline
MAX_INT = 2**62-1

n, m = map(int, input().split())
arr = [-int(s) for s in input().split()]
heapq.heapify(arr)

crit = -sum(arr) / (4*m)
while m > 0:
    cnt = -heapq.heappop(arr)
    # print(crit, cnt)
    m -= 1
    if cnt < crit:
        print('No')
        break
else:
    print('Yes')


Measured memory_bytes: 4844
#include<bits/stdc++.h>
#include<string.h>
#define pb push_back
#define all(v) v.begin(),v.end()
#define see(x) cout<<#x<<" : "<<(x)<<endl;
#define ya cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define ff first
#define sc second
typedef unsigned long long ll;
using namespace std;
ll dp[100009][15];
const ll mod=1e9+7;
int main()
{
//    ios::sync_with_stdio(false);
//    cin.tie(NULL),cout.tie(NULL);
    ll n,k,ans=0,i,j;
    string s;
    cin>>s;
    n=s.size();
    if(s[0]=='?')
    {
        for(i=0;i<=9;i++)
        {
            dp[0][i]=1;
        }
    }
    else
    {
        dp[0][s[0]-'0']=1;
    }
    for(i=1;i<n;i++)
    {
        if(s[i]=='?')
        {
            for(j=0;j<=12;j++)
            {
                for(k=0;k<=9;k++)
                {
                    dp[i][(j*10+k)%13]=(dp[i][(j*10+k)%13]%mod + dp[i-1][j]%mod)%mod;
                }
            }
        }
        else
        {
            for(j=0;j<=12;j++)
            {
                ll x=s[i]-'0';
                dp[i][(j*10+x)%13]=(dp[i][(j*10+x)%13]%mod+ dp[i-1][j]%mod)%mod;
            }
        }
    }
//    for(i=0;i<n;i++)
//    {
//        for(j=0;j<=12;j++)
//        {
//            cout<<dp[i][j]<<' ';
//        }
//        cout<<endl;
//    }
    cout<< dp[n-1][5] <<endl;
    return 0;
}


Measured memory_bytes: 15456
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=100000000000000000;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a.at(i);
    ll ans=0;
    while(true){
        ll s=0;
        rep(i,n) s+=a.at(i)/n;
        rep(i,n){
            ll c=a.at(i);
            a.at(i)-=(a.at(i)/n)*n;
            a.at(i)+=s-c/n;
        }
        ans+=s;
        bool u=true;
        rep(i,n){
            if (a.at(i)>n-1) u=false;
        }
        if (u) break;
    }
    cout << ans << endl;

}


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

int main(){
char s[201], t[101], p[101];

scanf("%s %s", s, p);
strcpy(t,s);
strcat(s,t);

if(strstr(s,p)==NULL) printf("No\n");
else printf("Yes\n");

return 0;
}


Measured memory_bytes: 2752
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      n: usize,
    }

    let mut temp = n;
    let mut s = 0;
    while temp > 0 {
        s += temp%10;
        temp /= 10;
    }

    if n%s == 0 {
        puts!("{}\n", "Yes");
    } else {
        puts!("{}\n", "No");
    }
}


Measured memory_bytes: 4352
#include <cmath>
#include <cstdio>
#include <algorithm>

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

using namespace std;

int main(){
	for(int r,n;scanf("%d%d",&r,&n),r;){
		int h[40]={};
		rep(i,n){
			int x1,x2,a; scanf("%d%d%d",&x1,&x2,&a);
			x1+=20;
			x2+=20;
			for(int x=x1;x<x2;x++) h[x]=max(h[x],a);
		}

		double ans=100;
		for(int x1=20-r;x1<20+r;x1++){
			int x2=x1+1;
			ans=min(ans,h[x1]+r-max(sqrt(r*r-(x1-20)*(x1-20)),sqrt(r*r-(x2-20)*(x2-20))));
		}
		printf("%.9f\n",ans);
	}

	return 0;
}

Measured memory_bytes: 1068
N, K = map(int, input().split())
A = list(map(int, input().split()))


class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


def inversion(a):
    "転倒数を求める"
    d = {av: i+1 for i, av in enumerate(sorted(a))}
    b = Bit(len(a))
    ans = 0
    for i, av in enumerate(a):
        ans += i-b.sum(d[av])
        b.add(d[av], 1)
    return ans


MOD = 10**9+7
L = len(set(A))

count = 0
for i in range(N):
    for j in range(N):
        if A[i] > A[j]:
            count += 1
ans = (inversion(A) * K) % MOD + (K*(K-1)//2) * count % MOD
ans %= MOD
print(ans)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#include <string>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) a=max(a, b)
#define chmin(a, b) a=min(a, b)
#define moC(a, s, b) a=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;


/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/


int main(void) {
  ll i, j, k;
  
  ll A, B, N;
  cin >> A >> B >> N;
  
  if(B>N) {
    pt(A*N/B-A*(N/B));
  }else {
    ll t=B-1;
    pt(A*t/B-A*(t/B));
  }
  
  
}


Measured memory_bytes: 3636
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int n, m;
bool ok(string &s, const set<string> &d, const set<string> &f){
	string t = s;
	bool flag = 0;
	if(t[t.size() - 1] == '/') t += "index.html", flag = 1;
	
	each(i, t) if(*i == '/') *i = ' ';
	stringstream ss(t);
	s = "";
	while(ss >> t){
		//dbg(s);
		if(!d.count(s)) return 0;
		if(t == ".") continue;
		if(t == ".."){
			int p = s.rfind("/");
			if(p != s.npos) s = s.substr(0, p);
		}
		else{
			s += "/" + t;
		}
	}
	if(!flag && !f.count(s)) s += "/index.html";
	return f.count(s);
}
int main(){
	while(cin >> n >> m, n){
		set<string> dir, file;
		string s, t;
		
		rep(i, n){
			cin >> s;
			file.insert(s);
			int p;
			while((p = s.rfind("/")) != s.npos){
				s = s.substr(0, p);
				dir.insert(s);
			}
		}
		rep(i, m){
			cin >> s >> t;
			if(!ok(s, dir, file) || !ok(t, dir, file)) cout << "not found" << endl;
			else cout << (s == t ? "yes" : "no") << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1232
use proconio::{input, fastout};
use proconio::marker::Chars;

use std::io::{self, Write};

macro_rules! chmin {
    ($base:expr, $($cmps:expr),+ $(,)*) => {{
        let cmp_min = min!($($cmps),+);
        if $base > cmp_min {
            $base = cmp_min;
            true
        } else {
            false
        }
    }};
}

macro_rules! chmax {
    ($base:expr, $($cmps:expr),+ $(,)*) => {{
        let cmp_max = max!($($cmps),+);
        if $base < cmp_max {
            $base = cmp_max;
            true
        } else {
            false
        }
    }};
}

macro_rules! min {
    ($a:expr $(,)*) => {{
        $a
    }};
    ($a:expr, $b:expr $(,)*) => {{
        std::cmp::min($a, $b)
    }};
    ($a:expr, $($rest:expr),+ $(,)*) => {{
        std::cmp::min($a, min!($($rest),+))
    }};
}

macro_rules! max {
    ($a:expr $(,)*) => {{
        $a
    }};
    ($a:expr, $b:expr $(,)*) => {{
        std::cmp::max($a, $b)
    }};
    ($a:expr, $($rest:expr),+ $(,)*) => {{
        std::cmp::max($a, max!($($rest),+))
    }};
}

#[fastout]
fn main() {
    input! {
        s: Chars,
        t: Chars,
    }

    let n = s.len();
    let m = t.len();
    let mut dp = vec![vec![0i64; 3010]; 3010];

    for i in 1..=n {
        for j in 1..=m {
            if s[i-1] == t[j-1] {
                dp[i][j] = dp[i-1][j-1] + 1;
            } else {
                dp[i][j] = max!(dp[i][j-1], dp[i-1][j]);
            }
        }
    }

    let mut res = Vec::<char>::new();
    let mut i = n;
    let mut j = m;
    while i > 0 && j > 0 {
        if s[i-1] == t[j-1] {
            res.push(s[i-1]);
            i -= 1;
            j -= 1;
        } else {
            if dp[i-1][j] > dp[i][j-1] { i -= 1; }
            else { j -= 1; }
        }
    }
    res.reverse();
    for x in res {
        print!("{}", x);
    }
    print!("\n");
    io::stdout().flush().unwrap();
}


Measured memory_bytes: 73092
n, Y = map(int, input().split())
a = 0
for x in range(n+1):
    for y in range(n-x+1):
        z = n-x-y
        if (x*10000 + y*5000 + z*1000) == Y:
            print(x, y, z)
            a = 1
            break
    if a == 1:
        break
if a != 1:
    print(-1, -1, -1)

Measured memory_bytes: 40684
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A1 = sc.nextInt();
    int A2 = sc.nextInt();
    int A3 = sc.nextInt();
    if (A1 + A2 + A3 >= 22) {
      System.out.println("bust");
    } else {
      System.out.println("win");
    }
  }
}
    

Measured memory_bytes: 22740
a, b = map(int, input().split())
string = ''

if a == b:
  for i in range(a):
    string += str(a)
  print(string)
elif a < b:
  for i in range(b):
    string += str(a)
  print(string)
else:
  for i in range(a):
    string += str(b)
  print(string)

Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7


def main():
    N, T = map(int, input().split())
    AB = []
    for _ in range(N):
        AB.append(list(map(int, input().split())))
    AB.sort()

    dp = [0] * (T + 1)
    ans = 0
    for i in range(N-1):
        for j in range(T, -1, -1):
            if j + AB[i][0] <= T:
                dp[j + AB[i][0]] = max(dp[j + AB[i][0]], dp[j] + AB[i][1])
        ans = max(ans, dp[T-1]+AB[i+1][1])
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 75420
program main
  implicit none
  integer :: n, i, p(50), sp(50), c
  read (*, *) n
  read (*, *) p(1:n)
  sp(1:n) = p(1:n)
  call insertion_sort(sp(1:n))
  c = 0
  do i = 1, n
    if (p(i) /= sp(i)) c = c + 1
  end do
  if (c <= 2) then
    write (*, "(a)") "YES"
  else
    write (*, "(a)") "NO"
  end if

  contains
  subroutine insertion_sort(s)
    implicit none
    integer, intent(inout) :: s(:)
    integer :: i, j, tmp
    do i = 2, size(s)  ! ループ終了時に [1, i] が昇順
      do j = i, 2, -1  ! i の位置にあった新要素が適切な位置に来るまで隣同士 swap
        if (s(j) >= s(j - 1)) exit
        tmp = s(j)
        s(j) = s(j - 1)
        s(j - 1) = tmp
      end do
    end do
  end subroutine insertion_sort
end program main


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	long long n,m;
	while(scanf("%lld%lld",&n,&m)!=EOF)
	{
		long long ans=0;
		if(m>=2*n)
		ans+=n;
		else
		ans=m/2;
		m=m-ans*2;
		ans+=m/4;
		printf("%lld\n",ans);
	}
	return 0;
 }

Measured memory_bytes: 256
/*
    It’s Always Darkest Before the Dawn
                This Time is that Darkness in you Life
                                                            */
 
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define pb push_back  
#define F first
#define S second
#define pii pair<int,int>
#define all(a) a.begin(),a.end()
 
const ll mod=1e9+7,di=998244353,N=3e5+1;
 
bool IsQuery=false; 
ll q=1,a[N];
 
map<int,vector<int>> edge;
map<int,bool> occ;
 
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
 
void solve(){
		
  	string s,t,ans;
  	
  	cin>>s>>t;
  	
  	int dp[3001][3001]={0};
  
  	for(int i=1;i<=(int)s.size();i++){
      
      for(int j=1;j<=(int)t.size();j++){
        
        	if(s[i-1]==t[j-1])
          	dp[i][j]=dp[i-1][j-1]+1;
        	
        	else
              dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
      }      
    }
  	
  	int r=s.size(),c=t.size();
  
  	while(dp[r][c]>0){
      	
      	if(s[r-1]==t[c-1]){
          ans.push_back(s[r-1]);
          r--,c--;
        }
      
      	else if(dp[r-1][c]>dp[r][c-1])
          r--;
      	
      	else
          c--;
    }
  	reverse(all(ans));
  
  	cout<<ans;
  
    return;   
} 
int main(){
    
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    
    if(IsQuery)
    cin>>q;
 
    for(int i=0;i<q;i++){
        solve();
        cout<<"\n";
    }
    return 0;
}

Measured memory_bytes: 38816
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e10;

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

	vector<ll> dp(n,INF);
	for(int i=0;i<n;i++)
	{
		auto itr = lower_bound(dp.begin(), dp.end(), a[i]);
		*itr = a[i];
		/*
		for(int j=0;j<=i;j++)
		{
			if(dp[j] >= a[i])
			{
				dp[j] = a[i];
				break;
			}
		}
		*/
	}
	int ans = n;
	for(int i=0;i<n;i++)
	{
		if(dp[i]==INF)
		{
			ans = i;
			break;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 4424
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

i64 solve() {
  i64 N;
  cin >> N;
  vector<tuple<i64, i64, i64, i64>> lefters;
  vector<tuple<i64, i64, i64, i64>> righters;
  REP(i, N) {
    i64 k, l, r;
    cin >> k >> l >> r;
    if (l >= r) {
      lefters.emplace_back(l - r, k, l, r);
    } else {
      righters.emplace_back(r - l, k, l, r);
    }
  }
  sort(lefters.rbegin(), lefters.rend());
  sort(righters.rbegin(), righters.rend());

  set<int> available;
  REP(i, N) available.insert(i);
  available.insert(-1);  // sentinel
  available.insert(N);   // sentinel

  i64 ans = 0;
  for (auto [gain, k, l, r] : lefters) {
    i64 j = min<i64>(k - 1, lefters.size() - 1);
    auto it = available.upper_bound(j);
    --it;
    if (*it == -1) {
      ans += r;
    } else {
      ans += l;
      available.erase(it);
    }
  }
  for (auto [gain, k, l, r] : righters) {
    i64 j = max<i64>(k, lefters.size());
    auto it = available.lower_bound(j);
    if (*it == N) {
      ans += l;
    } else {
      ans += r;
      available.erase(it);
    }
  }
  return ans;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  cin >> T;
  while (T--) {
    cout << solve() << '\n';
  }
}


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

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

int main() {
    set<string> dic;
    int n;
    cin >> n;
    REP(i,n){
        string q,s;
        cin >> q >> s;
        if(q=="insert")dic.insert(s);
        else{
            if(dic.find(s)!=dic.end())cout << "yes" << endl;
            else cout << "no" << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 32156
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// string to int : -48
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ld r;
    cin >> r;
    cout << r * 2* 3.14159 << endl;

}

Measured memory_bytes: 3816
fun main(){
    val N = readLine()!!.toInt()
    val AB = Array(N){ readLine()!!.split(" ").map { it.toLong() }.let { Pair(it[0], it[1]) } }

    if(N % 2 == 1){
        val aMedian = AB.map { it.first }.sorted()[(N + 1)/2 - 1]
        val bMedian = AB.map { it.second }.sorted()[(N + 1)/2 - 1]
        println(bMedian - aMedian + 1)
    }else{
        val aMedian = AB.map { it.first * 2 }.sorted().let { (it[N/2 - 1] + it[N/2]) / 2 }
        val bMedian = AB.map { it.second * 2 }.sorted().let { (it[N/2 - 1] + it[N/2]) / 2 }
        println(bMedian - aMedian + 1)
    }
}

Measured memory_bytes: 82452
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        var input = new List<int>(10);
        for (int i = 0; i < 10; i++)
        {
            input.Add(int.Parse(Console.ReadLine()));
        }

        for (int i = 0; i < 3; i++)
        {
            Console.WriteLine(input.Max().ToString());
            input.Remove(input.Max());
        }
    }
}

Measured memory_bytes: 9860
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  int n;
  ll d, a;
  cin >> n >> d >> a;
  vector<vector<ll>> x(n, vector<ll>(2));
  for(int i = 0; i < n; i++){
    cin >> x[i][0] >> x[i][1];
  }
  sort(x.begin(), x.end());
  ll cnt = 0;
  vector<pair<ll, ll>> rng(n, pair<ll, ll>(0, 0));
  queue<pair<ll, ll>> que;
  ll sum = 0;
  for(int i = 0; i < n; i++) {
    while(true){
      pair<ll, ll> tmp = que.front();
      if(tmp.first < x[i][0] && !que.empty()){
        sum -= tmp.second;
        que.pop();
      }else{
        break;
      }
    }
    x[i][1] -= sum * a;
    if(x[i][1] <= 0) {
      continue;
    }

    ll r = min(x[i][0] + 2 * d, x[n - 1][0]);
    ll bomb = (x[i][1] + a - 1) / a;
    que.push(make_pair(r, bomb));
    sum += bomb;
    cnt += bomb;
    x[i][1] -= bomb * a;
  }
  cout << cnt << '\n';
  return 0;
}

Measured memory_bytes: 16000
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main() {
    int N; cin >> N;
    vector<int> A(N);
    for(int &a:A){
        cin >> a;
    }
    
    vector<int> L(N+1);
    vector<int> R(N+1);
    for(int i=0; i<N; i++){
        L[i+1] = max(L[i], A[i]);
    }
    
    for(int i=N-1; i>=0; i--){
        R[i] = max(R[i+1], A[i]);
    }
    
    for(int i=0; i<N; i++){
        cout << max(L[i], R[i+1]) << endl;
    }
    
    
    
    
    
    return 0;
}



Measured memory_bytes: 3968
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        A: i64,
        B: i64,
    }
    println!("{}", if (A-B).abs()<2{"Brown"}else{"Alice"});
}

Measured memory_bytes: 4352
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int a,n,m,sai[1001],mas[1001],i;
	while(1){
		int sai[1001]={0},mas[1001]={0};
		scanf("%d %d",&n,&m);
		a=1;
		if(n==0&&m==0){
			break;
		}
		for(i=1;i<=n;i++){
			scanf("%d",&mas[i]);
		}
		for(i=1;i<=m;i++){
			scanf("%d",&sai[i]);
		}
		for(i=1;i<=m;i++){
			a+=sai[i];
			a+=mas[a];
			if(a>=n){
				printf("%d\n",i);
				break;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 2716
#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>;

// 約数を列挙
vector<ll> enumDivisors(ll n) {
  vector<ll> res;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      // 対応する約数も追加(自分自身でなければ)
      if (n / i != i) {
        res.push_back(n / i);
      }
    }
  }
  // 昇順にソート
  sort(res.begin(), res.end());
  return res;
}

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

  vector<ll> divisors = enumDivisors(n);
  ll result = LONG_LONG_MAX;
  rep(i, divisors.size()) {
    ll a = divisors[i];
    ll b = n / a;
    ll digitsSize = max(to_string(a).size(), to_string(b).size());
    result = min(result, digitsSize);
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256