akhauriyash/Code-Regression huggingface dataset:
def main():
    N, L, T = list(map(int, input().split(' ')))
    ants = [list(map(int, input().split(' '))) for _ in range(N)]
    # calculate number of ants by which first ant pass
    k = 0
    first_ant = ants[0]
    for a in ants[1:]:
        if first_ant[1] == a[1]:  # same direction
            continue
        if (first_ant[0] > a[0] and a[1] == 1) or (first_ant[0] < a[0] and first_ant[1] == 1):
            d = (max([first_ant[0], a[0]]) - min([first_ant[0], a[0]]))
        else:
            d = (L - max([first_ant[0], a[0]]) + min([first_ant[0], a[0]]))
        k += max([(2 * T - d) // L + 1, 0])
    k %= N
    # ants final locations
    ants_final_loc = [(a[0] + T * (1 if a[1] == 1 else -1)) % L for a in ants]
    first_ant_final_loc = ants_final_loc[0]
    first_ant_final_num = k if first_ant[1] == 1 else (- k) % N
    ants_final_loc.sort()
    # answer
    offsets = [i for i in range(N) if ants_final_loc[i] == first_ant_final_loc]
    offset = offsets[0]
    if len(offsets) > 1 and first_ant[1] == 1:
        offset = offsets[1]
    ants_loc = [ants_final_loc[(i + offset - first_ant_final_num) % N] for i in range(N)]
    for loc in ants_loc:
        print(loc)


if __name__ == '__main__':
    main()

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

int a[200009];
int main()
{
    int n,k,x;
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        a[x]++;
    }
    sort(a,a+n+1);
    int j=0,ans=0;
    for(int i=n;i>=0;i--)
    {
        if(j>=k)
        {
            ans+=a[i];
        }
        j++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
object Main {
  def main(args: Array[String]): Unit = {
    val lines = io.Source.stdin.getLines().toSeq
    println(solve(lines))
  }

  def solve(lines: Seq[String]): String = {
    val n = lines.head.toInt
    val values = lines(1).split(" ").take(n).map(_.toInt)
    val costs = lines(2).split(" ").take(n).map(_.toInt)

    var totalValue = 0
    for (i <- values.indices) {
      if (values(i) - costs(i) > 0) totalValue += values(i) - costs(i)
    }
    totalValue.toString
  }
}


Measured memory_bytes: 25520
#include <bits/stdc++.h>
 
using namespace std;
  
int main() {
  int a, b, c;
  scanf("%d %d", &a, &b);
  c = a + b;
  
  if ((a % 3) * (b % 3) * (c % 3) == 0){
  	cout << "Possible" << endl;
  } else {
  	cout << "Impossible" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

use std::cmp::{max, min};

fn main() {
  let n = read::<i64>();
  let mut ans = 0;

  for i in 1..n + 1 {
    if i.to_string().len() % 2 == 1 {
      ans += 1;
    }
  }

  println!("{}", ans)
}



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

using ll=long long;
int main(){
    ll n;
    cin>>n;
    ll a,d;
    cin>>a>>d;
    int m;
    cin>>m;
    map<ll,ll> mp;
    auto setValue=[&](ll pos){
        if(mp.count(pos)) return;
        mp[pos]=a+(pos-1)*d;
    };
    while(m--){
        ll x,y,z;
        cin>>x>>y>>z;
        setValue(y);
        setValue(z);
        if(x==0) swap(mp[y],mp[z]);
        else mp[y]=mp[z];
    }
    ll k;
    cin>>k;
    setValue(k);
    cout<<mp[k]<<endl;
    return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
int main () {
	string N;
	cin >> N;
	int num = atoi(N.c_str());
	int sum = 0;
	for (int i = 0;i < (int)N.size(); ++i)
	{
		sum += (int)(N[i] - '0');
	}
	if(num % sum == 0){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
import numpy as np
s = int(input())

ans = np.zeros(1000000)
a = s
ans[a] += 1
for i in range(1,1000000):
  if a % 2 == 0:
    a =  a//2
    ans[a] += 1
  else:
    a = 3*a+1
    ans[a] += 1
  if ans[a] == 2:
    print(i+1)
    break

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

int main () {
  int A , B ; 
  cin >> A >> B ;
  
  if (A - 2*B <= 0){
    cout << 0 << endl ; 
  }
  
  else {
    cout << A - 2*B << endl ; 
  }
  
  
  
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
#define lowbit(i) ((i)&-(i)) 
 
using namespace std;
 
typedef long long ll;
 
int n;
ll b1[100100],b2[100100];
 
void add(ll *bit,int i,ll x)
{
    while(i<=n)
    {
        bit[i]+=x;
        i+=lowbit(i);
    }
}
 
ll sum(ll *bit,int x)
{
    ll s=0;
    while(x>0)
    {
        s+=bit[x];
        x-=lowbit(x);
    }
    return s;
}
 
void add(ll x,ll y,ll s)
{
    add(b1,x,s);add(b1,y+1,-s);
    add(b2,x,x*s);add(b2,y+1,-(y+1)*s);
}
 
ll sum(ll x)
{
    return (x+1)*sum(b1,x+1)-sum(b2,x+1);
}
 
int main()
{
    //freopen("in.txt","r",stdin);freopen("out.txt","w",stdout); 
    int q;
    scanf("%d%d",&n,&q);
    n+=10;
    memset(b1,0,sizeof(b1));
    memset(b2,0,sizeof(b2));
    for(int i=0;i<q;i++)
    {
        int com;
        scanf("%d",&com);
        if(com==0)
        {
            ll x,y,s;
            scanf("%lld%lld%lld",&x,&y,&s);
            add(x,y,s);
        }
        else
        {
            ll x,y;
            scanf("%lld%lld",&x,&y);
            printf("%lld\n",sum(y)-sum(x-1));
        }
    }
    return 0;
}


Measured memory_bytes: 4780
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N, T;
	cin >> N >> T;

	vector<vector<Int>> ab(N, vector<Int>(2));
	for (Int i = 0; i < N; i++) {
		cin >> ab[i][0] >> ab[i][1];
	}
	sort(ab.begin(), ab.end());

	vector<vector<Int>> dp(N+1, vector<Int>(T));//dp[i+1][j]: i番目までの料理の中で時間j以内となる最大うまさ

	Int ans = 0;
	for (Int i = 0; i < N; i++) {
		for (Int j = 0; j < T; j++) {

			//i番目の料理を食べる場合
			if (j + ab[i][0] < T) {
				dp[i + 1][j + ab[i][0]] = max(dp[i][j] + ab[i][1], dp[i + 1][j + ab[i][0]]);
			}

			//i番目の料理を食べない場合
			dp[i + 1][j] = max(dp[i][j], dp[i + 1][j]);
		}
	}

	for (Int i = 0; i < N; i++) {
		ans = max(ans, dp[i][T-1] + ab[i][1]);
	}

	cout << ans << "\n";
}


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

const double pi = 3.14159265358979323846;
const ll mod = 1000000007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int k; cin >> k;
	int a = (k+1)/2;
	int b = k/2;
	cout << a * b << endl;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1e9+7;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

template<class T> inline bool chmin(T &a,T b){
    if (a>b){
        a=b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T &a,T b){
    if (a<b){
        a=b;
        return true;
    }
    return false;
}

int main(){
    int N,A,B;
    cin >> N >> A >> B;
    if (A+B-1>N){
        cout << -1 << endl;
        return 0;
    }
    if (A==1){
        if (B!=N){
            cout << -1 << endl;
            return 0;
        }
        for (int i=N;i>0;--i) cout << i << ' ';
        cout << endl;
        return 0;
    }
    if (B==1){
        if (A!=N){
            cout << -1 << endl;
            return 0;
        }
        for (int i=1;i<=N;++i) cout << i << ' ';
        cout << endl;
        return 0;
    }
    if ((N+A-1)/A<=B){
        int x=(N-B)/(A-1),y=(N-B)%(A-1)+1,now=N-A+1;
        rep(i,x){
            rep(j,A){
                cout << now+j << ' ';
            }
            if (i!=x-1) now-=A;
            else now-=y;
        }
        if (now<=0) return 0;
        rep(i,y) cout << now+i << ' ';
        --now;
        while(now>0){
            cout << now << ' ';
            --now;
        }
        cout << endl;
        return 0;
    }
    if ((N+B-1)/B<=A){
        int x=(N-A)/(B-1),y=(N-A)%(B-1)+1,now=B;
        rep(i,x){
            rep(j,B){
                cout << now-j << ' ';
            }
            if (i!=x-1) now+=B;
            else now+=y;
        }
        if (now>=N+1) return 0;
        rep(i,y) cout << now-i << ' ';
        ++now;
        while(now<=N){
            cout << now << ' ';
            ++now;
        }
        cout << endl;
    }
    else cout << -1 << endl;
}

Measured memory_bytes: 2176
/*
lakshaygpt28
Lakshay Gupta
*/

#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;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
using vll = vector < ll >;

template < typename T > using OrderedSet = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;


#ifndef ONLINE_JUDGE
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
    cerr << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define debug(...)
#endif

#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

const db PI = acos(-1);
const ll LINF = LLONG_MAX;
const int INF = INT_MAX, MOD = 1e9 + 7, N = 1e5 + 10;

ll a[N], b[N];

int main() {
    fast_io();
    ll n;
    cin >> n;
    for (ll i = 1; i <= n; i++) {
        cin >> a[i];
        b[i] = a[i];
    }
    sort(b + 1, b + n + 1);
    ll cnt = 0;
    for (ll i = 1; i <= n; i++) {
        if (a[i] != b[i]) {
            cnt++;
        }
    }
    if (cnt == 0 or cnt == 2) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }
    return 0;
}


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

int main()
{
    
    int N,X;
    cin >> N >> X;
    vector<int> L(N+1);
    L.push_back(0);
    for (int i = 1; i <= N; i++) {
        cin >> L[i];
    }
    
    int ans = 0;
    int sum = 0;
    for (int i = 0; i < N+1; i++) {
        sum = sum + L[i];
        if (sum > X) {
            break;
        }
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
use std::io;
use std::io::Read;

fn main() {
    let mut stdin = io::stdin();
    let mut lines = String::new();
    let _ = stdin.read_to_string(&mut lines);
    let vec = lines.lines().collect::<Vec<&str>>();
    let vec2 = vec[0].split(' ').collect::<Vec<&str>>();
    let n :usize = vec2[0].trim().parse().unwrap();
    let m :usize = vec2[1].trim().parse().unwrap();
    let mut xy :Vec<(usize,usize)> = Vec::new();
    for i in 0..m {
        let vec3 = vec[i+1].split(' ').collect::<Vec<&str>>();
        xy.push((vec3[0].trim().parse::<usize>().unwrap() - 1,
        vec3[1].trim().parse::<usize>().unwrap() - 1));
    }
    let xy = xy;

    let mut is_red = vec![false;n];
    is_red[0] = true;
    let mut ball_num = vec![1;n];
    for (x, y) in xy {
        if is_red[x] {
            is_red[y] = true;
        }
        ball_num[x] -= 1;
        ball_num[y] += 1;
        if ball_num[x] == 0 {
            is_red[x] = false;
        }
    }
    let mut red_ball_num = 0;
    for i in 0..n {
        if is_red[i] {
            red_ball_num += 1;
        }
    }
    println!("{}", red_ball_num);
}


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

int main(void)
{
	int n;
	cin >> n;
	vector<int> a(n), b;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for(int i = 0; i < n; i++) {
		int t = 0;
		while(t < i && b[t] < a[i]) t++;
		// cout << t << "  ";
		b.push_back(a[i]);
		rotate(b.begin() + t, b.end() - 1, b.end());
		for(int j = 0; j <= i; j++) {
			cout << b[j] << (j == n - 1 ? "\n" : " ");
		}
		for(int j = i + 1; j < n; j++) {
			cout << a[j] << (j == n - 1 ? "\n" : " ");
		}
	}
	return 0;
}


Measured memory_bytes: 3164
def gcd(a, b):
    while b!=0:
        a, b = b, a % b
    return a

k = int(input())
ans = []
tmp = [gcd(i+1, j+1) for i in range(k) for j in range(k)]
print(sum([gcd(tmp[i], j+1) for i in range(len(tmp)) for j in range(k)]))

Measured memory_bytes: 71744
#include <stdio.h>
int main(void){
    int a,b,c,d;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    if(a*b<c*d){
        printf("%d",c*d);
    }
    else{
        printf("%d",a*b);
    };
    return 0;
};


Measured memory_bytes: 128
import java.util.Scanner;

// ABC171-A
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String input = sc.next();
		char alphabet = input.charAt(0);

		if (Character.isUpperCase(alphabet)) {
			System.out.println('A');
		} else {
			System.out.println('a');
		}

		sc.close();
	}
}


Measured memory_bytes: 35588
n = int(input())
p = list(map(int,input().split()))
count = 0
flag = True
max_l = p[0]
min_l = p[0]
for i in range(n):
    key = p[i]
    if min_l > key:
        count += 1
        min_l = key
print(count+1)


Measured memory_bytes: 24744
<?php
list($H, $N) = ints();
$dp = array_fill(0, $N + 1, array_fill(0, $H + 1, 10**18));
$dp[0][0] = 0;
for($i = 1; $i <= $N; $i++){
  $dp[$i] = $dp[$i-1];
  list($a, $b) = ints();
  for($j = 1; $j <= $H; $j++){
    if($j - $a >= 0){
      $dp[$i][$j] = min($dp[$i][$j], $dp[$i][$j-$a]+$b);
    }else{
      $dp[$i][$j] = min($dp[$i][$j], $b);
    }
  }
}
//o($dp);
echo $dp[$N][$H];
function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}
function chmin(&$a,$b){if($a>$b){$a=$b;return 1;}return 0;}

function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array: ";
            echo implode(" ", addIndex($val))."\n";
        }else{
            echo "array:array\n";
            if(isCleanArray($val)){
                foreach($val as $row)echo implode(" ", addIndex($row))."\n";
            }else{
                foreach($val as $i => $row)echo "[".$i."] ".implode(" ", addIndex($row))."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}
function addIndex($val){
    if(!isCleanArray($val)){
        $val = array_map(function($k, $v){return $k.":".$v;}, array_keys($val), $val);
    }
    return $val;
}
function isCleanArray($array){
    $clean = true;
    $i = 0;
    foreach($array as $k => $v){
        if($k != $i++)$clean = false;
    }
    return $clean;
}

Measured memory_bytes: 686712
def main():
    n=int(input())
    num=[i*(i+1)//2 for i in range(4473)]
    ans=[]
    while n>0:
        for i in range(1,4473):
            if num[i]>=n:
                ans.append(i)
                n-=i
                break
    for i in range(len(ans)):
        print(ans[len(ans)-1-i])
if __name__=="__main__":
    main()

Measured memory_bytes: 3708
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*
cout<<fixed<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=998244353;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	int n,m,x,y;cin>>n>>m>>x>>y;
	while(n--){int a;cin>>a;maxeq(x,a);}
	while(m--){int a;cin>>a;mineq(y,a);}
	cout<<(x<y?"No War":"War")<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,a,b) for(int i=a ; i<b ; i++)
const int max_n = 2000;
const ll mod = 1e9+7;
const int INF = 1e5;
typedef long double ld;
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; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
struct edge{
  ll to,cost;
};
vector<edge> G[max_n];
map<ll,ll> ma;
ll d[max_n][max_n];
int main(){
  int n,x,y; cin >> n >> x >>y;
  --x;  --y;
  int ans[2010]={0};
  rep(i,0,n)rep(j,i+1,n){
    int k = min(j-i, abs(x-i)+1+abs(y-j));
    ans[k]++;
  }
  rep(i,1,n){
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N = I()
A = []
for _ in range(N):
    A.append(III())

S = []
for i in range(N):
    j = A[i][0]-1
    if i==A[j][0]-1:
        if i<j:
            S.append((i,j))

c = [0]*N
ans = 0
while S:
    q = []
    for i,j in S:
        c[i] += 1
        c[j] += 1
        if c[i] <= N-2:
            x = A[i][c[i]]-1
            if A[x][c[x]]-1==i:
                q.append((min(i,x), max(i,x)))
        if c[j] <= N-2:
            y = A[j][c[j]]-1
            if A[y][c[y]]-1==j:
                q.append((min(j,y), max(j,y)))
    S = q
    ans += 1

for i in range(N):
    if c[i] != N-1:
        print(-1)
        exit()

print(ans)

Measured memory_bytes: 56412
function abs(x) {
  return Math.abs(x)
}
// inputに入力データ全体が入る
function Main(input) {
  inputs = input.split(/\n/);
  var n = inputs[0]
  var line2 = inputs[1].split(/\s/)
  var t = parseInt(line2[0], 10)
  var a = parseInt(line2[1], 10)
  var line3 = inputs[2].split(/\s/)
  var hs = line3.map(x => parseInt(x, 10))

  // console.log(n)
  // console.log(t)
  // console.log(a)
  // console.log(hs)

  var min = null
  var minIdx = -1
  for (var i = 0, len = hs.length; i < len; i++) {
    var tx = t - hs[i] * 0.006
    var tm = null
    if (a > 0 && tx > 0) {
      tm = abs(a-tx)
    } else if (a > 0 && tx <= 0) {
      tm = abs(a-tx)
    } else if (a <= 0 && tx > 0) {
      tm = abs(tx-a)
    } else if (a <= 0 && tx <= 0) {
      tm = abs(abs(tx) - abs(a))
    }

    if (min == null) {
      min = tm
      minIdx = i
    } else {
      if (min > tm) {
        min = tm
        minIdx = i
      }
    }
  }
  console.log(minIdx+1)
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 8008
#include<bits/stdc++.h>
using namespace std;
int main()
{
      int n,m,s;
      scanf("%d%d",&n,&m);
      s=n+m;
      if((n-m)>s) s=n-m;
      if((n*m)>s) s=n*m;
      printf("%d",s);
      return 0;
}


Measured memory_bytes: 256
s = input()[::-1]

while True:
    if len(s) == 0:
        break
    if s[:7] == "remaerd":
        s = s[7:]
    elif s[:6] == "resare":
        s = s[6:]
    elif s[:5] == "maerd" or s[:5] == "esare":
        s = s[5:]
    else:
        print("NO")
        exit()

print("YES")

Measured memory_bytes: 9264
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>    // PBDS
#include <ext/pb_ds/tree_policy.hpp>        // PBDS

using namespace std;
using namespace __gnu_pbds;                 // PBDS

/* typedef starts */

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> PBDS_INT;               // PBDS for int
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> PBDS_LL;    // PBDS for long long

/* typedef ends */

/* macro starts */

#define PI acos(-1)
#define EPS 1e-9
#define fastIO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define sinD(degree) sin((degree * PI) / 180.0)
#define cosD(degree) cos((degree * PI) / 180.0)
#define tanD(degree) tan((degree * PI) / 180.0)
#define cotD(degree) (1.0 / tanD(degree))
#define secD(degree) (1.0 / cosD(degree))
#define cosecD(degree) (1.0 / sinD(degree))
#define asinD(value) (asin(value) * 180.0) / PI
#define acosD(value) (acos(value) * 180.0) / PI
#define atanD(value) (atan(value) * 180.0) / PI
#define forn(i,n) for(int i=0;i<n;i++)
#define min(a,b) a<b ? a:b
#define max(a,b) a>b ? a:b
#define value_at_index(x) find_by_order(x)
#define index_of(x) order_of_key(x)
#define pb push_back
#define set0(add) memset(add,0,sizeof(add));

/* macro ends */

/* function starts */

/// calculates n-th (0-based) Gray Code
template<typename dataType>
dataType nthGrayCode(dataType n)
{
    return (n ^ (n >> 1));
}

/// generates all possible subsets for the given set
template<typename dataType>
void generateAllSubset(vector<dataType> &data)
{
    int i, j, n;
    n = data.size();

    for (i = 0; i < (1 << n); i++) {
        for (j = 0; j < n; j++) {
            if (i & (1 << j)) {
                cout << data[j] << " ";
            }
        }
        cout << "\n";
    }
}


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

int fact(int n){
	if(n<=1)
		return 1;
	else 
	return n*fact(n-1);
}

bool compare(const pair<int,int> &a,const pair<int,int> &b){
	return (a.second<b.second);
}



int main()
{
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif

    fastIO;
    int a;
    cin >> a;
    int diff=ceil((double)a/1000);
    cout << (diff*1000)-a;

    
   return 0;
   
   
   	}
    


Measured memory_bytes: 3648
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type splitter int

const (
	bySpace splitter = iota
	byLine
)

func newScanner(sp splitter) *sc {
	scanner := bufio.NewScanner(os.Stdin)
	if sp == bySpace {
		scanner.Split(bufio.ScanWords)
	}
	return &sc{
		s: scanner,
	}
}

type sc struct {
	s *bufio.Scanner
}

func (s *sc) nextInt() int {
	if s.s.Scan() {
		val := s.s.Text()
		v, err := strconv.Atoi(val)
		if err != nil {
			panic(err)
		}
		return v
	}
	panic("no more stdin")
}

var clusters = []*cluster{}

type cluster struct {
	nodes []*node
}

type node struct {
	cls *cluster
}

func create(n1, n2 *node) {
	c := &cluster{
		nodes: []*node{
			n1, n2,
		},
	}
	n1.cls = c
	n2.cls = c
	clusters = append(clusters, c)
}

func add(c *cluster, n *node) {
	n.cls = c
	c.nodes = append(c.nodes, n)
}

func merge(c1, c2 *cluster) {
	var parent, child *cluster
	if len(c1.nodes) > len(c2.nodes) {
		parent = c1
		child = c2
	} else {
		parent = c2
		child = c1
	}
	for _, n := range child.nodes {
		n.cls = parent
	}
	parent.nodes = append(parent.nodes, child.nodes...)
	child.nodes = []*node{}
}

func main() {
	scanner := newScanner(bySpace)
	n := scanner.nextInt()
	m := scanner.nextInt()
	arr := make([]*node, n)
	for i := 0; i < n; i++ {
		arr[i] = new(node)
	}
	for i := 0; i < m; i++ {
		a := scanner.nextInt() - 1
		b := scanner.nextInt() - 1
		if arr[a].cls == nil && arr[b].cls == nil {
			create(arr[a], arr[b])
			continue
		}
		if arr[a].cls == nil && arr[b].cls != nil {
			add(arr[b].cls, arr[a])
			continue
		}
		if arr[b].cls == nil && arr[a].cls != nil {
			add(arr[a].cls, arr[b])
			continue
		}
		if arr[a].cls == arr[b].cls {
			continue
		}
		merge(arr[a].cls, arr[b].cls)
	}

	max := 1
	for _, v := range clusters{
		if len(v.nodes) > max {
			max = len(v.nodes)
		}
	}
	fmt.Println(max)
}


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


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

	int h = S/3600;
	int m = S%3600/60;
	int s = S % 3600 % 60;
	printf("%d:%d:%d\n",h,m,s);
}


Measured memory_bytes: 3216
N=int(input())
xy=[list(map(int,input().split())) for _ in [0]*N]

pq = {0:0}
for i in range(N):
    for j in range(N):
        if i==j:continue
        p = xy[i][0] - xy[j][0]
        q = xy[i][1] - xy[j][1]
        pq[(p,q)] = pq.get((p,q),0)+1

print(N - max(pq.values()))

Measured memory_bytes: 3444
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#include <numeric>
#define IINF 1000000000
#define INF 9223372036854775807
#define MOD 998244353
#define mod 998244353
#define INT_MAX_ 2147483647
#define EPS (1e-10)
#define REP(i, a, n) fo-r (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
#define me memset
#define bit(n,k) ((n>>k)&1)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<ll,ll> a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi>b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_t=clock();
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //------------------------------
    ll n;cin>>n;
    ll cnt=26;
    ll len=1;
    while(n>cnt){
        n-=cnt;
        cnt*=26;
        len++;
    }
    //cout<<len<<endl;
    string ans;
    for(ll i=0;i<len;i++)ans+='a';
    cnt/=26;
    for(ll i=0;i<len;i++){
        char now='a';
        while(n>cnt){
            n-=cnt;
            ans[i]=++now;
        }
        cnt/=26;
    }
    cout<<ans<<endl;
    //------------------------------
    //fclose(stdin);
    //fclose(stdout);
    //ll end_t=clock();cout<<"time="<<end_t-begin_t<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------






























Measured memory_bytes: 3648
#include <iostream>

using namespace std;

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

	for (int i = 1; i < 1300; i++) {
		if ((int)(i * 0.08) == a && (int)(i * 0.1) == b) {
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;

	return 0;
}

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

#define int long long

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


signed main(void) {
  int num; // num
  num = 0; // count, result
  // num = numeric_limits<int>::min(); // max
  // num = numeric_limits<int>::max(); // min
  int N;
  // int M;
  // array<int, 100000> A;;
  // string S;
  // string T;

  cin >> N;

  for (int i = 1; i <= 9; ++i) {
    if (N <= i * 111) {
      num = i * 111;
      break;
    }
  }

  cout << num << endl;
  
  return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
vector<ll> fac, inv_fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; inv_fac.resize(x); rep(i,x) inv_fac[i] = inv(fac[i]); }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

ll pnk(ll n, ll k) {
  ll result = 1, pn = n, now = 0;
  while(k>=1<<now) {
    if (k&1<<now) result = result * pn % MOD;
    pn = pn * pn % MOD;
    now++;
  }
  return result;
}

int main() {
  ll N, A, B, C, D; cin >> N >> A >> B >> C >> D;
  ll dp[B+1][N+1] = {}; dp[A-1][N] = 1;

  c_fac();
  repr(i,A,B+1) rep(j,N+1) {
    dp[i][j] = (dp[i][j] + dp[i-1][j]) % MOD;
    ll con;
    for (ll k=C; j>=i*k&&k<=D; k++) {
      if (k==C) con = fac[j] * inv(pnk(fac[i],k)) % MOD * inv_fac[j-i*k] % MOD * inv_fac[k] % MOD;
      else con = con * nck(j-i*(k-1),i) % MOD * inv(k) % MOD;
      dp[i][j-i*k] = (dp[i][j-i*k] + dp[i-1][j]*con) % MOD;
    }
  }
  // rep(i,B+1) debug(dp[i],dp[i]+(N+1));

  ll result = dp[B][0];
  cout << result << endl;
  return 0;
}

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

using namespace std;

typedef long long ll;
#define int ll
typedef long double ld;

typedef pair<int,int> pii;
#define x first
#define y second

const int N=4010;

bool TRUE=true;

#define can(xy) \
bool _can##xy[2*N+1]; \
bool& can##xy(int dist) \
{ \
    if(dist<-N||dist>N) \
        return TRUE; \
    return _can##xy[dist+N]; \
}

can(ab)
can(ac)
can(bc)

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

    string a,b,c;
    cin>>a>>b>>c;
    #define x a
    #define y b
    #define canxy canab
    for(int dist=-N;dist<=N;dist++)
    {
        bool ok=true;
        for(int i=0;i<x.size();i++)
        {
            int j=i-dist;
            if(j>=0&&j<y.size()&&x[i]!='?'&&y[j]!='?'&&x[i]!=y[j])
                ok=false;
        }
        canxy(dist)=ok;
    }
    #define x a
    #define y c
    #define canxy canac
    for(int dist=-N;dist<=N;dist++)
    {
        bool ok=true;
        for(int i=0;i<x.size();i++)
        {
            int j=i-dist;
            if(j>=0&&j<y.size()&&x[i]!='?'&&y[j]!='?'&&x[i]!=y[j])
                ok=false;
        }
        canxy(dist)=ok;
    }
    #define x b
    #define y c
    #define canxy canbc
    for(int dist=-N;dist<=N;dist++)
    {
        bool ok=true;
        for(int i=0;i<x.size();i++)
        {
            int j=i-dist;
            if(j>=0&&j<y.size()&&x[i]!='?'&&y[j]!='?'&&x[i]!=y[j])
                ok=false;
        }
        canxy(dist)=ok;
    }
    #undef x
    #undef y
    #undef xy
//    cout<<canab(4)<<canac(2)<<canbc(-2)<<"\n";
    int ans=1e9;
    for(int ab=-N;ab<=N;ab++)
        for(int bc=-N;bc<=N;bc++)
        {
            int ac=ab+bc;
            if(canab(ab)&&canbc(bc)&&canac(ac))
            {
                int l=min<int>({0,ab,ac});
                int r=max<int>({0+a.size(),ab+b.size(),ac+c.size()});
//                if(r-l<=8||ab==4&&bc==-2)
//                    cout<<ab<<" "<<bc<<" -> "<<l<<" "<<r<<"\n";
                ans=min(ans,r-l);
            }
        }
    cout<<ans;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#define int long long
using namespace std;

int a[100000];
int rui[100000];
signed main() {
	int b; scanf("%lld", &b);
	for (int c = 0; c < b; c++) {
		scanf("%lld", &a[c]);
	}
	sort(a, a + b);
	rui[0] = a[0];
	for (int c = 0; c < b; c++) {
		rui[c] = rui[c-1] + a[c];
	}
	for (int i = b - 2; i >= 0; i--) {
		if (rui[i] * 2 < a[i + 1]) {
			cout << b - i-1 << endl;
			return 0;
		}
	}
	cout << b << endl;
}

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

int main(){
	bool card[10]; 
	int my1, my2, cpu1, safe;
	while (cin >> my1 >> my2 >> cpu1) {
		safe = 0;
		for (int i = 1; i <= 10; i++) {
			if (i != my1 && i != my2 && i != cpu1 && my1+my2+i <= 20){
				safe++;
			}
		}
		if ((double)safe/7.0 >= 0.5) {
			cout << "YES" << endl;
		}else {
			cout << "NO" << endl;
		}
	}
	return 0;
}

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

vector<pair<int,int>> tasks;

int main(void){
    int n;
    cin >> n;
    rep(i,n){
        int a,b;
        cin >> a >> b;
        tasks.emplace_back(b,a);
    }
    sort(tasks.begin(), tasks.end());
    int sum = 0;
    bool check=true;
    for(auto& v:tasks){
        sum += v.second;
        if(sum>v.first){
            check = false;
            break;
        }
    }
    cout << (check ? "Yes" : "No") << endl;
    
    
    
    
    
    return 0;
}





















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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

ll dp[105][4][4][4];

void Main() {
    int N;
    cin >> N;
    dp[0][3][3][3] = 1;
    rep(i, N) {
        rep(j, 4) {
            rep(k, 4) {
                rep(m, 4) {
                    rep(l, 4) {
                        if (l == 2 && j == 1 && k == 0) continue;
                        if (l == 2 && j == 0 && k == 1) continue;
                        if (l == 1 && j == 2 && k == 0) continue;
                        if (l == 2 && j == 1 && m == 0) continue;
                        if (l == 2 && k == 1 && m == 0) continue;
                        dp[i + 1][l][j][k] += dp[i][j][k][m];
                        dp[i + 1][l][j][k] %= MOD;
                    }
                }
            }
        }
    }
    ll ans = 0;
    rep(i, 4) {
        rep(j, 4) {
            rep(k, 4) {
                ans += dp[N][i][j][k];
                ans %= MOD;
            }
        }
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


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

a = sorted(a)

ans = 0

for i in range(n):
	if x >= a[i]:
		ans = ans + 1
		x = x - a[i]
	else:
		pass
	
if ans == n and x != 0:
	ans = ans - 1	
	
print(ans)


Measured memory_bytes: 3060
#import numpy as np
#import math
#from decimal import *
#from numba import njit

#@njit
def main():
    K = int(input())

    rest = [False]*K
    a = 7
    count = 1
    while a < K:
        a = 10*a+7
        count += 1
    r = a % K
    while r != 0:
        if rest[r-1]:
            print(-1)
            return
        else:
            rest[r-1] = True
            a = 10*r+7
            count += 1
            r = a % K
    print(count)
    
main()


Measured memory_bytes: 16704
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)

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

#define int long long

using namespace std;

signed main()
{
    int x,y,z,w,i,j=1;
    cin>>x;
    std::vector<int> v(x);
    rep(i,x){
          cin >> v[i];
    }
    z=v[0];
    repone(i,x){

      if(v[i]>=z){
    j++;
    z=v[i];
      }
    }


    cout<<j<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int MAXN = 55555;
vector<bool> prime(MAXN+1); 

int init()
{
    for(int i = 2; i <= MAXN; i++)
    {
        if(prime[i])
        {
            int j = i + i;
            while(j <= MAXN)
            {
                prime[j] = false;
                j += i;
            }
        }
    }
}
int main()
{
    int n;
    cin >> n;
    for(int i = 0; i <= MAXN; i++)
    {
        prime[i] = true;
    }
    init();
    int count = 0;
    for(int i = 2; i <= MAXN; i++)
    {
        if(prime[i] && i % 5 == 1)
        {
            count++;
            cout << i;
            if(count == n)
            {
                cout << endl;
                break;
            }
            cout << " ";
        }
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include<queue>
#include<limits.h>
#include<string.h>
#include<functional>
using namespace std;

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

Measured memory_bytes: 3064
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
using namespace std;
//typedef pair<int,int> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[10000001];
//char str[1010][1010];
//vector<pair<int,int> > pc[100001];
//int ABS(int a){return max(a,-a);}
int main(){
	int n,m;
	cin>>n>>m;
	long long a[n+1],b[n+1];
	long long c[m+1],d[m+1];
	for(int i=0;i<n;i++)cin>>a[i]>>b[i];
	for(int i=0;i<m;i++)cin>>c[i]>>d[i];
	for(int i=0;i<n;i++){
		long long min=10000000000;
		int ans=0;
		for(int j=0;j<m;j++){
			long long tmp;
			tmp=abs(a[i]-c[j])+abs(b[i]-d[j]);
			if(tmp<min) {
              min=tmp; 
              ans=j+1;
            }
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <map>
#include <vector>
#include <string>
#include <vector>
#include <cassert>
#include <cmath>
#include <stack>
#include <list>
#include <cctype>
#include <queue>
#include <algorithm>
#include <memory>
#include <memory.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int INF = 1 << 30;
const double EPS = 1e-10;
const double PI = 3.14159;

int p[200];
int s[200];
list<P> cakes;

int main(){
	int n, w, d;
	while(cin >> n >> w >> d && (n || w || d)){
		cakes.clear();
		cakes.push_back(P(w, d));
		for(int i = 0; i < n;i++){
			list<P>::iterator iter = cakes.begin();
			cin >> p[i] >> s[i];
			for(int j = 1; j < p[i]; j++) iter++;
			P p = *iter;
			cakes.erase(iter);
			int w1 = p.first;
			int d1 = p.second;
			s[i] = s[i] % (w1 + d1);
			if(s[i] > w1){
				s[i] -= w1;
				P p1 = P(w1, s[i]);
				P p2 = P(w1, d1 - s[i]);
				if(s[i] < d1 - s[i]){
					cakes.push_back(p1);
					cakes.push_back(p2);
				}else{
					cakes.push_back(p2);
					cakes.push_back(p1);
				}
			}else{
				P p1 = P(s[i], d1);
				P p2 = P(w1 - s[i], d1);
				if(s[i] < w1 - s[i]){
					cakes.push_back(p1);
					cakes.push_back(p2);
				}else{
					cakes.push_back(p2);
					cakes.push_back(p1);
				}
			}
		}
		vector<int> res;
		for(list<P>::iterator iter = cakes.begin(); iter != cakes.end(); iter++) res.push_back(iter->first * iter->second);
		sort(res.begin(), res.end());
		for(int i = 0; i < (int)res.size(); i++){
			if(i!=0) cout << " ";
			cout << res[i];
		}
		cout << endl;
	}
	return 0;
}

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

using namespace std;

typedef long long int lli;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pair<int, int>> vii;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(int i=a;i<b;i++)

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int d[1000005]={};

int main() {
//	#ifndef ONLINE_JUDGE
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
//	#endif
	
	FASTIO

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

	while(T--) {
		int n,count=0;
		cin >> n;

		int a[n];
		REP(i,0,n) {
			cin >> a[i];
		}

		sort(a,a+n);

		REP(i,0,n) {
			int t=a[i];

			if(d[t]==0) 
				d[t]=1;
			else if(d[t]==1) 
				d[t]=-1;

			if(d[t]==-1) 
				continue;

			t+=a[i];
			while(t<=a[n-1]) {
				d[t]=-1;
				t+=a[i];
			}
		}

		REP(i,0,n) {
			if(d[a[i]]==1) {
				count++;
			}
		}

		cout << count;
	}

	return 0;
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	std::string s[3];
	for (auto &i : s) std::cin >> i;
	std::sort(s, s + 3);
	int res = 1000000000;
	do {
		int n[3];
		for (int i = 0; i < 3; i++) n[i] = s[i].size();
		std::vector<int> slide[3];
		int head = 0;
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < i; j++) {
				int max = (i == 2 && j == 0) ? 4000 : 2000;
				for (int k = 0; k <= max; k++) {
					bool ok = true;
					for (int l = k; l < n[j]; l++) {
						if (l - k < n[i] && s[i][l - k] != '?' && s[j][l] != '?' && s[i][l - k] != s[j][l]) ok = false;
					}
					if (ok) slide[head].push_back(k);
				}
				head++;
			}
		}
		std::vector<bool> ok(4001);
		for (auto i : slide[1]) ok[i] = true;
		for (auto i : slide[0]) {
			for (auto j : slide[2]) {
				if (ok[i + j]) res = std::min(res, std::max({n[0], n[1] + i, n[2] + i + j}));
			}
		}
	} while (std::next_permutation(s, s + 3));
	printf("%d\n", res);
	return 0;
}




Measured memory_bytes: 256
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    a, b = input().split()
    a = int(a)
    b = int((float(b) + 0.005) * 100)

    ans = (a * b) // 100

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10784
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;

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

    string t, u;
    int p = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == '(') p++; else p--;
        if (p < 0) {
            t += '(';
            p++;
        }
    }
    if (p > 0) {
        for (int i = 0; i < p; i++) {
            u += ')';
        }
    }

    cout << t + s + u << endl;

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
using namespace std;
int main(void)
{
	ll n, w1, j;
	cin>>n>>w1;
	ll w[n+1], v[n+1], i;
	for(i=1; i<=n; i++)
		cin>>w[i]>>v[i];
	ll dp[n+1][w1+1];
	for(i=0; i<n+1; i++)
		dp[i][0] = 0;
	for(i=0; i<w1+1; i++)
		dp[0][i] = 0;
	for(i=1; i<=n; i++)
	{
		for(j=1; j<=w1; j++)
		{
			if(j-w[i]<0)
				dp[i][j] = dp[i-1][j];
			else
				dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]] + v[i]);
		}
	}
	cout<<dp[n][w1]<<"\n";
}	

Measured memory_bytes: 79104
#include<stdio.h>
#include<iostream>

using namespace std;

void InsertionSort(int *,int);

int main(){
  int a[100],v,n,i,j,k,l;

  cin >> n;

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

  for (j=0;j<n;j++){
    v = a[j];
    k = j - 1;
    while(k >= 0 && a[k] > v){
      a[k+1] = a[k];
      k--;
      a[k+1] = v;
    }
    for(l=0;l<n-1;l++)cout << a[l] << " ";

    cout << a[l] << endl;
  }

  return 0;
 
}

Measured memory_bytes: 3068
N, L = map(int, input().split())

all_taste = N*(L-1)+N*(N+1)/2
tastes_list=[0]*N

for i in range(1,N+1):
    tastes_list[i-1] = L+i-1
abs_list = [abs(x) for x in tastes_list]
min_idx = abs_list.index(min(abs_list))
ans = sum(tastes_list) - tastes_list[min_idx]
print(ans)



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (int i = 0; i < sz(v); i++) {
        os << v[i];
        if (i < sz(v) - 1) os << " ";
    }
    return os;
}
int main() {
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    for (int i = k; i < n; i++) {
        cout << (a[i] > a[i - k] ? "Yes" : "No") << endl;
    }
}

Measured memory_bytes: 4848
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define il inline
int n,m,x[N],y[N];
ll a[N],b[N];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%d",&x[i]);
	for(int i=1;i<=m;i++) scanf("%d",&y[i]);
	for(int i=n;i>=1;i--) a[i]=a[i+1]+x[i];
	for(int i=m;i>=1;i--) b[i]=b[i+1]+y[i];
	ll s=0,t=0;
	for(int i=2;i<=m;i++){
		s=(s+b[i]-1LL*(m-i+1)*y[i-1])%mod;
	}
	s=(s%mod+mod)%mod;
	for(int i=2;i<=n;i++){
		t=(t+a[i]-1LL*(n-i+1)*x[i-1])%mod;
	}
	t=(t%mod+mod)%mod;
	printf("%lld\n",s*t%mod);
	return 0;
}

Measured memory_bytes: 6056