akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
#define p(p) cout<<(p)<<" ";
#define pb push_back
#define mp make_pair
#define INF 1<<25

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pi;
typedef long long ll;

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

int N,M,l,r;
vi a,b,c,d;
int A,B;
string S;
void input(){
	cin>>N;
	//cin>>S;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	input();
	S=to_string(N);
	int t=0;
	rep(i,S.size()){
		t+=S[i]-'0';
	}
	if(N%t==0)P("Yes")
	else P("No")
	return 0;
}




Measured memory_bytes: 256
import java.util.*;
import java.math.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}

class Solver {

    private boolean check(int k) {
        for (int i = 1; i * i <= k; i++) {
            if (i * i == k) {
                return true;
            }
        }
        return false;
    }

    private int dist2(int[][] X, int N, int D, int i, int j) {
        int sum = 0;
        for (int k = 0; k < D; k++) {
            int v = X[i][k] - X[j][k];
            sum += v * v;
        }
        return sum;
    }

    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();

        int[][] X = new int[N][D];
        int[][] M = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                X[i][j] = sc.nextInt();
            }
        }

        int cnt = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                if (i != j) {
                    // comapring i with j.
                    int s = dist2(X, N, D, i, j);
                    if (check(s)) {
                        cnt++;
                    }
                }
            }
        }
        System.out.println(cnt);

        return;
    }

}

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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int a,b,c;
	ll k;
	cin >> a >> b >> c >> k;
	int ans = a - b;
	if(k % 2 == 1)ans *= -1;
	ANS(ans);
	return 0;
}


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

using lli = long long int;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

template <class T>ostream &operator<<(ostream &o,const pair<T, T>&p)
{o<<"("<<p.first<<", "<<p.second<<")";return o;}

int main(void){
    string s;
    cin >> s;
    int odsz = 0, odso = 0, evnz = 0, evno = 0;
    for(int i = 0; i < s.size(); i++){
        if(i%2 == 1){
            if(s.at(i) == '0') odsz++;
            else odso++;
        }else{
            if(s.at(i) == '0') evnz++;
            else evno++;
        }
    }
    cout << min(odsz+evno, odso+evnz) << endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>

using namespace std;

int main(void)
{
    string str;

    getline(cin, str);

    for (int i=0; i<str.size(); i++) {
        if ((str[i] >= 65) && (str[i] <= 90))
            str[i] += 32;
        else if ((str[i] >= 97) && (str[i] <= 122))
            str[i] -= 32;
    }
    cout << str << endl;
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
const int MOD=1e9+7;

int main() {
    int n,m;
    cin >> n >> m;
    vector<vector<int>> r(n,vector<int>(n));
    vector<int> br(n);
    int a,b;
    rep(i,m) {
        cin >> a >> b;
        ++r[a-1][b-1];
        ++r[b-1][a-1];
        ++br[a-1];
        ++br[b-1];
    }
    queue<int> q;
    rep (i,n) {
        if (br[i]==1) q.push(i);
    }
    int ans=0;
    while (!q.empty()) {
        int now = q.front();
        q.pop();
        if (br[now]>1) break;
        else if (br[now]==1) {
            rep(j,n) {
                if (r[now][j]==1) {
                    r[now][j]=0;
                    r[j][now]=0;
                    --br[j];
                    if (br[j]==1) q.push(j);
                }
            }
            ++ans;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return list(sys.stdin.readline())
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
mod = 1000000007

#A
"""
x, y = LS()
if x > y:
    print(">")
elif x == y:
    print("=")
else:
    print("<")
"""

#B
"""
x, y, z = LI()
print((x-z)//(y+z))
"""

#C
"""
n, m = LI()
print((m*1900+(n-m)*100)*2**m)
"""

# D
# 解説AC
# 山札のどれからとってもいいという話ではないのか！！！！
n, z, w = LI()
a = LI()
if n == 1:
    print(abs(a[0] - w))
else:
    print(max(abs(a[-1] - w), abs(a[-1] - a[-2])))

Measured memory_bytes: 38768
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cassert>
using namespace std;
#define INF 1LL<<60

int N;
vector<long long> A;
vector<vector<int>> G;
long long dp[5555][2][5555];
int sz[5555];

void dfs(int s, int p){
    sz[s] = 1;
    dp[s][1][0] = A[s];
    if(A[s] > 0) dp[s][0][0] = A[s];

    for(int t : G[s]){
        if(t == p) continue;
        dfs(t, s);
        if(A[s] > 0){
            vector<long long> v(sz[s]+sz[t]+2, INF);

            for(int i=0; i<=sz[s]; i++){
                for(int j=0; j<=sz[t]; j++){
                    v[i+j] = min(v[i+j], dp[s][0][i] + dp[t][0][j]);
                    if(dp[t][0][j] != INF || dp[t][1][j] < 0){
                        v[i+j+1] = min(v[i+j+1], dp[s][0][i]);
                    }
                }
            }

            for(int i=0; i<sz[s]+sz[t]+2; i++){
                dp[s][0][i] = v[i];
                dp[s][0][i] = min(dp[s][0][i], INF);
            }
        }
        {
            vector<long long> v(sz[s]+sz[t]+2, INF);

            for(int i=0; i<=sz[s]; i++){
                for(int j=0; j<=sz[t]; j++){
                    v[i+j] = min(v[i+j], dp[s][0][i] + dp[t][1][j]);
                    v[i+j] = min(v[i+j], dp[s][1][i] + dp[t][0][j]);
                    v[i+j] = min(v[i+j], dp[s][1][i] + dp[t][1][j]);
                    if(dp[t][0][j] != INF || dp[t][1][j] < 0){
                        v[i+j+1] = min(v[i+j+1], dp[s][1][i]);
                    }
                }
            }

            for(int i=0; i<sz[s]+sz[t]+2; i++){
                dp[s][1][i] = v[i];
                dp[s][1][i] = min(dp[s][1][i], INF);
            }
        }
        sz[s] += sz[t];
    }
}

int main(){
    cin >> N;
    A.resize(N);
    G.resize(N);
    for(int i=0; i<N; i++) cin >> A[i];
    for(int i=0; i<N-1; i++){
        int U, V;
        cin >> U >> V;
        U--; V--;
        G[U].push_back(V);
        G[V].push_back(U);
    }
    for(int i=0; i<=N; i++)
        for(int j=0; j<2; j++)
            for(int k=0; k<=N; k++)
                dp[i][j][k] = INF;

    dfs(0, -1);

    long long ans = INF;
    for(long long i=0; i<=N; i++){
        if(dp[0][1][i] < 0){
            ans = i;
            break;
        }
    }
    for(long long i=0; i<=N; i++){
        if(dp[0][0][i] != INF){
            ans = min(ans, i);
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  vector<vector<int>> A(3, vector<int>(3));
  for (int i = 0; i<3; i++){
    for (int j=0; j<3; j++){
      cin >> A.at(i).at(j);
    }
  }
  
  int N;
  cin >> N;
  
  vector<int> B(N);
  for (int i=0; i<N; i++){
    cin >> B.at(i);
  }
  
  for(int i=0; i<N; i++){
    int ret = B.at(i);
    for(int j=0; j<3; j++){
      for(int k=0; k<3; k++){
        if (A.at(j).at(k) == ret){
          A.at(j).at(k) = 0;
        }
      }
    }
  }
  
  if (A.at(0).at(0) == 0 && A.at(0).at(1) == 0 && A.at(0).at(2) == 0){
    cout << "Yes" << endl;
  }
  else if (A.at(1).at(0) == 0 && A.at(1).at(1) == 0 && A.at(1).at(2) == 0){
    cout << "Yes" << endl;
  }
  else if (A.at(2).at(0) == 0 && A.at(2).at(1) == 0 && A.at(2).at(2) == 0){
    cout << "Yes" << endl;
  }
  else if (A.at(0).at(0) == 0 && A.at(1).at(0) == 0 && A.at(2).at(0) == 0){
    cout << "Yes" << endl;
  }
  else if (A.at(0).at(1) == 0 && A.at(1).at(1) == 0 && A.at(2).at(1) == 0){
    cout << "Yes" << endl;
  }
  else if (A.at(0).at(2) == 0 && A.at(1).at(2) == 0 && A.at(2).at(2) == 0){
    cout << "Yes" << endl;
  }
  else if (A.at(0).at(0) == 0 && A.at(1).at(1) == 0 && A.at(2).at(2) == 0){
    cout << "Yes" << endl;
  }
  else if (A.at(0).at(2) == 0 && A.at(1).at(1) == 0 && A.at(2).at(0) == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" <<endl;
  }
  
  
  //vector<int> vec = {2, 5, 2, 1};
  //sort(vec.begin(), vec.end());
  //reverse(vec.begin(), vec.end());
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define repo(i,o,n) for(int i=o;i<(int)(n);i++)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);

int a[100000],ans;
string s;
stack<int> st;

main() {
    cin >> s;
    rep(i,s.size()) {
        if (s[i] == '1') a[i] = 1;
        else a[i] = 0;
    }
    st.push(a[0]);
    rep1(i,s.size()-1) {
        if (!st.size()) {st.push(a[i]);continue;}
        if (st.top() != a[i]) ans += 2,st.pop();
        else st.push(a[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1920
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <cstddef>
#include <queue>
#include <math.h>
using namespace std;

int main()
{
    int N;
    cin >> N;
    if(N % 2 == 0) cout << N / 2 - 1 << endl; 
    else cout << N / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
A11, A12, A13 = map(int, input().split())
A21, A22, A23 = map(int, input().split())
A31, A32, A33 = map(int, input().split())

aList = list([A11, A12, A13, A21, A22, A23, A31, A32, A33])

N = int(input())


bList = list([])

for indx in range(N):
    bList.append(int(input()))


for b_indx in range(N):
    for a_indx in range(int(9)):
        if aList[a_indx] == bList[b_indx]:
            aList[a_indx] = -1

if (((aList[0] == -1) and (aList[1] == -1) and (aList[2] == -1)) or 
    ((aList[3] == -1) and (aList[4] == -1) and (aList[5] == -1)) or
    ((aList[6] == -1) and (aList[7] == -1) and (aList[8] == -1)) or
    ((aList[0] == -1) and (aList[3] == -1) and (aList[6] == -1)) or
    ((aList[1] == -1) and (aList[4] == -1) and (aList[7] == -1)) or
    ((aList[2] == -1) and (aList[5] == -1) and (aList[8] == -1)) or
    ((aList[0] == -1) and (aList[4] == -1) and (aList[8] == -1)) or
    ((aList[2] == -1) and (aList[4] == -1) and (aList[6] == -1))):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();

		System.out.println(a + b == 15 ? "+" : a * b == 15 ? "*" : "x");

		sc.close();
	}
}



Measured memory_bytes: 22996
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



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

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  string s,res;
  cin>>n>>s;
  res=s;
  stack<int> st;
  rep(i,n){
    if(s[i]==')'){
      if(st.size()>0){
        st.pop();
      }
      else {
        res='('+res;
      }
    }
    else{
      st.push(1);
    }
  }
  rep(i,st.size())res=res+')';
  cout<<res<<endl;
  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//<(") 
#define ll long long 
using namespace std;
 
const ll mod = 1e9 + 7;
const ll siz = 5e3 + 10;
const ll base = 32;
const ll MAXX = 1e18; 

ll n;
string s;
ll hashVal[siz];
ll hV[siz];
ll Pow[siz];
ll Pow1[siz];

const ll base1 = 31;
const ll mod1 = 1e9 + 9;

void setup() {
	Pow[0] = 1;
  	Pow1[0] = 1;
	for (ll i = 1; i <= n; i++) {
		Pow[i] = (Pow[i - 1] * base) % mod;
      	Pow1[i] = (Pow1[i - 1] * base1) % mod1;
	}
	for (ll i = 1; i <= n; i++) {
		hashVal[i] = (hashVal[i - 1] * base + s[i] - 'a' + 1) % mod;
      	hV[i] = (hV[i - 1] * base1 + s[i] - 'a' + 1) % mod1;
	}
}

ll get(ll i, ll j) {
	return (hashVal[j] - hashVal[i - 1] * Pow[j - i + 1] + mod * mod) % mod;
}

ll g(ll i, ll j) {
	return (hV[j] - hV[i - 1] * Pow1[j - i + 1] + mod1 * mod1) % mod1;
}

bool check(ll l) {
	for (ll i = 1; i + l - 1 <= n; i++) {
		for (ll j = i + l; j + l - 1 <= n; j++) {
			if (get(i, i + l - 1) == get(j, j + l - 1)
               && g(i, i + l - 1) == g(j, j + l - 1)
               ) {
				return true;
			}
		} 
	}
	return false;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("INP.txt", "r", stdin);
	//freopen("OUT.txt", "w", stdout);
	cin >> n;
	cin >> s;
	s = ' ' + s;
	setup();
	ll ans = 0;
	ll le = 0, ri = n;
	while (le <= ri) {
		ll mid = (le + ri) / 2;
		if (check(mid)) {
			ans = mid;
			le = mid + 1;
		}
		else {
			ri = mid - 1;
		}
	}
	cout << ans << '\n';
	return 0;
}


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

void solve(long long N)
{
    N %= 10;
    string ans;
    if (N == 3)
        ans = "bon";
    else if (N == 0 or N == 1 or N == 6 or N == 8)
        ans = "pon";
    else
        ans = "hon";
    cout << ans << endl;
}

signed main()
{
    long long N;
    scanf("%lld", &N);
    solve(N);
    return 0;
}


Measured memory_bytes: 3692
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::vec::Vec;

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

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)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

fn main() {
    input!{
        n: String,
    }
    let num = n.parse::<usize>().unwrap();
    let mut s_num = 0;
    for ch in n.chars() {
        s_num += ch.to_string().parse::<usize>().unwrap();
    }
    println!("{}", if num % s_num == 0 { "Yes" } else { "No" });
}


Measured memory_bytes: 4352
import sys;sys.setrecursionlimit(10**6)
from collections import*
n=int(input())
d=defaultdict(list)

start=float("inf")
for i in range(n-1):
    a,b=map(int,input().split())
    d[a].append(b)
    d[b].append(a)
    start=min(a,start)
p=sorted(map(int,input().split()))

def DFS(point,TFlist):
    global ans
    global score
    if all(TFlist):
        return 1
    for i in d[point]:
        if TFlist[i-1]:
            continue
        TFlist[i-1]=True
        tmp=p.pop()
        ans[i-1]=tmp
        score.append(tmp)
        #print(score)
        DFS(i,TFlist)
        TFlist[i-1]=False
    return score,ans

TFlist=[False]*(n)
TFlist[start-1]=True
ans=[0 for i in range(n)]
score=[]
ans[start-1]=p.pop()
s,t=DFS(start,TFlist)
#print(d)
print(sum(s))
print(*t)

Measured memory_bytes: 11432
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<ll>())
#define ll long long
#define rep(i, s, g) for (ll i = (s); i < (g); i++)
#define MOD 1000000007
#define vfind(v, target) find(v.begin(), v.end(), target)
#define notFound(v, target) (vfind(v, target) == v.end())

using namespace std;

int main()
{
  ll N; cin >> N;
  string S; cin >> S;
  string Sdash = S;
  while(Sdash.find("()") != string::npos){
  	Sdash.erase(Sdash.find("()"), 2);
  }
  ll left, right = 0;
  for (char c : Sdash) {
  	if (c == ')') right++;
    else break;
  }
  left = Sdash.size() - right;
  rep(i, 0, left) {
    S = S + ')';
  }
  rep(i, 0, right) {
  	S = '(' + S;
  }
  cout << S << endl;
}

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

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------
    ll n;cin>>n;
    V<ll>a(n),b(n);
    for(ll i=0;i<n;i++)cin>>a[i]>>b[i];
    ll ans=0;
    for(ll i=n-1;i>=0;i--){
        ll times;
        a[i]+=ans;
        if(a[i]==0)continue;
        if(b[i]>a[i])times=1;
        else{
            times=a[i]/b[i];
            if(a[i]%b[i]!=0)times++;
        }
        ans+=b[i]*times-a[i];
    }
    cout<<ans<<endl;
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------





































Measured memory_bytes: 1792
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

int main(){
  int n,i;
  cin>>n>>i;
  
  cout<<n+1-i<<endl;

  return 0;
}

Measured memory_bytes: 3480
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
//typedef __int128_t lll;
using namespace std;

int main(int argc, char const *argv[]) {
  string s;std::cin >> s;

  ll ans = 0, S = 0, T = 0;
  re(i, s.size()){
    if(s[i]=='S') {
      S++;
      ans++;
    }else {
      T++;
      if(S==0) ans++;
      else{
        S--, T--, ans--;
      }
    }
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 832
n = raw_input()
w = raw_input().split(' ')

s1 = 0
s2 = 0
t = 0
n = int(n)

min = 999999999999

for t in range(1,n):
  for i in range(0,t):
    s1 += int(w[i])
  for i in range(t,n):
    s2 += int(w[i])

  tmp = abs(s2 - s1)

  if tmp < min:
    min = tmp

  s1 = 0
  s2 = 0

print(min)

Measured memory_bytes: 2696
#include <bits/stdc++.h>
 using namespace std;
 using pii = pair<int, int>;
 using ll = long long;
 #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
 const ll MOD = 1000000007;
 const ll INFL = (1LL << 60);
 const int INFI = (1 << 30);

 int main() {
   char a; cin >> a;
   if (isupper(a)) cout << "A" << endl;
   else cout << "a" << endl;
 }


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

int main() {
    int N, number;
    int count_odd = 0, count_even = 0, count_four = 0;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> number;
        if (number % 4 == 0) count_four++;
        else if (number % 2 == 0) count_even++;
        else count_odd++;
    }
    if (count_odd == 0) cout << "Yes" << endl;
    else {
        if (count_four >= count_odd) cout << "Yes" << endl;
        else {
            if (count_four + 1 == count_odd && count_even == 0) cout << "Yes" << endl;
            else cout << "No" << endl;
        }
    }
    return 0;
}

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

using ll = long long;
using ii = pair<int, int>;

const int maxn = 1e3 + 3;
const int mod = 1e9 + 7;

int n, k;
int a[maxn];
int C[maxn][maxn];
int dp[21][maxn];

int mul(vector<int> v) {
	int ret = 1;
	for(int x : v) {
		ret = ((ll)ret * (ll)x) % mod;
	} return ret;
}

int main(int argc, char const *argv[])
{
#ifdef LOCAL
	freopen("in", "r", stdin);
#endif
	for(int i = 0; i < maxn; i++) {
		C[i][i] = C[i][0] = 1;
	}
	for(int i = 1; i < maxn; i++) {
		for(int j = 1; j < i; j++) {
			C[i][j] = C[i-1][j] + C[i-1][j-1];
			if(C[i][j] >= mod) C[i][j] -= mod;
		}
	}
	cin >> n >> k;
	for(int i = 1; i <= k; i++) {
		cin >> a[i];
	}
	dp[0][0] = 1;
	for(int i = 1; i <= k; i++) {
		dp[i][0] = mul({dp[i-1][0], C[n][a[i]]});
		for(int j = 1; j <= n; j++) {
			for(int tek = 0; tek <= j and tek <= a[i]; tek++) {
				dp[i][j] += mul({dp[i-1][j-tek], C[j][tek], C[n-tek][a[i]-tek]});
				if(dp[i][j] >= mod) dp[i][j] -= mod;
			}
		}
	}
	cout << dp[k][n] << endl;
	return 0;
}

Measured memory_bytes: 4224
f=lambda:map(int,input().split())
n,d,a=f()
lt=sorted(tuple(f()) for _ in range(n))
from collections import *
q=deque()
c=s=0
for x,h in lt:
  while q and q[0][0]<x: s+=q.popleft()[1]
  h-=s
  if h>0: t=-h//a; c-=t; s-=t*a; q.append((x+d*2,t*a))
print(c)

Measured memory_bytes: 81368
#define DEBUG
#include <bits/stdc++.h>
#include <ext/numeric>
using namespace std; using __gnu_cxx::power;
using ll = long long; using ull = unsigned long long; using ld = long double;
const ll llinf = (1ll<<61)-1; const double eps = 1e-6, ldeps = 1e-9;
#define all(x) begin(x), end(x)
#define sl(a) int(strlen(a))
#define sz(a) int(a.size())
#define TCC template<class C
struct Dbg { static constexpr auto &os = cout;   // replace by cerr in interactive.
#define ENI typename enable_if<
#define DTOR , Dbg&>::type operator<<
#define RIS return *this
TCC> static auto o(C *x)->decltype(os << *x, 0);
TCC> static char o(...);
TCC> ENI sizeof o<C>(0)!=1 DTOR(const C &x) {os<<x; RIS;}
TCC> Dbg &dump(C b, C e) {
    int ii = 0;
    for(C i = (os << "\n[", b); i!=e and ii<26; i++, ii++) *this << ", "+2*(i==b) << *i;
    RIS << ']';
}
TCC> ENI sizeof o<C>(0)==1 DTOR(const C &x) {
    return dump(all(x));
}
TCC, size_t X> ENI !is_same<C, const char>::value DTOR(C (&x)[X]) {
    return dump(all(x));
}
TCC, class D> Dbg &operator<<(const pair<C, D> &x) {RIS<<'{'<<x.first<<", "<<x.second<<'}';}
Dbg &operator<<(ostream&(*x)(ostream&)) { os << x; RIS; }
} dbg;
void err(istringstream *iss) { delete iss; }
TCC, class... Args> void err(istringstream *iss, const C &val, const Args &... args) {
    string name; *iss >> name; if (name.back()==',') name.pop_back();
    dbg << name << " = " << val << "; ", err(iss, args...);
}
#ifdef DEBUG
#define bug(args...) dbg << __LINE__ << ": ", err(new istringstream(#args), args), dbg << endl
#else
#define bug(args...) 0
#endif
#define ASSERT(a, o, b, args...) if (!((a)o(b))) bug(a, b, ##args), assert((a)o(b));
int T = 1, Q, cn;
const int inf = 1000000007, mxn = 200005;

int n;
bool c[mxn];
char s[mxn];

signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cout.precision(11), cout.setf(ios::fixed);
    // cin >> T;
    auto inputAll = [&]()->void {
        
    };
    auto kase = [&]()->void {
        // cout << "Case " << cn << ": ";
        cin>>n>>s;
        map<char,bool>m={{'R',0},{'W','1'}};
        for(int i=0;i<n;i++)c[i]=m[s[i]];
        int tot=0,rght=0;
        for(int i=0;i<n;i++){
            tot+=c[i];
        }
        for(int i=n-1,o=0;o<tot;i--,o++)rght+=c[i];
        cout<<tot-rght<<'\n';
    };
    auto resetAll = [&]()->void {
        
    };
    while (cn++!=T) inputAll(), kase(), resetAll();
}


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

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> dp(n+1, 0);
    rep(i, 1, n)
    {
        int ox = 0;
        if (s[i] != s[i-1]) ox = 1;
        dp[i+1] = max(dp[i-1]+ox, dp[i]);
    }
    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 3460
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int, int>;
ll N;
vector<ll> A;
vector<ll> B;
const ll INF = 1e12;

int main()
{
    cin >> N;
    A.resize(N);
    for (int i = 0; i < N; ++i)
        cin >> A[i];
    B = A;
    sort(B.begin(), B.end(), greater<ll>());
    for (ll a : A)
    {
        if (B[0] == a)
        {
            cout << B[1] << endl;
        }
        else
        {
            cout << B[0] << endl;
        }
    }
}

Measured memory_bytes: 4736
#include <stdio.h>

int main()
{
    int n, i, count;
    char s[101];
    count = 0;
    scanf("%d", &n);
    for (i=0; i<n; i++)
    {
        scanf("%s", &s[i]);
    }
    for (i=0; i<n; i++)
    {
        if (s[i] == 'P') {
            count++;
            break;
        }
    }
    for (i=0; i<n; i++)
    {
        if (s[i] == 'W') {
            count++;
            break;
        }
    }
    for (i=0; i<n; i++)
    {
        if (s[i] == 'G') {
            count++;
            break;
        }
    }
    for (i=0; i<n; i++)
    {
        if (s[i] == 'Y') {
            count++;
            break;
        }
    }
    if (count == 3) {
        printf("Three\n");
    } else if (count == 4) {
        printf("Four\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//CODE

void solve(void)
{
  int N;
  cin>>N;
  map<int,int> mp;
  for (int i = 0; i < N; i++)
  {
    int A;
    cin>>A;
    auto itr = mp.find(A);
    if(itr == mp.end())
    {
      mp[A] = 1;
    }
    else
    {
      mp[A]++;
    }
    
  }
  int H = 0, W = 0;
  auto itr = mp.end();
  itr--;
  for (int i = 0; i < mp.size(); i++)
  {
    if(itr->second >= 4)
    {
      
      chmax(H,itr->first);
      chmax(W,itr->first);
    }
    else if(itr->second >= 2)
    {
    if(itr->first >= H)
    {
      H = W;
      W = itr->first;
      // DEBUG(itr-> first,itr->second );
    }
    }

    if(i!=mp.size()-1)itr--;
  }
  // DEBUG(H,W);
  cout<<H*W<<endl;

   
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  

 
  return 0;
}


Measured memory_bytes: 6528
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		
		// 計算
		float result = 0;
		result = (float)((n+1)/2)/n;
		
		// 出力
        System.out.println(result);
	}
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
#define ll long long
using P = pair<ll, ll>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

int num[20020020];

int main(){
    fast_io
    
    int n;
    cin>>n;
    int A[n];
    rep(i,n-1) {
        cin>>A[i];
        num[A[i]-1]++;
    }
    rep(i,n){
        cout<<num[i]<<endl;
    }

    return 0;
}

Measured memory_bytes: 5132
import java.util.*;

class Main {

    static void swapRange(int b, int e, int t, int[] arr) {
        for (int k = 0; k < e - b; k ++) {
            int tmp = arr[b + k];
            arr[b + k] = arr[t + k];
            arr[t + k] = tmp;
        }
    }

    static Scanner input = new Scanner(System.in);
    public static void main(String[] args) {
        int n = input.nextInt();
        int[] arr = new int[n];

        for (int i = 0; i < n; i ++) {
            arr[i] = input.nextInt();
        }

        int q = input.nextInt();
        for (int count = 0; count < q; count++) {
            int b = input.nextInt();
            int e = input.nextInt();
            int t = input.nextInt();
            swapRange(b, e, t, arr);
        }

        for (int i = 0; i < n - 1; i ++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println(arr[n-1]);
    }
}


Measured memory_bytes: 36392
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
using namespace std;

typedef long long ll;
typedef double db;
typedef long double ldb;

template<class T> inline void checkmin(T &a,const T &b){if(b<a) a=b;}
template<class T> inline void checkmax(T &a,const T &b){if(b>a) a=b;}

const int maxn=1e6+10;

int n,a[maxn],ans=0;
bool exist[maxn];

inline bool prime(int val){
	int now=val,sum=0;
	for(int i=2;i*i<=val;i++) if(now%i==0){
		sum++;
		if(exist[i]) return false;
		exist[i]=true;
		while(now%i==0) now/=i;
	}
	if(now>1) if(exist[now]) return false;
	if(now>1) exist[now]=true;
	return true;
}

inline int get_gcd(int a,int b){
	if(b==0) return a;
	else return get_gcd(b,a%b);
}

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",&a[i]);
	bool flag=true;
	for(int i=0;i<n;i++){
		flag&=prime(a[i]);
		if(!flag) break;
	}
	if(flag){
		printf("pairwise coprime");
		return 0;
	} 
	int gcd=a[0]; 
	for(int i=1;i<n;i++) gcd=get_gcd(a[i],gcd);
	printf(gcd==1?"setwise coprime":"not coprime");
	return 0;
}


Measured memory_bytes: 7656
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    total = 0
    for i in range(N):
        if i == 0:
            total += abs(A[i] - 0)
        elif i == N - 1:
            total += abs(A[i] - A[i - 1])
            total += abs(A[i])
        else:
            total += abs(A[i] - A[i - 1])


    for i in range(N):
        if i == 0:
            sabun = abs(abs(A[i] - 0) + abs(A[i] - A[i + 1]) - abs(A[i + 1] - 0))
            print(total - sabun)
        elif i == N - 1:
            sabun = abs(abs(A[i] - A[i - 1]) + abs(A[i]) - abs(A[i - 1]))
            print(total - sabun)
        else:
            sabun = abs(abs(A[i] - A[i - 1]) + abs(A[i] - A[i + 1]) - abs(A[i + 1] - A[i - 1]))
            print(total - sabun)



if __name__ == '__main__':
    main()



Measured memory_bytes: 13164
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
constexpr auto INF = INT_MAX / 2;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

ll lpow(int p, int q) {
	ll ans = 1;
	ll pp = p;
	while (q) {
		if (q % 2) {
			ans *= pp;
			ans %= MOD;
		}
		q /= 2;
		pp *= pp;
		pp %= MOD;
	}
	return ans;
}

vi prime, mnpf;
void preprime(int n) {

	prime.resize(0);
	mnpf.assign(n + 1, 1);
	rep1(i, n) {
		if (i < 2)continue;
		if (mnpf[i] != 1)continue;

		prime.push_back(i);
		mnpf[i] = i;
		int ii = i;
		while (ii <= n) {
			if (mnpf[ii] == 1)mnpf[ii] = i;
			ii += i;
		}
	}
}

int main() {

	int n;
	cin >> n;
	preprime(1000020);

	map<int, int> lcmpf;
	vi a(n);

	rep(i, n) {
		
		cin >> a[i];
		int aa = a[i];

		map<int, int> pp;

		while (aa>1) {
			pp[mnpf[aa]]++;
			aa /= mnpf[aa];
		}

		for (auto x : pp)lcmpf[x.first] = max(lcmpf[x.first], x.second);

	}

	ll ans = 0;
	ll lcm = 1;
	for (auto x : lcmpf) { lcm *= lpow(x.first, x.second);lcm %= MOD; }

	rep(i, n) {

		ll plu = lcm;
		plu *= lpow(a[i], MOD - 2);
		ans += plu % MOD;
		ans %= MOD;

	}

	cout << ans << endl;

}

Measured memory_bytes: 4984
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <cstdlib>
#include <cmath>
using namespace std;

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

	if(a * n < b) {
		cout << a * n << endl;
	} else {
		cout << b << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <algorithm>
#include <cassert>
#include <string>
#include <climits>
#include <numeric>

#define all(x) begin(x),end(x)

using namespace std;
using ll = long long;

int main()
{
	int n, k; cin >> n >> k;
	string s; cin >> s;
	int slen = (int)s.size();
	vector<int> nums;
	int cnt = 0;
	int num = 1;
	for (int i = 0; i < slen; ++i) {
		if ('0' + num == s[i])
			cnt++;
		else {
			nums.push_back(cnt);
			num = 1 - num;
			cnt = 1;
		}
	}
	if (cnt)
		nums.push_back(cnt);

	vector<int> sum(nums.size()+1, 0);
	for (int i = 0; i < (int)nums.size(); ++i) {
		sum[i + 1] = nums[i] + sum[i];
	}

	int ans = 0;
	int add = 2 * k + 1;
	for (int i = 0; i < (int)nums.size(); i+=2) {
		int left = i;
		int right = min(i + add, (int)nums.size());
		ans = max(ans, sum[right] - sum[left]);
	}
	cout << ans << endl;
}



Measured memory_bytes: 1272
# include<bits/stdc++.h>
using namespace std;
const int MAX=2e5+5;
int n,ans;
int a[MAX];
map<int,int> ma;
bool use[MAX];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	  scanf("%d",&a[i]),++ma[a[i]];
	sort(a+1,a+1+n);
	for(int i=31;i>=1;--i)
	  {
	  	for(int j=1;j<=n;++j)
	  	  if(ma[a[j]])
		  {
	  	  	int x=(1<<i)-a[j];
	  	  	if(x<=0) break;
	  	  	if(x!=a[j])
	  	  	{
	  	  		if(ma[x]) ++ans,--ma[x],--ma[a[j]];
			}
			else
			{
				if(ma[x]>=2) ++ans,ma[x]-=2;
			}
		  }
	  }
	return printf("%d",ans),0;
}

Measured memory_bytes: 39168
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
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;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll n;
ll a[200100];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		int a1;
		cin>>a1;
		a[a1]=i;
	}
	ll ans=0;
	multiset<ll> t1;
	for(ll i=1;i<=n;i++){
		auto ut=t1.lower_bound(a[i]);
		//auto lt=(--t1.lower_bound(a[i]));
		ll ut1,lt1;
		if(ut==t1.end()){
			ut1=n+1;
		}else{
			ut1=*ut;
		}
		if(ut==t1.begin()){
			lt1=0;
		}else{
			lt1=*(--ut);
		}
		//cout<<i<<" "<<ut1<<" "<<lt1<<endl;
		//cout<<(ut1-a[i])*(a[i]-lt1)*i<<endl;
		t1.insert(a[i]);
		ans+=(ut1-a[i])*(a[i]-lt1)*i;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 11136
//From Naruto to Hokage
//#include <RJ>
#include<bits/stdc++.h>
using namespace std;

#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=10000007;
void solve(){
    ll n,k;
    cin>>n>>k;
    vi dp(N,2);
    vi v(n);
    // dp[0]=0;
    rep(i,0,n-1){
        cin>>v[i];
    }
    rep(j,0,1e5){
        rep(i,0,n-1){
            if(dp[j]==2) dp[j+v[i]]=1;
            if(dp[j]==1 && dp[j+v[i]]==2) dp[j+v[i]]=2;
        }
    }
    if(dp[k]==1) cout<<"First";
    else cout<<"Second";
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

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

long long a, b, c, d;

long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

bool solve() {
  if (a < b) return false;
  if (d < b) return false;
  if (c >= b-1) return true;

  long long g = GCD(b, d);

  // g で割って a%g あまる数で、c より大きく b 未満な整数があるかどうか
  // g で割って a%g あまる数で、b 未満の最大の数
  long long Max = (b - a%g + g-1)/g*g + a%g - g; // b が g の倍数であることを考慮して、Max = b + a%g - g でも OK
  if (Max > c) return false;
  else return true;
}

int main() {
  int T; cin >> T;
  for (int CASE = 0; CASE < T; ++CASE) {
    cin >> a >> b >> c >> d;
    if (solve()) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int a[5],b,i,j,f,c,d;
    d=0;
    c=0;
    b=9;
    f=5;
    for (i=0;i<5;i++){
        cin>>a[i];
    }
    for (i=0;i<5;i++){
        if ((b%10>=a[i]%10)&&(a[i]%10!=0)){
            b=a[i];
            f=i;
            
        }
        else
            d=d+1;
        
        
        
    }
    
    if (d==5)
        b=0;
    for (i=0;i<5;i++){
        if  (i!=f){
            if (a[i]%10==0){
                c=a[i]+c;
            }
            else
                c=a[i]+10-a[i]%10+c;
        }
    }
    cout<<c+b;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<double> vec(n, 0);
	for(int i = 0; i < n; ++i){
		cin>>vec[i];
	}
	double x;
	for(int i = 0; i < n; ++i){
		x += (double)1 / double(vec[i]);
	}
	cout<<setprecision(10);
	cout<<(double)1/(double)x<<endl;
	return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
input = sys.stdin.readline
input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

def main():
	a,b=input().decode().split()
	a=int(a)
	b=float(b)*100
	ans=a*int(b+0.5)
	print(ans//100)




if __name__ == "__main__":
	main()


Measured memory_bytes: 9192
H, W = map(int, input().split())

G = [['0'] * (W + 2)]
for _ in range(H):
    tmp = ['0'] + list(input()) + ['0']
    G.append(tmp)
G.append(['0'] * (W + 2))

move = [[1, 0], [0, 1]]

INF = 10 ** 6
ans = [[INF] * (W + 2) for _ in range(H + 2)]
if G[1][1] == '.':
    ans[1][1] = 0
else:
    ans[1][1] = 1


stack = [[1, 1]]
while stack:
    tmp = stack.pop()
    x, y = tmp[0], tmp[1]
    for dx, dy in move:
        nx = x + dx
        ny = y + dy
        if G[nx][ny] == '0':
            continue
        elif G[nx][ny] == '.':
            if ans[nx][ny] > ans[x][y]: #更新できるとき
                ans[nx][ny] = ans[x][y]
                stack.append([nx, ny])
        else:
            if G[x][y] == '.': #白から黒色への変わり目
                if ans[nx][ny] > ans[x][y] + 1:
                    ans[nx][ny] = ans[x][y] + 1
                    stack.append([nx, ny])
            else:
                if ans[nx][ny] > ans[x][y]: #更新できるとき
                    ans[nx][ny] = ans[x][y]
                    stack.append([nx, ny])
                    
print (ans[H][W])

# for tmp in ans:
#     print (tmp)

Measured memory_bytes: 3316
def dfs(s, l, n):
    '''
    l?????????????????°??????n???????????§s????????????????????????????????°
    '''
    if s < 0:
        return 0
    elif n == 0:
        if s == 0:
            return 1
        else:
            return 0
    else:
        return sum([dfs(s-l[i], l[i+1:], n-1) for i in range(len(l))])

nl, sl = [], []
while True:
    n, s = map(int, input().split())
    if s == 0 and n == 0:
        break
    nl.append(n)
    sl.append(s)

for n, s in zip(nl, sl):
    print(dfs(s, list(range(10)), n))

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

int main() {
  int H, W;
  cin >> H >> W;

  vector<string> a(H);
  rep(i, H) cin >> a[i];

  vector<bool> row(H, false);
  vector<bool> col(W, false);

  rep(i, H) {
    rep(j, W) {
      if (a[i][j] == '#') {
        row[i] = true;
        col[j] = true;
      }
    }
  }

  rep(i, H) {
    if (row[i]) {
      rep(j, W) {
        if (col[j]) {
          cout << a[i][j];
        }
      }
      cout << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <string.h>
#include <iomanip>
using namespace std;
#define int long long
#define ull unsigned long long
#define F first
#define S second
#define nl "\n"
#define ld long double
#define div 1000000007
#define pi 3.14159265358979323846
#define pb push_back

void solve()
{
    int a;cin>>a;
    cout<<a+a*a+a*a*a<<nl;
}

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

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


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

int main() {
  char c;
  cin >> c;
  
  if (c == 'a'  || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
    cout << "vowel" <<endl;
  }
  else {
    cout << "consonant" << endl;
  }
}

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

int main(){
  string s;
  int k;
  cin >>s >>k;
  int n = s.size();
  int cnt = 1;
  rep(i,n-1){
    if(s[i]==s[i+1]) cnt++;
    else break;
  }
  if(cnt==n){
    cout << (ll)n*k/2 << endl;
    return 0;
  }
  ll ans = 0;
  rep(i,n-1){
    if(s[i]==s[i+1]){
      ans++;
      s[i+1]='*';
    }
  }
  ans *= k;
  if(s[0]==s[n-1]&&cnt%2==1) ans+=k-1;
  cout << ans << endl;
  return 0;
}

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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define intMAX 1000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

int n;
int main(){
  cin >> n;
  vector<int>d(n);
  for(int i = 0; i < n; i++){
    cin >> d[i];
  }
  sort(all(d));
  int ans = d[n/2] - d[n/2 - 1];
  cout << max(ans, 0) << endl;
}

Measured memory_bytes: 640