akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <deque>
#include <algorithm>

using namespace std;

int ret;
int w;

void solve(int tmpw, int c){
  //cout << "tmpw = " << tmpw << endl;
  if(c >= ret) return;
  if(tmpw == 0){
	ret = min(ret, c);
	return;
  }
  if(c+850*3*0.88 < ret && tmpw - 1500 >= 0){
	solve(tmpw-1500, c+850*3*0.88);
  }
  if(c+380*5*0.8 < ret && tmpw-1000 >= 0){
	solve(tmpw-1000, c+380*5*0.8);
  }
  if(c+550*4*0.85 < ret && tmpw-1200 >= 0){
	solve(tmpw-1200, c+550*4*0.85);
  }
  if(c+850 < ret && tmpw - 500 >= 0){
	solve(tmpw-500, c+850);
  }
  if(c+550 < ret && tmpw - 300 >= 0){
	solve(tmpw-300, c+550);
  }
  if(c+300 < ret && tmpw - 200 >= 0){
	solve(tmpw-200, c+380);
  }
  
  return;
}

int main(void){
  while(cin >> w && w){
	ret = 1 << 30;
	solve(w,0);
	cout << ret << endl;
  }
}

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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define per(i,n) for(ll i = n-1; i >= 0; i--)
#define REP(i,n) for(ll i = 1; i < n; i++)
#define PER(i,n) for(ll i = n; i >= 1; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPP = vector<vP>;
using vPl = vector<Pl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll mod = 1e9+7;

long long Modpow(long long a, int n){
  if(n == 0) return 1;
  if(n%2 == 0){
    long long res = Modpow(a, n/2);
    return res * res % mod;
  }
  return a * Modpow(a, n-1) % mod;
}

int inv(int n) { // 逆元
  return Modpow(n, mod-2);
}

struct Combination { 
  vector<long long> fact, ifact;
  Combination(int n):fact(n+1), ifact(n+1) {
    fact[0] = 1;
    for(long long i = 1; i <= n; i++) fact[i] = fact[i-1]*i % mod;
    ifact[n] = inv(fact[n]);
    for(long long i = n; i >= 1; i--) ifact[i-1] = ifact[i]*i % mod;
  }
  long long operator()(int n, int k) { // modcom (nCk % mod)
    if(k < 0 || k > n) return 0;
    return ((fact[n] * ifact[k]) % mod * ifact[n-k]) % mod;
  }
};



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

  int n, k;
  cin >> n >> k;
  vi a(n);
  rep(i,n) cin >> a[i];
  sort(all(a));
  Combination c(n-1);
  ll ans = 0;
  rep(i,n) {
    ll cnt = c(i,k-1) - c(n-i-1,k-1);
    cnt %= mod;
    ll cur = a[i] * cnt;
    cur %= mod;
    ans += cur;
    ans %= mod;
  }
  cout << ans << endl;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef long double ld;
const ld pi = 4*atan((ld)1);
const ll mod = 1e9 + 7;
const ll inf = 922337203685477;
const ll nax = 0;

ll n;
ll memo[2005];

ll dp(ll x){
	if(x == 0){
		return 1;
	}
	if(x < 3){
		return 0;
	}
	if(memo[x] != -1){
		return memo[x];
	}
	ll ret = 0;
	for(ll i = 3; i <= x; i++){
		ret += dp(x - i);
		ret %= mod;
	}
	return memo[x] = ret;
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	memset(memo, -1, sizeof(memo));
	cin >> n;
	cout << dp(n) << '\n';
}



Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define ll long long
using namespace std;
char str[60][60];
char ans[60][60];
int dx[]= {1,-1,0,0,1,1,-1,-1};
int dy[]= {0,0,-1,1,-1,1,-1,1};
int main()
{
    int h,w;
    cin>>h>>w;
    for(int i=0; i<h; i++)
        for(int j=0; j<w; j++)cin>>str[i][j];
    for(int i=0; i<h; i++)
    {

        for(int j=0; j<w; j++)
        {
            int cnt=0;
            if(str[i][j]=='.')
            {
                for(int k=0; k<8; k++)
                {
                    int row=i+dx[k];
                    int col=j+dy[k];
                    if(row>=0 && col>=0 && row<h && col<w)
                    {
                        if(str[row][col]=='#')
                        {
                            cnt++;
                        }
                    }
                }
            }
            if(str[i][j]=='.')
            {
                char ch=(cnt+'0');
                ans[i][j]=cnt+'0';
            }
            else ans[i][j]='#';
        }
    }
    for(int i=0; i<h; i++)
    {
        for(int j=0; j<w; j++)cout<<ans[i][j];
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
/**
	Language: C++
	Author  : 21
**/

#include <bits/stdc++.h>

using namespace std;

#define FastIO() ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define Debug(v) cerr << '\n' << #v << ":\t" << v << '\n'

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;

int main() {
	FastIO();
	string s,t ;
	cin >> s >> t;
	if (t.substr(0, t.size() - 1) == s) {
		cout << "Yes\n";
	} else {
		cout << "No\n";
	}
	return 0;
}


Measured memory_bytes: 3648
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int ans = 0;

    if(b + c > a){
      ans = (b + c) - a;
    }

    System.out.println(ans);
  }
}


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


 long max(long a,long b){
     return (a>=b) ? a : b ;
 }

int main(){
    int n,w;
    cin>>n>>w;
    int wt[n],v[n];
    for(int i=0;i<n;i++){
        cin>>wt[i]>>v[i];
    }
    long res[n+1][w+1];
    for(int i=0;i<=n;i++){
        for(int j=0;j<=w;j++){
            if(i==0 || j==0)
                res[i][j]=0;
            else if(wt[i-1]<=j)
                res[i][j]=max(v[i-1]+res[i-1][j-wt[i-1]],res[i-1][j]);
            else
                res[i][j]=res[i-1][j];
        }
    }
    cout<<res[n][w]<<endl;
}



Measured memory_bytes: 79104
#

import sys
input=sys.stdin.readline
MOD=10**9+7

def main():
    H,N=map(int,input().split())
    AB=[list(map(int,input().split())) for i in range(N)]
    dp=[10**9]*(H+1+10**4)
    dp[0]=0
    for i in range(H+10**4):
        for j in range(N):
            if 0<=i+AB[j][0]<=H+10**4:
                dp[i+AB[j][0]]=min(dp[i+AB[j][0]],dp[i]+AB[j][1])
    ans=10**9
    for i in range(H,H+1+10**4):
        ans=min(ans,dp[i])
    print(ans)
    
        
    
if __name__=="__main__":
    main()


Measured memory_bytes: 76876
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>

#define MOD 1e9+7;
#define INF 1e17+9;
#define PI acos(-1);

typedef long long LL;

using namespace std;

int main(){
	int s,w;
	cin >> s >> w;
	if(w>=s)cout << "unsafe" << endl;
	else cout << "safe" << endl;
	return 0;
}


Measured memory_bytes: 3596
// G++ MACRO.CPP -STD=C++14
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;

#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl

#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])

#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) if(1){for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl;}

#define ALL(obj) (obj).begin(),(obj).end()

#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define EN(x) if(1){cout<<#x<<endl;return 0;}
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template <class T = ll>
T IN(){T x;cin>>x;return (x);}

template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
  VECCIN(head);
  VT2(move(tail)...);
}

template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
  seco[head]=IN();
  VT3(head,move(tail)...);
}

#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision; // cpp_int

#define P pair<int,int>
#define V vector<ll>
#define M map<ll,ll>
#define S set<ll>

#define pb(a) push_back(a)
#define mp make_pair

int main(){
  CIN(a,b);
  if(a+b==15)EN(+);
  if(a*b==15)EN(*);
  COUT("x");

  return 0;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,p,a;
  set<int> s;
  cin>>n;
  a=n;
  while(n--)
  { 
    int a; cin>>a;
    s.insert(a);
  }
  p=s.size();
  if(p==a) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong



llong GCD(llong A[],int n){
    llong a,b,c;
    a=A[0];
    b=A[1];
    int i=1;
    while(1){
        if(a<b) swap(a,b);
        while(1){
            if(a%b==0) break;
            c=b;
            b= a%b;
            a=c;
        }
        i+=1;
        if(i==n) break;
        a=A[i];
    }
    return b;
}

signed main(){
    int n;
    cin >> n;
    int A[MAX];
    REP(i,n) scanf("%lld",&A[i]);
    cout << GCD(A,n);
}

Measured memory_bytes: 1024
s = input()
#x, y = map(int, input().split())
#in_ls = list(map(int, input().split()))
if s == "SUN":
    print(7)
elif s == "MON":
    print(6)
elif s == "TUE":
    print(5)
elif s == "WED":
    print(4)
elif s == "THU":
    print(3)
elif s == "FRI":
    print(2)
elif s == "SAT":
    print(1)




#print(a)


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


int main() {
	string S, T;
	cin >> S >> T;
	vector<int> start(26, -1);
	vector<int> goal(26, -1);
	for (int i = 0; i < S.size(); i++)
	{
		int a = S[i] - 'a';
		int b = T[i] - 'a';

		if (start[a] != -1 || goal[b] != -1) {
			if (start[a] != b || goal[b] != a) {
				cout << "No" << endl;
				return 0;
			}
		}
		else {
			start[a] = b;
			goal[b] = a;
		}
	}

	cout << "Yes" << endl;
}


Measured memory_bytes: 776
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    auto isuruu = [](int x){ return !(x%4)^!(x%100)^!(x%400);};
    int a, b, cnt = 0;
    while(cin >> a >> b, a){
        if(cnt++){
            puts("");
        }
        int ok = 0;
        for (int i = a; i <= b; ++i) {
            if(isuruu(i)) {
                ok = 1;
                cout << i << "\n";
            }
        }
        if(!ok) puts("NA");
    }
    return 0;
}


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

using namespace std;

#define FOR(i,s,e) for((i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

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

const double EPS = 1e-10;

const int INF = 1000*1000*1000;
const int N = 500000;
const int M = 20;
int n, m;
int dp[M+1][N+1];
int c[N+1];

int main() {
  int i, j, k;
  scanf("%d%d ", &n, &m);
  for (i=0; i<m; i++)
    scanf("%d ", c+i+1);

  for (i=0; i<=m; i++)
    for (j=0; j<=n; j++)
      dp[i][j] = INF;

  for (j=0; j<=n; j++)
    if (!(j%c[1])) dp[1][j] = j/c[1];

  for (i=2; i<=m; i++)
    for (j=0; j<=n; j++) {
      if (j-c[i]<0)
        dp[i][j] = dp[i-1][j];
      else
        dp[i][j] = min(dp[i-1][j], dp[i][j-c[i]]+1);
//      for (k=0; j-c[i]*k>=0; k++)
//        dp[i][j] = min(dp[i][j], dp[i-1][j-c[i]*k]+k);
    }
  printf("%d\n", dp[m][n]);

	return 0;
}

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

int main(){
  int H,N;
  cin >> H >> N;
  vector<int> A(N),B(N);
  for(int i=0;i<N;i++)  cin >> A.at(i) >> B.at(i);

  vector<int> dp(H+1,1e9);
  dp.at(0)=0;
  for(int i=0;i<N;i++){
    for(int j=0;j<H+1;j++){
      if(j-A.at(i)<0) dp.at(j)=min(dp.at(j),B.at(i));
      else  dp.at(j)=min(dp.at(j),dp.at(j-A.at(i))+B.at(i));
    }
  }
  cout << dp.at(H) << endl;

  return 0;
}


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

int main(void){
    int n;
    while(cin >> n, n){
        int ans = 0;
        for(int i = 1; i*i <= n; i++){
            if(i*i == n) ans++;
            for(int j = i; j*j <= n; j++){
                if(i*i + j*j == n) ans++;
                for(int k = j; k*k <= n; k++){
                    if(i*i + j*j + k*k == n) ans++;
                    for(int l = k; l*l <= n; l++){
                        if(i*i + j*j + k*k + l*l == n) ans++;
                    }
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 2992
import sys
from collections import deque
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    H,W=map(int,input().split())
    S=[[] for _ in range(H+2)]
    S[0]=S[H+1]=['#']*(W+2)
    l=[]
    for i in range(1,H+1):
        S[i]=['#']+list(input())+['#']
        for j,x in enumerate(S[i]):
            if x=='.':
                l.append([i,j])
    dx=[1,0,-1,0]
    dy=[0,1,0,-1]
    ans=0
    for start in l:
        d=[[INF]*(W+2) for _ in range(H+2)]
        queue=deque()
        queue.append(start)
        d[start[0]][start[1]]=0
        longest=0
        while queue:
            cell=queue.popleft()
            for k in range(4):
                if S[cell[0]+dy[k]][cell[1]+dx[k]]=='.' and d[cell[0]+dy[k]][cell[1]+dx[k]]==INF:
                    queue.append([cell[0]+dy[k],cell[1]+dx[k]])
                    d[cell[0]+dy[k]][cell[1]+dx[k]]=d[cell[0]][cell[1]]+1
                    longest=max(longest,d[cell[0]+dy[k]][cell[1]+dx[k]])
        ans=max(ans,longest)
    print(ans)
        

if __name__ == '__main__':
    main()


Measured memory_bytes: 44396
def insertion_sort(a, n):   # N個の要素を含む0-オリジンの配列A
    for i in range(n):
        v = a[i]
        j = i - 1
        while j >= 0 and a[j] > v:
            a[j+1] = a[j]
            j -= 1
        a[j+1] = v
        output(a)
    return a


def main():
    n = int(input())
    a = [int(x) for x in input().split()]
    insertion_sort(a, n)


def output(int_arr):
    print(" ".join([str(x) for x in int_arr]))


if __name__ == '__main__':
    main()



Measured memory_bytes: 5608
#include<bits/stdc++.h>
using namespace std;
map<int,int>mp;
char a[30];
int main()
{
	for(int i=0;i<26;i++)
	{
		a[i]=(char)i+'a';
	}
	int pos;
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		mp[s[i]-'a']++;
	}
	pos=26;
	for(int i=0;i<26;i++)
	{
		if(mp[i]==0)
		{
			pos=i;
			break;
		}
	}
	//cout<<pos<<endl;
	if(pos==26) cout<<"None"<<endl;
	else cout<<a[pos]<<endl;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
#define N 100

int main(){

  int a[N];
  int i,j,minj,len,count=0,c;

  scanf("%d\n",&len);
  if(len>N)exit(8);
  for(i = 0; i < len; i++){
    scanf("%d",&a[i]);
  }

  for(i =0; i < len; i++){
    minj = i;
    for(j = i; j < len; j++){
      if(a[j] < a[minj]) minj = j;
    }
 
    if(minj != i)count++;

    c = a[i];
    a[i] = a[minj];
    a[minj] = c;

  }

  for(i = 0; i < len; i++){
    if(i == len-1)printf("%d",a[i]);
    else{
      printf("%d",a[i]);
      printf(" ");
    }
  }
  printf("\n");
  printf("%d\n",count);

  return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(), a.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define endl "\n"
typedef long long ll;

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

    string s;
    cin >> s;
    sort(s.begin(), s.end());
    if(s.at(0) == s.at(1) && s.at(1) != s.at(2) && s.at(2) == s.at(3)) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 3648
import sys

N, K = map(int, sys.stdin.readline().rstrip().split())
P = [int(x) for x in sys.stdin.readline().rstrip().split()]


# 目が 1 ... p のときの期待値
def kitaichi(p):
    return (p + 1) / 2

goukei = 0
for i in range(K):
    goukei += kitaichi(P[i])

gmax = goukei
for i in range(N - K):
    goukei = goukei + kitaichi(P[K + i]) - kitaichi(P[i])  # 次の区間の合計
    gmax = max(goukei, gmax)

print(gmax)


Measured memory_bytes: 31968
using System;
using System.Collections.Generic;

namespace AOJ.Volume0
{
    public class RomanFigure
    {
        public static int Main()
        {
            var dic = new Dictionary<char, int>()
            {
                {'I', 1},
                {'V', 5},
                {'X', 10},
                {'L', 50},
                {'C', 100},
                {'D', 500},
                {'M', 1000}
            };

            while (true)
            {
                string input = Console.ReadLine();
                if (string.IsNullOrEmpty(input)) { break; }

                int answer = 0;
                for (int i = 0; i < input.Length; i++)
                {
                    if (i == input.Length - 1)
                    {
                        // 最後の1文字
                        answer += dic[input[i]];
                    }
                    else if (dic[input[i]] < dic[input[i + 1]])
                    {
                        // 引き算
                        answer -= dic[input[i]];
                    }
                    else
                    {
                        // 足し算
                        answer += dic[input[i]];
                    }
                }
                Console.WriteLine(answer);
            }
            return 0;
        }
    }
}

Measured memory_bytes: 9428
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<ll, int> P;
ll powmod(__int128_t a, ll k, ll m){
	__int128_t ap=a, ans=1;
	while(k){
		if(k&1){
			ans*=ap;
			ans%=m;
		}
		k>>=1;
		ap=ap*ap%m;
	}
	return ans;
}
bool is_prime(ll n){
    if(n<=1 || !(n&1)) return (n==2);
	ll d=n-1;
	int k=0;
	while(!(d&1)){
		d>>=1;
		k++;
	}
	vector<ll> va{2, 325, 9375, 28178, 450775, 9780504, 1795265022};
	for(auto aa:va){
		ll a=aa%n;
		if(a==0) continue;
		bool comp=1;
		ll ap=powmod(a, d, n);
		if(ap==1 || ap==n-1) continue;
		for(int r=1; r<k; r++){
			ap=(__int128_t)ap*ap%n;
			if(ap==n-1){
				comp=0;
				break;
			}
		}
		if(comp) return false;
	}
	return true;
}
ll gcd(ll a, ll b){
	if(a==0) return b;
	if(b==0) return a;
	if(a<0) a=-a;
	if(b<0) b=-b;
	const int s=__builtin_ctzll(a|b);
	a>>=__builtin_ctzll(a);
	while(b){
		b>>=__builtin_ctzll(b);
		if(a>b) swap(a, b);
		b-=a;
	}
	return a<<s;
}
ll rho(ll n, ll& c){
	if(!(n&1)) return 2;
	while(1){
		ll x=2, y=2, d=1;
		while(d==1){
			x=((__int128_t)x*x+c)%n;
			y=((__int128_t)y*y%n+c)%n;
			y=((__int128_t)y*y%n+c)%n;
			d=gcd(abs(x-y), n);
		}
		if(d==n){
			c++;
			continue;
		}
		return d;
	}
}
vector<pair<ll, int>> factorize(ll n){
	if(n<=1){
		vector<pair<ll, int>> ret;
		return ret;
	}
	map<ll, int> mp;
	vector<ll> v(1, n);
	ll c=1;
	while(!v.empty()){
		ll x=v.back();
		v.pop_back();
		if(is_prime(x)){
			mp[x]++;
			continue;
		}
		ll p=rho(x, c);
		v.push_back(p);
		v.push_back(x/p);
	}
	vector<pair<ll, int>> ret;
	for(auto p:mp) ret.push_back(p);
	return ret;
}
int main()
{
	int n;
	cin>>n;
	map<ll, int> mp;
	const ll INF=1e11;
	vector<pair<ll, ll>> v(n);
	for(int i=0; i<n; i++){
		ll s;
		cin>>s;
		vector<P> fac=factorize(s);
		ll x=1, y=1;
		for(auto p:fac){
			if(p.second%3==1){
				x*=p.first;
				if(y>INF/p.first) y=INF;
				else y*=p.first;
				if(y>INF/p.first) y=INF;
				else y*=p.first;
			}else if(p.second%3==2){
				x*=(p.first*p.first);
				if(y>INF/p.first) y=INF;
				else y*=p.first;
			}
		}
		mp[x]++;
		if(x>y) swap(x, y);
		v[i]=make_pair(x, y);
	}
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
	int ans=0;
	for(auto p:v){
		if(p.first==1) ans++;
		else{
			int mx=0;
			if(mp.find(p.first)!=mp.end()) mx=max(mx, mp[p.first]);
			if(mp.find(p.second)!=mp.end()) mx=max(mx, mp[p.second]);
			ans+=mx;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

// int find(unordered_map<int,vector<int>>& um,int st){
// 	int ans=0;
// 	for(int i=0;i<um[st].size();i++){
// 		ans=ans+1+find(um,um[st][i]);
// 	}
// 	return ans;
// }

int main() {
	// your code goes here
	int n;
	cin>>n;
	int* arr=new int[n-1];
	for(int i=0;i<n-1;i++){
		cin>>arr[i];
	}
	unordered_map<int,vector<int>>um;
	for(int i=0;i<n-1;i++){
		um[arr[i]].push_back(i+2);
	}
	for(int i=0;i<n;i++){
		int count=um[i+1].size();
		cout<<count<<endl;
	}
	return 0;
}

Measured memory_bytes: 21432
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
from decimal import *
import heapq
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

a = INT()
print(a + a ** 2 + a ** 3)

Measured memory_bytes: 72628
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
const lli INF = 1e9 + 100;
const lli INF64 = (1LL << 61) + 100;
const lli MOD = 1e9 + 7;
const lli MH1 = 1599614977, MH2 = 2034417103, MH3 = 1090250123, MH4 = 2024491871; 
lli bpow(lli baseee, lli exponenttt) {
	if(exponenttt < 0) return 0;
	lli res = 1;
	baseee %= MOD;
	while (exponenttt > 0) {
		if ((exponenttt & 1) == 1) res = (res*baseee) % MOD;
		baseee = (baseee*baseee) % MOD;
		exponenttt >>= 1;
	}
	return res;
}
lli multInverse(lli a) {//if_mod_is_prime
	return bpow(a, MOD - 2);
}
lli divm(lli a, lli b) {//if_mod_is_prime
	return (a * multInverse(b)) % MOD;
}
lli multm(lli a, lli b) {
	return (a * b) % MOD;
}
lli subm(lli a, lli b) {
	a += MOD;
	lli r = a - b;
	if(r >= MOD) return r - MOD;
	return r;
}
lli addm(lli a, lli b) {
	lli r = a + b;
	if(r >= MOD) return r - MOD;
	return r;
}
signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//	freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);
	int a;
	cin >> a;
	cout << (a + a*a + a*a*a) << "\n";
	
	return 0;
}

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

using namespace std;

int main(void)
{
    int N;
    cin >> N;
    deque<int> A;
    int minus = 0;
    int plus = 0;
    for(int i = 0; i < N; i++){
        int x;
        cin >> x;
        A.push_back(x);
        if(x > 0){
            plus++;
        }else{
            minus++;
        }
    }
    sort(A.begin(), A.end());
    int sum = 0;
    vector<pair<int, int>> ans(N-1);
    for(int i = 0; i < N-1; i++){
        
        int fwd = A.front();
        int bak = A.back();
        A.pop_front();
        A.pop_back();
        int mrg;
        if(A.size() == 0){
            int big = max(fwd, bak);
            int small = min(fwd, bak);
            mrg = big - small;
            A.push_back(mrg);
            ans[i].first = big;
            ans[i].second = small;
            break;
        }
        else if(minus > plus){
            mrg = bak - fwd;
            A.push_back(mrg);
            ans[i].first = bak;
            ans[i].second = fwd;
            plus++;
        }else{
            mrg = fwd - bak;
            A.push_front(mrg);
            ans[i].first = fwd;
            ans[i].second = bak;
            minus++;
        }
        if(fwd > 0){
            plus--;
        }else{
            minus--;
        }
        if(bak > 0){
            plus--;
        }else{
            minus--;
        }
    }
    cout << A[0] << endl;
    for(int i = 0; i < N-1; i++){
        cout << ans[i].first << " " << ans[i].second << endl;
    }

    return 0;
}

Measured memory_bytes: 3072
import collections
import heapq
n,m = map(int,raw_input().split(' '))

elems = [map(int, raw_input().split(' ')) for _ in range(n)]
elems.sort(key = lambda x:x[0])
heap = []

j = 0
cumul = 0
for i in range(1,m+1):

	while(j < len(elems) and elems[j][0] <= i): 
		heapq.heappush(heap,-elems[j][1])
		j+=1
	if heap:
		cumul -= heapq.heappop(heap)

print cumul

Measured memory_bytes: 50460
#include <stdio.h>
#define W 8
#define H 8

/*

¨ÅPA«ÅQ

A		B		C			D		E		F		G
¨ «		«		¨ ¨ ¨ *		  «		¨ «	 	«		  ¨ *
- *		«		-------		- *		  ¨	*	¨ «		- -	
---		«		    111		-		-----	  *		-----
@12		*					---		  121	---		    1
		---					2				212
		222

*/

#define A 12
#define B 222
#define C 111
#define D 2
#define E 121
#define F 212
#define G 1

int main(void){
	char a[W][H]; int x, y, t=0;
	
	while(1){
		t=0;
		
		for(y=0; y<H; y++){
			for(x=0; x<W; x++) a[x][y]=getchar()-'0';
			getchar();	/* üsðÇÝÌÄ */
		}
		
		for(y=0; y<H; y++) for(x=0; x<W; x++)
			if(a[x][y]) goto end;
			
		end:
		while(1){
			if(a[x+1][y]!=0 && x+1<W) x++, t=t*10+1;
			else if(a[x][y+1]!=0 && y+1<H) y++, t=t*10+2;
			else break;
		}
		
		switch(t){
			case A: printf("A\n"); break;	case B: printf("B\n"); break;
			case C: printf("C\n"); break;	case D: printf("D\n"); break;
			case E: printf("E\n"); break;	case F: printf("F\n"); break;
			case G: printf("G\n"); break;
		}
		
		if(getchar()==EOF) return 0;	/* ósðÇÝÌÄ, EOFÈçI¹ */
	}
}

Measured memory_bytes: 0
#include<iostream>  
#include<algorithm>  
#include<cstdio>  
#include<cstring>  
#include<vector>  
#include<queue>  
#include<map>  
#include<cmath>  
#define N 100009  
using namespace std;  
const int INF = 0x3f3f3f3f;  
int a[N];  
  
int main()  
{  
    int n, x;  
    scanf("%d%d", &n, &x);  
    for(int i = 1; i <= n; i++) scanf("%d", &a[i]);  
    long long ans, now; ans = now = 0;  
    for(int i = 1; i <= n; i++)  
    {  
        if(now + a[i] <= x) now = a[i];  
        else ans += now + a[i] - x, now = a[i] - (now + a[i] - x);  
    }  
    printf("%lld\n", ans);  
    return 0;  
}  

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll          long long int
#define lld          long double
#define pb          push_back
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define vec         vector<ll>
#define all(a)     (a).begin(),(a).end()
#define F           first
#define S           second
#define mod         1000000007
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repi(i,a,b)	for(ll  i=a;i<=b;i++)
#define per(i,a,b)  for(ll i=a;i>=b;i--)
#define mp          make_pair
#define mit         map<ll,ll>::iterator
#define sit         set<ll>::iterator
#define pit         pair<ll,ll>::iterator
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;
ll xo(ll x, ll y) 
{ 
   return (x | y) & (~x | ~y); 
}  
ll bin_Expo(ll x,ll n)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return bin_Expo(x*x,n/2);
    else                             //n is odd
        return x*bin_Expo(x*x,(n-1)/2);
}
ll mod_Expo(ll x,ll n,ll M)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return mod_Expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*mod_Expo((x*x)%M,(n-1)/2,M))%M;
 
}
bool prime_check(ll x)
{
    bool prime = (x >= 2);
    for (ll i = 2; i * i <= x; i++) 
    {
        if (x % i == 0) 
        {
            prime = false;
            break;
        }
    }
    return prime;
}
ll logg(ll base,ll x) 
{
    return (ll)(log(x) / log(base));
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
    while(TESTS--)
    {
    	ll n,m,k,l,g,i,h,w;
    	cin>>h>>w;
		n=max(h,w);
		m=min(h,w);
		if(n==1 || m==1)
		cout<<1;
		else if(m%2!=0)
		cout<<((n+1)/2)*((m+1)/2)+(((m+1)/2)-1)*(n/2);
		else
		cout<<((n+1)/2)*((m+1)/2)+(((m+1)/2))*(n/2);
	}
	return 0;
}

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

int N;
long long rec[15][15] = {0};
long long ans = 0;

int main()
{
    scanf("%d", &N);
    for (int i = 1; i <= N; i++)
    {
        int x = i;
        while (x >= 10) x /= 10;
        rec[x][i%10]++;
    }
    for (int i = 1; i <= 9; i++)
    {
        for (int j = 1; j <= 9; j++)
        {
            ans += (rec[i][j]*rec[j][i]);
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
n,m,*a=map(int,open(0).read().split());c,d=[0,2,5,5,4,5,6,3,7,6],[0]*n*9
for i in range(n):
 for j in a:
  if d[i]or i<1:d[i+c[j]]=max(d[i+c[j]],d[i]*10+j)
print(d[n])

Measured memory_bytes: 15348
use std::io;
use std::io::prelude::*;
use std::cmp::min;

fn main (){
    let mut stdin = io::stdin();
    let mut buf = String::new();
    let _ = stdin.read_to_string(&mut buf);
    let mut iter = buf.split_whitespace();

    let n: usize = iter.next().unwrap().parse().unwrap();
    let s = iter.next().unwrap().parse().unwrap();
    let a: Vec<usize> = iter.map(|nstr| nstr.parse().unwrap()).collect();

    let mut i = 0;
    let mut j = 0;
    let mut sum = 0;
    let mut ans = std::usize::MAX;
    while j <= n {
        if sum < s {
            if j == n {
                break;
            }
            sum += a[j];
            j += 1;
        } else {
            ans = min(ans, j - i);
            sum -= a[i];
            i += 1;
        }
    }
    if ans == std::usize::MAX {
        ans = 0;
    }

    println!("{}", ans);
}



Measured memory_bytes: 5032
#include<iostream>
#include<vector>
#define N 100000
#define MOD 1000000007
using namespace std;
typedef long long LL;
LL fac[N+1];
LL fac_inv[N+1];
LL mod_pow(LL base, LL exp)
{
	if(exp==0) return 1;
	if(exp&1) return (base*mod_pow(base,exp-1))%MOD;
	else return mod_pow((base*base)%MOD,exp/2);
}
LL C(LL n, LL k)
{
	if(n < k || k < 0) return 0;
	LL num = fac[n];
	LL den = (fac_inv[k]*fac_inv[n-k])%MOD;
	return (num*den)%MOD;
}
LL P(LL n, LL k)
{
	return (C(n,k)*fac[k])%MOD;
}
vector<int> adj[N+1];
LL k;
LL f(int u, int p)
{
	LL used_colors = p==-1 ? 1 : 2;
	LL children = p==-1 ? adj[u].size() : (adj[u].size()-1);
	LL ans = P(k-used_colors,children);
	for(const int& v : adj[u])
		if(v!=p)
			ans = (ans*f(v,u))%MOD;
	return ans;
}
int main()
{
	fac[0] = 1;
	for(LL n = 1; n <= N; n++)
		fac[n] = (fac[n-1]*n)%MOD;
		
	fac_inv[N] = mod_pow(fac[N],MOD-2);
	for(LL n = N-1; n >= 0; n--)
		fac_inv[n] = (fac_inv[n+1]*(n+1))%MOD;
		
	LL n; cin >> n >> k;
	for(int i = 0; i < n-1; i++)
	{
		int u, v; cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	cout<<(k*f(1,-1))%MOD<<endl;
	return 0;
}

Measured memory_bytes: 11904
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

long get_max_count(std::vector<long>& A, const std::vector<long>& B)
{
	long result = 0;
	for (int i = 0; i < B.size(); ++i) {
		if (B[i] <= A[i]) {
			result += B[i];
		} else {
			long b = B[i] - A[i];
			long b2 = std::min(A[i+1], b);
			result += A[i] + b2;
			A[i+1] -= b2;
		}
	}
	return result;
}

int main()
{
	int N;
	std::vector<long> A;
	std::vector<long> B;

	std::cin >> N;
	A.resize(N+1);
	B.resize(N);
	for (auto& a : A) {
		std::cin >> a;
	}
	for (auto& b : B) {
		std::cin >> b;
	}

	std::vector<long> A2 = A;
	long result = get_max_count(A, B);
	std::reverse(A2.begin(), A2.end());
	std::reverse(B.begin(), B.end());
	result = std::max(result, get_max_count(A2, B));
	std::cout << result << "\n";
}


Measured memory_bytes: 2560
s = input()
s1 =(s[0])
s2 =(s[1])
s3 =(s[2])
s4 =(s[3])

c1 = s.count(s1)
c2 = s.count(s2)
c3 = s.count(s3)
c4 = s.count(s4)

if c1 == c2 == c3 == c4 == 2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<unordered_map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 8;
const ll MOD = 1e9 + 7;
const ll LLINF = 1e18;
#define Pint pair<int, int>
#define Graph vector<vector<int>>
#define rng(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rnr(i, a, b) for(ll i = ll(a); i >= ll(b); i--)
#define rep(i, b) rng(i, 0, b)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */


const int MAX = 500000;

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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int 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(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    COMinit();
    int s; cin >> s;
    ll ans = 0;
    for(int i = 1; i <= (s/3); ++i) {
        int surplus = s - 3 * i;
        ans = (ans + COM(surplus + i - 1, i - 1)) % MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 15336
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
	static boolean [] visited;
	static ArrayList<Integer>[] adj;
	static int MOD = 998244353;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Robot[] a = new Robot[n];
		for(int i=0;i<n;i++) {
			a[i] = new Robot(sc.nextInt(),sc.nextInt());
		}
		Arrays.sort(a);
		adj = new ArrayList[n];
		for(int i=0;i<n;i++) {
			adj[i]= new ArrayList<>();
		}
		int currIndex =0;
		TreeSet<Integer> active = new TreeSet<Integer>(new Comparator<Integer>() {

			@Override
			public int compare(Integer o1, Integer o2) {
				// TODO Auto-generated method stub
				if( a[o1].x+a[o1].d-a[o2].x-a[o2].d !=0) {
					return a[o1].x+a[o1].d-a[o2].x-a[o2].d;
				}
				return a[o1].x-a[o2].x;
			}
			
		});
		TreeSet<Integer> order = new TreeSet<Integer>(new Comparator<Integer>() {

			@Override
			public int compare(Integer o1, Integer o2) {
				// TODO Auto-generated method stub
				return a[o1].x-a[o2].x;
			}
			
		});
		for(int i=0;i<n;i++) {
			int currPos = a[i].x;
			while(!active.isEmpty()) {
				int temp = active.first();
				if((a[temp].x+a[temp].d)<=currPos) {
					active.remove(temp);
					order.remove(temp);
				}
				else {
					break;
				}
			}
			if(order.size()>0) {
				//assign active.last()
				int add = order.last();
				adj[add].add(i);
				adj[i].add(add);
			}
			active.add(i);
			order.add(i);
		}
		visited = new boolean[n];
		long prod = 1;
		for(int i=0;i<n;i++) {
			if(!visited[i]) {
				long mult = dfs(i);
				prod*=mult;
				prod%=MOD;
			}
		}
		System.out.println(prod);
		
	}
	private static long dfs(int i) {
		// TODO Auto-generated method stub
		visited[i]= true;
		long prod = 1;
		for(int next : adj[i]) {
			if(!visited[next]) {
				prod*=dfs(next);
				prod%=MOD;
				
			}
		}
		prod++;
		return prod;
		
	}
	static class Robot implements Comparable<Robot>{
		int x;
		int d;
		public Robot(int x,int d) {
			this.x = x;
			this.d = d;
		}
		@Override
		public int compareTo(Robot o) {
			// TODO Auto-generated method stub
			return x-o.x;
		}
	}
}


Measured memory_bytes: 206940
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define sz 200009
#define mod 998244353
ll n,m,arr[sz],brr[sz],k,l,crr[sz],t,i,j,hi,lo,mi,q;
vector<ll>v;
char c[sz];
int main()
{
 scanf("%lld",&n);
 for(i=1;i<=n;i++)
 {
     scanf("%lld",&arr[i]);
     brr[arr[i]]++;
 }
 k=0;
 for(i=1;i<=100000;i++)
    k+=brr[i]*i;
 scanf("%lld",&q);
 for(i=1;i<=q;i++)
 {
     scanf("%lld %lld",&j,&l);
     m=l-j;
     m*=brr[j];
     brr[l]+=brr[j];
     brr[j]=0;
     k+=m;
     printf("%lld\n",k);
 }
}


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

int main(){
    int n;
    cin >> n;
    vector<string> S(n);
    copy_n(istream_iterator<string>(cin), n, S.begin());
    
    map<char, int64_t> C;
    for (const auto &s: S)
        C[s[0]]++;
    
    const string MARCH = "MARCH";
    int64_t ans = 0;

    for (int i = 0; i < (1 << 5); i++){
        if (__builtin_popcount(i) != 3)
            continue;
        int64_t res = 1;
        for (int j = 0; j < 5; j++){
            if ((i >> j) & 1)
                res *= C[MARCH[j]];
        }
        ans += res;
    }

    cout << ans << endl;
}

Measured memory_bytes: 6144
import java.util.Scanner; // ?????¨?????????????????????

public class Main {
    public static void main(String[] args) {
        // ?????????????????\?????????????????¨?????? sc ??????????????? (???????????????????????????????????????????????°???????????????).
        Scanner sc = new Scanner(System.in);

        // ????????? sc ??? int ?????¨?????? 1 ?????\???????????????.
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        // ??????????????¨???
        if (a < b && b < c) { System.out.println("Yes"); }
        else  { System.out.println("No"); }
    }
}

Measured memory_bytes: 26380
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var X = int.Parse(Console.ReadLine());
            long a = 0;

            while (true)
            {
                var n = Math.Pow(a, 5) - X;
                Func<long, double> f = s => Math.Pow(s, 5) - Math.Abs(n);
                var b = SearchLast(s => f(s) <= 0, 0, Math.Max(a, 46));

                if (f(b) == 0)
                {
                    if (n < 0) b = -b;
                    Console.WriteLine(string.Format("{0} {1}", a, b));
                    return;
                }
                a++;
            }
        }

        public static long SearchLast(Func<long, bool> f, long min, long max)
        {
            if (f(max)) return max;
            var k = min + (max - min) / 2;

            return f(k) ? SearchLast(f, k, max - 1) : SearchLast(f, min, k);
        }
    }
}


Measured memory_bytes: 27876
#include <iostream>
#include<bits/stdc++.h>
const int N=1e5+5;
const int M=1e7;
using namespace std;
int main()
{
    char s[105],t[105];
    string a,b;
    scanf("%s %s",s,t);
    a=s;
    b=t;
    a=b+a;
    cout<<a;
    return 0;
}


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

int tos(int h,int m,int s){
  return h*60*60+m*60+s;
}

void solve(int h,int m,int s,int a,int b,int c){
  int res=tos(a,b,c)-tos(h,m,s);
  cout <<res/3600<<" ";
  res%=3600;
  cout << res/60<<" ";
  res%=60;
  cout << res<<endl;
}

int main(){
  
  int h,m,s,a,b,c;
  for(int i=0;i<3;i++){
    cin>>h>>m>>s>>a>>b>>c;
    solve(h,m,s,a,b,c);
  }
  
  return 0;
}

Measured memory_bytes: 1160
// B - Echo

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

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

    string S;
    cin >> S;

    if (N % 2 == 1) {
    	cout << "No" << endl;
    	return 0;
    }

    string ans = "Yes";
    for (int i = 0; i < N/2; i++) {
    	if (S[i] != S[i + N/2]) {
    		ans = "No";
    		break;
    	}
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
money = []
unit = []
for i in range(n):
    a, b = map(str, input().split())
    money.append(float(a))
    unit.append(b)
    
total = 0
for i in range(len(unit)):
    if unit[i] == "JPY":
        total += money[i]
    else:
        total += money[i] * 380000.0

print(total)

Measured memory_bytes: 3064
//LCS
#if 0

#endif // 0
#include<iostream>
#define MAX 1010
using namespace std;
int l[MAX][MAX];

int main()
{
    string s1,s2;
    cin>>s1>>s2;
    for(int m=0;m<=s1.size();m++)
        for(int n=0;n<=s2.size();n++)
        {
            if(m==0||n==0)
                l[m][n]=max(m,n);
            else if(s1[m-1]==s2[n-1])
                l[m][n]=l[m-1][n-1];
            else
                l[m][n]=min(min(l[m-1][n-1],l[m-1][n]),l[m][n-1])+1;
        }
    cout<<l[s1.size()][s2.size()]<<endl;
    return 0;
}



Measured memory_bytes: 7108
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();
    int e = sc.nextInt();
    int k = sc.nextInt();
    boolean p = true;

    int m = Math.abs(a - b);
    int n = Math.abs(a - c);
    int l = Math.abs(a - d);
    int x = Math.abs(a - e);
    int y = Math.abs(b - c);
    int z = Math.abs(b - d);
    int q = Math.abs(b - e);
    int w = Math.abs(c - d);
    int r = Math.abs(c - e);
    int t = Math.abs(d - e);

    int data[] = { m , n , l , x , y , z , q , w , r , t };

    for (int i = 0 ; i < data.length ; i++ ) {

      if ( data[i] <= k ) {
        p = true;
      } else {
        p = false;
        break;
      }
    }

    if (p) {
      System.out.println("Yay!");
    } else {
      System.out.println(":(");
    }

  }
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
const int  MAX = 1e5;

int main(){
    string s,t;
    cin >> s >> t;
    vector<int> a(26),b(26);
    int s_int,t_int,n;
    n = s.size();
    for(int i=0;i<n;i++){
        s_int = s[i]-'a';
        t_int = t[i]-'a';
        a[s_int]++;
        b[t_int]++;
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    bool flag=true;
    for(int i=0;i<26;i++){
        if(a[i]!=b[i])flag=false;
    }
    cout << (flag?"Yes":"No") << endl;
}


Measured memory_bytes: 776
#include <stdio.h>

int main(){
  int n,m,x;
  int a[12][13]={0};
  int b[12];
  int i,j,k,tmp,pat=1;
  int cost,flag;
  int min_cost=1000000000;
  
  scanf("%d %d %d",&n,&m,&x);
  pat=pat<<n;
  
  for(i=0;i<n;i++){
    scanf("%d",&a[i][0]);
    for(j=1;j<=m;j++){
      scanf("%d",&a[i][j]);
    }
  }
  
  //sort by cost
  for(i=n;0<i;i--){
    for(j=0;j<i-1;j++){
      if(a[j][0]>a[j+1][0]){
        for(k=0;k<=m;k++){
          tmp=a[j][k];
          a[j][k]=a[j+1][k];
          a[j+1][k]=tmp;
        }
      }
    }
  }
  
  /*
  for(i=0;i<n;i++){
	for(j=0;j<=m;j++){
      printf("%d ",a[i][j]);
    }
    printf("\n");
  }
  printf("\n");*/
  
  //calc cost
  for(i=1;i<=pat;i++){
    //initialize step
    cost=0;
    flag=0;
    for(j=0;j<m;j++){
      b[j]=0;
    }
    
    //calc skillX
    for(j=0;j<n;j++){
      if(((1<<j)&i) !=0){
        cost+=a[j][0];
        for(k=1;k<=m;k++){
          b[k-1]+=a[j][k];
        }
      }
    }
    
    //check skillX
    /*
    printf("%d ",cost);
    for(k=0;k<m;k++){
      printf("%d ",b[k]);
    }
    printf("\n");
    */
    
    for(k=1;k<=m;k++){
      if(b[k-1]<x){
        flag=1;
        break;
      }
    }
    
    if(flag==0 && cost<min_cost){
      min_cost=cost;
    }
  }
  
  if(min_cost<1000000000){
    printf("%d",min_cost);
  } else {
    printf("-1");
  }
}

Measured memory_bytes: 1704
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define Mid ((l+r)/2)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define drep(i,a,b) for(int i=(a);i>=(b);--i)
#define file(a) freopen(#a".in","r",stdin),freopen(#a".out","w",stdout);
const int maxn=2e5+5,mod=1e9+7,inf=0x3f3f3f3f;
int n,m,Q,K,T;
int read(){
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}int a[maxn];
int dsum[maxn];

signed main(){
    //file(a);
    n=read();
    rep(i,1,n)a[i]=read();
    dsum[n]=a[n];
    drep(i,n-1,1)dsum[i]=(dsum[i+1]+a[i])%mod;
    int ans=0;
    rep(i,1,n-1){
        ans=(ans+1ll*a[i]*dsum[i+1]%mod)%mod;
    }printf("%lld\n",ans);


    return 0;
}

Measured memory_bytes: 6784
import numpy as np
def calc(n, k):
    prob = 0
    for i in range(1, n+1):
        #print(i)
        if i<k:
            time_to_win = int(np.ceil(np.log2(k/i)))
            prob += (1 / n) * (0.5**time_to_win)
        else:
            prob += (1/n) * (n- i+1)
            break
    return prob

n, k = map(int, input().split())
print(calc(n,k))

Measured memory_bytes: 20368