akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<bitset>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
ll fact(ll x, ll k, ll p) {//最大値、個数、あまり
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%p;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
short ctos(char a) {
	return (int)(a - '0');
}
#define int long long
const long long Inf = 4523372036854775807;
const int inf = 15000000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
ld solve(int t) {
	string s = to_string(t);
	int sum = 0;
	for (int i = 0; i < s.size(); i++) {
		sum += (int)s[i] - '0';
	}
	return sum;
}
bool F(int t) {
	ld re = 1;
	for (int i = 0; i < 16; i++) {
		if (t / solve(t) > (t + re) / solve(t + re)) {
			return 0;
		}
		if (re - 1 > t&&t / solve(t) > (re - 1) / solve(re - 1)) {
			return 0;
		}
		re *= 10;
	}
	return 1;
}
signed main() {
	int k;
	cin >> k;
	int t = 1;
	ld re = 1;
	cout << 1 << endl;
	k--;
	while (k > 0) {
		while (k > 0) {
			if (!F(t + re))
				break;
			k--;
			cout << (t += re) << endl;
		}
		re *= 10;
		t = (ceil(t / re))*re - 1;
	}
}

Measured memory_bytes: 256
N, X =  map(int,input().split())
L_list =list(map(int,input().split()))
count = 0
cood = 0

count = 1
for i in range(len(L_list)):
  cood = cood + L_list[i]
  if cood <= X:
    count += 1
  else:
    break
print(int(count))

Measured memory_bytes: 3060
import sys
s1=raw_input()
s2=raw_input()

for idx, s in enumerate(s1):
    if s2[0] != s:
        continue
    
    s1_idx = idx
    s2_idx = 0
    while True:
        s1_now = s1[s1_idx:]
        s2_now = s2[s2_idx:]
        if len(s1_now) >= len(s2_now):
            if s1_now.startswith(s2_now):
                print "Yes"
                sys.exit(0)
            else:
               break
        else:
            if s2_now.startswith(s1_now):
                s1_idx = 0
                s2_idx += len(s1_now)
            else:
                break

print "No"

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

#define NIL NULL

struct node{

  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;
 
Node root;

void insert(int k){

  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while(x != NIL){
    
    y = x;
    
    if(z->key < x->key){
      x = x->left;
    }
    else {
      x = x->right;
    }
  }
  
  z->parent = y;
  
  if( y ==  NIL ){
    root = z;
  }
  else if( z->key < y->key ){
    y->left = z;
  }
  else {
    y->right = z;
  }
  
  
}

void inorder(Node u){

  if(u->left != NIL){

    inorder(u->left);
  }

  printf(" %d",u->key);

  if(u->right != NIL){
    
    inorder(u->right);
  }

}
void preorder(Node u){

  printf(" %d",u->key);
  
  if(u->left != NIL){
    preorder(u->left);
  }
  
  if(u->right != NIL){
    preorder(u->right);
  }
  
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);


    /* if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
      } else */
    if ( com[0] == 'i' ){
      scanf("%d", &x);
       insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } /* else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
      }*/
  }

  return 0;
}

Measured memory_bytes: 24036
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		 Scanner scan = new Scanner(System.in);
	        int N  = scan.nextInt();
	        int D  = scan.nextInt();
	        int i=0;
	        int x =  N;

	        for(i=0; x > 0;i++) {
	        	x -= 2*D+1;
	        }
	        System.out.println(String.valueOf(i ));
	}
}


Measured memory_bytes: 23888
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <bitset>
#include <iomanip>
#include <cmath>
#include <queue>
using namespace std;
using PP = pair<int, int>;
const int INF = 1e9;

template <class T> T Next() { T t; cin >> t; return t; }


int main() {
  int a, b;
  cin >> a >> b;
  cout << a + b / 2 << endl;
}


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

using namespace std;

const int maxn = 1e4;
const int maxl = 100;
int H, W;
int n;
int ans[maxl][maxl];
int a[maxn];
bool b = false;

int main(){
	cin >> H >> W >> n;
	for(int i=0; i<n; i++)
		cin >> a[i];
	int i=0, j=0;
	for(int z=0; z<n; z++){
		for(int x=0; x<a[z]; x++){
			ans[i][j] = z+1;
			if(b == false){
				j++;
				if(j == W){
					b = true;
					i++;
					j--;
				}
			}
			else{
				j--;
				if(j == -1){
					b = false;
					i++;
					j++;
				}
			}
		}
	}
	for(int i=0; i<H; i++){
		for(int j=0; j<W; j++){
			cout << ans[i][j] << ' ';
		}
		cout << endl;
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 384
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int N=sc.nextInt();
    int count=1;
    int Answer=0;
    
    for(int i=0;i<N;i++){
      if(sc.nextInt()==count){
        count++;
      }else{
        Answer++;
      }
    }
    
      if(Answer==N){
        Answer=-1;
      }
    
    System.out.println(Answer);
    
  }
}

Measured memory_bytes: 62768
import math
import numpy as np
a, b, h, m = map(int, input().split())
h1 = 30 * h + m / 2
m1 = 6 * m
theta = abs(h1 - m1)
if theta > 180:
  theta = 360 - theta
#print(theta)
theta = theta * (np.pi / 180)
c = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * np.cos(theta))
print(c)
#print(theta)

Measured memory_bytes: 27072
#include<bits/stdc++.h>
using namespace std;
int main(){
	long a,b,k;
	cin>>a>>b;
	
	if((a%10+b%10)%2==1){cout<<"IMPOSSIBLE";return 0;
	}
	long i=(max(a,b)+min(a,b))/2;
	if(abs(a-i)==abs(b-i)){cout<<i;	return 0;}	
	
//	for(long i=min(a,b);i<=max(a,b);i+=2){
//		if(abs(a-i)==abs(b-i)){
//			cout<<i;
//		}

//		cout<<"i="<<i<<endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 1000

int N,num_query;
stack<int> S[NUM];

int main(){

	scanf("%d %d",&N,&num_query);

	int command,A,B;

	for(int loop = 0; loop < num_query; loop++){

		scanf("%d",&command);

		switch(command){
		case 0:

			scanf("%d %d",&A,&B);
			S[A].push(B);
			break;

		case 1:

			scanf("%d",&A);
			if(!S[A].empty()){
				printf("%d\n",S[A].top());
			}

			break;

		case 2:

			scanf("%d",&A);
			if(!S[A].empty()){
				S[A].pop();
			}
			break;
		}
	}

	return 0;
}



Measured memory_bytes: 4392
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		sc.close();
		int s500 = X/500;
		int s5 = (X%500)/5;
		int uresi = s500*1000 + s5*5;
		System.out.println(uresi);
	}

}

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

string str;

int main() {
    int ans=0;
    cin>>str;
    for(int i=1;i<str.length();i++) ans+=9;
    int flag=1;
    for(int i=1;i<str.length();i++) if(str[i]!='9') flag=0;
    if(flag) cout<<ans+str[0]-'0';
    else cout<<ans+str[0]-'1';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
string s;
ll ter, res;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> s;
    n = s.size();
    for(int i=0; i<n; i++){
        if(s[i] == 'W') res += ter;
        else ter++;
    }
    cout << res;
}


Measured memory_bytes: 720
function parseInt(x)
    parse(Int, x)
end

function main()
    n = parseInt(readline())
    p = parseInt.(split(readline()))
    min = 10 ^ 7
    count = 0
    for pi in p
        if pi < min
            min = pi
            count += 1
        end
    end
    print(count)
end

main()

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  int n, m;
  cin >> n >> m;
  
  vector<pll> a(m), c;
  REP(i,m)
    cin >> a[i].FI >> a[i].SE;
  
  sort(a.begin(), a.end());

  REP(i, m){
    bool addflag = true;
    REP(j, c.size()){
      if((c[j].FI <= a[i].FI && a[i].FI < c[j].SE) || (c[j].FI < a[i].SE && a[i].SE <= c[j].SE)){
        c[j].FI = max(c[j].FI, a[i].FI);
        c[j].SE = min(c[j].SE, a[i].SE);
        addflag = false;
        break;
      }
    }
    if(addflag)
      c.push_back(make_pair(a[i].FI, a[i].SE));
  }
  


  cout << c.size() << endl;
  
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <vector>
#include <cctype>
#include <cmath>
using namespace std;
typedef long long ll;
const double PI = acos( -1.0 );

int main( void ) {
    int n;
    while( cin >> n && n ) {
        double s[1005];
        double avg = 0, sum = 0;
        for( int i = 0; i < n; ++i ) {
            cin >> s[i];
            avg += s[i];
        }
        avg /= (double)n;
        for( int i = 0; i < n; ++i ) {
            sum += pow( avg - s[i], 2 );
        }
        sum /= (double)n;
        printf( "%.8lf\n", sqrt( sum ) );
    }
    return 0;
}



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

int main() {
    int a, b, c, tmp;
    cin >> a >> b >> c;
    if (a > b) {
        tmp = b;
        b = a;
        a = tmp;
    }
    if (b > c) {
        tmp = c;
        c = b;
        b = tmp;
    }
    if (a > b) {
        tmp = b;
        b = a;
        a = tmp;
    }
    cout << a << " " << b << " " << c << endl;
}


Measured memory_bytes: 3108
#codng utf-8
N=int(input())
S=list(input())
s1=[0]*N#open
s2=[0]*N#close
p=[0]*N
if S[0]=='(':
    s1[0]=1
else:
    s2[0]=1
for i in range(1,N):
    if S[i]=='(':
        s1[i]=s1[i-1]+1
        s2[i]=s2[i-1]
        p[i]=p[i-1]
    else:
        s1[i]=s1[i-1]
        s2[i]=s2[i-1]+1
        if s1[i]-p[i-1]>0:
            p[i]=p[i-1]+1
        else:
            p[i]=p[i-1]
if s1[N-1]-p[N-1]>0:
    S.append(')'*(s1[N-1]-p[N-1]))
if s2[N-1]-p[N-1]>0:
    l2='('*(s2[N-1]-p[N-1])
    S.insert(0,l2)
print(''.join(S))

#print(s1,s2,p)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		int k = (a + b) % 2 == 0 ? (a+b)/2: -1;

		if (k != -1) {
			System.out.println(k);
		} else {
			System.out.println("IMPOSSIBLE");
		}
	}
}


Measured memory_bytes: 23764
#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>;
#define chmax(x,y) x = max(x,y);

int main() {
    int n;
    cin >> n;
    vector<int> L(n);
    rep(i,n) cin >> L[i];
    sort(L.begin(), L.end());
    ll ans = 0;
    rep(b,n)rep(a,b) {
        int ab = L[a]+L[b];
        int r = lower_bound(L.begin(), L.end(), ab) - L.begin();
        int l = b+1;
        ans += max(0, r-l);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3616
#[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 ) * } } ; }
#[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" ) } ; }

fn main() {
    input! {
        n: u64
    }
    println!("{}", n / 3);
}

Measured memory_bytes: 4352
function main()
  n = parse(Int, readline())
  s = readline()

  r = []
  g = []
  b = []

  for (i, str) in enumerate(s)
    if str == 'R'
      push!(r, i)
    elseif str == 'G'
      push!(g, i)
    else
      push!(b, i)
    end
  end

  exclude_num = 0
  for (i, str) in enumerate(s)
    for diff in 1:Int(floor((n - i) / 2))
      if str != s[i + diff] && s[i + diff] != s[i + 2diff] && s[i + 2diff] != str
        exclude_num += 1
      end
    end
  end

  println(size(r)[1] * size(g)[1] * size(b)[1] - exclude_num)
end

main()


Measured memory_bytes: 163372
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let s = input_line_str();
        let split_result = s.split(SPLIT_DELIMITER);
        let mut vec_line: Vec<T> = Vec::new();
        for z in split_result {
            let buf = match z.parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            vec_line.push(buf);
        }
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}

fn main() {
    let n: usize;
    let m: usize;
    let q: usize;

    input!(n, m, q);
    let mut v = vec![vec![0; n]; n];

    for _ in 0..m {
        let l: usize;
        let r: usize;
        input!(l, r);
        v[l - 1][r - 1] += 1;
    }

    for x in 0..n {
        for y in 1..n {
            v[x][y] = v[x][y - 1] + v[x][y];
        }
    }

    for _ in 0..q {
        let mut ans = 0;
        let p: usize;
        let q: usize;
        input!(p, q);

        for z in p - 1..q {
            if p == 1 {
                ans += v[z][q - 1];
            } else {
                ans += v[z][q - 1] - v[z][p - 2];
            }
        }
        println!("{}", ans);
    }
}

Measured memory_bytes: 4988
import java.util.Scanner;

public class Main {


	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		long n = scan.nextLong();
		long a = scan.nextLong();
		long b = scan.nextLong();

		long r = a * (n / (a+b));
		long k = n % (a+b);
		r += (  k < a ? k : a  );

		System.out.println(r);
	}

}


Measured memory_bytes: 23764
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  lint x; cin >> x;
  lint ans = 0;
  ans += 1000 * (x / 500);
  x %= 500;
  ans += 5 * (x / 5);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
# ABC099D - Good Grid
import sys
input = sys.stdin.readline

from collections import Counter
from itertools import product


def main():
    N, C = map(int, input().split())
    D = [0] + list([0] + list(map(int, input().split())) for _ in range(C))
    grid = tuple(tuple(map(int, input().split())) for _ in range(N))
    cost = [Counter() for _ in range(3)]
    for i, g in enumerate(grid):
        for j in range(3):
            cost[j].update(g[(j - i) % 3 :: 3])
    dist = [[] for _ in range(3)]
    for i, target in product(range(3), range(1, C + 1)):
        cur = sum(D[source][target] * cnt for source, cnt in cost[i].items())
        dist[i].append(cur)
    ans = 1 << 60
    for i, j in product(range(C), repeat=2):
        if i == j:
            continue
        cur = dist[0][i] + dist[1][j]
        cur += min(x for k, x in enumerate(dist[2]) if k not in (i, j))
        ans = min(ans, cur)
    print(ans)


if __name__ == "__main__":
    main()

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

using namespace std;

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

	// int*はポインタ変数
	int* m = new int[n];
	int sum = 0;
	int moto = INT16_MAX;
	for (int i = 0; i < n; i++)
	{
		cin >> m[i];
		sum += m[i];
		moto = min(moto, m[i]);
	}

	cout << n + (x - sum) / moto << endl;
	return 0;
}

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

using namespace std;

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int suma = 0;
    if (a >= k && k > 0) {
        suma += k;
        k = 0;
    }
    else if (k > 0){
        suma += a;
        k -= a;
    }
    if (b >= k && k > 0) {
        k = 0;
    }
    else if (k > 0){
        k -= b;
    }
    if (k > 0) {
        suma -= k;
    }
    cout << suma;
    return 0;
}



Measured memory_bytes: 3608
from decimal import Decimal
N, K = map(int, input().split())
t = 0
i = 1
while(i < K):
    t += 1
    i *= 2
under = 2**t

p = 0
for i in range(1, N+1):
    c = 0
    while(i < K):
        c += 1
        i *= 2
    p += 2**(t-c)
print(Decimal(p/((2**t)*N)))


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n;
	string s;
	cin>>n>>s;
	ll r = 0, g = 0, b = 0;
	for(int i = 0; i < n; i++){
		if(s[i] == 'R')r++;
		if(s[i] == 'G')g++;
		if(s[i] == 'B')b++;
	}
	ll ans = r*g*b;
	for(int j = 1; j < n; j++){
		for(int i = 0; i < j; i++){
			int k = 2*j - i; if(k >= n)continue;
			if(s[i] != s[j] && s[j] != s[k] && s[k] != s[i])ans--;
		}
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 3692
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] an = new int[5];
		for(int i = 0; i < 5; i++) {
			an[i] = sc.nextInt();
		}
		int k = sc.nextInt();
		String ans = ":(";
		sc.close();
		if (an[4] - an[0] <= k) {
			ans = "Yay!";
		}
		System.out.println(ans);
	}
}

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

using namespace std;

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

    string s;
    cin >> s;

    bool x = true;
    for(size_t i = 0; i < s.size(); ++i){
        if(s[i] != 'x') x = false;
    }
    if(x){
        cout << 0 << endl;
        return 0;
    }

    int mae = 0, ushiro = s.size() - 1;
    int64_t ans = 0;
    bool check = true;
    while(mae <= ushiro){
        if(s[mae] == s[ushiro]){
            mae ++;
            ushiro --;
        }
        else if(s[mae] == 'x'){
            mae ++;
            ++ans;
        }
        else if(s[ushiro] == 'x'){
            ushiro --;
            ++ans;
        }
        else {
            check = false;
            break;
        }
    }
    if(check){
        cout << ans << endl;
    }
    else {
        cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 512
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.System.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    static void solve() throws Exception {
        int a = scanInt(), b = scanInt(), c = scanInt(), d = scanInt();
        while (true) {
            c -= b;
            if (c <= 0) {
                out.println("Yes");
                break;
            }

            a -= d;
            if (a <= 0)  {
                out.println("No");
                break;
            }
        }
    }

    static int scanInt() throws IOException {
        return parseInt(scanString());
    }

    static long scanLong() throws IOException {
        return parseLong(scanString());
    }

    static String scanString() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            solve();
            in.close();
            out.close();
        }
        catch (Throwable e) {
            e.printStackTrace();
            exit(1);
        }
    }
}

Measured memory_bytes: 32880
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
#ifdef _debug
#define out(i) cout << #i << ' ' << i
#else 
#define out(i)
#endif
using ll = long long;
using ull = unsigned long long;
using ul = unsigned;
using db = double;
const int maxn = 3000;
int n, m;
vector<int> edge[maxn];
vector<int> res;
int pos[maxn], ted[maxn];
int start;
vector<pair<int,int>> all;
bool dfs(int now){
	if(pos[now] != -1){
		vector<int> p;
		for(int i = pos[now];i < res.size();++i)p.push_back(res[i]);
		int cnt = 0;
		for(auto &k : all)if(pos[k.first] >= pos[now] and pos[k.second] >= pos[now]){
			++cnt;
		}
		if(cnt != p.size())return false;
		cout << p.size() << '\n';
		for(auto &u : p)cout << u << '\n';
		return true;
	}
	pos[now] = res.size();
	res.push_back(now);
	for(auto & i : edge[now])if(dfs(i))return true;
	pos[now] = -1;
	res.pop_back();
	return false;
}
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	fill(pos, pos + maxn, -1);
	cin >> n >> m;
	for(int i = 0, a, b;i < m;++i){
		cin >> a >> b;
		all.emplace_back(a, b);
		edge[a].emplace_back(b);
	}
	for(int i = 1;i <= n;++i)if(dfs(i))return 0;;
	cout << -1 << '\n';
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(){
     int total;
     cin>>total;
while(total!=0){
       int a,b,c,d,e,f,g,h,i,j;
       cin>>a>>b>>c>>d>>e>>f>>g>>h>>i;
       j=total-(a+b+c+d+e+f+g+h+i);
       cout<<j<<endl;
       cin>>total;
}
return 0;
}

Measured memory_bytes: 1160
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int readint() { return readln.chomp.to!int; }
int[] readints() { return readln.split.map!(to!int).array; }

void calc(Vec2 p, Vec2 a, Vec2 b) {
    auto ab = b - a;
    auto ap = p - a;

    auto e = ab.normalized;
    // ベクトル ap のベクトル ab への正射影ベクトルを求める
    auto ah = ap.dot(e) * e;

    auto hp = ap - ah;
    auto hx = -hp;
    auto x = a + ah + hx;
    writefln("%.8f %.8f", x.x, x.y);

/*
    auto d = ab.normalize().dot(ap);
    auto m = a + ab.normalize() * d;

    auto x = p + (m - p) * 2;
    writefln("%.8f %.8f", x.x, x.y);
    */
}

void main() {
    auto xs = readints();
    auto p1 = Vec2(xs[0], xs[1]);
    auto p2 = Vec2(xs[2], xs[3]);

    int q = readint();
    for (int i = 0; i < q; i++) {
        auto xy = readints();
        auto p = Vec2(xy[0], xy[1]);
        calc(p, p1, p2);
    }
}

struct Vec2 {
    immutable double x;
    immutable double y;

    this(double x, double y) {
        this.x = x;
        this.y = y;
    }

    Vec2 opNeg() { return Vec2(-this.x, -this.y); }
    Vec2 opAdd(Vec2 other) { return Vec2(this.x + other.x, this.y + other.y); }
    Vec2 opSub(Vec2 other) { return Vec2(this.x - other.x, this.y - other.y); }
    Vec2 opMul(double d) { return Vec2(this.x * d, this.y * d); }

    double dot(Vec2 other) { return this.x * other.x + this.y * other.y; }
    double cross(Vec2 other) { return this.x * other.y - other.x * this.y; }
    double mag() { return sqrt(magSq()); }
    double magSq() { return this.x * this.x + this.y * this.y; }

    Vec2 normalized() {
        auto m = mag();
        if (m != 0 && m != 1)
            return Vec2(this.x / m, this.y / m);
        return this;
    }

    static double distance(Vec2 a, Vec2 b) {
        return (a - b).mag();
    }
}



Measured memory_bytes: 2560
#include <iostream>
#include <vector>


int main() {


	std::cin.tie(nullptr); std::ios::sync_with_stdio(false);
	int N; std::cin >> N;
	std::vector<int> T(N); for (int i = 0; i < T.size(); i++)std::cin >> T.at(i);
	int M; std::cin >> M;
	std::vector<int> P(M), X(M); for (int i = 0; i < P.size(); i++)std::cin >> P.at(i) >> X.at(i);


	int ans = 0;
	for (int i = 0; i < P.size(); i++) {
		for (int j = 0; j < T.size(); j++) {
			if (P.at(i) - 1 == j) {
				ans += X.at(i);
			}
			else {
				ans += T.at(j);
			}
		}
		if (i == P.size() - 1)std::cout << ans;
		else std::cout << ans << '\n';
		ans = 0;
	}


	return 0;


}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <sstream>
#include <numeric>
#include <cstdio>
#include <cassert>
using namespace std;

string to_str(int n)
{
	string res;
	res.push_back('0' + n % 10000 /1000);
	res.push_back('0' + n % 1000 / 100);
	res.push_back('0' + n % 100 / 10);
	res.push_back('0' + n % 10 / 1);
	return res;
}

bool same_all(string s) { return count(s.begin(), s.end(), s[0]) == s.size(); }
int to_int(string s) { return atoi(s.data()); }

int main()
{
	for(string line; cin >> line && (line != "0000"); ) {
	  int times = 0;

		if(same_all(line)) {
			cout << "NA" << endl;
			continue;
		}
		
		for(; line != "6174"; times++) {
			sort(line.begin(), line.end());
			int small = to_int(line);
		
			reverse(line.begin(), line.end());
			int big = to_int(line);

			int next = big - small;

			line = to_str(next);
		}

		cout << times << endl;
	}
}

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

using namespace std;
using ll = long long;


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

    int cnt = 0;
    for(int i = 1; i < n - 1; i++) {
        vector<int> t = {a[i - 1], a[i], a[i + 1]};
        sort(t.begin(), t.end());
        if(t[1] == a[i])cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3632
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String[] str = new String[N];
        int[] a = new int[N];
        int[] num = new int[N];
        String[] s = new String[N];
        
        for(int i=0; i<N; i++){
            str[i] = sc.next();
            a[i] = sc.nextInt();
            if(i<9){
                num[i] = 1;
            }else if(i < 99){
                num[i] = 2;
            }else{
                num[i] = 3;
            }
            if(a[i]<1){
                s[i] = str[i]+(100-a[i])+(i+1)+num[i];
            }else if(a[i]<91){
                s[i] = str[i]+"0"+(100-a[i])+(i+1)+num[i];
            }else{
                s[i] = str[i]+"00"+(100-a[i])+(i+1)+num[i];
            }
            //System.out.println(s[i]);
        }
        Arrays.sort(s);
        for(int i=0; i<N; i++){
            //System.out.println(s[i]);
            if(s[i].charAt(s[i].length()-1) == '1'){
                System.out.println(s[i].charAt(s[i].length()-2));
            }else if(s[i].charAt(s[i].length()-1) == '2'){
                System.out.print(s[i].charAt(s[i].length()-3));
                System.out.println(s[i].charAt(s[i].length()-2));
            }else{
                System.out.print(s[i].charAt(s[i].length()-4));
                System.out.print(s[i].charAt(s[i].length()-3));
                System.out.println(s[i].charAt(s[i].length()-2));
            }
            //System.out.println(s[i].charAt(s[i].length()-1));
        }
    }
}

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

using namespace std;

const int MX = 190;

int n, m;
char mp[MX][MX];
int f[MX][MX][MX], g[MX][MX][MX];
int sum[2][MX][MX];

void cmax(int &a, const int &b)
{
	if(b > a) a = b;
}

void input()
{
	scanf("%d%d", &n, &m);
	for(int i=1; i<=n; i++) scanf("%s", mp[i]+1);
}

void work()
{
	for(int i=1; i<=n; i++)
		for(int j=1; j<=m; j++)
		{
			sum[0][i][j] = sum[0][i][j-1] + (mp[i][j]=='.');
			sum[1][i][j] = sum[1][i][j-1] + (mp[i][j]=='#');
		}
	for(int i=n; i>=1; i--)
		for(int j=1; j<=m; j++)
			for(int k=j; k<=m; k++)
				for(int c=0; c<2; c++)
					if(sum[c][i][k]-sum[c][i][j-1]==k-j+1)
					{
						if(sum[c][i+1][k]-sum[c][i+1][j-1]==k-j+1) cmax(f[i][j][k], f[i+1][j][k]+1);
						else cmax(f[i][j][k], 1);
					}
	if(f[1][1][m] == n)
	{
		printf("%d\n", 0);
		return;
	}
	for(int r=1; r<=15; r++)
	{
		for(int i=1; i<=n; i++)
			for(int j=1; j<=m; j++)
				for(int k=j; k<=m; k++)
					cmax(g[j][i][i+f[i][j][k]-1], k-j+1);
		for(int i=1; i<=n; i++)
			for(int j=1; j<=m; j++)
				for(int k=m; k>=j; k--)
					cmax(f[i][j][k], f[i][j][k+1]);
		for(int i=1; i<=m; i++)
			for(int j=1; j<=n; j++)
				for(int k=n; k>=j; k--)
					cmax(g[i][j][k], g[i][j][k+1]);
		for(int i=1; i<=n; i++)
			for(int j=1; j<=m; j++)
				for(int k=1; k<=m; k++)
					cmax(f[i][j][k], f[i][j][k]+f[i+f[i][j][k]][j][k]);
		for(int i=1; i<=m; i++)
			for(int j=1; j<=n; j++)
				for(int k=1; k<=n; k++)
					cmax(g[i][j][k], g[i][j][k]+g[i+g[i][j][k]][j][k]);
		for(int i=1; i<=m; i++)
			for(int j=1; j<=n; j++)
				for(int k=j; k<=n; k++)
					cmax(f[j][i][i+g[i][j][k]-1], k-j+1);
		if(f[1][1][m] == n)
		{
			printf("%d\n", r);
			return;
		}
	}
	printf("16\n");
}

int main()
{
	input();
	work();
	return 0;
}

Measured memory_bytes: 53504
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;

int main(){
  ll n;
  cin>>n;
  ll cnt=0;
  string s=to_string(n);
  int m=s.size();
  for(int i=0;i<m;i++){
    cnt+=s[i]-'0';
  }
  if(n%cnt==0) cout<<"Yes";
  else cout<<"No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K, x ,L;
  cin >> N >> K;
  L=0;

  for(int i=0; i<N; i++){
    cin >> x;
    if(x < K - x){
      L += 2*x; 
    }
    else {
      L += 2*(K - x);
    }
  }
  cout << L << endl;
}

Measured memory_bytes: 256
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  rep(i,n) cin >> h.at(i);
  int wa=0;
  rep(i,n) wa += h.at(i);
//  cout << wa <<endl;
  int mi = 1000;
  int miwa = 0;
  int i=0;
  for(;;){//mugenstart
    int b = 0;
    mi = 1000;
  for(int i=0;i<n;i++){
    if(h.at(i) == 0 ){
      for(int k=b; k<i;k++){
        mi = min(mi,h.at(k));
      }
      for(int k=b; k<i;k++){
       h.at(k) -= mi;
      }
      if(mi != 1000){
      wa -= mi * (i-b);
      miwa += mi;
      }
      b = i+1;
      mi = 1000;
    }//ifend
    else if(i == n-1){
      i++;
      for(int k=b; k<i;k++){
        mi = min(mi,h.at(k));
//        cout << "test"<< k << endl;
      }
//        cout << "最小値は"<< mi << endl;
      for(int k=b; k<i;k++){
       h.at(k) -= mi;
      }
      if(mi != 1000){
      wa -= mi * (i-b);
      miwa += mi;
      }
      b = i+1;
      mi = 1000;
    }//else if end
  }//for i end
  if(wa == 0)break;
  }//mugenend
  
/*  //2kaimawasudakenotameshi
    for(int i=0;i<n;i++){
    int b = 0;
    if(h.at(i) == 0 ){
      for(int k=b; k<i;k++){
        mi = min(mi,h.at(k));
      }
      for(int k=b; k<i;k++){
       h.at(k) -= mi;
      }
      wa -= mi * (i-b);
      miwa += mi;
      b = i+1;
    }//ifend
    else if(i == n-1){
      i++;
      for(int k=b; k<i;k++){
        mi = min(mi,h.at(k));
        cout << "test"<< k << endl;
      }
        cout << "最小値は"<< mi << endl;
      for(int k=b; k<i;k++){
       h.at(k) -= mi;
      }
      wa -= mi * (i-b);
      miwa += mi;
      b = i+1;
    }//else if end
  }//for i end

  //2kaimawasudakenotameshi
  */
//  cout << wa <<endl;
  cout << miwa <<endl;
//  rep(i,n) cout << h.at(i);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define F               first
#define S               second
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18 + 1
#define endl            '\n'
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define forI(i,a,n)     for(int i=a;i<=n;i++)
#define forD(i,a,n)     for(int i=n;i>=a;i--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
void init(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

vi g[100005];
int dp[100005];

int compute(int src){
    if(dp[src] != -1)    return dp[src];

    int leaf = 1, bestChild = 0;
    for(auto child : g[src]){
        leaf = 0;
        bestChild = max(bestChild, compute(child));
    }

    return dp[src] = leaf ? 0 : 1 + bestChild;
}

void solve(){
    int n, m, x, y;   cin>>n>>m;
    memset(dp, -1, sizeof dp);    
    forI(i, 1, m){
        cin>>x>>y;
        g[x].pb(y);
    }
    
    int ans = 0;
    forI(i, 1, n)   ans = max(ans, compute(i));

    cout<<ans;
}

int32_t main(){
    init();
    // w(t) 
    solve();
    return 0;
}

Measured memory_bytes: 11932
use std::fmt::Debug;
use std::str::FromStr;

pub struct TokenReader {
    reader: std::io::Stdin,
    tokens: Vec<String>,
    index: usize,
}

impl TokenReader {
    pub fn new() -> Self {
        Self {
            reader: std::io::stdin(),
            tokens: Vec::new(),
            index: 0,
        }
    }

    pub fn next<T>(&mut self) -> T
    where
        T: FromStr,
        T::Err: Debug,
    {
        if self.index >= self.tokens.len() {
            self.load_next_line();
        }
        self.index += 1;
        self.tokens[self.index - 1].parse().unwrap()
    }

    pub fn vector<T>(&mut self) -> Vec<T>
    where
        T: FromStr,
        T::Err: Debug,
    {
        if self.index >= self.tokens.len() {
            self.load_next_line();
        }
        self.index = self.tokens.len();
        self.tokens.iter().map(|tok| tok.parse().unwrap()).collect()
    }

    pub fn load_next_line(&mut self) {
        let mut line = String::new();
        self.reader.read_line(&mut line).unwrap();

        self.tokens = line
            .split_whitespace()
            .map(String::from)
            .collect();
        self.index = 0;
    }
}

struct Fenwick {
    nodes: Vec<usize>,
}

impl Fenwick {
    fn new(len: usize) -> Self {
        Self {
            nodes: vec![1 << 30; len + 1],
        }
    }

    fn set(&mut self, value: usize, mut pos: usize) {
        while pos < self.nodes.len() {
            self.nodes[pos] = std::cmp::min(self.nodes[pos], value);
            pos += Fenwick::lsb(pos);
        }
    }

    fn get(&self, mut pos: usize) -> usize {
        let mut res = 1 << 30;
        while pos > 0 {
            res = std::cmp::min(res, self.nodes[pos]);
            pos -= Fenwick::lsb(pos);
        }
        res
    }

    fn lsb(num: usize) -> usize {
        num & (!(num - 1))
    }
}

struct Helper {
    tree: Fenwick,
    len: usize,
}

impl Helper {
    fn new(len: usize) -> Self {
        Self {
            tree: Fenwick::new(len),
            len,
        }
    }

    fn update_lower(&mut self, value: usize, pos: usize) {
        self.tree.set(value, self.len + 1 - pos);
    }

    fn get_lowest(&self, pos: usize) -> usize {
        self.tree.get(self.len + 1 - pos)
    }
}

fn main() {
    let mut reader = TokenReader::new();
    let n = reader.next();
    let q = reader.next();

    let mut rows = Helper::new(n);
    let mut cols = Helper::new(n);
    let mut total: i64 = (n as i64 - 2) * (n as i64 - 2);

    rows.update_lower(n, n);
    cols.update_lower(n, n);

    for _ in 0..q {
        let kind: i32 = reader.next();
        let pos = reader.next();

        if pos == 1 || pos == n {
            continue;
        }

        if kind == 1 {
            let limit = rows.get_lowest(pos);
            total -= limit as i64 - 2;
            cols.update_lower(pos, limit - 1);
        } else {
            let limit = cols.get_lowest(pos);
            total -= limit as i64 - 2;
            rows.update_lower(pos, limit - 1);
        }
    }
    println!("{}", total);
}


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

int main() {
  int n, m;
  int taro[104];
  int hanako[104];
  while(scanf("%d %d", &n,&m), n||m) {
    int taro_sum = 0;
    int hanako_sum = 0;
    
    for (int i=0; i<n; i++) {
      scanf("%d", &taro[i]);
      taro_sum += taro[i];
    }
    for (int i=0; i<m; i++) {
      scanf("%d", &hanako[i]);
      hanako_sum += hanako[i];
    }
    
    sort(taro, taro+n);
    sort(hanako, hanako+m);

    // cout << "debug" << endl;
    // cout << taro_sum << endl;
    // cout << hanako_sum << endl;
    
    int diff = taro_sum - hanako_sum;
    int taro_found, hanako_found;

    // cout << "debug" << endl;
    // cout << diff << endl;
    
    for (int i=0; i<n; i++) {
      for (int j=0; j<m; j++) {
	// cout << "taro[i]" << taro[i] << " hanako[j]" << hanako[j] << endl;
	
	if ((taro[i] - hanako[j])*2 == diff) {
	  taro_found = taro[i];
	  hanako_found = hanako[j];
	  goto found;
	} 
      }
    }

    printf("-1\n");
    continue;
  found:
    printf("%d %d\n", taro_found, hanako_found);
  }
}

Measured memory_bytes: 3212
def nCr(n,r):
  ret = 1
  for i in range(r):
    ret *= n-i
    ret /= i+1
  return ret

def top(N,K):
  if K == 0:
    return 1
  L = len(N)
  ans = 0
  if L < K:
    return 0
  else:
    ans += nCr(L-1,K) * 9 ** K

    u = int(N[0])
    z = N.count('0')
    o = N.count('1')
    f = 0
    if z + o == L:
      f = 1
    if f == 0:
      ans += (u - 1) * nCr(L-1,K - 1) * 9 ** (K - 1)
      if L == 1:
        return ans + 1
      else:
        return ans + top(str(int(N[1:])),K - 1)
    else:
      if len(str(int(N[1:]))) != 1:
        return ans + top(str(int(N[1:])),K - 1)
      else:
        if o >= K:
          return ans + 1
        else:
          return ans

N = str(input())
K = int(input())

print(int(top(N,K)))

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

using Edge = pair<int, int>;
using Graph = vector<vector<int>>;	//グラフ

// 入力
int N,Q;
Graph G;

// res は答え
vector<int> res;

void dfs(int v, int p) {
  for (auto e : G[v]) {
    if (e == p) continue;
    res[e] += res[v];
    dfs(e, v);
  }
}

int main(void) {
  cin >> N >> Q;
  G.assign(N, vector<int>());
  for (int i = 0; i < N - 1; i++) {
    int u, v; cin >> u >> v;
    --u, --v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  res.assign(N, 0);
  for (int i = 0; i < Q; i++) {
    int x, value; cin >> x >> value;
    x--;
    res[x] += value;
  }
  dfs(0, -1);
  for (auto v : res) cout << v << ' ';
  cout << endl;
  return 0;
}

Measured memory_bytes: 23424
package main

import (
	"fmt"
	"os"
)

func main() {
	var n, m int
	fmt.Scanf("%d %d", &n, &m)

	pos := []int{-1, -1, -1}
	for i := 0; i < m; i++ {
		var s, c int
		fmt.Scanf("%d %d", &s, &c)
		if pos[s-1] == -1 {
			pos[s-1] = c
		} else if pos[s-1] != c {
			pos[s-1] = -2
		}
	}

	if pos[0] == -2 || pos[1] == -2 || pos[2] == -2 {
		fmt.Println("-1")
		os.Exit(0)
	}

	if n == 1 {
		if pos[0] == -1 {
			fmt.Println("0")
		} else {
			fmt.Println(pos[0])
		}
		os.Exit(0)
	}

	if pos[0] == 0 {
		fmt.Println("-1")
		os.Exit(0)
	} else if pos[0] == -1 {
		fmt.Print("1")
	} else {
		fmt.Print(pos[0])
	}
	for i := 1; i < n; i++ {
		if pos[i] == -1 {
			fmt.Print("0")
		} else {
			fmt.Print(pos[i])
		}
	}
	fmt.Println("")

}


Measured memory_bytes: 512
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main() 
{
	ll n1,s1=0;
	cin>>n1;
	for(int i=1;i<=n1;i++)
	{
	    for(int j=1;j<=n1;j++)
	    {
	        for(int k=1;k<=n1;k++)
	        {
	            s1+=(__gcd(i,__gcd(j,k)));
	        }
	    }
	}
	cout<<s1<<"\n";
	return 0;
}

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

int a, b;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> a >> b;
    if(a+b>=10) {
        cout << "error";
        return 0;
    }
    else cout<<a+b;

    return 0;
}



Measured memory_bytes: 256
a = input()
x = [a[i:i+1] for i in range(len(a))]

b = input()
y = [b[i:i+1] for i in range(len(b))]
n=0
for i in range(len(x)):
    n = n+1
    if x[i] != y[i]:
        print("No")
        break

if n == len(a) and x[len(a)-1]==y[len(a)-1]:
    print("Yes")

Measured memory_bytes: 9132
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;in(__VA_ARGS__)
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, nod, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007; ll INF = 1LL << 62; ll ans = 0; ll z = 0, o = 1;
vl flag, color, D; vll path;
//***********//
int main() {
	ll A, B, C, D;
	cin >> N >> A >> B >> C >> D;
	//+する回数をk回に固定する
	for (k = 0; k < N; k++) {
		if (-D*(N-1-k)+C*k <= B - A && B-A<= -C * (N-1-k) + D*k) {
			cout << "YES";
			exit(0);
		}
	}
	cout << "NO";
}

Measured memory_bytes: 256