akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define all(cont) cont.begin(), cont.end()
#define pb push_back
#define fi first
#define se second
#define DEBUG(x) cerr << (#x) << ": " << (x) << '\n'

using namespace std;

typedef pair <int, int> pii;
typedef vector <int> vi;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll, ll> pll;
typedef long double ld;

ld xIntersect (pll a, pll b) {
  if (a.fi == b.fi) return numeric_limits <ld>::infinity();
  return (b.se - a.se) / (a.fi - b.fi);
}

bool intersectsEarlier (pll to_intersect, pll curr_line, pll last_line) {
  return (curr_line.se - to_intersect.se) * (to_intersect.fi - last_line.fi) <=
         (last_line.se - to_intersect.se) * (to_intersect.fi - curr_line.fi);
}

ll valueAt (pll a, ll x) {
  return a.fi * x + a.se;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifdef LOCAL_DEFINE
  freopen (".in", "r", stdin);
#endif

  ll n, c;
  cin >> n >> c;
  vector <ll> h (n + 2);
  for (int i = 1; i <= n; ++i) {
    cin >> h[i];
  }

  vector <ll> min_cost (n + 2);
  min_cost[1] = 0;
  deque <pll> dq;
  dq.pb ({-2 * h[1], min_cost[1] + h[1] * h[1]});
  for (int i = 1; i <= n; ++i) {
    while (dq.size() >= 2 && valueAt (dq[0], h[i]) >= valueAt (dq[1], h[i])) {
      dq.pop_front();
    }

    min_cost[i] = valueAt (dq[0], h[i]) + h[i] * h[i] + c;

    pll curr_line = {-2 * h[i], min_cost[i] + h[i] * h[i]};
    int sz = dq.size();
    while (sz >= 2 && intersectsEarlier (dq[sz - 2], curr_line, dq[sz - 1])) {//xIntersect (dq[sz - 1], dq[sz - 2]) >= xIntersect (curr_line, dq[sz - 2])
      --sz;
      dq.pop_back();
    }
    dq.pb (curr_line);
  }

  cout << min_cost[n] << '\n';

  return 0;
}


Measured memory_bytes: 5632
#include<stdio.h>
int main()
{
  int a[3],p=0,sum=0;
  scanf("%d %d %d", &a[0], &a[1], &a[2]);
  for(int i=0;i<3;i++){
   if(a[i]==5) p++;
   sum+=a[i];
  }
  if(p==2 && sum==17) printf("YES\n");
  else printf("NO\n");
  return 0;
}


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

int main()
{
  string word,answer;
  cin >> word;
  
  if(word.at(word.size()-1) == 's')
  {
    answer = word + "es";
  }
  else
  {
    answer = word + 's';
  }
  cout << answer << endl;
}

Measured memory_bytes: 3624
#include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <vector>
    #include <string>
    #include <string.h>
     
    typedef long long ll;
    using namespace std;
    const ll INF = 1000000000000000000ll;
    const ll MOD = 1000000007ll;
     
    const double EPS = 1e-8;
     
    int main()
    {
   		long K,S;
		long ans=0;

		cin >> K >> S ;

		for(int i=0;i<=K;i++){
			for(int j=0;j<=K;j++){
				int z=S-i-j;
				if(z>=0&&z<=K) ans++;
			}
		}

		cout << ans;

		return 0;
    }

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int n,k,x,y;
	cin>>n>>k>>x>>y;
	int ans=0;
	if(k>n)
	{
		cout<<x*n;
		return 0;
	}
	ans+=k*x;
	ans+=(n-k)*y;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <tuple>
using namespace std;
const long long INF = 1LL << 60;    // 1.15x10^18
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

//-----------------------
const int MOD = (int)1e9 + 7;
struct mint { long long n; mint(long long n_ = 0) : n(n_ % MOD) { if (n < 0) n += MOD; } };
mint operator+(mint a, mint b) { return (a.n += b.n) >= MOD ? a.n - MOD : a.n; }
mint operator-(mint a, mint b) { return (a.n -= b.n) < 0 ? a.n + MOD : a.n; }
mint operator*(mint a, mint b) { return a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }
ostream &operator<<(ostream &os, mint a) { return os << a.n; }
istream &operator>>(istream &is, mint& a) { return is >> a.n; }
mint inv(mint x) { long long a = x.n, b = MOD, u = 1, v = 0;
    while (b) { long long t = a/b; swap((a -= t*b), b); swap((u -= t*v), v); }
    return mint(u); }
mint operator^(mint a, long long n) { mint r = 1;
    while (n) { if (n & 1) r *= a; a *= a; n >>= 1; } return r; }
bool operator<(const mint &a, const mint &b) { return a.n < b.n; }
//-----------------------

using edge = pair<int, long long>;
using Graph = vector<vector<edge>>;

vector<long long> dijkstra(const Graph &g, int s, vector<mint> &pat) {
    vector<long long> dist(g.size(), INF);
    using Pi = pair<long long, int>;
    priority_queue<Pi, vector<Pi>, greater<Pi>> que;
    dist[s] = 0; pat[s] = 1; que.emplace(dist[s], s);
    while (!que.empty()) {
        long long cost; int u; tie(cost, u) = que.top(); que.pop();
        if (dist[u] < cost) continue;
        for (auto &e: g[u]) {
            int v; long long nc; tie(v, nc) = e;
            if (chmin(dist[v], dist[u] + nc)) {
                que.emplace(dist[v], v), pat[v] = pat[u];
            } else if (dist[v] == dist[u] + nc) {
                pat[v] += pat[u];
            }
        }
    }
    return dist;
}

int main() {
    int n, m; cin >> n >> m;
    int s, t; cin >> s >> t; s--, t--;
    Graph g(n);
    while (m--) {
        int u, v, d; cin >> u >> v >> d; u--, v--;
        g[u].emplace_back(v, d);
        g[v].emplace_back(u, d);
    }
    vector<mint> patS(n);
    auto distS = dijkstra(g, s, patS);
    vector<mint> patT(n);
    auto distT = dijkstra(g, t, patT);
    mint all = patS[t] * patT[s];
    mint bad = 0;
    long long d = distS[t];
    for (int u = 0; u < n; u++) {
        if (distS[u] + distT[u] == d && distS[u] == distT[u]) {
            bad += (patS[u] * patT[u]) * (patT[u] * patS[u]);
        }
    }
    for (int u = 0; u < n; u++) for (auto &e: g[u]) {
        int v; long long c; tie(v, c) = e;
        if (distS[u] + c + distT[v] != d) continue;
        if (distS[u] * 2 < d && distT[v] * 2 < d) {
            bad += (patS[u] * patT[v]) * (patT[v] * patS[u]);
        }
    }
    cout << all - bad << endl;
    return 0;
}


Measured memory_bytes: 18772
import java.util.*;
import java.util.stream.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        long w = sc.nextLong();
        if (h == 1 || w == 1) {
            System.out.println(1);
            return;
        }
        if (h*w%2==0) {
            System.out.println(h*w/2);
        } else {
            System.out.println(h*w/2+1);
        }
    }

}


Measured memory_bytes: 22612
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
x = 0
y = s
ans = sum(list(map(abs, a)))
if n == 2:
    ans = abs(a[0]-a[1])
else:
    for i in range(n):
        x += a[i]
        y -= a[i]
        if i == 0 or i == n-1:
            continue
        ans = min(ans, abs(x-y))
print(ans)

Measured memory_bytes: 23800
input_text = input()
count_a = 0
count_b = 0
count_c = 0
for i in range(3):
    if input_text[i] == "a":
        count_a += 1
    elif input_text[i] == "b":
        count_b += 1
    else:
        count_c += 1

if count_a == 1 and count_b == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;

const int MAX_N = 2 * 1e5 + 2;
const ll INF = 1LL << 40;

ll A[MAX_N];

int main() {
    int N;
    cin >> N;
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
        A[i] += A[i - 1];
    }
    ll ans = INF;
    for (int i = 2; i <= N - 2; i++) {
        ll sub_ans = 0;
        int idx1 = lower_bound(A + 1, A + i, A[i] / 2) - A;
        if (idx1 == i) idx1--;
        int idx2 = lower_bound(A + i + 1, A + N + 1, A[i] + ((A[N] - A[i]) / 2)) - A;
        if (idx2 == N) idx2--;
        for (int j = -1; j <= 1; j++) {
            for (int k = -1; k <= 1; k++) {
                if (idx1 + j == 0 || idx1 + j == N + 1 || idx2 + k == 0 || idx2 + k == N + 1) continue;
                ll P = A[idx1 + j], Q = A[i] - A[idx1 + j], R = A[idx2 + k] - A[i], S = A[N] - A[idx2 + k];
                ans = min(ans, abs(max(P, max(Q, max(R, S)))) - min(P, min(Q, min(R, S))));
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
fn getline() -> String{
    let mut __ret = String::new();
    std::io::stdin().read_line(&mut __ret).ok();
    return __ret;
}


fn printvec<T: std::fmt::Display>(x: &Vec<T>){
    for v in x {
        print!("{} ",v);
    }
    println!("");
}

fn main() {
    let s = getline();
    let inp:Vec<_> = s.trim().split(' ').collect();
    let n: usize = inp[0].parse().unwrap();
    let a: i64 = inp[1].parse().unwrap();
    let b: i64 = inp[2].parse().unwrap();
    let mut h = vec![0;n];
    for i in 0..n {
        let s = getline();
        let inp: Vec<_> = s.trim().split(' ').collect();
        h[i] = inp[0].parse().unwrap();
    }
    let mut l: i64 = 0;
    let mut r: i64 = 10000000000;
    while l+1 < r {
        let m = (l+r)/2;
        let mut cnt = 0;
        for e in &h {
            let tmp = e-m*b;
            if tmp > 0 {
                cnt += (tmp+(a-b-1))/(a-b);
            }
        }
        // println!("{},{},{}",l,r,cnt);
        if cnt <= m {
            r = m;
        }else{
            l = m;
        }
    }
    println!("{}",r);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define all(a) a.begin(),a.end()

bool eval(vector<int> &table,string &s,int &i){
    if(isdigit(s[i])) return s[i++] == '1';
    if(s[i] == '-') return !eval(table,s,++i);
    if(isalpha(s[i])) return table[s[i++]-'a'];
    i++; // (
    bool e1 = eval(table,s,i);
    char op = s[i++];
    bool e2 = eval(table,s,i);
    i++; // )
    if(op == '^') return e1^e2;
    if(op == '*') return e1*e2;
    assert(false);
}

int feature(string &E){
    int k = 0;
    int f = 0;
    rep(a,2)rep(b,2)rep(c,2)rep(d,2){
        vector<int> table = {a,b,c,d};
        int i = 0;
        if(eval(table,E,i)){
            f |= 1<<k;
        }
        k++;
    }
    return f;
}

int main(void){
    vector<string> exps[17];
    exps[1] = {"a","b","c","d"};
    for(int m = 2; m <= 16; m++){
        for(string E : exps[m-1]){
            if(E[0] == '-') continue;
            exps[m].push_back("-"+E);
        }
        rep1(x,m-2){
            int y = m-3-x;
            if(x>y) continue;
            for(string E1 : exps[x]){
                for(string E2 : exps[y]){
                    bool ng = false;
                    for(char ch : {'a','b','c','d'}){
                        if(count(all(E1),ch)+count(all(E2),ch)>1){
                            ng = false;
                        }
                    }
                    if(ng) continue;
                    exps[m].push_back("("+E1+"^"+E2+")");
                    exps[m].push_back("("+E1+"*"+E2+")");
                }
            }
        }
    }
    exps[1].push_back("0");
    exps[1].push_back("1");


    vector<int> min_len(1<<16, 20);
    rep1(m,16){
        for(string E : exps[m]){
            int f = feature(E);
            min_len[f] = min(min_len[f], m);
        }
    }

    string E;
    while(cin>>E, E != "."){
        cout<<min_len[feature(E)]<<endl;
    }
    return 0;
}



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

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i, k , n) for(int i = k; i <= n; i++)
typedef long long ll;

const char nl = '\n' ;
const ll MOD = 1e9 + 7;


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

   int n, h; cin >> n ;
   map< string , int> m;
   int ans =0;
   rep(i,n)
   {
      string s; cin >> s;
      m[s]++;
   }
   cin >> h;
   rep(i, h)
   {
      string s; cin >> s;
      m[s]--;
   }
   for(auto it = m.begin(); it!=m.end(); it++)
   {
      ans = max(ans, it->second);
   }

   cout << ans << nl;
   return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;cin >> s;
  int n = s.size(),i,j,k;;cin >> k;vector<string> v;
  for(i=1;i<=min(n,k);i++){
    for(j=0;j+i<=n;j++) v.push_back(s.substr(j,i));
  }
  sort(v.begin(),v.end());
  v.erase(unique(v.begin(),v.end()),v.end());
  cout << v[k-1] << "\n";
}

Measured memory_bytes: 1660
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<set>
#include<map>

using namespace std;

#define x first
#define y second
#define NMAX 300005
#define INF 1000000007

int n,m, AIB[NMAX], ans[NMAX], mars[NMAX];
vector<int> mylist[NMAX];
pair<int,int> v[NMAX];

void update(int poz,int val)
{
    for(;poz<=m;poz+=(poz^((poz-1)&poz)))
        AIB[poz]+=val;
}
 
int query(int poz)
{
    int s=0;
    for(;poz;poz-=(poz^((poz-1)&poz)))
        s+=AIB[poz];
    return s;
}

inline void deleteIntervals(int salt){
    int lim = mylist[salt].size();
   // printf("lim is %d\n", lim);
    for(int i = 0; i < lim; i++){
        int index = mylist[salt][i];
        update(v[index].x, -1);
        update(v[index].y + 1, +1);
    }
}

inline void checkAnswer(int index){
    for(int i = index; i <= m; i += index){
     //   printf("%d %d\n", query(i), query(i - 1));
        ans[index] += query(i);
    }
}

int main (){
    
    scanf("%d%d",&n,&m);
    for(int i = 1; i <= n; i++){
        scanf("%d%d",&v[i].x,&v[i].y);
        mars[v[i].y - v[i].x + 1]++;
        update(v[i].x, +1);
        update(v[i].y + 1, -1);
        mylist[v[i].y - v[i].x + 1].push_back(i);
    }
    for(int i = m; i >= 1; i--)
        mars[i] += mars[i + 1];
    for(int i = m; i >= 1; i--){
        ans[i] = mars[i];
        deleteIntervals(i);
        checkAnswer(i);
    }
    
    for(int i = 1; i <= m; i++)
        printf("%d\n", ans[i]);
    
    return 0;
}

Measured memory_bytes: 14592
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <tuple>
#include <utility>
#include <set>
#include <numeric>
#include <queue>
using namespace std;
using LLI = long long int;

#define Rep(i, N) for (int i = 0; i < N; i++)

int main(int argc, char *argv[])
{
    int X;
    cin >> X;

    switch (X)
    {
    case 7:
    case 5:
    case 3:
        cout << "YES" << endl;
        break;
        
    default:
        cout << "NO" << endl;
        break;
    }

    return 0;
}

Measured memory_bytes: 256
#include<cmath>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<algorithm>
#include<list>
#include<cstring>
#include <numeric>
#include <iomanip>

#define ll long long
#define int long long
#define ld long double
#define endl "\n"
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(p) cerr<<#p<<'='<<(p.first)<<" "<<p.second<<endl;
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define output(x)   cout << (x ? "YES" : "NO")<<endl;
const ll MOD = 1e9 + 7;
const int N = 1e5+5;
const int demo = 10;
using namespace std;
const ll cfmod=998244353;
ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
char button[4]={'L','R','U','D'};

// Ahhiya thi lakhvanu chalu thasse....

signed main() {
    FAST
    int q = 1;
    //cin>>q;
    while (q--) {
        int n;
        cin>>n;
        for(int i=1;i<361;i++){
            int num=n*i;
            if(num%360==0){
                cout<<i;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3208
import qualified Data.ByteString.Char8 as BSC8
import qualified Data.Maybe            as Maybe

readIntegers :: IO [Integer]
readIntegers = map ( fst . Maybe.fromJust . BSC8.readInteger ) . BSC8.words <$> BSC8.getLine

main :: IO ()
main = do
  (a:b:c:_) <- readIntegers
  if c < a || c < b then putStrLn "No" 
                    else if (c - a - b) ^ 2 > 4 * a * b
                                 then putStrLn "Yes"
                                 else putStrLn "No"


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

int main() {
  int N;
  cin >> N;
  vector<vector<vector<int>>> F(N, vector<vector<int>>(5, vector<int>(2)));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 5; j++) {
      for (int k = 0; k < 2; k++) cin >> F[i][j][k];
    }
  }
  vector<vector<int>> P(N, vector<int>(11));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 11; j++) cin >> P[i][j];
  }
  int ans = -1000000000;
  for (ll bit = 0; bit < (1<<10); bit++) {
    if (bit == 0) continue;
    vector<int> common(N, 0);
    int tmp = 0;
    for (int i = 0; i < 11; i++) {
      if (bit & (1<<i)) {
        for (int j = 0; j < N; j++) {
          if (F[j][i%5][i/5]) common[j]++;
        }
      }
    }
    for (int k = 0; k < N; k++) tmp += P[k][common[k]];
    if (tmp > ans) ans = tmp;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3620
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

static double max(double a, double b) { return a < b ? b : a; }

int main(int argc, char **argv) {
  int n, k;
  scanf("%d %d", &n, &k);
  double q[n + 1];
  q[0] = 0;
  for (int i = 0; i < n; i++) {
    double p;
    scanf("%lf", &p);
    q[i + 1] = q[i] + p * (p + 1) / (p + p);
  }
  double r = 0;
  for (int i = 0; i <= n - k; i++) {
    r = max(r, q[i + k] - q[i]);
  }
  printf("%.7lf\n", r);
  return EXIT_SUCCESS;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+5;
vector<int>v[N];
int cal[N];
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	cin>>cal[i];
	while(m--)
	{
		int x,y;
		cin>>x>>y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	int cnt=0;
	for(int i=1;i<=n;i++)
	{
		int f=0;
		for(int j=0;j<v[i].size();j++)
		if(cal[i]<=cal[v[i][j]])f=1;
		if(!f)cnt++;
	}
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 9132
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll t[100];
ll a[209];
int n;
string S;
void add(ll x){
    for(int i=59; i>=0; --i){
        if(x&(1ll<<i))x^=t[i];
        if(x&(1ll<<i)){
            t[i]=x;
            break;
        }
    }
}

bool check(ll x){
    for(int i=59; i>=0 && x; --i)
    if(x&(1ll<<i))x^=t[i];
    return x;
}

void xuli(){
    for(int i=0; i<60; ++i)t[i]=0;
    cin >> n;
    for(int i=1; i<=n; ++i) cin >> a[i];
    cin >> S;
    S=" "+S;
    for(int i=n; i>=1; --i){
        if(S[i]=='0')add(a[i]);
        else
        if(check(a[i])){
            cout << 1<<endl;
            return;
        }
    }
    cout << 0 <<endl;
}

int main()
{
    #ifdef abcxyz
    freopen("a.inp","r", stdin);
    #endif // abcxyz
    int t;
    cin >> t;
    while(t--)xuli();
    return 0;
}


Measured memory_bytes: 3584
fun main(arr:Array<String>) {
    val (n,m) = readLine()!!.split(" ").map { it.toInt() }
    val cityCount = (1..n).map { 0 }.toMutableList()
    val ans = StringBuilder()
    val city = (0 until m).map {idx -> readLine()!!.split(" ").let { City(idx, it[0].toInt(), it[1].toLong()) } }
    city.sortedBy { it.year }.forEach {
        cityCount[it.ken - 1]++
       it.num = it.ken.toString().padStart(6, '0') +  cityCount[it.ken - 1].toString().padStart(6, '0')
    }
    city.forEach { ans.appendln(it.num) }
    print(ans.toString())
}
class City(val id:Int, val ken:Int, val year:Long) {
    var num:String = ""
}

Measured memory_bytes: 87528
import Control.Applicative ((<$>), (<*>))

main :: IO ()
main = solve <$> f <*> f <*> f >>= putStrLn
  where f = map read <$> words <$> getLine

solve :: [Int] ->  [Int] -> [Int] -> String
solve [h1, h2] [s1, s2] [a, b, c, d] = case compare (f h1 h2) (f s1 s2) of
                                        GT -> "hiroshi"
                                        EQ -> "even"
                                        LT -> "kenjiro"
  where f i y = i * a + y * b + (i `div` 10) * c + (y `div` 20) * d



Measured memory_bytes: 3708
//1444
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cassert>
#include<sstream>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<cstring>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;


struct edge{
	int fr;
	int to;
	double d;
	int j;
	edge(int f,int t,double d0,int j0){
		fr=f;
		to=t;
		d=d0;
		j=j0;
	}
};
struct cmp{
	bool operator()(edge a,edge b){
		return a.d>b.d;
	}
};


int main(){
	int n,m,p,a,b;
	while(cin >> n >> m >> p >> a >> b){
		a--;
		b--;
		if(n==0) break;
		vector<vector<edge> > g(m);
		vint baken(n);
		for(int i=0;i<n;i++) cin >> baken[i];
		for(int i=0;i<p;i++){
			edge e(0,0,0,0);
			cin >> e.fr >> e.to >> e.d;
			e.fr--;
			e.to--;
			g[e.fr].push_back(e);
			g[e.to].push_back(edge(e.to,e.fr,e.d,0));
		}
		
		int prev[31][1<<9];
		priority_queue<edge,vector<edge>,cmp> pq;
		memset(prev,-1,sizeof(prev));
		
		edge e(-2,a,0,0);
		pq.push(e);
		
		int imp=1;
		while(!pq.empty()){
			e=pq.top();
//			cout << e.fr << " " << e.to << " " << e.d << endl;
			pq.pop();
			if(prev[e.to][e.j]!=-1) continue;
			prev[e.to][e.j]=e.d;
			if(e.to==b){
				imp=0;
				break;
			}
			for(int i=0;i<g[e.to].size();i++){
				for(int j=1,k=0;j<(1<<n);j*=2,k++){
					if((e.j&j)==0){
						pq.push(edge(e.to,g[e.to][i].to,e.d+((double)g[e.to][i].d/baken[k]),(e.j|j)));
					}
				}
			}
		}
		if(imp==0){
			printf("%.5f\n",e.d);
		}else{
			printf("Impossible\n");
		}
	}
	
	return 0;
}
	

Measured memory_bytes: 10000
#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x,y) make_pair(x,y)


int main(){

    ll N,M,K;
    cin>>N>>M>>K;
    vector<ll> A(N);
    vector<ll> B(M);

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

    for(ll i=0;i<M;i++){
        cin>>B[i];
    }


    vector<ll> arui(N+1);
    vector<ll> brui(M+1);
        for(ll i=0;i<N;i++){
       arui[i+1]=arui[i]+A[i];
    }

    for(ll i=0;i<M;i++){
        brui[i+1]=brui[i]+B[i];
    }

    ll ans=0;
    ll now=M;
    ll f=1;
    for(ll i=0;i<=N;i++){
        for(ll j=now;j>=0;j--){
            if(K>=arui[i]+brui[j]){
                now=j;
                ans=max(ans,i+j);
                break;
            }
        }
    }
    
    cout<<ans<<endl;

}

Measured memory_bytes: 9540
import sys
N ,D= map(int,input().split())

A = [[0 for x in range(D)]for y in range(N)]
for i in range(N):
  A[i] = [int(x) for x in sys.stdin.readline().split()]

B=[]
x=-126
while x**2 <= 16000:
  B.append(x**2)
  x+=1
count = 0
for i in range(N-1):
  for j in range(i+1,N):
    y = 0
    for k in range(D):
      y += (A[j][k]-A[i][k])**2

    if y in B:
      count+=1
print(count)

Measured memory_bytes: 3064
import math

a, b = list(map(int, input().split()))
result = -1
end_flag = False
for i in range(1, 1251):
    if not end_flag:
        x = math.floor(i * 0.08)
        if int(x) == a:
            for j in range(1, 1001):
                y = math.floor(j * 0.1)
                if i == j:
                    if int(y) == b:
                        result = i
                        end_flag = True
                        break
print(result)


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

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

struct BinaryIndexedTree {
private:
    int n;
    vector<int> bit;
public:
    BinaryIndexedTree(int n_) {
        n = n_+10;
        bit = vector<int>(n,0);
    }

    void add(int a,int w) {
        for (int x = a;x <= n;x += x&-x) bit[x] += w;
    }

    int sum(int a) {
        int ret = 0;
        for (int x = a;x > 0;x -= x&-x) ret += bit[x];
        return ret;
    }

    void update(int a,int w) {
        int v = w-sum(a)+sum(a-1);
        add(a,v);
    }
};

int main() {
    string s;
    cin >> s;
    int n = s.size(),a[26],b[26],p = 0;
    vector<int> x(n),y[26];
    BinaryIndexedTree bit(n);
    for (int i = 0;i < 26;++i) a[i] = b[i] = 0;
    for (int i = 0;i < n;++i) a[s[i]-'a']++;

    int ok = 0;
    for (int i = 0;i < 26;++i) if (a[i]&1) ok++;
    if (ok > (n&1)) {
        cout << "-1" << endl;
        return 0;
    }

    for (int i = 0;i < n;++i) {
        int c = s[i]-'a';
        b[c]++;
        if ((a[c]&1) && b[c]*2 == a[c]+1) x[i] = n/2;
        else if (b[c]*2 > a[c]) {
            x[i] = n-1-y[c].back();
            y[c].pop_back();
        } else {
            x[i] = p;
            y[c].push_back(p);
            p++;
        }
    }
    ll ans = 0;
    for (int i = 0;i < n;++i) {
        ans += i-bit.sum(x[i]+1);
        bit.add(x[i]+1,1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2816
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
int main() {
	int w, d;
	while (cin >> w >> d, w) {
	    int cnt = 0;
		int cnt1[21] = {}; int cnt2[21] = {};
		int x;
		rep(i, w) {
			cin >> x; cnt1[x]++;
		}
		rep(i, d) {
			cin >> x; cnt2[x]++;
		}
		rep1(i, 20) {
			cnt += i * max(cnt1[i], cnt2[i]);
		}
		cout << cnt << endl;
	}
	return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                           \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
  cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  char C;
  cin >> C;
  C += 1;
  cout << C << endl;
  return 0;
}


Measured memory_bytes: 3656
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner s = new Scanner(System.in);
		
		String ss = s.nextLine();
		String st = s.nextLine();
		
		int count=0;
		
		char[] sstri= ss.toCharArray();
		char[] tstri= st.toCharArray();
		
		for(int i=0;i<sstri.length;i++){
			if(sstri[i] != tstri[i]){
				count++;
			}
		}
		System.out.print(count);
	}
}

Measured memory_bytes: 42936
s = input()

res = int(s)
for i in range(1,len(s)):
    l = len(s)-i
    for j in range(len(s)-l+1):
        x = i-1
        if j>0 and j<len(s)-l:
            x -=1
        res+=int(s[j:j+l])*(2**x)

print(res)


Measured memory_bytes: 3060
<?php
fscanf(STDIN, "%d", $n);
while ($n--) {
	fscanf(STDIN, "%s", $s);
	$a = str_split($s);
	sort($a);
	@$q[implode($a)]++;
}
$x = 0;
foreach ($q as $k => $v) {
	if ($v > 1) {
		$x += $v * ($v - 1) / 2;
	}
}
echo $x;

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


int main() {
	/*freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);*/

	int n, m;
	cin >> n >> m;
	vector<vector<int>> adj(n+1);

	for (int i=0; i<m; i++) {
		int u, v;
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	vector<int> ans(n+1);
	vector<bool> vis(n+1, false);
	queue<int> q; q.push(1);
	int rooms = n-1;
	vis[1] = true;
	while (!q.empty()) {
		int sz = q.size();

		while (sz--) {
			int t = q.front();
			q.pop();
			for (int x: adj[t]) {
				if (!vis[x]) {
					vis[x] = true;
					--rooms;
					ans[x] = t;
					q.push(x);
				}
			}
		}
	}

	if (rooms) {
		puts("No");
		return 0;
	}

	puts("Yes");
	for (int i=2; i<=n; i++) cout << ans[i] << '\n'; puts("");

	return 0;
}

Measured memory_bytes: 10008
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
  
int main(void){
    string s;
    cin >> s;
    
    if (s == "Sunny") {
        cout << "Cloudy"; 
    } else if (s == "Cloudy") {
        cout << "Rainy";
    } else if (s == "Rainy") {
        cout << "Sunny";
    }

    return 0;
}

Measured memory_bytes: 256
a = raw_input()
l = a.split()
A = l[0]
B = l[1]
ans = 0


if int(A) == int(B):
  ans = 1

for i in range(int(A),int(B)+1):
  C = list(str(i))
  if C[0] == C[4] and C[1] == C[3]:
    ans += 1
    
print(ans)

Measured memory_bytes: 5508
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    string s,hako;
    cin >> s;
    int ans= 1000,tmp;

    for(int i = 0;i < s.size()-2;i++){
        hako = s.substr(i,3);
        tmp = stoi(hako);
        if(ans > abs(753 - tmp))
            ans = abs(753 - tmp);
    }

    cout << ans << endl;

}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

int main() {
    string s;
    cin >> s;
    if(s[2]==s[3]&&s[4]==s[5]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

// a[i]をp位以内にできるか
bool check(lint cand, lint m, lint v, lint p, vector<lint> &a) {
    lint n = a.size();
    lint modi = a[cand] + m;
    if (modi < a[n - p]) {
        return false;
    }
    lint l = cand + 1, r = n - p + 1;
    lint limit = 0;
    for (int i = l; i < r; i++) {
        limit += min(m, modi - a[i]);
    }
    return limit >= (v - l - n + r) * m;
}

int main() {
    lint n, m, v, p;
    cin >> n >> m >> v >> p;
    vector<lint> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    lint ok = n - 1, no = -1;
    while (abs(ok - no) > 1) {
        lint mid = (ok + no) / 2;
        if (check(mid, m, v, p, a)) {
            ok = mid;
        } else {
            no = mid;
        }
    }
    cout << n - ok << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define FORq(i, m, n) for(int i = m;i <= n;i++)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define PRINTD(n) printf("%d\n",n)
#define DEBUG printf("%s\n","debug")
using namespace std;
//////////////////////////////////////////////////////
int main(){
	int N,M,X;
	SCD(N);SCD(M);SCD(X);
	int a[M];
	
	REP(i,M){
		SCD(a[i]);
	}
	int c = 0;

	REP(i,M){
		if (a[i] < X) c++;
	}
	
	
	int ans = min(c,M-c);
	
	PRINTD(ans);
	
	return 0;
}







Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	string s;
	cin >> s;
	reverse(s.begin(), s.end());
	int N = s.length();
	ll res = 0;
	for (int i = 0; i < 224; ++ i) {
		int x = 1;
		int y = 0;
		vector<int> a(2019);
		for (int j = i; j < N; ++ j) {
			if (x == 1) ++ a[y];
			y = (y + x * (s[j]-'0')) % 2019;
			res += a[y];
			x = x * 10 % 2019;
		}
	}
	cout << res << endl;
}


Measured memory_bytes: 3756
def solve():
    n = int(input())
    data = input()
    # n, data = [x for x in input().split(" ")]
    n = int(n)
    if data[:n//2] == data[n//2:]:
        return "Yes"
    return "No"

if __name__ == "__main__":
    # test = int(input())
    # for _ in test:
    print(solve())

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

int main() {
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif

    int n;
    cin>>n;
    for(int i = 1;i <= 9;i++) {
        if(n%i == 0) {
            int first = i, second = n/i;
            if(first <= 9 && second <= 9) {
                cout<<"Yes\n";
                return 0;
            }
        }
    }
    cout<<"No\n";
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n)
	ts := make([]int, n)
	for i := range ts {
		fmt.Scan(&ts[i])
	}
	fmt.Scan(&m)
	ps := make([]int, m)
	xs := make([]int, m)
	for i := range ps {
		fmt.Scan(&ps[i])
		fmt.Scan(&xs[i])
	}

	for i, t := range ps {
		sum := 0
		for j := range ts {
			if j == t-1 {
				sum += xs[i]
			} else {
				sum += ts[j]
			}
		}
		fmt.Println(sum)
	}
}


Measured memory_bytes: 512
/****************************
/////  Shubham Singhal
/////  LNMIIT
*****************************/
#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define lwr lower_bound
#define upr upper_bound
#define pq priority_queue
#define umap unordered_map
#define rep(i,n) for(i=0; i<n;i++)
#define repp(i,a,n) for(i=a; i<n;i++)
#define precise(x) cout<<fixed<<setprecision(x)
#define all(x) x.begin(),x.end()
#define lcm(a,b) (a*b)/__gcd(a,b)
#define prn(x) cout<<x<<"\n"
#define prn2(x, y) cout<<x<<" "<<y<<"\n"
#define prn3(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define prn4(x, y, z, a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<"\n"
#define prnv(x) for(auto i:x) cout<<i<<" "; cout<<"\n"
#define MOD 1000000007
#define MAX 300005
using namespace std;
 
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd; 
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;
const long long INF64 = 1e18;
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
void doc()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
}
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
}
int main()
{
	fast();
	ll n,a,b;
	cin>>n>>a>>b;
	ll t=a+b;
	ll q=n/t;
	ll ans=q*a;
	ll r=n%t;
	ans+=min(r,a);
	cout<<ans;
}

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

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl
#define debug2(s, t, u) cout << s << " " << t << " " << u << endl
#define printvec(v)       \
    for (auto &&i : v)    \
        cout << i << " "; \
    cout << endl
#define rep(n, i) for (int i = 0; i < n; i++)

using namespace std;
using i64 = long long;

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

    int ct = 0;
    int nsqrt = sqrt(n) + 0.5;
    for (int i = 1; i <= nsqrt; i++)
    {
        for (int j = i; i*j<n; j++)
        {
            if (i==j) ct--;
            ct +=2;
        }
    }
    

    cout << ct << endl;

    return 0;
}

Measured memory_bytes: 3676
#include<cstdio>
using namespace std;
 
int main(){
  int n;
  long long d, a = 0, b = 0, cnta = 0, cntb = 0, i, ans;
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%lld", &d);
    a += d; b += d;
    if(i%2){
      if(a > -1){cnta += a + 1; a = -1;}
      if(b <  1){cntb += 1 - b; b = 1;}
    }else{
      if(b > -1){cntb += b + 1; b = -1;}
      if(a <  1){cnta += 1 - a; a = 1;}
    }
  }
  printf("%lld\n", (cnta < cntb) ? cnta : cntb);
}

Measured memory_bytes: 128
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         fozubaoyou    pass System Test!
*/
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define int long long
#define pb push_back
using ll = long long;
using namespace std;

signed main(){

  int A,B;
  cin >> A >> B;

  if(B%A == 0){
    cout << A+B << endl;
  }else{
    cout << B-A << endl;
  }

}


Measured memory_bytes: 256
N = int(input())

btc = []
yen = []

for i in range(N):
  x,y = map(str,input().split())
  if y == "JPY":
    yen.append(float(x))
  else:
    btc.append(float(x))

print(sum(btc)*380000.0 + sum(yen))

Measured memory_bytes: 3060
#include <cassert>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
#include "limits.h"
 
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if(b==0)return 1;
  if ((a == 0)||(mod!=-1&&(a+mod)%mod==0)) {
    return 0;
  }
  long long x = 1;
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}

// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P=std::pair<long long,long long>;

ll f(ll num){
  if(num==1)return 1;
  return 1+2*f(num/2);
}

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

  ll h;
  std::cin>>h;

  std::cout<<f(h)<<"\n";

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

ll debugFlag = false;
template<typename T> void debug(T&);
template<typename T> void debug(T&, bool);
template<typename T> void debug(vector<T>&);
template<typename T> void debug(vector<T>&, bool);
template<typename T, typename U> void debug(pair<T, U>&);
template<typename T, typename U> void debug(pair<T, U>&, bool);

template<typename T>
void debug(T& obj) {
	debug(obj, true);
}

template<typename T>
void debug(T& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << obj;
	if (lnFlag) cout << endl;
}

template<typename T>
void debug(vector<T>& obj) {
	debug(obj, true);
}

template<typename T>
void debug(vector<T>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "[";
	rep(i, obj.size()) {
		if (i != 0) cout << ",";
		debug(obj[i], false);
	}
	cout << "]";
	if (lnFlag) cout << endl;
}

template<typename T, typename U>
void debug(pair<T, U>& obj) {
	debug(obj, true);
}

template<typename T, typename U>
void debug(pair<T, U>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "(";
	debug(obj.first, false);
	cout << ",";
	debug(obj.second, false);
	cout << ")";
	if (lnFlag) cout << endl;
}

void solve() {
	ll N, M;
	cin >> N >> M;

	vector<pair<ll, ll>> vec(N);

	rep(i, N) cin >> vec[i].second >> vec[i].first;

	sort(vec.begin(), vec.end(), [](const pair<ll, ll>& x, const pair<ll, ll>& y) {
		return x.second < y.second;
	});

	ll ans = 0;

	multiset<pair<ll, ll>, std::greater<pair<ll, ll>>> ST;
	ll pos = 0;

	for (ll i = 1; i <= M; i++) {

		while (1) {
			if (pos == N) break;
			if (vec[pos].second == i) {
				ST.insert(vec[pos]);
				pos++;
			}
			else {
				break;
			}
		}

		//auto M = ST.begin();
		if (ST.size() != 0) {
			ans += (*(ST.begin())).first;
			ST.erase(ST.begin());
		}

	}

	cout << ans;

}

int main(int argc, char* argv[]) {
	if (argc == 2 && string(argv[1]) == "debug") debugFlag = true;
	solve();
	cout << endl;
	return 0;
}


Measured memory_bytes: 8064
import sys
h, w = list(map(int, sys.stdin.readline().split()))
graph = [list(sys.stdin.readline().rstrip()) for _ in range(h)]

dp = [[10**5 for _ in range(w)] for _ in range(h)]
dp[0][0] = 0 if graph[0][0] == '.' else 1

for i in range(1,h):
    if graph[i][0] == '.' or graph[i-1][0] == '#':
        dp[i][0] = dp[i-1][0]
    else:
        dp[i][0] = dp[i-1][0]+1

for j in range(1,w):
    if graph[0][j] == '.' or graph[0][j-1] == '#':
        dp[0][j] = dp[0][j-1]
    else:
        dp[0][j] = dp[0][j-1]+1

for j in range(1, h):
    for i in range(1, w):
        if (graph[j][i] == '.') or (graph[j][i] == graph[j-1][i] == graph[j][i-1]):
            dp[j][i] = min(dp[j-1][i], dp[j][i-1])
        elif graph[j-1][i] == '#' and graph[j][i-1] == '.':
            dp[j][i] = min(dp[j-1][i], dp[j][i-1]+1)
        elif graph[j][i-1] == '#' and graph[j-1][i] == '.':
            dp[j][i] = min(dp[j-1][i]+1, dp[j][i-1])
        else:
            dp[j][i] = min(dp[j-1][i], dp[j][i-1])+1

print(dp[-1][-1])


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

#define ll long long int
#define inv(name,Type,size) vector<Type> name(size);for(int index=0;index<n;index++) cin>>name[index];
#define F(a,n,i) for(int i=a;i<n;i++)
#define pb push_back
#define endl "\n"
#define mod 1000000007
#define modpro 99824435

const int d4i[4]={-1,0,1,0},d4j[4]={0,1,0,-1};
const int d8i[8]={-1,-1,0,1,1,1,0,-1},d8j[8]={0,1,1,1,0,-1,-1,-1};


void solve(){
	int h,w;
	cin>>h>>w;
	char grid[h][w];
	F(0,h,i) F(0,w,j) cin>>grid[i][j];
	vector<vector<int>> dp(h,vector<int>(w));
	if(grid[1][0] != '#') dp[1][0] = 1;
	if(grid[0][1] != '#') dp[0][1] = 1;
	F(0,h,i){
		F(0,w,j){
			if(grid[i][j]=='#') continue;
			if(i-1<0){
				dp[i][j] += (dp[i][j-1]) % mod;
			}
			else if(j-1<0){
				dp[i][j] += (dp[i-1][j]) % mod; 
			}
			else dp[i][j] += (dp[i-1][j]+dp[i][j-1]) % mod; 
			//cout<<dp[i][j]<<" ";
		}
		//cout<<endl;
	}
	cout<<dp[h-1][w-1];
}

int main()
{
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  
  //int t;cin>>t;while(t--) solve(),cout<<endl;
  solve();
}



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

std::vector<int>::iterator top;

int merge(	std::vector<int>::iterator left,
			std::vector<int>::iterator mid, 
			std::vector<int>::iterator right){
	
	std::vector<int> L(mid-left);
	std::vector<int> R(right-mid);

	for(int i=0; i<L.size(); i++) L[i] = *(left+i);
	for(int i=0; i<R.size(); i++) R[i] = *(mid+i);

	R.push_back(1000000000);
	L.push_back(1000000000);
	int ri=0,li=0;
	int cnt = 0;
	for(std::vector<int>::iterator k=left; k<right; k++){
		if(L[li]>R[ri]){
			*k = R[ri];
			ri += 1;
		}else{
			*k = L[li];
			li += 1;
		}
		cnt += 1;
	}
	return cnt;
}

int mergeSort(	std::vector<int>::iterator left, 
				std::vector<int>::iterator right ){
	int cnt = 0;

	if(right>left+1){	
		int num = right - left;
		std::vector<int>::iterator mid = left + num/2;
		cnt += mergeSort(left,mid);
		cnt += mergeSort(mid,right);
		cnt += merge(left,mid,right);
	}
	return cnt;

}

int main(int argc, char const *argv[]){
	int n,cnt;
	std::cin >> n;
	std::vector<int> S(n);
	for(int i=0; i<n; i++) std::cin >> S[i];
	top = S.begin();
	cnt = mergeSort(S.begin(),S.end());

	for(int i=0; i<n; i++) std::cout << S[i] << ((i<n-1)?" ":"\n");
	std::cout << cnt << std::endl;

	return 0;
}


Measured memory_bytes: 8688
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#include <random>
#define INF 1000000007
using namespace std;

int main(void){
	int n;
	cin >> n;
	vector<long long> a(n);
	for(int i=0; i<n; i++)cin >> a[i];
	long long ans=0;
	for(int i=0; i<n; i++){
		for(int j=i+1; j<n; j++){
			ans=max(ans,abs(a[i]-a[j]));
		}
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = (1 << 30);
constexpr ll L_INF = (1ll << 62);

//==================================

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

    string S, T;
    cin >> S >> T;

    cout << T + S << endl;

    return 0;
}

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

int main() {
    int N;
    string s,t;
    cin >> N >> s >> t;
    for(int i = 0; i <= N; ++i) {
        // sの[i,N)と、tの[0,N-i)が等しいか調べる
        bool flg = true;
        for(int j = 0; j < N-i; ++j) {
            if(s[i+j] != t[j]) {
                flg = false; break;
            }
        }
        if(flg) {
            cout << N + i << endl;
            return 0;
        }
    }
    cout << 2*N << endl;
    return 0;
}

Measured memory_bytes: 256
<?php  
  list($s) = explode(" ", trim(fgets(STDIN)));
  list($t) = explode(" ", trim(fgets(STDIN)));

  $s = str_split($s);
  $t = str_split($t);

  sort($s);
  rsort($t);
  for($i=0;$i<count($s)||$i<count($s);$i++){
    if($t[$i] > $s[$i]){
      echo "Yes";
      exit;
    }else if($t[$i] < $s[$i]){
      echo "No";
      exit;
    }
  }
  if(count($t) > count($s)){
    echo "Yes";
  }else{
    echo "No";
  }


Measured memory_bytes: 16240
import java.util.*;

public class Main {
	void solve() {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int y = scan.nextInt();
		System.out.println(x + y + 2 - gcd(x, y) - 1);
		scan.close();
	}
	
	int gcd(int x, int y) {
		if(x % y == 0) return y;
		return gcd(y, x % y);
	}
	
	public static void main(String[] args) {
		new Main().solve();
	}
}



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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;

signed main() {
    int N;
    cin >> N;
    int ans = 0;
    for (int m = 1; m <= (int) sqrt(N); ++m) {
        ans += m * (m + N / m) * (N / m + 1 - m);
    }
    int n2 = (int) sqrt(N);
    ans -= n2 * (n2 + 1) * (2 * n2 + 1) / 6;
    cout << ans << endl;
}


Measured memory_bytes: 3576