akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <tuple>

using ll = long long;
using namespace std;
#define modmod 1000000007

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,k,n) for(int i=k;i<n;i++)

int waru(ll N){
    int count = 1;
    while(1){
        if(N/10 == 0){
            break;
        }else{
            count++;
            N = N/10;
        }
    }
    return count;
}

bool nine(ll N){
    while(1){
        if(N/10 == 0){
            break;
        }else{
            if(N%10 != 9){
                return false;
            }
            N = N/10;
        }
    }
    return true;
}

int main(){
    ll N;
    cin >> N;

    ll for1;
    int count = waru(N);

    //printf("%d\n",count);

    if(count == 1){
        cout << N << endl;
        return 0;
    }
    int result=0;
    for1 = N/pow(10,count-1);
    if(for1 == 10){
        for1 = 9;
    }
    /*
    int for2 = N/pow(10,count-2);
    //printf("%d,%d,%d\n",N,pow(10,count-2), for2);
    for2 = for2%10;
    //printf("%d\n", for2);
    printf("result : %d\n",result);
    printf("for2,count : %d,%d\n",for2,count);
    if(for2 == 9){
        result = 1 + 9*(count-1) + (for1-1);
    }else{
        result = 9*(count-1) + (for1-1);
    }
    */
    result = 9*(count-1) + (for1-1);

    if(nine(N)) result += 1;

    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
typedef long long ll;

using namespace std;

int N, Q;
ll A[200010], B[200010];
multiset<ll> S;

int main() {
	cin >> N >> Q;
	rep(i, 0, 2 * N) cin >> A[i];
	rep(i, 0, 2 * N) cin >> B[i];

	ll ans = 0; bool odd = false;
	ans += A[0] + A[2 * N - 1];
	rep(i, 1, 2 * N - 1) {
		ans += max(A[i], B[i]);
		odd ^= (A[i] > B[i]);
		S.insert(abs(A[i] - B[i]));
	}
	while(Q--) {
		ll a, x, y;
		cin >> a >> x >> y; a--;
		if(a == 0 || a == 2 * N - 1) {
			ans += x - A[a];
			A[a] = x;
		}
		else {
			odd ^= (A[a] > B[a]);
			odd ^= (x > y);
			ans += max(x, y) - max(A[a], B[a]);
			S.erase(S.lower_bound(abs(A[a] - B[a])));
			S.insert(abs(x - y));
			A[a] = x; B[a] = y;
		}
		cout << (!odd ? ans : ans - (*S.begin())) << "\n";
	}
}


Measured memory_bytes: 14208
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<utility>
#include<functional>
#include<algorithm>
#include<bitset>
#include<ctime>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;
long long n,w;
string a[2005];
long long Left[2005][2005],Right[2005][2005],Up[2005][2005],Down[2005][2005];
int main()
{
    cin>>n>>w;
    for(long long i=0;i<n;i++)
		cin>>a[i];
    for(long long i=0;i<n;i++)//左 
	{
        long long cur=0;
        for(long long j=0;j<w;j++)
		{
            if(a[i][j]=='#')
				cur=0;
            else
				cur++;
            Left[i][j]=cur;
        }
    }
    for(long long i=0;i<n;i++)//右 
	{
        long long cur=0;
        for(long long j=w-1;j>=0;j--)
		{
            if(a[i][j]=='#')
				cur=0;
            else
				cur++;
            Right[i][j]=cur;
        }
    }
    for(long long j=0;j<w;j++)//上 
	{
        long long cur=0;
        for(long long i=0;i<n;i++)
		{
            if(a[i][j]=='#')
				cur=0;
            else
				cur++;
            Up[i][j]=cur;
        }
    }
    for(long long j=0;j<w;j++)//下 
	{
        long long cur=0;
        for(long long i=n-1;i>=0;i--)
		{
            if(a[i][j]=='#')
				cur=0;
            else
				cur++;
            Down[i][j]=cur;
        }
    }
    long long ans=0;
    for(long long i=0;i<n;i++)
        for(long long j=0;j<w;j++)
		{
            if(a[i][j]=='#')
				continue;
            ans=max(ans,Left[i][j]+Right[i][j]+Up[i][j]+Down[i][j]-3);
        }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 130048
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args)
	{
		Scanner s=new Scanner(System.in);
		
		int n=s.nextInt();
		
		int a=0;
		int w=0;
		int t=0;
		int r=0;
		
		for(int i=0;i<n;i++)
		{
			String str=s.next();
			
			if(str.charAt(0)=='A')
				a++;
			else if(str.charAt(0)=='W')
			{
				w++;
			}
			else if(str.charAt(0)=='T')
			{
				t++;
			}
			else
			{
				r++;
			}
		}
		
		System.out.println("AC x "+a);
		System.out.println("WA x "+w);
		System.out.println("TLE x "+t);
		System.out.println("RE x "+r);
		
	}	
	
}

Measured memory_bytes: 58756
import sys
input = sys.stdin.readline   # 439ms -> 
# input = sys.stdin.buffer.readline   # 439ms -> 188ms

n = int(input())
p = [int(input()) for _ in range(n)]

q = [0] * n
for i in range(n):
    q[p[i]-1] = i
mxk = 1
k = 1
for i in range(n-1):
    if q[i] < q[i+1]:
        k += 1
        if k > mxk:
            mxk = k
    else:
        k = 1
print(n-mxk)


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

typedef long long int ll;

vector <ll> input;
vector <ll> prices;

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

	ll i,j,t,k,l,m,n,x,y,z;

	cin >> n;

	for(i=0;i<n;i++)
	{
		cin >> k;
		input.push_back(k);
	}

	prices.push_back(input[0]);

	for(i=1;i<n;i++)
	{
		if(input[i] == input[i-1])
			continue;
		prices.push_back(input[i]);
	}



	m = prices.size();

	// for(i=0;i<m;i++)
	// 	cout << prices[i] << " ";
	// cout << '\n';


	ll total = 1000;

	ll stocks = 0;
	
	j = 0;
	k = 0;

	while(j<m)
	{
		// cout << j << '\n';
		if(j == m-1)
			break;
		for(i=j;i+1<m;)
		{
			if(prices[i] < prices[i+1])
				break;
			else
				i++;
		}


		j = i;

		if(j == m-1)
			break;

		stocks += total/prices[j];
		total = total-prices[j]*(total/prices[j]);

		// cout << stocks << " " << total << '\n';
		// cout << "j= " << j << '\n';
		
		for(i=j;i+1<m;)
		{
			// cout << prices[i] << " " << prices[i+1] << '\n';
			if(prices[i]>prices[i+1])
				break;
			else
				i++;
		}

		j = i;

		// cout << j << '\n';

		total += prices[j]*stocks;
		stocks -= stocks;

		// cout << stocks << " " << total << '\n';
		// j++;
		// k++;

		// if(k == 3)
		// 	break;
	}

	cout << total << '\n';


	
	

}

Measured memory_bytes: 3652
#include<iostream>

int main() 
{
    std::string input;
    std::cin >> input;
    for (int i = 0; i < 3; ++i) {
        if (input[i] == '1') {input[i] = '9';}
        else {input[i] = '1';}
    }
    std::cout << input << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n);i++)
#define ll long long
int main()
{
    int n, m;
    int ans;
    cin >> n >> m;
    vector<int> x(m);
    rep(i, m) cin >> x[i];
    sort(x.begin(), x.end());

    if(n >= m){
        cout << 0 << endl;
        return 0;
    }
    else{
        ll zenkukan = x[m - 1] - x[0];
        vector<ll> kukan(m - 1);
        ll hiku=0;
        rep(i,m-1){
            ll k;
            k = abs(x[i] - x[i + 1]);
            kukan[i] = k;
        }
        sort(kukan.rbegin(), kukan.rend());
        rep(i, n-1){
            hiku += kukan[i];
        }
        ans = zenkukan - hiku;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
class Dice
  attr_reader :top, :front, :right, :left, :back, :bottom
  def initialize(pips)
    @top, @front, @right, @left, @back, @bottom = pips.split.map(&:to_i)
  end

  def rotate(dir)
    case dir
    when 'E'; tmp = @top; @top = @left; @left = @bottom; @bottom = @right; @right = tmp
    when 'W'; tmp = @top; @top = @right; @right = @bottom; @bottom = @left; @left = tmp
    when 'S'; tmp = @top; @top = @back; @back = @bottom; @bottom = @front; @front = tmp
    when 'N'; tmp = @top; @top = @front; @front = @bottom; @bottom = @back; @back = tmp
    when 'Z'; tmp = @front; @front = @right; @right = @back; @back = @left; @left = tmp
    end
  end
end

d = Dice.new gets
gets.to_i.times do
  t, f = gets.split.map(&:to_i)
  case t
  when d.top
  when d.bottom; d.rotate('N'); d.rotate('N')
  when d.front; d.rotate('N')
  when d.back; d.rotate('S')
  when d.left; d.rotate('E')
  when d.right; d.rotate('W')
  end

  d.rotate('Z') until d.front == f
  puts d.right
end

Measured memory_bytes: 6124
module solution;
import core.bitop, std.algorithm, std.stdio, std.range;

void main ()
{
	int n, m;
	while (readf (" %s %s", &n, &m) > 0)
	{
		alias Cake = long [3];
		auto a = new Cake [n];
		foreach (ref c; a)
		{
			readf (" %s %s %s", &c[0], &c[1], &c[2]);
		}
		long res = 0;
		foreach (i; 0..8)
		{
			a.schwartzSort !(c => c[0] + c[1] + c[2], q{a > b});
			long cur = 0;
			foreach (ref c; a.take (m))
			{
				cur += c[0] + c[1] + c[2];
			}
			res = max (res, cur);

			int q = bsf (i + 1);
			if (q >= 3)
			{
				break;
			}
			foreach (ref c; a)
			{
				c[q] *= -1;
			}
		}
		writeln (res);
	}
}


Measured memory_bytes: 256
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
use std::cmp::*;
fn main(){
    let n=read::<i32>();
    let k=read::<i32>();
    println!("{}",2*(0..n).map(|_|{let a=read::<i32>();min(a,(k-a).abs())}).sum::<i32>())
}


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

int a[10];
vector<int> b,c;

bool dfs(int i) {
  if (i == 10) {
    // 判定
    for (int j = 1; j < b.size(); j++) {
      if (b[j] < b[j-1])
        return false;
    }
    for (int j = 1; j < c.size(); j++) {
      if (c[j] < c[j-1])
        return false;
    }
    return true;
  }

  bool res = false;

  b.push_back(a[i]);
  res = res || dfs(i+1);
  b.pop_back();
  c.push_back(a[i]);
  res = res || dfs(i+1);
  c.pop_back();

  return res;
}

int main() {
  // ifstream ifs( "test.txt" );
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    // 入力
    for (int j = 0; j < 10; j++) {
      cin >> a[j];
    }
    b.clear();
    c.clear();
    // 計算
    bool res = dfs(0);
    // 出力
    cout << ((res) ? "YES" : "NO")<< endl;
  }
}

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

int main()
{
    int n,i;
    cin >> n;
    vector<int> b(n);
    for(i = 0;i < n-1;++i){
        cin >> b.at(i);
    }
    int sum = b.at(0);
    for(i = 1;i < n-1;++i){
        sum += min(b.at(i-1),b.at(i));
    }
    sum += b.at(n-2);
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
left = 0
right = 10 ** 7 + 1
while right - left > 1:
    mid = (left + right) // 2
    if mid * (mid + 1) // 2 < N:
        left = mid
    else:
        right = mid
ans = {i for i in range(1, right + 1)}
rem = N - right
except_n = right * (right - 1) // 2 - N + right
ans -= {except_n}
[print(i) for i in ans]


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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#define rep(i,a,n)    for(int i=a; i<=n; ++i)
#define rep1(i,a,n)   for(int i=a; i>=n; --i)
#define pb            push_back
#define mp            make_pair
#define int           long long
#define fr            first
#define sc            second
#define vc            vector
#define sz(v)         (int)v.size()
#define all(x)        (x).begin(),(x).end()
#define rall(x)       (x).rbegin(),(x).rend()
#define N             (int)(1e6+5)
#define M             1000000007
#define MM            998244353
#define PI            3.14159265358979
#define INF           1000000000000000

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mii;

int n,m,ans; string str;

int solve(){
    cin>>n>>m; int s=0;
    rep(i,1,m){
        int a; cin>>a;
        s+=a;
    }
    if(s>=n) cout<<"Yes";
    else cout<<"No";
    return 0;
}

signed main() {
    ios::sync_with_stdio(0);
    //std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}


Measured memory_bytes: 256
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int[] line = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int N = line[0];
            int A = line[1];
            int B = line[2];
            Console.WriteLine(Math.Min(A * N, B));
        }
    }
}

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

int main(){
    long long n, m; cin >> n >> m;
    vector<pair<long long, long long>>data(n); //2個1セットの配列を用意
    long long a, b;
    for(int i=0;i<n;i++){
        cin >> a >> b;
        data[i] = make_pair(a, b); //各入力を一組として扱う
    }
    sort(data.begin(), data.end());

    long long ans = 0;
    for(int i=0;i<n;i++){
        ans += data[i].first * min(data[i].second, m);
        m -= min(data[i].second, m);
        if(m==0){
            break;
        }
    }
    cout << ans << endl;
}

//long型及びlong long型にしないとACされない
//sampleの3つ目で変な数値が出てくるので注意

Measured memory_bytes: 1792
// abc171_b
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF (ll)(1e9)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    REP(i, N) cin >> A[i];

    sort(ALL(A));
    int ans = 0;
    REP(i, K) ans += A[i];

    print(ans);

    return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#include<iomanip>
#include<numeric>

using namespace std;
using ll = long long;
constexpr int mo = 1000000007;
constexpr int  mod = mo;
constexpr ll inf = 1ll<<62;
int main(){
    string str;
    cin>>str;
    int n = (int)str.size();
    vector<int> p = {1,10,9,12,3,4};
    vector<vector<int>> dp(n+1,vector<int>(13));
    dp[0][0] =1;
    for(int i=0;i<n;++i){
            int p10 = p[(n-i-1)%6];
        if(str[i] == '?'){
            for(int k=0;k<13;++k)
            for(int j=0;j<10;++j){
                (dp[i+1][(k+j*p10)%13] += dp[i][k])%= mo;
            }
        }else{
            int j=stoi(str.substr(i,1));
            for(int k=0;k<13;++k){
                (dp[i+1][(k+j*p10)%13] += dp[i][k])%= mo;
            }
        }
    }
    cout << dp[n][5] << endl;
    return 0;
}



Measured memory_bytes: 8960
#include<iostream>
#include<vector>
using namespace std;
vector<int> u[10010];
int n,m,t[10010],d[10010];
void dfs(int p){
	cout<<p<<"\n";
	for(int i=0;i<u[p].size();i++){
		d[u[p][i]]++;
		if(d[u[p][i]]==t[u[p][i]]){
			dfs(u[p][i]);	
			d[u[p][i]]=1008610086;
		}
	}
}
int main(){
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		u[a].push_back(b);
		t[b]++;
	}
	for(int i=0;i<n;i++) if(t[i]==0) dfs(i);
	return 0;
}

Measured memory_bytes: 3800
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")

    /*
    ||||||||||||||||||||||||||||||||||||||||||||||||
       |      |||         |      ||||    ||||  |   |
      | |     |   |      | |     |   |  |      |   |
     |   |    |    |    |   |    |   |  |      |   |
    |||||||   |    |   |||||||   |||     |||   |||||
    |     |   |   |    |     |   | |        |  |   |
    |     |   |||      |     |   |  ||  ||||   |   |
    ||||||||||||||||||||||||||||||||||||||||||||||||

    */
    using namespace std;
    //#include "testlib.h"
    #define ff first
    #define ss second
    #define mp make_pair
    #define all(v) v.begin(),v.end()
    #define int long long
    #define ll long long
    #define M 1000000007
    #define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
    #define GCD(m,n) __gcd(m,n)
    #define LCM(m,n) m*(n/GCD(m,n))
    #define mii  map<ll ,ll >
    #define sz(a) (int)a.size()
    #define msi  map<string,ll >
    #define mis  map<ll int, string>
    #define rep(a,b)    for(ll i=a;i<b;i++)
    #define rep0(n)    for(ll i=0;i<n;i++)
    #define repi(i,a,b) for(ll i=a;i<b;i++)
    #define pb push_back
    #define vi vector<ll>
    #define mp make_pair
    #define vs vector<string>
    #define ppb pop_back
    #define endl '\n'
    #define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    #define r0 return 0;
    #define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i)
    #define FORE(it, c) for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
    #define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
    #define input freopen("input.txt", "r", stdin);
    #define Set(a, s) 4(a, s, sizeof (a))
    #define FOR repi
    #define pii pair<int,int>
    #define REVERSE(v) reverse(ALL(v))
    #define display(x) trav(a,x) cout<<a<<" ";cout<<endl
    #define debug cerr<<"bhau"<<endl
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        std::cerr << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
    ll max(ll a, ll b) { return (a > b)? a : b;}
    int min(int a, int b) { return (a < b)? a : b;}
    void amax(int &a,int b){a=max(a,b)%M; }
    void amin(int &a,int b){ a=min(a,b)%M;}
    void inc(int &a,int b){a=(a+b)%M;}
    void dec(int &a,int b){a=(a-b+M)%M;}


    
     int solve()
     {  
     	int a,b,c;cin>>a>>b>>c;
     	if(a+b+c>=22) cout<<"bust";
     	else cout<<"win";

        r0   
     }
    signed main()
    {   
        asdf
        
        int t=1;
        //cin>>t;
        while(t--)
        {
            solve();
        }     
        
}	

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int N,A,B;
	cin >> N >> A >> B;
	vector<char> V(N);
	for (int i = 0; i < N; i++) {
		cin >> V[i];
	}
	int count = 0;
	int countb = 1;
	for (int i = 0; i < N; i++) {
		if (V[i] == 'a') {
			if (count < A + B) {
				count++;
				cout << "Yes" << endl;
			}
			else {
				cout << "No" << endl;
			}
		}
		else if (V[i] == 'b') {
			if (count < A + B && countb <= B) {
				count++;
				countb++;
				cout << "Yes" << endl;
			}
			else {
				cout << "No" << endl;
			}
		}
		else {
			cout << "No" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3704
# 1-indexed　Binary Indexed Tree
class BIT:
    def __init__(self, n, init_list):
        self.num = n+1
        self.tree = [0]*self.num
        for i,e in enumerate(init_list):
            self.update(i,e)

    def update(self,k,x):
        k = k+1
        while k < self.num:
            self.tree[k] += x
            k += (k&(-k))
        return 
    
    # sum([l,r))
    def query(self, l,r):
        ret = 0
        while r>0:
            ret += self.tree[r]
            r -= r&(-r)
        while l>0:
            ret -= self.tree[l]
            l -= l&(-l)
        
        return ret


N = int(input())
A = list(map(int,input().split()))
#%%
idxlist = [0]*N
for i,a in enumerate(A):
    idxlist[a-1] = i


ans = 0
seg = BIT(N,[0]*N)

def judge(l,r):
    if l>r:
        l,r = r,l
    res = seg.query(l,r+1)
    if res:
        return False
    else:
        return True


for idx in idxlist:    
    ng_l = -1
    ng_r = N
    left = idx
    while abs(left-ng_l)>1:
        mid = (left+ng_l)//2
        if judge(idx,mid):
            left = mid
        else:
            ng_l = mid
    
    right = idx
    while abs(ng_r-right)>1:
        mid = (right+ng_r)//2
        if judge(idx,mid):
            right = mid
        else:
            ng_r = mid
    
    ans += A[idx]*(idx-left+1)*(right-idx+1)
    seg.update(idx,1)
    
print(ans)





Measured memory_bytes: 80336
#undef NDEBUG
#include <bits/stdc++.h>

using namespace std;

#define all(v) (v).begin(), (v).end()

using li = long long;
using ld = long double;

void solve(bool);

int main() {
#ifdef YA
    auto s = clock();
    assert(freopen("input.txt", "r", stdin));
    // assert(freopen("output.txt", "w", stdout));
#else
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#endif

    cout << fixed << setprecision(20);

    solve(true);

#ifdef YA1
    while (true) solve(false);
#endif

#ifdef YA
    cout << endl << endl << "time = " << (clock() - s) / (double)CLOCKS_PER_SEC << endl;
#endif

    return 0;
}

const int maxn = 1e5 + 5;

li n, a[maxn];
li ans;

void solve(bool __attribute__((unused)) read) {
    cin >> n;
    bool fl0 = 0, fl1 = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if (a[i] <= 0)
            fl0 = 1;
        if (a[i] >= 0)
            fl1 = 1;
    }
    if (n == 1) {
        cout << a[0] << "\n";
        return;
    }
    ans = 0;
    for (int i = 0; i < n; ++i)
        ans += abs(a[i]);
    if (fl0 && fl1) {
        cout << ans << "\n";
        int ip = 0, in = 0;
        for (int i = 0; i < n; ++i) {
            if (a[ip] < a[i])
                ip = i;
            if (a[in] > a[i])
                in = i;
        }
        if (a[ip] == 0 && a[in] == 0) {
            for (int i = 0; i < n - 1; ++i) {
                cout << "0 0\n";
            }
        } else {
            for (int i = 0; i < n; ++i) {
                if (i == ip || i == in)
                    continue;
                if (a[i] < 0) {
                    cout << a[ip] << " " << a[i] << "\n";
                    a[ip] -= a[i];
                } else {
                    cout << a[in] << " " << a[i] << "\n";
                    a[in] -= a[i];
                }
            }
            cout << a[ip] << " " << a[in] << "\n";
        }
    } else {
        int id = 0;
        for (int i = 0; i < n; ++i) {
            if (abs(a[i]) < abs(a[id]))
                id = i;
        }
        ans -= 2ll * abs(a[id]);
        cout << ans << "\n";
        if (fl0) {
            for (int i = 0; i < n; ++i) {
                if (i == id)
                    continue;
                cout << a[id] << " " << a[i] << "\n";
                a[id] -= a[i];
            }
        } else {
            int cnt = 0;
            for (int i = 0; i < n; ++i) {
                if (i == id)
                    continue;
                ++cnt;
                if (cnt < n - 1) {
                    cout << a[id] << " " << a[i] << "\n";
                    a[id] -= a[i];
                } else {
                    cout << a[i] << " " << a[id] << "\n";
                    a[i] -= a[id];
                }
            }
        }
    }
}

Measured memory_bytes: 2688
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <vector>
#define ll long long int
#define  INF pow(10,9)
#define vi vector<long long int>
#define fast ios_base::sync_with_stdio(false)
#define pb push_back
using namespace std;
int main()
{
    ll x,y;
    cin>>x>>y;
    if(x==y){
        cout<<(x+y)<<endl;
    }
    else if(x>y){
        cout<<(x+x-1)<<endl;
    }
    else{
        cout<<(y+y-1)<<endl;
    }
}


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

#define int long long
#define rep(i,a,n) for(int i = a; i < n; i++)
#define pb push_back
#define eb emplace_back
#define dump(x) cout << #x << " = " << (x) << endl
#define chk() cout << "now" << endl;
#define SORT(c) sort((c).begin(), (c).end())
#define SORTG(c) sort((c).begin(), (c).end(), greater<int>());
#define fi first
#define se second
  
typedef pair<int,int> P;
typedef vector<int> vi;

int H, W, INF = 2001;
vector<string> S;

signed main() {
    cin >> H >> W;
    rep(i, 0, H) {
        string s; cin >> s;
        S.pb(s);
    }

    vector<vector<int>> R(H, vector<int>(W, INF));
    vector<vector<int>> U(H, vector<int>(W, INF));
    vector<vector<int>> D(H, vector<int>(W, INF));
    vector<vector<int>> L(H, vector<int>(W, INF));

    rep(i, 0, H) {
        rep(j, 0, W) {
            if(S[i][j] == '#') {
                R[i][j] = 0;
                L[i][j] = 0;
                D[i][j] = 0;
                U[i][j] = 0;
            }else{
                if(i > 0 and D[i-1][j] != INF and S[i-1][j] != '#') {
                    D[i][j] = D[i-1][j] - 1;
                }else{
                    int index = i+1, ctn = 0;
                    while(index <= H-1) {
                        if(S[index][j] == '.') ctn++;
                        else break;
                        index++;
                    }
                    D[i][j] = ctn;
                }
                if(i > 0 and U[i-1][j] != INF and S[i-1][j] != '#') {
                    U[i][j] = U[i-1][j] + 1;
                }else{
                    int index = i-1, ctn = 0;
                    while(index >= 0) {
                        if(S[index][j] == '.') ctn++;
                        else break;
                        index--;
                    }
                    U[i][j] = ctn;
                }
                if(j > 0 and L[i][j-1] != INF and S[i][j-1] != '#') {
                    L[i][j] = L[i][j-1] + 1;
                }else{
                    int index = j-1, ctn = 0;
                    while(index >= 0) {
                        if(S[i][index] == '.') ctn++;
                        else break;
                        index--;
                    }
                    L[i][j] = ctn;
                }
                if(j > 0 and R[i][j-1] != INF and S[i][j-1] != '#') {
                    R[i][j] = R[i][j-1] - 1;
                }else{
                    int index = j+1, ctn = 0;
                    while(index <= W-1) {
                        if(S[i][index] == '.') ctn++;
                        else break;
                        index++;
                    }
                    R[i][j] = ctn;
                }
            }
        }
    }
                    
        int ans = 0;
        rep(i, 0, H) {
            rep(j, 0, W) {
                int sum = D[i][j] + U[i][j] + R[i][j] + L[i][j];
                if(sum > ans) ans = sum;
            }
        }

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



Measured memory_bytes: 129664
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,i,e,f,g,n,m,k,l;
string s;
int main() {
  cin>>s;
  for(long long i=0;i<s.size();i++) {
    if(s[i]=='7') { cout<<"Yes"; return 0; }
  }
  cout<<"No";
}


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

int main() {
  char c;
  cin >> c;

  string ans = "consonant";
  string vowel = "aiueo";

  for (int i = 0; i < vowel.size(); i++) {
    if (c == vowel.at(i)) {
      ans = "vowel";
      break;
    }
  }

  cout << ans << endl;
}


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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

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

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

int main(){
    bool flag=false;
    ll ans=0,sum=0;

    int n,m;
    cin >>n>>m;

    //cout <<fixed<<setprecision(16)<< << endl;
    //cout<<ans<<endl;
    if(m==n)cout << "Yes" <<endl;
    else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
//writer：Sakura
//problem：Digit Sum 2
//id：021_a
//from：Actor

#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

ll n;
int ans[20];
int cnt=0;

void work(){
	cnt=0;
	int j=0;
	while(n>0){
		ans[++j]=n%10;
		n/=10;
		cnt++;
	}
}

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%lld",&n);
	work();
	int sum=0;
	int res=0;
	for(int i=1;i<=cnt;i++){
		res+=ans[i];
	}
	sum=(cnt-1)*9;
	sum+=ans[cnt]-1;
	sum=max(sum,res);
	printf("%d\n",sum);
	return 0;
}


Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())

count = 0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if a*500 + b*100 + c*50 == X:
                count += 1

print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}


int main(){

  string s,t;
  cin >> s >> t;
  ll q;
  cin >> q;
  vector<ll> sumAs(s.size()+1,0),sumAt(t.size()+1,0);

  FOR(i,0,s.size()){
    sumAs[i+1] = sumAs[i] + ( s[i]=='A' );
  }
  FOR(i,0,t.size()){
    sumAt[i+1] = sumAt[i] + ( t[i]=='A' );
  }

  FOR(i,0,q){

    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll numAs = (sumAs[b]-sumAs[a-1]) + 2*((b-a+1)-sumAs[b]+sumAs[a-1]);
    ll numAt = (sumAt[d]-sumAt[c-1]) + 2*((d-c+1)-sumAt[d]+sumAt[c-1]);

    if(numAt%3 == numAs%3){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }

  }


}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define _Sync ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0) ;
#define _End return cout << '\n' , 0 ;
#define fo(i,x,y) for (int i = x; i < y; i++)
#define fd(i,x,y) for(int i = x; i>= y; i--)
#define ll long long
#define clr(A,x) memset(A, x, sizeof A)
#define pb push_back
#define mod 1000000007
#define debug(x) cout <<#x << " = " << x << endl
#define PI 3.14159265

using namespace std;
int n;
string s;
int cnt[26];
int main() {
    _Sync
    //freopen("D:/input.txt","r",stdin);
    cin>>n;
    cin>>s;
    fo(i,0,n){
        cnt[ (s[i]-'a') ]++;
    }
    ll ans=1;
    fo(i,0,26){
        ans=((ans%mod)*(cnt[i]+1)+mod)%mod;
    }
    ans--;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 512
from collections import defaultdict
import sys
sys.setrecursionlimit(10 ** 7)
graph = defaultdict(list)

N, K = map(int, input().split())
for i in range(N-1):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

mod = 10 ** 9 + 7


def dfs(fro, to, f):
    caseNum = f
    colorNum = K - 1 if f == K else K - 2
    for u in graph[fro]:
        if u == to:
            continue
        pat = dfs(u, fro, colorNum)
        if pat == 0:
            caseNum = 0
            break
        caseNum = caseNum * pat % mod
        colorNum -= 1
    return caseNum


ans = dfs(0, -1, K)
print(ans)

Measured memory_bytes: 96236
from itertools import chain, islice

h, w = map(int, input().split())
n = int(input())
a = map(int, input().split())
c = chain.from_iterable([i] * ai for i, ai in enumerate(a, 1))

for i in range(h):
    l = list(islice(c, 0, w))
    if i % 2 == 1:
        l.reverse()
    print(*l)


Measured memory_bytes: 3828
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	var a int
	as := make([][]int, n)
	for i := 0; i < n; i++ {
		as[i] = make([]int, m)
		for j := 0; j < m; j++ {
			fmt.Scan(&a)
			a--
			as[i][a] = j
		}
	}

	ans := int(1e9)
	xs := make(map[int]bool, 0)
	for len(xs) < m {
		es := make([]int, n)
		fs := make([]int, n)
		for i := 0; i < n; i++ {
			fs[i] = int(1e9)
		}
		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				if xs[j] {
					continue
				}
				f := as[i][j]
				if f < fs[i] {
					fs[i] = f
					es[i] = j
				}
			}
		}

		mx := 0
		xi := -1
		xm := make(map[int]int)
		for _, e := range es {
			xm[e]++
			if mx < xm[e] {
				mx = xm[e]
				xi = e
			}
		}
		ans = min(ans, mx)
		xs[xi] = true
	}

	fmt.Println(ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}


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

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}

template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}


signed main(void) {
	int n;
	cin >> n;
	int a[2][101];
	rep(i, 2) {
		rep(j, n) {
			cin >> a[i][j];
		}
	}
	int b[2][101];
	b[0][0] = a[0][0];
	b[1][n - 1] = a[1][n - 1];
	rep1(i, n) {
		b[0][i] = b[0][i - 1] + a[0][i];//0からiまでを計算したもの
		b[1][n - 1 - i] = b[1][n - i] + a[1][n - 1 - i];//n-1からiまでを計算したもの
	}
	int ret = 0;
	rep(i, n) {
		ret = max(ret, b[0][i] + b[1][i]);
	}
	print(ret);
}

Measured memory_bytes: 3500
n = int(input())
ary = list(map(int,input().split()))
sorted_ary = sorted(ary)
for i in range(n):
    a = n//2-1
    if sorted_ary[a] >= ary[i]:
        print(sorted_ary[a+1])
    else:
        print(sorted_ary[a])


Measured memory_bytes: 26772
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){
    
    int n;
    cin >> n;
    rep(i,0,n){
	ll a;
	cin >> a;
	if(a&1){
	    P("first");
	    ret 0;
	}
    }
    P("second");
    return  0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
 
using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
 
//std::ios::sync_with_stdio(false);   
int a[212345];
vii vec;
int ans[212345];
int main(){
    std::ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int i;
    rep(i,n){
    	cin>>a[i];
    	vec.pb(mp(a[i],i));
    }
    sort(all(vec));
    rep(i,n){
    	if(i<n/2){
    		ans[vec[i].ss]=vec[n/2].ff;
    	}
    	else{
    		ans[vec[i].ss]=vec[n/2-1].ff;
    	}
    }
    rep(i,n){
    	cout<<ans[i]<<endl;
    }
    
}

Measured memory_bytes: 5488
def main():
  if 'get_ipython' not in globals():  
    N = input()
    X = list(map(int,input().split()))
  else:
    N = 5
    X = list(map(int, "9 5 6 8 4".split()))
    print(X)

  max = 0
  count = 0
  for value in X:
    if value >= max:
      count = count + 1
      max = value
    else:
      continue
  print(count)
      
  
main()

Measured memory_bytes: 3064
class UnionFind:
    def __init__(self, n):
        self.parent = [ -1 for _ in range(n) ]
        self._size = n
    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x != y:
            if self.parent[y] < self.parent[x]:
                x, y = y, x
            self.parent[x] += self.parent[y]
            self.parent[y] = x
            self._size -= 1
    def same(self, x, y):
        return self.root(x) == self.root(y)
    def root(self, x):
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.root(self.parent[x])
            return self.parent[x]
    def size(self, x):
        return -self.parent[self.root(x)]

n, m, k = map(int, input().split())
friends = [ [] for _ in range(n) ]
blocks  = [ [] for _ in range(n) ]

tree = UnionFind(n)

for _ in range(m):
    a, b = map(int, input().split())
    a -= 1; b -= 1;
    friends[a].append(b)
    friends[b].append(a)
    tree.unite(a, b)

for _ in range(k):
    a, b = map(int, input().split())
    a -= 1; b -= 1;
    blocks[a].append(b)
    blocks[b].append(a)

for i in range(n):
    ret = tree.size(i)
    s = set()
    for j in friends[i]:
        s.add(j)
    for j in blocks[i]:
        if tree.same(i, j):
            s.add(j)
    ret -= len(s)
    print(ret-1)

Measured memory_bytes: 127904
# include <iostream>
# include <algorithm>

using namespace std;

int main() {
  int N, a[100];
  cin >> N;
  for (int i = 0; i < N; i++) cin >> a[i];
  
  sort(a, a + N);
  reverse(a, a + N);
  
  int alice = 0, bob = 0;
  for (int i = 0; i < N; i += 2) alice += a[i];
  for (int i = 1; i < N; i += 2) bob += a[i];
  
  cout << alice - bob << endl;
  
  return 0;
}

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

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

    string s1, s2;
    cin>>s1>>s2;
    for(int i=0; i<s1.size(); i++) {
    	if(s1[i]!=s2[i]) {
    		cout<<"No";
    		return 0;
    		
    		
		}
	}
	if(s1.size()==s2.size()-1) cout<<"Yes";
	else cout<<"No";
	return 0;
}


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

using namespace std;

const int INF = 1 << 30;

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M;
  cin >> N >> M;
  map<pair<int, int>, vector<pair<pair<int, int>, int>>> G;
  for (int i = 0; i < M; i++) {
    int p, q, c;
    cin >> p >> q >> c;
    p--, q--;
    G[make_pair(p, c)].emplace_back(make_pair(make_pair(q, c), 0));
    G[make_pair(q, c)].emplace_back(make_pair(make_pair(p, c), 0));
    G[make_pair(p, c)].emplace_back(make_pair(make_pair(q, 0), 0));
    G[make_pair(q, c)].emplace_back(make_pair(make_pair(p, 0), 0));
    G[make_pair(p, 0)].emplace_back(make_pair(make_pair(q, c), 1));
    G[make_pair(q, 0)].emplace_back(make_pair(make_pair(p, c), 1));
  }
  set<pair<int, int>> used;
  vector<int> dist(N, INF);
  dist[0] = 0;
  priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>,
                 greater<pair<int, pair<int, int>>>>
      que;
  que.push(make_pair(0, make_pair(0, 0)));
  while (!que.empty()) {
    auto q = que.top();
    que.pop();
    int d = q.first, u = q.second.first, a = q.second.second;
    if (used.find(make_pair(u, a)) != used.end()) continue;
    used.insert(make_pair(u, a));
    for (auto g : G[make_pair(u, a)]) {
      int v = g.first.first, b = g.first.second, c = g.second;
      if (used.find(make_pair(v, b)) != used.end()) continue;
      que.push(make_pair(d + c, make_pair(v, b)));
      chmin(dist[v], d + c);
    }
  }
  if (dist[N - 1] != INF) {
    cout << dist[N - 1] << '\n';
  } else {
    cout << -1 << '\n';
  }
  return 0;
}


Measured memory_bytes: 87112
#include <iostream>

using namespace std;

int main() {
	int a,b,c;
	cin >> a >> b >> c;
	if( b <= a ) { cout << "No" << endl; }
	else if( c <= b ) { cout << "No" << endl; }
	else { cout << "Yes" << endl; }
	return 0;
}

Measured memory_bytes: 3080
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
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;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);

int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    string s,t; cin>>s>>t;
    priority_queue<string,vector<string>,greater<string> > que;
    if(sz(t)>sz(s)) cout<<"UNRESTORABLE"<<endl;
    else{
        //i:tの先頭。
        rep(i,sz(s)-sz(t)+1){
            bool check=true;
            rep(j,sz(t)){
                if(s[i+j]==t[j] || s[i+j]=='?'){
                    
                }
                else{
                    check=false;
                }
            }
            
            //[i,i+sz(t))一致
            if(check){
                string tmp="";
                rep(k,sz(s)){
                    if(i<=k && k<i+sz(t)) tmp+=t[k-i];
                    else if(s[k]=='?') tmp+="a";
                    else tmp+=s[k];
                }
                que.push(tmp);
            }
        }
        if(que.empty()) cout<<"UNRESTORABLE"<<endl;
        else{
            cout<<que.top()<<endl;
        }
    }
}



Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,K;cin>>N>>K;
  if(N*(N-1)/2-K<N-1)cout<<-1<<endl;
  else{
    int count=0;
    cout<<N*(N-1)/2-K<<endl;
    for(int i=2;i<=N;i++)cout<<1<<" "<<i<<endl;
    for(int i=2;i<N;i++){
      for(int j=i+1;j<=N;j++){
        if(N*(N-1)/2-N+1-count==K){
          j=N+1;
          i=N;
          break;
        }
        cout<<i<<" "<<j<<endl;
        count++;
      }
    }
  }
}

Measured memory_bytes: 256
n, h = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]
A, B = zip(*l)
max_a = max(A)
c = 0
for b in sorted([b for b in B if b > max_a], reverse=True):
  h -= b
  c += 1
  if h <= 0:
    print(c)
    exit()
print(c + h // max_a + (h % max_a != 0))

Measured memory_bytes: 36084