akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.C
{
    internal static class CR
    {
        public static string GetText() { return Console.ReadLine(); }
        public static List<string> GetTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long GetLong() { return long.Parse(Console.ReadLine()); }
        public static List<long> GetLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }
    }

    public class Program
    {
        public static long K { get; private set; }

        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            K = CR.GetLong();
            var sum = 0L;
            for (int i = 1; i <= K; i++)
            {
                for (int j = 1; j <= K; j++)
                {
                    for (int k = 1; k <= K; k++)
                    {
                        sum += Gcd(Gcd(i, j), k);
                    }
                }
            }

            return sum;
        }
        public static long Gcd(long a, long b)
        {
            // 引数を入替えて自分を呼び出す
            if (a < b) return Gcd(b, a);

            while (b != 0)
            {
                var remainder = a % b;
                a = b;
                b = remainder;
            }

            return a;
        }
    }
}


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

#define PI 3.14159265358979

int main(){
  double r; cin>>r;
  printf("%.6f %.6f",r*r*PI,r*2*PI);
}


Measured memory_bytes: 3192
#include <stdio.h>

int main(void) {

  int r, D, x_2000;
  do {
    scanf("%d %d %d", &r, &D, &x_2000);
  } while (r < 2 || r > 5 || D < 1 || D > 100 || x_2000 <= D || x_2000 > 200);

  int x[11];
  x[0] = x_2000;
  for (int i = 1; i < 11; i++) {
    x[i] = r * x[i - 1] - D;
    printf("%d\n", x[i]);
  }

  return 0;
}


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

int main() {
	int N;
	cin >> N;
	vector<pair<long long, long long>>A(N);
	for (int n = 0; n < N; ++n) {
		long long a, b;
		cin >> a >> b;
		A[n] = make_pair(b,a);
	}
	sort(A.begin(),A.end());

	long long time = 0;
	for (int n = 0; n < N; ++n) {
		if (time + A[n].second > A[n].first) {
			cout << "No"<<endl;
			return 0;
		}
		time += A[n].second;
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 6420
def main():
    class Node:
        __slots__ = ["string", "index"]
        def __init__(self, string, index):
            self.string = string
            self.index = index

        def get_children(self):
            parent = self.string
            out = [None]*(self.index+1)
            for i, c in enumerate(s[:self.index]):
                out[i] = Node(parent+c, self.index)
            out[i+1] = Node(parent+s[self.index], self.index+1)
            return out

    n = int(input())
    root = Node("a", 1)
    children = [root]
    for _ in range(n-1):
        parents, children = children, []
        for parent in parents:
            children.extend(parent.get_children())
    for child in children:
        print(child.string)

if __name__ == "__main__":
    s = "abcdefghij"
    main()

Measured memory_bytes: 21820
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int X, A, B;
    cin >> X >> A >> B;

    cout << (X-A)%B << endl;

    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;

/*int P[10010];
void init(int n){
    for(int i=0;i<n;++i)P[i]=i;
}
int root(int a) {
    if(P[a]==a)return a;
    return (P[a]=root(P[a]));
}
bool is_same_set(int a,int b){
    return root(a) == root(b);//代表元を求める
}
void unite(int a,int b){
    P[root(a)]=root(b);
}//対set,グラフ？
//セグメント木？？？
*/

double dot_product(xy_t a, xy_t b) { return (conj(a)*b).real(); }//内積
double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); }//外積
xy_t projection(xy_t p, xy_t b) { return b*dot_product(p,b)/norm(b); }//投影
//対図形

#define mod 1000000007
/*ll f[2001];
//int n,k とかしておく

ll pw(ll x, ll y){//euclidの互除法より
    ll a= 1;
    while(y){
        if(y&1){//奇数なら
            a = a*x%mod;
        }
        x = x*x%mod;
        y /= 2;
    }
    return a;
}

ll modinv(ll x){//逆元を求める
    return pw(x, mod - 2 );
}

ll comb(int n,int r){
    if(n<r){
        return 0;
    }
    return f[n] * modinv(f[r])%mod*modinv(f[n-r])%mod;
}//対combination//ただしfは用意してね
*/

struct BIT{
    vector<int> dat;
    int sz;
    BIT(int n){
        for(sz=1;sz<n;sz *= 2);
        dat.resize(++sz);
    }
    int q(int n){
        int ret = 0;
        for(int i=n;i>0;i-=i&-i)ret +=dat[i];//和の計算　iから最後の１のbit(i&-i 多分＆はビット積)を減算
        for(int i=n;i<sz;i+=i&-i) dat[i]++;//値の加算　iから最後mの１のbitを加算
        return ret;
    }
};



//偶数から始まる連続する２整数の和は１になる！！！！！を以下フル活用
int main(){
    ll a,b;
    cin >> a>> b;
    a--;
    ll ans=0,res_a,res_b;
    if(a%4==0){
        res_a=a;
    }else if(a%4==1){
        res_a=1;
    }else if(a%4==2){
        res_a=a+1;
    }else{
        res_a=0;
    }
    if(b%4==0){
        res_b=b;
    }else if(b%4==1){
        res_b=1;
    }else if(b%4==2){
        res_b=b+1;
    }else{
        res_b=0;
    }
    ans=res_a^res_b;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] sa = br.readLine().split(" ");
		int[] x = new int[n];
		int[] x2 = new int[n];
		for (int i = 0; i < n; i++) {
			x[i] = Integer.parseInt(sa[i]);
			x2[i] = x[i];
		}
		br.close();

		Arrays.sort(x2);
		int b1 = x2[n / 2 - 1];
		int b2 = x2[n / 2];
		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < n; i++) {
			if (x[i] <= b1) {
				System.out.println(b2);
			} else {
				System.out.println(b1);
			}
		}
		pw.flush();
	}
}


Measured memory_bytes: 91088
fun main(args: Array<String>){
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    val a = readLine()!!.split(" ").map { it.toInt() }

    val a1 = a.filter { it >= a.sum().div((4*m).toDouble())}
    if (a1.size < m){
        println("No")
    }else{
        println("Yes")
    }
}

Measured memory_bytes: 38120
#include <iostream>
#include <vector>
#include <list>
#include <string>
#include <iterator>
#include <algorithm>
#include <functional>
#include <numeric>

using namespace std;


int main(int argc, char *argv[]) {
    int n;
    int dum;
    cin >> n;
    vector<long> a_in(n), b_in(n), c_in(n);
    for_each(begin(a_in), end(a_in), [](long & val) {
        scanf("%ld", &val);
    });
    for_each(begin(b_in), end(b_in), [](long & val) {
        scanf("%ld", &val);
    });
    for_each(begin(c_in), end(c_in), [](long & val) {
        scanf("%ld", &val);
    });
    //copy_n(istream_iterator<long>(cin), n, begin(a_in));
    //copy_n(istream_iterator<long>(cin), n, begin(b_in));
    //copy_n(istream_iterator<long>(cin), n, begin(c_in));
    auto gt = [] (long l, long r) {return l > r;};
    sort(begin(a_in), end(a_in), gt);
    sort(begin(b_in), end(b_in), gt);
    sort(begin(c_in), end(c_in), gt);
    int last_small_beg_b = 0, last_small_beg_a = 0;
    long long result = 0;
    vector<long> b_a_counts(n);
    transform(begin(b_in) + last_small_beg_b, end(b_in), begin(b_a_counts), [&a_in, &last_small_beg_a](long b_i) {
        auto first_small = find_if(begin(a_in) + last_small_beg_a, end(a_in), [b_i](long a_i){return a_i < b_i;});
        last_small_beg_a = first_small - begin(a_in);
        return a_in.size() - last_small_beg_a;
    });
    vector<long long> b_a_sums(n);
    long long sum_val = 0;
    transform(b_a_counts.rbegin(), b_a_counts.rend(), b_a_sums.rbegin(), [&sum_val](long val) {
        sum_val += val;
        return sum_val;
    });
    for_each (begin(c_in), end(c_in), [&a_in, &b_in, &last_small_beg_b, &b_a_sums, &result](long c_i){ 
        auto first_small = find_if(begin(b_in) + last_small_beg_b, end(b_in), [c_i](long b_i) {return b_i < c_i;});
        last_small_beg_b = first_small - begin(b_in);
        result += b_a_sums[last_small_beg_b];
    });
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 4224
import java.util.*;
import java.lang.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int l[] = new int[n];
        for (int i = 0; i < n; i++) {
            l[i] = sc.nextInt();
        }
        Arrays.sort(l);
        int sum = 0;
        for (int i = 0; i < k; i++) {
            sum += l[n - i - 1];
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define INF 2147483647
pair<int,int> data[4000021];
int n,_n;
void init(int n){
  _n=1;
  while(_n<2000000)_n*=2;
}
void update(int i,int x){
  int p=i;
  i+=_n-1;
  data[i].f+=x;
  data[i].s=p+1;
  while(i>0){
    i=(i-1)/2;
    if(data[2*i+1].f==data[2*i+2].f){
      if(data[2*i+1].s<data[2*i+2].s)
        data[i]=data[2*i+1];
      else data[i]=data[2*i+2];
    }
    else if(data[2*i+1].f>data[2*i+2].f)
      data[i]=data[2*i+1];
    else data[i]=data[2*i+2];
  }
}
int main(){
  int q;
  cin>>n>>q;
  init(n);
  while(q--){
    int a,b;
    cin>>a>>b;
    update(a-1,b);
    cout<<data[1].second<<' '<<data[1].first<<endl;
  }
}

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

using ll = long long;
const int MAX_N = 100010;
ll a[MAX_N];

ll max_val[MAX_N], min_val[MAX_N];

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

    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    for (int i = 0; i < n; i++) {
        min_val[i] = a[i];
        if (i > 0) {
            min_val[i] = min(min_val[i], min_val[i - 1]);
        }
    }

    for (int i = n - 1; i >= 0; i--) {
        max_val[i] = a[i];
        if (i < n - 1) {
            max_val[i] = max(max_val[i], max_val[i + 1]);
        }
    }
    ll diff = 0;
    for (int i = 0; i < n; i++) {
        diff = max(diff, max_val[i] - min_val[i]);
    }
    map<ll, int> counter;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        counter[a[i]] = 1;
        if (counter.find(a[i] - diff) != counter.end()) {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


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


int main()
{
    string n ;
    cin >> n  ;
    if(n[0] == '7' || n[1] == '7' || n[2] == '7')
        cout<< "Yes\n";
    else
        cout << "No";
    return 0;
}


Measured memory_bytes: 3592
a ,b =map(int,input().split())
#aとbを結合した数字cを作成
c = a * (10 ** len(str(b))) + b
l=[]
#2の累乗で表されるリストを作成
for i in range(400):
    l.append(i**2)
print('Yes' if c in l else 'No')

Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////

int main() {
    int n, k; cin >> n >> k;
    string s; cin >> s;
    s[k-1] = s[k-1]-'A'+'a';
    cout << s << endl;
    return 0;
}


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

using namespace std;
using ll = long long;
constexpr int mo = 1e9+7;
constexpr int  mod = mo;
constexpr ll inf = 1ll<<62;

int main(){
    int n;
    cin>>n;
    vector<int> a(n+1),b(n+1);
    vector<int> ans;
    for(int i=1;i<=n;++i) cin>>a[i];
    for(int i=n;i>=1;i--){
        int cur = 0;
        for(int j=i;j<=n;j+=i) cur ^= b[j];
        if(a[i] != cur){
            b[i] = 1;
            ans.push_back(i);
        }
    }
    cout << ans.size() << endl;
    for(auto a : ans) cout << a << endl;
    return 0;
}



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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int a, b;
  cin >> a >> b;
  if (a <= 0 && 0 <= b) {
    cout << "Zero\n";
  } else if (a < 0 && (b-a+1)%2) {
    cout << "Negative\n";
  } else {
    cout << "Positive\n";
  }
  return 0;
}

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

int main(){
  int i,j;ll cnt=0;
  ll n,h;
  cin>>n>>h;
  ll a[n],b[n];
  for(i=0;i<n;i++)cin>>a[i]>>b[i];
  ll maxa=0;
  for(i=0;i<n;i++)maxa=max(maxa,a[i]);
  sort(b,b+n,greater<int>());
  for(i=0;i<n;i++){
    if(b[i]>maxa){
      h-=b[i];
      cnt++;
    }else break;
    if(h<=0){
      cout<<cnt<<endl;
      return 0;
    }
  }
  cout<<(h+maxa-1)/maxa+cnt<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)


const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * g / b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}




const long double PI = 3.14159265359;
const int MAX_N = 100010;


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	VE a(n), b(n), c(n);
	rep(i, n)cin >> a[i];
	rep(i, n)cin >> b[i];
	rep(i, n)cin >> c[i];
	sort(ALL(a)); sort(ALL(b)); sort(ALL(c));
	int ans = 0;
	rep(i, n) {
		int tmp = 1;
		tmp *= lower_bound(ALL(a), b[i]) - a.begin();
		tmp *= c.end() - upper_bound(ALL(c), b[i]);
		ans += tmp;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define arep(i,v) for(auto i : v)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
// #define endl '\n';
#define fi first
#define se second
#define NONVOID [[nodiscard]]
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
template <class T> inline void dump(T &v){irep(i, v){cout<<*i<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
constexpr double EPS = 1e-9;

ll ans=0;
void check(vvi &a, vi &v){
    ll t=0;
    rep(i,a.size()){
        if(v[a[i][1]] - v[a[i][0]] == a[i][2]){
            t+=a[i][3];
        }
    }
    chmax(ans,t);
}

void dfs(int pos, vi &v, int m, vvi &a) {
    if(pos==v.size()){
        check(a, v);
        return;
    }
    int fi=1;
    if(pos)fi=v[pos-1];
    for(int i=fi;i<=m;i++){
        v[pos]=i;
        dfs(pos+1, v, m, a);
    }
    return;
}

int main() {

    int n,m,q;
    cin>>n>>m>>q;
    vvi a(q,vi(4));
    rep(i,q){
        rep(j,4){
            cin>>a[i][j];
        }
        a[i][0]--;
        a[i][1]--;
    }
    vi v(n);
    dfs(0, v, m, a);
    fin(ans);
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define ci(n) cin >> n
#define co(n) cout << n << endl
using namespace std;

int main(){
  long n, c=0;
  cin >> n;
  int t[n];
  rep(i,0,n){
    cin >> t[i];
    c+=t[i];
  }
  
  int m;
  cin >> m;
  
  int p, x;
  
  rep(i,0,m){
    cin >> p >> x;
    co(c-t[p-1]+x);
  }
  
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
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; }

int main(){
  int N, M;
  cin >> N >> M;
  vector<tuple<int , int, int>> c(M);
  rep(i, M) {
    int P, Y;
    cin >> P >> Y;
    c[i] = tie(P, Y, i);
  }
  sort(c.begin(), c.end());
  get<1>(c[0]) = 1;
  int cnt = 2;
  for(int i=1; i<M; i++) {
    if(get<0>(c[i]) != get<0>(c[i-1]))
      cnt = 1;
    get<1>(c[i]) = cnt;
    cnt++;
  }
  sort(c.begin(), c.end(), [](tuple<int, int, int> x, tuple<int, int, int> y) {
    return get<2>(x) < get<2>(y);
  });
  rep(i, M)
    cout << setw(6) << setfill('0') << get<0>(c[i]) << setw(6) << setfill('0') << get<1>(c[i]) << endl;
  return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, int> LI;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N; cin >> N;
	vector<ll> A(N, 0LL), B(N, 0LL);
	rep (i, N){
		cin >> A[i];
	} // end rep
	rep (i, N){
		cin >> B[i];
	} // end rep

	ll totalA = accumulate(ALL(A), 0LL);
	ll totalB = accumulate(ALL(B), 0LL);

	if (totalB > totalA){
		cout << -1 << endl;
		return 0;
	} // end if

	vector<LI> redundant; redundant.clear();
	vector<ll> rack; rack.clear();
	rep (i, N){
		if (A[i] > B[i]){
			redundant.push_back(LI(-(A[i] - B[i]), i));
		} // end if
		if (A[i] < B[i]){
			rack.push_back(B[i] - A[i]);
		} // end if
	} // end rep

	ll totalRack = accumulate(ALL(rack), 0LL);
//	cerr << "totalRack: " << totalRack << endl;
	sort(ALL(redundant));

//	cerr << "rack_sz: " << (int)rack.size() << endl;
//	cerr << "redu_sz: " << (int)redundant.size() << endl;

	ll total = 0LL;
	vector<LI> usedIndex; usedIndex.clear();

	rep (i, (int)redundant.size()){
		ll curr = -redundant[i].first;
		int ind = redundant[i].second;
//		cerr << "curr: " << curr << " ind: " << ind << endl;
		usedIndex.push_back(LI(curr,ind));
		if (total + curr >= totalRack){
			ll used = totalRack - total;
			usedIndex[(int)usedIndex.size() - 1] = LI(used, ind);
			break;
		}else{
			total += curr;
		} // end if
	} // end rep

//	cerr << "usedIndex_sz: " << (int)usedIndex.size() << endl;

	vector<ll> C(N, 0LL);
	rep (i, N){
		if (A[i] < B[i]){
			C[i] = B[i];
		}else
		if (A[i] >= B[i]){
			C[i] = A[i];
		} // end if
	} // end rep

	rep (i, (int)usedIndex.size()){
		ll used = usedIndex[i].first;
		int ind = usedIndex[i].second;
		C[ind] = A[ind] - used;
	} // end rep

/*
	rep (i, N){
		cerr << C[i] << (i != N - 1 ? ' ' : '\n');
	} // end rep
*/
	int res = 0;
	rep (i, N){
		if (A[i] != C[i]){
			++res;
		} // end if
	} // end rep

	cout << res << endl;
	
	return 0;
}

Measured memory_bytes: 4724
#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(0); cin.tie(0)
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;

ll best[101010]; // best value using at w weight

int main() {
  IO;
  int n, W; cin>>n>>W;
  for (int i = 1; i <= n; i++) {
    ll w, v; cin>>w>>v;
    for (int cw = W - w; cw >= 0; cw--) {
      best[cw + w] = max(best[cw + w], best[cw] + v);
    }
  }

  ll ans = 0;
  for (int cw = 0; cw <= W; cw++) ans = max(ans, best[cw]);
  cout<<ans<<"\n";
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int, int >
#define F first
#define S second
#define int long long int
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define endl '\n'
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
int32_t main(){
    ll n;
    cin >> n;
    if (n==2){
        kill(1);
    }
    ll ans=2;
    for (int i=2;i*i<=n;i++){
        if (n%i==0){
            ll z=n;
            while(z%i==0) z/=i;
            if (z%i==1) ans++;
        }
        else continue;
        if (n/i!=i){
            ll z=n,d=n/i;
            while(z%d==0) z/=d;
            if (z%d==1) ans++;
        }
    }
    for (int i=2;i*i<=n;i++){
        if (n%i==1) ans++;
        else continue;
        if (n/i!=i) ans++;
      //  cout << i << endl;
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int cn = 0, cm = 0;
        if (n != 0) {
            cn = n * (n - 1) / 2;
        }
        if (m != 0) {
            cm = m * (m - 1) / 2;
        }
        System.out.println(cn + cm);
        sc.close();
    }
}

Measured memory_bytes: 23252
import java.io.*;

class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] price = new int[n];
        int i, j;

        for (i = 0; i < n; i++) {
            price[i] = Integer.parseInt(br.readLine());
        }

        int max = price[1] - price[0];
        int min = price[0] + 1;

        for (i = 0; i < n-1; i++) {
            if (price[i] < min) min = price[i];
            else continue;

            for (j = i+1; j < n; j++) {
                if (price[j] - min > max) {
                    max = price[j] - min;
                }
            }
        }
        System.out.println(max);
    }
}

Measured memory_bytes: 43248
#include <bits/stdc++.h> 
#define FOR(i,a,b) for(int i=(a);i<=(b);++i) 
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i) 
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end() 
#define asn ans
using namespace std;
template <typename T> istream& operator >> (istream& is, vector<T>& vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;

int main() {
	int n; CI n;
	vector<int> p(n);  CI p;

	int ans=0;
	REP(i, n) {
		ans += p[i];
	}
	ans -= *max_element(p.begin(), p.end())/2;


	CO ans EN;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;
struct LazySegmentTree {
private:
    int n;
    vector<ll> node, lazy;

public:
    LazySegmentTree() {
        int sz = 200050;
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1, 0);

        for(int i=0; i<sz; i++) node[i+n-1] = 0;
        for(int i=n-2; i>=0; i--) node[i] = node[i*2+1] + node[i*2+2];
    }
    void eval(int k, int l, int r) {
        if(lazy[k] != 0) {
            node[k] += lazy[k];
            if(r - l > 1) {
                lazy[2*k+1] += lazy[k] / 2;
                lazy[2*k+2] += lazy[k] / 2;
            }
            lazy[k] = 0;
        }
    }

    void add(int a, int b, ll x, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
            lazy[k] += (r - l) * x;
            eval(k, l, r);
        }
        else {
            add(a, b, x, 2*k+1, l, (l+r)/2);
            add(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = node[2*k+1] + node[2*k+2];
        }
    }

    ll getsum(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);

        if(b <= l || r <= a) return 0;
        if(a <= l && r <= b) return node[k];
        ll vl = getsum(a, b, 2*k+1, l, (l+r)/2);
        ll vr = getsum(a, b, 2*k+2, (l+r)/2, r);
        return vl + vr;
    }

};

ll N, D, A;
vector<l_l> v;
int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> D >> A;
    v.resize(N);
    for(int i = 0; i < N; i++) {
        cin >> v[i].first >> v[i].second;
    }
    v.push_back({1e17, 1e17});
    sort(v.begin(), v.end());
    LazySegmentTree seg;
    for(int i = 0; i < N; i++) {
        ll num = (v[i].second + A - 1) / A;
        seg.add(i, i + 1, num);
    }
    ll ans = 0;
    for(int i = 0; i < N; i++) {
        if(seg.getsum(i, i + 1) <= 0) continue;
        ll num = seg.getsum(i, i + 1);
        l_l tmp = {v[i].first + 2 * D + 1, -1e18};
        auto itr = lower_bound(v.begin(), v.end(), tmp);
        itr--;
        int j = distance(v.begin(), itr);
        ans += num;
        seg.add(i, j + 1, -num);
    }
    cout << ans;
    return 0;
}

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

int main() {
  int w,n;
  cin >>w >> n;
  vector <int> tate(w);

  for(int i=0;i<w;i++){// 配列tateに順に1-wを入力
    tate.at(i)=i+1;
  }
  
  while (n--) {
		int a, b;
		scanf("%d,%d", &a, &b);
		a--; b--;
		swap(tate.at(a), tate.at(b));
	}

    for(int i=0;i<w;i++){// 配列tateを左から順に出力
    cout << tate.at(i)<<endl;
  }
	return 0;
}




Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int ll;
int main(){
    ll x;
    cin >> x;
    ll sum=100,ans=0;
    while(sum<x)
    {
        sum=sum*1.01;
        ans++;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3636
//#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

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


int main(void) {

	while (1) {
		int N, M, L, K, A, H;
		int x, y, t;
		int p;

		int d[100][100] = {};
		int cool[100] = {};// 0 普通　1冷凍

		cin >> N >> M >> L >> K >> A >> H;
		if (N == 0) {
			break;
		}

		if (L == 0) {
			string c;
			getline(cin, c);
		}
		else {
			FOR(i, 1, L) {
				cin >> p;
				cool[p] = 1;
			}
		}
		

		cool[A] = cool[H] = 1;

		FOR(i, 0, 99) {
			FOR(j, 0, 99) {
				d[i][j] = INF;
			}
		}

		FOR(i, 1, K) {
			cin >> x >> y >> t;
			d[x][y] = d[y][x] = t;
			
		}



		FOR(i, 0, N - 1) {
			FOR(j, 0, N - 1) {
				FOR(k, 0, N - 1) {
					if (k != j) {
						d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
					}
					
				}
			}
		}


		FOR(i, 0, N - 1) {
			FOR(j, 0, N - 1) {
				if (cool[i] == 0 || cool[j] == 0) {
					d[i][j] = INF;
				}
				if (d[i][j] > M) {
					d[i][j] = INF;
				}
			}
		}

		FOR(i, 0, N - 1) {
			FOR(j, 0, N - 1) {
				FOR(k, 0, N - 1) {
					if (k != j) {
						d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
					}

				}
			}
		}


		if (d[A][H] > 100000) {
			cout << "Help!" << endl;
		}
		else {
			cout << d[A][H] + max(0, (d[A][H] - M)) << endl;
		}
		

	}
	
	return 0;
}


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

typedef vector<int> V;
typedef vector<V> VV;

int N;
VV cubes;
int front[6] = {5, 4, 3, 2, 1, 0};
int sides[6][4] = {
  {1, 3, 4, 2},
  {0, 2, 5, 3},
  {0, 4, 5, 1},
  {0, 1, 5, 4},
  {0, 3, 5, 2},
  {1, 2, 4, 3}
};

int str2id(string s) {
  if (s == "Red") {
    return 0;
  } else if (s == "Yellow") {
    return 1;
  } else if (s == "Blue") {
    return 2;
  } else if (s == "Magenta") {
    return 3;
  } else if (s == "Green") {
    return 4;
  } else if (s == "Cyan") {
    return 5;
  } else {
    return -1;
  }
}

bool input() {
  cin >> N;
  if (!N) {
    return false;
  }
  cubes.resize(N);
  
  for (int i = 0; i < N; ++i) {
    cubes[i].resize(6);
    for (int j = 0; j < 6; ++j) {
      string s;
      cin >> s;
      cubes[i][j] = str2id(s);
    }
  }

  return true;
}

void align(V &v) {
  int tmp[6];
  int z = -1;
  for (int i = 0; i < 6; ++i) {
    if (v[i] == 0) {
      z = i;
    }
  }
  tmp[0] = 0;
  tmp[1] = v[front[z]];
  int x = 6;
  int y = -1;
  for (int i = 0; i < 4; ++i) {
    if (x > v[sides[z][i]]) {
      x = v[sides[z][i]];
      y = i;
    }
  }
  for (int i = 0; i < 4; ++i) {
    tmp[i + 2] = v[sides[z][(y + i) % 4]];
  }
  for (int i = 0; i < 6; ++i) {
    v[i] = tmp[i];
  }
}

int solve() {
  for (int i = 0; i < N; ++i) {
    align(cubes[i]);
  }
  sort(cubes.begin(), cubes.end());
  VV::iterator it = unique(cubes.begin(), cubes.end());
  int num_uniq = it - cubes.begin();
  return N - num_uniq;
}

int main() {
  while (input()) {
    int ans = solve();
    cout << ans << endl;
  }
  return 0;
}

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

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

    int c[10][10];
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> c[i][j];
        }
    }

    for (int k = 0; k < 10; k++) {
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
            }
        }
    }

    int a[H][W];
    int ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> a[i][j];
            ans += c[a[i][j]][1];
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(int argc, char*argv[])
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int N, K;
	cin >> N >> K;
	int a[N+1];
	
	for (int i = 1; i <= N ; ++i)
		cin >> a[i];
	int dp[N+1];
	dp[0] = 0;
	dp[1] = 0;
	for (int i = 2; i<=N; ++i)
	{
		int k = K-1;
		dp[i]  = dp[i-1] + abs(a[i]-a[i-1]);
		for (int j = i-2; j >= 1  && k ; --j, --k)
	       dp[i] = min(dp[j] + abs(a[i]-a[j]) , dp[i] );
	}
	cout << dp[N];
}



Measured memory_bytes: 1024
PROGRAM ATCODER

implicit none
integer(16) :: n,i,j,count=0,count_a=0,count_b=0,count_ab=0
character(len=10),allocatable :: s(:)

read*, n
allocate(s(n))
read*, s(1:n)

do i = 1, n
  do j = 1, len_trim(s(i))-1
    if ( s(i)(j:j+1) == 'AB' ) then
      count = count + 1
    end if
  end do
  if ( s(i)(1:1) == 'B' ) then
    count_b = count_b + 1
  end if   
  if ( s(i)(len_trim(s(i)):len_trim(s(i))) == 'A' ) then
    count_a = count_a + 1
  end if
  if ( s(i)(1:1) == 'B' .and. s(i)(len_trim(s(i)):len_trim(s(i))) == 'A' ) then
    count_ab = count_ab + 1
  end if
end do

count_a = count_a - count_ab
count_b = count_b - count_ab

if ( count_a == 0 .and. count_b == 0 .and. count_ab == 0 ) then
  print'(i0)', count
  stop
end if

if ( count_a == 0 .and. count_b == 0 ) then
  print'(i0)',  count + count_ab - 1
else
  print'(i0)',  count + min(count_a,count_b) + count_ab
end if

END PROGRAM ATCODER


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

int main() {
	int a, b, k;
	cin >> a >> b >> k;
	if (a > b)swap(a, b);
	int counter = 0;
	for (size_t i = a; i >= 1; i--)	{
		if (a % i == 0 && b % i == 0)counter++;
		if (counter == k) {
			cout << i << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
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; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll modpow(ll a, ll n){
  if(n==0)return 1;
  if(n%2==0){
    ll t=modpow(a,n/2);
    return t*t%MOD;
  }
  return a*modpow(a,n-1)%MOD;
}
ll modinv(ll a){
  return modpow(a,MOD-2);
}
long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
 
    UnionFind(int n = 1) {
        init(n);
    }
 
    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;
    }
 
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
 
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
 
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};
vvl G;
ll dfs(int v){
  ll res=1;
  for(auto nv:G[v]){
    res+=dfs(nv);
  }
  return res;
}
    
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  COMinit();
  
  int n;
  cin >> n;
  int ans=1;
  while(ans<=n){
    ans*=2;
  }
  cout << ans/2 << endl;
}


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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int _i=(first);_i<(last);++_i){cout<<#a<<"["<<_i<<"] = "<<(a)[_i]<<endl;}
#define PRINTI(a,i)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<#i<<"] = "<<#a<<"["<<(i)<<"] = "<<(a)[i]<<endl;
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#define PRINTI(a,i)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define MOD 1000000007
//#define MOD 998244353

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

template <class T, class U>
std::ostream& operator<<(std::ostream &os, const std::pair<T, U> &p) {
	os << "(" << p.first << ", " << p.second << ")";
	return os;
}
 
template <class T>
std::ostream& operator<<(std::ostream &os, const std::vector<T> &v) {
    os << "[";
	for (int i = 0; i < v.size(); ++i) {
        if (i) {
            if (i % 5 == 0) {
                os << ",\n ";
            } else {
                os << ", ";
            }
        }
		os << v[i];
	}
	os << "]";
	return os;
}

template <class T>
using vec2 = vector<vector<T>>;

template <class T>
using vec3 = vector<vector<vector<T>>>;

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

int ceildiv(int x, int y) {
    return (x + y - 1) / y;
}

template <class Pred>
ll partition_point_ll(ll first, ll last, Pred p) {
    ll count = last - first;
    while (count > 0) {
        ll step = count / 2;
        ll mid = first + step;
        if (p(mid)) {
            first = mid + 1;
            count -= step + 1;
        } else {
            count = step;
        }
    }
    return first;
}

int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);

    constexpr int A_MAX = 1000000000;

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

    // K回までの切断でx以下にできるか
    // できれば false.
    function<bool(int)> f = [&](int x) {
        ll cnt = 0;
        REP(i, N) {
            cnt += ceildiv(A[i], x) - 1;
            if (cnt > K) {
                break;
            }
        }
        return !(cnt <= K);
    };

    int result = partition_point_ll(1, A_MAX + 1, f);

    cout << result << endl;

    return 0;
}


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

int main() {
    int X, N;

    cin >> X >> N;

    int p[N];

    int ans = X;

    int i, j;

    for (i = 0; i < N; i++) {
        cin >> p[i];
    }

    for (i = 0; i <= N; i++) {
        for (j = 0; j < N; j++) {
            if (p[j] == X - i) {
                break;
            }
        }

        if (j == N) {
            ans = X - i;
            break;
        }

        for (j = 0; j < N; j++) {
            if (p[j] == X + i) {
                break;
            }
        }

        if (j == N) {
            ans = X + i;
            break;
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 3612
use std::io::*;
use std::collections::HashMap;

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

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

fn main() {
    let n = read::<usize>();
    let v = read_vec::<usize>();
    let mut map: HashMap<usize,usize> = HashMap::new();
    for x in v {
        if let Some(c) = map.get_mut(&x) {
            *c += 1;
            continue;
        }
        map.insert(x,1);
    }
    let mut ans = 0;
    for (x,c) in map {
        if x > c {
            ans += c;
        } else {
            ans += c - x;
        }
    }
    println!("{}",ans);
}


Measured memory_bytes: 13560
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 1001001001001001001;  // > 10^18
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int main() {

    string s; cin >>s;
    set<char> c;

    for (int i = 0; i < s.length(); i++) {
        c.insert(s[i]);
    }
    
    if (c.size() == s.length()) {
        cout << "yes" << endl;
    } else {
        cout << "no" << endl;
    } 

    return 0;
}


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

void solve()
{
    ll n, d;
    cin >> n >> d;
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        ll x, y;
        cin >> x >> y;

        if(x * x + y * y <= d * d)
        {
            ans++;
        }
    }
    cout << ans << endl;
}


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


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

struct city {
    int p;
    int y;
    int n;
    string id;
};

int main() {
    int n, m;
    cin >> n >> m;
    vector<city> c(m);
    for(int i = 0; i < m; i++){
        cin >> c[i].p >> c[i].y;
        c[i].n = i;
    }

    sort(begin(c), end(c), [](auto a, auto b) {return a.p == b.p ? a.y < b.y : a.p < b.p; });
    for(int i = 0, s = -1, t = 1;i < m; i++, t++){
        if(c[i].p != s) s = c[i].p, t = 1;
        stringstream ss;
        ss << setfill('0') << setw(6) << c[i].p;
        ss << setfill('0') << setw(6) << t;
        c[i].id = ss.str();
    }

    sort(begin(c), end(c), [](auto a, auto b) {return a.n < b.n; });
    for(auto& e : c) cout << e.id << endl;
    return 0;
}

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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;

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

constexpr long long mod = 1000000007;

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

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

    double a, b, h, m;
    cin >> a >> b >> h >> m;

    double pi = 3.1415926535898;

    double c = h * 360.0 / 12.0 + m * 30 / 60.0;
    double d = m * 360.0 / 60.0;

    double ans;

    if (c > d) {
        double e = (c - d);
        if (e > 180.0) {
            e = 360.0 - e;
        }

        e = e * pi / 180.0;

        ans = sqrt(a * a + b * b - 2 * a * b * cos(e));
    } else {
        double e = (d - c);

        if (e > 180.0) {
            e = 360.0 - e;
        }

        e = e * pi / 180.0;

        ans = sqrt(a * a + b * b - 2 * a * b * cos(e));
    }

    printf("%.10lf\n", ans);
}

Measured memory_bytes: 4184
import java.util.*;

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

class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        StringBuffer b = new StringBuffer();
        for (int i = 0; i < s.length; i++) {
            char ch = s[i];
            int len = b.length();
            if (ch == 'B' && len > 0) {
                b.deleteCharAt(len - 1);
            } if (ch == 'B') {
            } else {
                b.append(ch);
            }
        }
        System.out.println(b.toString());
        return;
    }

}

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

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

  vector<int> a(n), b(n), c(n-1);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  rep(i, n-1) cin >> c[i];

  int sum = b[n-1];
  rep(i, n-1){
    sum += b[i];
    if(a[i+1] - a[i] == 1){
      sum += c[a[i]-1];
    }
  }

  cout << sum << endl;

}


Measured memory_bytes: 256