akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#else
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
 public:
  int a[maxn];
  int pos[maxn];
  void solve() {
    int n;
    i64 k;
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    vector<int> c;
    c.push_back(1);
    pos[1] = 1;
    while (!pos[a[c.back()]]) {
      c.push_back(a[c.back()]);
      pos[c.back()] = c.size();
    }
    if (k < c.size()) {
      cout << c[k] << '\n';
    } else {
      k -= c.size();
      int M = c.size() - pos[a[c.back()]] + 1;
      k %= M;
      int ans = c[pos[a[c.back()]] - 1];
      for (int i = 0; i < k; ++i) {
        ans = a[ans];
      }
      cout << ans << '\n';
    }
  }
} NSPACE;
int main() {
  FPEN;
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  NSPACE.solve();
}

Measured memory_bytes: 5816
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    int dp[n];dp[0]=0;dp[1]=abs(arr[1]-arr[0]);
    for(int i=2;i<n;i++)
    {
        dp[i]=min((dp[i-1]+abs(arr[i]-arr[i-1])),(dp[i-2]+abs(arr[i]-arr[i-2])));
        //cout<<dp[i]<<" ";
    }
    cout<<dp[n-1];
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] H = new int[N];
        int count = 0;
        boolean[] b = new boolean[N];
        for (int i = 0; i < N; i++) {
        	H[i] = sc.nextInt();
        }
        Set<int[]> set = new HashSet<>();
        for (int i = 0; i < M; i++) {
        	int[] ar = new int[2];
        	int A1 = sc.nextInt();
        	int B1 = sc.nextInt();
        	if (H[A1 - 1] < H[B1 - 1]) {
        		b[A1 - 1] = true;
        	} else if (H[A1 - 1] > H[B1 - 1]) {
        		b[B1 - 1] = true;
        	} else {
        		b[A1 - 1] = true;
        		b[B1 - 1] = true;
        	}
        }
        for (boolean bb: b) {
        	if (!bb) count++;
        }
        System.out.println(count);
    }
}

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

int main() {
  int sx, sy, tx, ty, dx, dy;
  cin >> sx >> sy >> tx >> ty;
  dx = tx - sx;
  dy = ty - sy;
  cout << string(dy, 'U') << string(dx, 'R');
  cout << string(dy, 'D') << string(dx, 'L');
  cout << "L" << string(dy + 1, 'U') << string(dx + 1, 'R') << "D";
  cout << "R" << string(dy + 1, 'D') << string(dx + 1, 'L') << "U";
  cout << endl;
  getchar();
}

Measured memory_bytes: 3620
#include<iostream>
#include<string>
#include<cstring>

int main(){
    using namespace std;

    int n;
    string taro,hanako;
    int scota=0,scoha=0;

    cin>>n;
    for(int i=0;i<n;i++){
        cin>>taro>>hanako;
        if(taro==hanako){
            scoha+=1;
            scota+=1;
        }else if(taro>hanako){
            scota+=3;
        }else{
            scoha+=3;
        }
    }
    cout<<scota<<" "<<scoha<<endl;
    return 0;
}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define range(i, l, r) for(int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    lint A, B;
    string S;
    cin >> A >> B;
    cin >> S;
    range(i, 0, A + B + 1) {
        const char c = S.at(i);
        if (i == A && c != '-') {
            cout << "No" << "\n";
            return 0;
        }
        else if (i != A && (c - '0' < 0 || c - '0' > 9)) {
            cout << "No" << "\n";
            return 0;
        }
    }
    cout << "Yes" << "\n";
    return 0;
}


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

const long long int MOD = 1e9+7;

int main(){
	long long int n;
	cin >> n;
	vector<long long> data(n);
	for(int i=0;i<n;++i){
		cin >> data[i];
	}
	
	vector<long long> counter(65,0);
	
	for(int j=0;j<n;++j){
		for(int i=0;i<63;++i){
			counter[i] += ((data[j] >> i) & 1);
		}
	}
	long long int res = 0;
	
	for(int i=0;i<63;++i){
		//cout << i << " " << counter[i] <<endl;
		res += (1ll << i) %MOD * counter[i]%MOD * ((n-counter[i])%MOD);
		//cout << res <<" " << (1ll << i) %MOD <<endl;
		res %=MOD;
	}
	
	cout << res <<endl;
	
	
	return 0;
}



Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <complex>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
#include <iterator>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;

int main() {
    double l;
    cin >> l;
    l /= 3;
    printf("%.10f\n", l * l * l);
    return 0;
}

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

int main()
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    while( 1 )
    {
        c = c-b;
        if( c <= 0 )
        {
            cout << "Yes" << endl;
            break;
        }
        a = a-d;
        if( a <= 0 )
        {
            cout << "No" << endl;
            break;
        }
    }
    return 0;
}



Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
const int MOD = 1e9 + 7;

int N;

int main() {
    cin >> N;
    vector<ll> A(N);
    vector<ll> sum(N + 1, 0);  // sum[i+1] := A[i] までの和
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
        sum[i + 1] = sum[i] + A[i];
    }

    ll P, Q, R, S;
    ll ans = 1e18;
    for (int i = 2; i <= N - 2; i++) {  // [0,i) と[i,N) に分ける
        // [0,id) と [id, i)
        int id = lower_bound(ALL(sum), sum[i] / 2) - sum.begin();
        if (i - id < 1) {
            id--;
        } else {
            if (abs(sum[i] - sum[id - 1] * 2) < abs(sum[i] - sum[id] * 2)) id--;
        }
        P = sum[id];
        Q = sum[i] - sum[id];

        // [i, id2) と[id2, N)
        int id2 = lower_bound(ALL(sum), (sum[N] - sum[i]) / 2 + sum[i]) - sum.begin();
        if (N - id2 < 1) {
            id2--;
        } else {
            if (abs((sum[N] - sum[id2 - 1]) - (sum[id2 - 1] - sum[i])) < abs((sum[N] - sum[id2]) - (sum[id2] - sum[i]))) id2--;
        }
        R = sum[N] - sum[id2];
        S = sum[id2] - sum[i];
        //cout << 0 << " " << id << " " << i << " " << id2 << " " << N << " " << P << " " << Q << " " << R << " " << S << " " << ans << endl;
        chmin(ans, max(P, max(Q, max(R, S))) - min(P, min(Q, min(R, S))));
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h> 
#define MAX 1000
using namespace std; 
  
// Function to print Excel column name for a given column number 
void printString(long long int n) 
{ 
    char str[MAX]; // To store result (Excel column name) 
    int i = 0; // To store current index in str which is result 
  
    while (n > 0) { 
        // Find remainder 
        int rem = n % 26; 
  
        // If remainder is 0, then a 'Z' must be there in output 
        if (rem == 0) { 
            str[i++] = 'z'; 
            n = (n / 26) - 1; 
        } 
        else // If remainder is non-zero 
        { 
            str[i++] = (rem - 1) + 'a'; 
            n = n / 26; 
        } 
    } 
    str[i] = '\0'; 
  
    // Reverse the string and print result 
    reverse(str, str + strlen(str)); 
    cout << str << endl; 
  
    return; 
} 
  
// Driver program to test above function 
int main() 
{ 
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("E:/codes/testcases/input.in", "r", stdin);
    // for writing output to output.txt
    freopen("E:/codes/testcases/output.in", "w", stdout);
    #endif
    long long int a,b,x,n,m,k,sum=0,ans=0,res=0;
    cin >> n;
    
    printString(n);
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef signed long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
//vvi(n, vector<int>(m, -1))
 
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define all(a) (a).begin(), (a).end()
#define out(x) cout << (x) << endl;

int main(){
	int r, g, b, n;
	cin >> r >> g >> b >> n;
	int i, j, k;
	ll ans = 0;
	rep(i, 3001){
		rep(j, 3001){
			k = (n - i*r - j*g);
			if(k < 0) continue;
			if(k%b == 0) ans++;
		}
	}

	cout << ans << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define max3(a,b,c) max(a,max(b,c))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define min3(a,b,c) min(a,min(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define yes cout<<"YES"<<nl
#define no  cout<<"NO"<<nl
#define nl  '\n'
#define tr ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define tst int t;cin>>t;while(t--)
#define     Max             1000000000000000014
#define     Min             -1000000000000000014
#define     PI              3.1415926535897
#define     Fr               first
#define     Se               second
#define     all(v)          v.begin(),v.end()
#define     mem(a,v)        memset(a,v,sizeof(a))
#define     space            ' '
#define COUT(v) for(auto it:v)cout<<it<<space;cout<<nl;
/*error cheaking method starts from here */
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
 
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}
/*error cheaking method ebds here */
 
#define vi    vector<int>
#define    vl    vector<ll>
#define    si    set<int>
#define    sl    set<ll>
#define    msi    multiset<int>
#define    msl    multiset<ll>
#define    pii    pair<int,int>
#define    pil    pair<int,ll>
#define    pli    pair<ll,int>
#define    pll    pair<ll,ll>
#define    mp    make_pair
#define    pb    push_back
int main()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll m1=a*c,m2=a*d,m3=b*c,m4=b*d;
    cout<<max4(m1,m2,m3,m4);
}


Measured memory_bytes: 3644
#include<stdio.h>
int main()
{
	int n,m;
	int x,y,z,ans;
	scanf("%d%d",&n,&m);
	x=n+m;
	y=n-m;
	z=n*m;
	if(x>y)
		ans=x;
	else
		ans=y;
	if(ans>z)
		printf("%d\n",ans);
	else
		printf("%d\n",z);
	return 0;
}

Measured memory_bytes: 128
#include <cassert>
#include <queue>
#include <vector>
#include <iostream>
using namespace std;

bool rev(string &s, int i, int j, string &t, int k, int l) {
    assert(j - i == l - k);
    assert(j <= s.size());
    assert(l <= t.size());
    while (i < j) {
        if (s[i] != t[l-1]) return false;
        i++; l--;
    }
    return true;
}

bool palindrome(string &s, int i, int j) {
    assert (i <= j);
    assert (j <= s.size());
    return rev(s, i, j, s, i, j);
}

int main() {
    int N; cin >> N;
    string s[N];
    int C[N];
    for (int i = 0; i < N; i++) cin >> s[i] >> C[i];
    int pref[N][21], suf[N][21], idx = 0;
    const int goal = idx++;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= s[i].size(); j++) {
            pref[i][j] = idx++;
            suf[i][j] = idx++;
        }
    }
    vector<pair<int, int> > adj[idx];
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= s[i].size(); j++) {
            for (int k = 0; k < N; k++) {
                const int ni = s[i].size(), nk = s[k].size();
                if (j > nk) {
                    if (rev(s[i], j-nk, j, s[k], 0, nk)) {
                        adj[pref[i][j]].push_back({pref[i][j-nk], C[k]});
                    }
                    if (rev(s[i], ni-j, ni-j+nk, s[k], 0, nk)) {
                        adj[suf[i][j]].push_back({suf[i][j-nk], C[k]});
                    }
                } else {
                    if (rev(s[i], 0, j, s[k], 0, j)) {
                        adj[pref[i][j]].push_back({suf[k][nk-j], C[k]});
                    }
                    if (rev(s[i], ni-j, ni, s[k], nk-j, nk)) {
                        adj[suf[i][j]].push_back({pref[k][nk-j], C[k]});
                    }
                }
            }
            if (palindrome(s[i], 0, j))
                adj[pref[i][j]].push_back({goal, 0});
            if (palindrome(s[i], s[i].size()-j, s[i].size()))
                adj[suf[i][j]].push_back({goal, 0});
        }
    }

    long long dist[idx];
    const long long INF = 1LL<<60;
    fill(dist, dist+idx, INF);
    priority_queue<pair<long long, int> > pq;
    for (int i = 0; i < N; i++) {
        int u = pref[i][s[i].size()], v = suf[i][s[i].size()];
        dist[u] = dist[v] = C[i];
        pq.push({-C[i], u});
        pq.push({-C[i], v});
    }
    while (!pq.empty()) {
        auto [d, u] = pq.top();
        d = -d;
        pq.pop();
        if (d > dist[u]) continue;
        for (auto [v, e] : adj[u]) {
            if (d + e < dist[v]) {
                dist[v] = d + e;
                pq.push({-d-e, v});
            }
        }
    }
    // for (int i = 0; i < idx; i++) cerr << i << " " << dist[i] << endl;
    // for (int i = 0; i < idx; i++) {
    //     for (auto [u, d] : adj[i])
    //         cerr << i << " " << u << " " << d << endl;
    // }
    cout << (dist[goal] == INF ? -1 : dist[goal]) << endl;
}


Measured memory_bytes: 3336
class UnionFind
  def initialize(size)
    @rank = Array.new(size, 0)
    @parent = Array.new(size, &:itself)
  end

  def unite(id_x, id_y)
    x_parent = get_parent(id_x)
    y_parent = get_parent(id_y)
    return if x_parent == y_parent

    if @rank[x_parent] > @rank[y_parent]
      @parent[y_parent] = x_parent
    else
      @parent[x_parent] = y_parent
      @rank[y_parent] += 1 if @rank[x_parent] == @rank[y_parent]
    end
  end

  def get_parent(id_x)
    @parent[id_x] == id_x ? id_x : (@parent[id_x] = get_parent(@parent[id_x]))
  end

  def size
    @parent.map { |id_x| get_parent(id_x) }.uniq.size
  end
end

nn, mm = gets.chomp.split.map(&:to_i)

union = UnionFind.new nn

mm.times do
  union.unite(*gets.chomp.split.map { |g| g.to_i - 1 })
end

p union.size - 1


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

int main(){
    int X, N, T;
    cin >> N >> X >> T;
    int s;
    if (N%X != 0) {
        s = (N/X + 1) * T;
    } else {
        s = (N/X) * T;
    }
    cout << s;
    return 0;
}

Measured memory_bytes: 3620
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <iomanip>
#include <limits>

#define roop(i, n) for(int i=0;i<n;i++)
#define DIV 1000000007
//static const long double pi = 3.1415926535897932;

using namespace std;
using ll = long long int;
using ull = unsigned long long;

char toSmall(char c) { // 大文字を小文字へ
	return (c + 0x20);
}

char toLarge(char c) { // 小文字を大文字へ
	return (c - 0x20);
}

float myPower(int a, int n) { // aのn乗の計算
	float x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

ll combination(ll n, ll r) { // nCr の計算
	if (n < 0 || r < 0 || r > n) return -1;

	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> num(r);
	vector<ll> den(r);

	for (ll i = 0; i < r; i++) {
		num[i] = n - r + i + 1;
		den[i] = i + 1;
	}

	for (ll p = 2; p <= r; p++) {
		ll pivot = den[p - 1];
		if (pivot > 1) {
			ll offset = (n - r) % p;
			for (ll k = p - 1; k < r; k += p) {
				num[k - offset] /= pivot;
				den[k] /= pivot;
			}
		}
	}
	ll result = 1;
	for (ll k = 0; k < r; k++) {
		if (num[k] > 1) result *= num[k];
	}
	return result;
}

vector<string> split(const string& src, const char* delim = ",") { //カンマ区切り
	vector<string> vec;
	string::size_type len = src.length();

	for (string::size_type i = 0, n; i < len; i = n + 1) {
		n = src.find_first_of(delim, i);
		if (n == string::npos) {
			n = len;
		}
		vec.push_back(src.substr(i, n - i));
	}

	return vec;
}

bool check_int(string str)
{
	if (all_of(str.cbegin(), str.cend(), [](char ch) { return isdigit(ch);}))
	{
		return true;
	}
	return false;
}

struct rest {
	string s;
	int p;
	int num;

	/* -------------------------------------
	sort関数を使用したときのソートの定義をする。
	まずは文字列sでソートする。
	文字列sが同じだった場合、pでソートする。
	この条件を参考演算子で表現(ifでもOK)
	-------------------------------------*/
	bool operator<(const rest& right) const {
		return s == right.s ? p > right.p : s < right.s;
	}
};

int main() {
	int n;
	cin >> n;
	vector<int> ans(4);
	for (int i = 0; i < 4; i++) {
		ans[i] = 0;
	}
	for (int i = 0; i < n; i++)
	{
		string s;
		cin >> s;
		if (s == "AC") {
			ans[0]++;
		} else if (s == "WA") {
			ans[1]++;
		} else if (s == "TLE") {
			ans[2]++;
		} else {
			ans[3]++;
		}
	}
	cout << "AC x " << ans[0] << endl;
	cout << "WA x " << ans[1] << endl;
	cout << "TLE x " << ans[2] << endl;
	cout << "RE x " << ans[3] << endl;
	
	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false); 
    int n;
    cin>>n;
    n%=10;
    if(n==3){
        cout<<"bon";
    }else if(n==0||n==1 ||n==6 ||n==8){
        cout<<"pon";
    } else{
        cout<<"hon";
    }

    

}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

#define fread           freopen("input.txt","r",stdin)
#define fwrite          freopen("output.txt","w",stdout)
#define eb              emplace_back
#define em              emplace
#define pb              push_back
#define Mp              make_pair
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())
#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define memo(ara,val)   memset(ara,val,sizeof(ara))
#define II              ( { int a ; read(a) ; a; } )
#define LL              ( { ll a ; read(a) ; a; } )
#define DD              ({double a; scanf("%lf", &a); a;})
#define rep(i,n)        for(int i=0;i<n;i++)
#define rep1(i,n)       for(int i=1;i<=n;i++)
#define rrep(i,a,n)     for(int i=a;i<=n;i++)
#define per(i,n,a)      for(int i=n;i>=a;i--)
#define pf(n)           printf("%lld",n)
#define pfi(n)          printf("%d",n)
#define sp              printf(" ")
#define ln              printf("\n")
#define sc(x)           scanf("%lld",&x)
#define scw(x)          scanf("%I64d",&x)
#define sci(x)          scanf("%d",&x)
#define sc2(x,y)        scanf("%lld %lld",&x,&y)
#define sc3(x,y,z)      scanf("%lld %lld %lld",&x,&y,&z)
#define Found(a, b)     a.find(b) != a.end()
// bool operator< (const node& sx) const { return sx.val < val; }
//set<ll,greater<ll> >st;
//priority_queue<ll , vector<ll> , greater<ll> >
template<class T>inline bool read(T &x){ int c=getchar();int sgn=1;
  while(~c&&c<'0'|c>'9'){if(c=='-')sgn=-1;c=getchar();}
  for(x=0; ~c&&'0'<=c&&c<='9'; c=getchar())x=x*10+c-'0';x*=sgn;return ~c;
}
const ll N = 100005;
const ll MOD = 1e9+7;
ll cost[N][3];
ll dp[N][3];
int main(){
   //fread;
    ll n = LL;
    rep(i,n) cost[i][0] = LL, cost[i][1] = LL, cost[i][2] = LL;
    memset(dp, -1, sizeof(dp));
    dp[0][0] = cost[0][0], dp[0][1] = cost[0][1] , dp[0][2] = cost[0][2];
    for(ll i = 1; i<n; ++i){
        for(ll j = 0; j<3; ++j){
            for(ll k = 0; k<3; ++k){
                if(j==k) continue;
                dp[i][j] = max(dp[i][j], dp[i-1][k] + cost[i][j]);
            }
        }
    }
    ll ans =  max( dp[n-1][2], max( dp[n-1][0], dp[n-1][1] ) ) ;
    pf(ans),ln;
}











Measured memory_bytes: 4992
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<queue>
#include<cstring>

using namespace std;
typedef long long ll;

int main(){
  int sx,sy,tx,ty;
  scanf("%d %d %d %d",&sx,&sy,&tx,&ty);

  for(int i=0;i<ty-sy;i++){
    printf("U");
  }
  for(int i=0;i<tx-sx;i++){
    printf("R");
  }
  for(int i=0;i<ty-sy;i++){
    printf("D");
  }
  for(int i=0;i<tx-sx;i++){
    printf("L");
  }

  printf("L");
  for(int i=0;i<ty-sy+1;i++){
    printf("U");
  }
  for(int i=0;i<tx-sx+1;i++){
    printf("R");
  }
  printf("D");

  printf("R");
  for(int i=0;i<ty-sy+1;i++){
    printf("D");
  }
  for(int i=0;i<tx-sx+1;i++){
    printf("L");
  }
  printf("U\n");
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
int N,ame[2*N],i,j,sum1,sum=0;
scanf("%d",&N);
for(i=0;i<2*N;i++){
scanf("%d ",&ame[i]);
}
for(i=0;i<=N-1;i++){
sum1=0;
for(j=0;j<=i;j++){
sum1+=ame[j];
}
for(j=0;j<=N-1-i;j++){
 sum1+=ame[i+N+j];
}
if(sum1>=sum) sum = sum1;
}
printf("%d",sum);
return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;

int main() {
    int n;  cin >> n;
    set<ll> s;
    ll x;
    vector<ll> l;
    for (int i = 0; i < n; i++) {
        cin >> x;
        l.push_back(x);
        s.insert(x);
    }
    
    int ans = 0;
    for (int i = 0; i < l.size(); i++) {
        for (int j = i+1; j < l.size(); j++) {
            for (int k = j+1; k < l.size(); k++)
                if (abs(l[i]-l[j]) < l[k] && l[k] < l[i] + l[j] && l[i] != l[j] && l[j] != l[k] && l[k] != l[i])
                    ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define rg register
#define rep(i,a,b) for (rg int i=a;i<=b;i++)
#define per(i,a,b) for (rg int i=b;i>=a;i--)
#define pb push_back
#define lowbit(x) (x&(-x))
#define mk make_pair
#define VI vector<int>
#define pii pair<int,int>
#define pLL pair<long long,long long>
#define fi first
#define se second
#define il inline
#define ll long long
#define db double
#define ld long double
#define inf 0x3f3f3f3f3f
#define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<15,stdin),p1==p2)?EOF:*p1++)
char buf[1<<15],*p1 = buf,*p2 = buf;
inline ll read(){
    #define num ch-'0'
    char ch;bool flag=0;ll res;
    while(!isdigit(ch=getc()))
    (ch=='-')&&(flag=true);
    for(res=num;isdigit(ch=getc());res=res*10ll+num);
    (flag)&&(res=-res);
    #undef num
    return res;
}
inline void write(ll x){
	if (x < 0) x = ~x + 1ll, putchar('-');
	if (x > 9) write(x / 10ll);
	putchar(x % 10ll + '0');
}
#define mid ((l + r)>>1)
#define ls (x<<1)
#define rs ((x<<1)|1)
#undef mid
#undef ls
#undef rs
#define maxn 310
ll d[maxn][maxn];
ll a[maxn][maxn];
void solve()
{
	int n = read(),m = read();
	ll l = read();
	rep(i,1,n) rep(j,1,n) d[i][j] = (i == j) ? 0:inf;
	rep(i,1,m)
	{
		int x = read(),y = read();
		ll z = read();
		if(z <= l) d[x][y] = d[y][x] = min(d[x][y],z);
	}
	rep(k,1,n)
	{
		rep(i,1,n)
		{
			rep(j,1,n)
			{
				d[i][j] = min(d[i][j],d[i][k] + d[k][j]);
			}
		}
	}
	rep(i,1,n)
	{
		rep(j,1,n)
		{
			a[i][j] = (d[i][j] <=l)?1:inf;
			if(i == j) a[i][j] = 0;
		}
	}
	rep(k,1,n)
	{
		rep(i,1,n)
		{
			rep(j,1,n)
			{
				a[i][j] = min(a[i][j],a[i][k] + a[k][j]);
			}
		}
	}
	int q = read();
	while(q--)
	{
		int s = read(),t = read();
		cout<<((a[s][t]>=inf)?-1:a[s][t]-1)<<endl;
	}
}
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("data.txt","r",stdin);
	#endif
//	int T = read();
//	while(T--)
	solve();
}

Measured memory_bytes: 5140
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353,INF=1e18;



int main() {
    int N,S;
    cin>>N>>S;
    vector<int> A(N);
    rep(i,N)cin>>A.at(i);
    vector<vector<ll>> dp(N+1,vector<ll>(S+1));
    dp.at(0).at(0)=1;
    rep(i,N){
        rep(j,S+1){
            if(j+A.at(i)<=S)dp[i+1][j+A.at(i)]+=dp[i][j];
            dp[i+1][j+A.at(i)]%=MOD2;
            dp[i+1][j]+=dp[i][j]*2%MOD2;
            dp[i+1][j]%=MOD2;
        }
    }
    cout<<dp[N][S]<<endl;
}

Measured memory_bytes: 73696
#include<bits/stdc++.h>
using namespace std;
struct _IO{_IO(){ios::sync_with_stdio(0);cin.tie(0);}}_io;
typedef long long ll; typedef long double db;
const int N = 5e5 + 5, M = 1e9 + 7;

typedef pair<int, int> pii;
#define fi first
#define se second

int bit[N];
void add(int p, int v) {
  for (; p < N; p += p&-p) bit[p] += v;
}
int get(int p) {
  int res = 0;
  for (; p; p -= p&-p) res += bit[p];
  return res;
}
vector<pii> q[N];
int ans[N], lst[N], a[N];

int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int l, r;
  for (int i = 1; i <= m; i++) {
    cin >> l >> r;
    q[r].push_back({l, i});
  }
  for (int i = 1; i <= n; i++) {
    if (lst[a[i]]) add(lst[a[i]], -1);
    add(i, 1);
    lst[a[i]] = i;
    for (auto &p : q[i]) {
      ans[p.se] = get(i) - get(p.fi-1);
    }
  }
  for (int i = 1; i <= m; i++) {
    cout << ans[i] << '\n';
  }
}


Measured memory_bytes: 33180
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;



int main(){

  int n,k;
  cin>>n>>k;
  llong sho = (int)n/k;
  llong ans = sho*sho*sho;
  if(k%2==0){
    sho = n/(k/2) - n/k;
    ans += sho*sho*sho;
  }
  cout<<ans<<endl;

  return 0;
}

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

int main(){
    string s;
    cin >> s;
    int MAX = 0;
    rep(i, s.size()){
        for(int j=i;j<s.size();j++){
            string tmp = s.substr(i,j-i+1);
            bool flag = true;
            rep(k,tmp.size()){
                if(!(tmp[k]=='A' || tmp[k]=='C' || tmp[k]=='G' || tmp[k]=='T')){
                    flag = false;
                    break;
                }
            }
            if(flag){
                // cout << tmp << endl;
                MAX = max(MAX, (int)tmp.size());
            }
        }
    }
    printf("%d\n", MAX);
    return 0;
}

Measured memory_bytes: 256
import Control.Monad

main = do
    [a, b, c, d, e, k] <- forM [1 .. 6] $ \i -> do
        read <$> getLine
    putStrLn $ solve a b c d e k

solve :: Int -> Int -> Int -> Int -> Int -> Int -> String
solve a b c d e k | e - a <= k = "Yay!"
                  | otherwise  = ":("


Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool compare( int a , int b)
{
    return a% 10 < b%10;
}
int main()
{
    int a[5];
    for(int i=0;i<5;i++)
    {
        cin>>a[i];
    }
    sort(a , a+5 , compare);
    int ans =0;
    bool found = false;
    for(int i=0;i<5;i++)
    {
        if( a[i] %10 != 0 && !found  )
        {
            ans += a[i];
            found = true;
        } else
        {
            int temp = a[i] %10;

            if(temp != 0)
            ans += a[i] + 10-temp ;
            else
                ans += a[i];
        }
    }
    cout<<ans;
}


Measured memory_bytes: 3624
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<set>
#include<map>
using namespace std;
 
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define ROF(i,b,a) for (int i=(b);i>(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,n-1,-1)
 
typedef int i32;
typedef long long int i64;
typedef unsigned long long int ui64;
typedef float f32;
typedef double f64;
typedef long double f128;
typedef pair<int,int> Pi;
 
constexpr int INF = 1e9 + 7;
constexpr int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
 
int main() {
    int N; cin>>N;
    int sum = 0;
    REP(i,N) {
        int tmp;
        cin>>tmp;
        sum += tmp-1;
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    constexpr int H = 3600;
    constexpr int M = 60;
    constexpr int N = 24 * H + 1;
    for(;;){
        int n;
        cin >> n;
        if(n == 0)  return 0;
        vector<int> S(N, 0);
        for(int i = 0; i < n; ++i){
            string s, t;
            cin >> s >> t;
            int L = stoi(s.substr(0, 2)) * H + stoi(s.substr(3, 2)) * M + stoi(s.substr(6, 2));
            int R = stoi(t.substr(0, 2)) * H + stoi(t.substr(3, 2)) * M + stoi(t.substr(6, 2));
            ++S[L], --S[R];
        }
        int ans = 0;
        for(int i = 0; i + 1 < N; ++i)  chmax(ans, S[i + 1] += S[i]);
        cout << ans << '\n';
    }
}


Measured memory_bytes: 3424
#include <iostream>
#include <vector>
#include <utility>
#include <cstdlib>
#define llint long long

using namespace std;
typedef pair<llint, llint> P;

llint T;
llint p, q;
vector<P> vec[20005];

int main(void)
{
	for(int i = -200; i <= 200; i++){
		for(int j = -200; j <= 200; j++){
			llint x = i*i+j*j;
			if(x < 20005) vec[x].push_back(P(i, j));
		}
	}
	
	cin >> T;
	for(int t = 0; t < T; t++){
		cin >> p >> q;
		
		llint v = p*p+q*q, ans = 0;
		for(int i = 1; i <= v; i++){
			if(v % i) continue;
			for(int j = 0; j < vec[i].size(); j++){
				llint x = vec[i][j].first, y = vec[i][j].second;
				//cout << x << " " << y << endl;
				if(abs(x*p+y*q) % (x*x+y*y) == 0 && abs(x*q-y*p) % (x*x+y*y) == 0) ans++;
			}
		}
		if(ans == 8) cout << "P" << endl;
		else cout << "C" << endl;
	}
	return 0;
}


Measured memory_bytes: 4500
#include <bits/stdc++.h>
//#include "atcoder/all"
typedef long long int ll;
using namespace std;
// using namespace atcoder;
int main() {
    int n;
    cin >> n;
    ll ret = 0;
    ll now = -1;
    bool ok = true;
    for (int i = 0; i < n; i++) {
        ll a;
        cin >> a;
        if (a >= now + 2) {
            ok = false;
        }
        else if (a == now + 1) {
            now = a;
            if (i == n - 1) ret += a;
        }
        else {
            ret += now;
            now = a;
            if (i == n - 1) ret += a;
        }
    }
    if (!ok) cout << -1 << endl;
    else cout << ret << endl;
    return 0;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(a) int(a.size())
#define clr(a) memset(a,0,sizeof(a))
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const int inf=1e9;
const ll Inf=1e18;
const int N=1e5+10;
const int mod=0;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
template<typename T> bool chkmax(T &a,T b) { return a<b?a=b,1:0; };
template<typename T> bool chkmin(T &a,T b) { return a>b?a=b,1:0; };
int add(int a,int b) { return a+b>=mod?a+b-mod:a+b; }
int sub(int a,int b) { return a-b<0?a-b+mod:a-b; }
void inc(int &a,int b) { a=(a+b>=mod?a+b-mod:a+b); }
void dec(int &a,int b) { a=(a-b<0?a-b+mod:a-b); }
int n;
pii a[N];
set<pii> l,r;
ll work() {
    ll ret=0;
    int now=0;
    for(int i=1;i<=n;i++) {
        if(i&1) {
            int x=(--l.end())->se;
            l.erase(mp(a[x].fi,x));
            r.erase(mp(a[x].se,x));
            if(now<a[x].fi) ret+=a[x].fi-now,now=a[x].fi;
            else if(now>a[x].se) ret+=now-a[x].se,now=a[x].se;
        }
        else {
            int x=r.begin()->se;
            l.erase(mp(a[x].fi,x));
            r.erase(mp(a[x].se,x));
            if(now<a[x].fi) ret+=a[x].fi-now,now=a[x].fi;
            else if(now>a[x].se) ret+=now-a[x].se,now=a[x].se;
        }
    }
    ret+=abs(now);
    return ret;
}
int main() {
    n=gi();
    for(int i=1;i<=n;i++) {
        a[i].fi=gi(),a[i].se=gi();
        l.insert(mp(a[i].fi,i)),r.insert(mp(a[i].se,i));
    }
    ll ans=work();
    l.clear(),r.clear();
    for(int i=1;i<=n;i++) {
        a[i].fi*=-1,a[i].se*=-1,swap(a[i].fi,a[i].se);
        l.insert(mp(a[i].fi,i)),r.insert(mp(a[i].se,i));
    }
    ans=max(ans,work());
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 10368
#include<iostream>
#include<iomanip>
#include<stdio.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#include<math.h>
#include<unordered_set>
using namespace std;

const int MAX = 26;

char maxch(bool check[],int i) {
	for (; i < MAX; i++) {
		if (check[i] == false) {
			return 'a' + i;
		}
	}
	return '0';
}

int main() {
	string str;
	bool check[MAX] = { false };

	cin >> str;

	for (int i = 0; i < str.length(); i++) {
		check[str[i] - 'a'] = true;
	}

	int i = str.length() - 1;
	int j = 0;

	 while(true){
		char c = maxch(check, j);

		if (c != '0') {
			str += c;
			break;
		}

		if (str.length() == 0)break;
		
		check[str[i] - 'a'] = false;	
		j = str[i] - 'a' + 1;
		str.pop_back();
		i--;
	}

	if (str.length() == 0)cout << -1 << endl;
	else cout << str << endl;


	return 0;
}

Measured memory_bytes: 256
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int a, b;
    cin >> a >> b;
    cout << a / b + (a % b > 0);
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    static class Task {

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            long d = in.nextInt();
            int ans = 0;
            for (int i = 0; i < n; i++) {
                long x = in.nextInt();
                long y = in.nextInt();
                if (x * x + y * y <= d * d) {
                    ans++;
                }
            }

            out.println(ans);
        }
    }

    private static void sort(double[] arr) {
        Double[] objArr = Arrays.stream(arr).boxed().toArray(Double[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(int[] arr) {
        Integer[] objArr = Arrays.stream(arr).boxed().toArray(Integer[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(long[] arr) {
        Long[] objArr = Arrays.stream(arr).boxed().toArray(Long[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task task = new Task();
        task.solve(1, in, out);
        out.close();
    }

    public static void main(String[] args) {
        new Thread(null, () -> solve(), "1", 1 << 26).start();
    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

    }

}

Measured memory_bytes: 54604
#include <iostream>
#include <fstream>
#include <algorithm>       // for next_permutation
#include <vector>
#include <queue>
#include <bits/stl_numeric.h>

#define DEBUG 0
#define REP(i, n) for (long long i = 0; i < (n); i++) 
using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;


ll N, K;
int main() {

    cin >> N >> K;

    //種類が何個あるか
    vector <int> v[N];
    //ネタ
    vector <ll> t(N);
    //おいしさ
    vector <ll> d(N);
    vector <pii> p(N);
    REP(i,N)
    {
        cin >> t[i] >> d[i];
        --t[i];
        p.push_back(pii(d[i], t[i]));
    }
    //美味しさの順でソートする
    sort(p.begin(),p.end(), greater<pii>());

    ll res = 0;
    priority_queue <pii, vector<pii>, greater<pii> > que;
    ll cnt = 0;

    for(int i = 0; i < K; ++i)
    {
        if(v[p[i].second].size() == 0)
        {
            ++cnt;
        }
        else
        {
            //入れ替える可能性のあるものをqueに突っ込んどく(queは昇順ソートされている)
            que.push(p[i]);
        }
        res += p[i].first;
        v[p[i].second].push_back(p[i].first);
    } 

    res += (ll)cnt * cnt;
    ll out = res;
    int cur = K;
    for(; cur < N; ++cur)
    {
        if(que.empty())break;
        int idx = p[cur].second;
        if(v[idx].size() == 0)
        {
            pii top = que.top();
            que.pop();
            v[idx].push_back(p[cur].first);
            ++cnt;
            res += 2 * cnt - 1;
            res -= top.first;
            res += p[cur].first;
            //入れ替えて種類を増やしたときの値を求める
            out = max(res, out);
        }
    }


    cout << out << endl;
    return 0;
}


Measured memory_bytes: 8176
#define _USE_MATH_DEFINES
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int N;
	cin>>N;
	if(N<=999){
		cout << "ABC" << endl;
	}else{
		cout << "ABD" << endl;
	}
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define show(x) std::cerr << #x << " = " << (x) << std::endl
using ll = long long;
template <typename T>
constexpr T MOD = static_cast<T>(1000000007);
template <typename T>
constexpr T INF = std::numeric_limits<T>::max() / 16;
int main()
{
    int N;
    std::string A, B, C;
    std::cin >> N >> A >> B >> C;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        std::set<char> st;
        st.insert(A[i]), st.insert(B[i]), st.insert(C[i]);
        ans += st.size() - 1;
    }
    std::cout << ans << std::endl;
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  for(int i = 1; i <= 9; i++){
    for(int j = 1; j <= 9; j++){
      if(i * j == n){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
w = input()

# a ~ z までの辞書を生成(valueの初期値は0)
d = {chr(i): 50 for i in range(97, 97+26)}

for c in w:
    d[c] += 1

ans = 'Yes'
for k, v in d.items():
    if v%2==1:
        ans = 'No'
        break

print(ans)

Measured memory_bytes: 2940
#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 n;
	cin >> n;

	map<int,int> m;
	rep(i,n){
		int a;
		cin >> a;
		m[a]++;
	}

	int ans = 0;
	for(auto i : m){
		if(i.first == i.second) continue;
		else if(i.first < i.second){
			ans += i.second - i.first;
		}else{
			ans += i.second;
		}
	}
	cout << ans << endl;
}


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

int main() {
  int N,f,a;
  cin >> N ;
  vector<int> b(N+1,0);
  a = sqrt(N);
  for(int j=1 ; j<=a ; j++){
    for(int k=1 ; k<=a ; k++){
      for(int l=1 ; l<=a ; l++){
        f = j*j + k*k + l*l + j*k + k*l + l*j ;
        if(f <= N) b.at(f)++ ;
      }
    }
  }
  for(int i=1; i<=N ; i++) cout << b.at(i)<< endl;

}

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

char str[205];

bool judge(int i, int j) {
	int ll = (j-i+1)>>1;
	for(int i=0; i+ll<=j; i++) {
		if(str[i+ll]!=str[i]) return false;
	}
	return true;
}

int main() {
	cin >> str;
	int len = strlen(str);
	for(int i=len-2; i>1; i-=2) {
		for(int j=0; j<=len-i; j++) {
			if(judge(j, j+i-1)) {
				printf("%d\n", i); return 0;
			}
		}
	}
}

Measured memory_bytes: 256
x = gets.chomp.to_i

res = 1
2.upto x/2 do |n|
  count = 2
  loop do
    if n**count > x
      #res = {x: count}
      tmp = n**(count-1)
      if count>2 && tmp>res
        res = tmp
      end
      break
    end
    count+=1
  end
end

puts res


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 1<<20;
ll n, t, e, x[maxn], dp[maxn];
int main() {
	dp[0] = x[0] = 0;
	cin >> n >> e >> t;
	for(int i = 1; i <= n; i++) cin >> x[i];
	int j = 0;
	multiset<ll> p, s;
	for(int j = 1, i = 1; i <= n; i++) {
		while(2*(x[i]-x[j]) > t) {
			s.erase(s.find(dp[j-1] - x[j] + (x[j] - x[j-1])));
			p.insert(dp[j-1] - 3ll*x[j] + (x[j] - x[j-1]));
			//cout << j << " p " << (dp[j-1] - 3ll*x[j] + (x[j] - x[j-1])) << '\n';
			j++;
		}
		dp[i] = dp[i - 1] + (x[i] - x[i-1]) + t;
		if(!s.empty()) dp[i] = min(dp[i], *s.begin() + x[i] + t);
		if(!p.empty()) dp[i] = min(dp[i], *p.begin() + 3ll*x[i]);
		s.insert(dp[i-1] - x[i] + (x[i] - x[i-1]));
		//cout << i << " s " << (dp[i-1] - x[i] + (x[i] - x[i-1])) << '\n';
		//cout << i << " " << dp[i] << " " << x[i] << " " << t << "\n";
	}
	cout << dp[n]+(e-x[n]);
}


Measured memory_bytes: 7808
#!/usr/bin/env python3


def main():
    n = int(input())
    A = list(map(int, input().split()))
    MOD = 10 ** 18
    ans = 1
    if 0 in A:
        print('0')
        return
    for i in range(n):
        ans *= A.pop(0)
        if ans > MOD:
            print('-1')
            return
    print(ans)


if __name__ == "__main__":
    main()


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



int main() 
{
  string T; cin>>T;
  rep(i,T.size())
  {
    if(T.at(i)=='?')
    {
      T.at(i)='D';
    }
  }
  cout<<T<<endl;
}


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

using namespace std;
int n;
int k;
int a[1000009];
int main()
{
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>a[i];
    long long sum=0;
    for(int i=0;i<n;i++)
    {
        sum=sum+min(abs(0-a[i])*2,abs(k-a[i])*2);
    }
    cout<<sum;
}


Measured memory_bytes: 256