akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
using namespace std;
int main() {
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	if (a[0] == a[1] && a[0] != a[2]) {
		cout << "Yes" << endl;
	}
	else if (a[1] == a[2] && a[0] != a[2]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}






Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
        public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            double r = sc.nextDouble();
            double area = r*r*Math.PI;
            double length = 2*r*Math.PI;
            System.out.printf("%f %f", area, length);
            sc.close();
        }
}


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

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int a;
    cin>>a;
    
    int v[a];
    for(int i=0; i<a; i++) cin>>v[i];
    
    for(int i=a-1; i>=0; i--){
        if(i!=0){
            printf("%d ",v[i]);
        }
        if(i==0) printf("%d\n",v[i]);
    }
    
    return 0;
    
}



Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
int main(){
	double w;
	while(scanf("%lf", &w) != EOF){
		if(w <= 48.0) printf("light fly\n");
		else if(w <= 51.0) printf("fly\n");
		else if(w <= 54.0) printf("bantam\n");
		else if(w <= 57.0) printf("feather\n");
		else if(w <= 60.0) printf("light\n");
		else if(w <= 64.0) printf("light welter\n");
		else if(w <= 69.0) printf("welter\n");
		else if(w <= 75.0) printf("light middle\n");
		else if(w <= 81.0) printf("middle\n");
		else if(w <= 91.0) printf("light heavy\n");
		else printf("heavy\n");
	}
	return 0;
}

Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D, left, right;
  cin >> A >> B >> C >> D;
  left = A + B;
  right = C + D;
  if (left > right) {
    cout << "Left" << endl;
  }
  else if (left < right) {
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map(&:to_i)
h = Array.new(10 ** 5 + 1, 0)
a.each do |v|
  h[v] += 1
end
s = a.sum
q = gets.to_i
q.times do
  b, c = gets.split.map(&:to_i)
  s += h[b] * (c - b)
  puts s
  h[c] += h[b]
  h[b] = 0
end


Measured memory_bytes: 22036
#include <iostream>
#include <cstdio>
#define N 1005
#define R 1000000007
using namespace std;

typedef long long ll;
ll n, s, cnt[N];
int main()
{
	ll i, j, k;
	cin >> n;
	for (i = 2; i <= n; i++) {
		j = 2;
		k = i;
		while (k > 1) {
			while (k % j == 0) {
				k /= j;
				cnt[j]++;
			}
			j++;
		}
	}
	s = 1;
	for (i = 1; i <= n; i++) {
		cnt[i]++;
		s = (s * cnt[i]) % R;
	}
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 1; i <= (int)(n); i++)

int main() {
  int K;
  cin >> K;
  
  int ans = 0;
  rep(i, K) {
    rep(j, K) {
      rep(k, K) {
        int temp = __gcd(i, j);
        ans += __gcd(k, temp);
      }
    }
  }
  cout << ans << endl;
}

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

int main(){
  string S;
  bool A=true;
  cin >> S;
  for(int i=1;i<S.size();i++){
    if(S.at(i)==S.at(i-1)){
      cout << "Bad" << endl;
      A=false;
      break;
    }
  }
  if(A==true){
    cout << "Good" << endl;
  }
}


Measured memory_bytes: 3568
#include <iostream>
#include<string>
#include<algorithm>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
int cnt_digits(ll n) {
     int digits = 0;

	 while (n > 0) {
	 n /= 10;
	 digits++;
	
	}
	
		 return digits;
	
}
int main(void) {
	ll n;
	cin >> n;
	int ans = cnt_digits(n); 
	for (ll a= 1; a*a <= n; a++) {
		if (n%a != 0)continue;
		 ll b = n / a;
		 int iwa = max(cnt_digits(a), cnt_digits(b));
		if (iwa < ans) { ans = iwa; }
	}
	cout << ans << endl;
}


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

#define min(_x,_y)_y^(_x^_y)&-(_x<_y)

using namespace std;

int s[200001];
int v[200001];

int main(){
	
	int X;
	scanf("%d", &X);
	for (int i = 0; i < X; ++i)
	{
		scanf("%d", v+i);
		s[i] = v[i];

	}
	sort(s, s+X);
	if(X%2){
		int x = ((X+1)/2)-1;
		for(int i = 0; i < X; ++i ){
			if(v[i] < s[x])
				printf("%d\n", s[x]);
			else printf("%d\n", s[x-1]);
		}
	} else {
		int x = (X/2)-1;
		for(int i = 0; i < X; ++i ){
			if(v[i] <= s[x])
				printf("%d\n", s[x+1]);
			else printf("%d\n", s[x]);
		}
	}
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  vector<int> x(n);
  int sum=0;
  for(int i=0;i<n;i++){
    cin>>x[i];
    sum+=x[i];
  }
  int ave=sum/n;
  int ans1=0,ans2=0;
  for(int i=0;i<n;i++) ans1+=((abs(x[i]-ave))*(abs(x[i]-ave)));
  for(int i=0;i<n;i++) ans2+=((abs(x[i]-ave-1))*(abs(x[i]-ave-1)));
  cout<<min(ans1,ans2)<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int         long long
#define mod         1000000007
#define FAST        ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n)      for(int i=0;i<n;i++)
#define fp(i,k,n)   for(int i=k;i<=n;i++)
#define fr(i,k,n)   for(int i=k;i>=n;i--)
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define dbg(x)      cout << (#x) << " is " << (x) << '\n' 
#define F           first
#define S           second
#define sz(x)       (int)(x).size()
#define lb          lower_bound
#define ub          upper_bound
#define mems(x)     memset(x,0,sizeof(x))
#define all(a)      a.begin(),a.end()
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

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

void solve()
{
  int n,x,t;
  cin >>n >> x >> t;
  cout << t*((n+x-1)/x) << '\n';
  return;
} 

signed main()
{
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  FAST
  int T=1;
//   cin >> T;
  while(T--)
  {
    solve();
  }
  return 0;
}


Measured memory_bytes: 3648
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef unsigned long long u64;
typedef signed long long l64;
u64 over = 1000000007;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  int from[m], to[m];
  int chukan[n];
  for (int i = 0; i < n; ++i) chukan[i] = 0;
  for (int i = 0; i < m; ++i) {
    cin >> from[i] >> to[i];
    if (from[i] == 1) {
      chukan[to[i]] = 1;
    }
  }
  for (int i = 0; i < m; ++i) {
    if (to[i] == n && chukan[from[i]] == 1) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int N, A, B;
    cin >> N >> A >> B;

    int diff = B - A;

    // CHECK FOR SPECIAL CASE WHEN A IS NEXT TO B
    if(diff == 0 && (A==1 || B==N)) {
        if(A==1) cout << "Borys" << endl;
    }
    else {
        // CHECK PARITY: ALICE WINS IF EVEN
        if(diff%2 == 0) cout << "Alice" << endl;
        else cout << "Borys" << endl;
    }
}

Measured memory_bytes: 3108
"use strict";
const Main = (input) =>{
   let xs = input.trim().split(' ').map(v=>parseInt(v,10));
   let ans = 0;
   if(xs[0]<=10){
   	 ans = xs[1]+(10 - xs[0])*100
   }else{
     ans = xs[1];
   }
   console.log(ans);
}
Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 7372
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	while(true){
		int n,p;	cin>>n>>p;
		if(n==0)	break;
		vector<int> a(n,0);
		int cur=0;
		int left=p;
		while(true){
			if(left){
				a[cur]++;
				left--;
			}
			else{
				left=a[cur];
				a[cur]=0;
			}
			if(left==0&&a[cur]==p)	break;
			cur=(cur+1)%n;
		}
		cout<<cur<<endl;
	}
	return 0;
}

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

int main()
{
    int n;
    cin>>n;
    vector<int>a(n,1);

    REP(i,n-1)a[i+1]=a[i]+1;
    REP(i,n){if(i!=0)cout<<" ";cout<<a[i];}cout<<endl;
    while(next_permutation(a.begin(),a.end())){REP(i,n){if(i!=0)cout<<" ";cout<<a[i];}cout<<endl;}
}


Measured memory_bytes: 3108
let _ = 
  let to_idx (x, y) = x * 10 + y in
  let drop a (x, y) s =
    let sl = [(0,0); (1,0); (0, 1); (-1,0); (0,-1)]
    and ml = [(1,1); (-1, 1); (-1,-1); (1,-1)]
    and ll = [(2,0); (0,2); (-2,0); (0,-2)] in
    let drop' lst = List.iter (fun (i, j) -> let x' = x + i and y' = y + j in if x' >= 0 && x' < 10 && y' >= 0 && y' < 10 then a.(to_idx (x',y')) <- a.(to_idx (x',y')) + 1 else ()) lst in
    match s with
    | 1 -> drop' sl
    | 2 -> drop' sl; drop' ml
    | 3 -> drop' sl; drop' ml; drop' ll
    | _ -> failwith "drop" in
  let ar = Array.make 100 0 in
  try while true do
        let ((x,y),s) = Scanf.scanf "%d,%d,%d\n" (fun x y s -> ((x,y),s)) in
        drop ar (x, y) s
      done
  with
    End_of_file -> Printf.printf "%d\n%d\n" 
                                 (Array.fold_left (fun n x -> if x = 0 then n + 1 else n) 0 ar)
                                 (Array.fold_left (fun m x -> if m > x then m else x) 0 ar)

Measured memory_bytes: 2344
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
const int inf = 1001001000;
const long long int Inf = 1001001001001001000;

void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}


int main()
{
	long long int n, d, a;
	cin >> n >> d >> a;
	vector<pair<long long int, long long int>> enemy(n);
	rep(i,n){
		long long int x, y;
		cin >> x >> y;
		enemy[i] = pair<long long int, long long int>(x, y);
	}
	sort(all(enemy));
	d = d * 2;
	queue<pair<long long int,long long int>> ruiseki_damage;
	long long int ruiseki = 0;
	long long int ans = 0;
	rep(i, n)
	{
		long long int x = enemy[i].first;
		long long int h = enemy[i].second;
		while(!ruiseki_damage.empty() && ruiseki_damage.front().first < x){
			ruiseki -= ruiseki_damage.front().second;
			ruiseki_damage.pop();
		}
		h -= ruiseki;
		if (h > 0){
			long long int t = (h + a - 1) / a;
			ans += t;
			long long int damage = t * a;
			ruiseki += damage;
			ruiseki_damage.push(pair<long long int, long long int>(x + d, damage));
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4992
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
const int Maxn=1e5+5;
const int Mod=1e9+7;
struct edge{
	int v,nx;
}e[Maxn<<1];
int n,ne,f[Maxn];
ll dp[Maxn][2];
void read(int u,int v)
{	e[++ne].v=v;
	e[ne].nx=f[u];
	f[u]=ne;
}
void dfs(int u,int fa)
{	dp[u][0]=dp[u][1]=1ll;
	for(int i=f[u];i;i=e[i].nx)
	{	int v=e[i].v;
		if(v==fa)continue;
		dfs(v,u);
		dp[u][0]=((dp[v][1]+dp[v][0])%Mod*dp[u][0])%Mod;
		dp[u][1]=(dp[u][1]*dp[v][0])%Mod;
	}
}
int main()
{	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{	int u,v;
		scanf("%d%d",&u,&v);
		read(u,v);read(v,u);
	}
	dfs(1,0);
	printf("%lld\n",(dp[1][0]+dp[1][1])%Mod);
	return 0;
}

Measured memory_bytes: 14064
def dfs(n):
    global b,check,d
    #ttfは235、chaはabc
    #2,3,5の場合それぞれ
    for ttf,cha in zip([2,3,5],b):
        #-1ずつしていく場合
        if check[0]>check[n]+n*d:
            check[0]=check[n]+n*d

        #最寄りまで-してく場合
        x1,x2=n//ttf,n%ttf
        if x1 in check:
            if check[x1]>check[n]+x2*d+cha:
                check[x1]=check[n]+x2*d+cha
                dfs(x1)
        else:
            check[x1]=check[n]+x2*d+cha
            dfs(x1)

        #最寄りまで+1してく場合
        x1,x2=n//ttf+1,ttf-n%ttf
        if x1 in check:
            if check[x1]>check[n]+x2*d+cha:
                check[x1]=check[n]+x2*d+cha
                dfs(x1)
        else:
            check[x1]=check[n]+x2*d+cha
            dfs(x1)

t=int(input())
for i in range(t):
    N,*b,d=map(int,input().split())
    check={N:0,0:N*d}
    dfs(N)
    print(check[0])


Measured memory_bytes: 119560
from sys import stdin
import sys
import math

N = int(input())
A = list(map(int, stdin.readline().rstrip().split()))

h = {}

for i in range(1, N+1):
    h[i] = 0


for j in range(N-1):
    h[A[j]] += 1


for val in h.values():
    print(val)


Measured memory_bytes: 40360
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int N;
vector<vector<int>> G;
int dfs(int v,int p,int L){
	multiset<int> ls,cls;
	for(int u:G[v]) if(u!=p){
		int tmp = dfs(u,v,L);
		if(tmp==-1) return -1;
		if(tmp>L) return -1;
		ls.insert(tmp);
	}
	cls = ls;
	int K = ls.size();

	if(K%2==0){
		{
			bool perfect = 1;
			vector<int> v;
			for(int x:ls) v.pb(x);
			rep(i,K/2) if(v[i]+v[K-1-i]>L) perfect = 0;
			if(perfect) return 1;
		}
		auto it = ls.end();
		it--;
		ls.erase(it);
	}

	int lef = -1;
	while(ls.size()>1){
		auto it = ls.end();
		it--;
		int a = *it;
		ls.erase(it);
		it = ls.upper_bound(L-a);
		if(it==ls.begin()){
			if(lef!=-1) return -1;
			lef = a;
			continue;
		}
		it--;
		ls.erase(it);
	}
	if(ls.size()==1) lef = *ls.begin();
	return lef + 1;
}
bool can(int L){
	int r = -1;
	rep(i,N) if(G[i].size()==1) r = i;
	int tmp = dfs(r,-1,L);
	if(tmp==-1) return 0;
	if(tmp-1>L) return 0;
	return 1;
}
int main(){
	cin>>N;
	G.resize(N);
	rep(i,N-1){
		int x,y;
		cin>>x>>y;
		x--,y--;
		G[x].pb(y);
		G[y].pb(x);
	}
	int A=0;
	rep(v,N){
		int deg = G[v].size();
		A += deg%2;
	}
	A/=2;
	int ub = N-1, lb = 0;
	while(ub-lb>1){
		int m = (ub+lb)/2;
		if(can(m)) ub = m;
		else lb = m;
	}
	int B = ub;
	cout<<A<<" "<<B<<endl;
}


Measured memory_bytes: 27648
import sys
sys.setrecursionlimit(10**9)
from collections import defaultdict

IA = lambda: map(int,input().split())
IAS= lambda: map(str,input().split())

s=list(IAS())
n=list(IA())
u=input()

for i in range(0,2):
    if s[i]==u:
        n[i]-=1
print(str(n[0])+" "+str(n[1]))

N=int(100005)
a=[int(0) for i in range(N)]




Measured memory_bytes: 4212
import sys

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):

    return [il(t) for _ in range(N)]


N = ii()
A = il()
ans = float("inf")
for sign in (1, -1):
    sum_a = 0
    c = 0
    for a in A:
        sum_a += a
        if sum_a * sign <= 0:
            # +1になるまで加算
            c += abs(sum_a) + 1
            # 総和は1or-1のため
            sum_a = sign
        sign *= -1
    ans = min(ans, c)
print(ans)


Measured memory_bytes: 14468
<?php
$x = 0;
fscanf(STDIN, "%d %d", $N, $M);

for ($i = 0; $i < $N; $i++) {
    fscanf(STDIN, "%d %d", $A, $B);
    $a[$A][] = $B;
}

$h = new SplMaxHeap;
for ($i = 1; $i <= $M; $i++) {
    if (isset($a[$i]) === true) {
        foreach ($a[$i] as $v) {
            $h->insert($v);
        }
    }
    if ($h->count() !== 0) {
        $x += $h->extract();
    }
}
echo $x;

Measured memory_bytes: 47604
#include "bits/stdc++.h"

using namespace std;

int main(int argc, char const *argv[])
{
	int N;
	cin >> N;
	vector< int > a(N);
	int sum = 0;
	for(int j = 0;j < N;j++){
		cin >> a[j];
		sum += a[j];
	}

	vector<int> ans;
	int x_sum = 0;
	for(int i = 1;i < N;i+=2)x_sum += a[i];
	ans.push_back(sum - 2*x_sum);

	for(int j = 1;j < N;j++){
		int x = 2*a[j-1]-ans[j-1];
		ans.push_back(x);
	}
	for(int j = 0;j < ans.size();j++){
		cout << ans[j];
		if(j != N-1)cout << " ";
	}
	cout << endl;
 
	return 0;
}

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

using namespace std;

#define int long long

#ifndef bhupixb
    #define var(...)
    #define stl(...)
#endif

#define single_test

void solve() {
    int x;
    cin >> x;
    cout << (x^1) << '\n';
}

signed main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    #ifndef single_test
        cin >> t;
    #endif
    for (int i = 1; i <= t; ++i) {
        // cout << "Case #" << i << ": ";
        solve();
    }

    return 0;
}

Measured memory_bytes: 3612
void main() {
	auto L = readAs!real;
	real a = L/3;
	writefln("%.9f", pow(a, 3));
}

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

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 256
#include <iostream>

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

int main() {
  int a, b, c;

  cin >> a >> b >> c;

  if (a + b == c || a + c == b || b + c == a) cout << "Yes" << endl;
  else                                        cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <set>
using namespace std;
int main(){
  int n, m;
  cin >> n >> m;
  multiset<int> s;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    s.insert(a);
  }
  for (int i = 0; i < m; i++) {
    auto itr = s.end();
    itr--;
    int tmp = *itr;
    s.erase(itr);
    s.insert(tmp >> 1);
  }
  long long int ans = 0;
  for (auto itr = s.begin(); itr != s.end(); itr++) {
    ans += *itr;
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 4992
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int d = sc.nextInt();
    int g = sc.nextInt();
    int[] p = new int[d];
    int[] c = new int[d];
    for(int i = 0; i < d; i++) {
      p[i] = sc.nextInt();
      c[i] = sc.nextInt();
    }
    int ans = Integer.MAX_VALUE;
    if((100 * d * (p[d - 1] - 1)) >= g) {
      if((g % (100 * d)) == 0) {
        ans = Math.min(ans, g / (100 * d));
      } else {
        ans = Math.min(ans, (g / (100 * d)) + 1);
      }
    }
    for(int i = 1; i < Math.pow(2, d); i++) {
      int sum = 0;
      int s = 0;
      int q = 0;
      for(int j = 0; j < d; j++) {
        if((i & (1 << j)) != 0) {
          s += p[j];
          sum += ((100 * (j + 1) * p[j]) + c[j]);
        } else {
          q = j;
        }
      }
      if(sum >= g) ans = Math.min(ans, s);
      if((sum + (100 * (q + 1) * (p[q] - 1))) >= g) {
        if(g > sum) {
          int r = g - sum;
          if((r % (100 * (q + 1))) == 0) {
            s += (r / (100 * (q + 1)));
          } else {
            s += (r / (100 * (q + 1)) + 1);
          }
          ans = Math.min(ans, s);
        }
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23892
#include<stdio.h>
int table[]={0,1,2,3,5,7,8,9};
int output[100];
int now;
int main(){
	int a;
	while(scanf("%d",&a),a){
		now=0;
		while(a>0){
			output[now++]=table[a%8];
			a/=8;
		}
		for(int i=now-1;i>=0;i--)printf("%d",output[i]);
		printf("\n");
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
const int N = 1e6 + 10, OO = 0x3f3f3f3f, mod = 1e9 + 7;

#define PI acos(-1)
#define clr(arr, val) memset(arr, val, sizeof(arr))
#define loop(i, n) for (int i = 0; i < int(n); i++)
#define rloop(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define xloop(i, a, b) for (int i = int(a); i <= int(b); i++)
#define ALL(v) ((v).begin()), ((v).end())
#define SZ(v) ((int)((v).size()))
//int dx[] = {1, 0, -1, 0};
//int dy[] = {0, 1, 0, -1}; //4 Direction
//int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
//int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; //8 direction
int dx[] = {2, 1, -1, -2, -2, -1, 1, 2};
int dy[] = {1, 2, 2, 1, -1, -2, -2, -1}; //Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction

//-- "كلٌّ من يسعى لابد يصل .. كلٌّ من يسعى مضمون له الوصول" --//



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

  string s, t;
  cin >> s >> t;
  int pos = s.find(t);
  if(pos != -1)
    cout << "0\n";
  else{
    int ans = OO;
    int lenS = SZ(s);
    int lenT = SZ(t);
    for (int i = 0; i <= lenS - lenT ; ++i){
      int cnt = 0;
      int st = i;
      for (int j = 0; j < lenT; ++j , ++st)
      {
        if(s[st] == t[j])
          continue;
        cnt++;
      }
      ans = min(ans, cnt);
    }
    printf("%d\n", ans);
  }

  return 0;
}

Measured memory_bytes: 3728
s = list(input())
ans=0
if len(s)%2 == 0:
  for i in range(len(s)//2):
    if s[i] != s[len(s)-1-i]:
      ans = ans+1
else:
  for i in range((len(s)-1)//2):
    if s[i] != s[len(s)-1-i]:
      ans = ans+1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
	int n,w;
	cin>>n>>w;
    vector<ll> weights(n),vals(n);
    for(int i=0;i<n;i++)
     {
         cin>>weights[i]>>vals[i];
     }
          ll dp[101][100001];
     for(int i=0;i<=n;i++)
      dp[0][i]=0;
     for(int i=0;i<=n;i++)
      dp[i][0]=0;
	
	for(int i=1;i<=n;i++)
	   {
	     for(int j=1;j<=w;j++)  
	       {
	           if(j<weights[i-1])
	            dp[i][j]=dp[i-1][j];
	           else
	           {
	               dp[i][j]=max(dp[i-1][j],dp[i-1][j-weights[i-1]]+vals[i-1]);
	           }
	       }
	   }
	   
	   cout<<dp[n][w];
	return 0;
}


Measured memory_bytes: 81712
/* ex4_3
  sachiyan */

#include <stdio.h>
int snow(int a, int b); //関数preのプロトタイプ宣言

int main(void){
    int west, east; //A,Bの定義
    scanf("%d %d", &west, &east); //A,Bの読み取り
    printf("%d\n", snow(west, east)); //答えを出力
}

int snow(int a, int b){ //関数preの定義　differenceを引数とする
    int pre_east; //pre_eastを定義
    int diff, answer; //差と答えの定義
    int i; //for内の変数定義
    pre_east = 0;
    diff = b - a; //高さの差を算出
    for(i = 1; i <= diff; i++){
        pre_east += i; //差と同じ値まで足し続ける
    }
    answer = pre_east - b; //関数preを呼び出し、積もる前との高さを比較する
    return(answer); //東の塔のもとの高さが分かる
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<map>
#include<algorithm>
using namespace std;
#define N 200005
#define M 100005
struct node1{
	int to,nxt;
}e1[2*M];
int fir1[N],cnt1;
void adde1(int a,int b)
{
	e1[++cnt1].to=b;
	e1[cnt1].nxt=fir1[a];
	fir1[a]=cnt1;
	e1[++cnt1].to=a;
	e1[cnt1].nxt=fir1[b];
	fir1[b]=cnt1;
}
int vis1[N],tot1;
void dfs1(int u)
{
	int v,p;
	vis1[u]=tot1;
	for(p=fir1[u];p;p=e1[p].nxt){
		v=e1[p].to;
		if(!vis1[v])
			dfs1(v);
	}
}

struct node2{
	int to,nxt;
}e2[2*M];
int fir2[N],cnt2;
void adde2(int a,int b)
{
	e2[++cnt2].to=b;
	e2[cnt2].nxt=fir2[a];
	fir2[a]=cnt2;
	e2[++cnt2].to=a;
	e2[cnt2].nxt=fir2[b];
	fir2[b]=cnt2;
}
int vis2[N],tot2;
void dfs2(int u)
{
	int v,p;
	vis2[u]=tot2;
	for(p=fir2[u];p;p=e2[p].nxt){
		v=e2[p].to;
		if(!vis2[v])
			dfs2(v);
	}
}
map<long long,int >b;
int main()
{
	int n,m1,m2,u,v,i;
	scanf("%d%d%d",&n,&m1,&m2);
	for(i=1;i<=m1;i++){
		scanf("%d%d",&u,&v);
		adde1(u,v);
	}
	for(i=1;i<=n;i++)
		if(!vis1[i]){tot1++;dfs1(i);}
	
	for(i=1;i<=m2;i++){
		scanf("%d%d",&u,&v);
		adde2(u,v);
	}
	for(i=1;i<=n;i++)
		if(!vis2[i]){tot2++;dfs2(i);}
	
	for(i=1;i<=n;i++)
		b[1ll*vis1[i]*N+1ll*vis2[i]]++;
	for(i=1;i<=n;i++){
		printf("%d",b[1ll*vis1[i]*N+1ll*vis2[i]]);
		if(i!=n)printf(" ");
	}
}

Measured memory_bytes: 17920
// https://atcoder.jp/contests/ddcc2020-qual/tasks/ddcc2020_qual_c

#include "algorithm"
#include "cmath"
#include "functional"
#include "iostream"
#include "numeric"
#include "queue"
#include "set"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll H, W, K;
  cin >> H >> W >> K;

  V<string> mat(H);
  rep(i, H) cin >> mat[i];

  VVL res(H, VL(W));

  ll crk = 0;
  rep(i, H) {
    crk++;
    ll appeared = false;

    rep(j, W) {
      auto c = mat[i][j];

      if (c == '#') {
        if (appeared) {
          crk++;
        }
        appeared = true;
      }

      res[i][j] = crk;
    }

    if (!appeared) {
      rep(j, W) { res[i][j] = -2; }
      crk--;
    }
  }

  rep(i, H) {
    if (i == 0) continue;

    if (res[i][0] == -2) {
      rep(j, W) res[i][j] = res[i - 1][j];
    }
  }

  repr(i, H) {
    if (i == H - 1) continue;

    if (res[i][0] == -2) {
      rep(j, W) res[i][j] = res[i + 1][j];
    }
  }

  rep(i, H) { print_ints(res[i]); }
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

#ifndef TEST
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

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

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


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

int main(){
	int beru[3];
	for(int i = 0; i < 3; i ++){
		cin >> beru[i];
	}
	sort(beru, beru+3);
	int sum = beru[0] + beru[1];
	cout << sum;
	return 0;
}

Measured memory_bytes: 256
from math import ceil
n,a,b=map(int,input().split())
h=[int(input()) for i in range(n)]
h.sort(reverse=True)
ok,ng=10**9,0
while ok-ng>1:
  mid=(ok+ng)//2
  damage=mid*b
  addition=mid
  flag=True
  for i in range(n):
    if h[i]<=damage:
      continue
    else:
      if addition>=ceil((h[i]-damage)/(a-b)):
        addition-=ceil((h[i]-damage)/(a-b))
      else:
        addition-=ceil((h[i]-damage)/(a-b))
        flag=False
        break
  if flag:
    ok=mid
  else:
    ng=mid
print(ok)

Measured memory_bytes: 7528
#include<stdio.h>
#define MAX 100
#define INFTY (1<<21)
void dikstra(void);
int white=0,gray=1,black=2;
int n,M[MAX][MAX];



int main(){
  int i,k,c,u,v,j;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
  for(j=0;j<n;j++){
      M[i][j]=INFTY;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d %d", &u,&k);
    for(j=0;j<k;j++){
      scanf("%d %d", &v, &c);
      M[u][v]=c;
    }}

  dikstra();

  return 0;
}
  
void dikstra(){
  int minv,u,v,i;
  int d[MAX],color[MAX];
  for(i=0;i<n;i++){
    d[i]=INFTY;
    color[i]=white;
  }
  
  d[0]=0;
  color[0]=gray;
  while(1){
    minv=INFTY;
    u=-1;
    for(i=0;i<n;i++){if(minv>d[i]&&color[i]!=black){
	u=i;
	minv=d[i];}
    }
    
    if(u==-1)break;
    color[u]=black;
   for(v=0;v<n;v++){
     if(color[v]!=black&&M[u][v]!=INFTY){if(d[v]>d[u]+M[u][v]){d[v]=d[u]+M[u][v];
	 color[v]=gray;
       }}
    }
  }
  for(i=0;i<n;i++){
    printf("%d ", i);
    if(d[i]==INFTY)printf("-1");
    else printf("%d\n", d[i]);
  }}



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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> e(m);
	vector<vector<int>> g(n);
	for (auto&& ei : e)
	{
		cin >> ei.first >> ei.second;
		ei.first--;
		ei.second--;
		g[ei.first].push_back(ei.second);
		g[ei.second].push_back(ei.first);
	}
	int count = 0;
	for (auto&& ei : e)
	{
		queue<int> next;
		vector<bool> check(n, false);
		check[ei.first] = true;
		next.push(ei.first);
		bool found = false;
		while (!next.empty() && found == false)
		{
			auto current = next.front();
			next.pop();
			for (auto&& adjacent : g[current])
			{
				if (adjacent == ei.second)
					if (current != ei.first)
					{
						found = true;
						break;
					}
					else continue;
				if (!check[adjacent])
				{
					next.push(adjacent);
					check[adjacent] = true;
				}
			}
		}
		if (!found) count++;
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int segA[530000];
int segB[530000];
void kakiA(int a,int b,int k,int l,int r,int pa){
    if(r<=a||b<=l)return;
    if(a<=l&&r<=b){
        segA[k]=min(pa,segA[k]);
    }
    else{

        kakiA(a,b,k*2,l,(l+r)/2,pa);
        kakiA(a,b,k*2+1,(l+r)/2,r,pa);
    }
}
void kakiB(int a,int b,int k,int l,int r,int pa){
    if(r<=a||b<=l)return;
    if(a<=l&&r<=b){
        segB[k]=min(pa,segB[k]);
    }
    else{

        kakiB(a,b,k*2,l,(l+r)/2,pa);
        kakiB(a,b,k*2+1,(l+r)/2,r,pa);
    }
}
int main(){
    long long int N,Q;
    cin>>N>>Q;
    for(int i=0;i<530000;i++){
        segA[i]=N;
        segB[i]=N;
    }
    long long int ans=(N-2)*(N-2);
    for(int i=0;i<Q;i++){
        long long int a,b;
        cin>>a>>b;
        if (a==1){
            long long int torimin=2100000000;
            int miru=b+(262144-1);
            while(1){
                torimin=min(torimin,(long long int)segA[miru]);
                miru/=2;
                if(miru==0)break;
            }
            ans-=(torimin-2);
            segA[b+(262144-1)]=1;
            //printf("[[[[[%d]]]]]\n",torimin);
            kakiB(2,torimin,1,1,262145,b);
        }
        else{
            swap(a,b);
            long long int torimin=2100000000;
            int miru=a+(262144-1);
            while(1){
                torimin=min(torimin,(long long int)segB[miru]);
                miru/=2;
                if(miru==0)break;
            }
            ans-=(torimin-2);
            segB[a+(262144-1)]=1;
            kakiA(2,torimin,1,1,262145,a);
        }
        //printf("[%lld]\n",ans);









/*
        printf("=========\n");
        printf("segA\n");
        printf("[         %d          ]\n",segA[262144/2/2/2]);
        printf("[    %d    ][    %d    ]\n",segA[262144/2/2],segA[262144/2/2+1]);
        printf("[ %d  ][ %d  ][ %d  ]\n",segA[262144/2],segA[262144/2+1],segA[262144/2+2]);
        printf("[%d][%d][%d][%d][%d][%d]\n",segA[262144],segA[262144+1],segA[262144+2],segA[262144+3],segA[262144+4],segA[262144+5]);
        printf("=========\n");

        printf("=========\n");
        printf("segB\n");
        printf("[         %d          ]\n",segB[262144/2/2/2]);
        printf("[    %d    ][    %d    ]\n",segB[262144/2/2],segB[262144/2/2+1]);
        printf("[ %d  ][ %d  ][ %d  ]\n",segB[262144/2],segB[262144/2+1],segB[262144/2+2]);
        printf("[%d][%d][%d][%d][%d][%d]\n",segB[262144],segB[262144+1],segB[262144+2],segB[262144+3],segB[262144+4],segB[262144+5]);
        printf("=========\n");


*/










    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 7340
n,a,b = map(int,input().split())
if (b - a)%2 == 0:
    x = (b - a)//2
    y = min(max(a-1,b-1),max(n-a,n-b))
    print(min(x,y))
else:
    p = max(a-1,b-1)
    q = max(n-a,n-b)
    r = a-1+1+(b-(a-1)-1-1)//2
    s = n-b+1+(n-(n-b+1)-a)//2
    #print(p,q,r,s)
    print(min(p,q,r,s))

Measured memory_bytes: 3188
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
typedef double lf;
typedef long double Lf;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;

#define TRACE(x) cerr << #x << "  " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

#define fi first
#define sec second
#define mp make_pair

const int MAXN = 2010;

int n, k;

vector <int> v[MAXN];

queue <pii> q;
int bio[MAXN];

int bfs() {
  int ret = 0;
  while (!q.empty()) {
    int cvor = q.front().fi;
    int dist = q.front().sec;
    ret += (dist > k/2);
    q.pop();

    for (auto ncvor : v[cvor]) {
      if (bio[ncvor]) continue;
      bio[ncvor] = 1;
      q.push({ncvor, dist + 1});
    }
  }
  return ret;
}

int main() {
  scanf("%d %d",&n,&k);
  REP(i, n - 1) {
    int a, b;
    scanf("%d %d",&a,&b);
    v[a].push_back(b);
    v[b].push_back(a);
  }
  
  int sol = MAXN;

  if (k % 2) {
    REP(cvor, n) {
      for (auto ncvor : v[cvor + 1])  {
        memset(bio, 0, sizeof bio);
        bio[cvor + 1] = bio[ncvor] = 1;
        q.push({cvor + 1, 0});
        q.push({ncvor, 0});
        sol = min(sol, bfs());
      }
    }
  }
  else {
    REP(cvor, n) {
      memset(bio, 0, sizeof bio);
      bio[cvor + 1] = 1;
      q.push({cvor + 1, 0});
      sol = min(sol, bfs());
    }
  }

  printf("%d\n",sol);
  return 0;
}


Measured memory_bytes: 384
class BellmanFord:
    def __init__(self, graph, num_v, start_point):
        self.num_v = num_v
        self.graph = graph
        self.start_point = start_point
        self.negative = [False for _ in range(num_v)]

    def execute(self):
        dist = [float("inf") for _ in range(self.num_v)]
        dist[self.start_point] = 0

        for i in range(self.num_v - 1):
            for src, dest, cost in self.graph:
                if dist[dest] > dist[src] + cost:
                    dist[dest] = dist[src] + cost
        for i in range(self.num_v):
            for src, dest, cost in self.graph:
                if dist[dest] > dist[src] + cost:
                    dist[dest] = dist[src] + cost
                    self.negative[dest] = True
                if self.negative[src]:
                    self.negative[dest] = True
        return dist, self.negative


n, m = map(int, input().split())
graph = []

for i in range(m):
    a, b, c = map(int, input().split())
    graph.append([a - 1, b - 1, -c])
bellman = BellmanFord(graph, n, 0)
result, negative = bellman.execute()

if negative[-1]:
    print("inf")
else:
    print(-result[-1])


Measured memory_bytes: 3444
// input! macro is published in the following URLs.
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
// https://github.com/tanakh/competitive-rs.git
#[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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (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")
    };
}

fn main() {
    input! {
        a: i64,
        b: i64,
    }
    let n = format!("{}{}", a, b).parse::<i64>().unwrap();
    for i in 1..n {
        let k = i * i;
        if k == n {
            println!("Yes");
            return;
        }
    }
    println!("No");
}


Measured memory_bytes: 4352
//author : raghav_0901

#include <bits/stdc++.h>
using namespace std; 
#define int long long int

int n,k,d,a;

signed main()
{
    cin>>n>>k;
    vector<bool> v(n+1,0);
    for(int i=0;i<k;i++)
    {
        cin>>d;
        for(int j=0;j<d;j++)
        {
            cin>>a;
            v[a]=1;
        }
    }
    int cnt=0;
    for(int i=1;i<=n;i++)
        cnt+=v[i];
    cout<<(n-cnt)<<endl;
}


Measured memory_bytes: 3604
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
template<class T> bool INRANGE(T x,T a,T b) { return a<=x&&x<=b; }
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;
}

#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;


typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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


    int a, b, k;
    cin >> a >> b >> k;

    vi v;
    FOR(i,1,max(a,b)+1){
        if (a%i == 0 and b%i == 0) v.emplace_back(i);
    }

    //for (int n : v) cout << n << " ";
    cout << v[v.size()-k] << endl;

    return 0;
}

Measured memory_bytes: 256
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#define llong long long
#define fr(i,l,r) for(i=(l);i<(r);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000//10^12

int main(void)
{
	//変数の宣言
	int a,b;
	int num[5];
	int ans;
	int i;
	int flag;
	
	//データの読み込み
	//scanf("%d %d",&n,&k);
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	for(i=0;i<5;i++){
		num[i]=0;
	}
	
	for(i=0;i<3;i++){
		scanf("%d %d",&a,&b);
		num[a]++;
		num[b]++;
	}
	
	flag=0;
	for(i=1;i<=4;i++){
	//	printf("i=%d,num[i]=%d\n",i,num[i]);
		if(num[i]==3){
			flag=1;
		}
	}
	
//	printf("計算部分終了\n");
	
	//出力
	if(flag==0){
		printf("YES");
	}else{
		printf("NO");
	}
	
//	printf("結果の出力終了\n");
	
	return 0;
}



Measured memory_bytes: 128
#!/usr/bin/env python3

a, b, c, x, y = list(map(int, input().split()))

numa = 0
numb = 0
numc = max(x, y)*2
value = c*numc

# print(numa, numb, numc, value)

while numc:
    numc_tmp = numc-2
    numa_tmp = max(x-numc_tmp//2, 0)
    numb_tmp = max(y-numc_tmp//2, 0)

    value_tmp = a*numa_tmp+b*numb_tmp+c*numc_tmp
    # print(numa_tmp, numb_tmp, numc_tmp, value_tmp)

    if value_tmp >= value:
        print(value)
        exit()
    numc = numc_tmp
    numa = numa_tmp
    numb = numb_tmp
    value = value_tmp

print(value)


Measured memory_bytes: 9112
#include<iostream>
#include<iomanip>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=long long;

using ld = long double;
constexpr ld EPS = 1e-11;
int main(){
    int n;
    cin>>n;
    vector<int> b(n);
    vector<int> c(n);
    vector<int> d(n);
    for(int i=0;i<n;i++){
        string a;
        cin>>a;
        int pos = find(a.begin(),a.end(),'.')-a.begin();
        ll an;
        if(pos!=a.size()){
            string x = a.substr(0,pos);
            string y = a.substr(pos+1,a.size()-pos-1);
            an = stoi(x);
            for(int i=0;i<y.size();i++) an*=10;
            an+=stoi(y);
            b[i] = y.size();
        }
        else{
            an=stoi(a);
        }
        while(an%2==0){
            c[i]++;
            an/=2;
        }
        while(an%5==0){
            d[i]++;
            an/=5;
        }
    }

    vector<vector<vector<ll>>> cnt(10,vector<vector<ll>>(21,vector<ll>(21)));

    for(int i=0;i<n;i++){
        cnt[b[i]][min(c[i],20)][min(d[i],20)]++;
    }
    ll ans = 0;
    for(int li=0;li<10;li++){
        for(int lj=0;lj<=20;lj++){
            for(int lk=0;lk<=20;lk++){
                if(cnt[li][lj][lk]==0) continue;
                for(int ri=0;ri<10;ri++){
                    for(int rj=0;rj<=20;rj++){
                        for(int rk=0;rk<=20;rk++){
                            int c2 = lj+rj;
                            int c5 = lk+rk;
                            int c10 = min(c2,c5);
                            if(li+ri<=c10){
                                if(li==ri && lj==rj && lk==rk){
                                    ans+=cnt[li][lj][lk]*(cnt[ri][rj][rk]-1);
                                }
                                else{
                                    ans+=cnt[li][lj][lk]*cnt[ri][rj][rk];
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    cout<<ans/2<<endl;

    
    
    return 0;
}


Measured memory_bytes: 5640
#include "bits/stdc++.h"
using namespace std;
const long long m = 998244353;
long long int dp[3001][3001];
long long binpow(long long a, long long b) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
int main(){
	int n,s;
	cin >> n >> s;
	int vet[3001];
	for(int i=0;i<n;i++) cin >> vet[i];
	dp[0][0]=binpow(2,n);
	for(int i=0;i<=n;i++){
		for(int j=0;j<=s;j++) if(!(i==0 && j==0))dp[i][j]=0;
	}
	for(int i=1;i<=n;i++){
		for(int j=0;j<=s;j++){
			dp[i][j]=(dp[i][j]%m + dp[i-1][j]%m)%m;
			if((j+vet[i-1])<=s) dp[i][j+vet[i-1]] = (dp[i][j+vet[i-1]]%m + (dp[i-1][j]*499122177)%m)%m; 
		}
	}
	cout << (dp[n][s]+m)%m << endl;
}

Measured memory_bytes: 73952
s = input() + "!"
t = input() + "@"
len_s = len(s)
len_t = len(t)

dp=[[0 for _ in range(3100)] for _ in range(3100)]

# dp[i][j] := sをi+1番目,tをj+1番目まで見たときの最長部分列
# 最後の文字を使うか使わないか
ans = ''
for i in range(1,len_s + 1):
    for j in range(1,len_t + 1):
        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])

j= len_t - 1
for i in range(len_s)[::-1]:
    while(dp[i][j - 1] == dp[i][j] and j >= 1):
        j -= 1
    if dp[i - 1][j] == dp[i][j]:
        continue
    ans += s[i -1]
print(ans[::-1])



Measured memory_bytes: 122460
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
#define PI pair<int,int>
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}

int ans,n,m,a[105];
signed main(){
	n=read(); m=read();
	for(int i=1;i<=n;i++)a[i]=read();
	sort(&a[1],&a[n+1]);
	for(int i=1;i<=n;i++)if(m>=a[i]){
		ans+=(i<n)||(m==a[i]); m-=a[i];
	}
	cout<<ans<<endl;
}

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

using namespace std;

void solve() {
  int N;
  cin >> N;
  int64_t res = 0;
  vector<vector<pair<int, int>>> K(N);
  for (int i = 0; i < N; i++) {
    int k, l, r;
    cin >> k >> l >> r;
    k--;
    K[k].emplace_back(make_pair(l, r));
    res += min(l, r);
  }
  priority_queue<int, vector<int>, greater<int>> que;
  for (int k = 0; k < N; k++) {
    for (auto& [l, r] : K[k]) {
      if (l > r) {
        que.push(l - r);
      }
    }
    while ((int)que.size() > k + 1) {
      que.pop();
    }
  }
  while (!que.empty()) {
    res += que.top();
    que.pop();
  }
  for (int k = N - 1; k > -1; k--) {
    for (auto& [l, r] : K[k]) {
      if (r > l) {
        que.push(r - l);
      }
    }
    while ((int)que.size() > N - k - 1) {
      que.pop();
    }
  }
  while (!que.empty()) {
    res += que.top();
    que.pop();
  }
  cout << res << '\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  cin >> T;
  for (int i = 0; i < T; i++) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 12440