akhauriyash/Code-Regression huggingface dataset:
/**
 * File    : D.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-9-8 21:12:40
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(19920725));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int H, W;
bool a[510][510];

typedef tuple<int, int, int, int> X;
vector<X> V;
int odd[510];

void flush()
{
  int N = (int)V.size();
  cout << N << endl;
  for (auto i = 0; i < N; i++)
  {
    X x = V[i];
    cout << get<0>(x) + 1 << " " << get<1>(x) + 1 << " " << get<2>(x) + 1 << " " << get<3>(x) + 1 << endl;
  }
}

void make_swap(int x, int y, int z, int w)
{
  // swap(a[x][y], a[z][w]);
  V.push_back(X(x, y, z, w));
}

int main()
{
  cin >> H >> W;
  for (auto i = 0; i < H; i++)
  {
    for (auto j = 0; j < W; j++)
    {
      int x;
      cin >> x;
      a[i][j] = (x % 2 == 1);
    }
  }
  fill(odd, odd + 510, -1);
  for (auto i = 0; i < H; i++)
  {
    int y = -1;
    int cnt = 0;
    for (auto j = 0; j < W; j++)
    {
      if (a[i][j])
      {
        // cerr << "(" << i << ", " << j << ")" << endl;
        if (cnt % 2 == 0)
        {
          y = j;
        }
        else
        {
          int z = j;
          // cerr << "y = " << y << ", z = " << z << endl;
          for (auto k = y; k < z; k++)
          {
            make_swap(i, k, i, k + 1);
          }
        }
        cnt++;
      }
    }
    if (cnt % 2 == 1)
    {
      odd[i] = y;
      for (auto k = y; k < W - 1; k++)
      {
        make_swap(i, k, i, k + 1);
      }
    }
  }
  int x = -1;
  int cnt = 0;
  for (auto i = 0; i < H; i++)
  {
    if (odd[i] >= 0)
    {
      if (cnt % 2 == 0)
      {
        x = i;
      }
      else
      {
        int z = i;
        for (auto k = x; k < z; k++)
        {
          make_swap(k, W - 1, k + 1, W - 1);
        }
      }
      cnt++;
    }
  }
  flush();
}

Measured memory_bytes: 4464
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int M = sc.nextInt();
        int D = sc.nextInt();
        
        int res = 0;
        
        for (int i = 4; i <= M; i++) {
            for(int k = 22; k <= D; k++){
                String str = Integer.toString(k);
                String[] A = str.split("");
                if(Integer.parseInt(A[1]) >= 2 &&
                  i == Integer.parseInt(A[0]) * Integer.parseInt(A[1])){
                  res += 1;
                }
            }
        }
        
        System.out.println(res);
    }
}

Measured memory_bytes: 27092
//============================================================================
// Name        : Undead2.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <istream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <set>
//#include <unordered_map>
#include <cstring>
#include <string.h>
#include <iomanip>
#include <queue>
#include <stack>
#include <list>
#include <sstream>
#define pb push_back
#define mp make_pair
#define ll long long
#define INF 1000000000
#define EPS 1e-6
#define EPS2 1e-8
using namespace std;

int n,m;
int cnt;

int main()
{
	cin >> n >> m;
	string s;
	for (int i = 0; i<n; ++i)
	{
		cin >> s;
		for (int j = 0; j<m; ++j)
		{
			if (s[j] == '#')
				cnt++;
		}
	}
	if (cnt == n+m-1)
	{
		cout << "Possible";
	} else {
		cout << "Impossible";
	}
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc161/tasks/abc161_c

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;

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

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

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

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

  ll res = N % K;
  chmin(res, abs(res - K));

  cout << res << "\n";
}

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif


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

int main()
{
    int N, M, Q;
    cin >> N >> M >> Q;

    int x[N + 1][N + 1] = {};
    int L;
    int R;

    for (int i = 0; i < M; i++)
    {
        cin >> L >> R;
        x[L][R]++;
    }

    int cumulate_sum[N + 1][N + 1] = {};
    for (int i = 1; i <= N; i++)
    {
        for (int j = 1; j <= N; j++)
        {
            cumulate_sum[i][j] = cumulate_sum[i][j - 1] + x[i][j];
        }
    }

    int p;
    int q;
    for (int i = 0; i < Q; i++)
    {
        cin >> p >> q;
        int ans = 0;
        for (int j = p; j <= q; j++)
        {
            ans += cumulate_sum[j][q] - cumulate_sum[j][p - 1];
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 2944
import java.util.Scanner;
import java.util.InputMismatchException;

class Main {
   public static void main(String args[]) {
      int x=0 ,y=0;
      Scanner scanner = new Scanner(System.in);
      x = scanner.nextInt();
      scanner.close();
      System.out.println(3*x*x);
   }
}


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

void rotate_side(vector<int> &si, int n) {
  if (n < 0) {
    n = 4 - (abs(n) % 4);
  }

  for (int i = 0; i < n; i++) {
    int tmp = si[0]; 
    si[0] = si[2];
    si[2] = si[5];
    si[5] = si[4];
    si[4] = tmp;
  }
}
void rotate_front(vector<int> &si, int n) {
  if (n < 0) {
    n = 4 - (abs(n) % 4);
  }

  for (int i = 0; i < n; i++) {
      int tmp = si[0];
      si[0] = si[1];
      si[1] = si[5];
      si[5] = si[3];
      si[3] = tmp;
  }
}

void rotate_top(vector<int> &si, int n) {
  if (n < 0) {
    n = 4 - (abs(n) % 4);
  }
  for (int i = 0; i < n; i++) {
    int tmp = si.at(1);
    si[1] = si[2];
    si[2] = si[3];
    si[3] = si[4];
    si[4] = tmp;
  }
}
 
int main() {
  vector<int> si(6);
  cin >> si[0];
  cin >> si[2];
  cin >> si[3];
  cin >> si[1];
  cin >> si[4];
  cin >> si[5];
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int top, front;
    cin >> top >> front;

    // find top
    int d = distance(si.begin(), find(si.begin(), si.end(), top));
    // cout << "DEBUG: " << d << endl;
    switch (d) {
    case 0:
      // do nothing
      break;
    case 1:
      rotate_front(si, 1);
      break;
    case 2:
      rotate_side(si, 1);
      break;
    case 3:
      rotate_front(si, 3);
      break;
    case 4:
      rotate_side(si, -1);
      break;
    case 5:
      rotate_front(si, 2);
      break;
    }

    // find front
    d = distance(si.begin(), find(si.begin(), si.end(), front));
    // cout << "DEBUG: " << d << endl;
    // cout << "DEBUG: ";
    // for (int k = 0; k < 6; k++) cout << si.at(k) << " ";
    // cout << endl;
    switch (d) {
    case 1:
      rotate_top(si, 3);
      break;
    case 2:
      // do nothing
      break;
    case 3:
      rotate_top(si, 1);
      break;
    case 4:
      rotate_top(si, 2);
      break;
    default:
      cout << "ERR: " << i << endl;
      return 0;
    }
    // cout << "DEBUG: ";
    // for (int k = 0; k < 6; k++) cout << si.at(k) << " ";
    // cout << endl;
    cout << si.at(3) << endl;
  }
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

int main()
{
  int n,k,m;
  cin>>n>>k>>m;
  if (n == 1) {
    cout << 1 << endl;
    return 0;
  } else if (k == 1) {
    cout << 0 << endl;
    return 0;
  }
  vector<vector<ll>> dp(2*n+1, vector<ll>(1<<k, 0));
  vector<vector<ll>> dpzero(2*n+1, vector<ll>(k+1, 0));
  dpzero[2][1] = 1;
  ll bit = 2;
  FOR(i,1,k+1) {
    if (i >= n) break;
    dp[2+i][bit] = 1;
    bit |= 1;
    bit <<= 1;
  }
  FOR(i,2,2*n) {
    REP(j,(1<<k)-1) {
      if (j != 0) {
        ll nb = j << 1;
        int d = 0;
        REP(l,k+1) {
          if ((nb >> l) & 1) d = l;
        }
        ll nb2 = nb ^ (1 << d);
        if (nb2 == 0) {
          dpzero[i+1][d] += dp[i][j];
          dpzero[i+1][d] %= m;
        } else {
          dp[i+1][nb2] += dp[i][j];
          dp[i+1][nb2] %= m;
        }
        if (d == k) continue;
        nb |= 1;
        dp[i+1][nb] += dp[i][j];
        dp[i+1][nb] %= m;
      } else {
        FOR(l,1,k) {
          dp[i+1][1] += dpzero[i][l];
          dp[i+1][1] %= m;
        }
      }
    }
  }
  ll sum = 0;
  REP(i,k+1) {
    sum += dpzero[2*n][i];
    sum %= m;
  }
  cout<<sum<<endl;
  return 0;
}



Measured memory_bytes: 4532
import java.io.PrintWriter;
import java.util.*;

public class Main {
    static PrintWriter out = new PrintWriter(System.out);
    final long mod = 1000000000+7;
    long[] fac, inv;

    public static void main(String[] args) {
        Main main = new Main();
//        main.solve();
//        out.flush();
        System.out.println(main.solve());
    }
    // segment tree to record minimum value
    // Each point has a infinite distance from 0 (except itself)
    long solve() {
        Scanner sc = new Scanner(System.in);
        int r1 = sc.nextInt(), c1 = sc.nextInt(), r2 =sc.nextInt(), c2 = sc.nextInt();
        initial(r2+c2+5);
        long ans = helper(r2,c2);
        ans -= helper(r2, c1-1);
        ans -= helper(r1-1,c2);
        ans += helper(r1-1,c1-1);
        ans = (ans+10*mod)%mod;
        return ans;
    }
    long helper(int r, int c){
        if(r==0) return c+1;
        if(c==0) return r+1;
        if(r>c){
            int mid = r;
            r = c; c = mid;
        }
        // let r <= c
        long ans = 0;
        for(int row = r; row >=0; row--){
            long cur = fac[row+c+1]*inv[c]%mod*inv[row+1]%mod;
            ans = (ans+cur)%mod;
        }
        return ans;
    }
    long power(long base, long p){
        long ans = 1;
        while(p>0){
            if(p%2==1) ans = ans*base%mod;
            base = base*base%mod;
            p /= 2;
        }
        return ans;
    }
    void initial(int maxN){
        fac = new long[maxN+1];
        inv = new long[maxN+1];
        fac[0] = 1;
        for(int i=1;i<=maxN; i++) fac[i] = i*fac[i-1]%mod;
        inv[maxN] = power(fac[maxN], mod-2);
        inv[0] = 1;
        for(int i=maxN-1;i>0;i--){
            inv[i] = inv[i+1]*(i+1)%mod;
        }
    }
    // compute nCm

}



Measured memory_bytes: 53460
#include<iostream>
using namespace std;
int main()
{
	int n,m,k,d,pd[105]={0};
	cin>>n>>k;
	for (int i=1;i<=k;i++)
	{
		cin>>m;
		for(int j=1;j<=m;j++)
		{
			cin>>d;
			pd[d] = 1;
		}
	}
	int sum=0;
	for (int i=1;i<=n;i++)
	{
		if (pd[i]==0) sum++;
	}
	cout<<sum;
 }

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
 
int main() {
   int D,T,S;
   cin>>D>>T>>S;
   if(D<=S*T)cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
}

Measured memory_bytes: 3660
#include<cstdio>
#include<algorithm>
#define N (100005)
#define CM cerr<<(&MOP2-&MOP1)/1024.0/1024.0<<endl
using namespace std;
bool MOP1;
int n,m;
struct node{
	int cost,val;
	bool operator < (const node &a)const{
		return val>a.val;
	}
	void read(){
		scanf("%d%d",&cost,&val);
	}
}A[N];
int f[N];
int find(int x){
	return f[x]==x?x:f[x]=find(f[x]);
}
int ans;
bool MOP2;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)A[i].read();
	for(int i=1;i<=m+1;i++)f[i]=i;
	sort(A+1,A+1+n);
	for(int i=1;i<=n;i++){
		int c=A[i].cost;
		int v=A[i].val;
		if(c>m)continue;
		int now=find(f[c]);
		if(now>m)continue;
		ans+=v,f[now]++;
	}
	printf("%d\n",ans);
	return 0;
}






Measured memory_bytes: 1280
S = list(input())
N = len(S)
al = [chr(ord('a') + i) for i in range(26)]
if N!=26:
    D = dict(zip(al,[0]*26))
    cand = []
    for i in range(N):
        D[S[i]]+=1
    for key in D.keys():
        if D[key]==0:
            cand.append(key)
    cand.sort()
    S.append(cand[0])
    print("".join(S))
else:
    if S==list(reversed(al)):
        print(-1)
    else:
        cand = []
        for i in range(26):
            if S[25-i-1]>S[25-i]:
                cand.append(S[25-i])
                continue
            else:
                change_ind = 25-i
                cand.append(S[25-i])
                break
        cand.sort()
        T = S[0:change_ind]
        i = 0
        while True:
            if T[-1]<cand[i]:
                T[-1]=cand[i]
                break
            i+=1
        print("".join(T))

Measured memory_bytes: 62064
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner kb = new Scanner(System.in);
		int n = kb.nextInt();
		int k = kb.nextInt();
		ArrayList<Long> h = new ArrayList<>();
		long sum = 0;
		for (int i = 0; i < n; i++) {
			long j = kb.nextLong();
			h.add(j);
		}
		Collections.sort(h);
		int count = 0;
		for (long e : h) {
			count += 1;
		}
		// System.out.println(count);
		for (long i = 0; i < k; i++) {
			h.remove(count - 1);
			count -= 1;
			if (count == 0)
				break;
		}
		// System.out.println(h);
		for (long e : h) {
			sum += e;
			//System.out.println(sum);
		}
		System.out.println(sum);

		kb.close();
	}

}


Measured memory_bytes: 96876
#include <iostream>
using namespace std;
int main(void){
    int h,m,s,H,M,S,T;
    for(int i=0;i<3; i++){
        cin>>h>>m>>s>>H>>M>>S;
        T=(3600*H+60*M+S)-(3600*h+60*m+s);
        cout<<T/3600<<" ";
        cout<<T%3600/60<<" ";
        cout<<T%60<<endl;
    }
}



Measured memory_bytes: 3080
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

int main() {
	ios_base::sync_with_stdio( false );

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

	int ans = -1;
	for( int i = 1; i <= 1250; ++i ) {
		int x = i * 8 / 100;
		int y = i * 10 / 100;
		if( x == A && y == B ) {
			ans = i;
			break;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
a = list(input())
su = 0
ko = 0
p = 0

for i in range(len(a)):
    if i % 2 == 0:
        if a[i] != "0":
            su += 1
    else:
        if a[i] != "1":
            su += 1

for i in range(len(a)):
    if i % 2 == 0:
        if a[i] != "1":
            ko += 1
    else:
        if a[i] != "0":
            ko += 1

print(min(su,ko))

Measured memory_bytes: 49600
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
#include<map>
#include <bits/stdc++.h>
typedef long long ll;
#define N 100010
using namespace std;
int a[N];
ll solve()
{
	ll n;
	ll add=0;
	cin>>n;
	ll ans=1;
	for (ll i=0;i<=n;i++) 
	{
		cin>>a[i];
	}
	ll now=1;
	if (n==0)
	{
		if (a[0]==1)
			return 1;
		else
			return -1;
	}
   else
   {
        if(a[0]!=0)
            return -1;
   }
	for (ll i=1;i<=n;i++) 
	{
		add+=a[i];
	}
   for (ll i=1;i<=n;i++)
	{
		now=min(ll(now<<1),add);
		ans+=now; 
		now-=a[i];
		add-=a[i];
		if (now<0)
			return -1;
	}
	if (now!=0)
		return -1;
	return ans;
}

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

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
typedef double DOUBLE;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1
#define j0 gray_cat_j0

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const ll LL_INF = 1e17 + 16;
const int INF = 1e9 + 10;
const ll MOD = 1e9 + 7;

const int MAXN = 2e5 + 5;

char s[MAXN];

void solve(){
	scanf("%s", &s[0]);
	for(int i = 0; s[i]; i++) {
		if (s[i] == '?') {
			s[i] = 'D';
		}
	}
	printf("%s\n", s);
}

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 3852
# https://atcoder.jp/contests/abc099/tasks/abc099_c
# 典型的なコイン問題

# 引き出す金額の候補はNによって動的に決定する。
# dp[i] を i 円引き出すのに最小の操作回数とする
# dp[i] = min_{j \in 引き出し額}(dp[i - j]) +1 なので更新できる

# 今回は実装の都合上集めるdpではなく配るdpで実装する


def full(shape, full_value):
    if isinstance(shape, tuple):
        sha = shape[::-1]
        ret = [full_value] * sha[0]
        for s in sha[1:]:
            ret = [ret.copy() for i in range(s)]
        return ret

        if len(shape) == 2:
            return [[full_value] * shape[1] for _ in range(shape[0])]
    else:
        return [full_value] * shape


INF = 10**9

N = int(input())
candi = [1]
i = 1
while 6 ** i <= N:
    candi.append(6**i)
    i += 1

i = 1
while 9 ** i <= N:
    candi.append(9**i)
    i += 1

candi.sort()

dp = full(N + 1, INF)
dp[0] = 0  # 初期化

for i in range(N):
    for j in candi:
        if i + j > N:
            continue
        dp[i + j] = min(dp[i + j], dp[i] + 1)

print(dp[-1])


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

//vector<vector<int>> vec(縦,vector<int>(横));
/*deque<型> 配列の先頭にも用がある時はvectorの代わりに。
入力はstringでもらってからpush_back()*/

int main(){
  ll a;
  ll b;
  ll c;
  cin>>a;
  cin>>b;
  cin>>c;
  
  if(a+b+2*sqrtl(a*b)<c)
  {
    cout<<"Yes"<<endl;
  }
  else
  {
    cout<<"No"<<endl;
  } 
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int inf = 1 << 20;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using namespace std;

int main()
{
    int n;
    cin >> n;
    string s,t;
    cin >> s >> t;
    int ans = n * 2;
    for(int i = 1; i <= n; i++){
        string a,b;
        for(int j = n-i; j < n; j++){
            a += s[j];
        }
        for(int j = 0; j < i; j++){
            b += t[j];
        }
        if(a == b){
            ans = min(ans,n+n-i);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define repR(i, n) for(ll i = n; i >= 0; i--)
#define For(i, m, n) for(ll i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;

ll gcd(ll a, ll b){
    ll r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

ll lcm(ll x, ll y)
{
    if(x == 0 || y == 0) {
        return -1;
    }
    
    return (x * y / gcd(x, y));
}

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll nCr(ll n, ll r) {
    if ( r * 2 > n ) r = n - r;
    ll dividend = 1;
    ll divisor  = 1;
    for ( ll i = 1; i <= r; ++i ) {
        dividend *= (n-i+1);
        divisor  *= i;
    }
    return dividend / divisor;
}

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

ll mod = 1e9+7;

int main(){
    ll n;
    cin >> n;
    
    double ans = n / 2;
    if(n % 2 != 0){
        ans ++;
    }
    
    cout << ans / n << endl;
    
    return 0;
}


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

using namespace std;

typedef pair<int, int> Pi;
typedef pair<double, int> Pd;
typedef pair<Pd, Pi> PP;

struct edge {
  int to, lim;
  double dist;
  edge(){}
  edge(int to, int lim, double dist):to(to), lim(lim), dist(dist){}
};

vector< vector<edge> > G;
double mint[33][33][33];
int n, m, s, g;

const double inf = 1 << 25;

void init()
{
  for(int i = 0; i < 33; i++) {
    for(int j = 0; j < 33; j++) {
      for(int k = 0; k < 33; k++) mint[i][j][k] = inf;
    }
  }
}

void dijkstra()
{
  init();
  priority_queue<PP, vector<PP>, greater<PP> > que;
  mint[s][0][0] = 0.0;
  que.push(PP(Pd(0.0, 0), Pi(s, 0)));
  while(!que.empty()) {
    PP p = que.top(); que.pop();
    int now = p.second.first, prev = p.second.second, v = p.first.second;
    double t = p.first.first;
    if(now == g && v == 1) continue;
    if(mint[now][prev][v] < t) continue;
    for(int i = 0; i < G[now].size(); i++) {
      edge e = G[now][i];
      if(e.to == prev) continue;
      for(int d = -1; d <= 1; d++) {
	if(v+d <= 0 || e.lim < v+d) continue;
	if(t + e.dist/(v+d) < mint[e.to][now][v+d]) {
	  mint[e.to][now][v+d] = t + e.dist/(v+d);
	  que.push(PP(Pd(mint[e.to][now][v+d], v+d), Pi(e.to, now)));
	}
      }
    }
  }
}

int main()
{
  while(cin >> n >> m, n) {
    cin >> s >> g;
    G.clear(); G.resize(n + 1);
    while(m--) {
      int x, y, d, c;
      cin >> x >> y >> d >> c;
      G[x].push_back(edge(y, c, d));
      G[y].push_back(edge(x, c, d));
    }
    dijkstra();
    double ans = inf;
    for(int i = 1; i <= n; i++) ans = min(ans, mint[g][i][1]);
    if(ans == inf) puts("unreachable");
    else printf("%.12f\n", ans);
  }
  return 0;
}

Measured memory_bytes: 3864
#include<iostream>
using namespace std;
int main()
{
    long long a,b,x,temp;
    cin>>x;
    a=-64,b=-64;
    temp=a*a*a*a*a-b*b*b*b*b;
    while(temp!=x)
    {
        if(temp>x) b++;
        else a++;
        temp=a*a*a*a*a-b*b*b*b*b;
    }
    cout<<a<<" "<<b;
    return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>

void DispArr(int32_t arr[], int32_t len) {
	printf("%d", arr[0]);
	for (int32_t i = 1; i < len; i++) {
		printf(" %d", arr[i]);
	}
	putchar('\n');
}

void Swap(int32_t *a, int32_t *b) {
	int32_t tmp = *a;
	*a = *b;
	*b = tmp;
}

void BubbleSort(int32_t arr[], int32_t len) {
	int32_t swapCnt = 0;
	bool needLoop = true;
	for (int32_t i = 0; needLoop; i++) {
		needLoop = false;
		for (int32_t j = len-1; j > i; j--) {
			if (arr[j-1] > arr[j]) {
				Swap(&arr[j-1], &arr[j]);
				swapCnt++;
				needLoop = true;
			}
		}
	}
	DispArr(arr, len);
	printf("%d\n", swapCnt);
}

int main() {
	int32_t dataNum;
	scanf("%d", &dataNum);

	int32_t *data = (int32_t *)calloc(dataNum, sizeof(int32_t));
	if (!data) return 1;

	for (int32_t i = 0; i < dataNum; i++) {
		scanf("%d", &data[i]);
	}
	
	BubbleSort(data, dataNum);
	return 0;
}



Measured memory_bytes: 2100
/*
    Problem 11
    https://atcoder.jp/contests/abc128/tasks/abc128_c
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int n, m;
    cin >> n >> m;
    vector<int> light(m, 0);  // lightにつながっているswitchをbitで管理
    vector<int> p(m);
    for (int i = 0; i < m; i++) {
        int k; cin >> k;
        for (int j = 0; j < k; j++) {
            int s; cin >> s;
            s--;
            light[i] |= (1 << s);
        }
    }
    for (int i = 0; i < m; i++) cin >> p[i];

    int ans = 0;
    // bit exhausive search
    for (int b = 0; b < (1 << n); b++) {  // b : 付けるSwitchをbitで管理
        // Judge
        bool can = true;
        for (int i = 0; i < m; i++) {
            int cnt = __builtin_popcount(b & light[i]);  // 付いているlightの数
            if (cnt % 2 != p[i]) can = false;
        }
        if (can) ans++;
    }
    cout << ans << '\n';
}

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

int main() {
  char c;
  cin >> c;
  if(c == 'a' ||
    c == 'e' ||
    c == 'i' ||
    c == 'o' ||
    c == 'u'
  )
  {
    cout << "vowel" << endl;
  }
  else
  {
    cout << "consonant" << endl;
  }

}


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

int main() {
  int N, K, x = 1;
  cin >> N >> K;
  for (int i=0; i<N; i++) {
    if (x*2 <= x+K) x*=2;
    else x+=K;
  }
  cout << x << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void)
{
	char S[101];
	int K,a,i;
	scanf("%d", &K);
	scanf("%s", S);
	a = strlen(S);
	if (a <= K)
	{
		printf("%s\n", &S);
	}
	else
	{
		for (i = K ; i <= a; i++)
		{
			S[i] = '\0';
		}
		for (i = K ; i <= K + 2; i++)
		{
			S[i] = '.';
			
		}
		printf("%s\n", &S);

			
	}

	return 0;
}

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


int main() {
    int N;
    cin >> N;
    vector<int> W(N);
    int sum = 0;
    for(auto&v:W){
        int t;
        cin>>t;
        sum += t;
        v = sum;
    }
    //cout << sum<<endl;
    for (int i = 1; i < N; i++)
    {
        //cout << "|" << sum-W[i]<<","<<W[i] <<endl;
        if(sum-W[i] < W[i]){
            cout << min(abs(-sum+2*W[i]), abs(-sum+2*W[i-1])) << endl;
            return 0;
        }
    }
    cout << "a" << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Text.RegularExpressions;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var l = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var A = l[0];
            var B = l[1];
            int count = 0;
            for (int i = A; i <= B; i++)
            {
                var checkTarget = i.ToString().ToCharArray();
                if (checkTarget[0] == checkTarget[4] &&
                    checkTarget[1] == checkTarget[3])
                {
                    count++;
                }
            }
            Console.WriteLine(count);
        }
    }
}

Measured memory_bytes: 15444
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    vec A(n),B(m);
    rep(i,n) cin>>A[i];
    rep(i,m) cin>>B[i];
    vec C=convolution(A,B);
    rep(i,n+m-1) cout<<C[i]<<" ";
}

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

int main() {
    long long N;
    cin >> N;
    long long A[N];
    for (long long i = 0; i < N; ++i) {
        cin >> A[i];
    }
    bool find = true;
    for (long long i = 0; i < N; ++i) {
        if (A[i] % 2 == 0) {
            if ((A[i] % 3) == 0 || (A[i] % 5) == 0) {
            }
            else {
                find = false;
            }
        }
    }
    if (find == false) {
        cout << "DENIED" << endl;
    }
    else {
        cout  << "APPROVED" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0; i<n; i++)

int gcd(int p, int q) {
    if (q==0) return p;
    else return gcd(q, p%q);
}

int lcm(int p, int q) {
    return p * q / gcd(p, q);
}

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

    int ans;
    if (360%x == 0) cout << 360/x << endl;
    else {
        int temp = lcm(360, x);
        cout << temp/x << endl;
    }

    return 0;
}

Measured memory_bytes: 3616
N = int(input())
X = list(map(int, input().split()))

S = 0
S_min = 100000000000000

for i in range(min(X), max(X)+1):
    for j in X:
        S += (j - i)**2
        
    if S < S_min:
        S_min = S
        S = 0
    else:
        S = 0
print(S_min)

Measured memory_bytes: 3060
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 998244353


#############
# Main Code #
#############

N, X = getNM()
A = getList()

lista = []
for i in range(N):
    lista.append(abs(A[i] - X))

ans = lista[0]
for i in range(1, N):
    ans = gcd(ans, lista[i])
print(ans)

Measured memory_bytes: 101128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;


int main() {
	string s; cin >> s;
	auto func = [](string s) {
		cerr << s << endl;
		string t = s;
		reverse(t.begin(), t.end());
		int n = s.size();
		for (int i = 0; i < n; i++) {
			if (s[i] != t[i]) {
				return false;
			}
		}
		return true;
	};
	int n = s.size();
	bool flag = func(s);
	flag &= func(s.substr(0, (n - 1) / 2));
	flag &= func(s.substr((n + 1) / 2));
	cout << (flag ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
#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;
#define u_b upper_bound
#define l_b lower_bound

const int FAC_SIZE = 4040;
int fac[FAC_SIZE], fac_inv[FAC_SIZE];
const int mod = 998244353;

int mod_pow(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1)res *= a;
        a *= a;
        res %= mod;
        a %= mod;
        b /= 2;
    }
    return res;
}

int inv(int x) {
    return mod_pow(x, mod - 2);
}

void calc() {
    fac[0] = 1;
    fac_inv[0] = 1;
    for (int i = 1; i < FAC_SIZE; ++i) {
        fac[i] = fac[i - 1] * i % mod;
        fac_inv[i] = inv(fac[i]);
    }
}

int C(int n, int r) {
    return fac[n] * fac_inv[r] % mod * fac_inv[n - r] % mod;
}

int H(int n, int r) {
    return C(n + r - 1, r);
}
//calcを必ず実行
//mod書き換え
//fac,facinv配列長書き換え

signed main() {
    calc();
    int K, N;
    cin >> K >> N;
    for (int i = 2; i <= 2 * K; ++i) {
        int ans = 0;
        if (i % 2 == 1) {
            int p = 0;
            if (i - 1 <= K) p = (i - 1) / 2;
            else {
                int a = i - K;
                int b = K - a + 1;
                p = b / 2;
            }
            for (int q = 0; q <= p; ++q) {
                if (q > N)break;
                int r = K - 2 * p + q;
                if (r == 0)continue;
                int N2 = N - q;
                ans += C(p, q) * mod_pow(2, q) % mod * fac[N2 + r - 1] % mod * fac_inv[N2] % mod * fac_inv[r - 1] % mod;
                ans %= mod;
            }
        } else {
            int p = 0;
            if (i - 1 <= K) p = (i - 1) / 2;
            else {
                int a = i - K;
                int b = K - a + 1;
                p = b / 2;
            }
            for (int q = 0; q <= p; ++q) {
                if (q > N)break;
                int r = K - 2 * p + q - 1;
                if (r == 0)continue;
                int N2 = N - q;
                ans += C(p, q) * mod_pow(2, q) % mod * fac[N2 + r - 1] % mod * fac_inv[N2] % mod * fac_inv[r - 1] % mod;
                ans %= mod;
            }

            if (i - 1 <= K) p = (i - 1) / 2;
            else {
                int a = i - K;
                int b = K - a + 1;
                p = b / 2;
            }
            for (int q = 0; q <= p; ++q) {
                if (q > N)break;
                int r = K - 2 * p + q - 1;
                if (r == 0)continue;
                int N2 = N - q - 1;
                ans += C(p, q) * mod_pow(2, q) % mod * fac[N2 + r - 1] % mod * fac_inv[N2] % mod * fac_inv[r - 1] % mod;
                ans %= mod;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main() {
    int n;
    ll k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> s;
    vector<int> t(n+1,-1);
    int c = 1, l = 0;
    {
        int v = 1;
        while (t[v] == -1) {
            t[v] = s.size();
            s.push_back(v);
            v = a[v-1];
        }
        c = s.size() - t[v];
        l = t[v];
    }
 
    if (k < l) cout << s[k] << endl;
    else {
        k -= l;
        k %= c;
        cout << s[l+k] << endl;
    }
    return 0;
}

Measured memory_bytes: 5856
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    N = int(input())

    ans = 0
    N2 = N//2
    for i in range(1, N2+1):
        j = N // i
        ans +=  i * j * (1+ j) // 2
    ans += (N2+1 + N) * (N-N2) // 2
    print(ans)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 63040
#include <iostream>
using namespace std;
int main(void){
   int a,b,c,d,e,f,sci,soc;
   cin>>a;
   cin>>b;
   cin>>c;
   cin>>d;
   cin>>e;
   cin>>f;
   if(a<=b&&a<=c&&a<=d){
       sci=b+c+d;
   }
   else if(b<=a&&b<=c&&b<=d){
       sci=a+c+d;
   }
   else if(c<=a&&c<=b&&c<=d){
       sci=a+b+d;
   }
   else{
       sci=a+b+c;
   }
   if(f<=e){
       soc=e;
   }
   if(f>=e){
       soc=f;
   }
   cout<<sci+soc<<endl;
}


Measured memory_bytes: 3068
N, M = map(int, input().split())

# 端を構成しているカードは常にオモテ
# 内部を構成しているカードは常にウラ
if N == 1 and M == 1:
    ans = 1
elif N == 1 or M == 1:
    ans = max(N, M) - 2
else:
    ans = (N - 2) * (M - 2) 

print(ans)




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

using namespace std;

#define N 100000

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

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

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

	int c[N];
	int j = 0;
	for (int i = 0; i < n; i++) {
		if (b[i] > ma) {
			c[j] = b[i];
			j++;
		}
	}

	sort(c, c + j, greater<int>());

	int ans = 0;
	int f = 0;
	int sum = 0;
	for (int i = 0; i < j; i++) {
		sum += c[i];
		ans++;
		if (sum >= h) {
			f = 1;
			break;
		}
	}

	if (f == 0) {
		if ((h - sum) % ma == 0) {
			ans += (h - sum) / ma;
		} else {
			ans += (h - sum) / ma + 1;
		}
	}

	cout << ans << endl;


	return 0;
}




Measured memory_bytes: 1408
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;

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

  vector<int> a(11, -1);

  for (int i = 0; i <= 10; i++)
  {
    n -= 1;
    uint64_t mod = n % 26;
    a[i] = mod;
    n = n / 26;
    if (n == 0)
    {
      break;
    }
  }

  char ini = 'a';
  for (int i = 10; i >= 0; i--)
  {
    // cout << a[i] << endl;

    if (a[i] >= 0)
    {
      printf("%c", ini + a[i]);
    }
  }
  cout << endl;
  return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int L = A + B, R = C + D;
  if (L < R) {
    cout << "Right" << endl;
  }
  else if (L == R) {
    cout << "Balanced" << endl;
  }
  else if (L > R) {
    cout << "Left" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <utility>
#include <iomanip>
#include <numeric>
#include <climits>
#include <algorithm>
#include <cstdint>
using namespace std;

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

    int cnt = 0;
    for (int i = 1; i <= n; i++)
    {
        if (i % 2)
        {
            int cnt_temp = 0;
            for (int j = 1; j <= i; j++)
            {
                if (i % j == 0)
                    cnt_temp++;
            }
            if (cnt_temp == 8)
                cnt++;
        }
    }
    cout << cnt;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

#define lpsbd(i, s, b, d) for(size_t i = s; i < b; i+=d)
#define lpsb(i, s, b) for(size_t i = s; i < b; i++)
#define lpn(i, n) for(size_t i = 0; i < n; i++)
#define fa(i, x) for(auto &i: x)
#define vcd(t, n, d) vector<t>(n, d)
#define vc(t, n) vector<t>(n)
#define all(x) (x).begin(), (x).end()

using namespace std;
using ull = unsigned long long;

const ull MOD = 1000000007;

int main(void)
{
    int N, K, R;
    cin >> N >> K;
    R = min(N, K);
    auto V = vc(int, N);
    fa(i, V) cin >> i;
    int ans=0, sum;
    auto v = vc(int, 0);
    int k;
    for (int i = 0; i <= R; i++)
    {
        for (int j = R - i; j >= 0; j--)
        {
            v.resize(i+j);
            for (k = 0; k < i; k++) v[k] = V[k];
            for (k = 0; k < j; k++) v[k+i] = V[N-k-1];
            sort(all(v));
            for (k = 0; k < i+j && k < K-(i+j) && v[k] < 0; k++);
            sum = 0;
            for (; k < i+j; k++) sum += v[k];
            ans = max(sum, ans);
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
	ll n,m;
	cin>>n>>m;
	ll a[n],b[n];
	//vector<ll>ab[100001];
	vector<pair<ll, ll> > ab(n);
	for(ll i=0;i<n;i++)cin>>a[i]>>b[i];
	/*for(ll i=0;i<n;i++){
		ab[a[i]].push_back(b[i]);
	}
	for(int i=0;i<n;i++)sort(ab[a[i]].begin(),ab[a[i]].end());
	int buy=0;
	for(int i=0;i<100001;i++){

	}*/
	for(int i=0;i<n;i++){
		ab[i] = make_pair(a[i],b[i]);
	}
	sort(ab.begin(),ab.end());
	ll tmp=0;
	ll res=0;
	for(int i=0;i<n;i++){
		tmp+=ab[i].second;
        m-=ab[i].second;
		res+=(ab[i].first)*ab[i].second;
      	if(m<=0){
          if(m<0){
			res+=ab[i].first*m;
          }
          break;
        }
		/*if(m==tmp){
			break;
		}else if(tmp>m){
			res-=ab[i].first*(tmp-m);
			break;
		}*/
	}
	cout<<res<<endl;

	  /*for (int i = 0; i < n; i++) {
	    printf("(%d,%d) ", ab[i].first, ab[i].second);
	  }*/
}


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

int main() {
  int N, T;
  cin >> N >> T;

  vector<int> c( N );
  vector<int> t( N );

  rep( i, 0, N ) {
    cin >> c.at( i );
    cin >> t.at( i );
  }

  int Ans = 1001;

  rep( i, 0, N ) {
    if ( t.at( i ) <= T ) {
      if ( c.at( i ) < Ans ) Ans = c.at( i );
    }
  }

  if ( Ans != 1001 ) {
    cout << Ans << endl;
  } else {
    cout << "TLE" << endl;
  }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:https://atcoder.jp/contests/abc130/tasks/abc130_a>
 問題文============================================================
 =================================================================
 解説=============================================================
 問題文の通りに出力
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll X,A; cin >> X >> A;
    return X < A?0:10;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():

    N = in_n()
    C = list(in_all())

    mod = 10**9 + 7

    d = defaultdict(lambda: -1)
    d[C[0]] = 0
    dp = [0] * N
    dp[0] = 1

    for i in range(1, N):
        j = d[C[i]]
        if j == -1:
            dp[i] = dp[i - 1]
        elif j == i - 1:
            dp[i] = dp[i - 1]
        else:
            dp[i] = dp[i - 1] + dp[j]

        dp[i] %= mod

        d[C[i]] = i

    print(dp[-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 42144
#include<bits/stdc++.h>
#define pb push_back
#define F first
#define S second
using ll = long long;
#define ull unsigned ll
#define endl "\n"
#define vi vector<int>
#define vl vector<ll>
#define all(v) (v).begin(),(v).end()
#define mst(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ppi pair<int, pii>
#define mt make_tuple
#define eb emplace_back
using namespace std;

const int N = 305, mod = 1e9 + 7;
const int inf = 1e9;
void solve(){
    string s, t;
    cin >> s >> t;
    int ans = 0;
    for(int i = 0; i < s.length(); i++){
        if(s[i] != t[i])
            ans++;
    }
    cout << ans << endl;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);//cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll t,p;
    t=1;
    //cin>>t;
    for(p=1;p<=t;p++){
        solve();
    }
    return 0;
}


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

using namespace std;

int cnt;

void insertionSort(int* a,int n,int g) {
	for(int i = g;i < n;i++) {
		int v = a[i];
		int j = i - g;
		while(j >= 0&& a[j]>v){
			a[j+g]=a[j];
			j=j-g;
			cnt++;
		}
		a[j+g]=v;
	}
}

void shellSort(int* a,int n) {
	vector<int> g;
	int t = n;
	while(t > 0) {
		g.push_back(t);
		t = t / 2;
	}
	cout << g.size() << endl;
	for(int i = 0;i < g.size()-1;i++) {
		cout << g[i] << " ";
	}
	cout << g[g.size()-1] << endl;
	for(auto e:g) {
		insertionSort(a,n,e);
	}
	cout << cnt << endl;
	for(int i = 0;i < n;i++) {
		cout << a[i] << endl;
	}
}

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



Measured memory_bytes: 7064
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long INF = 1e15;

#include <math.h>
#define PI 3.14159265358979323846264338327950L


int Z_algo(string s, int k) {
    int n = s.length();
    vector<int> z(n);
    int L = 0, R = 0;
    for (int i = 1; i < n; i++) {
        if (i > R) {
            L = R = i;
            while (R < n && s[R - L] == s[R]) R++;
            z[i] = R - L; R--;
        }
        else {
            int k = i - L;
            if (z[k] < R - i + 1) z[i] = z[k];
            else {
                L = i;
                while (R < n && s[R - L] == s[R]) R++;
                z[i] = R - L; R--;
            }
        }
    }
    int mx = 0;
    for (int i = k; i < n; i++) mx = max(mx, z[i]);
    return mx;
}

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int mx = 0;
    for (int i = n-1; i >= 0; i--) {
        mx = max(mx, Z_algo(s.substr(i, n-i) + "#" + s.substr(0, i), n-i));
    }
    cout << mx;
    return 0;
}

Measured memory_bytes: 3680