akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
priority_queue<long long,vector<long long>,greater<long long> >q2;//后半部分
priority_queue<long long,vector<long long>,less<long long> >q1;//前半部分
long long sum1,sum2;//qian hou
int main()
{
    long long sum1=0,sum2=0;
    long long num=0;
    int op;
    int q;
    scanf("%d",&q);
    while(q--)
    {
        scanf("%d",&op);
        if(op==1)
        {
            long long temp1,temp2;
            scanf("%lld%lld",&temp1,&temp2);
            num+=temp2;
            if(!q1.size()||temp1<q1.top()) q1.push(temp1),sum1+=temp1;
            else q2.push(temp1),sum2+=temp1;
            //维持均匀
            while(q1.size()<q2.size())
            {
                //cout<<"*";
                long long temp;
                temp=q2.top();
                q2.pop();
                q1.push(temp);
                sum2-=temp;
                sum1+=temp;
            }
            while(q1.size()-1>q2.size())
            {
                long long temp;
                temp=q1.top();
                q1.pop();
                q2.push(temp);
                sum1-=temp;
                sum2+=temp;
            }
        }
        else
        {
            long long sum=q1.size()+q2.size();
            long long ans;
            if(q1.size()&&q2.size())
            ans=1LL*q1.top()*q1.size()-sum1+sum2-q1.top()*q2.size()+num;
            else if(q1.size())
            {
                ans=num;
            }
            printf("%lld %lld\n",q1.top(),ans);
        }
    }
}

Measured memory_bytes: 3828
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<u32>();
    let s = read::<String>().chars().collect::<Vec<_>>();
    let mut ans = vec![];
    for ch in s {
        let num = (ch.to_digit(36).unwrap() - 10 + n) % 26;
        ans.push(std::char::from_digit(10 + num, 36).unwrap());
    }
    for ch in ans {
        for c in ch.to_uppercase() {
            print!("{}", c);
        }
    }
    println!("");
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<utility>
#include<list>
#include<algorithm>
#include <ctype.h>
#include<deque>
using namespace std;
using ll = long long int;

int n;
vector<int> a;
bool use[9] = { false };
int main(void) {
	cin >> n;
	int ret = 0;
	int all = 0;
	for (int i = 0; i < n; i++) {
		int ai;
		cin >> ai;
		if (ai < 400) {
			if (use[0])
				continue;
			ret++;
			use[0] = true;
		}
		else if (ai < 800) {
			if (use[1])
				continue;
			ret++;
			use[1] = true;
		}
		else if (ai < 1200) {
			if (use[2])
				continue;
			ret++;
			use[2] = true;
		}
		else if (ai < 1600) {
			if (use[3])
				continue;
			ret++;
			use[3] = true;
		}
		else if (ai < 2000) {
			if (use[4])
				continue;
			ret++;
			use[4] = true;
		}
		else if (ai < 2400) {
			if (use[5])
				continue;
			ret++;
			use[5] = true;
		}
		else if (ai < 2800) {
			if (use[6])
				continue;
			ret++;
			use[6] = true;
		}
		else if (ai < 3200) {
			if (use[7])
				continue;
			ret++;
			use[7] = true;
		}
		else {
			all++;
		}
	}
	int r1 = ret, r2 = ret + all;
	if (r1 == 0)
		r1 = 1;
	cout << r1 << " " << r2 << endl;
	return 0;
}

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


int main() {
    int N;
    cin >> N;
    vector<string> S(N);
    int cnt = 0;
    for (int i=0; i<N; i++) {
        cin >> S[i];
        for (int j=0; j<(int)(S[i].size()-1); j++) {
            if (S[i][j] == 'A' && S[i][j+1] == 'B') cnt++;
        }
    }
    
    //あとは組み合わせでできるやつ足すだけ
    
    int cnt_A = 0, cnt_B = 0, cnt_AB = 0;
    int fuyasu = 0;
    
    for (int i=0; i<N; i++) {
        if (S[i][0] == 'B') cnt_B++;
        if (S[i][S[i].size()-1] == 'A') cnt_A++;
        if (S[i][0] == 'B' && S[i][S[i].size()-1] == 'A') cnt_AB++;
    }
    
    /*if (cnt_AB != cnt_A || cnt_AB != cnt_B) fuyasu = min(cnt_A, cnt_B);
    else fuyasu = cnt_AB - 1;*/
    
    if (cnt_AB != 0 && cnt_AB == cnt_A && cnt_AB == cnt_B) fuyasu = cnt_AB - 1;
    else {
        fuyasu = min(cnt_A, cnt_B);
        //cout << cnt_A << " " << cnt_B << endl;
    }
    cnt += fuyasu;
    
    
    cout << cnt << endl;
    
}

Measured memory_bytes: 768
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n;
    cin >> n;

    vl a(n);
    rep(i, n) {
        cin >> a[i];
    }
    sort(all(a));

    vl b(n);
    rep(i, n) {
        cin >> b[i];
    }
    sort(all(b));

    vl c(n);
    rep(i, n) {
        cin >> c[i];
    }
    sort(all(c));

    ll ans = 0;
    rep(i, n) {
        ll x = lower_bound(all(a), b[i]) - a.begin();
        ll y = upper_bound(all(c), b[i]) - c.begin();
        ans += x*(n-y);
    }

    out(ans);
    re0;
}

Measured memory_bytes: 2560
/******************************************************************************

Coder :         rajath_pai
date :          17/05/2020
Contest :       AtCoder Beginner Contest 168
problem :       A - ∴ (Therefore)
link :          atcoder.jp/contests/abc168

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

#define w(x)            int x;  cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define fo(i,a,b)       for(int i = a; i < b; i++)
//int tc = 0;
//printf("Case #%d: %d\n",tc,);

/*
    string binary = bitset<8>(input number).to_string(); //to binary
    cout<<binary<<"\n";

    unsigned long decimal = bitset<8>(binary).to_ulong();   //binary to decimal
    cout<<decimal<<"\n";
*/

int main(){
    FIO;
    //w(t)
       //tc++;
       int n;
       cin >> n;
  		n = n%10;
       if(n == 3){cout<<"bon";}
       else if(n == 0||n == 1||n ==6||n == 8){cout<<"pon";}
       else if(n == 2||n == 4||n ==5||n == 7||n==9){
           cout<<"hon";
       }
    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<iomanip>
using namespace std;
void x_y(int x,int y,int n){
  if(x>=n) x = 0;
  if(y>=n) y = 0;
  if(x<0) x = n - 1;
  //if(y<0) y = n - 1;
}  
int main(){
  int n;
  while(cin>>n){
    if(n==0) break;
    int magic[n][n];
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++) magic[j][i] = 0;
    }
    magic[n/2][n/2+1] = 1;
    int x = n / 2;
    int y = n / 2 + 1;
    int count = 1;
    //cout << x << ' ' << y << endl;
    while(count!=n*n){
      count++;
      //x_y(x+1,y+1,n);
      if(x+1>=n) x = 0;
      else x++;
      if(y+1>=n) y = 0;
      else y++;
      //cout << x << ' ' << y << endl;
      while(magic[x][y]!=0){
	//x_y(x-1,y+1,n);
	if(x-1<0) x = n - 1;
	else x--;
	if(y+1>=n) y = 0;
	else y++;
      } 
      magic[x][y] = count;
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	cout << setw(4) << magic[j][i];
      }
      cout << endl;
    }
  }
  return 0;
} 

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

using namespace std;

int main(){
    int n;
    int *ordinary;
    int count = 0;
    cin >> n;
    ordinary = new int[n];
    for (int i=0;i<n;i++){
        cin >> ordinary[i];
    }
    for (int i=0;i<n-2;i++){
        if (max(ordinary[i],ordinary[i+1]) == min(ordinary[i+1], ordinary[i+2])){
            count++;
        }else if(min(ordinary[i],ordinary[i+1]) == max(ordinary[i+1], ordinary[i+2])){ 
            count++;
        }
    }
    cout << count << endl;

    delete[] ordinary;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define endl '\n'
using namespace std;
struct dice {
    int v[6];
    void mov(const char c) {
        int buf;
        switch (c) {
            case 'N':
                buf = v[0];
                v[0] = v[1];
                v[1] = v[5];
                v[5] = v[4];
                v[4] = buf;
                break;
            case 'E': {
                buf = v[0];
                v[0] = v[3];
                v[3] = v[5];
                v[5] = v[2];
                v[2] = buf;
                break;
            }
            case 'W': {
                buf = v[0];
                v[0] = v[2];
                v[2] = v[5];
                v[5] = v[3];
                v[3] = buf;
                break;
            }
            case 'S': {
                buf = v[0];
                v[0] = v[4];
                v[4] = v[5];
                v[5] = v[1];
                v[1] = buf;
                break;
            }
            case 'R': {
                buf = v[1];
                v[1] = v[2];
                v[2] = v[4];
                v[4] = v[3];
                v[3] = buf;
            }
        }
    }
    int top() { return v[0]; }
    int right() { return v[2]; }
    int left() { return v[3]; }
    int front() { return v[1]; }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    dice d;
    for (int i = 0; i < 6; i++) {
        cin >> d.v[i];
    }
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        if (d.left() == a) {
            d.mov('E');
        }
        if (d.right() == a) {
            d.mov('W');
        }
        while(d.top() != a) {
            d.mov('N');
        }
        while(d.front() != b) {
            d.mov('R');
        }
        cout << d.right() << endl;
    }
    return 0;
}


Measured memory_bytes: 3124
#include <stdio.h>

int main(void)
{
  int A;
  int B;
  
  scanf("%d",&A);
  scanf("%d",&B);
  
  if(A <= B * 2){
    printf("%d",0);
  }
  else{
    printf("%d",A - B * 2);
  }
  return 0;
}

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

int     main() {
        int N, K;
        string S;
        cin >>N >>K >>S;
        int O=0;
        int C=0;
        for (int i=1; i<N; i++) {
                if (S.at(i-1)=='L') {
                        if (S.at(i)=='R')
                                O++;
                } else {
                        if (S.at(i)=='L')
                                C++;
                }
        }
        int KK=min(O, C);
        if (K<KK) {
                O -=K;
                C -=K;
                K=0;
                cout <<N-1-O-C <<endl;
        } else {
                O -=KK;
                C -=KK;
                K -=KK;
                int KKK=max(O, C);
                if (K<KKK)
                        KKK -=K;
                else
                        KKK=0;
                cout <<N-1-KKK <<endl;
        }
        return 0;
};

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

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

Measured memory_bytes: 3752
from itertools import accumulate
Q = int(input())
ans = []
def eratosthenes(N):
    searchList = [i for i in range(2,N)]
    primeNum = []


    mx = int(N**0.5+1)
    while searchList[0] <= mx:
        primeNum.append(searchList[0])
        tmp = searchList[0]
        searchList = [i for i in searchList if i%tmp != 0]
    primeNum.extend(searchList)
    return primeNum

ok = [0]*(10**5+1)
primeNum = eratosthenes(10**5+1)
primeNumLst = [False] * (10**5+1)

for p in primeNum:
    primeNumLst[p] = True

for p in primeNum:
    if primeNumLst[(p+1)//2]:
        ok[p] = 1
    
ok = list(accumulate(ok))

for _ in range(Q):
    l, r = map(int, input().split())
    ans.append(ok[r] - ok[l-1])
    
print("\n".join(map(str,ans)))

Measured memory_bytes: 17928
#include <bits/stdc++.h>
#define INF 9223372036854775807
using namespace std;
signed long long N;
signed long long v;
string S;
void solve() {
  N = 0;
  scanf("%lld", &N);
  if(N == 0) {
    cout << 0 << endl;
    return;
  }

  v = 1;
  while(N) {
    if(N%(2*abs(v))){
      S = S + "1";
      N = N - v;
    } else {
      S = S + "0";
    }
    v = v * -2;
  }
  reverse(S.begin(), S.end());
  cout << S << endl;
}

int main(int arg, char* argv[]) {
  solve();
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	void main() {
		Scanner sc=new Scanner(System.in);
			for(;;) {
				int x = sc.nextInt();
				int y = sc.nextInt();
				if(x==0 && y==0)break;
				if(x>y) {
					System.out.println(y+" "+x);
				}
				else {
					System.out.println(x+" "+y);
				}
			}
	}
	
	public static void main(String[] args) {
		new Main().main();
	}

}


Measured memory_bytes: 36632
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  int x,a,b;
  cin>>x>>a>>b;
  cout<<(x-a)%b<<endl;
}

Measured memory_bytes: 3564
n = int(input())
c = [-1] + [int(input()) for i in range(n)]

count = [0]*(200005)
dp = [0]*(n+1)
dp[0] = 1
mod = 10**9+7
#dp[i]: i番目までの場合の数
for i in range(n):
    dp[i+1] = dp[i]
    if c[i+1] != c[i]:
        dp[i+1] += count[c[i+1]]
        dp[i+1] %= mod
        count[c[i+1]] += dp[i]
        count[c[i+1]] %= mod

print(dp[n]%mod)


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

#define INF 210000000
#define int long long

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

int lcm(int a, int b) { return a * b / gcd(a, b); }
void solve(){
    string s;
    cin >> s;
    map<char,int> cnt;
    for(int i=0;i<s.length();i++){
        cnt[s[i]]++;
    }
    string ans = "Yes";
    for(auto& a : cnt){
        if(a.second % 2 != 0){
            ans = "No";
            break;
        }
    }
    cout << ans;
}
signed main() {
    solve();
}



Measured memory_bytes: 256
N=int(input())
a = []
for i in range(N):
    l = tuple(map(int,input().split()))
    a.append(l)
a = sorted(a, key= lambda x: (x[1],x[0]) )
sm = 0
f = True
for aa in a:
    x,y = aa
    sm += x
    if sm > y:
        f = False
        break

print("Yes" if f else "No")

Measured memory_bytes: 88280
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a;
    cin >> a;
    
    int on=a/1000;
    int tw=  (a%1000) /100;
    int th = (a%100)/10;
    int fo = a-(on*1000+tw*100+th*10);
    
    
    if(on== tw&& tw == th)
    {
        cout << "Yes" << endl;
    }
    else if(tw == th && th == fo)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
}


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

using namespace std;

int main() {
  int n; cin >> n;
  string s; cin >> s;
  string ans = "";
  for(int i=0;i<(int)(s.size());++i) {
    ans.push_back((s[i]-'A'+n)%26 + 'A');
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
// #pragma GCC target("avx2")
#pragma GCC optimize("O3", "unroll-loops")

// #include <bits/extc++.h>
// using namespace __gnu_pbds;

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

#define int long long
#define double long double
// template <typename T>
// using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using pii = pair<int, int>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using Prior = priority_queue<T>;

#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back

#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define RANDOM() random_device __rd; \
                 mt19937 __gen = mt19937(__rd()); \
                 uniform_int_distribution<int> __dis(1, 1E8); \
                 auto rnd = bind(__dis, __gen)

const int INF = 1E18;
const int mod = 1E9 + 7;

int32_t main() {
    fastIO();
    
    int k, s, ans = 0;
    cin >> k >> s;
    
    for (int i = 0; i <= k; ++i) {
        if (0 <= s-i and s-i <= 2*k) {
            ans += min(s-i, k) - max(s-i-k, 0LL) + 1;
            // cerr << min(s-i, k) - max(s-i-k, 0LL) + 1 << "\n";
        }
    }
    
    cout << ans << "\n";
    
    return 0;
}

Measured memory_bytes: 256
// ~/Remember,remember the 6th of March

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double  EPS = 1e-8;
const ll MOD = 1000000007;
const int N = 100000 + 7;

int main()
{
    int a,b;
    cin>>a>>b;
    if(b==1)
    {
        cout<<0<<endl;
        return 0;
    }
    int i=1;
    while((a-1)*i<b&&((a-1)*i)+1<b)
        i++;
    cout<<i<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdtr1c++.h>
// typedef __int128 int128;
// typedef __float128 float128;

using namespace std;
using namespace rel_ops;
typedef long long ll;
typedef long double ld;
typedef complex<ld> pt;
typedef vector<pt> pol;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<ld> vd;
typedef vector<vd> vvd;
typedef pair<ll, ll> pii;
typedef vector<pii> vpii;
#define pb push_back

int main(){

  // freopen("A.in", "r", stdin);

  ll N, D;

  vvi X;

  cin >> N >> D;

  for (ll i = 0; i < N; ++i) {
    vi Xi;
    for (ll j = 0; j < D; ++j) {
      ll Xij;
      cin >> Xij;
      Xi.pb(Xij);
    }
    X.pb(Xi);
  }

  ll sol = 0;
  for (ll i = 0; i < N; ++i) {

    for (ll j = i+1; j < N; ++j) {
      ll dist = 0;
      for (ll k = 0; k < D; ++k) {
        dist += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
      }
      if(floor(sqrt(dist)) - sqrt(dist) == 0){
        sol++;
      }
    }


  }
  cout << sol << endl;

}


Measured memory_bytes: 256
from functools import reduce
from fractions import gcd

MOD = 10**9+7

def lcm_base(x, y):
    return x * (y // gcd(x, y))

def main():
    N = int(input())
    a = [int(i) for i in input().split()]

    lcm = reduce(lcm_base, a, 1)
    
    ans = 0
    for i in a:
        ans += lcm // i

    print(ans % MOD)


if __name__ == "__main__":
    main()


Measured memory_bytes: 6108
//Author: Rahul Purohit

#include<bits/stdc++.h>
#define vi vector<int>
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define ll  long long int
#define pi pair<ll,ll>
#define f first
#define mp make_pair
#define mod 1000000007
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
int gcd(int a, int b)
{
	if(b==0)
		return a;
	else
		return (b,a%b);
}
/*ll isp[N]={1};
void sieve(int n)
{
	isp[0]=isp[1]=0;
	for(int i=2;i<=n;i++)
	{
		if(isp[i]==1)
		{
			for(int j=i*i;j<=n;j+=i)
			{
				isp[j]==0;
			}
		}
	}
}*/
ll pow(int x,int  y,int m)
{
	ll ans=1;
	while(y!=0)
	{
		if(y%2==1)
		{
			ans=(ans*x)%m;
		}
		x=(x*x)%m;
		y/=2;
	}
	return ans;
}
template <class x>
void swap(x &a,x &b)
{
	x tp;
	tp=a;
	a=b;
	b=tp;
}
int main(void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    
    ll n;
    cin>>n;
    cout<<(n-2)*180;
    return 0;
}


Measured memory_bytes: 256
def gcd(a,b):
    while b > 0:
        a, b = b, a%b
    return a

def gcd_list(lst):
    g = lst[0]
    for i in range(1,len(lst)):
        g = gcd(g,lst[i])
    return g
    
n, k = (int(i) for i in input().split())
a = list(int(i) for i in input().split())  

maxA=max(a)

if (k <= maxA and k%gcd_list(a) == 0) or (k in a):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
    

Measured memory_bytes: 14480
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long int
#define pb push_back
#define mk make_pair
#define flp(i, k, n) for(int i=k; i<n; i++)
#define rev(i, k) for(int i=k; i>=0; i--)
#define F first
#define S second
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int dx[4] = {-1,1,0,0};
int dy[4] = {0,0,-1,1};

int32_t main(void)
{
    int n;
    cin>>n;
    int a[n];
    int ct[n]={0};
    a[0]=-1;
    flp(i, 1, n) cin>>a[i];
    bool vis[n]={false};
    vis[0]=true;

    flp(i, 1, n)
    {
        ct[a[i]-1]++;
    }

    flp(i, 0, n)
    cout<<ct[i]<<"\n";
    return 0;


}

Measured memory_bytes: 6888
import copy
from bisect import bisect_left
N=int(input())
la=list(map(int,input().split()))
ll=copy.copy(la)
#lr=copy.copy(la)
for i in range(1,N):
    ll[i]+=ll[i-1]
#for i in range(N-2,-1,-1):
#    lr[i]+=lr[i+1]
inl=bisect_left(ll,ll[-1]/2)
ds=ll[-1]/2-ll[inl-1]
db=ll[inl]-ll[-1]/2
if ds<=db:
    print(ll[-1]-ll[inl-1]*2)
else:
    print(ll[inl]*2-ll[-1])


Measured memory_bytes: 26172
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

bool A[1000000];
 
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    rep(i,1000000) A[i] = true;
    A[0] = A[1] = false;
    for (int i = 2; i < 1000000; i++) {
        if (A[i]) {
            for (int j = 2; j*i < 1000000; j++) A[j*i] = false;
        }
    }
    while (true) {
        int a,d,n; cin >> a >> d >> n;
        if (a == 0 && d == 0 && n == 0) break;
        
        int i = -1;
        while (n > 0) {
            i++;
            if (A[a+i*d]) n--;
        }

        cout << a+i*d << endl;
    }
}


Measured memory_bytes: 4012
//Author: intoabhi

#include<iostream>
using namespace std;

int main(){

	ios_base::sync_with_stdio(false);
    cin.tie(NULL);


	string s;
	cin>>s;

	int c=0;
	int len=s.size()/2;
	if(s.size()%2==0){
		for(int i=len-1,j=len; j<s.size() && i>=0; i--, j++){
				if(s[i] != s[j]){
					c++;
				}
			}
		}	
	

	else {
		for(int i=len-1,j=len+1; j<s.size() && i>=0; i--, j++){
				if(s[i] != s[j]){
					c++;
				}
			}

	}

	cout<<c<<endl;
	

}


Measured memory_bytes: 256
import math

summation = 0

K = int(input())
for i in range(1, K + 1):
    for j in range(1, K + 1):
        gcd_i_j = math.gcd(i, j)
        for k in range(1, K + 1):
            gcd = math.gcd(gcd_i_j, k)
            summation += gcd

print(summation)

Measured memory_bytes: 9184
#include<iostream>
using namespace std;
int m,n,a[1001];
int main(){
	cin>>m>>n;
	for(int i=0;i<n;i++){
   int x,y;
		cin>>x>>y;
		a[x]++;
		a[y]++;
	}
	for(int i=1;i<=m;i++)cout<<a[i]<<endl;
	return 0; 
}

Measured memory_bytes: 256
import sys
tmp=input().split()
a=int(tmp[0])
b=int(tmp[1])
c=int(tmp[2])
d=int(tmp[3])
da=a-b
db=b-c
dc=c-a
if a-b<0:
    da=b-a
if b-c<0:
    db=c-b
if c-a<0:
    dc=a-c
if dc<=d or da<=d and db<=d:
    print('Yes')
    sys.exit()
print('No')


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf INT_MAX
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(int *)a-*(int *)b;
}

int main(void){
	char s[1001],t[1001],w[1001];
	int i,j,f=0;
	chin(s);
	chin(t);
	for(i=0,j=0;i<strlen(s);i+=2,j++){
		w[j]=s[i];
	}
	w[j]=0;
	for(i=0,j=0;i<strlen(t)&&j<strlen(w);i++){
		if(t[i]==w[j]){
			j++;
		}
	}
	if(j==strlen(w)){
		f=1;
	}
	for(i=1,j=0;i<strlen(s);i+=2,j++){
		w[j]=s[i];
	}
	w[j]=0;
	for(i=0,j=0;i<strlen(t)&&j<strlen(w);i++){
		if(t[i]==w[j]){
			j++;
		}
	}
	if(j==strlen(w)){
		f=1;
	}
	puts(f?"Yes":"No");
	return 0;
}

Measured memory_bytes: 524
/* _________________________________________________________________________________________________
  |                                                                                                 |
  |                             Author      : Aditya Ahuja                                          |
  |                             Date        : Mon, 13th Jan 2020                                    |
  |_________________________________________________________________________________________________|
*/
 
#include<bits/stdc++.h>
using namespace std;

// #define int long long

#define pb          push_back
#define F           first
#define S           second
#define endl        "\n"
#define rep(i,a,b)  for(int i = a; i < (int)b; i++)
#define req(i,a,b)  for(int i = (int)b - 1; i >= a; i--)
#define all(a)      (a).begin(),(a).end()
#define ret(x)      {cout << x << endl; return;}
#define sz(x)       (int)x.size()
#define type(x)     typeid(x).name()

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;

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

#ifdef LOCAL
	#define wa(x)       cerr << (#x) << " --- " << (x) << endl
	#define pvi(v)      {for(auto it:v) cerr << it << " "; cerr << endl;}
	#define line1	    cerr << "---------------------------" << endl;
#else
	#define wa //
	#define line1 //
	#define pvi //
	#define printf //
#endif

void solve();
signed main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cout << fixed << setprecision(10);

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

//___________________________________________________________________________________________________

void solve() {

	int n,k;
	cin >> n >> k;

	vi a(n,0);
	rep(i,0,n) cin >> a[i];

	vi dp(n,1e9+5);
	dp[0] = 0;
	dp[1] = abs(a[0] - a[1]);

	rep(i,2,n){
		rep(j,1,k+1){
			if(i-j >= 0)dp[i] = min(dp[i], dp[i-j] + abs(a[i-j] - a[i]));
		}
	}

	ret(dp[n-1]);
}


Measured memory_bytes: 1024
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        (n, m): (usize, usize),
        aa: [usize; m]
    };

    let mut sum = 0;
    for a in aa {
        sum += a;
    }

    if n < sum {
        println!("-1");
    } else {
        println!("{}", n - sum);
    }
}


Measured memory_bytes: 2256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <math.h>
typedef long long ll;
using namespace std;
 
int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	int i = 0;
	for (i = 0; i < n; i++)
	{
		if (a[i] % 2 == 0)
		{
			if (!((a[i]%3 == 0) || (a[i] % 5 == 0))) break;
		}
	}
 
	cout << ( (i == n) ? "APPROVED" : "DENIED" ) << endl;

}	

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

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pair<ll,ll>> vii;
typedef vector<vii> vvii;
typedef pair<ll,ll> ii;

#define pb push_back
#define mp make_pair
#define sz(vs) (ll)(vs.size())
#define rep(i,a,b) for (ll i=a;i<b;i++)
#define iter(i,c) for (auto i:c)
#define ss second
#define ff first
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define DEBUG2(x,a) cout << '>' << #x << ':' << x << " >" << #a << ':' << a <<  endl;
#define DEBUG3(x,a,b) cout << '>' << #x << ':' << x << " >" << #a << ':' << a << " >" << #b << ':' << b << endl;
#define DEBUG4(x,a,b,c) cout << '>' << #x << ':' << x << " >" << #a << ':' << a << " >" << #b << ':' << b << " >" << #c << ':' << c << endl;
#define printstr(a,st,e,s) if (st<e) {cout<<s<<a[st];rep(noname,st+1,e) cout<<""<<a[noname];}cout<<"\n"
#define printarr1(a,st,e,s) if (st<e) {cout<<s<<a[st];rep(noname,st+1,e) cout<<" "<<a[noname];}cout<<'\n'
#define printarr(a,st,e,s) cout<<s<<": [";if (st<e) {cout<<a[st];rep(noname,st+1,e) cout<<", "<<a[noname];}cout<<"]\n"
#define printus(c,s) cout<<s<<": {";for (auto noname:c) cout<<noname<<",";cout<<"}\n"
#define printum(c,s) cout<<s<<": {";for (auto noname:c) cout<<noname.first<<":"<<noname.second<<", ";cout<<"}\n"
#define MAXN 102
#define mod 1000000007
 
ll n, m, k, a[MAXN];
string s;
char c;

void solve() {
	cin>>n;
	cout<<(n+n*n+n*n*n)<<endl;
}
 
void aux() {
}
 
int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	aux();
	ll _ = 1;
	// cin>>_;
	while(_--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 3632
from collections import defaultdict

n,k = map(int,input().split())
a = list(map(int,input().split()))
mod = 10**9 + 7
d = defaultdict(int)

inner = 0
for i in range(n):
    d[a[i]] += 1
    for j in range(i+1,n):
        if a[i] > a[j]:
            inner += 1

t = 0
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            t += 1

x = ((t)*(k)*(k-1))//2
y = inner*k
print(int((x+y)%mod))


Measured memory_bytes: 9552
#include <stdio.h>
int main(void) {
  int n, p, walk1, walk2, maxp, maxw, i;
  while(scanf("%d",&n),n) {
    maxp = 0; maxw = 0;
    scanf("%d",&maxp);
    scanf("%d",&walk1); maxw += walk1;
    scanf("%d",&walk2); maxw += walk2;
    for(i = 1; i < n; i++ ) {
      scanf("%d",&p);
      scanf("%d",&walk1);
      scanf("%d",&walk2);
      if(walk1 + walk2 > maxw ) {
	maxp = p;
	maxw = walk1 + walk2;
      }
    }
    printf("%d %d\n",maxp,maxw);
  }
  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>

using namespace std;
short int result = 0;
short int *color; /*
    0 - black
    1 - grey
    2 - white
*/

vector<short int> *g; // Graph

void DFS(short int v){
    int node;
    color[v] = 1;

    for(short int i = 0; i < g[v].size(); i++){
        node = g[v].at(i);

        if(color[node] == 1){
            result = 1;
        }
        if(color[node] == 2){
            DFS(node);
        }
    }
    color[v] = 0;

};


int main() {

    short int E; // number of transitions
    short int s, t; // transitions
    short int V; // number of nodes

    // get properties of Graph
    cin >> V >> E;

    color = new short int[V];
    g = new vector<short int>[V];


    // fill Graph
    for(short int i = 0; i < E; i++){
        cin >> s >> t;
        g[s].push_back(t);
    }
    for(short int i = 0; i < V; i++){
        color[i] = 2;
    }
    for(short int i = 0; i < V; i++){
        if(color[i] == 2){
            DFS(i);
        }
    }

    cout << result << endl;

    return 0;
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;
const int N = 1e6+10;

ll n,k,A[N],F[N];

bool chk(ll x){
	ll t = 0;
	for(int i=0;i<n;++i){
		ll m = x / F[n-i-1];
		if(A[i] > m){
			t += A[i] - m;
			if(t > k) return false;
		}
	}
	return true;
}

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

	cin >> n >> k;
	for(int i=0;i<n;++i) cin >> A[i];
	for(int i=0;i<n;++i) cin >> F[i]; 
	sort(A, A+n);
	sort(F, F+n);
	ll l=0,r=0;
	for(int i=0;i<n;++i) r = max(r, A[i]*F[n-i-1]);
	while(l<=r){
		ll mid = (l+r)/2;
		if(chk(mid)) r = mid-1;
		else l = mid + 1;
	}
	cout << l << endl;
	return 0;
}



Measured memory_bytes: 5888
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O0")
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1e9+7;
const ll INF = 1e18;
#define All(a) (a).begin(),(a).end()
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  chrono::system_clock::time_point start,end;
  start = chrono::system_clock::now();

  string s, t;
  cin >> s >> t;
  ll ans = INF;
  rep(i,s.size()-t.size()+1) {
    ll tmp = 0;
    rep(j, t.size()) {
      if (s[i+j] != t[j]) ++tmp;
    }
    ans = min(ans, tmp);
  }
  cout << ans << '\n';

  end = chrono::system_clock::now();
  auto elapsed = chrono::duration_cast< chrono::milliseconds >(end - start).count();
  cerr << elapsed << "ms" << '\n';
}

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

int main(){
    ll n, a, b;
    ll s, l;
    cin>>n>>a>>b;
    s = min(a,b);
    l = max(a,b);

    if(l%2 == s%2){
        ll aaa = (l-s)/2;
        cout<<aaa;
    }
    else{
        if(n-l<s-1){
            cout<<(n-l)+(-s+l-1)/2+1;
        }
        else{
            cout<<(s-1)+(l-1-s+1-1)/2+1;
        }
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){

	Scanner sc = new Scanner(System.in);

	int n1 = Integer.parseInt(sc.next());
	int n2 = Integer.parseInt(sc.next());
	int n3 = Integer.parseInt(sc.next());

        String result;

	if(n1 == n2){
	    if(n1 == n3){
		result = "No";
	    } else {
		result = "Yes";
	    }
	} else if(n1 == n3){
	    result = "Yes";
        } else if(n2 == n3) {
	    result = "Yes";
	} else {
	    result = "No";
	}
    
	System.out.println(result);

    }
}

Measured memory_bytes: 22740
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

int main(){
  int k;
  cin >> k;
  int cnt = 0;
  queue<ll> que;
  ll now;
  for(int i = 1; i <= 9; ++i)que.push(i);
  while(cnt != k){
    now = que.front();
    que.pop();
    if(now % 10 != 0)que.push(now * 10 + (now % 10) - 1);
    que.push(now * 10 + (now % 10));
    if(now % 10 != 9)que.push(now * 10 + (now % 10) + 1);
    ++cnt;
  }

  cout << now << endl;
  return 0;
}


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

int main(){
  int T;
  cin >> T;
  while(T--){
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    bool app[26] = {};

    for(int i = 0; i < H; ++i){
      cin >> S[i];
      for(int j = 0; j < W; ++j){
        if(S[i][j] == '.') continue;
        app[S[i][j]-'A'] = true;
      }
    }
    string A;
    for(int i = 0; i < 26; ++i)
      if(app[i]) A.push_back('A'+i);
    map<char,int> L, R, T, B;
    const int INF = 1e9;
    for(auto c : A){
      L[c] = INF;
      T[c] = INF;
    }
    for(int i = 0; i < H; ++i){
      for(int j = 0; j < W; ++j){
        char c = S[i][j];
        if(c == '.') continue;
        L[c] = min(L[c],j);
        R[c] = max(R[c],j);
        T[c] = min(T[c],i);
        B[c] = max(B[c],i);
      }
    }
    
    auto judge = [&](){
                   map<char,size_t> O;
                   for(size_t i = 0; i < A.length(); ++i)
                     O[A[i]] = i;
                   for(auto c : A){
                     for(int i = T[c]; i <= B[c]; ++i){
                       for(int j = L[c]; j <= R[c]; ++j){
                         if(S[i][j] == '.' or O[S[i][j]] > O[c])
                           return false;
                       }
                     }
                   }
                   return true;
                 };
    
    string ans = "SUSPICIOUS";
    do{
      if(judge()){
        ans = "SAFE";
        break;
      }
    }while(next_permutation(A.begin(), A.end()));
    cout << ans << endl;
  }
}



Measured memory_bytes: 2996
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int a=0;
        if((N-1)%(K-1)!=0){
            a = K-1;
        }
        int res = (N-1+a)/(K-1);
        

        
        System.out.println(res);
        }
    }

Measured memory_bytes: 35424
#include <iostream>
#include <algorithm>
#include <cstdio>
#define INF 0x3f3f3f3f
using namespace std;
int N,A,B,C,ans=INF;
int s[10];
void dfs(int n,int a,int b,int c,int col)
{
    if(n==N)
    {
        if(a&&b&&c)
            ans=min(ans,abs(a-A)+abs(b-B)+abs(c-C)+col);
        return;
    }
    dfs(n+1,a,b,c,col);
    dfs(n+1,a+s[n],b,c,col+10*(a>0));
    dfs(n+1,a,b+s[n],c,col+10*(b>0));
    dfs(n+1,a,b,c+s[n],col+10*(c>0));
}
int main()
{
    scanf("%d",&N);
    scanf("%d%d%d",&A,&B,&C);
    for(int i=0;i<N;i++)
        scanf("%d",&s[i]);
    dfs(0,0,0,0,0);
    cout << ans;
    return 0;
}


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

MOD = 10**9+7

def cmb(n,r,mod):        
    ret=1
    div = min(r,n-r)
    for i in range(div):        
        ret=ret*(n-i)*pow(div-i,mod-2,mod)%mod
        
    return ret % mod

ans = 1
ans = ans * pow(2,n,MOD)
ans = (ans - 1) % MOD

ans = (ans - cmb(n,a,MOD))%MOD
ans = (ans - cmb(n,b,MOD))%MOD

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
typedef pair<int,int> P;
struct edge{int to, id;};
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mod 1000000007
 
using graph = vector<vector<ll>>;

int main(){
    ll n;
    cin >> n;
    ll a[n];
    rep(i,n){
        ll temp;
        cin >> temp;
        a[i] = temp;
    }
    ll ans = 0;
    ll prev = a[0];
    if(n == 0) ans = 0;
    else{
        for(int i = 1; i < n; i++){
            if(a[i] < prev){
                ans += prev - a[i];
            }
            else{
                prev = a[i];
            }
        }
    }
    cout << ans << endl;
    
}

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

int main(){
	int n, k;
	cin >> n >> k;
	vector<int> ks(k+2);
	vector<int> ns(n+2);
	ns.at(0) = 0;
	ns.at(1) = 1;
	rep(i, k) cin >> ks.at(i);
	int kp = 0;
	ks.at(k+1) = 1000000;
	for(int i=2; i<n+2; i++){
    	int f = 0;
    	if(i-1 == ks.at(kp)){
          f = 1;
          kp++;
        }
    	if(f == 0){
	    	ns.at(i) = ns.at(i-2) + ns.at(i-1);
          	if(ns.at(i) >= 1000000007) ns.at(i) %= 1000000007;
        }else{
        	ns.at(i) = 0;
        }
    }
    cout << ns.at(n+1) << endl;
}

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

int main () {
  int N, A, B;
  cin >> N >> A >> B;
  
  if (N * A > B) {
    cout << B << endl;
  }
  else if (N * A < B) {
    cout << N * A << endl;
  }
  else {
    cout << B << endl;
  }
}
    

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

double cost(double r1, double r2)
{
	return sqrt((r1 + r2) * (r1 + r2) - (r1 - r2) * (r1 - r2));
}

int main(void)
{
	int N;
	vector<int>r;
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		int rr; cin >> rr; r.push_back(rr);
	}

	vector<double>place(1, 0.);
	for (int i = 1; i < N; ++i)
	{
		double big = 0;
		for (int j = 0; j < i; ++j)
		{
			big = max(big, place[j] + cost(r[j], r[i]));
		}
		place.push_back(big);
	}
	double head = 0, tail = 0;
	for (int i = 0; i < place.size(); ++i)
	{
		head = min(head, place[i] - r[i]);
		tail = max(tail, place[i] + r[i]);
	}
	cout.precision(15);
	cout << tail - head << endl;
	return 0;
}

Measured memory_bytes: 3276
import java.io.*;
import java.util.*;
 class Main
{
public static void main(String arg[])
{
Scanner s=new Scanner(System.in);
int a=s.nextInt();
int b=s.nextInt();
if(a>=1 && a<=9 && b>=1 && b<=9)
System.out.println(a*b);
else
System.out.println("-1");}}

Measured memory_bytes: 25044
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
   NodePointer cur = nil->next;
   while(1){
   if ( cur == nil ) break; 
   if(cur->key == key) return cur;
   cur = cur->next;
   }
   return 0;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  if(t == nil) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  NodePointer t = nil->prev;
  if ( t == nil ) return;
  deleteNode(t);
}

void delete(int key){
  NodePointer t;
  t = listSearch(key);
  if(t == 0) return;
  deleteNode(t);
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;

  x->next = nil->next;
  nil->next->prev = x;
  x->prev = nil;
  nil->next = x;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}



Measured memory_bytes: 32952
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        H, W, K = map(int, input().split())
        s = [list(input().rstrip()) for _ in range(H)]

        ichigo = 0
        k = 1
        ans = []
        for _ in range(H):
            ans.append([0] * W)

        for i in range(H):
            flag = False
            for j in range(W):
                if s[i][j] == '#':
                    flag = True
                    ichigo += 1
                    if ichigo == 1:
                        ans[i][j] = k
                    elif ichigo == 2:
                        k += 1
                        ans[i][j] = k
                        ichigo = 1
                else:
                    ans[i][j] = k
            if flag:
                ichigo = 0
                k += 1
            else:
                ans[i] = [0] * W

        copy = [0] * W
        for i in range(H):
            if ans[i][0] == 0:
                ans[i] = copy
            else:
                copy = ans[i]

        copy = [0] * W
        for i in range(H)[::-1]:
            if ans[i][0] == 0:
                ans[i] = copy
            else:
                copy = ans[i]

        for i in range(H):
            print(*ans[i])


# Run main
if __name__ == '__main__':
    AtCoder().main()


Measured memory_bytes: 50524
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstdlib>
#include <cmath>
#define MAX 1000000000000000000LL

using namespace std;
int main(){
    int X;
    cin>>X;
    int i=1;
    int ans=0;
    while(1){
        ans+=i;
        if(ans>=X){
            cout<<i<<endl;
            break;
        }
        else i++;
    }
    return 0;
}

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

using namespace std;

int main(void) {
  int N; cin >> N;
  int min = N;
  int ans = 0;

  for (int i = 0; i < N; i++) {
    int p; cin >> p;
    if (p < min) min = p;
    if (min >= p) ans++;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
  long long n,max=0,min=1000000001;
  cin >> n;
  for(int i=0;i<n;i++){
    long long a;
    cin >> a;
    if(a>max)max=a;
    if(a<min)min=a;
  }
  cout << abs(max-min) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> P;

int main(void) {
  int N, M;
  cin >> N >> M;
  vector<long long> A(N);
  vector<P> v;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    v.push_back(P(A[i], 1));
  }
  for (int i = 0; i < M; i++) {
    long long B, C;
    cin >> B >> C;
    v.push_back(P(C, B));
  }
  sort(v.begin(), v.end(), greater<P>());
  long long ans = 0;
  for (int i = 0, j = 0; i < N; j++) {
    while (v[j].second > 0 && i < N) {
      ans += v[j].first;
      v[j].second--;
      i++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 7280
#include <iostream>
using namespace std;
int num, temp;
int count = 0;
int flag = 1;

void print(int array[]) {
    for (int i = 0; i < num; i++) {
        if (i == num - 1) {
            cout << array[i] << endl;
        } else {
            cout << array[i] << " ";
        }
    }
}

    int main() {
        cin >> num;
        int array[num] = {};
        for (int i = 0; i < num; i++) {
            cin >> array[i];
        }
        while(flag) {
            flag = 0;
        for (int i = 0; i < num - 1; i++) {
                if (array[i] > array[i + 1]) {
                    temp = array[i + 1];
                    array[i+1] = array[i];
                    array[i] = temp;
                    count++;
                    flag++;
                }
            }

        }
        print(array);
        cout << count << endl;
        return 0;
    }


Measured memory_bytes: 3112
#include<stdio.h>
#include<string.h>
int main()
{
	char a[25];
	scanf("%s",&a);
	for(int i=0;i<=18;i++)
	{
		if(i==5||i==13)
		{
			printf(" ");
		}
	else printf("%c",a[i] );
	}
}

Measured memory_bytes: 504
#include <cstdio>
#define MAX 200000
#define SENTINEL 2000000000
typedef long long llong;
using namespace std;

int L[MAX/2+2],R[MAX/2+2];

llong merge(int A[],int n,int left,int mid,int right)
{
	int i,j,k;
	llong cnt=0;
	int n1=mid-left;
	int n2=right-mid;
	for(i=0;i<n1;++i)L[i]=A[left+i];
	for(i=0;i<n2;i++)R[i]=A[mid+i];
	L[n1]=R[n2]=SENTINEL;
	i=j=0;
	for(k=left;k<right;k++)
	{
		if(L[i]<=R[j])
		{
			A[k]=L[i++];
		}
		else
		{
			A[k]=R[j++];
			cnt+=n1-i;// =mid+j-k-1
		}
	}
	return cnt;
}

llong mergeSort(int A[],int n,int left,int right)
{
	int mid;
	llong v1,v2,v3;
	if(left+1<right)
	{
		mid=(left+right)/2;
		v1=mergeSort(A,n,left,mid);
		v2=mergeSort(A,n,mid,right);
		v3=merge(A, n, left, mid, right);
		return v1+v2+v3;
	}
	else return 0;
}

int main()
{
	int A[MAX],n,i;
	
	while(scanf("%d",&n)==1)
	{
		for(i=0;i<n;i++)scanf("%d",&A[i]);
		llong ans=mergeSort(A,n,0,n);
		printf("%lld\n",ans);
	}
	
}

Measured memory_bytes: 4292