akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main(){
    ll a,b,c;
    int x,y;
    cin >>a >>b >>c >>x >>y;

    ll ans = LLONG_MAX;
    rep(i,100001){
        ll t = c*2*i;
        t += a*max(0,x-i);
        t += b*max(0,y-i);
        ans = min(ans, t);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  	int A,B,C,i;
  	scanf("%d %d %d",&A,&B,&C);
  	i = A*100+B*10+C;
   	if (i==557 || i==575 || i==755)
      printf("YES");
 	else
      printf("NO");
  	return 0;
}

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

int main(){
    int k; cin >> k;
    ll ans;
    if(k%2==0 || k%5==0) ans = -1;
    else{
        ans = 1;
        ll num = 7, col = 1;
        while(num%k != 0) {
            col *= 10; col %= k;
            num += 7*col; num %= k;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
#define fast_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll a[N],dp[N];
bool vis[N],vis1[N];
vector<ll>v[N];
pair<ll,ll>p[N],p1[N];
set<int>s;
map<string,ll>mp;

main()
{fast_IO
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>a[i];
        dp[1]=abs(a[1]-a[0]);
    for(int i=2; i<n; i++)
    {
        int s1=abs(a[i]-a[i-1]);
        int s2=abs(a[i]-a[i-2]);
        int ans=min(s1+dp[i-1],s2+dp[i-2]);
        dp[i]=ans;
    }
    cout<<dp[n-1];

}










Measured memory_bytes: 9824
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;

 
lint fac[MAX], finv[MAX], inv[MAX];

void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return 0;
        }
    }

    // 素数である
    return 1;
}
   
    
  int main(){
        lint H,N;
        cin>>H>>N;
        lint A[N],B[N];
        lint mx=0;
        rep(i,N){
            cin>>A[i]>>B[i];
            mx=max(A[i],mx);
        }
        lint dp[N+1][H+1+mx];
        rep(i,N+1){
            rep(j,H+1+mx){
                dp[i][j]=INF;
            }
        }
       dp[0][0]=0;
        rep(i,N){
            rep(j,H+1+mx){
               if(j>=A[i]) dp[i+1][j]=min(dp[i][j],dp[i+1][j-A[i]]+B[i]);
               else dp[i+1][j]=dp[i][j];
            }
        }
       lint ans=INF;
       repp(i,H,H+mx+1){
           ans=min(ans,dp[N][i]);
       }
    cout<<ans;
    }
     
  


Measured memory_bytes: 87808
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
const int pArray[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997,1009,1013,1019,1021,1031,1033,1039,1049,1051,1061,1063,1069,1087,1091,1093,1097,1103,1109,1117,1123,1129,1151,1153,1163,1171,1181,1187,1193};
set<int> primes;
bool isPrime(int i){
  if(i<=1)return false;
  for(int p:pArray){
    if(p>i)break;
    if(i%p==0)return false;
  }
  return true;
}

int main(){ _;
  for(int p:pArray)
    primes.insert(p);
  for(int i=1201;i<1300000;i+=2)
    if(isPrime(i))
      primes.insert(i);
  int n;
  while(cin>>n,n!=0){
    auto u = primes.upper_bound(n); u--;
    auto l = primes.lower_bound(n);
    cout<<(*l-*u)<<endl;
  }
}

Measured memory_bytes: 5888
<?php
$N = trim(fgets(STDIN));
$line = trim(fgets(STDIN));
$cards = explode(" ", $line);

$count = 0;
$Alice = [];
$Bob = [];
for($i=0; $i<$N; $i++){
    if($i % 2 == 0){
        $Alice[] = max($cards);
    }else{
        $Bob[] = max($cards);
    }
    $maxes   = array_keys($cards, max($cards));
    $key_max = $maxes[0];
    array_splice( $cards, $key_max, 1);
}
echo abs(array_sum($Alice) - array_sum($Bob));

Measured memory_bytes: 16196
#include <stdio.h>
#include <string.h>
int main() {
	int n,tmpp;
	scanf("%d", &n);
	char city[100][11]={};
	char tmp[11]={};
	int p[100]={};
	int number[100]={};
	for (int i = 0; i < n; i++) {
		scanf("%s%d", city[i],&p[i]);
		number[i]=i+1;
	}
	for (int i = 0; i < n; i++) {
		for (int j = n-1; j > i; j--) {
			if(strcmp(city[j-1],city[j])>0){
				strcpy(tmp,city[j-1]);
				strcpy(city[j-1],city[j]);
				strcpy(city[j],tmp);
				tmpp=p[j-1];
				p[j-1]=p[j];
				p[j]=tmpp;
				tmpp=number[j-1];
				number[j-1]=number[j];
				number[j]=tmpp;
			}else if(strcmp(city[j-1],city[j])==0){
				if(p[j-1]<p[j]){
					strcpy(tmp,city[j-1]);
					strcpy(city[j-1],city[j]);
					strcpy(city[j],tmp);
					tmpp=p[j-1];
					p[j-1]=p[j];
					p[j]=tmpp;
					tmpp=number[j-1];
					number[j-1]=number[j];
					number[j]=tmpp;
				}
			}
		}
	}
	for (int i = 0; i < n; i++) {
		printf("%d\n", number[i]);
	}
	return 0;
}


Measured memory_bytes: 128
N, x = map(int, input().split())
A = list(map(int, input().split()))
INF = (1<<42)-1
cum = [[INF]*N for _ in range(N)]
for i in range(N):
  for j in range(i,N):
    cum[i][j] = min(cum[i][j-1],A[j])
ans = INF
for k in range(N):
  score = 0
  for j in range(N):
    if j-k>=0:
      score += cum[j-k][j]
    else:
      score += min(cum[0][j],cum[(j-k)%N][-1])
  ans = min(ans, k*x+score)
print(ans)

Measured memory_bytes: 100052
#include<stdio.h>
#include<string.h>
#define N 1000000
#define M 12


char H[N][M];

int getChar(char ch){
  if(ch == 'A') return 1;
  else if(ch == 'C') return 2;
  else if(ch == 'G') return 3;
  else if(ch == 'T') return 4;
  else return 0;
}

long long getKey(char str[]){
  long long sum=0,p=1,i;
  for(i=0;i<strlen(str);i++){
    sum+=p*(getChar(str[i]));
    p*=5;
  }
  return sum;
}
int h1(int key){return key % N; }
int h2(int key){return 1 + (key % (M - 1)); }

int find(char str[]){
  long long key,i,h;
  key=getKey(str);
  for(i=0;;i++){
    h = (h1(key)+i*h2(key)) % N;
    if(strcmp(H[h],str)==0) return 1;
    else if (strlen(H[h])==0) return 0;
  }
  return 0;
}

int insert(char str[]){
  long long key,i,h;
  key=getKey(str);
  for(i=0;;i++){
    h = (h1(key)+i*h2(key)) % N;
    if(strcmp(H[h],str)==0) return 1;
    else if (strlen(H[h])==0){
      strcpy(H[h],str);
      return 0;
    }
  }return 0;
}

main(){

  int i,j,n;
  char s[N],t[N];
  for(i=0;i<N;i++) H[i][0]='\0';
   scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s%s",s,t);
  
    if(s[0]=='i'){
      insert(t);
    }
    else{
      if(find(t)){
	printf("yes\n");
      }
      else{
	printf("no\n");
      }
    }
  }

  return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

int main() {

    string t,s;
    cin >> s>>t;

    int size_s, size_t;
    size_s = s.size();
    size_t = t.size();
    int count, m = 10000;

    for (int i = 0; i < size_s - size_t+1; i++) {
        count = 0;
        for (int j = 0; j < size_t; j++) {
            if (s[i + j] != t[j]) {
                count++;
            }
        }
        m = min(count, m);
    }

    cout << m;

    return 0;
}

Measured memory_bytes: 3632
def solve(n, H):
    prev_h, base_h = 0, 0
    count = 0
    up = True
    for h in H:
        if up and h < prev_h:
            # 上昇から下降に移ったら、ここまで何段上ったか記録
            count += prev_h - base_h
            up = False
        elif not up and prev_h < h:
            # 下降から上昇に移ったら、底辺の高さを記録
            base_h = prev_h
            up = True
        prev_h = h
    if up:
        count += prev_h - base_h
    return count

_n = int(input())
_H = list(map(int, input().split()))
print(solve(_n, _H))

Measured memory_bytes: 3064
#include <cstdlib>
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;

int top = 0, S[1000];
void push(int n)
{
	S[++top] = n;
}

int pop()
{
	return S[top--];
}


int main()
{
	int a, b;  
	char s[100];

	while (scanf("%s", s) != EOF)
	{
		if (s[0] == '+')
		{
			a = pop();
			b = pop();
			push(a+b);
		}			
		else if (s[0] == '-')
		{
			a = pop();
			b = pop();
			push(b-a);
		}
		else if (s[0] == '*')
		{
			a = pop();
			b = pop();
			push(a*b);
		}
		else 
		{
			push(atoi(s));
		}
	}
	cout << pop() << endl;
	return 0;
}




Measured memory_bytes: 3256
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<vector>
#include<string>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>

#define isNum(a) (a>='0'&&a<='9')
#define SP putchar(' ')
#define EL putchar('\n')
#define ri register int

template<class T>
inline void in(T&);
template<class T>
inline void out(const T&);

typedef long long ll;
using std::min;
using std::max;
using std::abs;
using std::sort;
using namespace std;

ll n,ans;

int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    in(n);
    for (ri i=0;i<=n;++i) ans+=ans+2;
    out(ans);EL;
    return 0;
}

template<class T>
void in(T &Re)
{
    T k=0;
    char ch=getchar();
    int flag=1;
    while (!isNum(ch))
	{
        if (ch=='-')
		{
            flag=-1;
        }
        ch=getchar();
    }
    while (isNum(ch))
	{
        k=(k<<1)+(k<<3)+ch-'0';
        ch=getchar();
    }
    Re=flag*k;
}
template<class T>
void out(const T &Wr)
{
    if (Wr<0)
	{
        putchar('-');
        out(-Wr);
    }
	else
	{
        if (Wr<10)
		{
            putchar(Wr+'0');
        }
		else
		{
            out(Wr/10);
            putchar((Wr%10)+'0');
        }
    }
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
    int N;
    cin >> N;
    int A[N];
    vector<int> B(N);
    rep(i,N){
        cin >> B[i];
    }
    rep(i,N){
        int index = -1;
        rep(j,N-i){
            if(j+1 == B[j]) index = j;
        }
        if(index == -1){
            cout << -1 << endl;
            return 0;
        }else{
            A[N-i-1] = index+1;
            B.erase(B.begin() + index);
        }
    }
    rep(i,N){
        cout << A[i] << endl;
    }

    return 0;
}

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

S_list = list(S)

from collections import Counter
ans = 0
for i in range(1, N ):
    fas = S_list[ : i]
    sec = S_list[i : ]
    #print(fas, sec)
    fas_dic = Counter(fas)
    sec_dic = Counter(sec)
    num = 0
    for j in fas_dic:
        if j in sec_dic:
            num += 1
    ans = max(ans, num)

print(ans)

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

int main() {
  
  int a,b,c;
  cin >> a >> b >> c;
  
  int sum = 100*a + 10*b + c;
  if(sum%4 == 0) cout << "YES" << endl;
  else cout << "NO" << endl;  
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define f0r(a, b) for (long long a = 0; a < (b); a++)
#define f1r(a, b, c) for (long long a = (b); a < (c); a++)
#define f0rd(a, b) for (long long a = (b); a >= 0; a--)
#define f1rd(a, b, c) for (long long a = (b); a >= (c); a--)
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define pb push_back
#define mp make_pair
#define f first
#define s second
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vpl = vector<pll>;
 
void fio() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); 
  cout.tie(0);
}
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const long double pi = 3.14159265358979323846;



void solve() {
  ll n; cin >> n; 
  ll a[n]; f0r(i, n) cin >> a[i];
  ll x = 0, s = 0;
  f0r(i, 2) s += a[i];
  f1r(i, 2, n) x ^= a[i];

  if (s < x) {
    cout << -1 << '\n';
    return;
  }

  if ((s - x) % 2 != 0) {
    cout << -1 << '\n';
    return;
  }

  ll v = (s - x) / 2;

  ll vsum = 0;
  vl var;
  f0r(i, 45) {
    ll k = (1LL << i);
    ll ab = x & (1LL << i), bb = v & (1LL << i);
    if (ab && bb) {
      cout << -1 << '\n';
      return;
    }
    if (ab || bb) vsum += k;
    if (ab) var.pb(k);
  }
  sort(var.rbegin(), var.rend());
  for (ll x: var) {
    if (vsum - x >= a[1]) vsum -= x;
  }

  if (vsum >= s || vsum < a[1]) {
    cout << -1 << '\n';
  } else {
    cout << vsum - a[1] << '\n';
  }
}
 
int main() {
  fio();
  
  int T = 1;
  // cin >> T;
  while (T--) solve();
} 

Measured memory_bytes: 3664
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380


int main()
{
	cout << fixed << setprecision(10);

	int n;
	cin >> n;
	cout << (1000 - n % 1000) % 1000;


	return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <queue>
#include <cstring>
#include <sstream>
using namespace std;

int main()
{
	string s;
	cin >> s;
	int count = 0;
	string tmp;
	while(!s.empty()){
		tmp.push_back(s[0]);
		s.erase(0, 1);
		if(s[0] == ','){
			 s.erase(0, 1);
			 cout << tmp << " ";
			 tmp.clear();
		}
	}
	cout << tmp << endl;

	return 0;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    switch (n%10) {
        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
        puts("hon");
        break;
        case 0:
        case 1:
        case 6:
        case 8:
        puts("pon");
        break;
        case 3:
        puts("bon");
        break;
    }
    return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
using namespace std;
#define int long long
const int N=302019;
int a[N],f[N][4],sf[N],pr[N];
#undef int
int main()
{
	#define int long long
	int n; cin>>n;
	for(int i=1;i<=n;i++)scanf("%lld",a+i);
	pr[1]=a[1]; pr[2]=a[2];
	for(int i=3;i<=n;i++)pr[i]=pr[i-2]+a[i];
	for(int i=1;i<=n;i++)f[i][0]=f[i][1]=f[i][2]=-1e18;
	f[1][0]=a[1]; f[2][0]=a[2];
	for(int i=3;i<=n;i++){
		f[i][1]=max(f[i-2][1]+a[i],pr[i-3]+a[i]);
		f[i][2]=max(f[i-2][2]+a[i],f[i-3][1]+a[i]);
		if(i>3)f[i][2]=max(f[i][2],pr[i-4]+a[i]);
	}
	if(n&1)cout<<max(pr[n]-a[1],max(max(pr[n-2],pr[n-1]),max(f[n][2],max(f[n-1][1],f[n][1]))))<<endl;
	else cout<<max(pr[n],max(pr[n-1],f[n][1]))<<endl;
	return 0;
}

Measured memory_bytes: 13072
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
int main(){
  int n;
  while (std::cin >> n, n) {
    vector<vector<int> > g(n,vector<int>(n, 1e9));
    for (int i = 0; i < n - 1; i++) {
      int to, from, cost;
      std::cin >> to >> from >> cost;
      to--, from--;
      g[to][from] = cost;
      g[from][to] = cost;
    }
    g[0][0] = 0;
    int ans = 0;
    vector<pii> leaf;
    for (int i = 1; i < n; i++) {
      g[i][i] = 0;
      int cnt = 0, p = -1;
      for (int j = 0; j < n; j++) {
        if(g[i][j] != 1e9 and g[i][j] != 0)cnt++, p = j;
      }
      if(cnt != 1)continue;
      leaf.push_back(pii(i, p));
    }
    for (int i = 0; i < leaf.size(); i++) {
      pii v = leaf[i];
      g[v.first][v.second] = 1e9;
      g[v.second][v.first] = 1e9;
    }
    for (int i = 0; i < n; i++) {
      for (int j = i; j < n; j++) {
        if(g[i][j] == 1e9)continue;
        ans += 2*g[i][j];
      }
    }
    for (int k = 0; k < n; k++) 
      for (int i = 0; i < n; i++) 
        for (int j = 0; j < n; j++) 
          g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
    int sub = 0;
    for (int i = 0; i < n; i++) {
      if(g[0][i] == 1e9)continue;
      sub = max(sub, g[0][i]);
    }
    std::cout << ans - sub << std::endl;
  }
  return 0;
}

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

int main() {
	int N;
	cin >> N;
	
	int nums[N]={0};
	int ave=0;
	int cost=0;

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

    if(ave>=0){ave= (ave+N/2)/N;}
    else{ave=(ave-N/2)/N;}
	for(int i=0; i<N; i++){
		cost+= (ave-nums[i])*(ave-nums[i]);
		
	}
	
	cout << cost <<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
def main():
    n, q = (int(i) for i in input().split())
    nt = [[i for i in input().split()] for j in range(n)]
    from collections import deque
    nt = deque(nt)
    time = 0
    finished = []
    while nt:
        time += min(int(nt[0][1]),q)
        nt[0][1]= max(0, int(nt[0][1]) - q)
        if int(nt[0][1]) == 0:
            finished.append((nt[0][0],time))
            nt.popleft()
        else:
            nt.rotate(-1)
    
    for f in finished:
        print(*f)

if __name__ == '__main__':
    main()


Measured memory_bytes: 14180
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 3
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	p := getNextInt(scanner)
	s := getNextString(scanner)
	mm := make([]int, n+1)
	pow := 1
	for i := n - 1; i >= 0; i-- {
		mm[i] = int(s[i]-'0')*pow + mm[i+1]
		mm[i] %= p
		pow = (pow * 10) % p
	}
	mp := map[int]int64{}
	var ans int64
	for i := n; i >= 0; i-- {
		if p == 2 || p == 5 {
			if i < n && int(s[i]-'0')%p == 0 {
				ans += int64(i + 1)
			}
			continue
		}
		ans += mp[mm[i]]
		mp[mm[i]] = mp[mm[i]] + 1
	}

	fmt.Fprintln(writer, ans)
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

int main() {
  int a,b;
  cin>>a>>b;
  if(b==1){
    cout<<0<<endl;
    return 0;
  }
  cout<<(a+b-3)/(a-1)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1000000;
#include <map>
#include <math.h>
 
using ll = long long;
using namespace std;

ll n, k;
const ll mod = 1000000007;



int main(){
    int a, b;
    cin >> a >> b;
    if(a<=5) out(0);
    else if(6<=a&&a<=12) out(b/2);
    else out(b);
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

int main() {
    int N, M;
    cin >> N >> M;
    vector<bool> b(N, false);
    map<int, int> mp;
    int ac = 0;
    int wa = 0;
    rep(i, M) {
        int p;
        string s;
        cin >> p >> s;
        p--;
        if (!b[p]) {
            if (s == "AC") {
                ac++;
                wa += mp[p];
                b[p] = true;
            } else {
                mp[p]++;
            }
        }
    }

    cout << ac << " " << wa << endl;
}

Measured memory_bytes: 4992
/* ex4_3
   kohei_suzuki */

#include <stdio.h>

/* プロトタイプ宣言 */
int snowfall(int height1, int height2); //積雪量を求める関数

int main(void){

    int low_height, high_height; //低い塔,高い塔 の高さ
    int ans; //答え
    scanf("%d %d",&low_height, &high_height) ; //入力受取

    ans = snowfall(low_height, high_height); //関数snowfallで積雪量を求める
    printf("%d\n",ans); //答えを出力

    return 0;
}

/* 関数の定義 */
int snowfall(int height1, int height2){
    int diff, snow_height=0; //塔の高さの差,積雪量


    for(diff = height2 - height1; diff !=0; diff--){ //繰り返しで高いほうの塔の高さ(1+2+3…+diff)を求める
        snow_height += diff;
    }
    snow_height = snow_height - height2; 
    return snow_height; //積雪量を返す
}

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

int main(){
    int n, m, ans, cnt;
    string s;
    vector<string> red;
    vector<string> blue;
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> s;
        red.push_back(s);
    }
    cin >> m;
    for(int i=0; i<m; i++){
        cin >> s;
        blue.push_back(s);
    }
    ans = 0;
    for(int i=0; i<n; i++){
        cnt = 0;
        for(int j=0; j<n; j++){
            if(red[i] == red[j]){
                cnt++;
            }
        }
        for(int j=0; j<m; j++){
            if(red[i] == blue[j]){
                cnt--;
            }
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

signed main(){

  int n; cin >> n;
  int res = 1;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
    if(a[i] == 0){
      cout << 0 << endl;
      return 0;
    }
  }
  for(int i = 0; i < n; i++){
    if(res > 1000000000000000000 / a[i]){
      cout << -1 << endl;
      return 0;
    }
    res *= a[i];
  }
  cout << res << endl;

  return 0;
}

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


int main(){
  int N;cin >>N;
  vector<int>a(N);
  rep(i,N){
   	cin >>a[i]; 
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  int g=a[0];
  double dif=10000000000;
  double x,y;
  int h=0;
    x=g/(double)2;
    rep(i,N){
    	dif=min(dif,abs(x-a[i]));
      	if(dif==abs(x-a[i])){
        	h=a[i];
        }
    }
 	cout<<g<<' '<<h;
}

Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <regex> //正規表現
#include <map>
#include <set>
#include <cassert> //assart
using namespace std;
#define ll long long int
#define FOR(i,min,max) for(int i=(min);i<(max);i++)
#define FOReq(i,min,max) for(int i=(min);i<=(max);i++)
#define FORREV(i,max,min) for(int i=(max)-1;i>=(min);i--)
const int  MOD=1000000007;
const int  INF=2000000000;
const int INF2=  10000000;
const double  Micro=1e-5;

int UnUsedVariable(){
    if(INF || Micro || MOD || INF2){;}
    return 0;
}

#define pf printf
#define sf scanf
#define inarray(array,min,max) FOR(i,min,max){cin>>array[i];}
#define inarrayW(arrayA,arrayB,min,max) FOR(i,min,max){cin>>arrayA[i]>>arrayB[i];}
inline int isEven(int x){return x%2==0;}
inline int isOdd (int x){return x%2==1;}
#define br printf("\n");
#define OutputAndReturn0(x) {cout<<(x)<<endl;return 0;}

int printintN(int array[],const int num){
    for(int i=0;i<num;i++){printf("%d ",array[i]);}
    br;
    return 0;
}


//#define int long long int

/*
 1.困った時こそ冷静に問題文を見直す！制約条件を見ろ！乱択アルゴリズムとかO(N^3)とか！
 2.一度に大量のことをやろうとしない。デバッグしやすいように細かく！
 3.プログラミングは半分数学だし、もう半分は数学ではない！
 4.できない問題はできない！！！！！
 */

int experiment(){
    int A,B;
    scanf("%d %d",&A,&B);
    if(A==B)OutputAndReturn0(A+B)
    else OutputAndReturn0(max(A,B)*2-1)
    return 0;
}
signed main(){
    assert(1);
    experiment();
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int l = sc.nextInt();
        int r = sc.nextInt();
        int d = sc.nextInt();
        int count = 0;
        for (int i = l;i<=r;++i)
        {
            if (i%d == 0) ++count;
        }
        System.out.println(count);
        sc.close();
    }
}

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

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    long long int n,i;
    cin>>n;
    long long int a[n],dp[n];
    for(i=0;i<n;i++)
        cin>>a[i];
    dp[0]=0;
    dp[1]=abs(a[0]-a[1]);
    for(i=2;i<n;i++)
        dp[i]=min(abs(a[i]-a[i-1])+dp[i-1],abs(a[i]-a[i-2])+dp[i-2]);
    cout<<dp[n-1];
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int n,m,dp[5][10010];
char a,b,c;

int main()
{
	cin>>a;
	if(a=='a'||a=='e'||a=='i'||a=='o'||a=='u') puts("vowel");
	else puts("consonant");
}

Measured memory_bytes: 256
A,B,C,X,Y = list(map(int,input().split()))
  
if X < Y:
  if C*2 <= B:
    print(C*2*Y)
  elif C*2 <= (A+B):
    print(C*2*X + B*(Y-X))
  else:
    print(A*X + B*Y)
else:
  if C*2 <= A:
    print(C*2*X)
  elif C*2 <= (A+B):
    print(C*2*Y + A*(X-Y))
  else:
    print(A*X + B*Y)

Measured memory_bytes: 3064
public class Main {
	
	private char[] e;
	private int p;

	public int number() {
		int res = 0;
		if (e[p] == '(') {
			++p;
			res = expression();
			++p;
		} else {
			for (; Character.isDigit(e[p]); ++p) {
				res = res * 10 + (e[p] - '0');
			}
		}
		return res;
	}
	
	public int factor() {
		int res = number();
		for (;;) {
			if (e[p] == '*') {
				++p;
				res *= number();
			} else if (e[p] == '/') {
				++p;
				res /= number();
			} else break ;
		}
		return res;
	}
	
	public int expression() {
		int res = factor();
		for (;;) {
			if (e[p] == '+') {
				++p;
				res += factor();
			} else if (e[p] == '-') {
				++p;
				res -= factor();
			} else break ;
		}
		return res;
	}
	
	public void run(java.util.Scanner sc, java.io.PrintStream out) {
		final int n = sc.nextInt();
		for (int i = 0; i < n; ++i) {
			e = sc.next().toCharArray();
			p = 0;
			out.println(expression());
		}
	}
	
	public static void main(String[] args) {
		try (java.util.Scanner sc = new java.util.Scanner(System.in)) {
			(new Main()).run(sc, System.out);
		}
	}

}

Measured memory_bytes: 25976
#include <bits/stdc++.h>
#include <boost/multi_array.hpp>
#define rep(i,n) for (int i=0; i< (n); ++i)
using namespace std;
typedef long long ll;

int main() {
  int a,b;
  cin >> a >> b;
  int ans = (b-1)/(a-1);
  if ((b-1)%(a-1)!=0) ans++;
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
# input
n = int(input())
li = []
for i in range(n):
    s = input()
    s = sorted(s)
    s = "".join(s)
    li.append(s)

# check
dic = {}
for i in li:
    if (i in dic):
        dic[i] += 1
    else:
        dic[i] = 1

def calc(n):
    return n * (n - 1) // 2

ans = 0

for i in dic.values():
    ans += calc(i)

# output
print(ans)


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

#import
#import math
#import numpy as np
N = int(input())
A = list(map(int, input().split()))
n = N // 3
dic = {}

for a in A:
    if a in dic:
        dic[a] += 1
    else:
        dic[a] = 1

ans = True

if len(dic) > 3:
    ans = False

elif len(dic) == 3:
    keys = dic.keys()
    t = []
    for k in keys:
        t.append(k)
        if dic[k] != n:
            ans = False

    a = t[0]
    b = t[1]
    c = t[2]

    if (a ^ b) != c:
        ans = False

elif len(dic) == 2:
    for k in dic:
        if k == 0:
            if dic[k] != n:
                ans = False
        else:
            if dic[k] != n * 2:
                ans = False

else:
    keys = dic.keys()
    if not 0 in keys:
        ans = False

if ans:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 20664
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define SZ(x) ((int)(x).size())
#define MEM(x,a) memset(x,a,sizeof(x))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1000000007,N=1e5+5,M=1e5+5,INF=0x3f3f3f3f;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//head

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m,sum=0;
    cin>>n>>m;
    VI a(n);
    rep(i,0,n){
        cin>>a[i];
        sum+=a[i];
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    int cnt=0;
    rep(i,0,n){
        if((a[i]<sum/(4*m))||(a[i]==sum/(4*m)&&sum%(4*m)))break;
        ++cnt;
    }
    if(cnt<m)cout<<"No";
    else cout<<"Yes";
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	long long a,b[10001],i,j,x,ans,ans2,ans3=0;
	scanf("%lld",&a);
	for(i=0;i<a;i++){
		scanf("%lld",&b[i]);
		ans3=ans3+b[i];
	}
	for(i=0;i<a;i++){
		for(j=i;j<a;j++){
			if(b[i]>b[j]){
				x=b[i];
				b[i]=b[j];
				b[j]=x;
			}
		}
	}
	ans=b[0];
	ans2=b[a-1];
	printf("%lld %lld %lld\n",ans,ans2,ans3);
	return 0;
}


Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pii pair<int,int>
#define pb push_back
const int maxn = 2e5 + 5;
int f1[maxn] , f2[maxn];
int getf (int x , int f[]){
    return x == f[x] ? x : f[x] = getf(f[x] , f);
}
void mer (int a , int b , int f[])
{
    int fa = getf(a , f) , fb = getf(b , f);
    if (fa == fb) return ;
    f[fb] = fa;
}
int n , k , l;
map<pii,int> Q;
int main()
{
    ios::sync_with_stdio(false);
    cin >> n >> k >> l;
    for (int i = 1 ; i <= n ; i++) f1[i] = i , f2[i] = i;
    for (int i = 1 ; i <= k ; i++){
        int x , y; cin >> x >> y;
        mer(x , y , f1);
    }
    for (int i = 1 ; i <= l ; i++){
        int x , y; cin >> x >> y;
        mer(x , y , f2);
    }
    for (int i = 1 ; i <= n ; i++)
        Q[mp(getf(i , f1) , getf(i , f2))]++;
    for (int i = 1 ; i <= n ; i++){
        cout << Q[mp(getf(i , f1) , getf(i , f2))] << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 16564
n = int(input())

prime = []
for i in range(2, n + 1):
    j = 2
    while j ** 2 <= i:
        if i % j == 0:
            break
        j += 1
    if j ** 2 > i:
        prime.append(i)
        
ans = 1

for p in prime:
    soinsu = 1
    for i in range(2, n + 1):
        while True:
            if i % p == 0:
                soinsu += 1
                i = int(i / p)
            else:
                break
    ans = (ans * soinsu) % (10 ** 9 + 7)
         
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h> 
using namespace std;
 
typedef signed long long ll;
const int MX = 1e6 + 5;

int main() {
	ll num;
	cin >> num;
	if((num % 2) == 1) cout << 0 << endl;
	else {
		ll cnt = 0, val = 10;
		for( ; val <= num ; cnt += num / val, val *= 5);
		cout << cnt << endl;
	}
    return 0;
}

Measured memory_bytes: 256
N = gets.to_i
even, odd = gets.split.map(&:to_i).partition.with_index{|_, i|
  i.even?
}

ev = even.group_by(&:itself).map{|k, v|[k, v.size]}.sort_by{|_, size| -size}
od = odd.group_by(&:itself).map{|k, v|[k, v.size]}.sort_by{|_, size| -size}
if ev[0][0] != od[0][0]
  p N - ev[0][1] - od[0][1]
else
  p N - [ev[0][1] + od.fetch(1, [0, 0])[1], od[0][1] + ev.fetch(1, [0, 0])[1]].max
end


Measured memory_bytes: 25296
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;

int main(){

  ll n;
  cin >> n ;


  ll count=0;
  for(ll i=1;i<n;i++){
    for(ll j=1;j<n;j++){
      if(i*j>=n){
        break;
      }
      if(i*j<n){
        count++;
      }
    }
  }


  cout << count << endl;


}


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

typedef long long ll;
#define READ(a) int a; cin >> a;
#define READARR(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define READMAT(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define print(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll N = 2e5;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	double h, a;
	cin >> h >> a;
	cout << ll(ceil(h/a));
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int n;
    cin >> n;
    vector<int> a(n * 3);
    rep(i, n * 3) cin >> a[i];
    priority_queue<int, vector<int>, greater<int>> pqmax;
    priority_queue<int> pqmin;

    vector<int> sumMax(3 * n);
    vector<int> sumMin(3 * n);
    int sum1 = 0;
    int sum2 = 0;
    rep(i, n){
        pqmax.push(a[i]);
        sum1 += a[i];
        pqmin.push(a[3*n-1-i]);
        sum2 += a[3*n-1-i];
        sumMax[i] = sum1;
        sumMin[3*n-1-i] = sum2;
    }
    for(int i = n; i < n * 2; i++){
        sum1 += a[i];
        pqmax.push(a[i]);
        sum1 -= pqmax.top();
        pqmax.pop();
        sumMax[i] = sum1;

        sum2 += a[3*n-1-i];
        pqmin.push(a[3*n-1-i]);
        sum2 -= pqmin.top();
        pqmin.pop();
        sumMin[3*n-1-i] = sum2;
    }

    int ans = -INF;
    for(int i = n - 1; i < 2 *n; i++){
        ans = max(ans, sumMax[i] - sumMin[i+1]);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 9076
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-03-04 18:18:42
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

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

  string s; cin >> s;
  vector<int64> cnt(26, 0);
  for (char c : s) ++cnt[c - 'a'];

  int64 n = s.size();
  int64 ans = n * (n - 1LL) / 2LL + 1LL;

  for (int64 x : cnt) ans -= x * (x - 1) / 2;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 720
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
using namespace std;
int main() {
	while (true) {
		int n;
		scanf("%d", &n);
		if (n == 0) break;
		int dp[10] = {};
		for (int i = 0;i < n;++i) {
			int a = 0;
			scanf("%d", &a);
			dp[a]++;
		}
		for (int i = 0;i < 10;++i) {
			if (dp[i] == 0) {
				printf("-\n");
			}
			else {
				for (int q = 0;q < dp[i];++q) {
					printf("*");
				}
				printf("\n");
			}
		}
	}
}


Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, n) for(ll i = 1; i <= ll(n); ++i)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); ++i)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); ++i)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  string S, T;
  cin >> S >> T;
  rep(i, S.size()) if(S[i]!=T[i]) goto OUT;
  cout << "Yes" << newl;
  return 0;
  
  OUT:
  cout << "No" << newl;
  return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const ll mod = 1000000007;
const ll INF = 1e+12;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;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--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define int long long

//ある量を決めるとどうすべきかがgreedyに決まる
//探索すべきものを絞る

//ちょうどを以上にしても大丈夫
//x種類選んだ状態とx+1種類選んだ状態との間の差分をいかに素早く更新できるようなデータの持ち方を工夫する

void solve() {
    int n, k; cin >> n >> k;
    vector<vector<int>> s(n);
    rep(i, n) {
        int t, d; cin >> t >> d;
        t --; //配列のindexにとる時はその範囲に要注意！
        s[t].push_back(d);
    }
    for(auto &v : s) {
        sort(all(v), greater<int>());
        if(v.empty()) v.push_back(-INF); //番兵
    }

    sort(all(s), [&](vector<int> a, vector<int> b) {return a[0] > b[0];});
    
    priority_queue<int> pque;
    int cur = 0;
    rep(i, k) {
        cur += s[i][0];
        for(int j = 1; j < (int)s[i].size(); j++) {
            pque.push(s[i][j]);
        }
    }
    Rep(i, k, n) {
        rep(j, (int)s[i].size()) {
            pque.push(s[i][j]);
        }
    }

    int res = cur + k * k;
    for(int x = k - 1; x >= 1; x--) { //何度も同じ計算をしない（例　累積和）
        int v = s[x][0];
        int w = pque.top();
        if(v < w) {
            cur += w; pque.pop();
            cur -= v; pque.push(v);
        }
        res = max(res, cur + x * x);
    }
    cout << res << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

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

int main() {
  int n;
  cin>>n;
  vector<double> a(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i);
  }
  double count=0;
  for(int i=0;i<n;i++){
    count+=(1/a.at(i));
  }
  cout<<(1/count);
}

Measured memory_bytes: 256
n = int(input())
a,b = [], []
for _ in range(n):
  i = input().split()
  a.append(int(i[0]))
  b.append(int(i[1]))
a.sort()
b.sort()
if n%2:
  l = a[n//2]
  h = b[n//2]
  print(h-l+1)
else :
  l = (a[n//2-1]+a[n//2]) / 2
  h = (b[n//2-1]+b[n//2]) / 2
  print(int((h-l)*2) +1)
           

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

int main() {
  int N, K;
  cin >> N >> K;
  for (int i=K-N+1; i<K+N; i++) {
  	if (-1000000 <= i && 1000000 >= i) {
      cout << i << " ";
    }
  }
  
}

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



string make(string s){
	int i = 0;
	for(i = 0 ; i < s.size() ; i++)
		if( s[i] != '.' ) break; 
	string w = string(i,'.');
	for( ; i < s.size() ; i++){
		if( string("()[]{}").find(s[i]) != -1 ) w += s[i];
	}
	return w;
}

int main(){
	int P,Q;
	while( cin >> P >> Q && P){
		vector< array<int,4> > data;
		int cnt[3] = {};
		for(int i = 0 ; i < P ; i++){
			string t;
			cin >> t;
			t = make(t);
			array<int,4> info;
			info[3] = count(t.begin(),t.end(),'.');
			for(int j = 0 ; j < 3 ; j++)
				info[j] = cnt[j];
			data.push_back(info);
			for(int j = 0 ; j < t.size() ; j++){
				if( t[j] == '(' ) cnt[0]++;
				if( t[j] == '{' ) cnt[1]++;
				if( t[j] == '[' ) cnt[2]++;
				if( t[j] == ')' ) cnt[0]--;
				if( t[j] == '}' ) cnt[1]--;
				if( t[j] == ']' ) cnt[2]--;				
			}
		}
		
		vector< array<int,3> > cand;
		for(int R = 1 ; R <= 20 ; R++){
			for(int C = 1 ; C <= 20 ; C++){
				for(int S = 1 ; S <= 20 ; S++){
					int f = 1;
					for(int i = 0 ; i < data.size() ; i++)
						if( data[i][0] * R + data[i][1] * C + data[i][2] * S != data[i][3] ){
							f = 0;
						}			
					if(f){
						cand.push_back(array<int,3>{R,C,S});
					}
				}
			}
		}
		
		cnt[0] = cnt[1] = cnt[2] = 0;
		for(int i = 0 ; i < Q ; i++){
			string t;
			cin >> t;
			t = make(t);
			set<int> ans;
			for( auto d : cand ){
				int w = d[0] * cnt[0] + d[1] * cnt[1] + d[2] * cnt[2];
				ans.insert(w);
			}
			if( ans.size() != 1 ) cout << -1;
			else cout << *ans.begin();
			if(Q-1==i)cout << endl;
			else cout << " ";
			
			for(int j = 0 ; j < t.size() ; j++){
				if( t[j] == '(' ) cnt[0]++;
				if( t[j] == '{' ) cnt[1]++;
				if( t[j] == '[' ) cnt[2]++;
				if( t[j] == ')' ) cnt[0]--;
				if( t[j] == '}' ) cnt[1]--;
				if( t[j] == ']' ) cnt[2]--;				
			}
		}
	}
	
}

Measured memory_bytes: 1376
#include<stdio.h>
#define N 105
#define V 100010
#define ll long long int
ll minn(ll x,ll y)
{
	return  x < y ? x : y;
}
ll dp[V];
ll w[N];
int v[N];
int n;
ll lim;
ll ans = 0;
int main()
{
	for (int i = 1; i <= V - 1; i++)
		dp[i] = 1e12;
	dp[0] = 0;
	scanf("%d %lld", &n, &lim);
	for (int i = 1; i <= n; i++)
		scanf("%lld %d", &w[i], &v[i]);
	for (int j = 1; j <= n; j++)
		for (int i = V - 1; i >= v[j]; i--)
			dp[i] = minn(dp[i], dp[i - v[j]] + w[j]);
	for (int i = 1; i <= V - 1; i++)
	{
		if (dp[i] != 1e12 && dp[i] <= lim)
			ans = i;		
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 896