akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define fi first
#define se second

const int mx = 1234567;
const int md = 1e9+7;
const int inf= 1e100;
const double eps = 1e-6;
const double pi = acos(-1.0);

typedef long long ll;

int dr[8] = {-1,-1,+0,+1,+1,+1,+0,-1};// counter clockwise
int dc[8] = {+0,-1,-1,-1,+0,+1,+1,+1};
int dr4[4] = {-1,+1,+0,+0};//UDLR
int dc4[4] = {+0,+0,-1,+1};

int ar[mx],xar[mx],uses[mx];
ll arr[mx];
int tab[1000][1000];
string st[1000];
int ar1[mx],ar2[mx],ar3[mx],ar4[mx];

void solve(){
	int n, m;
	int r,g,b,k;
	scanf("%d%d%d",&r,&g,&b);
	scanf("%d",&k);
	int op = 0;
	while(r >= g){
        g = g * 2;
        op++;
	}
	while(g >= b){
        b = b * 2;
        op++;
	}
	if(op <= k) cout<<"Yes\n";
	else cout<<"No\n";

}

int main(){
    int tk = 1,cs = 0;
//    freopen("in.txt","r", stdin);
//    freopen("out.txt","w", stdout);

//    scanf("%d",&tk);
    while(tk--)
        solve();
    return 0;
}


Measured memory_bytes: 3840
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);


    string S;
    string T;
    cin >> S >> T;

    int res = 0;
    for (int i = 0; i < S.length(); ++i) {
        if (S[i] != T[i]) {
            ++res;
        }
    }

    cout << res << '\n';
    
    return 0;
}

Measured memory_bytes: 3812
# -*- coding: utf-8 -*-
"""
D - Handstand
https://atcoder.jp/contests/abc124/tasks/abc124_d
WA
"""
import sys


from itertools import groupby
from collections import deque

def solve(N, K, S):
    seq = [[k, len(list(g))]  for k, g in groupby(S)]
    if len(seq) <= 2*K:
        return len(S)
    if seq[0][0] == '0':
        seq = [['1', 0]] + seq
    if len(seq) % 2 == 0:
        seq.append(['1', 0])

    seq = deque(seq)
    rem = deque()
    ans = 0
    for i in range(2*K+1):
        _, v = seq.popleft()
        ans += v
        rem.append(v)

    max_ans = ans
    while seq:
        _, v = seq.popleft()
        ans += v
        rem.append(v)
        ans -= rem.popleft()
        _, v = seq.popleft()
        ans += v
        rem.append(v)
        ans -= rem.popleft()
        max_ans = max(max_ans, ans)
    return max_ans


def main(args):
    N, K = map(int, input().split())
    S = input()
    ans = solve(N, K, S)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 14828
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < int(n); ++i)
#define REPE(i, a, b) for (int i = (a); i <= int(b); ++i)
#define SZ(x) ((int)(x).size())
#define ALL(x) x.begin(), x.end()
#define PB push_back
#define EB emplace_back
using LL = long long;
using PII = pair<int, int>;
#define F first
#define S second

int main() {
  long long a, b;
  cin >> a >> b;
  long long ans = min(a, b / 2);
  a -= ans;
  b -= ans * 2;
  ans += b / 4;
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n;
    
    while (cin >> n, n) {
        int res = 32;
        int jirou[25];
        int cnt = 0;

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

        while (true) {
            res -= (res - 1) % 5;
            cout << res << endl;

            res -= jirou[cnt];
            cnt = (cnt + 1) % n;
            if (res < 1) {
                cout << 0 << endl;
                break;
            }
            
            cout << res << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1160
N,M = [int(x) for x in input().split()]
li = [0]*(M+1)
for _ in range(N):
    li2 = [int(x) for x in input().split()]
    for index,i in enumerate(li2):
        if(not index == 0):
            li[i]+=1
counter = 0
for i in li:
    if(i == N):
        counter+=1
print(counter)


Measured memory_bytes: 3060
#![allow(non_snake_case)]
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;

fn main() {
    input!{
        _: usize,
        s: String,
    }

    let mut d: Vec<isize> = vec![0];

    for c in s.chars() {
        if c == '(' {
            d.push(d.last().unwrap() + 1)
        } else {
            d.push(d.last().unwrap() - 1)
        }
    }

    let min = *d.iter().min().unwrap();
    // dbg!(&min);
    let left = format!("{}", "(".repeat(min.abs() as usize));
    let right = format!("{}", ")".repeat((*d.last().unwrap() - min) as usize));
    println!("{}{}{}", left, s, right)
}


Measured memory_bytes: 2128
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;
  if(N<105)cout<<"0"<<endl;
  else if(N<135)cout<<"1"<<endl;
  else if(N<165)cout<<"2"<<endl;
  else if(N<189)cout<<"3"<<endl;
  else if(N<195)cout<<"4"<<endl;
  else cout<<"5"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;
int main() {
  int N;
  double power = 1.0;
  cin >> N;
  for (int i=1;i<=N;++i) {
    power *= i;
    power = fmod(power, 1000000007);
  }
  cout << int(power) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL v,e;

void dfs(LL i,vector<int> adj[],LL vis[],LL dp[])
{
    vis[i]=1;

    for(LL j=0;j<adj[i].size();j++)
    {
        if(vis[adj[i][j]]==0)
            dfs(adj[i][j],adj,vis,dp);
        //cout<<i<<" "<<adj[i][j]<<endl;
        dp[i]=max(dp[i],dp[adj[i][j]]+1);

    }

}


LL longestPath(vector<int> adj[])
{
    LL dp[v+1],vis[v+1];
    for(LL i=0;i<=v;i++){
        dp[i]=0;vis[i]=0;
    }

    for(LL i=1;i<=v;i++)
    {
        if(vis[i]==0)
        {
            dfs(i,adj,vis,dp);
        }

    }
    LL maxx=INT_MIN;
    for(LL i=1;i<=v;i++)
    {
        if(maxx<dp[i])
            maxx=dp[i];
    }

     /*for(LL i=1;i<=v;i++)
    {
        cout<<dp[i]<<" ";
    }
cout<<endl;*/

   return maxx;


}



int main()
{

    cin>>v>>e;

    vector<int> adj[v+1];

    for(LL i=0;i<e;i++)
    {
        LL u,v;
        cin>>u>>v;
        adj[u].push_back(v);
    }

    cout<<longestPath(adj);
    return 0;




}


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

const ll mod = 1e9+7;
const int maxn = 1e5+7;
ll sum[27];

int main (){
    int n;cin>>n;
    string s;cin>>s;
    memset(sum,0,sizeof(sum));
    for(int i=0;i<n;i++) sum[s[i]-'a']++;
    ll ans=1;
    for(int i=0;i<=26;i++) ans=ans*(sum[i]+1)%mod;
    ans=(ans-1+mod)%mod;
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 512
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc = new Scanner(System.in);
        int n;
        int i= 0;
        n= sc.nextInt();
        int sum=0;
        int [] price = new int[n];
        while(i<n)
        {
            price[i] = sc.nextInt();
            i++;
        }
        Arrays.sort(price);
        
        for(i=n-1;i>=0;i--)
        {
            if(i==n-1)
            {
                price[i]=price[n-1]/2;
                
            }
            sum = sum + price[i];  
          
        }
        
        System.out.println(sum);
        
    }

}

Measured memory_bytes: 23124
// g++ -I ~/Documents/programming/cppLib -std=gnu++14 -o test ~/Documents/programming/cppLib/test.cpp && ./test && rm test
#include <bits/stdc++.h>
using namespace std;
template <typename T> using vector2 = vector <vector  <T>>;
template <typename T> using vector3 = vector <vector2 <T>>;
template <typename T> using vector4 = vector <vector3 <T>>;
using lint = long long;
#define FOR( i, a, b ) for( lint i=(a) ; i <= (b) ; ++i )
#define REP( i, n )    for( lint i= 0  ; i <  (n) ; ++i )
#define ALL( v )       (v).begin(), (v).end()
#define MOD            1000000007

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

    vector<bool> A(N, false);
    REP( i, M ) {
        int a;
        cin >> a;
        A[a] = true;
    }

    vector<int> dp(N);
    dp[0] = 1;
    dp[1] = A[1] ? 0 : 1;

    for( int i=2; i<N; i++ ) {
        dp[i] = (dp[i-1] + dp[i-2]) % MOD;
        dp[i] = A[i] ? 0 : dp[i];
    }

    cout << (dp[N-1] + dp[N-2]) % MOD << endl;

}


Measured memory_bytes: 640
import java.util.*;
 
public class Main{
  public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    
    int k = sc.nextInt();
    int s = sc.nextInt();
    int count = 0;
    
    for(int x=0; x<=k; x++){
      for(int y=0; y<=k; y++){
        int z=s-x-y;
        if(0<=z && z<=k){
          count++;
        }
      }
    }
    
    System.out.println(count);
  }
}
 
 
      
  

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

using namespace std;

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

#define int ll

const ll mod = 1e9 + 7;


main(){
	int n;

	cin >> n;

	for(int i=0;i<=500000;i++){
		if(int(1.08*(double)i) == n){
			cout << i << endl;
			return 0;
		}
	}

	cout << ":(" << endl;
	

	return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>
int c, p, l, lp;
long long r;
int main() {
  for(; (c = getchar_unlocked()) != EOF && c > ' '; r += ++l) if(c != p) {
    if(c == '<')
      r -= l < lp ? l : lp;
    p = c; lp = l; l = 0;
  }
  if(p == '>')
    r -= l < lp ? l : lp;
  printf("%lld\n", r);
  return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <unordered_set>
const int MAXA = 26;
const int MAXS = 4;
const int TWO = 2;
int cnt[MAXA]{ };
char S[MAXS + 5];

int main() {
  scanf("%s", S);
  int two = 0;
  for (int i = 0; i < MAXS; ++i) {
    int c = S[i] - 'A';
    ++cnt[c];
    if (cnt[c] == TWO) {
      ++two;
    } else if (cnt[c] > TWO) {
      --two;
    }
  }
  puts((two == TWO) ? "Yes" : "No");
  return 0;
}

Measured memory_bytes: 128
#pragma comment(linker, "/STACK:500000000")
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <exception>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <time.h>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;

typedef long long ll;
const double PI = acos(-1.0);
const double EPS = 1e-9;
const int INF = static_cast<int>(2e9);

const int N = static_cast<int>(1e5);
vector<int> a[N + 9];
bool used[N + 9][11];
int v[N + 9];
int d[N + 9];
int c[N + 9];
int ans[N + 9];
 
void dfs(int node, int distLeft, const int color) {
	if (!ans[node]) {
		ans[node] = color;
	}
	used[node][distLeft] = true;
	if (distLeft == 0) {
		return;
	}
	for (int i = 0; i < a[node].size(); ++i) {
		int to = a[node][i];
		if (!used[to][distLeft - 1]) {
			dfs(to, distLeft - 1, color);
		}
	}
}
 
int main() {
	//freopen("in.txt", "rt", stdin);
	//freopen("out.txt", "wt", stdout);
	int n, m;
	scanf("%d %d", &n, &m);
	while (m--) {
		int u, v;
		scanf("%d %d", &u, &v);
		--u;
		--v;
		a[u].push_back(v);
		a[v].push_back(u);
	}
	int q;
	scanf("%d", &q);
	for (int i = 0; i < q; ++i) {
		scanf("%d %d %d", &v[i], &d[i], &c[i]);
		--v[i];
	}
	for (int i = q - 1; i >= 0; --i) {
		if (!used[v[i]][d[i]]) {
			dfs(v[i], d[i], c[i]);
		}
	}
	for (int i = 0; i < n; ++i) {
		printf("%d\n", ans[i]);
	}
	return 0;
}

Measured memory_bytes: 9080
#include <iostream>

using namespace std;

int N;
int a[105];
int C[10];

int main(void) {

	cin >> N;

	for (int i = 1; i <= N; i++) {
		cin >> a[i];
	}

	for (int i = 1; i <= N; i++) {

		if (a[i] < 400) { C[0]++; }
		for (int j = 1; j <=7; j++) {
			if (400 * j <= a[i] && a[i] < 400 * (j + 1)) { C[j]++; }
		}
		if (a[i] >= 3200) { C[8]++; }
	}

	int min_val = 0;
	for (int i = 0; i <= 7; i++) { if (C[i]) { min_val++; } }

	
	if (min_val != 0) {
		cout << min_val << " " << min_val + C[8] << endl;
	}
	else {
		cout << 1 << " " << C[8] << endl;
	}

	/*for (int i = 0; i <= 8; i++) {
		cout << "a[" << i << "]= " << C[i] << endl;
	}*/

	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define r(i,n) for(int i=0;i<n;i++)
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(c>=a&&c<=b)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
function main(input) {
    
    var aa=input.indexOf("a");
    var bb=input.indexOf("b");
    var cc=input.indexOf("c");

  if(aa==-1 || bb==-1 || cc==-1){
  console.log("No");
  }else{
    console.log("Yes");
}
}
  main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 11468
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <fstream>

using namespace std;

int dfs (const int depth, const int sum, int currs, int currd, int j)
{
	int count = 0;
	int i;

	if (currd == depth ){
		if (sum == currs ){
			return 1;
		}else{
			return 0;
		} // end if
	} // end if
	
	for (i = min(j, sum ); i >= 0; --i){
		currs += i;
		count += dfs (depth, sum, currs, currd + 1, i - 1 );
		currs -= i;
	} // end for

	return count;
}

int main()
{
//	cut here before submit 
//	freopen("testcase.si", "r", stdin);
	string str = "";

	while (getline (cin, str ) ){
		int n, sum;
		int res = 0;
		stringstream ss(str);
		ss >> n >> sum;

		if (n == 0 && sum == 0){
			break;
		} // end if
		
		res = dfs (n, sum, 0, 0, 9 );

		cout << res << endl;
	} // end while
	
	return 0;
}

Measured memory_bytes: 0
# include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
template<typename T>vector<T> make_v(size_t a){ return vector<T>(a); }
template<typename T,typename... Ts>auto make_v(size_t a, Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template<typename T,typename V>typename enable_if<is_class<T>::value==0>::type fill_v(T &t, const V &v){ t = v; }
template<typename T,typename V>typename enable_if<is_class<T>::value!=0>::type fill_v(T &t, const V &v){ for(auto &e : t) fill_v(e, v); }
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

string s; int main(){  
       std::cin >> s;  
          long long ans = 0;  
             for(int bit = 0;bit < (1 << ((int)s.size() - 1));bit++){   
                       long long num = s[0] - '0';     
                           long long sum = 0;      
                              for(int i = 0;i < (int)s.size() - 1;i++){
                                               if(bit & (1 << i)){
                sum += num;           
                      num = 0;   
                                }       
                                      num = num * 10 + s[i + 1] - '0';         
                                      }
                                               sum += num;   
                                                     ans += sum;  
                                                        }    
                                                         std::cout << ans << std::endl; 
                                                         } 

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
//#define _USE_MATH_DEFINES
#include<stdio.h>
#include<stdlib.h>
//#include<math.h>
#include<string.h>
//#include<time.h>
//#define pi acos(-1.0)
#define P(type,x) fprintf(stdout,"%"#type"\n",x)

int main(){
	int n, m, i, a, b;
	int sum, max;
	fscanf(stdin, "%d%d", &n, &m);
	for (i = sum = max = 0; i < m; i++) {
		fscanf(stdin, "%d%d", &a, &b);
		if (n - a > 0) 	sum += n - a;
		if (n - a > max) max = n - a;
	}
	P(d, sum - max);
	return 0;
}

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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

constexpr int mod = 1e9 + 7;
constexpr int32_t inf = 1001001001;
constexpr int64_t infll = 1001001001001001001ll;
constexpr int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}, dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const string YES = "YES", NO = "NO", Yes = "Yes", No = "No", yes = "yes", no = "no";

// clang-format off
// ostream &operator<<(ostream &os, __int128_t value) { if (ostream::sentry(os)) { __uint128_t tmp = value < 0 ? -value : value; char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
// istream &operator>>(istream &is, __int128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } if (in[0] == '-') value *= -1; return is; }
// ostream &operator<<(ostream &os, __uint128_t value) { if (ostream::sentry(os)) { char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[value % 10]; value /= 10; } while (value != 0); int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
// istream &operator>>(istream &is, __uint128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } return is; }
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { os << v[0]; for (int i = 1; i < v.size(); ++i) os << " " << v[i]; return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.fs << " " << p.sc; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.fs >> p.sc; return is; }

struct IoSetup { IoSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup;

inline int64_t in() { int64_t x = 0; cin >> x; return x; }

template <typename T> void sort(vector<T> &v) { sort(all(v)); }
template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

signed main(int argc, char *argv[]) {
  int n = in();
  vector<int> a(n);
  cin >> a;
  for (int i = 0; i < n; ++i) a[i] -= (i + 1);

  vector<int> b = a;
  sort(b);

  int64_t ans = 0;
  for (int i = 0; i < n; ++i) {
    ans += abs(a[i] - b[n / 2]);
  }

  cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
// #pragma GCC optimize("O3")

#define debug(var)  do{std::cerr << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cerr << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cerr << e << " "; } std::cerr << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ std::cerr << std::endl; for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> v1;
typedef vector<v1> v2;
typedef vector<v2> v3;

typedef unordered_map<ll, unordered_map<ll, ll>> graph;

const ll INF = 1ll << 50;
const ll mod = 1000000007;

ll k;
string s;
ll n;

// ll solve(ll k, ll n){
//     v2 dp = v2(n+k+1, v1(n+1, 0ll));
//     dp[0][0] = 1;
//     for(ll i = 1;i <= n+k; i++){
//         for(ll j = 0;j <= n;j++){
//             if(j < n) dp[i][j] += dp[i-1][j] * 25;
//             if(j-1 < n && j-1 >= 0) dp[i][j] += dp[i-1][j-1];
//             if(j == n) dp[i][j] += dp[i-1][j] * 26;
//             dp[i][j] %= mod;
//
//         }
//     }
//     return dp[k+n][n];
// }

ll factorial(ll n,ll mod=mod){
  static ll dp[4000000];
  static ll max_n=0;
  dp[0] = 1;
  while(n > max_n){
      dp[max_n+1] = dp[max_n]*(max_n+1) % mod;
      max_n++;
  }
  return dp[n];
}

ll powl(ll x,ll r,ll mod=mod){
  ll ret = 1;
  for(;r != 0;r >>= 1){
    if(r&1 != 0) ret *= x,ret %= mod;
    x *= x,x %= mod;
  }
  return ret;
}

ll inverse(ll x,ll mod=mod){
  return powl(x,mod-2,mod);
}

ll combination(ll n,ll m,ll mod){
  if(n < m) return 0;
  return (((factorial(n,mod)*inverse(factorial(m,mod),mod))%mod)*inverse(factorial(n-m,mod),mod))%mod;
}


ll solve2(ll k, ll n){
    ll ret = 0;
    for(ll i = n;i <= n+k;i++){
        ret += (combination(i-1, n-1, mod) * powl(25, i-n, mod) % mod) * powl(26, n+k-i) % mod;
        ret %= mod;
    }
    return ret;

}

int main(){
    cin >> k;
    cin >> s;
    n = s.size();
    cout << solve2(k, n) << endl;
}


Measured memory_bytes: 19996
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
#include <sstream>
#include <bitset>
#include <stack>
#include <cstdlib>

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

typedef long long ll;

using namespace std;

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
    
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {// 素数ではない
            return false;
        }
    }
    // 素数である
    return true;
}

int main() {
    
    int n;
    cin >> n;
    
    vector<int> ans(n,0);
    int i=1,j=0;
    while(ans[n-1]==0){
        int a;
        a = 1 + 10*i;
        if(IsPrime(a)){
            ans[j] = a;
            j++;
        }
        i++;
    }
    
    FOR(i, 0, n){
        cout << ans[i] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
import sys

InputText = ""
while True:
    try:
        InputText += input().lower()
    except:
        break

alphabet = [chr(i) for i in range(97,97+26)]
count = [0 for i in range(26)]

for i in range(len(InputText)):
    for j in range(26):
        if InputText[i] == alphabet[j]:
            count[j] = int(count[j]) + 1


for i in range(26):
    print(alphabet[i],":",count[i])

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

using namespace std;

int step;
int gcd(int a,int b){
  if(b==0)return a;
  step ++;
  return gcd(b,a%b);
}

int main(void){
  int a,b;
  while(cin>>a>>b,a+b){
    step = 0;
    cout<<gcd(max(a,b),min(a,b));
    cout<<" "<<step<<endl;
  }
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <math.h>
#include <string.h>

int main(){
  char s[ 101 ];
  unsigned long long int k;
  unsigned long long int i = 0;
  scanf( "%s", s );
  scanf( "%llu", &k );
  //scanf( "%d", &b );
  int j = 0;
  unsigned long long int one_num = 0;
  // for ( j = 0; j < 101; j++ ){
  //   if ( atoi( s[ j ] ) == 1 ){
  //     one_num++;
  //   }else
  //     break;
  // }
  one_num = strspn( s, "1" );
  //printf( "%llu\n", one_num );
  if ( k <= one_num ){
    printf( "1\n" );
    return 0;
  }

  char number;
  number = s[ one_num ];

  printf( "%c\n", number );
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define mod 1000000000
#define infll 1000000000000000000LL
#define pb push_back
#define sz(v) (v).size()
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define mp make_pair
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define REP(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
using namespace std;
template <typename T> void chmax(T &x,T y){x=x>y?x:y;return;}
template <typename T> void chmin(T &x,T y){x=x<y?x:y;return;}
typedef long long ll;
typedef unsigned long long ull;

int n,x[25],y[25],p[25],res[25][25];
ll ans[25];

void dfs(int i,int cnt)
{
	if(i>n)
	{
		ll ret=0;
		rep(j,1,n) ret+=ll(res[i][j])*ll(p[j]);
		chmin(ans[cnt],ret);
		return;
	}
	rep(j,1,n) res[i+1][j]=res[i][j];
	dfs(i+1,cnt);
	rep(j,1,n) res[i+1][j]=min(res[i][j],abs(x[i]-x[j]));
	dfs(i+1,cnt+1);
	rep(j,1,n) res[i+1][j]=min(res[i][j],abs(y[i]-y[j]));
	dfs(i+1,cnt+1);
	return;
}

int main()
{
	scanf("%d",&n);
	rep(i,1,n) scanf("%d%d%d",&x[i],&y[i],&p[i]);
	rep(i,1,n) res[1][i]=min(abs(x[i]),abs(y[i]));
	rep(i,0,n) ans[i]=infll;
	dfs(1,0);
	rep(i,0,n) printf("%lld\n",ans[i]);
	return 0;
}

Measured memory_bytes: 3820
#include <iostream>
#define llint long long
#define inf 1e18

using namespace std;

llint N;
llint A[200005], B[200005];

int main(void)
{
	cin >> N;
	for(int i = 1; i <= N; i++) cin >> A[i] >> B[i];
	
	bool flag = true;
	for(int i = 1; i <= N; i++) if(A[i] != B[i]) flag = false;
	if(flag){
		cout << 0 << endl;
		return 0;
	}
	
	llint ans = 0;
	llint sum = 0, mn = inf;
	for(int i = 1; i <= N; i++){
		sum += A[i];
		if(A[i] > B[i]) mn = min(mn, B[i]);
	}
	ans = sum - mn;
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#define eps 1e-8
#define zero(x) (((x)>0?(x):-(x))<eps)

#define pause cout << " press ansy key to continue...",  cin >> chh
#define file_r(x) freopen(x,  "r",  stdin)
#define file_w(x) freopen(x,  "w",  stdout)
#define lowbit(x) ((x) & (-x))
#define repit(i, c) for (__typeof__((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repe(i, u) for (int i = head[u]; i != -1; i = nxt[i])
#define repd(i, n) for (int i = (n - 1); i >= 0; i--)
#define FOR(i, n, m) for (int i = (n); i <= (m); i++)
#define FORD(i, n, m) for (int i = (n); i >= (m); i--)
#define pb push_back
#define X first
#define Y second
#define ins insert
#define rb rbegin
#define be begin
#define er erase
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define SZ(c) (c).size()
#define ALL(c) (c).begin(), (c).end()
#define sqr(r) ((LL) (r) * (r))
#define dis(x1, y1, x2, y2) (((x1) - (x2)) * ((x1) - (x2)) + ((y1) - (y2)) * ((y1) - (y2)))
#define FASTIO ios::sync_with_stdio(false);cin.tie(0)

#define sc(x) cout << #x" = " << x << endl, system("pause")
#define sc2(x, y) cout << #x" = " << x << " " << #y" = " << y << endl, system("pause")
#define sc3(x, y, z) cout << #x" = " << x << " " << #y" = " << y << " " << #z" = " << z << endl, system("pause")
#define sc4(x, y, z, w) cout << #x" = " << x << " " << #y" = " << y << " " << #z" = " << z << " " << #w" = " << w << endl, system("pause")
#define in(n) scanf("%d", &n)
#define in2(n, m) scanf("%d %d", &n, &m)
#define in3(x, y, z) scanf("%d %d %d", &x, &y, &z)

using namespace std;
int chh;

typedef vector<int> vi;
typedef set<int> si;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<int, pii> pi3;
typedef vector< pair<int, int> > vpii;
typedef long long LL;

const int N = 300005, MOD = 1000000007;

int n;
LL a[N];

int main() {
    LL ans, t, x, tmp;
    while (~in(n)) {
        rep (i, n) cin >> a[i];
        ans = 0, t = 1; 
        rep (k, 60) {
            x = 0, t = (1LL << k) % MOD;
            rep (i, n) x += (a[i] >> k) & 1;
            tmp = x * (n - x) % MOD;
            ans = (ans + tmp * t) % MOD;
        }
        cout << ans << '\n';
    }
    return 0;
}


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

using namespace std;

#define int long long

int n,p;
bool is_prime[1000001];
vector<int> prime;
vector<int> f;
int cnt = 0;
int res = 1;
void sieve()
{
	for (int i=2;i<=1000000;i++)
		is_prime[i] = true;
	is_prime[0] = is_prime[1] = false;
	for (int i=2;i*i<=1000000;i++) 
		if (is_prime[i])
			for (int j=i*i;j<=1000000;j+=i)
				is_prime[j] = false;
	for (int i=2;i<=1000000;i++)
		if (is_prime[i])
			prime.push_back(i);					
}
void factorise()
{
	for (int i=0;i<prime.size();i++)
	{
		if (prime[i] > p)
			break;
		while(p%prime[i] == 0)
		{
			p/= prime[i];	
			f.push_back(prime[i]);
		}	
	}
	if (p!=1)
		f.push_back(p);
	return;	
}

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	sieve();
	cin >> n >> p;
	if (p==1)
	{
		cout << 1;
		return 0;
	}
	factorise();
	f.push_back(0);
	for (int i=((int)f.size())-2;i>=0;i--)
	{
		if (f[i] != f[i+1])
			cnt = 1;
		else
			cnt++;
		if (cnt==n)
		{
			cnt = 0;
			res *= f[i];
		}	
	}
	cout << res;
}

Measured memory_bytes: 2552
#include <stdio.h>
#include <stdlib.h>

#define MAX 10000

  int n;

void CountingSort(int *,int *, int);

int main(){

  int i;
  int *A;
  int *B;
  
  scanf("%d",&n);
  
  A = malloc(sizeof(int)*n+1); 
  B = malloc(sizeof(int)*n+1);
  
 

  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }
  
  CountingSort(A,B,MAX);

  for(i=1;i<n;i++){
    printf("%d ",B[i]);
  }
    printf("%d\n",B[i]);
  
  return 0;
}
  
void CountingSort(int *A, int *B,int k){

  int i;
  int j;
  int C[MAX+1];
  
  for(i=0;i<=k;i++){
    C[i]=0;
  }
  for(j=1;j<=n;j++){
    C[A[j]]++;
  }
  for(i=1;i<=k;i++){
    C[i]=C[i]+C[i-1];
  }
  for(j=n;j>=1;j--){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF=1e9;
const int MAX=100005;
const int MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,n){cout<<arr[i][j]<<" ";}cout<<endl;}
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}


struct UnionFind{
    Vec par;
    Vec sz;
    Vec rank;
    UnionFind(ll n):par(n),sz(n),rank(n){
        rep(i,n){
            par[i]=i;
            sz[i]=1;
            rank[i]=0;
        }
    }
    ll root(ll x){
        if(par[x]==x){
            return x;
        }else{
            return root(par[x]);
        }
    }

    void unite(ll x, ll y){
        x = root(x);
        y = root(y);
        if(rank[x]<rank[y]){
            par[x]=y;
            sz[y]+=sz[x];
        }else{
            par[y]=x;
            sz[x]+=sz[y];
            if(rank[x]==rank[y]){
                rank[x]++;
            }
        }
    }

    bool same(ll x, ll y){
        return root(x)==root(y);
    }

    ll size(ll x){
        return sz[root(x)];
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    Vec unique(n,0);
    UnionFind uf(n+1);

    ll x,y,z;
    rep(i,m){
        cin>>x>>y>>z;
        x--;
        y--;
        uf.unite(x,y);
    }

    ll ans=0;
    rep(i,n){
        if(unique[uf.root(i)]==0){
            unique[uf.root(i)]=1;
            ans++;
        }
    }
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 3456
import math
N=int(input())
T,A=1,1
for i in range(N):
  t,a=map(int,input().split())
  k=(T+t-1) //t
  l=(A+a-1) //a
  T=t*max(k,l)
  A=a*max(k,l)
print(T+A)

Measured memory_bytes: 3060
#include<stdio.h>
#define MOD 1000000007;
int N, i, j;
char S[100001], c;
long long int dp[100001][4];
int main(){
	c=getchar(); while(c!=10){S[N++]=c; c=getchar();}

	dp[N][3]=1;
	for(i=N-1; i>=0; --i){
		{
			dp[i][3] = dp[i+1][3] * (S[i] == '?' ? 3LL : 1LL);
			dp[i][3] %= MOD;
		}
		for(j=2; j>=0; --j){
			dp[i][j] = dp[i+1][j] * (S[i] == '?' ? 3LL : 1LL);
			if(S[i] == '?' || S[i] == j+'A'){
				dp[i][j] += dp[i+1][j+1];
			}
			dp[i][j] %= MOD;
		}
	}
	printf("%lld\n", dp[0][0]);
}


Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <climits>
typedef long long ll;
using namespace std;

int main(void){
  int a,sum=0,i;
  for(i=0;i<3;i++){
    cin>>a;
    sum+=a;
  }

  if(sum<=21){
    cout<<"win"<<endl;
  }
  else{
    cout<<"bust"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100

int matrix[MAX][MAX];//隣接行列
int d[MAX];//発見時刻
int f[MAX];//終了時刻
int flg[MAX];//ノード訪問の情報
int timecnt=0;

void dfs(int u,int n){
	
	flg[u]=1;
	d[u]=++timecnt;
	
	for(int i=0;i<n;i++){
		if(matrix[u][i] && !flg[i]){/*ノードuから到達可能かつ未訪問*/
			dfs(i,n);
		}
	}
	f[u]=++timecnt;
	
	return;
	
}

int main(){
	int n,i,j;
	int x,y,z;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		flg[i]=0;
		for(j=0;j<n;j++)
			matrix[i][j]=0;
	}
	
	for(i=0;i<n;i++){
		scanf("%d %d",&x,&y);
		for(j=0;j<y;j++){
			scanf("%d",&z);
			matrix[x-1][z-1]=1;
		}
	}
	
	for(i=0;i<n;i++)
		if(!flg[i])
			dfs(i,n);
	
	
	for(i=0;i<n;i++)
		printf("%d %d %d\n",i+1,d[i],f[i]);
	
	return 0;
	
}




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

int n,res=0;
bool map[20][20];
bool fh[10],fc[10],fl[20],fr[20];

void print()
{
	for(int i=0;i!=8;++i)
	{
		for(int j=0;j!=8;++j)
		{
			if(map[i][j])	cout<<'Q';
			else			cout<<'.';	
		}
		cout<<endl;
	}
}

bool check(int x,int y)
{
	return !(fh[x] || fc[y] || fr[x+y] || fl[x+n-y+1]);
}

void pcfz(int x,int y,bool type)
{
	fh[x]=type; fc[y]=type;
	fr[x+y]=type;
	fl[x+n-y+1]=type;
	map[x][y]=type;
}

void dfs(int r)
{
	if(r==8)		print();
	else if(fh[r])	dfs(r+1);
	else
	{
		for(int i=0;i!=8;++i)
			if(check(r,i))
			{
				pcfz(r,i,1);
				dfs(r+1);
				pcfz(r,i,0);
			}
	}
}

int main()
{
	cin>>n;
	for(int i=0;i!=n;++i)
	{
		int tx,ty;
		cin>>tx>>ty;
		pcfz(tx,ty,1);		
	}
	dfs(0);
	return 0;
}

Measured memory_bytes: 3100
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int N = scn.nextInt();
		int nt = 0,nx = 0, ny = 0;
		boolean ans = true;
		for(int i = 0;i < N && ans;i++) {
			int t = scn.nextInt();
			int x = scn.nextInt();
			int y = scn.nextInt();
			if(t-nt < Math.abs(x-nx) + Math.abs(y-ny)) {
				ans = false;
			}
			if(((t-nt) - Math.abs(x-nx) + Math.abs(y-ny))%2 == 1) {
				ans = false;
			}
		}
		System.out.println(ans?"Yes":"No");
	}

}


Measured memory_bytes: 91008
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <tuple>
#include <stdlib.h>

using namespace std;

int main()
{
	int N, K, Q,tmp;
	cin >> N >> K >> Q;
	int unchi = K - Q;
	vector<int>A(N,0);
	for (int i = 0; i < Q; i++)
	{
		cin >> tmp;
		A[tmp - 1]++;
	}
	for (int i = 0; i < N; i++)
	{
		if ((A[i] + unchi) > 0)cout << "Yes"<<endl;
		else cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 1024
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("inline")
//#pragma GCC optimize("-ffast-math")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("inline-small-functions")
//#pragma GCC optimize("-finline-small-functions")
//#pragma GCC optimize("-fexpensive-optimizations")
//#pragma GCC optimize("-funsafe-loop-optimizations")
//#pragma GCC optimize("inline-functions-called-once")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pi = pair<ll, ll>;
using vpi = vector<pi>;
using oset = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
const int maxn = 2e5 + 33, mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll n, k, a[maxn], fact[maxn], inv[maxn];
ll bp(ll a, ll p) {
	ll r = 1;
	while(p) {
		if(p&1) r = (r*a)%mod;
		p>>=1, a=(a*a)%mod;
	}
	return r;
}
void setup() {
	fact[0] = inv[0] = 1;
	for(int i = 1; i < maxn; i++) {
		fact[i] = (fact[i-1]*1ll*i)%mod;
		inv[i] = bp(fact[i], mod-2);
	}
}
ll nck(ll n, ll k) {
	if(k>n) return 0;
	if(k<0) return 0;
	ll r = (fact[n]*inv[k])%mod;
	return (r*inv[n-k])%mod;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    setup();
    ll sm = 0;
    cin >>n  >> k;
    for(int i = 0; i < n; i++) {
    	cin >> a[i];
    }
    sort(a, a+n);
    for(int i = 0; i < n; i++) {
    	ll t = a[i]*nck(i, k-1);
    	sm = (sm+t)%mod;
    	t = (a[i]*nck(n-i-1, k-1))%mod;
    	sm = (mod+sm-t)%mod;
    }
    cout << sm;
}


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

int main() {
  int n, k;
  std::cin >> n >> k;
  std::vector<int> l(n);

  for (auto &i : l) {
    std::cin >> i;
  }

  std::sort(l.begin(), l.end(), std::greater<int>());

  int sum = 0;
  for (int i = 0; i < k; i++) {
    sum += l[i];
  }

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


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
from bisect import bisect_left
INF = float("inf")


def main():
    X, N = map(int, input().split())
    if N > 0:
        p = set(map(int, input().split()))
    else:
        p = set()

    ans = INF
    for n in range(110):
        if n in p:
            continue
        if abs(n-X) < abs(ans-X):
            ans = n

    print(ans)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9220
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		int count = 0;
		for (int i = 0; i < n; i++) {
			int minj = i;
			for (int j = i; j < n; j++) {
				if (a[j] < a[minj]) {
					minj = j;
				}
			}
			if (i != minj) {
				count++;
			}
			int tmp = a[i];
			a[i] = a[minj];
			a[minj] = tmp;
		}
		for (int i = 0; i < n; i++) {
			System.out.print(a[i]);
			if (i < n - 1) {
				System.out.print(" ");
			} else {
				System.out.println();
			}
		}
		System.out.println(count);
	}
}


class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}
	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}
	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
		return hasNextByte();
	}
	public String next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || Integer.MAX_VALUE < nl) {
			throw new NumberFormatException();
		}
		return (int) nl;
	}
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}



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


int main(){
  int p, q, r;
  cin >> p >> q >> r;

  int x = p + q;
  int y = q + r;
  int z = r + p;
  
  cout << min(x, min(y, z)) << endl;
}


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

namespace ConsoleApplication8 {
    class Program {
        static void Main(string[] args) {
            string data = "";
            while((data = Console.ReadLine()) != null){
            string[] hand = data.Split(',');
            DrawPoker table = new DrawPoker();
            table.setHand(hand);
            table.checkHand();
            }
        }
    }

    
    class DrawPoker {
        int[] hand;

        public DrawPoker() {
            hand = new int[5];
        }
        public void setHand(string[] playhand){
            for (int i = 0; i < playhand.Length; i++) {
                hand[i] = int.Parse(playhand[i]);
            } 
        }
        public void checkHand() {
            Array.Sort(hand);
            int num_pair = 0;
            bool TKind = false;

            for (int i = 0; i < hand.Length; i++) {
                int max_surt = 1;
                for (int j = i + 1; j < hand.Length; j++) {
                    if (hand[i]==hand[j]) {
                        max_surt++;
                    }
                }
                if (max_surt == 2) {
                    num_pair++;
                    i += 1;
                } else if (max_surt == 3) {
                    TKind = true;
                    i += 2;
                } else if (max_surt == 4 ) {
                    Console.WriteLine("four card");
                    return;
                }
            }


            if (TKind && num_pair == 0) {
                Console.WriteLine("three card");
                return;
            } else if (TKind && num_pair == 1) {
                Console.WriteLine("full house");
                return;
            } else if (!TKind && num_pair == 1) {
                Console.WriteLine("one pair");
                return;
            } else if (num_pair == 2) {
                Console.WriteLine("two pair");
                return;
            }

            if (hand[1] == hand[0] + 1 && hand[2] == hand[0] + 2 && hand[3] == hand[0] + 3 && hand[4] == hand[0] + 4
                ||hand[0] == 1 && hand[1] == 10 && hand[2] == 11 && hand[3] == 12 && hand[4] == 13) {
                Console.WriteLine("straight");
                return;
            }

            Console.WriteLine("null");
        }
    }
}

Measured memory_bytes: 8916
// import chie template :) {{{
import std.stdio,
       std.algorithm,
       std.array,
       std.string,
       std.math,
       std.conv,
       std.range,
       std.container,
       std.bigint,
       std.ascii,
       std.typecons;
// }}}
// tbh.scanner {{{
class Scanner {
  import std.stdio;
  import std.conv : to;
  import std.array : split;
  import std.string : chomp;

  private File file;
  private dchar[][] str;
  private uint idx;

  this(File file = stdin) {
    this.file = file;
    this.idx = 0;
  }

  private dchar[] next() {
    if (idx < str.length) {
      return str[idx++];
    }

    dchar[] s;
    while (s.length == 0) {
      s = file.readln.chomp.to!(dchar[]);
    }

    str = s.split;
    idx = 0;

    return str[idx++];
  }

  T next(T)() {
    return next.to!(T);
  }

  T[] nextArray(T)(uint len) {
    T[] ret = new T[len];

    foreach (ref c; ret) {
      c = next!(T);
    }

    return ret;
  }
}
// }}}

void main() {
  auto cin = new Scanner;
  int n = cin.next!int;
  auto ar = cin.nextArray!int(n);

  int res;
  ar.sort!("a > b");
  foreach (i; 0 .. n) {
    if (i % 2 == 0) res += ar[i];
    else res -= ar[i];
  }
  writeln(res);
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
public class RollingHash{
    const long base1 = 1009;
    const long base2 = 1007;
    const long mod1 = 1000000007;
    const long mod2 = 1000000009;
    long[] hash1, hash2, pow1, pow2;
    public RollingHash(string s){
        int n = s.Length;
        hash1 = new long[n+1];
        hash2 = new long[n+1];
        pow1 = new long[n+1];
        pow2 = new long[n+1];
        pow1[0] = 1;
        pow2[0] = 1;
        for(int i=0; i<n; i++){
            hash1[i+1] = (hash1[i]+s[i]) * base1 % mod1;
            hash2[i+1] = (hash2[i]+s[i]) * base2 % mod2;
            pow1[i+1] = pow1[i] * base1 % mod1;
            pow2[i+1] = pow2[i] * base2 % mod2;
        }
    }
    public Tuple<long, long> get(int l, int r){
        long t1 = ((hash1[r] - hash1[l] * pow1[r-l]) % mod1 + mod1) % mod1;
        long t2 = ((hash2[r] - hash2[l] * pow2[r-l]) % mod2 + mod2) % mod2;
        return new Tuple<long,long>(t1, t2);
    }
}

public class Hello{
    public static void Main(){
        int N = int.Parse(Console.ReadLine());
        string S = Console.ReadLine();
        var dict = new Dictionary<Tuple<long,long>, Tuple<int,int>>();
        var rh = new RollingHash(S);
        
        int left = 0;
        int right = N+1;
        while (right - left > 1){
            int l = left + (right - left) / 2;
            bool flag = false;
            for(int i=0; i+l<=N; i++){
                var hash = rh.get(i,i+l);
                if(dict.ContainsKey(hash)){
                    if(dict[hash].Item2 <= i){
                        //2つ目を発見
                        flag = true;
                        break;
                    }
                }else{
                    dict[hash] = new Tuple<int, int>(l, i+l);
                }
            }
            if(flag){
                left = l;
            }else{
                right = l;
            }
        }
        Console.WriteLine(left);
    }
}

Measured memory_bytes: 24284
#include <bits/stdc++.h>
using namespace std;
const int Max = 100001;

int main() {

    long long a[Max] = {};
    int A,b,c;
    int n, q;
    long long sum=0;

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> A;
        a[A]++;
        sum += A;
    }
    
    cin >> q;

    for (int i = 0; i < q; i++) {
        cin >> b >> c;

        a[c] += a[b];
        sum +=  (c - b) * a[b];
        a[b] = 0;
        
        cout << sum << endl;
    }
        
      
    }

Measured memory_bytes: 4344