akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

struct UnionFind{
    int sz;     // vertex number
    vector<int> par;
    vector<int> rank;

    UnionFind(int n) : sz(n) {
        par.resize(sz);
        rank.assign(sz, 0);
        for(int i = 0; i < sz; ++i){
            par[i] = i;
        }
    }

    int find(int x){
        if(par[x] == x) return x;
        else    return par[x] = find(par[x]);
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }

    void unite(int x, int y){
        x = find(x), y = find(y);
        if(x == y)  return;
        if(rank[x] < rank[y])   par[x] = y;
        else{
            par[y] = x;
            if(rank[x] == rank[y])  ++rank[x];
        }
    }
};

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

    int N, M;
    cin >> N >> M;
    UnionFind uf(N);
    for(int i = 0; i < M; ++i){
        int a, b;
        cin >> a >> b;
        --a, --b;
        uf.unite(a, b);
    }
    set<int> st;
    for(int i = 0; i < N; ++i){
        st.emplace(uf.find(i));
    }
    int ans = st.size();
    cout << ans - 1 << endl;
}

Measured memory_bytes: 7732
//解説放送を見て書き直す
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;

int main(){
	string s;
	cin >> s;
	int n;
	n = (int)s.length();
	vector<int> ans(n);
	rep(ri,2){
		{	
			int cnt=0;
			rep(i,n){
				if(s[i] == 'R') cnt++;
				else{
					ans[i] += cnt/2;
					ans[i-1] += (cnt+1)/2;
					cnt = 0;
				}
			}
		}
		reverse(ans.begin(),ans.end());
		reverse(s.begin(),s.end());
		rep(i,n){
			if(s[i] == 'L') s[i] = 'R';
			else s[i] = 'L';
		}
	}
	rep(i,n){
		printf("%d\n",ans[i]);
	}
	return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000

int ans = 0;
int N,K;

void dfs(vector<int> &dp,vector<vector<int>> &E,int now,int p){
	for(int i=0;i<E[now].size();i++){
		dfs(dp,E,E[now][i],now);
		dp[now] = max(dp[now],dp[E[now][i]]+1);
	}
	if(dp[now]==K-1&&p!=0&&now!=0){
		dp[now] = -1;
		ans++;
	}
}

int main(){
	
	
	cin>>N>>K;
	
	vector<vector<int>> E(N,vector<int>());
	
	for(int i=0;i<N;i++){
		int a;
		cin>>a;
		a--;
		if(i==0){
			if(a!=0)ans++;
		}
		else{
			E[a].push_back(i);
		}
	}

	vector<int> dp(N,0);
	dfs(dp,E,0,-1);

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

Measured memory_bytes: 16908
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >>n;
    long long ans=0;
    for(int i=1;i<n+1;i++){
        if(i % 3 != 0 && i % 5 != 0)ans += i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
//---------------laziness is poison-------------------
#include <bits/stdc++.h>
using namespace std;
const int N = 1234567;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef priority_queue<pii, vector<pii>, greater<pii>> min_pq;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define inf 1e18
int cnt[26];
int main()
{
	ios_base:: sync_with_stdio(false); cin.tie(0);
	// freopen ("inp","r",stdin);
	// freopen ("out","w",stdout);
	string s;
	cin>>s;
	for(int i=0;i<s.length();i++)
		cnt[s[i]-'a']++;
	ll val =0,tot=s.length();
	tot=tot*(tot-1)/2;
	for(int i=0;i<26;i++)
	{
		val+=(1ll*cnt[i]*(cnt[i]-1)/2);
	}
	cout<<1+tot-val<<endl;
	
	return 0;
}

Measured memory_bytes: 720
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

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

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"5"# => r#"YES"#,
r#"6"# => r#"NO"#,
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        x: usize,
    }
    if x == 7 || x == 5 || x == 3 { "YES" } else {"NO" }.to_string()
}

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

typedef long long ll;
typedef long double ld;

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

ll gcd(ll a, ll b){return b ? gcd(b, a % b) : a;}

int main(){

    ll N, A, B;

    cin >> N;

    if(N == 1)
        cout << "Hello World" << endl;
    else
    {
        cin >> A >> B;
        cout << A + B << endl;
    }
    

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int MOD = 1000000007;
const int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;

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

  int N,A,B;
  cin >> N >> A >> B;
  cout << min(A,B) << ' ' << max(A+B-N, (int)0) << endl;
}

Measured memory_bytes: 764
#include <stdio.h>

int main(void){
	int n,r;
  
  scanf("%d %d", &n, &r);
  
  if(n>=10){
    printf("%d", r);
  }
  
  else{
    printf("%d", (10-n)*100+r);
  }
  


  return 0;

}

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



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    s=s+"#";
    int i,j,k,cnt=0,mx=-1;
    for(i=0;i<s.size();i++)
    {
        if(s[i]=='R')
        {
            cnt++;
        }
        else{
            mx=max(cnt,mx);
            cnt=0;
        }
    }
    cout<<mx<<endl;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}

const int M = 2005;

bool match(char x, char y) {
  return (x == y) || (x == '?') || (y == '?');
} 

int main() {
  string a, b, c; cin >> a >> b >> c;
  int la = a.size();
  int lb = b.size();
  int lc = c.size();

  vector<bool> ab(4*M+5, true);
  vector<bool> bc(4*M+5, true);
  vector<bool> ca(4*M+5, true);

  rep2(i, -M, M) rep(j, lb) if (i+j >= 0 && i+j < la && !match(a[i+j], b[j])) ab[2*M+i] = false;
  rep2(i, -M, M) rep(j, lc) if (i+j >= 0 && i+j < lb && !match(b[i+j], c[j])) bc[2*M+i] = false;
  rep2(i, -M, M) rep(j, la) if (i+j >= 0 && i+j < lc && !match(c[i+j], a[j])) ca[2*M+i] = false;

  int ans = INF;
  rep2(i, -2*M, 2*M) rep2(j, -2*M, 2*M) {
    if (j-i <= 2*M && j-i >= -2*M && ab[2*M+i] && bc[2*M+j-i] && ca[2*M-j]) {
      chmin(ans, max({la, i+lb, j+lc}) - min({0, i, j}));
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    n = int(input())
    a = list(map(int, input().split()))

    x = 0
    for i in range(2, n):
        x ^= a[i]
    d = a[0]+a[1]-x
    if d%2 == 1 or d < 0:
        print(-1)
        return
    d >>= 1
    if d&x != 0 or d > a[0]:
        print(-1)
        return
    k = x.bit_length()
    tmp = d
    # d^tmp はd&x=0からd|tmpと一緒
    for i in range(k, -1, -1):
        if (x >> i) & 1:
            if tmp+(1<<i) <= a[0]:
                tmp += 1<<i
    if 0 < tmp <= a[0]:
        print(a[0]-tmp)
    else:
        print(-1)



if __name__ == '__main__':
    main()

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

int main() {

	int n, b, f, r, v,tenant[4][3][10];
	
	cin >> n;

	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 10; k++) {
				tenant[i][j][k] = 0;
			}
		}
	}

	for (int i = 0; i < n; i++) {
		cin >> b >> f >> r >> v;
		tenant[b - 1][f - 1][r - 1] += v;
	}

	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 10; k++) {
				cout << " " << tenant[i][j][k];
			}
			cout << "\n";
		}
		if(i!=3)cout << "####################\n";
	}

	return 0;
}

Measured memory_bytes: 1168
import java.util.Scanner;
import java.util.StringJoiner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int size = Integer.parseInt(scanner.next());
        int[] array = new int[size];
        for (int i = 0; i < size; i++) {
            array[i] = Integer.parseInt(scanner.next());
        }

        int swapCount = 0;
        for (int i = 0; i < size; i++) {
            int mini = i;
            for (int j = i; j < size; j++) {
                if (array[j] < array[mini]) {
                    mini = j;
                }
            }
            if (i != mini) {
                swap(i, mini, array);
                swapCount++;
            }
        }
        System.out.println(concat(array));
        System.out.println(swapCount);
    }

    private static String concat(int[] array) {
        StringJoiner joiner = new StringJoiner(" ");
        for (int value : array) {
            joiner.add(String.valueOf(value));
        }
        return joiner.toString();
    }

    private static void swap(int i, int j, int[] array) {
        int temp = array[i];
        array[i] = array[j];
        array[j] = temp;
    }
}

Measured memory_bytes: 26184
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String r = sc.next();
        String g = sc.next();
        String b = sc.next();
        String concat = r + g + b;
        if (Integer.parseInt(concat) % 4 == 0 ) {
            System.out.println("YES");    
        } else {
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9
const ll inff = 1000000000000000000; //10^18

int main(){
    string s;
    cin >> s;
    cout << s[0] << (int)s.size()-2 << s[s.size()-1] << endl;

    return 0;
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), x = sc.nextInt();
		int[] m = new int[n];
		for (int i = 0; i < m.length; i++)
			m[i] = sc.nextInt();

		int min = Integer.MAX_VALUE;
		for (int i = 0; i < m.length; i++) {
			x -= m[i];
			min = Math.min(m[i], min);
		}

		System.out.println(x / min + n);
	}

}

Measured memory_bytes: 27004
/******************************************
* AUTHOR : Lokesh goel*
* NICK : InsaneNerd *
* INSTITUTION : NIT Kurukshetra *
******************************************/
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MAX 1000000000
#define N 100005
#define pii pair<int,int>
#define vp vector<pair<int,int > >
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define gsz(x) ((int)(x).size())
#define F first
#define S second
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cerr.tie(NULL);
#define endl "\n"
#define ms(x,v) memset(x,v,sizeof(x))

int main()
{
	fastio;
	ll n;
	cin>>n;
	if(n%1000!=0)
		cout<<1000-n%1000<<endl;
	else cout<<0<<endl;

	return 0;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <vector>

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

using namespace std;

int rint() {
  int n;
  scanf("%lld", &n);
  return n;
}

void wint(int n) {
  printf("%lld\n", n);
}

struct union_find {
  vector<int> p;
  union_find(int n): p(n) {
    dotimes(x, n)
      p[x] = x;
  }
  int find(int x) {
    while (x != p[x]) {
      int y = p[x];
      p[x] = p[y];
      x = y;
    }
    return x;
  }
  bool eqv(int x, int y) {
    int a = find(x), b = find(y);
    return a == b;
  }
  bool unite(int x, int y) {
    int a = find(x), b = find(y);
    if (a == b)
      return true;
    if (!(a < b))
      swap(a, b);
    p[b] = a;
    return false;
  }
};

signed main() {
  int n = rint();
  int q = rint();
  union_find uf(n);
  dotimes(i, q) {
    int com = rint();
    int x = rint();
    int y = rint();
    switch (com) {
    case 0:
      uf.unite(x, y);
      break;
    case 1:
      wint(uf.eqv(x, y));
      break;
    default:
      break;
    }
  }
  return 0;
}



Measured memory_bytes: 2828
#include<stdio.h> 
int main()
{
    char S[100];
    scanf("%s",S);
    if(S[0]=='S') 
    printf("Cloudy\n");
    else if(S[0]=='C')
    printf("Rainy\n");
    else if(S[0]=='R')
    printf("Sunny\n");
}

Measured memory_bytes: 128
import java.util.*;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		sc.close();
		out.println(n/10==9||n%10==9?"Yes":"No");
	}
}


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

const int M=1e5+5;
int h[M],dp[M];

int main()
{
	int n; scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&h[i]);
	for(int i=2;i<=n;i++)
	{
		dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
		if(i>2)
			dp[i]=min(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
	}
	printf("%d\n",dp[n]);
	return 0;
}

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

int main(){
    int n,i,hen=0; cin >> n;
    long long int ans = 1;
    vector<int> a(n);
    for(i = 0; i < n; i++) cin >> a.at(i);
    sort(a.begin(),a.end(),greater<int>());
    
    for(i=0; i<n-1; i++){
        if(a.at(i)==a.at(i+1)){
            hen++;
            ans *= a.at(i);
            i++;
        }
        if(hen == 2) break;
    }
    if(hen <2) ans = 0;
    cout << ans << endl;
    return 0;
}

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


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

  int n;
  cin >> n;
  long double x[n],y[n];
  rep(i,n) cin >> x[i] >> y[i];
  long double sum=0;
  rep(i,n){
    rep(j,n){
      sum+=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
    }
  }
  cout << fixed << setprecision(10) << sum/n << endl;
  return 0;
    

}


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

int main() {
  string T;
  cin >> T;
  for (int i=0; i < T.size(); i++) {
    if (T.at(i) == '?')
      cout << 'D';
    else
      cout << T.at(i);
  }
  cout << endl;  
}


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

int main(void){
    long n, d, x;
    cin >> n >> d >> x;
    vector<long> a(n);
    for(long i=0; i<n; i++){
        cin >> a[i];
    }
    for(long i=0; i<n; i++){
        x += (d+a[i]-1)/a[i];
    }
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;cin>>N;
  vector<int> d(N);
  for(int i=0; i<N; i++)cin>>d[i];
  sort(d.begin(),d.end());
  int zm,a=0;
  for(int i=0; i<N; i++){
    if(d[i]==zm)continue;
    a++;
    zm=d[i];
  }
  cout<<a<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  int h[n];
  for(int i=0;i<n;i++){
    cin >> h[i];
  }
  if (n ==1){
    cout << "Yes";
  }
  else{
  	int flag = 0;
  	int tmp = h[n-1];
 	 for(int i = (n-2);i>=0;i--){
 	   if((h[i] - tmp) >= 2){
         cout << "No";
         flag = 1;
         break;
       }
       else if((h[i] - tmp) == 1) {
         tmp = h[i] - 1;
       }
       else{
         tmp = h[i];
       }
 	 }
 	 if(flag == 0){
  	  cout << "Yes";
 	 }    
  }
}

Measured memory_bytes: 640
# ABC119B - Digital Gifts
n = int(input())
lst = [input().rstrip().split() for _ in range(n)]
total = 0

for i in range(n):
    if lst[i][1] == 'JPY':
        total += int(lst[i][0])
    else:
        total += 380000 * float(lst[i][0])
        
print(total)

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

#define N 100

int n, M[N][N], d[N];

queue<int> Q;

void bfs(int x){
    //初期化
    rep(i,n){
        d[i] = -1;
    }

    d[x] = 0;
    Q.push(x);

    while(!Q.empty()){
        int v = Q.front(); Q.pop();
        for(int i = 0; i < n; i++){
            if(M[v][i] == 1){
                if(d[i] == -1){
                    Q.push(i);
                    d[i] = d[v] + 1;
                }else{
                    d[i] = min(d[i], d[v] + 1);
                }
                
            }
        }
    }
}


int main(){
    cin >> n;

    rep(i,N)rep(j,N) M[i][j] = 0;

    int u, k, v;
    rep(i,n){
        cin >> u >> k;
        u--; //0オリジンに変換
        rep(j,k){
            cin >> v;
            v--; //0オリジンに変換
            M[u][v] = 1;
        }
    }

    bfs(0);

    rep(i,n){
        cout << i + 1 << " " << d[i] << endl;
    }

    return 0;
    
}


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

class Multiple{
private:
    string S;
    long long digitSum(string S){
        long long ans=0;
        for(char d: S){
            ans += (d-'0');
        }
        return ans;
    }
public:
    Multiple(){
        cin>>S;
    }
    bool solve(){
        long long ans = digitSum(S);
        return !(ans%9);
    }
    ~Multiple(){

    }
};

int main(){
    Multiple problem = Multiple();
    bool ans = problem.solve();
    if(ans) cout<<"Yes\n";
    else cout<<"No\n";
}

Measured memory_bytes: 3904
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define FI first
#define SE second
#define SI size()
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PF push_front
#define PB push_back
#define VE vector<int>
#define VP vector<PA>
#define LL long long
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//
int N;
VE A[100001];//だれにかったか
int C[100001];
bool F[100001];
int DFS(int now){
  if((int)A[now].SI==0){
    F[now]=true;
    return C[now]=0;
  }
  VE V;
  FOR(i,0,(int)A[now].SI){
    if(!F[A[now][i]]){
      V.PB(DFS(A[now][i]));
    }else{
      V.PB(C[A[now][i]]);
    }
  }
  sort(V.rbegin(),V.rend());
  int MIN=0;
  FOR(i,0,(int)V.SI){
    MIN=max(MIN,V[i]+i+1);
  }
  F[now]=true;
  return C[now]=MIN;
}
int main(){
  cin>>N;
  FOR(i,2,N+1){
    int num;
    cin>>num;
    A[num].PB(i);
  }
  cout<<DFS(1)<<endl;
  return 0;
}


Measured memory_bytes: 17152
# D - Decayed Bridges

import sys

N, M = map(int, sys.stdin.buffer.readline().split())
AB = list(map(int, sys.stdin.buffer.read().split()))

A = AB[::2]
B = AB[1::2]

root = [-1] * N  # 負ならそのノードが根かつ絶対値が木の要素数を示す、正なら値のノードが根であることを示す
rank = [1] * N  # 木の高さを示す

# インデックスxを与えると、xの根を返す関数
def find_root(x):
    if root[x] < 0:
        return x
    else:
        root[x] = find_root(root[x])
        return root[x]

def union_and_return_convenience(x, y):
    # root_x, root_yは根のインデックス
    root_x = find_root(x)
    root_y = find_root(y)
    if root_x == root_y:
        return 0
    elif rank[root_x] > rank[root_y]:  # 短い木(yの方)を長い木(xの方)に繋ぐ
        gain_convenience = root[root_x] * root[root_y]
        root[root_x] += root[root_y]  # 要素数結合
        root[root_y] = root_x  # 根を切り替え
        return gain_convenience
    else:
        gain_convenience = root[root_x] * root[root_y]
        root[root_y] += root[root_x]
        root[root_x] = root_y
        if rank[root_x] == rank[root_y]:
            rank[root_y] += 1  # 新しい木の高さを1追加
        return gain_convenience

ans = [(N*(N-1))//2]
for idx in reversed(range(M)):
    gain_convenience = union_and_return_convenience(A[idx]-1, B[idx]-1)
    ans.append(ans[-1] - gain_convenience)

for idx in reversed(range(M)):
    print(ans[idx])

Measured memory_bytes: 22472
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

int dx[] = { -1, 0, 1, 0, -1, -1, 1, 1};
int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};


int main() {

	long long n, k; cin >> n >> k;
	long long gd = 0, max_ele = 0;
	for (long long i = 1; i <= n; i++) {
		long long a; cin >> a;
		max_ele = max(max_ele, a);
		gd = gcd(gd, a);
	}

	cout << ((((k % gd) == 0) and k <= max_ele) ? "POSSIBLE" : "IMPOSSIBLE");

	return 0;
}

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

ans = 1000
left = A[0]
right = 0
for i in range(n-1):
    right = A[i]
    if A[i]>A[i+1]:
        ans+=(right-left)*(ans//left)
        left = A[i+1]
        #print(left)
#print(ans,left,right)
if left<A[-1]:
    ans+=(A[-1]-left)*(ans//left)
print(ans)


Measured memory_bytes: 61788
import math

li = [input() for i in range(5)]
digit = [li[i][-1:] for i in range(5)]
digitAsc = sorted(digit)

for lastOrderDight in range(5):
    if digitAsc[lastOrderDight] != '0':
        break


for lastOrder in range(5):
    if digit[lastOrder] == digitAsc[lastOrderDight]:
        break

li_i = [int(i) for i in li]

time = 0
for i in range(5):
    if i != lastOrder:
        time += math.ceil(li_i[i] / 10) * 10 
    else:
        time += li_i[i]

print(time)

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

int main(void){
    int N;
    cin >> N;
    map<int,int> data;
    bool ok=true;
    for(int i=0;i<N;i++){
        int num;
        cin >> num;
        if(data.count(num)){
            ok = false; break;
        }
        else data[num] = 1;
    }
    if(ok) cout << "YES" << endl;
    else cout << "NO" << endl;

}

Measured memory_bytes: 9600
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

template <class T> void swap(T& a, T& b) { T t = std::move(a); a = std::move(b); b = std::move(t); }

int main(void)
{
    string S;
    ll N, i;

    cin >> S;

    if(S=="AAA" || S=="BBB"){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }

    return 0;
}

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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		int z;
		cin >> z;
		--z;
		a[i] = z;
	}
	int now = 0, c = 0;
	while (true) {
		if (now == 1) {
			cout << c << '\n';
			break;
		}
		if (c >= n) {
			cout << -1 << '\n';
			break;
		}
		++c;
		now = a[now];
	}	
	
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cassert>
using namespace std;
bool dp[60][60][60],c[60][60];
int a[60],b[60];
int main(){
	int i,j,k,n;
	cin >> n;
	for(i=0;i<n;i++) cin >> a[i];
	for(i=0;i<n;i++) cin >> b[i];
	for(i=0;i<=50;i++){
		for(j=0;j<=50;j++){
			for(k=0;k<=50;k++){
				dp[i][j][k] = false;
			}
		}
	}
	for(i=0;i<=50;i++){
		dp[0][i][i] = true;
		c[i][i] = true;
	}
	for(i=1;i<=50;i++){
		for(j=0;j<=50;j++){
			for(k=0;k<=50;k++){
				dp[i][j][k] = dp[i - 1][j][k]|dp[i - 1][j%i][k];
			}
		}
	}
	for(i=0;i<n;i++){
		if(!(dp[50][a[i]][b[i]])){
			cout << -1 << endl;
			return 0;
		}
	}
	long long ans = 0;
	for(i=50;i>=1;i--){
		bool flag = true;
		for(j=0;j<n;j++){
			for(k=0;k<=50;k++){
				if(c[a[j]][k] && dp[i - 1][k][b[j]]) break;
				if(k==50) flag = false;
			}
		}
		if(!flag){
			ans += (1LL<<i);
			for(j=0;j<=50;j++){
				for(k=0;k<=50;k++){
					c[j][k%i] |= c[j][k];
				}
			}
		}
	}
	cout << ans << endl;
}

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

sum_water = sum(a) // 2

sum_even_left = [0]
sum_odd_left = [0]
for i in range(n):
    if i % 2 == 0:
        sum_even_left.append(sum_even_left[-1] + a[i])
    else:
        sum_odd_left.append(sum_odd_left[-1] + a[i])

sum_even_right = [0]
sum_odd_right = [0]
for i in range(n-1, -1, -1):
    if i % 2  == 0:
        sum_even_right.append(sum_even_right[-1] + a[i])
    else:
        sum_odd_right.append(sum_odd_right[-1] + a[i])
sum_even_right = sum_even_right[::-1]
sum_odd_right = sum_odd_right[::-1]

for i in range(n):
    if i % 2 == 0:
        print(2 * (sum_water - sum_even_left[i//2] - sum_odd_right[i//2]), end=' ')
    else:
        print(2 * (sum_water - sum_odd_left[i//2] - sum_even_right[i//2+1]), end=' ')

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

using namespace std;

#define ll long long
#define ull unsigned long long
#define PI acos(-1.0)
#define eps 1e-12
#define fi first
#define se second
#define MEM(a,b) memset((a),(b),sizeof(a))
#define mod(x) ((x)%MOD)
#define pii pair<int,int>
#define wz cout<<"-----"<<endl;
const int INF_INT = 2147483647;
const ll INF_LL = 9223372036854775807LL;
const ull INF_ULL = 18446744073709551615Ull;
const ll P = 92540646808111039LL;

const ll maxn = 1e5 + 10, MOD = 1e9 + 7;
const int Move[4][2] = {-1,0,1,0,0,1,0,-1};
const int Move_[8][2] = {-1,-1,-1,0,-1,1,0,-1,0,1,1,-1,1,0,1,1};

inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}


void init() {

}


bool vis[maxn];
pair<ll, pair<ll, int> >  a[maxn];
pair<ll, pair<ll, int> >  sa[maxn];
pair<ll, pair<ll, int> >  sb[maxn];

bool cmp1(pair<ll, pair<ll, int> > x, pair<ll, pair<ll, int> >y) {
    return x.fi + x.se.fi > y.fi + y.se.fi;
}


int main(){
//    freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
//    freopen("C:\\Users\\Administrator\\Desktop\\out.txt","w",stdout);
//    ios_base::sync_with_stdio(0);
    init();
    ll n; cin >>n;
    for (int i = 0; i < n; i++) {
        cin >> a[i].fi >> a[i].se.fi;
        a[i].se.se = i;
    }
    sort(a, a+n, cmp1);
    for (int i = 0; i < n; i++) {
        sa[i] = a[i];
    }
    ll suma = 0, sumb = 0;
//    int cnt = 0;
//    int l1 = 0, l2 = 0;
    for (int i = 0; i < n; i++) {
        suma += sa[i].fi;
        i++;
        if (i == n)break;
        sumb += sa[i].se.fi;
    }
//
//    while (cnt < n) {
//        while (vis[sa[l1].se.se]) l1++;
//        suma += sa[l1].fi;
//        vis[sa[l1++].se.se] = 1;
//        cnt ++;
//        if (cnt >= n) break;
//        while (vis[sb[l2].se.se]) l2++;
//        sumb += sb[l2].se.fi;
//        vis[sb[l2++].se.se] = 1;
//        cnt ++;
//    }
    cout << suma - sumb << endl;





    return 0;
}


Measured memory_bytes: 5248
#![allow(unused_imports)]
#![allow(clippy::many_single_char_names)]

// language: Rust(1.42.0)
// check available crates on AtCoder at "https://atcoder.jp/contests/language-test-202001"
// My Library Repo' is at "https://github.com/Loptall/prcn_lib"

/*
    そう甘くはないんだな〜w
*/

// from std...
use std::cmp::{
    max, min, Ordering,
    Ordering::{Equal, Greater, Less},
    Reverse,
};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::convert::TryInto;
use std::mem::swap;
use std::num::{NonZeroU32, ParseIntError};
use std::ops::{
    Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div, DivAssign,
    Index, IndexMut, Mul, MulAssign, Neg, Rem, RemAssign, Shl, ShlAssign, Shr, ShrAssign, Sub,
    SubAssign,
};
use std::process::exit;
use std::{f32, f64, i128, i16, i32, i64, i8, isize, u128, u16, u32, u64, u8, usize};

// Dep' crates are...
use itertools::*;
use itertools_num::*;
use lazy_static::lazy_static;
use maplit::{btreemap, btreeset, hashmap, hashset};
use num_bigint::{BigInt, BigUint};
use num_complex::Complex;
use num_integer::{binomial, gcd, lcm, multinomial, Integer};
use num_rational::Rational;
use num_traits::{clamp, one, pow, zero, Num, NumAssignOps, NumOps, One, Pow, Zero};
use permutohedron::Heap;
use proconio::{
    fastout, input, is_stdin_empty,
    marker::{Bytes, Chars, Isize1, Usize1},
};
use rand::random;

pub const MOD10E9_7: i64 = 1000000007;
pub const MOD99_: usize = 998244353;
pub const MAX: usize = std::usize::MAX;
pub const PI: f64 = f64::consts::PI;
pub const A: u8 = 65;

// code...
// #[fastout]
fn main() {
    input! {
        n: usize, k: usize,
        mut a: [i64; n]
    }

    a.sort_by_key(|x| x.abs());

    if k == n {
        let mut i = 1;
        for e in a {
            i *= e;
            // dbg!(i);
            i %= MOD10E9_7;
        }
        if i < 0 {
            i += MOD10E9_7;
        }
        println!("{}", i);
    } else if a.iter().all(|x| *x < 0) && k.is_odd() {
        let mut i = 1;
        for e in a.into_iter().take(k) {
            i *= e;
            i %= MOD10E9_7;
        }
        if i < 0 {
            i += MOD10E9_7;
        }
        println!("{}", i);
    } else {
        let mut i = 1;
        let mut rest = k;
        let mut ps = a.iter().filter(|x| **x >= 0).collect_vec();
        let mut ne = a.iter().filter(|x| **x < 0).collect_vec();

        loop {
            if rest == 0 {
                break;
            } else if ps.len() >= 1
                && (rest == 1
                    || ne.len() < 2
                    || ps[ps.len() - 1] * *ps.get(ps.len() - 2).unwrap_or(&&1)
                        >= ne[ne.len() - 1] * ne[ne.len() - 2])
            {
                i *= ps.pop().unwrap();
                i %= MOD10E9_7;
                rest -= 1;
            } else {
                i *= ne.pop().unwrap();
                i %= MOD10E9_7;
                i *= ne.pop().unwrap();
                i %= MOD10E9_7;
                rest -= 2;
            }
        }

        println!("{}", i);
    }
}


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

int main(){
  string s;
  cin >> s;
  vector<int> x(s.size());
  int kekka = 1000000;
  for(int i = 0;i < s.size();i++){
    for(char m = '0';m < s.at(i);m++){ 
      x.at(i)++;
    }
  }
  for(int i = 0;i < s.size()-2;i++){
    int cur = abs(753 - (x.at(i)*100 + x.at(i+1)*10 + x.at(i+2)));
    kekka = min(kekka,cur);
  }
  cout << kekka << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE

Int N;
vector<Int> A;

Int dfs(Int i){
  static Int used[100010], mem[100010];
  if(used[i]++) return mem[i];
  if(i+1 >= N || A[i] < A[i+1]) return 0;
  return mem[i] = dfs(i+1) + 1;
}

signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin>>N;
  A.resize(N);
  cin>>A;

  Int ans = 0;
  for(Int i=0;i<N;i++){
    Max(ans, dfs(i));
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 4224
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <math.h>
#include <cassert>
#include <unordered_map>
#include <chrono>
#include <random>
#include <ctime>
using namespace std;
#pragma warning(disable : 4996)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ld PI = 3.14159265358979323846;
const ll MOD = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll MAXN = 5e5 + 1;

ll fact[MAXN];

ll mul(ll a, ll b) {
	return (a * b) % MOD;
}


ll pw(ll a, ll p) {
	ll res = 1;
	while (p > 0) {
		if (p & 1) {
			res = mul(res, a);
		}
		a = mul(a, a);
		p /= 2;
	}
	return res;
}

ll inv(ll a) {
	return pw(a, MOD - 2);
}


ll bin(ll k, ll n) {
	return mul(mul(fact[n], inv(fact[k])), inv(fact[n - k]));
}


int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	srand(time(0));
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	fact[0] = 1;
	for (int i = 1; i < MAXN; i++) {
		fact[i] = mul(fact[i - 1], i);
	}
	ll n, m;
	cin >> n >> m;
	ll ans = 0;
	for (int i = 0; i <= n; i++) {
		ll opa = bin(n - i, m - i);
		opa = mul(opa, opa);
		ll c = bin(i, m);
		ll add = mul(mul(c, opa), fact[n - i]);
		if (i & 1)add = -add;
		ans = (ans + add) % MOD;
	}
	cout << mul(ans, fact[n]);
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll K;
    cin >> K;
    string S;
    cin >> S;
    if (S.size() <= K)
    {
        cout << S << endl;
    }
    else
    {
        cout << S.substr(0, K) + "..." << endl;
    }
    
}


Measured memory_bytes: 3632
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll long long
#define cat(p) cout<<p<<endl
#define catA(p,n) for(int i=0;i<n;i++)cout<<p[i]<<((i==n-1)?"\n":" ")

ll n,m;
ll t[111111];
map<ll,ll>ta;

int main(){ 
  cin>>n>>m;
  rep(i,n){
    cin>>t[i];
    ta[t[i]]++;
  }

  rep(ii,m){
    ll a,b;
    cin>>a>>b;
    ta[b]+=a;
  }
  ll ans=0;
  int cnt=0;

  for(map<ll,ll>::reverse_iterator itr=ta.rbegin();itr!=ta.rend();itr++){
    //cout<<(itr->first)<<" "<<(itr->second)<<endl;
    ll a=(itr->first),b=(itr->second);
    //cout<<a<<" "<<b<<endl;
    if(cnt<n){
      if(cnt+b>=n){ans+=(n-cnt)*a;cnt=n;}
      else {ans+=a*b;cnt+=b;}
    }
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 13568
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
using namespace std;
int main(){
  long long int n,k,a;
  scanf("%lld %lld\n",&n,&k);
  a=n%k;
  if(a<=k/2){
    printf("%lld\n",a);
  }
  else{
    printf("%lld\n",k%a);
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>
#include <bitset>
 
using namespace std;
 
/* template */
 
using ll = long long;
 
void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
 
#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};
 
struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};
 
 
using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;
 
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;
}
 
template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}
 
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
 
constexpr ll LNF = 1LL<<50;
 
constexpr int INF = 1e9+7;
 
const long double PI=3.14159265358979323846;
 
 
vector<int> dx = {1,0,-1,1,-1,0};
vector<int> dy = {1,1,1,0,0,-1};
 
/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,x,t; cin >> n >> x >> t;
    int ans = (n+x-1)/x;
    ans *= t;
    cout << ans << endl;
}


Measured memory_bytes: 3604
#[allow(unused_macros)]
macro_rules! input_byline {
    ($($r:tt)* ) => {
        let stdin = std::io::stdin();
        let mut q = std::collections::VecDeque::new();
        let mut next = || {
            if q.is_empty() {
                let mut s = String::new();
                stdin.read_line(&mut s);
                for v in s.split_whitespace() {
                    q.push_back(v.to_string());
                }
            }
            q.pop_front().unwrap()
        };
        input_inner!{next, $($r)*}
    };

}

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

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

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

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

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

trait Printable {
    fn p(&self);
}

impl<T: std::fmt::Display> Printable for T {
    fn p(&self) {
        println!("{}", self);
    }
}

impl<T: std::fmt::Display> Printable for [T] {
    fn p(&self) {
        for i in 0..self.len() {
            if i != 0 {
                print!(" ");
            }
            print!("{}", self[i]);
        }
        println!("");
    }
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap};

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;

fn main() {
    input! {
        s: chars,
    }
    for i in 0..s.len() {
        if i + 1 < s.len() && s[i] == s[i + 1] {
            println!("{} {}", i + 1, i + 2);
            return;
        }
        if i + 2 < s.len() && s[i] == s[i + 2] {
            println!("{} {}", i + 1, i + 3);
            return;
        }
    }
    println!("-1 -1");
}


Measured memory_bytes: 4352
#include <stdio.h>
int main(void){
	int N,a,i;
	scanf("%d",&N);
	for(i = 9; i >= 2; i--){
		if(N % i == 0){
		a = N / i;
			break;
		}
		if(i == 2){
			a = 1;
			break;
		}
	}
	if(N % a == 0 && N / a <= 9 && a < 10){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <map>

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int N, L; cin >> N >> L;
  string S[N]; rep(i,N) cin >> S[i];
  sort(S,S+N);

  rep(i,N) cout << S[i];
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fast ios_base::sync_with_stdio(false),cin.tie(nullptr)
#define pi 3.14159265358979323846264338327950L
int main()
{
        fast;
        int t=1;
       // cin>>t;
        while(t--)
        {
                int n,m,a,b;
                cin>>n>>m;
                ll h[n+1]={0},no[n+1]={0};
                for(int i=1;i<=n;i++)
                        cin>>h[i];
                for(int i=0;i<m;i++)
                {
                        cin>>a>>b;
                        if(h[a]==h[b])
                        {
                                no[a]=1;
                                no[b]=1;
                        }
                        else if(h[a]>h[b])
                                no[b]=1;
                        else
                                no[a]=1;
                }
                int ans=n;
                for(int i=1;i<=n;i++)
                {

                        if(no[i]==1)//bad observatories
                        {
                                --ans;
                        }
                }
                cout<<ans<<endl;
        }
}

Measured memory_bytes: 5176
n, m = map(int, input().split())

tmp = [-1] * n
hantei = True

for _ in range(m):
    s, c = map(int, input().split())
    if tmp[s-1] == -1 or tmp[s-1] == c:
        tmp[s-1] = c
    else:
        hantei = False


if tmp[0] == -1 and n != 1:
    tmp[0] = 1
elif tmp[0] == -1 and n == 1:
    tmp[0] = 0
elif tmp[0] == 0 and n != 1:
    hantei = False

for i in range(n):
    if tmp[i] == -1:
        tmp[i] = 0


ans = 0

if hantei:
    for i in range(0, n)[::-1]:
        ans += int(tmp[(n-i-1)]) * (10**i)
    print(ans)
else:
    print(-1)

Measured memory_bytes: 3188