akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using pci = pair<char, int>;
using vpci = vector<pci>;
#define out(S) cout<<(S)<<endl;
#define REP(i,b) for(size_t i=0;i<(b);i++)
#define rREP(i,b) for(int i=(b)-1;i>=0;i--)
#define FOR(i,a,b) for(size_t i=(a);i<(b);i++)
#define rFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define Foreach(item,collection) for(auto item:collection)
#define mod(i) ((i) % (ll)(1e9 + 7))
ll modpow(ll i, ll j) { ll tmp = 1; while (j) { if (j % 2)tmp = mod(tmp*i); i = mod(i*i); j /= 2; }return tmp; }
#define divmod(a,b) (mod(a * modpow((ll)b,(ll)(1e9 + 5))))
#define Yes out("Yes")
#define No out("No")
#define NO out("NO")
#define YES out("YES")
#define INF 1e10;
#define ShowAll(collection) for(auto i:collection){out(i);}
#define IfOut(condition,text) if((condition)){out(text);return 0;}
#define IfeOut(condition,itext,etext) if(condition){out(itext);return 0;}else{out(etext);return 0;}
#define Select(collection,condition,result) Foreach(i,collection){result+=condition;}
#define GetAuto(_N,vect) {cin>>_N;vect.resize(_N);REP(i,_N){cin>>vect[i];}}
#define beginend(vec) (vec).begin(),(vec).end()
#define pb(item) push_back(item)
#define removeAll(vec,deleg) auto itr=remove_if(beginend(vec),deleg);vec.erase(itr,vec.end());
void removeAt(string& s, int index) { s.erase(index, 1); }
template<typename T> void removeAt(vector<T>& v, int index) { v.erase(v.begin() + index); }
ll manhattanDistance(ll x1, ll y1, ll x2, ll y2) { return (abs(x2 - x1) + abs(y2 - y1)); }
vector<ll> sieveOfEratosthenes(int max) { ll prime; double sqrtmax = sqrt(max); vector<ll> primeVec, searchVec; FOR(i, 2, max + 1) searchVec.push_back(i); do { prime = searchVec[0]; primeVec.push_back(prime); auto itr = remove_if(beginend(searchVec), [=](ll x)->bool {return x%prime == 0; }); searchVec.erase(itr, searchVec.end()); } while (prime < sqrtmax); primeVec.reserve(primeVec.size() + searchVec.size()); primeVec.insert(primeVec.end(), beginend(searchVec)); return primeVec; }
bool isPrime(ll x) { if (x == 2) return true; if (x < 2 || x % 2 == 0) return false; ll i = 3; while (i <= sqrt(x)) { if (x%i == 0) return false; i += 2; }return true; }

int N;

int main() {
	while (cin>>N,N)
	{
		vector<string> box(N);
		REP(i, N) cin >> box[i];
		bool lcond = false, rcond = false, nextstep = true;
		int ans = 0;
		Foreach(x, box) {
			if (x == "lu") lcond = true;
			if (x == "ru")rcond = true;
			if (x == "ld")lcond = false;
			if (x == "rd")rcond = false;
			if (nextstep == lcond&&nextstep == rcond) { ans++; nextstep = !nextstep; }
		}
		out(ans);
	}
	return 0;
}

Measured memory_bytes: 3180
#include <iostream>
using namespace std;
int map[21][21];
int n,m,a,b,d,cnt;
typedef struct{
	int x;
	int y;
}POS;
POS pos;

void check(char c,int p){
	switch(c){
		case'N':
		for(int i=1;i<=p;i++){
			pos.y++;
			if(map[pos.x][pos.y]==1){
				map[pos.x][pos.y]=0;
				cnt--;
			}
		}
		break;
		case'E':
		for(int i=1;i<=p;i++){
			pos.x++;
			if(map[pos.x][pos.y]==1){
				map[pos.x][pos.y]=0;
				cnt--;
			}
		}
		break;
		case'S':
		for(int i=1;i<=p;i++){
			pos.y--;
			if(map[pos.x][pos.y]==1){
				map[pos.x][pos.y]=0;
				cnt--;
			}
		}
		break;
		case'W':
		for(int i=1;i<=p;i++){
			pos.x--;
			if(map[pos.x][pos.y]==1){
				map[pos.x][pos.y]=0;
				cnt--;
			}
		}
		break;
	}
}



int main(){
	char c;
	while(1){
		cin >>n;
		if(n==0)break;
		for(int i=0;i<=20;i++){
			for(int j=0;j<=20;j++){
				map[i][j]=0;
			}
		}
		for(int i=0;i<n;i++){
			cin >>a >>b;
			map[a][b]=1;
		}
		cin >>m;
		pos.x=pos.y=10;
		cnt=n;
		for(int i=0;i<m;i++){
			cin >>c >>d;
			check(c,d);
		}
		if(cnt==0){
			cout <<"Yes" <<endl;
		}else{
			cout <<"No" <<endl;
		}

	}
	
	return 0;
}

Measured memory_bytes: 3004
n = int(input())
a = []
flag = 1
before = ""
def is_unique(seq):
    return len(seq) == len(set(seq))
for i in range(n):
    a1 = input()
    a.append(a1)
    if i == 0:
        before = a1[len(a1)-1]
        continue
    if before != a1[0]:
        flag = 0
    before = a1[len(a1)-1]
if is_unique(a) == False:
    flag = 0
if flag==0:
    print("No")
else:
    print("Yes")

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	std::map<int, int> all;
	for (int i = 0; i < n; i++) all[ri()]++;
	int64_t res = 0;
	for (auto i : all) res += (int64_t) i.first * i.second;
	int q = ri();
	for (int i = 0; i < q; i++) {
		int b = ri();
		int c = ri();
		all[c] += all[b];
		std::cout << (res += (int64_t) all[b] * (c - b)) << std::endl;
		all[b] = 0;
	}
	return 0;
}


Measured memory_bytes: 8044
#include <stdio.h>

main(){
  int n, sum, max, min, i, j, temp;

  while(1){
    scanf("%d", &n);
    if(n==0) break;

    max=-1;
    min=501;
    for(i=0;i<n;i++){
      sum=0;
      for(j=0;j<5;j++){
	scanf("%d", &temp);
	sum+=temp;
      }
      if(max<sum) max=sum;
      if(min>sum) min=sum;
    }

    printf("%d %d\n", max, min);

  }
  return 0;
}

Measured memory_bytes: 0
# -*- coding: utf-8 -*-

k, n = map(int, input().split(' '))
distances = list(map(int, input().split(' ')))

diff = []
for i in range(len(distances)):
    if i == len(distances) - 1 :
        diff.append(k + distances[0] - distances[i])
    else:
        diff.append(distances[i + 1] - distances[i])
max_d = max(diff)
print(sum(diff) - max_d)




Measured memory_bytes: 26444
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,x=0;cin>>n;
  lvector A(n);rep(i,n) {cin>>A[i];x^=A[i];}
  rep(i,n) A[i]^=x;
  rep(i,n-1) cout<<A[i]<<' ';
  cout<<A[n-1]<<endl;
  return 0;
}


Measured memory_bytes: 4764
using System;
using System.Linq;

namespace CSharp
{
    class Program
    {
        static void Main()
        {
            var N = int.Parse(Console.ReadLine());
            var H = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();

            var result = 0;
            var t = H[0];
            for (int i = 0; i < N; i++)
            {
                if (H[i] >= t)
                {
                    result++;
                }
                t = Math.Max(H[i], t);
            }
            Console.WriteLine(result);
        }
    }
}

Measured memory_bytes: 11348
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef map<ll,ll> mll;
typedef set<ll> sll;

#define se second
#define fi first
#define pb push_back
const ll MOD = 1e9+7;
const ll NMAX = 5*1e5+1;
ll n,m,k,x,ans1,ans2[NMAX],y;
ll w[NMAX];
string s;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n>>m;
	for(ll i=1;i<=m;i++)
	{
		cin>>x>>s;
		if(s=="AC" && !w[x])
			ans1++,w[x]=1,y+=ans2[x];
		else
		if(s=="WA" && !w[x])
			ans2[x]++;
	}
	cout<<ans1<<" "<<y;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define int long long
#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;

signed main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int x; cin >> x;
    int a, b;
    // 9,223,372,036,854,775,807の5乗根は6208.4
    rep(i,6209) rep2(j,i+1,6209){
        if (j*j*j*j*j - i*i*i*i*i == x){
            a = j;
            b = i;
            break;
        }
        if (j*j*j*j*j + i*i*i*i*i == x){
            a = j;
            b = -i;
            break;
        }
    }
    cout << a << " " << b << endl;

    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int64_t> v(N);
  for(int i=0;i<N;i++){
    cin >> v.at(i);
  }
  sort(v.begin(),v.end(),[](int64_t a,int64_t b){ return a>b; });
  int64_t x=v.front();
  int64_t count=0;
  int64_t ans;
  bool flag=false;
  for(int i=0;i<v.size();i++){
    if(x==v.at(i)){
      count++;
    }else{
      x=v.at(i);
      count=1;
    }
    if(count%2==0){
      if(flag){
        cout << ans*v.at(i) << endl;
        return 0;
      }else{
        ans=x;
        flag=true;
      }
    }
  }
  cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 1024
n,m=map(int,input().split())
l=[]
ans=[]
for _ in range(n):
        k=list(map(int,input().split()))
        l.append(k[1:])
for i in range(1,m+1):
        for j in range(n):
                if i in l[j]:
                        continue
                else:
                        break
        else:
                ans.append(i)
print(len(ans))

Measured memory_bytes: 3064
#include <bits/stdc++.h> 
#define int long long
#define quickie ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rep(i, a, b) for(int i=a; i<b; i++)
#define rep1(i, a, b) for(int i=a; i<=b; i++)
#define repp(i, a, b) for(int i=b-1; i>=a; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define db double
#define mi map<int, int>
#define mc map<char, int>
#define ms map<string, int>
#define vi vector<int>
#define qi queue<int>
#define MI(x) power(x, mod-2)
#define test int t; cin >> t;
//#define mod 1000000007LL
#define mod 998244353 
using namespace std;
int power(int x, int y) ;
int gcd(int a, int b) ;
#define pi 3.141592653589
const int lll = 39800;
vi t(4*lll);
vi ans;

void solve(int v, int tl, int tr)
{
	if(tl==tr) {
		t[v] = ans[tl];
	}
	else {
		int tm = (tl+tr)/2;
		solve(v*2,tl,tm);
		solve(v*2+1,tm+1,tr);
		t[v]=t[v*2]+t[v*2+1];
	}
}

int fun(int v, int tl, int tr, int l, int r)
{
	if(l>r)
		return 0;
	if(tl==l&&tr==r)
		return t[v];
	int tm = (tl+tr)/2;
	return fun(v*2,tl,tm,l,min(r,tm))+fun(v*2+1,tm+1,tr,max(l,tm+1),r);
}

signed main() {
    quickie 
    set<string> ans ;
    test
    while(t--) {
        string s ;
        cin >> s ;
        ans.insert(s) ;
    }
    cout << ans.size() << "\n" ;
}

int power(int x, int y) {
    int res = 1; x %= mod;
    while (y > 0) {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res%mod;
}
 
int gcd(int a,int b){
    if(a==0) return b;
    return gcd(b%a,a);
}

Measured memory_bytes: 20076
#include<iostream>
#include<string>
#include<cmath>
using namespace std;

int main(){
	string S;
	cin>>S;
	bool rside = true;
	double len = 0;
	int lindex;
	int ans[S.size()];
	for(int i=0;i<S.size();++i){
		if(rside && S[i]=='L'){
			len++;
			rside = false;
			lindex = i;
			ans[i] = ceil(len/2);
			ans[i-1] = len/2;
			len = 0;
		}
		else if(!rside && S[i]=='R'){
			rside = true;
			ans[lindex-1] += ceil(len/2);
			ans[lindex] += len/2;
			ans[i] = 0;
			len = 1;
		}
		else{
			ans[i] = 0;
			len++;
		}
	}
	ans[lindex-1] += ceil(len/2);
	ans[lindex] += len/2;
	for(int i=0;i<S.size();++i){
		cout<<ans[i]<<" ";
	}
	cout<<endl;
}


Measured memory_bytes: 1152
"use strict";
    
const main = arg => {
  	const N = arg.split("\n")[0]*1;
    const Nums = arg.split("\n")[1].split(" ");
  	// ソートかけた
  	let sortNums = Nums.sort((a,b)=>{ return a-b });
  	// 真ん中の地点を探る
  	console.log(sortNums[(N/2)] - sortNums[(N/2) - 1]);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 18108
#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.at(i);
  }
  int64_t num = 0;
  int current_max = 0;
  for(int i=0; i<N; i++){
    if(A.at(i) > current_max){
      current_max = A.at(i);
    }else if(A.at(i) < current_max){
      num += (int64_t)current_max - A.at(i);
    }
  }
  
  cout << num << endl;
}

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

int main() {
	int n; cin>>n;
	int answer = 0;
	for(int a = 1; a <= n; a++){
		for(int b = a; b < n; b += a){
			answer++;
		}
	}
	cout<<answer<<endl;
	return 0;
}

//a * b + c = n
// a * b = n - c

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

char z[62];
int s[128], p[128];
queue<pair<pair<int, int>, int> > q;
vector<int> v;

int lar;
void it(int N) {if (++lar > 850) assert(0); printf("? "); for (int i = 0; i < N; ++i) putchar(z[s[i]]); printf("\n"); fflush(stdout);}

int main() {
    srand(100);
    int N, x, f, l, h, c, i, j;
    for (i = 0; i < 26; ++i) z[i] = 'a' + i;
    for (i = 0; i < 26; ++i) z[i + 26] = 'A' + i;
    for (i = 0; i < 10; ++i) z[i + 52] = '0' + i;
    random_shuffle(z, z + 62);
    it(128);
    scanf("%d", &f);
    l = 1;
    h = 128;
    while (l < h) {
        N = (l + h) / 2;
        it(N);
        scanf("%d", &x);
        ((f - x == 128 - N) ? h : l) = N + !(f - x == 128 - N);
    }
    N = (l + h) / 2;
    it(N);
    scanf("%d", &f);
    for (i = 0; i < N; ++i) {
        s[i] = 1;
        it(N);
        scanf("%d", &x);
        if (f < x) p[i] = 0;
        else if (x < f) p[i] = 1;
        else p[i] = -1;
        s[i] = 0;
    }
    for (i = 0; i < N; ++i) {s[i] = !!p[i]; if (p[i] < 0) v.push_back(i);}
    it(N);
    scanf("%d", &f);
    for (i = 2; i < 62; ++i) {
        for (j = 0; j < v.size(); ++j) s[v[j]] = i;
        it(N);
        scanf("%d", &x);
        q.emplace(make_pair(0, v.size() - 1), f - x);
        while (!q.empty()) {
            if (!q.front().second) {q.pop(); continue;}
            l = q.front().first.first;
            h = q.front().first.second;
            if (q.front().second == h - l + 1) {for (j = l; j < h + 1; ++j) p[v[j]] = i; q.pop(); continue;}
            c = (l + h) / 2;
            for (j = 0; j < l; ++j) s[v[j]] = 0;
            for (j = l; j < c + 1; ++j) s[v[j]] = i;
            for (j = c + 1; j < v.size(); ++j) s[v[j]] = 0;
            it(N);
            scanf("%d", &x);
            x = f - x;
            q.emplace(make_pair(l, c), x);
            q.emplace(make_pair(c + 1, h), q.front().second - x);
            q.pop();
        }
        for (j = 0; j < N; ++j) s[j] = p[j];
        for (j = 0; j < v.size(); ++j) if (p[v[j]] > 0) {--f; v[j] = N;}
        sort(v.begin(), v.end());
        while (!v.empty() && v.back() == N) v.pop_back();
        if (v.empty()) break;
    }
    printf("! ");
    for (int i = 0; i < N; ++i) putchar(z[s[i]]);
    printf("\n");
    fflush(stdout);
    return 0;
}


Measured memory_bytes: 3804
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

X = I()

if X >= 30:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 65532
#include <iostream>
using namespace std;
int main() {
    long long m, f, r, t;
    do {
        cin >> m >> f >> r;
        t = m + f;
        if ((m == -1) || (f == -1)) {
        	if (!((m == -1) && (f == -1) && (r == -1))) {
				cout << 'F' << '\n';
			}
        } else if (t >= 80) {
            cout << 'A' << '\n';
        } else if (t >= 65) {
            cout << 'B' << '\n';
        } else if (t >= 50) {
            cout << 'C' << '\n';
        } else if (t >= 30) {
            if (r >= 50) {
                cout << 'C' << '\n';
            } else if (r < 50) {
                cout << 'D' << '\n';
            }
        } else if (t < 30) {
            cout << 'F' << '\n';
        }
    } while (!((m == -1) && (f == -1) && (r == -1)));
}


Measured memory_bytes: 3072
import heapq
N,M = map(int,input().split())
AB_s = [list(map(int, input().split())) for _ in range(N)]
MAPperA = {i: [] for i in range(1,M+1)}
# 残り日数ごとのマップを作る
for i, AB in enumerate(AB_s):
    if AB[0] in MAPperA:
        MAPperA[AB[0]].append(AB[1])
excutableJobList = []
heapq.heapify(excutableJobList)
answer = 0
# 短期間でできる仕事からリストを作って追加してそーとして最大値を追加していく
for i in range(1,M+1):
    for j in MAPperA[i]:
        heapq.heappush(excutableJobList, j*-1)
    if excutableJobList:
        answer += heapq.heappop(excutableJobList) * -1
print(answer)

Measured memory_bytes: 87508
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 998244353;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

ll fact[200000], invFact[200000]; 

long long power(long long x, long long c) {
    if(c==0) return 1;
    if(c==1) return x;
    if (c%2==1) return (power( (x*x)%MOD, c/2)*x)%MOD;
    else return power( (x*x)%MOD, c/2)%MOD;
}

void make_combT(ll n){
    fact[0]=1;
    rep1(i,n) fact[i]= fact[i-1]*i%MOD;
    
    invFact[n] = power(fact[n],MOD-2);
    rrep(i,n-1) invFact[i] = invFact[i+1] * (i+1) %MOD;
}

ll comb(ll n, ll m){
    if(n<m||n<0||m<0) return 0;
    return (fact[n] * invFact[m] %MOD) * invFact[n-m] %MOD;
}

ll hcomb(ll n, ll m){
    if(n==0&&m==0) return 1;
    return comb(n+m-1,m);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int K, N;
    cin>>K>>N;
    
    make_combT(10000);
    
    for(int t=2;t<=2*K;t++){
        ll ans=0;
        ll n=min(t,(2*K+2-t))/2;
        rep1(i,n){
            ans = (ans+(i%2?1:-1)*hcomb(K,N-2*i)*comb(n,i))%MOD;
        }
        ans = (hcomb(K,N)-ans)%MOD;
        cout1((ans+MOD)%MOD);
    }
}

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

using namespace std;

int main() {
	string S;
	cin >> S;

	if (S == "A") {
		cout << "T" << endl;
	}
	else if (S == "T") {
		cout << "A" << endl;
	}
	else if (S == "C") {
		cout << "G" << endl;
	}
	else if (S == "G") {
		cout << "C" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
/*input
7
1 1 1 1 1 1 1
*/
 
 
 
#include <bits/stdc++.h>
using namespace std;
 
 
 
#define int long long int
#define rep(i,n) \
    for(int i = 0; i < n; i++)
#define rep2(i, a, b) \
    for(int i = a; i < b; i++)
#define all(c) \
    c.begin(), c.end()
#define init(arr, num) \
    memset(arr, num, sizeof(arr))
#define fast\
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inputFile \
    freopen("input.txt", "r", stdin); 
#define outputFile \
    freopen("output.txt", "w", stdout);
#define modM 1000000007
#define PI 3.1415926535897932
#define F first
#define S second  
#define pb push_back  
#define INF 3e18
#ifdef gaviria
#define TRACE
#endif
#ifdef TRACE
#define trace(...) _f(#VA_ARGS, __VA_ARGS_)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std::endl;
 
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define trace(...)
#endif
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair< ll, ll > ii;
typedef unordered_set<int> usi;
 
 
 
ll n,i,j,k,m;
 
 
 
 
 
void solve()
{
cin>>n;
int a[n];



for(i=0;i<n;i++)
    cin>>a[i];

sort(a,a+n,greater<int>());

int ans=0;
ans+=a[0];
for(i=1;i<(n)/2;i++)
{
ans+=2*a[i];



}
if((n)%2)
{
    ans+=a[i];

}
cout<<ans;


}
 
 
 
signed main()
{
 
    // inputFile;
    // outputFile;
    fast;
    int T = 1;
    // cin >> T;
    ll h=T;
    while(T--){
 
        solve();
        cout<<endl;
 
     
        
        
 
    }
    
    
    return 0;
 
}

Measured memory_bytes: 5140
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <map>
#include <cmath>
using namespace std;
typedef long long ll;
#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++)

int main() {
  int N;
  cin >> N;
  string dummy;
  getline(cin, dummy);

  vector<string> S;
  rep(i, N) {
	string s;
	getline(cin, s);
	S.push_back(s);
  }

  map<map<char, int>, int> counts;
  ll total = 0LL;
  rep(i, N) {
	map<char, int> c;
	string s = S[i];
	rep(j, s.size()) {
	  c[s[j]]++;
	}
	total += counts[c];
	counts[c]++;
  }
  cout << total << endl;
}


Measured memory_bytes: 49904
#include<iostream>

using namespace std;

int main(){
int A,B,K; cin >> A >> B >> K;
  int t = min(A,B);
  int cnt = 0;
  while( t > 0 && cnt < K){
    if( A % t == 0 && B % t == 0){ cnt++;}
    t--;}
  
  cout << t + 1 << endl;
  
  return 0;}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

// x^n in mod
ll modpow(ll x, ll n, ll mod){
  if(n==0) return 1;

  if(n%2==0){
    return modpow(x*x%mod, n/2, mod) % mod;
  }else{
    return x * modpow(x, (n-1), mod) % mod;
  }
}


// nCr in mod
ll comb(ll n, ll r){
  if(n<0 || n<r || r<0)return 0;

  ll u = 1, d=1;
  rep(i, r){
    u *= n-i;
    u %= MOD;

    d *= r-i;
    d %= MOD;
  }
  
  d = modpow(d, MOD-2, MOD) % MOD;
  
  ll result = u * d % MOD;
 
  return result;
}

int main(){
  ll n,a,b;cin>>n>>a>>b;

  ll all = modpow(2, n, MOD);
  ll a_pat = comb(n, a);
  ll b_pat = comb(n, b);
  ll result = all-a_pat+MOD-b_pat+MOD;
  result %= MOD;
  if(result<0){
    result+=MOD;
    result+=MOD;
    result %= MOD;
  }

  cout<<result-1;
  
  return 0;
}

Measured memory_bytes: 256
n, m = [int(x) for x in input().split()]
a = set([int(input()) for _ in range(m)])

dp = [0]*(n+1)
dp[0] = 1

for i in range(1, n+1):
    dp[i] = (dp[i-1] + dp[i-2]) % (10**9+7)
    if i in a:
        dp[i] = 0

print(dp[n])

Measured memory_bytes: 13192
import java.lang.Math._
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val A, B, H, M = sc.nextDouble
  val hour = Polar(A, PI * (H + M / 60d) / 6d)
  val minute = Polar(B, PI * M / 30d)
  println(hour distance minute)
}

case class Polar(r: Double, θ: Double) {
  lazy val rectangular: Rectangular =
    Rectangular(r * cos(θ), r * sin(θ))
  def distance(that: Polar): Double =
    rectangular distance that.rectangular
}

case class Rectangular(x: Double, y: Double) {
  def distance(that: Rectangular): Double = {
    val dx = x - that.x
    val dy = y - that.y
    sqrt(dx * dx + dy * dy)
  }
}


Measured memory_bytes: 55512
#include<bits/stdc++.h>
using namespace std;
int main(){
 long long int N,A,B,a,b,r;
 
  cin>>N>>A>>B;
  a=N/(A+B);
  b=N%(A+B);
  r=min(b,A);
  cout<<A*a+r<<endl;
  
  
}


Measured memory_bytes: 256
I = input
s = I()
q = int(I())
a = [], []
i = 0
for _ in range(q):
  x = I()
  if x[0] == '1':
    i ^= 1
  else:
    f = int(x[2]) - 1
    a[i ^ f].append(x[4])
print(''.join(reversed(a[i])) + (s[::-1] if i else s) + ''.join(a[i^1]))

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

int main()
{
  int A,B;
  cin >> A >> B;
  
  int sum = 0;

  for (int i = A; i <= B; i++) {
    int a = i % 10; //12345 5
    int b = i / 10000; //12345 1

    int c = i / 10 % 10; //12345 4
    int d = i / 1000 % 10; //12345 2

    if ( a == b && c == d) {
      sum++;
    }
  }

  cout << sum << endl;

}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
int n,x,y,z,nw;
const int mod=1e9+7;
int S,f[45][1<<17],ans=1;
int main()
{
	scanf("%d",&n);
	scanf("%d%d%d",&x,&y,&z);
	for (int i=1;i<=n;i++) ans=1ll*ans*10%mod;
	nw=(1<<x-1)|(1<<x+y-1)|(1<<x+y+z-1);
	S=(1<<x+y+z)-1;
	f[0][0]=1;
	for (int i=1;i<=n;i++)
		for (int j=0;j<=S;j++)
		{
			for (int k=1;k<=10;k++)
			{
				int T=(j<<k)|(1<<k-1);
				T&=S;
				if ((T&nw)!=nw) f[i][T]=(f[i][T]+f[i-1][j])%mod;
			}
		}
	for (int i=0;i<=S;i++) ans=(ans-f[n][i]+mod)%mod;
	printf("%d",ans);
} 

Measured memory_bytes: 22272
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
#define PB push_back
#define MP make_pair
#define REP(i,n) for(int i=0;i<(n);i++)
int main(){
    string s;
    cin>>s;
    string ss=s;
    reverse(ss.begin(),ss.end());
    if(s==ss)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using vv = vector<vector<ll>>;
using edge = struct {
  int to;
  int cost;
};
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end());
#define MIN(vec) *std::min_element(vec.begin(), vec.end());
#define BIT(n, num) std::bitset<(n)>((num)).to_string()
#define REV(T) greater<T>()

typedef pair<ll, ll> Pair;
bool pairCompare(const Pair &firstElof, const Pair &secondElof) {
  return firstElof.second > secondElof.second;
}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

map<ll, int> prime_factor(ll n) {
  map<ll, int> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1)
    ret[n] = 1;
  return ret;
}

ll factorial(int n) {
  ll ans = 1;
  for (int i = 2; i <= n; i++) {
    ans *= i;
    ans %= MOD;
  }
  return ans;
}
ll P(int n, int m) {
  ll ans = 1;
  for (int i = m + 1; i <= n; i++) {
    ans *= i;
    ans %= MOD;
  }
  return ans;
}
ll power(int n, int m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = power(n, m / 2);
    return (tmp * tmp) % MOD;
  } else {
    return (n * power(n, m - 1)) % MOD;
  }
}
ll C(int n, int m) {
  return (P(n, n - m) * power(factorial(m), MOD - 2)) % MOD;
}
ll GCD(ll a, ll b) {
  if (b == 0)
    return a;
  return GCD(b, a % b);
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  string S;
  ll count0 = 0;
  ll count1 = 0;
  cin >> S;
  REP(i, S.size()) {
    if (S[i] == '1')
      count1++;
    else
      count0++;
  }
  cout << min(count0, count1) * 2 << endl;
  return 0;
}


Measured memory_bytes: 512
// A. 

#include <iostream>
#include <algorithm>
#include <sstream>
#include <cstdio>
#include <cstring>

using namespace std;

int main(int argc, char *argv[])
{
	int H, W;
	string b[16];
	cin >> H >> W;
	for (int i = 0; i < H; ++i) {
		cin >> b[i];
	}
	bool ans = true;
	int r = 0, c = 0;
	while (true) {
		b[r][c] = '.';
		if (r == H - 1 && c == W - 1) {
			break;
		}
		if (c < W - 1 && b[r][c + 1] == '#') {
			++c;
		} else if (r < H - 1 && b[r + 1][c] == '#') {
			++r;
		} else {
			ans = false;
			break;
		}
	}
	for (int i = 0; i < H; ++i) {
		if ((int)b[i].find('#') >= 0) {
			ans = false;
		}
	}
	cout << (ans ? "Possible" : "Impossible") << endl;
	return 0;
}


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

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

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

#define x1 gray_cat_x1
#define y1 gray_cat_y1

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

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

#define file "I1"

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

const int MAXV = 2e5 + 5, MAXN = 205;

int v[MAXN];
ll dp[MAXV];
int cnt[MAXV];

ll a[MAXN][MAXN];

void solve(){
	int n, x;
	scanf("%d%d", &n, &x);
	REP(i, 0, n) {
		scanf("%d", &v[i]);
		cnt[v[i]]++;
	}
	sort(v, v + n);
	REP(i, 1, MAXV) {
		cnt[i] += cnt[i - 1];
	}
	
	REPN(i, 0, n) {
		a[i][0] = 1;
		REPN(j, 1, i) {
			a[i][j] = (a[i][j - 1] * (i + 1 - j)) % MOD;
		}
	}
	
	dp[x] = a[n][n - cnt[x]];
	for(int i = x; i >= 0; i--) {
		if (dp[i] == 0) {
			continue;
		}
		REP(k, 0, n) {
			if (v[k] > i) {
				continue;
			}
			int rem = i % v[k];
			ll add = (dp[i] * a[cnt[i] - 1][cnt[i] - cnt[rem] - 1]) % MOD;
			if (add) {
				//printf("%d - %d: %d %d +%lld\n", i, rem, cnt[i] - 1, cnt[i] - cnt[rem] - 1, add);
				dp[rem] = (dp[rem] + add) % MOD;
			}
		}
	}
	ll ans = 0ll;
	REPN(i, 0, min(x, v[0] - 1)) {
		ans = (ans + i * dp[i]) % MOD;
	}
	
	/*REPN(i, 0, x) {
		if (dp[i]) {
			printf("%d %lld\n", i, dp[i]);
		}
	}*/
	
	cout << ans << endl;
}   

int main(){

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


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

int main() {
  int N;
  cin >> N;
  
  vector<int> P(N);
  
  int min = 1000000;
  int count=0;
  
  for(int i=0;i<N;i++){
    cin >> P.at(i);
    
    if(min>P.at(i)){
      count++;
      min = P.at(i);
    }
  }
  
  cout << count << endl;  
}

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

using namespace std;
using ll = long long;

const ll nax = 1e4 + 12;
const ll md = 1e9 + 7;

ll dp[nax][123][2];
ll n, d;
string s;

ll add (ll &a, ll b)
{
  a += b;
  if (a > md) {
    a -= md;
  }
}

ll sub (ll &a, ll b)
{
  a -= b;
  if (a < 0) {
    a += md;
  }
}

ll solve (ll pos, ll rem, ll f)
{
  if (pos == n) {
    return (rem == 0);
  }
  if (dp[pos][rem][f] != -1) {
    return dp[pos][rem][f];
  }
  ll ans = 0;
  ll limit = 0;
  if (f == 1) {
    limit = 9;
  } else {
    limit = s[pos] - '0';
  }
  for (ll i = 0; i <= limit; i++) {
    ll nf = f;
    if (f == 0 && i < limit) {
      nf = 1;
    }
    ll new_rem = (rem + i) % d;
    add (ans, solve (pos + 1, new_rem, nf) );
  }
  return dp[pos][rem][f] = ans;
}

int main()
{
  ios_base::sync_with_stdio (0);
  cin.tie (0);
  memset (dp, -1, sizeof (dp) );
  cin >> s >> d;
  n = (ll) s.length();
  ll ans  = solve (0, 0, 0);
  sub (ans, 1LL);
  cout << ans << '\n';
  return 0;
}


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

#define mp make_pair
#define sz(x) ((int)((x).size()))
#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int , int > ipair;
typedef pair < ll , ll > lpair;
const int IINF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const double DINF = numeric_limits<double>::infinity();
const int MOD = 1000000007;
const double EPS = 1e-9;
const int DX[] = { 1,  0, -1,  0,  1, -1,  1, -1};
const int DY[] = { 0,  1,  0, -1,  1, -1, -1,  1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll sqr(ll x) { return x*x; } ll sqr(int x) { return (ll)x*x; }
double sqr(double x) { return x*x; } ld sqr(ld x) { return x*x; }
mt19937 mmtw(960172);
ll rnd(ll x, ll y) { static uniform_int_distribution<ll> d; return d(mmtw) % (y - x + 1) + x; }

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

const int N = 100179;

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

    int n, m;
    cin >> n >> m;
    vector < vector<int> > e(n);
    for (int i = 0; i < m; ++i) {
        int x, y;
        cin >> x >> y;
        --x;
        --y;
        e[x].push_back(y);
        e[y].push_back(x);
    }

    vector < int > col(n);
    int w[2] = {0,0};
    function < void(int, int) > dfs = [&](int v, int cc) {
        if (col[v]) {
            if (col[v] != cc) {
                cout << 1LL*n*(n-1)/2 - m << "\n";
                exit(0);
            }
            return;
        }
        col[v] = cc;
        ++w[cc-1];
        for (int nv : e[v])
            dfs(nv, 3-cc);
    };
    dfs(0, 1);

    cout << 1LL*w[0]*w[1] - m << "\n";

    return 0;
}


Measured memory_bytes: 6656
#include <bits/stdc++.h>
        #define endl '\n'
        #define modulo 1000000007
       // #define int long long
        //#define __int128 long long
        #pragma GCC optimize("-Ofast")
        #define float double
        #define PI 3.141592653589793238462643383279502884
        #define sinDegrees(x) sin((x) * PI / 180.0)
        #define tanDegrees(x) tan((x) * PI / 180.0)
        #define atanDegrees(x) atan(x)* 180.0 / PI
        #define f first
       // #define s second
        using namespace std;
        int power(int x,int y,int m)
        {
        int temp;
        if(y == 0)
        return 1;
        temp = (power(x, y/2,m))%m;
        if (y%2 == 0)
        return ((temp%m)*temp);
        else
        return ((x*temp%m)*temp%m)%m;
        }
        int inv(int x)
        {
        return (power(x,modulo-2,modulo))%modulo;
        }
        bool comp(pair<int,int>a,pair<int,int>b)
        {
            if(a.second==b.second)
            return a.first<b.first;
            return a.second<b.second;
        }
        set<vector<int>>total;
        int maxer;
        void calculate(vector<int>n){
        set<int>buff;
        if(n.size()==maxer){
        total.insert(n);
        return;
        }
        for(int i=0;i<n.size();i++)
        buff.insert(n[i]);
        for(int i=0;i<maxer;i++)
        if(buff.find(i)==buff.end()){
        n.push_back(i);
        calculate(n);
        n.pop_back();
        }
        }
        ///Solution created by:Ahmadsm2005
        int32_t main()
        {
            //freopen("output.txt","w", stdout);
            //freopen("input0.txt","r", stdin);
            iostream::sync_with_stdio(0);
            cin.tie(0);
            cout.tie(0);
            int n;
            cin>>n;
            vector<int>filter;
            for(int i=1;i<=n;i++){
            if(i<10)
            filter.push_back(i*10+i);
            else{
            int buff=i,last=i%10;
            while(buff>=10){
            buff/=10;
            }
            filter.push_back(buff*10+last);
            }
            }
            map<int,int>lol;
            for(int i=0;i<filter.size();i++)
            if(lol.find(filter[i])==lol.end())
            lol.insert({filter[i],1});
            else
            lol.at(filter[i])++;
            int counter=0;
            for(int i=0;i<filter.size();i++){
            if(lol.find((filter[i]%10)*10+((filter[i]/10)%100))!=lol.end()){
            counter+=lol.at((filter[i]%10)*10+((filter[i]/10)%100));
            }
            //cout<<counter<<endl;
            }
            cout<<counter;
            return 0;
        }


Measured memory_bytes: 1400
"""
https://atcoder.jp/contests/abc167/tasks/abc167_b
"""
import numpy as np
from numba import jit


@jit(nopython=True, parallel=False)
def calc(A: int, B: int, C: int, K: int) -> int:
    if A >= K:
        return K
    if A + B >= K:
        return A
    return A - (K - (A + B))


def load_input_as_int_array() -> np.ndarray:
    return np.array([int(v) for v in input().split(" ")])


def main() -> None:
    A, B, C, K = load_input_as_int_array()
    result = calc(A, B, C, K)
    print(result)
    # print("Yes" if result else "No")


main()


Measured memory_bytes: 107776
#include <bits/stdc++.h>
using namespace std;
int main(){
	vector <int> a;
	for (int i = 0; i < 3; i++){
		int x; cin >> x;
		a.push_back(x);
	} 
	sort(a.begin(), a.end());
	cout << a[0] +a[1] << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, string> P;
typedef tuple<int, string, string> T;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int a;

int solve() {
    return a + a * a + a * a * a;
}

void input() {
    cin >> a;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 3588
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  int n;
  cin >> n;
  int h[n];
  rep(i,n)cin >> h[i];
  int ans=0;
  rep(i,n){
    if(i==0)ans++;
    else{
      bool ok=true;
      rep(j,i){
        if(h[j]>h[i])ok=false;
      }
      if(ok)ans++;
    }
  }
  cout << ans << endl;
return 0;}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <iostream>
using namespace std;
typedef long long ll;

#ifdef MUTABLE
int mod;
#else
template<int mod>
#endif
struct ModInt {
  int val;
  ModInt inv() const{
    int tmp,a=val,b=mod,x=1,y=0;
    while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
    return ModInt(x);
  }
  ModInt():val(0){}
  ModInt(ll x){if((val=x%mod)<0)val+=mod;}
  ModInt pow(ll t){ModInt res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;}return res;}
  ModInt& operator+=(const ModInt& x){if((val+=x.val)>=mod)val-=mod;return *this;}
  ModInt& operator-=(const ModInt& x){if((val+=mod-x.val)>=mod)val-=mod; return *this;}
  ModInt& operator*=(const ModInt& x){val=(ll)val*x.val%mod; return *this;}
  ModInt& operator/=(const ModInt& x){return *this*=x.inv();}
  bool operator==(const ModInt& x) const{return val==x.val;}
  bool operator!=(const ModInt& x) const{return val!=x.val;}
  bool operator<(const ModInt& x) const{return val<x.val;}
  bool operator<=(const ModInt& x) const{return val<=x.val;}
  bool operator>(const ModInt& x) const{return val>x.val;}
  bool operator>=(const ModInt& x) const{return val>=x.val;}
  ModInt operator+(const ModInt& x) const{return ModInt(*this)+=x;}
  ModInt operator-(const ModInt& x) const{return ModInt(*this)-=x;}
  ModInt operator*(const ModInt& x) const{return ModInt(*this)*=x;}
  ModInt operator/(const ModInt& x) const{return ModInt(*this)/=x;}
  static int get_mod() { return mod; }
};

#ifndef MUTABLE
using modint = ModInt<1000000007>;
#endif

template< typename T >
struct Edge {
  int from, to;
  T cost;
  Edge() {}
  Edge(int f, int t) : from(f), to(t), cost(1) {}
  Edge(int f, int t, T c) : from(f), to(t), cost(c) {}
  friend bool operator < (const Edge& lhs, const Edge& rhs) { return lhs.cost < rhs.cost; };
  friend bool operator > (const Edge& lhs, const Edge& rhs) { return rhs < lhs; };
  friend bool operator <= (const Edge& lhs, const Edge& rhs) { return !(lhs > rhs); };
  friend bool operator >= (const Edge& lhs, const Edge& rhs) { return !(lhs < rhs); };
};

template< typename T >
using Edges = std::vector< Edge< T > >;
template< typename T >
using Graph = std::vector< Edges< T > >;


typedef long long ll;

int k;
modint dfs(const Graph<int>& g, int s, int par, int depth) {
  modint ret = 1;
  int cnt = k-min(2, depth);
  for (auto &e: g[s]) {
    if (e.to == par) continue;
    ret *= cnt;
    --cnt;
    ret *= dfs(g, e.to, s, depth+1);
  }
  return ret;
}

int main() {
  int n; cin >> n >> k;
  Graph<int> g(n);
  for (int i = 0; i < n-1; ++i) {
    int a, b;
    cin >> a >> b; --a; --b;
    g[a].emplace_back(a, b);
    g[b].emplace_back(b, a);
  }
  modint ans = dfs(g, 0, -1, 1);
  ans *= k;
  cout << ans.val << endl;
}



Measured memory_bytes: 12800
#include <stdio.h>
#define rep(i,n) for(int i =0; i<(int)(n); i++)

int main(){
  int N;
  char mix[400];
  char S[110];
  char T[110];

  scanf("%d", &N);
  scanf("%s %s", S, T);

  rep(i,2*N){
    if(i %2 ==0){
      mix[i] = S[i/2];
    }else{
      mix[i] = T[(i-1)/2];
    }
  }
  mix[N*2]='\0';

  printf("%s\n", mix);

  /*
  rep(i,N){
    printf("%c%c",S[i],T[i]);
  }という方法もある*/

  return 0;
}

Measured memory_bytes: 128
import random

D = int(input())
C = list(map(int,input().split()))
S = []
for i in range(D):
    S.append(list(map(int,input().split())))
t = [1]*365
lastds = [0]*26
satisfaction = [0]*D
for d in range(D):
    ans = 0
    for j in range(1,27):
        if d != 0:
            satisfaction[d] = satisfaction[d-1]
        else:
            satisfaction[d] = 0
        escape = lastds[j-1]
        lastds[j-1] = d+1
        satisfaction[d] += S[d][j-1]
        for i in range(26):
            satisfaction[d] -= C[i] * (d+1-lastds[i])
        if ans < satisfaction[d]:
            ans = satisfaction[d]
            t[d] = j
        lastds[j-1] = escape
    lastds[t[d]-1] = d+1
    print(t[d])


Measured memory_bytes: 78828
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>

#define pb push_back
#define mp make_pair

using namespace std;

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

int main() {
  vi d;
  for (int i = 0; i < 5; ++i) {
    int t;
    cin >> t;
    d.pb(t);
  }

  sort(d.begin(), d.end());

  int min_res = 100000;
  do {
    int t = 0;
    for (int i = 0; i < 5; ++i) {
      t += d.at(i);
      if (i != 4) {
        if (t % 10 != 0) {
          t += (10-(d.at(i)%10));
        }
      }
    }
    min_res = min(min_res, t);
  } while (next_permutation(d.begin(), d.end()));

  cout << min_res << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7+1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n,m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/



ll num[5];

int main()
{
	while (1) {
		cnt = 0;
		REP(i, 5)
		{
			cin >> num[i];
			if (num[i] == 0) {
				cnt++;
			}
		}
		if (cnt == 5) {
			return 0;
		} else {
			ll a[1000];
			fill(a, a + 1000, 0);
			REP(i, num[0])
			{
				cin >> a[i];
			}

			ll r = num[4];
			ll count = 0;
			ll j = 0;
			while (1) {
				if (count > 10000) {
					count = -1;
					break;
				}
				if (r == a[j]) {
					j++;
				}
				if (j == num[0]) {
					break;
				}
				r = (num[1] * r + num[2]) % num[3];
				count++;
			}
			cout << count << endl;
		}
	}
}

Measured memory_bytes: 3128
import sys

alphabets = range(ord('a'), ord('z') + 1)
dic = { chr(c): 0 for c in alphabets }

text = sys.stdin.read()
for c in text:
  c = c.lower()
  if ord(c) in alphabets:
    dic[c] += 1

for c, n in sorted(dic.items()):
  print(c, ":", n)

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

//pdf見て回答

int main(){
    ll a, b, c, k; cin >> a >> b >> c >>k;
    ll x, y, z;
    
    if(k mod 2 == 0){
        cout << a - b << endl;
    }else{
        cout << b - a << endl;
    }


    /*
    rep(i,k){
        x = b + c;
        y = a + c;
        z = a + b;

        a = x; b = y; c = z;
    }

    if(abs(a - b) < 1e18){
        cout << a - b;
    }else{
        cout << "Unfair";
    }
    cout << endl;
    */
}

Measured memory_bytes: 256
import bisect
import sys
import math
import itertools
sys.setrecursionlimit(10000)

INF = float('inf')

# input macro
def i():
    return int(raw_input())
def ii():
    return map(int,raw_input().split(" "))
def s():
    return raw_input()
def ss():
    return raw_input().split(" ")
def slist():
    return list(raw_input())
#

def join(s):
    return ''.join(s)

#iterate macro
def piter(n,m):
    return itertools.permutations(n,m)
def citer(n,m):
    return itertools.combinations(n,m)

#modulo macro
def modc(a,b,m):
    c = 1
    for i in xrange(b):
        c = c * (a - i) % m
        c = c * modinv(i + 1,m) % m
    return c
 
def gcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)
 
def modinv(a, m):
    (inv, q, gcd_val) = gcd(a, m)
    return inv % m

#bisect macro
def index(a, x):
    #Locate the leftmost value exactly equal to x
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    return -1

#memoize macro
def memoize(f):
    cache = {}
    def helper(*args):
        if args not in cache:
            cache[(args)] = f(*args)
        return cache[args]
    return helper

@memoize
def nck(a,b,m):
    b = min([a-b,b])
    if (b>a or b<0 or a<0):
        return 0
    elif a == 0:
        return 1
    return (nck(a-1,b-1,m)+nck(a-1,b,m)) % m

nh=zip([1,0,-1,0],[0,1,0,-1])

###########

s=slist()
g=s.count('g')
p=s.count('p')
print (g-p)/2


Measured memory_bytes: 3712
from collections import deque
N,M,*AB=map(int,open(0).read().split())
to=[[] for _ in range(N+1)]
for a,b in zip(*[iter(AB)]*2):
  to[a].append(b)
  to[b].append(a)
q=deque([1])
r=[None]*(N+1)
while q:
  x=q.popleft()
  for i in to[x]:
    if r[i] is None:
      q.append(i)
      r[i]=x
print("Yes",*r[2:],sep="\n")

Measured memory_bytes: 56848
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
using namespace std;

const double EPS = 1e-9;

//æØè¶ÅæØéB
//s=üÍ,t=æØè¶
std::vector<string> splitAll(string s,string t){

  std::vector<string> v;

  for(int p=0; (p = s.find(t)) != s.npos; ){
    v.push_back(s.substr(0,p));
    s=s.substr(p+t.size());
  }
  v.push_back(s);

  return v;
}


int main() {

  string s;
  while(getline(cin,s)){
    if( s=="" ) break;
    vector<string> v;
    v = splitAll(s,",");
    double w = atof( v[1].c_str() );
    double h = atof( v[2].c_str() );
    if( (w/(h*h) - 25.0) > -EPS ) {
      cout<<v[0]<<endl;
    }
  }
}

Measured memory_bytes: 0