akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
# 標準入力の取得
A, B, C, K = list(map(int, input().split()))

# 求解処理
result = int()
if K <= A:
    result = K
elif A < K and K <= A + B:
    result = A
elif A + B < K and K <= A + B + C:
    result = 2*A + B - K

# 結果出力
print(result)


Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> A(n); rep(i, n) cin >> A[i];
  sort(all(A), greater<ll>());
  ll ans = A[0];
  rep(i, (n-2)/2) ans += A[i+1]*2;
  if((n-2)%2) ans += A[n/2];
  cout << ans << endk;
  return 0;
}


Measured memory_bytes: 4768
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.PriorityQueue;

public class Main{
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(isr);
		
		PriorityQueue<Pair> que = new PriorityQueue<Pair>();
		int INT;
		double DOB;
		for(int i = 0; i < 3; i++){
			PriorityQueue<Pair> hoge = new PriorityQueue<Pair>();
			for(int j = 0; j < 8; j++){
				String str[] = reader.readLine().split(" ");
				INT = Integer.valueOf(str[0]);
				DOB =  Double.valueOf(str[1]);
				hoge.add(new Pair(DOB, INT));
			}
			System.out.println(hoge.peek().INT + " " + hoge.poll().DOB);
			System.out.println(hoge.peek().INT + " " + hoge.poll().DOB);
			
			while(!hoge.isEmpty()){ que.add(hoge.poll()); }
		}
		System.out.println(que.peek().INT + " " + que.poll().DOB);
		System.out.println(que.peek().INT + " " + que.poll().DOB);
		
		reader.close();
	}
}

class Pair implements Comparable<Pair>{
	int INT;
	double DOB;
	Pair(double DOB, int INT){
		this.INT = INT;
		this.DOB = DOB;
	}
	@Override
	public int compareTo(Pair e) {
		return DOB < e.DOB ? -1 : 1;
	}
}

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

a = [[0] * 10 for _ in range(10)]
for i in range(1, N + 1):
    s = str(i)
    a[int(s[0])][int(s[-1])] += 1

ans = sum(a[i][j] * a[j][i] for i in range(10) for j in range(10))

print(ans)


Measured memory_bytes: 2940
arg = []
while (get = gets)
  arg << get.to_i
end
max = 0
suspection = []
temp = 0
count = 0
arg.sort.each{|i|
  if temp == i
    count += 1
    if max < count
      suspection = [i]
      max = count
    elsif max == count
      suspection << i
    end
  else
    temp = i
    count = 1
  end}
puts suspection

Measured memory_bytes: 6084
//good luck
# include <iostream>
# include <cstdio>
# include <cmath>
# include <cstdlib>
# include <cstring>
# include <string>
# include <algorithm>
# include <vector>
# include <queue>
# include <ctime>
# include <map>

#define LL long long
#define maxn (int)4e5+5
#define inf  (int)2147483640
#define is(a) (a>='0'&&a<='9')
#define iabs(a) ((a)>0?(a):(-a))
#define imax(a,b) ((a)>(b)?(a):(b))
#define imin(a,b) ((a)<(b)?(a):(b))
 
using namespace std;

int N,Q,ax,bx,tot,head[maxn],next[maxn],ver[maxn],val[maxn],fa[maxn];

inline void read(int &x)
{
  x=0;bool f=0;char ch=getchar();
  for (;!is(ch);ch=getchar()) f|=ch=='-';
  for (;is(ch);ch=getchar()) x=(x<<3)+(x<<1)+(ch^48);
  x=f?-x:x;
}

void addedge(int x,int y)
{
	++tot; next[tot] = head[x]; head[x] = tot; ver[tot] = y; 
	++tot; next[tot] = head[y]; head[y] = tot; ver[tot] = x; 
}

void Dfs(int x)
{
	for (int i = head[x];i ;i = next[i])
	{
		int y = ver[i];
		if (fa[x] == y) continue;
		fa[y] = x;
		Dfs(y);
	}
}

void Debug(int x)
{
	for (int i = head[x];i ;i = next[i])
	{
		int y = ver[i];
		if (fa[x] == y) continue;
		val[y] += val[x];
		Debug(y);
	}
}

int main()
{
	read(N); read(Q);
	for (int i = 1; i < N; ++i) 
	{
		read(ax),read(bx);
		addedge (ax,bx);
	}
	Dfs(1);
	for (int i = 1; i <= Q; ++i) 
	{
		read(ax),read(bx);
		val[ax]+=bx;
	}
	Debug(1);
	for (int i = 1; i <= N; ++i)  printf("%d%c",val[i],(i == N)?'\n':' ');
	return 0;
}

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

using namespace std;
#define sqr(x) ((x)*(x))
#define cube(x) ((x)*(x)*(x))
#define GCD(a, b) __gcd(a, b)
#define LCM(a, b) ((a)*(b)/GCD(a,b))
#define PI (3.141592653589793238462643383279502884197169399375105820974944)
#define MP make_pair
#define n1 first
#define n2 second
#define ALL(x) (x).begin(), (x).end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PDB pair<db,db>
#define SI set<int>
#define SL set<ll>
#define MS multiset
#define MSI multiset<int>
#define MSLL multiset<ll>
#define PB push_back
#define PF push_front
#define VI vector<int>
#define VPI vector<pair<int,int>>
#define VLL vector<ll>
#define VS vector<string>
#define SZ(x) ((int)x.size())

typedef long long ll;

typedef unsigned long long ull;
typedef long double ld;
typedef double db;
const db eps = 0.000001;
const int INF = 1000000007;
const ll LINF = 1000000000000000555;
const int N = 1850555;
const int M = 1155;
const int L = 20;

void solve() {
    ll a;
    cin >> a;

    cout << a + a*a + a*a*a;


}

int main() {
    ios_base::sync_with_stdio(false);
#ifdef dxz05
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else

#endif

    int T = 1;
    //cin >> T;

    while (T--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3636
import sys
input = sys.stdin.readline

from collections import deque

class Node:
    def __init__(self, id_=0):
        self.id = id_
        self.link = []
        self.check = False

def main():
    N, M = map(int, input().split())

    nodes = [Node(i) for i in range(N)]
    for i in range(M):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        nodes[a].link.append(nodes[b])
        nodes[b].link.append(nodes[a])
    
    pre = [-1] * N
    q = deque()
    q.append(nodes[0])
    nodes[0].check = True
    while len(q) > 0:
        node = q.popleft()
        for nex in node.link:
            if not nex.check:
                nex.check = True
                pre[nex.id] = node.id
                q.append(nex)
    
    print("Yes")
    for i in range(1, N):
        print(pre[i]+1)

if __name__ == "__main__":
    main()

Measured memory_bytes: 41896
#include<stdio.h>

int gcd(int x, int y);

int main(){
  int x,y,z;

  scanf("%d %d", &x, &y);

  z = gcd(x, y);

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

  return 0;
}

int gcd(int x, int y){
  int z;
  int tmp;

  if(x < y){
    tmp = x;
    x = y;
    y = tmp;
  }

  for(;;){
    z = x % y;
    if(z==0){
      return y;
    }
    x = y;
    y = z;
  }
}



Measured memory_bytes: 2100
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int cnt1=0,cnt2=0;
  int num1=(s[0]-'0')*10+s[1]-'0';
  int num2=(s[2]-'0')*10+s[3]-'0';
  if(num1>0 && num1<13)cnt1++;
  if(num2>0 && num2<13)cnt2++;
  if(cnt1==0 && cnt2==0)	cout<<"NA"<<endl;
  else if(cnt1==1 && cnt2==0)	cout<<"MMYY"<<endl;
  else if(cnt2==1 && cnt1==0) cout<<"YYMM"<<endl;
  else	cout<<"AMBIGUOUS"<<endl;
  return 0
    ;
}


Measured memory_bytes: 256
def change(s):
    n = len(s)
    cc = 0

    for i in range(n // 2):
        if (s[i] == s[n - i - 1]):
            continue
        cc += 1
        if (s[i] < s[n - i - 1]):
            s[n - i - 1] = s[i]
        else:
            s[i] = s[n - i - 1]

    print(str(cc))
s = input()
change(list(s)) 

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <tuple>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

//素因数分解
vector<pair<ll,int>> factorize(ll n){
    vector<pair<ll,int>>res;
    for(ll i=2;i*i<=n;i++){
        if(n%i)continue;
        res.emplace_back(i,0);
        while (n%i == 0)
        {
        n /= i;
        res.back().second++;
        }
        
    }
    if(n != 1) res.emplace_back(n,1);
    return res;
}

int main(){
    int N;
    cin >> N;
    vector<tuple<string,int,int>>a;
    for(int i=1;i<=N;i++){
        string s;
        int p;
        cin >> s >> p;
        p = p*-1;
        a.push_back(tie(s,p,i));
    }
    sort(a.begin(),a.end());
    for(int i=0;i<N;i++){
        cout << get<2>(a[i]) << endl;
    }


}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class A
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var X = int.Parse(Console.ReadLine());
            var c = new int[] { 0, 0, 8, 7, 6, 5, 4, 3, 2, 1 };
            Console.WriteLine(c[X / 200]);
        }
    }
}


Measured memory_bytes: 27472
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int l, r;
  cin >> l >> r;
  if (r-l >= 2019) {
    cout << 0 << '\n';
    return 0;
  }
  l %= 2019;
  r %= 2019;
  int tmp = 0;
  int ans = 10000;
  if (r <= l) r += 2019;
  for (int i = l; i < r; i++) {
    for (int j = i+1; j < r+1; j++) {
      tmp = i*j % 2019;
      ans = min(ans,tmp);
      if (tmp == 0) break;
    }
  }
  cout << ans << '\n';
}

Measured memory_bytes: 256
import sys
import math
import copy
import random
import itertools
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

dic = dict()

def getnigo(num):
    org = num
    if num in dic:
        return dic[num]
    ni, go = 0, 0
    while num % 2 == 0:
        ni += 1
        num //= 2
    while num % 5 == 0:
        go += 1
        num //= 5

    ni, go = min(18, ni), min(18, go)
    dic[org] = (ni, go)
    return ni, go

def solve(n=None, s1=None, s2=None):
    n = getN()
    li = []
    for i in range(n):
        s = getS()
        if "." not in s:
            num = int(s) *  10 ** 9
        else:
            sei, syo = s.split(".")
            num = int(sei) * 10 ** 9 + int(syo) * 10 ** (9 - len(syo))
        li.append(num)

    nigoli = [[0 for i in range(20)] for i in range(20)]

    for num in li:
        ni, go = getnigo(num)
        nigoli[ni][go] += 1

    for i in range(20):
        for j in range(18, -1, -1):
            nigoli[i][j] += nigoli[i][j+1]

    for i in range(18, -1, -1):
        for j in range(20):
            nigoli[i][j] += nigoli[i+1][j]

    # for lili in nigoli:
    #     print(lili)

    ans = 0
    for num in li:
        ni, go = getnigo(num)
        tni, tgo = 18 - ni, 18 - go
        ans += nigoli[tni][tgo]
        if ni >= 9 and go >= 9:
            ans -= 1
        # print(num, ni, go, ans)

    print(ans // 2)
    # print(getnigo(1))




def main():
    for _ in range(n):
        solve()
    return


if __name__ == "__main__":
    # main()
    solve()


Measured memory_bytes: 108380
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}


fn main() {
    let line: Vec<i32> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = line[0];
    let q = line[1] as usize;
    let s = read_line();
    let s = s.trim().as_bytes();
    let mut td: Vec<(u8, u8)> = Vec::with_capacity(q);
    for _i in 0..q {
        let line: Vec<u8> = read_line().split_whitespace().map(|s| s.as_bytes()[0]).collect();
        td.push((line[0], line[1]));
    }

    let mut ans = 0;
    let mut l = -1;
    let mut r = n;
    while r - l > 1 {
        let m = (l + r) / 2;
        let mut pos = m;
        for i in 0..q {
            if td[i].0 == s[pos as usize] {
                if td[i].1 == 'L' as u8 {
                    pos -= 1;
                } else {
                    pos += 1;
                }
            }
            if pos < 0 || pos >= n {
                break;
            }
        }
        if pos < 0 {
            l = m;
        } else {
            r = m;
        }
    }
    ans += l + 1;
    let mut l = -1;
    let mut r = n;
    while r - l > 1 {
        let m = (l + r) / 2;
        let mut pos = m;
        for i in 0..q {
            if td[i].0 == s[pos as usize] {
                if td[i].1 == 'L' as u8 {
                    pos -= 1;
                } else {
                    pos += 1;
                }
            }
            if pos < 0 || pos >= n {
                break;
            }
        }
        if pos >= n {
            r = m;
        } else {
            l = m;
        }
    }
    ans += n - r;

    println!("{}", n - ans);
}


Measured memory_bytes: 4352
N, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
count = 0
for i in range(len(a)):
    if x - a[i] >= 0:
        x -= a[i]
        count += 1
    else:
        break
if count == N and x  > 0:
    print(count - 1)
else:
    print(count)

Measured memory_bytes: 8932
#include <cstdio>

int main()
{
    int n, x;
        
    while (true){
        int cnt = 0;
        scanf(" %d %d", &n, &x);
        if (x == 0 && n == 0){
            break;
        }
        
        for (int i = 1; i <= n; i++){
            for (int j = i + 1; j <= n; j++) {
                for (int k = j + 1; k <= n; k++){
                    if((i + j + k) == x){
                        cnt++;
                    }
                }
            }
        }
        printf("%d\n", cnt);
    }
     
   
   return 0;
}

Measured memory_bytes: 1028
#5で割る->すべて5n+mなら和が5(n+...)+5mで勝てる
n=int(input());i=j=0;a=[]
def p(n):
  if n==1:return False
  for i in range(2,int(n**0.5)+1):
    if n%i==0:return False
  return True
while i<n:
  if p(5*j+1):i+=1;a.append(5*j+1)
  j+=1
print(*a)

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

using namespace std;

int D[202020];
int n, ans;

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

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
int SIZE(string s){ return (int)s.size(); }
ll mod = 1e9+7;

int main(){
    cout << fixed << setprecision(20);
    ll n,k; cin >> n >> k;
    n++;
    ll ans = 0;
    rng(i,k,n+1){
        if(i == n){
            ans += 1;
            ans %= mod;
        } else {
            ll plus = 0;
            plus += (i*(n-i)+1) % mod;
            plus %= mod;
            ans += plus;
            ans %= mod;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
a, b, c, k = map(int, input().split())

ans = 0
cards = [a, b, c]
nums =  [1, 0, -1]

i = 0

while k>0:
    if cards[i] <= k:
        ans += cards[i] * nums[i]
        k -= cards[i]
    else:
        ans += nums[i] * k
        break
    i += 1

print(ans)


Measured memory_bytes: 9188
# -*- coding: utf-8 -*-
from sys import stdin
# a = input()
a = stdin.readline().rstrip()
while a != '0':
  # [sum += int(i) for i in list(a)]
  b = [(int(i)) for i in list(a)]
  #print(b)
  print(sum(b))
  a = stdin.readline().rstrip()



Measured memory_bytes: 5632
a=int(input())
b=input()
s1=s2=e1=e2=0
str1=str2=''

for i in range(len(b)):
    if( b[i] == '(' ):
        s1-=1
    elif( b[i] == ')' ):
        s1+=1
        if(s1>s2):
            s2=s1
            str1+='('

for i in range(len(b)-1,-1,-1):
    if( b[i] == '(' ):
        e1+=1
        if(e1>e2):
            e2=e1
            str2+=')'
    elif( b[i] == ')' ):
        e1-=1

print(str1 + b + str2)


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

using namespace std;

int main(){
    int n, t;
    cin >> n >> t;
    
    int ans = 1e9;
    for (int i = 1; i <= n; i++) {
        int a, b;
        cin >> a >> b;
        if (b <= t) ans = min(ans, a);
    }
    
    if (ans > 5e8) cout << "TLE";
    else cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int N, cnt = 0;
    cin >> N;
    vector<int> p(N);
    for (auto& i : p) cin >> i;
    for (int i = 0; i < N; i++) {
        if (p[i] == i + 1) {
            cnt++;
            if (i == N - 1) swap(p[i], p[i - 1]);
            else swap(p[i], p[i + 1]);
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 640
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;
const ll MOD = 998244353;

ll f(ll n) {
    if (n % 2 == 0) {
        return n / 2;
    } else {
        return 3 * n + 1;
    }
}

int main() {
    ll s;
    cin >> s;
    set<ll> m;
    ll cur = s;
    m.insert(cur);
    for (ll i = 2; i <= 1000000; ++i) {
        cur = f(cur);
        if (m.find(cur) != m.end()) {
            cout << i << endl;
            return 0;
        }
        m.insert(cur);
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
int find(int x, vector<int> &pa) {
    return pa[x] < 0 ? x : pa[x] = find(pa[x], pa);
}
typedef pair<int, int> pii;
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, m, k; cin >> n >> m >> k;
    vector<pii> M(m), K(k);
    for (auto &p : M)
        cin >> p.F >> p.S, p.F--, p.S--;
    for (auto &p : K)
        cin >> p.F >> p.S, p.F--, p.S--;
    vector<int> pa(n, -1);
    for (auto &p : M) {
        int x = find(p.F, pa);
        int y = find(p.S, pa);
        if (x == y)
            continue;
        pa[x] += pa[y];
        pa[y] = x;
    }
    vector<int> ans;
    for (int i = 0 ; i < n ; i++)
        ans.push_back(-pa[find(i, pa)]);
    for (auto &p : M)
        ans[p.F]--, ans[p.S]--;
    for (auto &p : K) {
        int x = find(p.F, pa);
        int y = find(p.S, pa);
        if (x != y)
            continue;
        ans[p.F]--, ans[p.S]--;
    }
    for (int i = 0 ; i < n ; i++)
        cout << ans[i] - 1 << " \n"[i + 1 == n];
}


Measured memory_bytes: 3960
use std::cmp::{max, min};
use whiteread::parse_line;

fn main() {
    let n: usize = parse_line().unwrap();
    let seq: String = parse_line().unwrap();
    let seq = seq.as_bytes();
    let (mut r, mut w) = (0, 0);
    for &c in seq.iter() {
        if c == b'R' {
            r += 1;
            continue;
        }
        w += 1;
    }
    let mut local_r = r;
    let mut local_w = 0;
    let mut res = r;
    for c in seq.iter() {
        match c {
            b'R' => {
                local_r -= 1;
            }
            _ => {
                local_w += 1;
            }
        }
        res = min(max(local_r, local_w), res);
    }
    res = min(res, w);
    println!("{}", res);
}


Measured memory_bytes: 2400
N = int(input())
P = [int(input()) for _ in range(N)]

Q = [-1]*N
for i in range(N):
    Q[P[i]-1] = i

x = 1
tmp = 1
for i in range(1,N):
    if Q[i] > Q[i-1]:
        tmp += 1
        x = max(x, tmp)
    else:
        tmp = 1

print(N-x)

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

using namespace std;

int main()
{
    int n; cin >> n;
    vector<double> dp(n+1);
    dp[0] = 1;
    for(int i = 1; i <= n; i++)
    {
        double hd, tl; cin >> hd;
        tl = 1 - hd;
        for(int j = i; j >= 0; j--)
            dp[j] = (j == 0) ? dp[j]*tl : ((dp[j-1]*hd)+(dp[j]*tl));
    }
    double ans = 0;
    for(int i = (n+1)/2; i <= n; i++)
            ans += dp[i];
    printf("%.10lf\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long lli;
typedef pair<int, int> pii;
const int cost[3] = {300000, 200000, 100000};
int x, y;

void ReadInput()
{
    cin >> x >> y;
}

void Solve()
{
    int ans = 0;
    --x; --y;
    if(x < 3) ans += cost[x];
    if(y < 3) ans += cost[y];
    if(x == y && x == 0) ans += 400000;
    cout << ans << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ReadInput();
    Solve();
}


Measured memory_bytes: 256
from bisect import bisect_left


S = input()
T = input()
if any(c not in S for c in T):
    print(-1)
    exit()

N = len(S)
pos = {c: [] for c in "abcdefghijklmnopqrstuvwxyz"}
for i in range(N):
    pos[S[i]].append(i)

loop = 0
cur = 0
for c in T:
    nxt = bisect_left(pos[c], cur)
    if nxt == len(pos[c]):
        loop += 1
        cur = pos[c][0] + 1
    else:
        cur = pos[c][nxt] + 1
print(loop * N + cur)


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

#define ll long long
#define INF 99999999
#define INF_LL 1LL << 60
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n); i >= 0; i--)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define RREP(i, a, n) for(int i = (int)(n); i >= a; i--)
#define all(x) (x).begin(),(x).end()

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

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

ll COM(ll n,ll r){
    if(r==1)return n;
    if(r==2)return n*(n-1)/2;
    return n*(n-1)*(n-2)/6;
}

int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    vector<ll> nums(N,0);
    rep(i,N)
    {
        cin >> A[i];
        nums[A[i]-1]++;
    }

    ll total = 0;
    rep(i, nums.size())
    {
        if( nums[i] > 1 ) total += COM(nums[i],2);
    }
    
    rep(i, N)
    {
        if( nums[A[i]-1]-1 > 1 ) cout << total - COM(nums[A[i]-1], 2) + COM(nums[A[i]-1]-1,2) << endl;
        else cout << total - COM(nums[A[i]-1],2) << endl;
        //cout << total - COM(nums[A[i]-1], 2) + COM(nums[A[i]-1]-1,2)-1 << endl;
        //cout << total << " " << COM(nums[A[i]-1], 2) << " " <<  COM(nums[A[i]-1]-1,2) << endl;
    }
}


Measured memory_bytes: 5760
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define range_for(i, b, e) for(int i=(b), i##_len=(e); i<=i##_len; ++i)
# define ALL(x) (x).begin(), (x).end()
# define RALL(x) (x).rbegin(), (x).rend()
# define pb push_back
# define len(x) ((int)(x).size())
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define debug(x) std::cerr<<#x<<": "<<(x)<<endl;
# define LINT_MAX (LONG_LONG_MAX)
# define cauto const auto
using namespace std;
using lint = long long;
template <class Type> inline constexpr bool InRange(const Type& x, const Type& i, const Type& a) { return (i <= x) && (x <= a); }
template<class Integer>bool chmax(Integer &a, const Integer &b) { if (a<b) { a=b; return 1; } return 0; }
template<class Integer>bool chmin(Integer &a, const Integer &b) { if (b<a) { a=b; return 1; } return 0; }
template<class Integer>bool IsOdd(Integer &n) { return n & 1; }
template<class Integer>bool IsEven(Integer &n) { return !(n & 1); }
int ctoi(const char c) { return ('0' <= c && c <= '9') ? (c - '0') : -1; }
string YesNo(bool b) { return b ? "Yes" : "No"; }
string YESNO(bool b) { return b ? "YES" : "NO"; }
string yesno(bool b) { return b ? "yes" : "no"; }
int dy[4] = {0, 1, 0, -1};
int dx[4] = {1, 0, -1, 0};

// 整数の桁数を返す ( log(N) )
template <class Integer> Integer GetDigit(Integer n) {
    if (n == 0) return 1;
    Integer d = 0;
    while (n) {
        n /= 10;
        d++;
    }
    return d;
}

// 素数かどうかを返す ( O(sqrt(N)) )
template <class Integer>
constexpr bool IsPrime(const Integer n) noexcept {
    if (n < 4) return n == 2 || n == 3;
    if (n % 2 == 0 || n % 3 == 0 || (n % 6 != 1 && n % 6 != 5)) return false;
    for (Integer i = 5; i * i <= n; i += 6) if (n % i == 0 || n % (i + 2) == 0) return false;
    return true;
}

// 1e4
int main()
{
    int N; cin >> N;
    string S; cin >> S;

    int ans = 0;
    range_for (i, 0, 999)
    {
        string sub;
        switch (GetDigit(i))
        {
            case 1:
                sub = "00" + to_string(i);
                break;
            case 2:
                sub = "0" + to_string(i);
                break;
            default:
                sub = to_string(i);
                break;
        }

        int cur = 0;
        rep (i, N)
        {
            if (S[i] == sub[cur]) cur++;
            if (cur == 3) break;
        }
        if (cur == 3)
        {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 384
from bisect import bisect
N, M = map(int, input().split())
A = list(map(int, input().split()))
R = [0]
s = 0
for a in A:
  s = (s+a)%M
  R.append(s)
R.sort()
ans = 0
n = 1
x = R[0]
for r in R[1:]:
  if r == x:
    n += 1
  else:
    ans += n*(n-1)//2
    x = r
    n = 1
ans += n*(n-1)//2
print(ans)



Measured memory_bytes: 64792
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
using namespace std;
int main() {
	int n, k;
	cin >> n >> k;
	int d[k];
	for (int i = 0; i < k; i++) cin >> d[i];
	int res = n;
	string s = to_string(res);
	while (1){
		string s = to_string(res);
		bool flag = 0;
		for (int i = 0; i < s.size(); i++){
			for (int j = 0; j < k; j++){
				if ((int)(s[i]-'0') == d[j]){
					flag = 1;
				}
			}
		}
		if (flag) res++;
		else break;
	}

	cout << res << endl;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pi 3.1415926536
#define pb push_back
#define ff first
#define ss second
#define N 1000000007
#define INF (1ll<<60) - 1
#define M 998244353
#define rep(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)
#define nrep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll t,i,j,x,y,q,n,z,l,k,r,ans=0;
    cin>>n;
    map<string,ll> m;
    while(n--){
    	string s;
    	cin>>s;
    	m[s]++;
	}
	cout<<"AC x "<<m["AC"]<<endl;
	cout<<"WA x "<<m["WA"]<<endl;
	cout<<"TLE x "<<m["TLE"]<<endl;
	cout<<"RE x "<<m["RE"]<<endl;
}

Measured memory_bytes: 3600
/* Author	: Jehian Norman Saviero (@Reiva5) */
#include <bits/stdc++.h>

/* MACROS SAMPAH */
#define jehian using
#define mau namespace
#define libur std
#define cepet {ios_base::sync_with_stdio(0);cin.tie(NULL);}

jehian mau libur;
/* MACROS FOR TYPE */
typedef long l;
typedef long double ld;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<l> vl;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<l,l> pl;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;

/* MACROS FOR PRINT */
#define nl printf("\n");
#define sp printf(" ");

/* MACROS FOR FUNCTION */
#define pb push_back
#define mp make_pair
#define eb emplace_back

/* MACROS FOR ATTRIBUTE */
#define fi first
#define se second

int main(){
	ll x, t;
	cin >> x >> t;
	if (x >= t){
		cout << x-t << endl;
	} else {
		cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }



string a, b;
int main() {
	cin >> a >> b;
	string str = a+b;
	int val;
	istringstream sin(str);
	sin >> val;

	bool ok = false;
	for (int i = 1; i <= 1000; ++i) if (i * i == val) ok = true;

	if (ok) puts("Yes");
	else puts("No");

}










Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
 
int main() {
    int N,K;
    cin >> N >> K;
    vector<int> x(N);
    rep(i,N) cin >> x.at(i);
    int ans=0;
    rep(i,N){
        ans+=2*min(abs(x.at(i)),abs(K-x.at(i)));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import Data.List

cmp [] = []
cmp x@((w1,p1):xs) = 
  let c = takeWhile (\ (w,p) -> w == w1) x
      r = dropWhile (\ (w,p) -> w == w1) x
      p = map snd c
  in
    (w1,p):cmp r

ans i =
  let s = sortBy (\ (w1,p1) (w2,p2) -> if w1 /= w2
                                       then compare w1 w2
                                       else compare p1 p2 ) i
      c = cmp s
  in
    c

pr (w,p) = do
  putStrLn w
  putStrLn $ unwords $ map show p

main = do
  c <- getContents
  let i = map (\ (w:p:_) -> (w,read(p)) ) $ map words $ lines c :: [(String,Int)]
      o = ans i
  mapM_ pr o

Measured memory_bytes: 3876
/* To Kaise Hain Aaplog*/

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) (x).begin(), (x).end()

void shuru_krte_hai_bina_kisi_bakchodi_ke()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}

int32_t main()
{
    //shuru_krte_hai_bina_kisi_bakchodi_ke();
    string s;
    cin>>s;
    int sum = 0;
    for(int i=0;i<s.length();i++){
        sum+=(s[i]-'0');
    }
    if(sum%9==0){
        cout<<"Yes"<<"\n";
    }else{
        cout<<"No"<<"\n";
    }
    return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define pb push_back
#define nl cout<<"\n"
#define F first
#define S second
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

const ll MOD = 1e9+7;
ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

const int MAXN = 1e6+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

map<ll, ll> pr;

void factorize( ll a )
{
    ll cnt = 0;
    while( a % 2 == 0 )
    {
        cnt++;
        a /= 2;
    }
    pr[2] = max( pr[2], cnt );

    for(ll i=3;i*i<=a;i+=2)
    {
        cnt = 0;
        while( a % i == 0 )
        {
            cnt++;
            a /= i;
        }
        pr[i] = max( pr[i], cnt );
    }
    if( a != 1 )
    {
        pr[a] = max( pr[a], 1ll );
    }
}


ll expo( ll base, ll exp, ll m = MOD )
{
    ll res = 1;
    while( exp )
    {
        if( exp&1 )
            res = mod( res*base, m );
        base = mod( base*base, m );
        exp >>= 1;
    }
    return res;
}

ll modinv( ll x, ll m = MOD )
{
    return expo(x,m-2,m);
}

int main() 
{
    fastio();

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

    ll lcm = 1;
    for( auto x : pr )
    {
        lcm = mod( lcm * expo(x.F,x.S) );
    }

    ll ans = 0;
    for(int i=0;i<n;i++)
    {
        ans = mod( ans + modinv(a[i]) );
    }
    ans = mod( ans * lcm );
    cout<<ans,nl;

    return 0;
}

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

int main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(a+b > c+d){
      cout << "Left" << endl;
    }
    if(a+b < c+d){
      cout << "Right" << endl;
    }
    if(a+b == c+d){
      cout << "Balanced" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
t = [0]*n
q = []
r = 1
for i in range(n):
    q.append([])
for i in range(m):
    a,b = map(int,input().split())
    q[a-1].append(b-1)
    q[b-1].append(a-1)
num = 0
for i in range(n):
    if(t[i] == 0):
        num += 1
        cnt = 0
        stc = [i]
        while(len(stc) > cnt):
            x = stc[cnt]
            for j in range(len(q[x])):
                if(t[q[x][j]] == 0):
                    t[q[x][j]] = num
                    stc.append(q[x][j])
            cnt += 1
        r = max(cnt-1,r)
print(r)

Measured memory_bytes: 106304
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/








int N;
string S[10101];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	rep(i, 0, N) cin >> S[i];

	int ans = 0;
	int backA = 0, topB = 0, AB = 0;
	rep(i, 0, N) {
		int n = S[i].length();
		rep(j, 0, n - 1) if (S[i][j] == 'A' && S[i][j + 1] == 'B') ans++;

		if (S[i][n - 1] == 'A') {
			if (S[i][0] == 'B') {
				AB++;
			}
			else {
				backA++;
			}
		}
		else {
			if (S[i][0] == 'B') {
				topB++;
			}
			else {

			}
		}
	}

	int pair = min(backA, topB);

	if (pair == 0) {
		if (backA + topB == 0) {
			if (0 < AB) ans += AB - 1;
		}
		else {
			ans += AB;
		}
	}
	else {
		ans += pair + AB;
	}

	cout << ans << endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    string s, t;
    cin >> s >> t;

    int sl = s.length();
    int tl = t.length();
    vvint dp(sl+1, vint(tl+1, 0));

    rep(i, sl) rep(j, tl) {
        if (s[i] == t[j]) dp[i+1][j+1] = dp[i][j]+1;
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1]);
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j]);
    }

    string ans = "";
    int i = sl, j = tl;
    while (i > 0 && j > 0) {
        if (dp[i][j] == dp[i-1][j]) --i;
        else if (dp[i][j] == dp[i][j-1]) --j;
        else {
            ans = s[i-1] + ans;
            --i;
            --j;
        }
    }

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

Measured memory_bytes: 35584
#include <bits/stdc++.h>
using namespace std;
#define int long long
 
signed main() {
  int x;
  int y;
  int z;
  cin >> x;
  cin >> y;
  cin >> z;
  cout << z << " " << x << " " << y;
 
  
  }
  

  
    
  
  
 
 

  

























Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <map>
#include <utility>
#include <queue>
#define ull unsigned long long
#define ll long long
#define mod 1000000007
using namespace std;

int main()
{
    int a,b;
    cin>>a>>b;

    cout<<max(a+b, max(a*b, a-b));
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cmath>

int main()
{
	int n;
	while (true) {
		std::cin >> n;
		if (n==0) break;
		long double opt_bmi = 2000001.0;
		int opt_p = n+1;
		for (int i=0; i<n; i++) {
			int p, h, w;
			std::cin >> p >> h >> w;
			long double bmi = (long double)w * 10000.0 / (h*h);
			if ( std::abs(opt_bmi - 22.0) > std::abs(bmi - 22.0) ) {
				opt_bmi = bmi;
				opt_p = p;
			} else if ( std::abs(opt_bmi - 22.0) == std::abs(bmi - 22.0) ) {
				if (opt_p > p) opt_p = p;
			}
		}
		std::cout << opt_p << std::endl;
	}
	return 0;
}



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

int main() {
    int n;
    std::cin >> n;
    std::vector<int> a(n);
    rep(i, n) std::cin >> a.at(i);
    sort(a.begin(), a.end());
    string ans = "YES";
    rep(i, n - 1){
        if(a.at(i) == a.at(i + 1)) ans = "NO";
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define debug(x) cout << #x << " = " << x << endl
typedef unsigned long long ull;
typedef long long ll;
using namespace std;
const int N=100000;
int a[N],n,i,j,c;
void generator()
{
	sort(a+1,a+1+n);
	for(i=1;i<=n;i++)
	{
		if(a[i]==a[i+1])
		c++;
	}
	cout << n-c;
}
int main()
{
	cin >>n;
	for(i=1;i<=n;i++)
	cin >> a[i];
	generator()	;
	
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <stack>
#include <vector>

#define FOR(i,k,n) for(int (i) = (k); (i) < (n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x,y) cerr << #x << ": " << x << ", " << #y << ": " << y << endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
template<class T> using vv=vector<vector<T>>;
typedef deque<int> di;
typedef deque<deque<int>> ddi;


int main() {
    int n,w;
    cin >> n >> w;
    i_i vw[101] = {};
    int dp[10001][101] = {};
    FOR(i,1,n+1) {
        cin >> vw[i].first >> vw[i].second;
    }
    FOR(i,1,w+1) {
        FOR(j,1,n+1) {
            if(i >= vw[j].second) {
                dp[i][j] = max((vw[j].first + dp[i-vw[j].second][j]),dp[i][j-1]);
            } else {
                dp[i][j] = dp[i][j-1];
            }
        }
    }
    cout <<  dp[w][n] << endl;
	return 0;
}

Measured memory_bytes: 7048
x,y=map(int,input().split())
if x*y>0:
    if x<y:
        print(y-x)
    else:
        print(x-y+2)
elif x*y<0:
    print(abs(abs(y)-abs(x))+1)
else:
    if x>0:
        print(x+1)
    if x<0:
        print(-x)
    if y>0:
        print(y)
    if y<0:
        print(-y+1)

Measured memory_bytes: 3064
from collections import Counter, defaultdict
# 拡張ユークリッド互除法
# ax + by = gcd(a,b)の最小整数解を返す
def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, y, x = egcd(b % a, a)
        return (g, x - (b // a) * y, y)


# mを法とするaの乗法的逆元
def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m


# 素因数分解
def prime_factors(n):
    i = 2
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            yield i
    if n > 1:
        yield n

# mを法とするときのa^n
def modpow(a,n,m):
    res = 1
    t = a
    while n:
        if n%2:
            res = (res*t)%m
        t = (t*t)%m
        n //= 2
    return res

def lcm_mod(nums, mod):
    p = defaultdict(int)
    for n in nums:
        c = Counter(prime_factors(n))
        for v,cnt in c.items():
            p[v] = max(p[v],cnt)

    res = 1
    for v,cnt in p.items():
        res *= modpow(v,cnt,mod)
        res %= mod
    return res


MOD = 10**9+7

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

s = sum(modinv(a,MOD) for a in A)%MOD

s *= lcm_mod(A, MOD)
print(s%MOD)


Measured memory_bytes: 78756
#include<stdio.h>
#include<string.h>
#define ll long long
#define MOD 1000000007
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}

char s[100010];
ll a[100010],c[100010],h[100010];
int main(){
	scanf("%s",s);
	int n=strlen(s);
	for(int i=0;i<n;i++){
		a[i+1]=a[i]+(s[i]=='A');
		c[i+1]=c[i]+(s[i]=='C');
		h[i+1]=h[i]+(s[i]=='?');
	}
	int ans=0;
	for(int i=0;i<n;i++)if(s[i]=='B'||s[i]=='?'){
		int la=a[i];
		int lk=h[i];
		int rc=c[n]-c[i+1];
		int rk=h[n]-h[i+1];
		ll l=la*pom(3,lk,MOD)+lk*pom(3,lk-1,MOD);
		ll r=rc*pom(3,rk,MOD)+rk*pom(3,rk-1,MOD);
		ans=(ans+(l%MOD)*(r%MOD))%MOD;
	}
	printf("%lld",(ans+MOD)%MOD);
}

Measured memory_bytes: 2560
n,m=input().split()
n,m=int(n),int(m)
x=[0 for _ in range(n)]
for i in range(m):
    a,b=input().split()
    a,b=int(a)-1,int(b)-1
    x[a]+=1
    x[b]+=1

for i in range(n):
    print(x[i])


Measured memory_bytes: 3060
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

int main()
{
	int P, Q, R;
	cin >> P >> Q >> R;

	int a = P + Q;
	int b = P + R;
	int c = Q + R;

	cout << min({ a,b,c }) << endl;
	
}

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

int main(void) {
  string a, b;
  string s;
  cin >> a >> b >> s;
  regex re("(\\d{" + a + "}-\\d{" + b + "})");
  if (regex_match(s, re)){
    cout << "Yes" << endl;
  }else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL N;
	in >> N;
	std::vector<LL>a(N);
	rep(i, N) in >> a[i];

	LL scores[] = { 399,799,1199,1599,1999,2399,2799,3199 };
	std::vector<bool>cnt(8, false);
	LL red = 0;
	rep(i, N)
	{
		if (a[i] < 3200)
		{
			rep(j, 8)
			{
				if (a[i] <= scores[j])
				{
					cnt[j] = true;
					break;
				}
			}
		}
		else ++red;
	}

	LL ans = 0;
	rep(i, 8)
	{
		if (cnt[i]) ++ans;
	}
	if (ans > 0)  out << ans << " " << ans + red << std::endl;
	else out << 1 << " " << red << std::endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int[] a = new int[3];
      	for(int i = 0; i < 3; i++){
        	a[i] = sc.nextInt();
        }
     	Arrays.sort(a);
      	System.out.println(a[0]+a[1]+(10*a[2]));
    }
}

Measured memory_bytes: 35836
#include<bits/stdc++.h>
using namespace std;
int main(){
		long long n;
		cin>>n;
		long long a[n];
		long long sum=0;
		long long freq[100001]={0};
		for(long long  i=0;i<n;i++){
			cin>>a[i];
			sum+=a[i];
			freq[a[i]]++;
		}
		long long q;
		cin>>q;
		long long temp=sum;
		long long b,c;
		vector<long long > ans;
		while(q--){
			cin>>b>>c;
			long long pr=b*(freq[b]);
			long long nw=c*(freq[b]);
			temp=temp+(nw-pr);
			freq[c]+=freq[b];
			freq[b]=0;
			ans.push_back(temp);
		}
		for(long long  i=0;i<ans.size();i++){
			cout<<ans[i]<<endl;
		}
return 0;
}

Measured memory_bytes: 5876
/*Filename: aoj0022.cpp
 *Author: Mushiyo
 */

#include <iostream>
#include <cmath>
#include <climits>

using namespace std;

int main(){
	int n = 0;

    while(cin >> n){
    	if(n == 0){
    		break;
    	}

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

        int sum[n];
        sum[0] = a[0];
        for(int i = 1; i < n; ++i){
        	sum[i] = sum[i - 1] + a[i];
        }

        int maxSum = INT_MIN;
        int minSum = 0;
        for(int i = 0; i < n; ++i){
        	maxSum = max(maxSum, sum[i] - minSum);
        	minSum = min(minSum, sum[i]);
        }
        
        cout << maxSum << endl;
    }

	return 0;
}

Measured memory_bytes: 1184