akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<climits>
#include<map>
#include<set>
#include<cassert>
#include<deque>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<27
#define all(n) n.begin(),n.end()
#define insert(a,b,c,d) PP(P(a,b),P(c,d))
#define F first
#define S second
#define pb push_back
#define MAX_N (1<<18)
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;
typedef long long ll;





template<class T>
class RMQ_segment{
private:
  int n;
  T dat[2*MAX_N-1];
public:
  void init(int n_){
    n = 1;
    while(n<n_)n*=2;
    for(int i=0;i<2*n-1;i++)dat[i] = 0;
  }

  void update(int k,T a){
    k += n-1;
    dat[k] = a;
    while(k > 0){
      k = (k-1)/2;
      dat[k] = max(dat[k*2+1],dat[k*2+2]);
    }
  }

  T _query(int a,int b,int k,int l,int r){
    if(r<=a || b<=l)return 0;
    else if(a<=l && r<=b)return dat[k];
    
      T vl = _query(a,b,k*2+1,l,(l+r)/2);
      T vr = _query(a,b,k*2+2,(l+r)/2,r);
      return max(vl,vr);
    
  }

  T query(int a,int b){//nの範囲でミスしないように極力こっちを利用
    return _query(a,b,0,0,n);
  }

};


 int x[1000010];
 RMQ_segment<ll> rmq;
int main(){
  int n;
  cin >> n;
 
  rmq.init(n+1);
 
  rep(i,n)cin >> x[i];
  ll mex=0;
  ll sum=0;

  for(int i=0;i<n;i++){
    sum+=x[i];
    ll premex = rmq.query(0,x[i])+x[i];
    rmq.update(x[i],premex);
    mex = max(mex,premex);
   
  }  
  
  cout << sum-mex << endl;

return 0;
}

Measured memory_bytes: 7296
#include<cstdio>
const int MAXN = 100000;
int pre[MAXN + 5], f[MAXN + 5];
int Find(int x) {
	if( pre[x] == x ) return x;
	int ret = Find(pre[x]);
	f[x] = f[x] + f[pre[x]];
	return pre[x] = ret;
}
int main() {
	int N, M;
	bool flag = true;
	scanf("%d%d",&N,&M);
	for(int i=1;i<=N;i++)
		pre[i] = i;
	for(int i=1;i<=M;i++) {
		int L, R, D;
		scanf("%d%d%d",&L,&R,&D);
		if( flag ) {
			if( Find(L) == Find(R) ) {
				if( f[R] <= f[L] ) {
					int p = f[L] - f[R];
					if( p != D ) flag = false;
				}
				else {
					flag = false;
				}
			}
			else {
				int k = Find(L);
				pre[k] = L;f[k] = -f[L];
				pre[L] = R;f[L] = D;
			}
		}
	}
	if( flag ) printf("Yes\n");
	else printf("No\n");
}


Measured memory_bytes: 896
#include<iostream>
#include<string>
#include<algorithm>
#define REP(i, n) for(int i = 0; i < n; ++i)
using namespace std;

int main()
{
    char S[3];
    cin >> S;
    int price = 700;
    REP(i, 3){
        if (S[i] == 'o') price += 100;
    }
    cout << price << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
const LL mod=1e9+7;
LL fac[200010],inv[200010];
void pre()
{
	inv[0]=inv[1]=fac[0]=fac[1]=1;
	for(LL i=2;i<=200000;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
	for(LL i=2;i<=200000;i++) inv[i]=inv[i-1]*inv[i]%mod,fac[i]=fac[i-1]*i%mod;
}
LL C(LL m,LL n) {return fac[m]*inv[m-n]%mod*inv[n]%mod;}
LL n,m,k,f[3010];
struct node{LL x,y;}a[3010];
bool cmp(node a,node b) {return a.x==b.x?a.y<b.y:a.x<b.x;}
int main()
{
	pre();
	scanf("%lld %lld %lld",&n,&m,&k);
	for(LL i=1;i<=k;i++)
	{
		scanf("%lld %lld",&a[i].x,&a[i].y);
		if((a[i].x==1&&a[i].y==1)||(a[i].x==n&&a[i].y==m)) return puts("0"),0;
	}
	a[++k].x=n;a[k].y=m;
	sort(a+1,a+k+1,cmp);
	for(LL i=1;i<=k;i++)
	{
		f[i]=C(a[i].x+a[i].y-2,a[i].x-1);
		for(LL j=1;j<i;j++)
			if(a[j].x<=a[i].x&&a[j].y<=a[i].y)
			{
				LL x=a[i].x-a[j].x,y=a[i].y-a[j].y;
				(f[i]-=f[j]*C(x+y,x))%=mod;
			}
		//printf("%lld %lld %lld\n",a[i].x,a[i].y,f[i]);
	}
	printf("%lld",(f[k]+mod)%mod);
}

Measured memory_bytes: 3456
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 210000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long C(int a,int b){
	if(a<b||b<0)return 0;
	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
// ここから編集しろ
int p[110000];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++){
		scanf("%d",p+i);
	}
	std::sort(p,p+a);
	if(a%3){
		if(p[a-1]==0)printf("Yes\n");
		else printf("No\n");return 0;
	}
	int A=p[0];
	int B=p[a/3];
	int C=p[a/3*2];
	for(int i=0;i<a;i++){
		if(i<a/3){
			if(p[i]!=A){printf("No\n");return 0;}
		}
		else if(i<a/3*2){
			if(p[i]!=B){printf("No\n");return 0;}
		}
		else{
			if(p[i]!=C){printf("No\n");return 0;}
		}
		
	}
	if((A^B)!=C){
		printf("No\n");return 0;
	}
	printf("Yes\n");
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(t) for(ll i=0;i<t;i++)
#define ll long long int
#define ld long double
#define umpl unordered_map<ll,ll> 
#define vl vector<ll>
#define vld vector<ld>
#define vvl vector<vl>
#define pb push_back
#define mod 1000000007
#define inf 1e18
#define pcout(x,p) cout<<fixed<<setprecision(p)<<x
#define all(a) a.begin(),a.end()
#define endl "\n"

inline ll mul(ll a, ll b){ return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c >= mod) c -= mod; return c; }
inline ll max(ll a, ll b){return a>b?a:b;}
inline ll min(ll a, ll b){return a<b?a:b;}
inline ll ceil(ll a,ll b){if(a%b==0)return a/b;else return a/b+1;}
inline ll mo(ll a,ll b){if(b<0){b=abs(b)%mod;b=a-b;return (b<0)?b+mod:b;}else{return (a+b)%mod;}}
inline ll pow(ll a,ll b){if(b==0){return 1;}else{if(b%2==0){ll temp=pow(a,b/2);return temp*temp;}
else{return a*pow(a,b-1);}}}

struct comp { 
    template<class T1,class T2,class T3,class T4>
    bool operator()(const pair<T1,T2> &p1,const pair<T3,T4> &p2){
        if(p1.first!=p2.first)return p1.first<p2.first;
        else return p1.second<p2.second;
    }
}; 

int main()
{
    fio;
    ll n,k;cin>>n>>k;
    vl a(n);
    f(n)cin>>a[i];
    vl dp(n,inf);
    dp[0]=0;
    for(ll i=1;i<n;i++){
        for(ll j=i-1;j>=max(0,i-k);j--){
            dp[i]=min(dp[i],abs(a[i]-a[j])+dp[j]);
        }
    }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 4740
#include <cstdio>
using namespace std;

int main() {
	char number;
	int sum = 0;
	bool end_loop=0;
	while (1) {
		for (int i = 0; i < 1005;i++) {
			(void)scanf("%c", &number);
			if (i == 0 && number == '0') {
				end_loop = 1;
				break;
			}
			if (number == '\n') break;
			sum += number - '0';
		}
		if (end_loop == 1) break;
		printf("%d\n", sum);
		sum = 0;
	}
	return 0;
}


Measured memory_bytes: 2592
#include <bits/stdc++.h>
using namespace std;
 
#define froop1(a,n) for(int i = a;i < n;i++)
#define froop2(a,n) for(int i = a;i > n;i--)
int main(){
	int a,b,c;
  cin >> a >> b >> c;
  cout << c << " " << a << " " << b << endl;
}

Measured memory_bytes: 3524
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include<math.h>
int main(){
    int n,cnt=0,cnt1=0;
    int k,l,e=0;
    scanf("%d",&n);
    char s[n],a[n/2],b[n/2];
    scanf("%s",&s);
      if(n%2!=0)
        printf("No");
    for(int k=0; k<n; k++){
    if(s[k]>='A' && s[k]<='Z'){
       cnt1++;}
    }
    if(cnt1==0){
    if(n%2==0){
    for(int i=0;i<n/2;i++){
        a[i]=s[i];}
    for(int j=n/2;j<n;j++){
        b[e++]=s[j];}

    for(k=0,l=0;k<n/2,l<n/2;k++,l++){
    if(a[k]==b[l])
        cnt++;
    else
        cnt=0;}
    if(cnt==n/2)
        printf("Yes");
    else
        printf("No");}}
    if(n%2==0 && cnt1>0)
        printf("No");
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
int A, B, C, D;
int main(void){
    std::cin >> A >> B >> C >> D;
    std::vector<bool> AB(101, false);
    for(int i=A; i<=B; ++i){
        AB[i] = true;
    }
    int cnt = 0;
    for(int i=C; i<=D; ++i){
        if(AB[i]){
            cnt++;
        }
    }
    std::cout <<  std::max(cnt-1, 0) << std::endl;
}


Measured memory_bytes: 256
//#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>

using namespace std;

typedef pair<long long, long long> pl;

long long N, M, k, a, b, c, d, e, H, W,X;
long long A[200000] = {};
long long B[20000] = {};
long long C[20000] = {};
bool f;
bool ff;
string S, SS;
set <long long>sll;
pl buf;
vector <long long>vl;


int main() {

	cin >> a>>b>>c;

	c /= a;;

	d =c*b;

	cout << d << endl;

	return 0;
}

Measured memory_bytes: 256
//
/*==========================================================*/
/*    Template ver 2017-0720    |    Created by JollyBee    */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
const double EPS=(double)1e-9;
const double PI=(double)acos(-1.0);
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define FOR(i,n) for(int i=0;i<n;i++)
#define REPP(i,l,r,c) for(int i=l;i<=r;i+=c)
#define REP(i,l,r) REPP(i,l,r,1)
#define FORD(i,n) for(int i=n-1;i>=0;i--)
#define REVV(i,l,r,c) for(int i=l;i>=r;i-=c)
#define REV(i,l,r) REVV(i,l,r,1)
//random
int irand(int lo, int hi){
    return (((double)rand())/(RAND_MAX+1.0)) * (hi-lo+1) + lo;
}
//ll to string
string toString(ll x) {
    stringstream ss;
    ss << x;
    return ss.str();
}
//string to ll
ll toNumber(string S) {
    ll ret;
    sscanf(S.c_str(),"%lld",&ret);
    return ret;
}
// std::fill(start, end, value);
// for(auto it: DS){}

const int INF=(int)2e9;
const ll MOD=(ll)1e9+7;
/*==========================================================*/
/*                     END OF TEMPLATE                      */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/

const int OFFS = 100;

int main(){
    // reset
    int ret[2*OFFS+5];
    FOR(i,2*OFFS+3) ret[i] = 0;
    // input
    int n; scanf("%d", &n);
    REP(i,1,n){
        int a; scanf("%d", &a);
        REP(to,-OFFS,OFFS) ret[to+OFFS] += (a-to) * (a-to);
    }
    int res = INF;
    REP(i,-OFFS,OFFS) res = min(res, ret[i+OFFS]);
    // print
    printf("%d\n", res);
    return 0;
}


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

int main(){
 int n;
 cin>>n;
 int W;
 cin>>W;
 int v[n];
 int w[n];
 for(int i=0;i<n;i++){
     cin>>v[i]>>w[i];
 }   

 int DP[n+1][W+1];
 for(int i=0;i<=W;i++){
     DP[0][i]=0;
 }

 for(int i=1;i<=n;i++){
     for(int j=0;j<=W;j++){
         if(j<w[i-1]) DP[i][j]=DP[i-1][j];
         else{
             if(DP[i-1][j]>DP[i-1][j-w[i-1]]+v[i-1]) DP[i][j]=DP[i-1][j];
             else DP[i][j]=DP[i-1][j-w[i-1]]+v[i-1];
         }
     }
 }
 cout<<DP[n][W]<<endl;

 return 0;
}


Measured memory_bytes: 7028
N,M = map(int,input().split())
L = []
R = []
for _ in range(M):
    a,b = map(int,input().split())
    L.append(a)
    R.append(b)

if min(R) - max(L) >= 0:
    print(min(R) - max(L) + 1)
else:
    print(0)

Measured memory_bytes: 81248
k = 1
while n = gets.to_i
  break if n == 0
  p = []
  n.times{ p << gets.split.map(&:to_f) }
  n.times{ |i| p[i] += p[(i+1) % n] }
  s = p.map{ |x0, x1, y0, y1| x1*y0 - x0*y1 }.inject(:+) / 2
  puts "#{k} %.1f" % s
  k += 1
  gets
end

Measured memory_bytes: 8788
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef pair<int,int> P;
typedef long long int ll;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}


int main() {
    int n;
    cin >> n;
    int a[n];
    int sum = 0;
    rep(i,n){
        cin >> a[i];
        sum += abs(a[i]);
    }
    sort(a,a+n);
    if(0<=a[0]){
        sum -= a[0]*2;
        cout << sum << endl;
        srep(i,1,n-1){
            cout << a[0] << ' ' << a[i] << endl;
            a[0] -= a[i];
        }
        cout << a[n-1] << ' ' << a[0] << endl;
        return 0;
    }

    if(a[n-1]<=0){
        sum -= abs(a[n-1]) * 2;
        cout << sum << endl;
        rep(i,n-1){
            cout << a[n-1] << ' ' << a[i] << endl;
            a[n-1] -= a[i];
        }
        return 0;
    }

    cout << sum << endl;

    srep(i,1,n-1){
        if(a[i]<0){
            cout << a[n-1] << ' ' << a[i] << endl;
            a[n-1] -= a[i];
        }else{
            cout << a[0] << ' ' << a[i] << endl;
            a[0] -= a[i];
        }
    }
    cout << a[n-1] << ' ' << a[0] << endl;


    return 0;
}
 
 


Measured memory_bytes: 2304
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int a[110000];
int main()
{
	int s = 0, n, k;
	scanf("%d %d", &n, &k);
	int i;
	for (i = 0; i<n; i++)
		scanf("%d", &a[i]);
	int l; l = n;
	while (l>1)
	{
		l = l - k + 1;
		s++;
	}
	printf("%d\n", s);
	getchar(); getchar();
	return 0;
}


Measured memory_bytes: 640
import sys, math
from functools import lru_cache
import numpy as np
from collections import defaultdict
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    N = ii()
    S = [input() for i in range(N)]

    k = sum(S[i].count('AB') for i in range(N))

    c = sum(1 for i in range(N) if S[i][-1] == 'A' and S[i][0] == 'B')
    a = sum(1 for i in range(N) if S[i][-1] == 'A') - c
    b = sum(1 for i in range(N) if S[i][0] == 'B') - c

    ans = k+c+min(a,b)
    if c > 0 and a == b == 0:
        ans -= 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 27428
# @author 

import sys

class FLCS:
    def solve(self):
        s = input()
        t = input()
        n = len(s)
        m = len(t)
        dp = [[0] * (m + 1) for _ in range(n + 1)]
        dp[0][0] = 0
        for i in range(1, n + 1):
            for j in range(1, m + 1):
                if s[i - 1] == t[j - 1]:
                    dp[i][j] = 1 + dp[i - 1][j - 1]
                else:
                    dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])

        ans = ""
        cur = max(dp[-1])
        cur_index = -float('inf')
        for i in range(n, 0, -1):
            if cur == 0:
                break
            if cur in dp[i] and (cur not in dp[i - 1] or dp[i - 1].index(cur) >= cur_index):
                index = dp[i].index(cur)
                ans += t[index - 1]
                cur -= 1
                cur_index = index

        print(ans[::-1])

solver = FLCS()
input = sys.stdin.readline

solver.solve()


Measured memory_bytes: 112092
'use strict'

const main = (INPUT) => {
  const N = Number(INPUT.split('\n')[0].split(' ')[0])
  const K = Number(INPUT.split('\n')[0].split(' ')[1])

  if ((N + 1) / 2 >= K) {
    console.log('YES')
  } else {
    console.log('NO')
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7372
def main():
    n,t = map(int, input().split())
    star = [list(map(str,input().split())) for i in range(n)]
    ans = []
    for i in range(n-1):
        a = list(map(int,star[i][2].split(":")))
        b = list(map(int,star[i+1][0].split(":")))
        ai = a[0]*60+a[1]
        bi = b[0]*60+b[1]
        x = bi-ai
        if x >= t:
            ans.append((star[i][3],x))
    print(len(ans))
    for a,b in ans:
        print(a,b)

main()



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

int main() {
  int n;
  cin >> n;
  
  int is_four = 0;
  int i = 0;
  while (i < n) {
    char color;
    cin >> color;
    if (color == 'Y')
      is_four = 1;
    i++;
  }
  if(is_four)
    cout << "Four" << endl;
  else
    cout << "Three" << endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
const Int MOD = 998244353;
Int modpow(Int x, Int y) {
    if (y == 0) return 1;
    if (y % 2 == 0) return modpow(x*x%MOD, y/2);
    return x*modpow(x, y-1)%MOD;
}
void fail() {
    cout << 0 << endl;
    exit(0);
}
int main() {
    int N; cin >> N;
    vector<int> A(N);
    int amax = 0;
    for (int i = 0; i < N; i++) {
        int d; cin >> d; A[d]++;
        amax = max(amax, d);
        if (i == 0 && d != 0) fail();
        if (i != 0 && d == 0) fail();
    }
    Int ans = 1;
    for (int i = 1; i <= amax; i++) {
        ans = ans * modpow(A[i - 1], A[i]) % MOD;
    }
    for (int i = 0; i <= amax; i++) if (A[i] == 0) ans = 0;
    cout << ans << endl;
    return 0;
}


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

int main()
{
    int K, A, B;
    cin >> K >> A >> B;

    for (int i = A; i <= B; i++) {
        if (i % K == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  string S;
  cin >> S;
  map<char, long> mp;
  for (auto it: S) mp[it]++;
  for (auto it: mp) {
    if (it.second != 2) {
      cout << "No" << endl;
      return;
    }
  }
  cout << "Yes" << endl;
}

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


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

#include <algorithm>
#include <cstdio>
#include <functional>
#include <vector>

using namespace std;

typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define lim 100010
#define mod 1e9 + 7
#define INF 1e9
#define REP(i, n) for (int i = 0; i < n; i++)

ll GCD(int x, int y) { return x % y == 0 ? y : GCD(y, x % y); }

int N, K, R, S, P;
char T[lim];

int point(int k) {
  int p_r = 0, p_s = 0, p_p = 0;

  for (int i = k; i <= N; i += K) {
    if (T[i] == 'r') {  //相手がグー
      int tmp = p_p;
      p_p = p_r > p_s ? p_r + P : p_s + P;
      p_r = tmp;
      p_s = tmp;
    }
    if (T[i] == 's') {  //相手がチョキ
      int tmp = p_r;
      p_r = p_p > p_s ? p_p + R : p_s + R;
      p_p = tmp;
      p_s = tmp;
    }
    if (T[i] == 'p') {  //相手がパー
      int tmp = p_s;
      p_s = p_r > p_p ? p_r + S : p_p + S;
      p_r = tmp;
      p_p = tmp;
    }
  }
  int ans = p_r;
  ans = ans > p_s ? ans : p_s;
  ans = ans > p_p ? ans : p_p;
  return ans;
}

int main() {
  scanf("%d%d", &N, &K);
  scanf("%d%d%d", &R, &S, &P);
  scanf("%s", T);

  int ans = 0;
  for (int i = 0; i < K; i++) {
    ans += point(i);
  }
  printf("%d", ans);

  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
#define inf 100000000000000000
#define mod 1000000007
#define ld long double
#define point complex<long double>
#define pi  acos(-1)
#define IO                    \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);                    \
	cout.tie(NULL);
using namespace std;
 
int main(){
	string s;
	cin>>s;
	ll resa=0;
	ll resb=0;
	for(int i=0;i<s.size();i++)
	{
		if(i%2==0)
		{
			if(s[i]=='0')resa++;
			else resb++;
		}
		else 
		{
			if(s[i]=='1')resa++;
			else resb++;
		}
	}
	cout<< min(s.size()-resa,s.size()-resb);
return 0;
}

Measured memory_bytes: 3756
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define ll long long
using namespace std;
const int ma=1e9+7;
int a[100001],n;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int j;scanf("%d",&j);
		a[j]++;
	}
	if((n&1)&&a[0]!=1) {
		printf("0\n");return 0;
	}
	for(int i=1;i<=n;i++)
	{
		if((n&1)&&(i&1)) continue;
		if(!(n&1)&&!(i&1)) continue; 
		if(a[i]!=2) {
			printf("0\n");return 0;
		}
	}
	ll p=1;
	for(int i=1;i<=(n>>1);i++)
	{
		p<<=1;p%=ma;
	}
	printf("%lld",p);
	return 0;
}


Measured memory_bytes: 640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        KStones solver = new KStones();
        solver.solve(1, in, out);
        out.close();
    }

    static class KStones {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }
            boolean[] f = new boolean[k + 1];

            for (int i = 0; i <= k; i++) {
                if (i < a[0]) {
                    f[i] = false;
                } else {
                    boolean g = true;
                    for (int j = 0; j < n; j++) {
                        if (i - a[j] >= 0) {
                            g = g && f[i - a[j]];
                        }
                    }
                    f[i] = !g;
                }
            }

            out.println(f[k] ? "First" : "Second");
        }

    }
}



Measured memory_bytes: 22228
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int A = scan.nextInt();
		int B = scan.nextInt();
		int C = scan.nextInt();

		if(C>=A && C<=B){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}

	}

}


Measured memory_bytes: 21972
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <queue>
#include <map>
#include <set>
using namespace std;
using ll = long long;
const int INF = 1 << 30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << p.first << " " << p.second;
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    for (int i = 0; i < (int)v.size(); i++)
        os << v[i] << (i + 1 != v.size() ? " " : "");
    return os;
}

void solve()
{
    int n;
    cin >> n;
    set<string> st;
    for (int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        st.insert(s);
    }
    cout << st.size() << endl;
}

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

Measured memory_bytes: 19280
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    std::ios::sync_with_stdio(false);

    int k;
    while (cin >> k) {
        int a = 1, b = 1, c = 2, d = 1;
        while (a + 2 <= k) {
            a += 2;
            b++;
            continue;
        }
        while (c + 2 <= k) {
            c += 2;
            d++;
            
        }
        cout << b*d << endl;
    }
}


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

int main() 
{
    ll n;
    cin >> n;
    vector<ll> v;
    for (ll i=0; i<n; i++)
    {
        ll a;
        cin >> a;
        v.push_back(a-i-1);
    }
    sort(v.begin(), v.end());
    ll d = n/2;
    ll sum = 0;
    for (ll i=0; i<n; i++)
        sum += abs(v[i]-v[d]);
    cout << sum;
    return 0;
}

Measured memory_bytes: 2420
S = input()

candidate_string_list = ['dream', 'dreamer', 'erase', 'eraser']
candidate_string_list_reverse = [elem[::-1] for elem in candidate_string_list]

buffer = ''
for character in S[::-1]:
    buffer += character
    if buffer in candidate_string_list_reverse:
        buffer = ''
        continue

if buffer == '':
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3188
coins = [int(input()) for c in range(4)]
x = coins[3]
ans = 0
for i in range(coins[0]+1):
	for j in range(coins[1]+1):
		for l in range(coins[2]+1):
			if (i*500) + (j * 100) + (l * 50) == x:
				ans += 1

print(ans)

Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define N 100010
#define ll long long

template<typename tp> inline void read(tp &x){
    x=0;register char c=getchar();register bool f=0;
    for(;c<'0'||c>'9';f|=(c=='-'),c=getchar());
    for(;c>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0',c=getchar());
    x=f?-x:x;
}
int d[N << 1];
int n;
ll ans = 0;
int main() {
    read(n);
    int a, b;
    read(a), read(b);
    ll ans2 = a, ans3 = b;
    for (int i = 1; i < n; ++i) {
        read(d[i << 1]);
        ans2 += d[i << 1];
        read(d[(i << 1) - 1]);
        ans3 += d[(i << 1) - 1];
        if (max(d[i << 1], d[(i << 1) - 1]) < max(a, b)) {
            swap(a, d[i << 1]);
            swap(b, d[(i << 1) - 1]);
        }
    }
    sort(d + 1, d + n * 2 - 1);
    for (int i = 1; i < n - 1; ++i) ans += d[i];
    ans += min(a + b, d[n] + d[n-1]);
    printf("%lld\n", min(ans, min(ans2, ans3)));
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
typedef pair<char,P>P2;
#define F first
#define S second

char a[200007],t[200007];
string s;
int m,n;

bool chL(int x){
    int idx=x;
    r(i,m){
        if(a[i]!=s[idx])continue;
        if(t[i]=='L')idx--;
        else idx++;
        if(idx<0)return 1;
    }
    return 0;
}

int L(){
    int l=-1,r=n;
    while(r-l>1){
        int mid=(l+r)/2;
        if(chL(mid))l=mid;
        else r=mid;
    }
    return l;
}

bool chR(int x){
    int idx=x;
    r(i,m){
        if(a[i]!=s[idx])continue;
        if(t[i]=='L')idx--;
        else idx++;
        if(n<=idx)return 1;
    }
    return 0;
}

int R(){
    int l=-1,r=n;
    while(r-l>1){
        int mid=(l+r)/2;
        if(chR(mid))r=mid;
        else l=mid;
    }
    return r;
}

signed main(){
    cin>>n>>m;
    cin>>s;
    r(i,m)cin>>a[i]>>t[i];

    int A=L();
    int B=R();

    //cout<<A<<' '<<B<<endl;
    A++;
    B=n-B;

    cout<<n-min(n,A+B)<<endl;
}

Measured memory_bytes: 900
package main

import "fmt"

func main() {
	var n int
	var a []int

	fmt.Scan(&n)
	for i := 0; i < n-1; i++ {
		var tmp int
		fmt.Scan(&tmp)
		a = append(a, tmp)
	}

	m := make(map[int]int)
	for i := 0; i < n-1; i++ {
		m[a[i]]++
	}
	for i := 1; i < n+1; i++ {
		if v, ok := m[i]; ok {
			fmt.Println(v)
		} else {
			fmt.Println(0)
		}
	}
}


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

#define reps(i,j,k) for(int i=(j);i<(k);i++)
#define rep(i,j) reps(i,0,j)
#define pb push_back

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main(){
	int m, ni,na;
	while(cin >> m >> ni >> na, m){
		vi p(m);
		rep(i,m){
			cin >> p[i];
		}
		int ans = -1, gap = -1;
		reps(i, ni, na+1){
			int g = p[i-1] - p[i];
			if(gap <= g){
			  ans = i;
			  gap = g;
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3084
#include<iostream>

int main() {
  std::string s;
  std::cin >> s;
  std::string subS = "";
  int maxlen = 0;
  for(int i = 0; i < s.length(); i++) {
    
    switch(s.at(i)) {
    case 'A':
    case 'G':
    case 'C':
    case 'T':
      subS += s.at(i);
      break;
    default:
      if(subS.length() > maxlen) maxlen = subS.length();
      subS = "";
      break;
    }
  }
  if(subS.length() > maxlen) maxlen = subS.length();
  std::cout << maxlen << std::endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <cmath>

intmax_t f(intmax_t b, intmax_t n) {
  if (n < b)
    return n;

  return f(b, n/b) + n%b;
}

int main() {
  intmax_t n, s;
  scanf("%jd %jd", &n, &s);

  if (s == n)
    return !printf("%jd\n", n+1);

  intmax_t sqrtn=sqrt(n);
  for (intmax_t b=2; b<=sqrtn; ++b)
    if (f(b, n) == s)
      return !printf("%jd\n", b);

  for (intmax_t p=sqrtn; p>0; --p) {
    intmax_t b=(n-s)/p+1;
    if (b < 2) continue;
    if (f(b, n) == s)
      return !printf("%jd\n", b);
  }

  printf("-1\n");
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;



class Program
{
    const int MOD = 1000000007;
    const int INF = 1 << 30;

    static void Main(string[] args)
    {
        Solve();
    }




    static void Solve()
    {
        Scan sc = new Scan();
        write wr = new write();

        var x = sc.intarr;
        wr.wri(x.Max() - x.Min());
    }
}
    




class Scan
{
        public string str => Console.ReadLine();

        public string[] strarr => str.Split(' ');

        public long[] longarr => strarr.Select(long.Parse).ToArray();
        public int[] intarr => strarr.Select(int.Parse).ToArray();
    public char[] chararr => str.ToArray();


}



class write
{
    public void wri<Type>(Type x)
    {
        Console.WriteLine(x);
    }
}


Measured memory_bytes: 13396
#include<stdio.h>
#define N 101
#define WHITE -1
#define GRAY 0
#define BRACK 1
int G[N][N] = {}, n, time;
int d[N] = {}, f[N] = {}, color[N];

void DFSvisit(int u){
  int i;
  color[u] = GRAY;
  d[u] = ++time;
  for(i = 1; i <= n; i++){
      if(G[u][i] == 1){
        if(color[i] == WHITE) DFSvisit(i);
      }
  }
  color[u] = BRACK;
  f[u] = ++time;
}

void DFS(void){
  int i, j;
  for(i = 1; i <= n; i++){
        color[i] = WHITE;
        time = 0;
  }
  for(i = 1; i <= n; i++){
        if(color[i] == WHITE) DFSvisit(i);
  }
}

int main(){
  int u, k, v, i, j;
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d%d", &u, &k);
    for(j = 0; j < k; j++){
      scanf("%d", &v);
      G[u][v] = 1;
    }
  }
  DFS();
  for(i = 1; i <= n; i++){
    printf("%d %d %d\n", i, d[i], f[i]);
  }
  return 0;
}

Measured memory_bytes: 636
import java.io.*;
import java.util.*;

public class Main {
	FastScanner in;
	PrintWriter out;

	void solve() {
		int n = in.nextInt();
		char[][] a = new char[n][];
		for (int i = 0; i < n; i++) {
			a[i] = in.next().toCharArray();
		}
		boolean full = true;
		boolean empty = true;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (a[i][j] == '.') {
					full = false;
				} else {
					empty = false;
				}
			}
		}
		if (empty) {
			out.println(-1);
			return;
		}
		if (full) {
			out.println(0);
			return;
		}
		int res = Integer.MAX_VALUE;
		for (int r = 0; r < n; r++) {
			boolean ok = false;
			for (int i = 0; i < n; i++) {
				if (a[i][r] == '#') {
					ok = true;
				}
			}
			int cnt = ok ? 0 : 1;
			for (int i = 0; i < n; i++) {
				if (a[r][i] == '.') {
					cnt++;
				}
			}
			for (int c = 0; c < n; c++) {
				boolean ok2 = true;
				for (int i = 0; i < n; i++) {
					if (a[i][c] == '.') {
						ok2 = false;
					}
				}
				if (!ok2) {
					cnt++;
				}
			}
			res = Math.min(res, cnt);

		}
		out.println(res == Integer.MAX_VALUE ? -1 : res);
	}

	void run() {
		try {
			in = new FastScanner(new File("object.in"));
			out = new PrintWriter(new File("object.out"));

			solve();

			out.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

	void runIO() {

		in = new FastScanner(System.in);
		out = new PrintWriter(System.out);

		solve();

		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		public FastScanner(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return null;
				st = new StringTokenizer(s);
			}
			return st.nextToken();
		}

		boolean hasMoreTokens() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return false;
				st = new StringTokenizer(s);
			}
			return true;
		}

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

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

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

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

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

int main(){
string s;
  cin>>s;
  if(s.at(0)==s.at(1)){
    if(s.at(2)==s.at(3)&&s.at(2)!=s.at(0))
      cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
  }
else if(s.at(0)==s.at(2)){
if(s.at(1)==s.at(3)&&s.at(1)!=s.at(0))
  cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}
  else if(s.at(0)==s.at(3)){
if(s.at(1)==s.at(2)&&s.at(1)!=s.at(0))
  cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}
  else
    cout<<"No"<<endl;
}


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

int main(int argc, char const* argv[])
{
    int N;
    cin >> N;
    int P[N];
    for (int i = 0; i < N; i++) {
        cin >> P[i];
    }

    int m = 2 * 100000 + 1;
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        if (m >= P[i]) {
            cnt++;
            m = P[i];
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<ll> > Graph;
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; }
const ll INF = 1e18;

int main(){
    ll n;
    cin >> n;
    vector<ll>c(5,0);
    rep(i,n){
        string s;
        cin >> s;
        if(s=="AC"){
            c[0]++;
        }
        else if(s=="WA"){
            c[1]++;
        }
        else if(s=="TLE"){
            c[2]++;
        }
        else if(s=="RE"){
            c[3]++;
        }
    }
    printf("AC x %d\n",c[0]);
    printf("WA x %d\n",c[1]);
    printf("TLE x %d\n",c[2]);
    printf("RE x %d\n",c[3]);

    
    return 0;
}


Measured memory_bytes: 3720
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;

	public static void Main(string[] args)
	{
		var p = Input();
		var w = p[0].ToLong();
		var h = p[1].ToLong();
		var x = p[2].ToLong();
		var y = p[3].ToLong();
		
		Console.WriteLine("{0} {1}", w * h / 2.0, ((w / 2.0) == (double)x && (h / 2.0 == (double)y)) ? 1 : 0);
	}

	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}


Measured memory_bytes: 13140
n,a,b,c = map(int,input().split())
l = [int(input()) for i in range(n)]
def dfs(cnt,A,B,C):
    if cnt == n:
        if min(A,B,C) == 0:
            return float('inf')
        else:
            return abs(a-A)+abs(b-B)+abs(c-C)-30
    else:
        ret1 = dfs(cnt+1,A+l[cnt],B,C)+10
        ret2 = dfs(cnt+1,A,B+l[cnt],C)+10
        ret3 = dfs(cnt+1,A,B,C+l[cnt])+10
        ret4 = dfs(cnt+1,A,B,C)
        return min(ret1,ret2,ret3,ret4)
print(dfs(0,0,0,0))

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<deque>
#include<map>
using namespace std;
typedef long long ll;

int main() {
    int n, m; cin >> n >> m;
    priority_queue<int, vector<int>, greater<int>> que;
    ll ans = 0;
    for (int i = 0; i < n; i++)
    {
        int a; cin >> a;
        que.push(a);
        ans += a;
    }

    vector<pair<int, int>> bc(m);
    for (int i = 0; i < m; i++)
    {
        int b, c; cin >> b >> c;
        bc[i] = make_pair(c, b);
    }
    sort(bc.begin(), bc.end(), greater<pair<int, int>>());
    
    
    for (int i = 0; i < m; i++)
    {
        int b, c;
        c = bc[i].first;
        b = bc[i].second;
        for (int j = 0; j < b; j++)
        {
            int tmp = que.top();
            if (tmp < c) {
                que.pop();
                que.push(c);
                ans -= tmp;
                ans += c;
            } else {
                break;
            }
        }
        
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1528
#include "bits/stdc++.h"

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

using namespace std;
const long long MOD = 1000000007;

long long gcd(long long a, long long b) {
    if (a % b == 0)return(b);
    else return(gcd(b, a % b));
}

long long modPow(int n, int num) {
    if (num == 0) return 1;
    long long res = modPow(n, num / 2);
    if (num % 2 == 0) res = (res * res) % MOD;
    else res = (((res * res) % MOD) * n) % MOD;
    return res;
}

int main() {
    int N; cin >> N;
    vector<long long> A(N), B(N);
    rep(i, N)cin >> A[i] >> B[i];
    // 傾きが対になっているペアを保存
    map<pair<long long, long long>, pair<int, int>> mp;

    // (0, 0)の数
    int zero = 0;
    rep(i, N) {
        if (A[i] == 0 && B[i] == 0)++zero;
        else if (A[i] == 0)++mp[make_pair(1, 0)].second;
        else if (B[i] == 0)++mp[make_pair(1, 0)].first;
        else {
            // gcdは正の数を引数に渡した方が良さそうか
            long long g = gcd(A[i], B[i]);
            A[i] /= g;
            B[i] /= g;
            if (B[i] < 0) {
                A[i] = -A[i];
                B[i] = -B[i];
            }
            if (A[i] > 0)++mp[make_pair(A[i], B[i])].first;
            else ++mp[make_pair(B[i], -A[i])].second;
        }
    }

    long long ans = 1;
    for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
        int p1 = itr->second.first;
        int p2 = itr->second.second;
        ans *= (modPow(2, p1) - 1 + modPow(2, p2)) % MOD;
        ans %= MOD;
    }
    // すべてのイワシを選ばなかった場合を除く
    cout << (ans - 1 + MOD + (long long)zero) % MOD;
}

Measured memory_bytes: 18744
while True:
    num = int(input())
    if num == 0:
        break
    else:
        sigma = 0
        score = list(map(int, input().split(" ")))
        mean = sum(score) / num
        for i in range(num):
            sigma += (score[i] - mean) ** 2
        alfa = (sigma / num) ** 0.5
        print(round(alfa, 8))


Measured memory_bytes: 5672
function main(input) {
  var num = input.split("\n");

  num.slice(0, num.length - 1).forEach(function(value) {
    var a = value.split(" ");
    var num = (parseInt(a[0]) + parseInt(a[1]));
    console.log(String(num).length);
  });
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 16044
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<vector>
#include<cmath>
#include<algorithm>
#define rep(i, a, b) for(int i=a; i<b; i++)
#define rrep(i, a, b) for(int i=b-1; i>=a; i--)
#define REP(i, n) for(int i=0; i<n; i++)
#define rREP(i, n) for(int i=n-1; i>=0; i--)
#define MAX 101
typedef long long ll;
using namespace std;

int main(void){
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.rbegin(), t.rend());
  if(s<t) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
//  RAKSHIT KADAM
//ALWAYS USE &IT FOR ITERATING USING AUTO ...
//USE COUNT(STARTING ADDRESS, ENDING ADRESS ,VALUE) FOR FINDING THE COUNT IN THE RESPECTIVE DATA STRUCTURE
//NOTE THAT MEMSET CANT FILL THE DOUBLE VALUES;
//ACCUMULATE DOES NOT WORK PROPERLY IF VALUES START SUMMING BEYOND 1E9...
 #include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree< int ,  null_type ,  less<int> ,  rb_tree_tag ,  tree_order_statistics_node_update>
#warning !!!check the size of arrayss!!!
 
// NUMERIC DEFINITIONS :
    #define INF 1000000000000000005
    #define inf 1000000037
    #define MOD  1000000007
    #define newMOD  998244353
    #define MAX 300006
    #define pi 3.1415926535897932384626433832795
#define ld long double
                         #define ll long long
                         #define int long long
//  #define ll int
 #define P(gg) for(auto rax:gg){cout<<rax<<" ";}cout<<endl;
 #define Need_for_speed(activated) ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
 #define satisfy ll t; cin>> t; while(t--)
 #define inp(n) int n;cin >> n
 #define mp make_pair
 #define pb push_back
 #define endl "\n"
 #define x first
 #define y second
 #define fore(i,a,b) for(ll i=a;i<b;i++)
 #define forci(i,n) for(ll i=0;i<n;i++)
 #define vi vector<ll>
 #define Endl endl
 #define lb lower_bound
 #define ub upper_bound
#define pii pair<ll,ll>
 
 #define input freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout)
// #define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;
 
ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}
int power(int x, unsigned int y, unsigned int m){ if (y == 0) return 1;int p = power(x, y/2, m) % m;  p = (p * p) % m;return (y%2 == 0)? p : (x * p) % m;}
ll modInverse(int a, int m){{ return power(a, m-2, m);}}
const int maxn =500003;


void solve()
{
    ll n;cin>>n;
    ll a[n];
    ll sum =0;ll x,y;
    ll f[maxn]={0};
    for(ll i=0;i<n;i++)
    {cin>>a[i];sum+=a[i];f[a[i]]++;}
    ll q;cin>>q;
    while(q--)
    {
        cin>>x>>y;
        sum+=f[x]*(y-x);
        f[y]+=f[x];
        f[x]=0;
        cout<<sum<<endl;
    }
}
 
signed main()
{
   Need_for_speed(activated);
    
   
//satisfy
//    {
//  solve();
//   }
    solve();
    
    return 0;
}
 


Measured memory_bytes: 8352
#include "bits/stdc++.h"

using namespace std;

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 10;
//const ll INF = 1e18 + 10LL;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
const double EPS = 1e-10;
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)

bool can = true;
int n;
int p[60], sp[60];

int main(void){
	cin>>n;
	for (int i = 0; i < n; i++) {
		cin>>p[i];
		sp[i] = p[i];
	}

	sort(sp, sp + n);

	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (sp[i] != p[i]) cnt++;
	}

	if (cnt == 2 || cnt == 0) printf("YES\n");
	else printf("NO\n");
	
	return 0;
}

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

int main() {
  int64_t n;
  std::cin >> n;
  std::vector<int64_t> a(n);
  for (int64_t i = 0; i < n; i++) {
    std::cin >> a[i];
    a[i] -= i + 1;
  }
  std::sort(std::begin(a), std::end(a));

  int64_t sum = 0;
  const auto dif = a[n / 2];
  for (const auto i : a) {
    sum += std::abs(i - dif);
  }

  std::cout << sum << std::endl;
  return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0;i<N;i++){cin >> A[i];}
  sort(A.begin(),A.end());
  int a=A[0];
  while(1){
    int m=a;
    for(int i=0;i<N;i++){
      if(A[i]!=a){A[i]=A[i]%a; if(A[i]!=0){m=min(m,A[i]);}}
    }
    if(m==a){cout << m << endl; return 0;}
    a=m;
  }
}

Measured memory_bytes: 640