akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, a[2020] = {}, c[2020] = {}, z = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i], c[a[i]]++;
    for (int i = 1; i <= 2000; i++) c[i] += c[i - 1];
    for (int i = 1; i <= n; i++) for (int j = i + 1; j <= n; j++) {
        z += c[2000] - c[a[i] + a[j] - 1];
    }
    cout << 1ll * n * (n - 1) * (n - 2) / 6 - z;
}


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

#define f first 
#define s second 
#define pb push_back               
#define mp make_pair 

using namespace std;                    

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

const int N = (int)1e5 + 123, mod = (int)1e9 + 7, inf = (int)1e9;

int main(){
	int n;
	string s, t, ans;
	cin >> n;
	cin >> s >> t;

	for(int i = 0; i <= n; i++){
		string c = s.substr(0, n - i) + t;
		bool ok = 1;
		cerr << c << endl;
		for(int j = 0; j < n; j++)
			if(c[j] != s[j])
				ok = 0; 		
		if(ok)
			ans = c;
	}   
	cout << ans.size();
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

using P = pair<ll, ll>;

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  while (cin >> N) {
    vector<ll> A(N), B(N);
    for (int i = 0; i < N; i++) cin >> A[i] >> B[i];
    vector<P> ps(N);
    for (int i = 0; i < N; i++) ps[i] = P(B[i], A[i]);
    sort(ps.begin(), ps.end());
    ll R = 0;
    bool res = true;
    for (auto &p : ps) {
      ll b = p.fst, a = p.snd;
      if (R + a <= b) {
        R += a;
      } else {
        res = false;
        break;
      }
    }
    cout << (res ? "Yes" : "No") << endl;
  }
  return 0;
}


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

typedef long long ll;
const int N = 1e5 + 10;
ll n, Q, m, q[N], x, f[N], ans[N];

void solve(ll x, ll v) {
    int k = upper_bound(q + 1, q + m + 1, x) - q - 1;
    if (!k) {
        ans[1] += v, ans[x + 1] -= v;  // 提前累计
        return;
    }
    f[k] += v * (x / q[k]), solve(x % q[k], v);
}

int main() {
    cin >> n >> Q;
    q[++m] = n;
    rep(i, 1, Q) {
        scanf("%lld", &x);
        while (m && q[m] >= x) --m;
        q[++m] = x;
    }

    f[m] = 1;
    for (int i = m; i >= 2; i--)
        f[i - 1] += f[i] * (q[i] / q[i - 1]), solve(q[i] % q[i - 1], f[i]);

    ans[1] += f[1], ans[q[1] + 1] -= f[1];
    rep(i, 1, n) ans[i] += ans[i - 1], printf("%lld\n", ans[i]);
    return 0;
}


Measured memory_bytes: 6076
#include <bits/stdc++.h>
using namespace std;
int main() {
    int h, w;
    cin >> h >> w;
    string s[h];
    for (int i = 0; i < h; i++) cin >> s[i];
    for (int i = 0; i < w + 2; i++)
        cout << '#';
    cout << endl;
    for (int i = 0; i < h; i++)
        cout << '#' << s[i] << '#' << endl;
    for (int i = 0; i < w + 2; i++)
        cout << '#';
}

Measured memory_bytes: 3548
#include<bits/stdc++.h>
using namespace std;
#define INF 100000000
int main(){
  int n,t;
  int ans=INF;
  cin>>n>>t;
  for(int i=0;i<n;i++){
    int a,b;
    cin>>a>>b;
    if(b<=t){
      ans=min(ans,a);
    }
  }
  if(ans==INF)cout<<"TLE"<<endl;
  else cout<<ans<<endl;
  return(0);
}


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

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  vector<ll>a(n);
  rep(i,0,n) cin >> a[i];
  sort(a.begin(),a.end());
  if(a[0] == 0){
    cout << 0 << endl;
    return 0;
  }
  rep(i,0,n){
    if(ans <= (ll)1e18/a[i]) ans *= a[i];
    else{
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4020
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vr vector
#define pb push_back

 int main()
 {

 ll n,a,b;
 cin>>n>>a>>b;

 ll s=n/(a+b);
 s=s*a;
 ll p=n%(a+b);
 s+=min(p,a);
 cout<<s;

cout<<endl;



    return 0;
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

int main(){
	int w, h;
	cin >> w >> h;

	vector<long long> x(w), y(h);
	rep(i, w){
		cin >> x[i];
	}
	rep(i, h){
		cin >> y[i];
	}

	sort(all(x));
	sort(all(y));

	vector<long long> sum(w + 1, 0);
	sum[0] = 0;
	rep(i,w){
		sum[i + 1] = sum[i] + x[i];
	}

	long long ans = 0;
	rep(i,h){
		int p = distance(x.begin(), lower_bound(all(x), y[i]));
		ans += sum[p] + (w - p) * y[i];
	}
	cout << ans + accumulate(all(x),0LL) + accumulate(all(y),0LL) << endl;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);

ll mpow(ll n, int m){
  if(n==1 || m ==0)return 1;
  if(n==0)return 0;

  if(m%2==0){
    return mpow(n*n, m/2);
  }else{
    return mpow(n*n, m/2)*n;
  }
}


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

  if(n==0){
    cout << 0 << endl;
    exit(0);
  }

  int t=1;
  vector<char> ans;
  while(n!=0){
    if(n%((ll)1<<t)==0){
      ans.emplace_back('0');
    }else{
      ans.emplace_back('1');
      n -= mpow((-2), t-1);
    }
    t++;
  }

  REP(i,ans.size()){
    cout << ans[ans.size()-i-1];
  }
  cout << endl;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>

using namespace std;

int main()
{
	int32_t n, k, x, y;
	int32_t payment;
	
	scanf("%d\n%d\n%d\n%d\n", &n, &k, &x, &y);

	payment = n >= k ? k * x : n * x;
	payment += n >= k ? (n - k) * y : 0;

	printf("%d\n", payment);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define inf 10000000000000007
#define eps 1e-8
#define PI 3.14159265359
#define sp printf(" ")
#define vi vector<int>
#define vl vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pcc pair<char, char>
#define mp make_pair
#define FF first
#define SS second
#define pb(x) push_back(x)
#define sd(x) scanf("%d", &(x))
#define pd(x) printf("%d", (x))
#define pdn(x) printf("%d\n", (x))
#define sld(x) scanf("%ld", &(x))
#define pld(x) printf("%ld", (x))
#define pldn(x) printf("%ld\n", (x))
#define slf(x) scanf("%lf", &(x))
#define plf(x) printf("%.9lf", (x))
#define plfn(x) printf("%.12lf\n", (x))
#define sch(x) scanf("%c", &(x))
#define pch(x) printf("%c", (x))
#define pchn(x) printf("%c\n", (x))
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define ios ios::sync_with_stdio(false); cin.tie(0) ; cout.tie(0)
#define endl '\n'
using namespace std;

int main()
{
    ll q,h,s,d;
    cin>>q>>h>>s>>d;
    h=min(h,2*q);
    s=min(s,2*h);
    d=min(d,2*s);
    ll n;
    cin>>n;
    if(n%2==0)
    {
        cout<<n*d/2LL<<endl;
    }
    else
    {
        n=n/2LL;
        cout<<n*d+s<<endl;
    }
   


    

    

    

}




Measured memory_bytes: 256
# nの階乗の素因数分解を二重配列で返す
def fact_fact(n)
  # nまでの素数を探す
  prime = Array.new(n+1,1)
  array = []
  (2..n).each do|i|
    if prime[i]
      (i*2).step(n,i) do |j|
        prime[j] = 0
      end
    end
  end

  (2..n).each do|i|
    if prime[i] == 1
      prime[i] = 0
      j = i
      cnt = 0
      while j <= n
        cnt += n / j
        j *= i
      end
      array << [i,cnt]
    end
  end
  return array
end

n = gets.to_i
MOD = 10 ** 9 + 7
array = fact_fact(n)
ans = 1
array.each do |a,b|
  ans *= b + 1
end
puts ans % MOD


Measured memory_bytes: 1788
#include <string>
#include <vector>
#include <iostream>
using namespace std;
string e = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?";
vector<string> s1 = {
	"100101", "10011010", "0101", "0001", "110",
	"01001", "10011011", "010000", "0111", "10011000",
	"0110", "00100", "10011001", "10011110", "00101",
	"111", "10011111", "1000", "00110", "00111",
	"10011100", "10011101", "000010", "10010010", "10010011",
	"10010000", "101", "010001", "000011", "10010001",
	"000000", "000001"
};
vector<string> s2 = {
	"00000", "00001", "00010", "00011", "00100", "00101", "00110", "00111", "01000", "01001",
	"01010", "01011", "01100", "01101", "01110", "01111", "10000", "10001", "10010", "10011",
	"10100", "10101", "10110", "10111", "11000", "11001", "11010", "11011", "11100", "11101",
	"11110", "11111"
};
string s;
int main() {
	while (s = "", getline(cin, s)) {
		string t;
		for (int i = 0; i < s.size(); i++) {
			for (int j = 0; j < e.size(); j++) {
				if (s[i] == e[j]) t += s1[j];
			}
		}
		while (t.size() % 5 != 0) t += "0";
		string ret = "";
		for (int i = 0; i < t.size(); i += 5) {
			string u = t.substr(i, 5);
			for (int j = 0; j < e.size(); j++) {
				if (u == s2[j]) ret += e[j];
			}
		}
		cout << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 3028
#include<stdio.h>

int main(void)
{
	int a,b;
	scanf("%d %d",&a,&b);
	if(a > b)
	{
		printf("a > b\n");
	}
	else if(a < b)
	{
		printf("a < b\n");
	}
	else
	{
		printf("a == b\n");
	}
	return 0;
}

Measured memory_bytes: 580
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

int sign(double x){
  return (x>0)-(x<0);
}

int deg(char *xy, int d){

  if(xy[0] == 'B') return 120 - d; //BC 
  if(xy[0] == 'C') return 60  - d; //CD
  if(xy[0] == 'D') return 180 - d; //DB 

  return 0;
}

int getID(int deg, int l){
  double eps = 1e-7;
  double s = sqrt(3)/2;
  
  double a = cos((deg-30) / 180.0 * M_PI) * l;
  double b = cos((deg-90) / 180.0 * M_PI) * l;
  double c = cos((deg-150)/ 180.0 * M_PI) * l;

  int A = floor(a / s + eps * sign(a));
  int B = floor(b / s + eps * sign(b));
  int C = floor(c / s + eps * sign(c));

  //debug(A);
  //debug(B);
  //debug(C);
  
  if((A + B) % 2 == 0){
    if((A + C) % 2 == 0){
      return 1;
    }else{
      return 3;
    }
  }else{
    if((A + C) %2 == 0){
      return 4;
    }else{
      return 2;
    }
  }
  
}

int main(){
  char xy[2][3];
  int d[2], l[2];

  for(int i=0;i<2;i++){
    scanf("%s%d%d",xy[i], d+i, l+i);
    d[i] = deg(xy[i], d[i]);
  }
  
  if(getID(d[0],l[0]) == getID(d[1],l[1])){
    puts("YES");
  }else{
    puts("NO");
  }
  
  return 0;
}



Measured memory_bytes: 3376
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>

using namespace std;
using ll = long long;
using P = pair<int, int>;

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

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

int main(){
    int N,D;cin >> N>>D;
    int count = 0;
    for (int i = 0; i < N; i++)
    {
        int X, Y;cin>>X>>Y;
        double dis = abs(sqrt(pow(X,2)+pow(Y,2)));

        if (dis<=(double)D) {
            count++;
        }

    }
    cout<< count<< endl;
    return 0;
}

Measured memory_bytes: 3668
/*
─────────▄▄▄▄▄▄▄▄▄▄▄▄─────────
─────▄▄▀▀░░░░░░░░░░░░▀▀▄▄─────
───▄▀░░░░░░░░░░░░░░░░░░░░▀▄───
──█░░░░░▄▄▄▄▄░░░░▄▄▄▄▄░░░░░█──
─█░░░░░██░█░██▄▄██░█░██░░░░░█─
█░░░░░░░▀▀▀▀▀░░░░▀▀▀▀▀░░░░░░░█
█░░░░▄▄▄░░░░░░░░░░░░░░▄▄▄░░░░█
█░░░░██▀█▄▄▄▄▄▄▄▄▄▄▄▄██▀█░░░░█
─█░░░▀██▄████████▄▄▄▄██▄▀░░░█─
──█░░░░▀██▀▀▀▀████████▀░░░░█──
───▀▄░░░░▀▄▄▄▄██████▀░░░░▄▀───
─────▀▀▄▄░░░░░░░░░░░░▄▄▀▀─────
─────────▀▀▀▀▀▀▀▀▀▀▀▀─────────
*/
#include <bits/stdc++.h>

using namespace std;

const int mod = 1e9 + 7;

int add(int a, int b) {
	return a + b - mod * (a + b >= mod);
}

int mul(int a, int b) {
	return int(1ll * a * b % mod);
}

int power(int a, int x) {
	if (x == 0) {
		return 1;
	}
	return mul(power(mul(a, a), x / 2), (x % 2 ? a : 1));
}

int sub(int a, int b) {
	return a - b + mod * (a < b);
}

int divide(int a, int b) {
	return mul(a, power(b, mod - 2));
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
	int n, k;
	cin >> n >> k;
	int sk = divide(add(mul(k, k), k), 2);
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		int l = 0, r = 0;
		for (int j = 0; j < i; ++j) {
			l += a[i] > a[j];
		}
		for (int j = i + 1; j < n; ++j) {
			r += a[i] > a[j];
		}
		ans = add(ans, add(mul(l, sub(sk, k)), mul(r, sk)));
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 256
//g++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main() {
  int A,B,C;
  cin >> A >> B >> C;
  int start = A%B;
  bool can = false;
  if(start == C){
    cout << "YES" <<endl;
  }
  else{
    for(int i = 1;i <=A*B ;i++){
      if((A*i)%B == C){
        can = true;
        break;
      }
    }
    if(can)cout << "YES" <<endl;
    else cout << "NO" <<endl;
  }

}


Measured memory_bytes: 256
'use strict'
const Main=input=>{
    input=input.split("\n");
    
    let hole=[[false,false,false],[false,false,false],[false,false,false]];
    const sheet=[];
    sheet.push(input[0].split(" "));
    sheet.push(input[1].split(" "));
    sheet.push(input[2].split(" "));
    
    for(let i=0;i<input[3];i++){
        const num=input[4+i];
        for(let y=0;y<3;y++){
            for(let x=0;x<3;x++){
                if(sheet[y][x]==num)hole[y][x]=true;
            }
        }
    }
    
    let check=false;
    for(let i=0;i<3;i++){
        if(hole[i][0]&&hole[i][1]&&hole[i][2])check=true;
        if(hole[0][i]&&hole[1][i]&&hole[2][i])check=true;
    }
    if(hole[0][0]&&hole[1][1]&&hole[2][2])check=true;
    if(hole[2][0]&&hole[1][1]&&hole[0][2])check=true;
    
    if(check){
        console.log("Yes");
    }else{
        console.log("No");
    }
}

Main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 21064
macro_rules! bind_from_vec {
    ( $($variable:ident),+ = $vector: expr ) => {
        let mut v = $vector.clone().into_iter();
        $(let $variable = v.next().unwrap();)+
    };
}

macro_rules! read_line {
    () => {{
        let mut input = String::new();
        std::io::stdin().read_line(&mut input).unwrap();
        input
    }};
}

fn read_to_vec<T: std::str::FromStr>() -> Vec<T> {
    read_line!().split_whitespace()
        .map(|e| e.parse::<T>().ok().unwrap())
        .collect()
}

fn main() {
    bind_from_vec!(h, w = read_to_vec());
    let mut input = Vec::new();
    for _ in 0..h {
        input.push(read_trim());
    }

    for line in input.iter() {
        println!("{}\n{}", line, line);
    }
}

fn read_trim() -> String {
    read_line!().trim().to_owned()
}

Measured memory_bytes: 4352
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    char a, b;
    cin >> a >> b;
    if (a < b) {
        for (int i = 0; i < b - '0'; i++) {
            cout << a;
        }
    }
    else {
        for (int i = 0; i < a - '0'; i++) {
            cout << b;
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
object Main extends App {

  import scala.io.StdIn._

  val Array(w, h, t) = readLine.trim.split(' ').map(_.toInt)
  val schedule = Array.tabulate(readLine.trim.toInt){_ ⇒
    val Array(x, y, _) = readLine.trim.split(' ').map(_.toInt)
    Coordinate(x, y)
  }
  val state = Array.tabulate(h){_ ⇒ readLine.trim.split(' ').map(_.toInt == 1)}
  println(
    schedule.count(p ⇒ state(p.y)(p.x))
  )
  case class Coordinate(x: Int, y: Int)
}



Measured memory_bytes: 44472
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N = I()
A = [I() for _ in range(N)]

B = [0]*N
C = [0]*N
for i in range(N):
    if i == 0:
        B[i] = A[i]
    else:
        B[i] = max(B[i-1],A[i])
for i in range(N-1,-1,-1):
    if i == N-1:
        C[i] = A[-1]
    else:
        C[i] = max(C[i+1],A[i])

for i in range(N):
    if i == 0:
        print(C[1])
    elif i == N-1:
        print(B[-2])
    else:
        print(max(B[i-1],C[i+1]))


Measured memory_bytes: 86024
W = input().lower()

input_str = []

while True:
    input_value = input()
    if input_value == "END_OF_TEXT":
        break
    else:
        input_str.append(input_value.lower().split())

input_str=sum(input_str,[])

count = 0
for i in input_str:
    if W == i :
        count += 1
print(count)


Measured memory_bytes: 5556
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

int str_cmp(const void *a,const void *b)
{
  return strcmp((char*)a, (char*)b);
}

int main(){
 long long int n;
 scanf("%lld", &n);
 char s[n][11];
 long long int a;
 for(a=0;a<n;a++)
 {
  scanf("%s",s[a]);
 }
 qsort(s,n,sizeof(s[0]),str_cmp);
 long long int ans=1;
 for(a=0;a<n - 1;a++)
 {
  if(strcmp(s[a],s[a+1])!=0)
  {
    ans++;
  }
 }
  
 printf("%lld\n",ans);
  
return 0;}


Measured memory_bytes: 5704
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< long long > vll;
typedef pair< int,int > ii;
typedef long long ll;
#define sz(a) int((a).size())
#define pb push_back
#define mp  make_pair
#define mod 1000000007
#define mod2 998244353
#define all(c) c.begin(),c.end()
#define tr(c,i) for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c,x) (c.find(x) != c.end())
#define cpresent(c,x) (find(all(c),x) != c.end())
#define rep(i, a, b) for (int i = (a); i <= int(b); i++)
#define fo(i,n) for(ll i=0;i<n;i++)
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
#define nl "\n"
ll gcd (ll a, ll b) {
    if (b == 0)
        return a;
    else
        return gcd (b, a % b);
}

unsigned long long factorial[1000004]; 
    /*factorial[0] = 1; 
    for (int i = 1; i <= n; i++) {
        factorial[i] = (factorial[i - 1] * i) % mod3; 
    }*/




unsigned long long power(unsigned long long x, 
                         int y, int p) 
{ 
    unsigned long long res = 1; // Initialize result 
  
    x = x % p; // Update x if it is more than or 
    // equal to p 
  
    while (y > 0) { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res * x) % p; 
  
        // y must be even now 
        y = y >> 1; // y = y/2 
        x = (x * x) % p; 
    } 
    return res; 
} 



  
// Returns n^(-1) mod p 
unsigned long long modInverse(unsigned long long n, int p) 
{ 
    return power(n, p - 2, p); 
} 
unsigned long long nc(unsigned long long n, 
                                 int r, int p) 
{ 
    // Base case 
    if (r == 0) 
        return 1; 
  
    // Fill factorial array so that we 
    // can find all factorial of r, n 
    // and n-r 
 
  
    return (factorial[n]* modInverse(factorial[r], p) % p * modInverse(factorial[n - r], p) % p) % p; 
} 



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    ll a[n+1];
    fo(i,n){
        cin>>a[i+1];
    
    }
    ll ans=0;
    for(int i=2;i<=n;i++){
        if(a[i]<a[i-1]){
            ans+= (a[i-1]-a[i]);
            a[i]=a[i-1];
        }
    }
    cout<<ans<<nl;
  
    

    


	return 0;
}


Measured memory_bytes: 5224
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

k=int(input())
a=sorted([int(i) for i in input().split()])
ma=a[-1]/2
#print(a)
eps=10**(-7)

m=a[-1]-ma
for i in range(k):
    m=min(abs(a[i]-ma),m)
print(a[-1],end=" ")
for i in range(k):
    if abs(abs(a[i]-ma)-m)<eps:
        print(a[i])
        break


Measured memory_bytes: 14436
#include<stdio.h>

int main(void){
	int H,W,h,w;
	scanf("%d%d%d%d",&H,&W,&h,&w);
	if(h<1||H<h)
	printf("eroor");
	else if(w<1||W<w)
	printf("error");
	else
	printf("%d",H*W-(H*w+W*h	)+h*w);
return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(x,y,z) for(int x = y; x < z; x++)
#define INF 9999999;
#define VEC vector<int>
#define in push_back
#define ans(x) cout<<x<<endl
#define ll long long int 

using namespace std;


int main()
{
	string a;
	cin >> a;
	for (int i = 0; i < a.length(); i++)
	{
		if (a[i] == 'A')a[i] = 'X';
		else if (a[i] == 'B')a[i] = 'Y';
		else if (a[i] == 'C')a[i] = 'Z';
		else
			a[i] -= 3;
	}
	cout << a << endl;
}

Measured memory_bytes: 3164
import sys
from collections import deque


class MaxFlow:
    class Edge:
        def __init__(self, to, cap, rev):
            self.to, self.cap, self.rev = to, cap, rev

    def __init__(self, node_size, inf):
        self._node = node_size
        self._inf = inf
        self._level = [-1]*self._node
        self._iter = [0]*self._node
        self._graph = [[] for _ in range(self._node)]

    def add_edge(self, from_, to, cap):
        self._graph[from_].append(self.Edge(to, cap, len(self._graph[to])))
        self._graph[to].append(self.Edge(from_, 0, len(self._graph[from_])-1))

    def bfs(self, start):
        self._level = [-1]*self._node
        que = deque()
        self._level[start] = 0
        que.append(start)
        while que:
            cur_vertex = que.popleft()
            for e in self._graph[cur_vertex]:
                if self._level[e.to] < 0 < e.cap:
                    self._level[e.to] = self._level[cur_vertex] + 1
                    que.append(e.to)

    def dfs(self, cur_vertex, end_vertex, flow):
        if cur_vertex == end_vertex:
            return flow
        for e in self._graph[cur_vertex][self._iter[cur_vertex]:len(self._graph[cur_vertex])]:
            if e.cap > 0 and self._level[cur_vertex] < self._level[e.to]:
                flowed = self.dfs(e.to, end_vertex, min(flow, e.cap))
                if flowed > 0:
                    e.cap -= flowed
                    self._graph[e.to][e.rev].cap += flowed
                    return flowed
        return 0

    def solve(self, source, sink):
        flow = 0
        while True:
            self.bfs(source)
            if self._level[sink] < 0:
                return flow
            self._iter = [0]*self._node
            while True:
                f = self.dfs(source, sink, self._inf)
                if f == 0:
                    break
                flow += f


class BipartiteMatching:
    def __init__(self, size1, size2):
        self._u_size, self. _v_size = size1, size2
        self.mf = MaxFlow(self._u_size+self. _v_size+2, min(self._u_size, self._v_size))
        for i in range(self._u_size):
            self.mf.add_edge(0, i+1, 1)
        for i in range(self._v_size):
            self.mf.add_edge(self._u_size+i+1, self._u_size+self._v_size+1, 1)

    def add_edge(self, from_, to):
        self.mf.add_edge(from_+1, to+self._u_size+1, 1)

    def solve(self):
        return self.mf.solve(0, self._u_size+self._v_size+1)

if __name__=='__main__':
    x, y, m = map(int, sys.stdin.readline().split())
    bm = BipartiteMatching(x, y)
    for _ in range(m):
        u, v = map(int, sys.stdin.readline().split())
        bm.add_edge(u, v)
    print(bm.solve())


Measured memory_bytes: 9488
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define double long double
using namespace std;

ll tec = 7, k;
set<ll> myset;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> k;
    if (tec % k == 0) {
        cout << 1;
        return 0;
    }
    tec %= k;
    myset.insert(tec);
    for (ll i = 2; i <= 1000000; ++i) {
        tec = tec * 10 + 7;
        tec %= k;
        if (myset.find(tec) != myset.end()) {
            cout << -1;
            return 0;
        }
        if (tec == 0) {
            cout << i;
            return 0;
        }
        myset.insert(tec);
    }
    cout << -1;
    return 0;
}


Measured memory_bytes: 50460
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, K, S):
    S = [c for c in S]
    K -= 1
    if S[K] == 'A':
        S[K] = 'a'
    elif S[K] == 'B':
        S[K] = 'b'
    elif S[K] == 'C':
        S[K] = 'c'
    return ''.join(S)


def main():
    # N = read_int()
    N, K = read_int_n()
    S = read_str()
    print(slv(N, K, S))


if __name__ == '__main__':
    main()


Measured memory_bytes: 8028
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█
 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long lo;
typedef pair< lo,lo > PII;
 
#define fi first
#define se second
#define mp make_pair
#define int long long
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
 
const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 20005;
const lo mod = 1000000007;
 
int n,m,b[li],a[li],k,flag,t,flag1,at,vis[li],par[li];
int cev;
string s;
vector<int> v[li];
//~ map<int,int> vis;
//~ map<int,int> par;
vector<PII> vv;
 
inline void dfs(int node,int der,int ind,int yes){
	//~ if(yes==1){
		//~ cout<<der<<" ()()() "<<at<<endl;
		//~ cout<<node<<" ()()() "<<ind<<endl;
	//~ }
	//~ cout<<ind<<endl;
	if(der>at && yes==1)return ;
	if(vis[ind]==1 && node==ind && (der==at || yes==0)){
		if(yes==1){
			flag=1;
			//~ if(yes==1)
			printf("%lld\n",der);
		}
		else vv.pb(mp(der,ind));
	}
	if(flag==1){
		if(node==ind && vis[ind]==2)exit(0);
		//~ if(yes==1)
		printf("%lld\n",node);
		//~ vv.pb(node,yes);
		vis[ind]=2;
		dfs(par[node],der,ind,yes);
		return ;
	}
	if(vis[node]==1 && node!=ind){return ;}
	//~ if(flag1==1)return ;
	vis[node]=1;
	for(int i=0;i<(int)v[node].size();i++){
		int go=v[node][i];
		par[go]=node;
		dfs(go,der+1,ind,yes);
	}
}
 
main(void){
	scanf("%lld %lld",&n,&m);
	for(int i=1;i<=m;i++){
		int x,y;
		scanf("%lld %lld",&x,&y);
		v[x].pb(y);
	}
	FOR{
		memset(vis,0,sizeof(vis));
		memset(par,0,sizeof(par));
		flag=0;
		flag1=0;
		dfs(i,0,i,0);	
	}
	//~ vv.clear();
	if(vv.empty()){printf("-1\n");return 0;}
	sort(vv.begin(),vv.end());
	flag=0;
	flag1=0;
	at=vv[0].fi;
	memset(vis,0,sizeof(vis));
	memset(par,0,sizeof(par));
	dfs(vv[0].se,0,vv[0].se,1);
	return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  ll g=gcd(a,b);
  return a/gcd(a,b)*b;
		

}
int main(){
  ll M1,M2,D1,D2;
  cin>>M1>>D1;
  cin>>M2>>D2;
  
  if(M1!=M2){
cout<<1<<endl;
  }
  else{
cout<<0<<endl;
  }
}


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

int main() {
    ll n,h;
    cin >> n >> h;
    vector<pair<ll,ll>> a(2*n);
    rep(i,n){
        cin >> a.at(2*i).first >> a.at(2*i+1).first;
        a.at(2*i).second=1;
        a.at(2*i+1).second=0;
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    ll ma=0;
    ll ans;
    rep(i,2*n){
        if (a.at(i).second==0) ma+=a.at(i).first;
        if (a.at(i).second==1) {
            ans=(h-ma)/a.at(i).first+i;
            if ((h-ma)%a.at(i).first!=0) ans++;
            break;
        }
        if (ma>=h) {ans=i+1;break;}
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 3328
#define _CRT_SECURE_NO_WARNINGS
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <array>
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <bitset>
#include <utility>
#include <assert.h>
#include <regex>
using namespace std;

typedef unsigned long long ull;
typedef signed long long ll;
#define INF (1LL << 48)

struct PT { ll x; ll y; };
string to_s(ull x) { return to_string(x); }
string to_s(ll x) { return to_string(x); }
ll to_ll(const string& x) { return stoll(x); }
ull to_ull(const string& x) { return stoull(x); }




int main(int argc, char* argv[])
{
	for (;;) {
		ll N, a[5];
		cin >> N >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
		if (cin.fail()) break;

		ll low = a[0];
		for (ll i = 1; i < 5; i++) {
			low = min(a[i], low);
		}
		cout << (N + (low - 1)) / low + 4 << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f;
#define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin.sync_with_stdio(0);
int main()
{
int n,array1[105],i,sum=0,m,temp;
scanf("%d",&n);
for(i=0;i<n;++i){
    scanf("%d",&array1[i]);
    sum+=array1[i];
}
scanf("%d",&m);
temp=sum;
while(m--){
    sum=temp;
    int p,x;
    scanf("%d %d",&p,&x);
    sum-=array1[p-1];
    sum+=x;
    printf("%d\n",sum);
}



    return 0;
}


Measured memory_bytes: 3724
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.HashMap;
import java.util.NoSuchElementException;
public class Main {
	public static void main(String[] args)throws Exception{
		PrintWriter out = new PrintWriter(System.out);
		int N=nextInt();
		HashMap<Integer,Integer> map=new HashMap<Integer,Integer>();
		Deque<Integer> q=new ArrayDeque<Integer>();
		long ans=0;
		for(int i=0;i<N;i++){
			int a=nextInt();
			if(map.containsKey(a)==false){
				map.put(a,1);q.add(a);
			}
			else
				map.put(a,map.get(a)+1);
		}
		while(q.size()>0){
			int x=q.poll();
			int a=map.get(x);
			ans+=x*a;
		}
		int Q=nextInt();
		for(int i=0;i<Q;i++){
			long b=nextLong();
			long c=nextLong();
			if(map.containsKey((int)(b))){
				int x=map.get((int)(b));
				ans-=b*x;ans+=c*x;
				map.remove((int)(b));
				if(map.containsKey((int)(c))==false)
					map.put((int)(c),x);
				else
					map.put((int)(c),x+map.get((int)(c)));
			}
			System.out.println(ans);
		}
		out.flush();
	}
	static boolean isOK(int index,int key,ArrayList<Integer>a){
		if (a.get(index) >= key) return true;
	    else return false;
	}
	static int binary_search(int key,ArrayList<Integer> a) {
	    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	    int ok = (int)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	    while (Math.abs(ok - ng) > 1) {
	        int mid = (ok + ng) / 2;

	        if (isOK(mid,key,a)) ok = mid;
	        else ng = mid;
	    }
	    return ok;
	}
	//FastScanner
	static InputStream in = System.in;
	static  byte[] buffer = new byte[1024];
	static int length = 0, p = 0;
	public static boolean hasNextByte () {
		if (p < length) return true;
		else {
			p = 0;
			try {length = in.read(buffer);}
			catch (Exception e) {e.printStackTrace();}
			if (length == 0) return false;
		}
		return true;
	}
	public static int readByte () {
		if (hasNextByte() == true) return buffer[p++];
		return -1;
	}
	public static boolean isPrintable (int n) {return 33<=n&&n<=126;}
	public static void skip () {
		while (hasNextByte() && !isPrintable(buffer[p])) p++;
	}
	public static boolean hasNext () {skip(); return hasNextByte();}
	public static String next () {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int temp = readByte();
		while (isPrintable(temp)) {
			sb.appendCodePoint(temp);
			temp = readByte();
		}
		return sb.toString();
	}
	public static int nextInt () {return Math.toIntExact(nextLong());}
	public static int[] nextInts (int n) {
		int[] ar = new int[n];
		for (int i=0; i<n; i++) ar[i] = nextInt();
		return ar;
	}
	public static long nextLong () {
		if (!hasNext()) throw new NoSuchElementException();
		boolean minus = false;
		int temp = readByte();
		if (temp == '-') {
			minus = true;
			temp = readByte();
		}
		if (temp<'0' || '9'<temp) throw new NumberFormatException();
		long n = 0;
		while (isPrintable(temp)) {
			if ('0'<=temp && temp<='9') {
				n *= 10;
				n += temp - '0';
			}
			temp = readByte();
		}
		return minus? -n : n;
	}
}


Measured memory_bytes: 79196
#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;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  bool approved = true;
  rep(i, n) if (a[i] % 2 == 0 && a[i] % 3 && a[i] % 5) approved = false;
  if (approved) cout << "APPROVED" << endl;
  else cout << "DENIED" << endl;
  return 0;
}

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    sort(all(h));
    int sub = 1001001001;
    for (int i=0; i<n-k+1; i++) {
        int tmp = abs(h[i] - h[i+k-1]);
        sub = min(sub, tmp);
    }
    cout << sub << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;
typedef long long ll;

ll gcd(ll,ll);
int main(void){
  vector<ll> v;
  int N;
  ll M;
  cin >> N >> M;
  for(int i=0;i<N;i++){
    ll tmp;
    cin >> tmp;
    v.push_back(tmp/2);
  }
  sort(v.begin(),v.end());
  // v[0] に 2がいくつ含まれているかを調べる
  int count = 0;
  ll v0 = v[0];
  while(v0%2 == 0){
    count++;
    v0 = v0/2;
  }
  //各v[i]が同じだけ2を含むかを調べる　違うなら0
  ll pow2 = pow(2,count);
  for(int i=0;i<N;i++){
    if(v[i]%pow2 != 0 || v[i]%(pow2*2) == 0){
      cout << 0 << endl;
      return 0;
    }
  }
  //各値の最小公倍数を求める
  ll koubai = v[0];
  for(int i=1;i<N;i++){
    ll g = gcd(koubai,v[i]);
    koubai = (koubai*v[i])/g;
  }
  // Mをkoubaiで割る
  ll num = (ll)(M/koubai);
  //この中に3以上の奇数がいくつあるかを探す
  ll ans = (ll)(num+1)/2;
  if(ans < 0){
    cout << 0 << endl;
  }else{
    cout << ans << endl;
  }
  return 0;
}


ll gcd(ll a,ll b){
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}


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


int main(){
  int i,j,k, D, G;
  cin >> D >> G;
  pair<int, int> tmp;
  vector<pair<int, int>> P;
  rep0(i, D){
    cin >> tmp.first >> tmp.second;
    P.push_back(tmp);
  }
  int total, num, min_num;
  min_num = 1 << 30;
  rep0(i, (1<<D)){
    total = 0;num = 0;
    bitset<10> bit(i);
    rep0(k, D){
      if(bit.test(k)){
        total += P[k].second + (100 * (k+1) * P[k].first);
        num += P[k].first;
      }
    }
    //cout << bit << " " << total << ", " << num << endl;
    if(total >= G){
      if(min_num > num){min_num = num;continue;}
    }
    if(total < G){
      for(k=D-1; k>=0; k--){
        if(!bit.test(k)){

          if (P[k].first > (G-total)/(100*(k+1))){
            
            if ((G-total)%(100*(k+1)) == 0){
              num += (G-total)/(100*(k+1));
            }
            else{
              num += (G-total)/(100*(k+1)) + 1;
            }
            if (min_num > num){
              min_num = num;
            }
          break;
            
          }
        }
      }
    }
  }

  cout << min_num << endl;
}

Measured memory_bytes: 256
def Sol(s,w):
    
    if s>w:
        print("safe")
    else:
        print("unsafe")
    
    return

    

#for t in range(int(input())):
n,k = map(int,input().split())
#n = int(input())
#arr = []
#for i in range(n):
#    time = list(map(int,input().split()))
#    time = time[0] + (time[1]/60)
#    arr.append(time)
#arr = list(map(int,input().split()))
#k = input()
#n = int(input())
Sol(n,k)


Measured memory_bytes: 9088
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

alias Pair = Tuple!(int, "y", int, "i");

void main() {
    int n, m;
    scan(n, m);

    auto ans = new string[](m);
    auto ken = new Pair[][](n + 1, 0);

    foreach (i ; 0 .. m) {
        int pi, yi;
        scan(pi, yi);
        ken[pi] ~= Pair(yi, i);
    }

    foreach (i ; 1 .. n + 1) {
        ken[i].sort();
    }

    foreach (i ; 1 .. n + 1) {
        foreach (j, si; ken[i]) {
            ans[si.i] = rightJustify(i.to!string, 6, '0') ~ rightJustify((j+1).to!string, 6, '0');
        }
    }

    writefln("%-(%s\n%)", ans);
}









void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 19964
N = int(input())
S = input()
left_cnt = 0
right_cnt = 0
for c in S:
    if '(' == c:
        left_cnt += 1
    elif left_cnt == 0:
        right_cnt += 1
    else:
        left_cnt -= 1
#print(right_cnt, left_cnt)
print('(' * right_cnt + S + ')' * left_cnt)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
#include <complex>
using namespace std;

constexpr double EPS = 1e-10;
using Point = complex<double>;
using Line  = pair<Point, Point>;

double dot(Point p, Point q) { return (conj(p) * q).real(); }
double cross(Point p, Point q) { return (conj(p) * q).imag(); }

vector<Point> convex_hull(vector<Point> &ps) {
    sort(ps.begin(), ps.end(), [&](Point a, Point b){ 
                if(a.imag() != b.imag()) return a.imag() < b.imag();
                return a.real() < b.real();
            });
    int n = (int)ps.size(), k = 0;
    vector<Point> res(n * 2);
    // lower side of convex hull
    for(int i = 0; i < n; res[k++] = ps[i++]) 
        while(k >= 2 && cross(res[k-1] - res[k-2], ps[i] - res[k-1]) < -EPS) --k; 
    // use "< -EPS", include corner or boundary, "< EPS", not include
    
    // upper side
    for(int i = n - 2, t = k+1; i >= 0; res[k++] = ps[i--])
        while(k >= t && cross(res[k-1] - res[k-2], ps[i] - res[k-1]) < -EPS) --k;

    res.resize(k - 1);
    return res;
}

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int n; cin >> n; 
    vector<Point> ps;
    for(int i=0; i < n; ++i) {
        double x,y; cin >> x >> y;
        ps.emplace_back(x,y);
    }
    auto qs = convex_hull(ps);
    cout << qs.size() << '\n';
    for(int i=0; i < (int)qs.size(); ++i) {
        cout << qs[i].real() << " " << qs[i].imag() << '\n';
    }
    return 0;
}


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

#define endl "\n"
#define ar array
#define INF 1e18;
#define ll long long
const int N=2e5+5;
int n,k,a[N];

bool go(int m){
    int val=0;
    for(int i=0;i<n;i++){
        val+=(a[i]-1)/m;
    }
    return val<=k;
}



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

    cin>>n>>k;
    for(int i=0;i<n;i++){
       cin>>a[i];
    }
    sort(a,a+n);
    ll l=1,r=1e9;
    while(l<r){
        ll mid =(l+r)/2;
        if(go(mid)){
            r=mid;
        }
        else{
            l=mid+1;
        }
    }
    cout<<l<<endl;

}


Measured memory_bytes: 4352
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;                                

struct cell{
  int b;
  int c;  
};
bool operator < (const cell& left,const cell& right){
  return left.c > right.c;  
}
int main(void){                                     
  int N,M;
  cin >> N >> M;
  vector<int> v;
  vector<struct cell> u;
  long long int sum = 0;
  for(int i = 0; i < N;i++){
    long int a;
    cin >> a;
    v.push_back(a);
    sum += a;
  }
  sort(v.begin(),v.end());
  for(int i = 0; i < M;i++){
    int b,c;
    cin >> b >> c;
    struct cell x = {b,c};
    u.push_back(x);  
  }
  sort(u.begin(),u.end());
  int k = 0,count = 0;
  for(int i = 0; i < N && k < M;i++){ 
    if(count >= u[k].b){
      count = 0; k++;
    }
    if(u[k].c > v[i]) sum += u[k].c - v[i];
    count++;
  }
  cout << sum << endl;
  return 0;                                         
}     


Measured memory_bytes: 1784
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N; cin >> N;
    vector<int> X(N);
    for(auto &it : X){
        cin >> it;
    }

    int sol = 1e9;
    for(int i=0; i<=100; i++){

        int cnt = 0;

        for(int j=0; j<N; j++){
            cnt += pow(X.at(j)-i,2);
        }

        sol = min(sol, cnt);

    }

    cout << sol << endl;
}

Measured memory_bytes: 256
a = raw_input().split()
for i in range(2):
	a[i] = int(a[i])
seki1 = 1
seki2 = 1
if (a[0] - a[1] == 1 or a[0] -a[1] == -1):
	for i in range(a[0]):
		seki1 *= i+1
		seki1  = seki1 % (10**9+7)
	for i in range(a[1]):
		seki2 *= i+1
		seki2  = seki2 % (10**9+7)
	ans = (seki1*seki2) % (10**9 + 7)
	print ans
	
elif a[0] == a[1]:
	for i in range(a[0]):
		seki1 *= i+1
		seki1  = seki1 % (10**9+7)

	ans = (2*seki1*seki1) % (10**9 + 7)
	print ans
	
else:
	print 0

Measured memory_bytes: 5764
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e9 + 1;
int main(){
    ll n; cin >> n;
    priority_queue<P, vector<P>, greater<P> > p;
    rep(i,n){
        ll x, l;
        cin >> x >> l;
        p.push(make_pair(x + l, x - l));
    }
    ll nx = (-1)*INF, r = 0;
    while(!p.empty()){
        //cout << p.top().second << " " << p.top().first << endl;
        if(nx <= p.top().second){
            nx = p.top().first;
            r++;
        }
        p.pop();
    }
    cout << r << endl;
    
    return 0;
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio( false ), cin.tie( nullptr ), cout.tie( nullptr );

    int N, min_sum = INT_MAX; cin >> N;
    
    const auto sum = [] ( int x )
    {
        int s = 0;
        
        while( x > 0 )
            s += x % 10, x /= 10;
            
        return s;
    };
    
    for( int A = 1, B = N - 1; A <= B; A++, B-- )
        min_sum = min( min_sum, sum( A ) + sum( B ) );
        
    cout << min_sum;
}

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

typedef long long ll;
using namespace std;
int main()
{

  ll w,h,n,x[110],y[110],a[110];


  cin>>w>>h>>n;
  rep(i,n){
    cin>>x[i]>>y[i]>>a[i];
  }
  ll area[w][h]={0};


  rep(i,n){
    switch(a[i]){
      case 1:
      rep(j,x[i]){
        rep(k,h){
          if(area[j][k]==0)area[j][k]=1;
        }
      }
      break;

      case 2:
      for(int j=w-1;j>=x[i];j--){
        rep(k,h){
          if(area[j][k]==0)area[j][k]=1;
        }
      }
      break;

      case 3:
      rep(j,y[i]){
        rep(k,w){
          if(area[k][j]==0)area[k][j]=1;
        }
      }
      break;

      case 4:
      for(int j=h-1;j>=y[i];j--){
        rep(k,w){
          if(area[k][j]==0)area[k][j]=1;
        }
      }
      break;
    }
  }


  ll ans=0;
  rep(i,w){
    rep(j,h){
      if(area[i][j]==0)ans++;
    }
  }


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


Measured memory_bytes: 3708
#include<iostream>
#include<string>
using namespace std;
int main()
{
  string a,b,c;
  cin>>a>>b>>c;
  int d,e;
  d=a.size();
  e=b.size();
  if(a[d-1]==b[0]&&b[e-1]==c[0]){
    cout<<"YES";
  }
  else{
    cout<<"NO";
  }
}


Measured memory_bytes: 3588
c=input()
alpha=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
num=alpha.index(c)
print(alpha[num+1])

Measured memory_bytes: 3060