akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#define int long long
#define mod(int)(1000000007)
using namespace std;
const int INF = 1000000000000;
int test[27], cnt[27];
signed main() {
	int n; string s; cin >> n;
	for (int i = 0; i < 27; i++) { test[i] = 100000; }
	for (int h = 0; h < n; h++) {
		cin >> s;
		for (int i = 0; i < 27; i++) { cnt[i] = 0; }
		for (int i = 0; i < s.size(); i++) {
			cnt[(int)(s[i]) - 97]++;
		}
		for (int i = 0; i < 27; i++) {
			test[i] = min(test[i], cnt[i]);
		}
	}
	for (int h = 0; h < 27; h++) {
		if (test[h] != 100000) {
			for (int i = 0; i < test[h]; i++) {
				cout << (char)(h + 97);
			}
		}
	}
	cout << endl; return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int n, ans = 0;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int cnt = 0, x = 1;
    for(int i = 0; i < n; i++){
        if(a[i] == x){
            x++;
            cnt++;
        }
    }
    ans = (cnt != 0? n - cnt : -1);
    cout << ans << endl;
    return 0;
}


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

//省略形
#define rep(i,n) for(auto i=0; i<n ; ++i)
#define REP(i,a,b) for(auto i=a; i<b; ++i)
#define all(v) (v).begin() , (v).end()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvc = vector<vector<char>>;
using pii = pair<int , int>;
using pll = pair<long long , long long>;

//よく使う定数
const int INF = 1e9;
const int MOD = 1e9+7;
//逆元
const int INV = 1e9+5;

//UnionFindTree
struct union_find{
  vector<int> data;
  union_find(int size) : data(size , -1) { }

  void merge(int x , int y){
    x = root(x); y = root(y);
    if(x == y) return;
    if(data[y] < data[x]) swap(x , y);
    data[x] += data[y];
    data[y] = x;
    return; 
  }

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

  int root(int x){
    return data[x] < 0 ? x : (data[x] = root(data[x]));
  }

  int size(int x){
    return -data[root(x)];
  }
};

//プロトタイプ宣言
void faster(void);
template <class T>
T get_digent(T);
template <class T>
T POW(T , T);
template <class T>
T modpow(T , T , T);
bool is_palindrome(string);

//メモ
//最大公約数:__gcd　|　最小公倍数:__lcm
//回文は反転させて一致すればよい

int main(){
  faster();
  int k;
  cin >> k;
  ll ans = 0;
  for(int i=1;i<=k;i++){
    for(int j=1;j<=k;j++){
      for(int l=1;l<=k;l++){
        ans += __gcd(__gcd(i,j),l);
      }
    }
  }
  cout << ans ;
}























//同期解除
void faster(void){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

//桁数取得
template <class T>
T get_digent(auto x){
  string s;
  s = to_string(x);
  ll digent = s.size();
  return digent;
} 

//繰り返し自乗法
template <class T>
T POW(T x, T y){
  if(y==0) return 1;
  if(y%2 == 1){
    ll temp = POW(x,y-1);
    return (temp*x);
  }
  else{
    ll temp = POW(x,y/2);
    return temp*temp;
  }
} 

//繰り返し自乗法(剰余)
template <class T>
T modpow(T x , T y , T mod){
  if(y == 0) return 1;
  if(y%2 == 1){
    ll temp = modpow(x,y-1,mod);
    return temp*x%mod;
  }
  else{
    ll temp = pow_mod(x,y/2,mod);
    return temp*temp%mod;
  }
}

bool is_palindrome(string s){
    string t(s.rbegin(),s.rend());
    return s == t;
}

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

namespace ABC_Training
{
    public class Program
    {
        static void Main(string[] args)
        {
            var nm = Console.ReadLine().Split(' ');
            var n = int.Parse(nm[0]);
            var m = int.Parse(nm[1]);
            
            List<int[]> conditions = new List<int[]>();
            for(int i = 0; i < m; i++)
            {
                var sc = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                conditions.Add(sc);
            }
            var ans = -1;

            var begin = n == 1 ? 0 : n == 2 ? 10 : 100;
            var end = n == 1 ? 9 : n == 2 ? 99 : 999;
            
            for (int i = begin; i <= end; i++)
            {
                var flg = true;

                var CandidateString = i.ToString();

                var i1 = i / 100;
                var i2 = (i % 100) / 10;
                var i3 = i % 10;

                foreach(var sc in conditions)
                {
                    flg &= n == 3 && sc[0] == 1 && sc[1] == i1
                        || n == 3 && sc[0] == 2 && sc[1] == i2
                        || n == 3 && sc[0] == 3 && sc[1] == i3
                        || n == 2 && sc[0] == 1 && sc[1] == i2
                        || n == 2 && sc[0] == 2 && sc[1] == i3
                        || n == 1 && sc[0] == 1 && sc[1] == i3;
                }
                if (flg)
                {
                    ans = i;
                    break;
                }
            }

            Console.WriteLine(ans);
        }
    }
}


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

int p, q, r;
int a, b, c, ans;


void solve() {
  a = p +q;
  b = p+r;
  c= q+r;

  ans = min(a,min(b,c)); 
}

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

      solve();

    cout << ans << endl;
}

Measured memory_bytes: 256
//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
    #ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        //freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    clock_t clk;
    clk = clock();
//-----------------------------------------------------------------------------------------------------------//

    ll A,B,C,K;
    cin>>A>>B>>C>>K;
    ll ans=min(A,K);
    K-=min(A,K);
    K-=min(B,K);
    ans-=min(C,K);
    cout<<ans<<endl;

//-----------------------------------------------------------------------------------------------------------//


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

    return 0;
}

Measured memory_bytes: 3808
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int A = in.nextInt();
            int B = in.nextInt();
            System.out.println(Math.max(A + B, Math.max(A - B, A * B)));
        }
    }
}


Measured memory_bytes: 27088
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

X, Y = MAP()
print(100000*max(0, 4-X)+100000*max(0, 4-Y)+400000*(X==Y==1))


Measured memory_bytes: 10620
#include <iostream>

using namespace std;

struct item {
    long long w, v;
};

int main() {
    int N, W;
    cin >> N >> W;
    item *items = new item[N];
    for (int i = 0; i < N; i++){
        cin >> items[i].w >> items[i].v;
    }
    long long *curr_memo;
    curr_memo = new long long[W];
    for (int w = 0; w < W; w++){
        curr_memo[w] = (w + 1 < items[0].w) ? 0 : items[0].v;
    }
    for (int i = 1; i < N; i++) {
        long long* prev_memo = curr_memo;
        curr_memo = new long long[W];
        long long curr_w = items[i].w;
        long long curr_v = items[i].v;
        for (int w = 0; w < W; w++) {
            if (w + 1 < curr_w) curr_memo[w] = prev_memo[w];
            else if (w + 1 > curr_w) curr_memo[w] = max(prev_memo[w], curr_v + prev_memo[w - curr_w]);
            else curr_memo[w] = max(curr_v, prev_memo[w]);
        }
        delete[] prev_memo;
    }
    
    cout << curr_memo[W - 1];
    delete[] curr_memo;
    return 0;
}


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

typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=100000000000000000;

ll min(ll a,ll b){
    if(a<b)return a;
    return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    return b;
}

ll mark[100010];
vector<ll> counter[100010];

int main(){
    ll n,m;cin>>n>>m;
    ll a[m],b[m];
    for(ll i=0;i<m;i++){
        cin>>a[i]>>b[i];
    }
    for(ll i=1;i<=n;i++){
        mark[i]=i;
        counter[i].push_back(i);
    }
    ll ans[m];
    ans[m-1]=n*(n-1)/2;
    ll c,d;
    for(ll i=m-1;i>=1;i--){
        if(mark[a[i]]==mark[b[i]]){
            ans[i-1]=ans[i];
        }else{
            c=mark[a[i]];
            d=mark[b[i]];
            ans[i-1]=ans[i]-(counter[c].size()*counter[d].size());
            if(counter[c].size()>counter[d].size()){
                for(ll j=0;j<counter[d].size();j++){
                    mark[counter[d][j]]=c;
                    counter[c].push_back(counter[d][j]);
                }
                
            }else{
                for(ll j=0;j<counter[c].size();j++){
                    mark[counter[c][j]]=d;
                    counter[d].push_back(counter[c][j]);
                }
            }
        }
    }
    for(ll i=0;i<m;i++){
        cout<<ans[i]<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 17520
#include<iostream>
#include<string>
using namespace std;
int main(){
    string a;
    cin>>a;
    long ans=0,b=0;
    for (int i=0; i<a.size(); i++) {
        if (a[i]=='W') {
            ans+=i;
            b++;
        }
    }
    for (int i=1; i<b; i++) {
        ans-=i;
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 640
N, M = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(M)]

res = [""] * M
ctr = [0] * (N + 1)
for i, (p, y) in sorted(enumerate(X), key=lambda x: (x[1][0], x[1][1])):
    ctr[p] += 1
    res[i] = "{:0>6}{:0>6}".format(p, ctr[p])

print(*res, sep="\n")


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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define IPT(x) ll t; cin >> t; x.push_back(t);
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<string> vvs;

const static ll MOD = 1e9 + 7;

int main(int argc, char *argv[]) {
    ll a, b, k;
    cin >> a >> b >> k;
    if (a >= k) a -= k;
    else if (a+b >= k) {
        b -= k-a;
        a = 0;
    } else {
        a = 0;
        b = 0;
    }
    cout << to_string(a) << " " << to_string(b) << endl;
}


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

namespace _0017
{
    public class Program

    {
        public static void Main(string[] args)
        {
            double g = 9.8;

            List<int> n = new List<int>();
            string str;
            while (!((str = Console.ReadLine())==null))
            {
                double v_min = double.Parse(str);
                double h = Math.Pow(v_min, 2) / ((double)2 * g);
                int floor = (int)Math.Ceiling(h / 5) + 1;
                n.Add(floor);
            }

            foreach (int item in n)
                Console.WriteLine(item);     
        }
    }

}


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

int main() {
    int n;
    string s;
    cin >> n >> s;
    for(int i=0;i<s.length();i++) {
        int x = s[i]-'A';
        x = (x+n)%26;
        s[i] = 'A'+x;
    }
    cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long MOD=1e9+7;

template<typename T> T gcd(T x,T y){return y!=0?gcd(y,x%y):x;}
template<typename T> T lcm(T x,T y){return x/gcd(x,y)*y;}
template<typename T> T extgcd(T a,T b,T &x,T &y){
    T d=a;
    if (b!=0){
        d=extgcd(b,a%b,y,x);
        y-=(a/b)*x;
    } else x=1,y=0;
    return d;
}
template<typename T> int digit(T n){
    string cnt=to_string(n);
    return cnt.size();
}

template<typename T> bool is_prime(T n){
    for (T i=2;i*i<=n;++i)
        if (n%i==0) return false;
    return 1<n;
}
template<typename T> vector<T> divisor(T n){
    vector<T> res;
    for (T i=1;i*i<=n;++i) if (n%i==0){
        res.emplace_back(i);
        if (i!=n/i) res.emplace_back(n/i);
    }
    return res;
}
template<typename T> map<T,int> prime_factor(T n){
    map<T,int> res;
    for (T i=2;i*i<=n;++i){
        while (n%i==0){
            ++res[i]; n/=i;
        }
    }
    if (n!=1) res[n]=1;
    return res;
}
vector<bool> prime_table(int n){
    vector<bool> prime(n+1,true);
    prime[0]=prime[1]=false;
    for (int i=2;i<=n;++i) if (prime[i]){
        for (int j=i+i;j<=n;j+=i) prime[j]=false;
    }
    return prime;
}
vector<int> primes(int n){
    vector<int> res;
    vector<bool> pt=prime_table(n);
    for (int i=2;i<=n;++i) if (pt[i]){
        res.emplace_back(i);
    }
    return res;
}

long long modpow(long long x,long long n,long long mod){
    long long res=1;
    while (n>0){
        if (n&1LL) res=res*x%mod;
        x=x*x%mod; n>>=1LL;
    }
    return res;
}
long long modinv(long long x,long long p){
    return modpow(x,p-2,p);
}

template<typename T>
T eular_phi(T n){
    T res=n;
    for (T i=2;i*i<=n;++i) if (n%i==0){
        res-=res/i;
        while (n%i==0) n/=i;
    }
    if (n!=1) res-=res/n;
    return res;
}
vector<int> eular_phi_table(int n){
    vector<int> eular(n+1);
    iota(eular.begin(),eular.end(),0);
    for (int i=2;i<=n;++i) if (eular[i]==i){
        for (int j=i;j<=n;j+=i) eular[j]-=eular[j]/i;
    }
    return eular;
};


// https://onlinejudge.u-aizu.ac.jp/courses/library/6/NTL/1/NTL_1_A

void NTL_1_A(){
    int n; cin >> n;
    map<int,int> ans=prime_factor(n);
    cout << n << ':';
    for (auto p:ans){
        for (int i=0;i<p.second;++i){
            cout << ' ' << p.first;
        }
    }
    cout << '\n';
}

// https://onlinejudge.u-aizu.ac.jp/courses/library/6/NTL/1/NTL_1_B

void NTL_1_B(){
    ll m,n; cin >> m >> n;
    cout << modpow(m,n,MOD) << '\n';
}

// https://onlinejudge.u-aizu.ac.jp/courses/library/6/NTL/1/NTL_1_C

void NTL_1_C(){
    int n; cin >> n;
    ll ans=1;
    for (;n--;){
        ll a; cin >> a;
        ans=lcm(ans,a);
    }
    cout << ans << '\n';
}

// https://onlinejudge.u-aizu.ac.jp/courses/library/6/NTL/1/NTL_1_D

void NTL_1_D(){
    int n; cin >> n;
    cout << eular_phi(n) << '\n';
}

// https://onlinejudge.u-aizu.ac.jp/courses/library/6/NTL/1/NTL_1_E

void NTL_1_E(){
    int a,b,x,y; cin >> a >> b;
    extgcd(a,b,x,y);
    cout << x << ' ' << y << '\n';
}


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


Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)

#define endl '\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007LL
#define INF 5000000000000000000
#define PI 3.1415926

const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};

typedef long long ll;

template <typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T> inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	int n; char s[600][600]; cin >> n;
	REP(i, n) REP(j, n){
		cin >> s[i][j];
		s[i+n][j] = s[i][j+n] = s[i+n][j+n] = s[i][j];
	}
	int ans = 0;
	REP(a, n){
		bool issym = 1;
		REP(i, n) REP(j, n){
			if(s[i][a+j] != s[j][a+i]) issym = 0;
		}
		if(issym) ans += n;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
// ABC163E.cpp :

#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <numeric> // accumulate
using namespace std;
using ll = long long;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using P = pair<ll, ll>;

int main()
{
	ll n;
	cin >> n;
	vector<P>a(n);
	rep(i, n) {
		cin >> a[i].first;
		a[i].second = i;
	}
	sort(a.rbegin(), a.rend()); // 降順ソート
	vector<vector<ll>>h(2020, vector<ll>(2020));
	// h[x][y] 左からxの場所にy番目の幼児を移動させた時に増えるうれしさ
	rep(i, n) {
		rep(j, n) {
			h[i][j] = a[j].first * max(a[j].second - i, i - a[j].second);
		}
	}
	vector<vector<ll>>dp(2020, vector<ll>(2020)); // dp[左の人数][右の人数]
	dp[0][0] = 0;
	for (int i = 1; i <= n; i++) {
		dp[i][0] = dp[i - 1][0] + h[i - 1][i - 1];
	}
	for (int j = 1; j <= n; j++) {
		dp[0][j] = dp[0][j - 1] + h[n - j][j - 1];
	}
	ll fromU = 0;
	ll fromR = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			fromU = dp[i - 1][j] + h[i - 1][i + j - 1];
			fromR = dp[i][j - 1] + h[n - j][i + j - 1];
			dp[i][j] = max(fromU, fromR);
		}
	}
	ll ans = 0;
	for (ll i = 0; i <= n; i++) {
		for (ll j = 0; j <= n; j++) {
			if (i + j == n) {
				ans = max(ans, dp[i][j]);
			}
			//cout << dp[i][j] << " ";
		}
		//cout << endl;
	}
	cout << ans << endl;
}

Measured memory_bytes: 67008
#include <queue>
#include <vector>
#include <utility>
#include <iostream>

using namespace std;

#define INF   (1 << 30)

int main()
{
	int N, K, A, B;

	cin >> N >> K;

	vector<int> C(N + 1);
	vector<int> R(N + 1);

	vector<bool> S(N + 1, false);
	vector<int> D(N + 1, INF);
	vector<int> P(N + 1, INF);

	vector<vector<int> > M1(N + 1, vector<int>());
	vector<vector<int> > M2(N + 1, vector<int>(N + 1, INF));

	for (int i = 1; i <= N; i++)
		cin >> C[i] >> R[i];

	for (int i = 1; i <= K; i++)
	{
		cin >> A >> B;

		M1[A].push_back(B);
		M1[B].push_back(A);
	}

	for (int i = 1; i <= N; i++)
	{
		if (R[i] < N - 1)
		{
			queue<pair<int, int> > que;

			pair<int, int> start;

			start.first = i;
			start.second = (short)0;

			que.push(start);

			while (!que.empty() && que.front().second < R[i])
			{
				pair<int, int> p1 = que.front(); que.pop();

				for (int j = 0; j < M1[p1.first].size(); j++)
				{
					if (M2[i][M1[p1.first][j]] == INF)
					{
						pair<int, int> p2;

						p2.first = M1[p1.first][j];
						p2.second = p1.second + 1;

						que.push(p2); 

						M2[i][M1[p1.first][j]] = C[i];
					}
				}
			}
		}
		else
		{
			for (int j = 1; j <= N; j++)
			{
				if (i != j)
				{
					M2[i][j] = C[i];
				}
			}
		}
	}

	D[1] = 0;
	P[1] = -1;

	while (true)
	{
		int mincost = INF;

		int u = -1;

		for (int i = 1; i <= N; i++)
		{
			if (S[i] == false && D[i] < mincost)
			{
				mincost = D[i];

				u = i;
			}
		}

		if (mincost == INF) { break; }

		S[u] = true;

		for (int v = 1; v <= N; v++)
		{
			if (S[v] == false && M2[u][v] != INF)
			{
				if (D[u] + M2[u][v] < D[v])
				{
					D[v] = D[u] + M2[u][v];
					P[v] = u;
				}
			}
		}
	}

	cout << D[N] << endl;

	return 0;
}

// Time : O ( N ^ 2 )

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

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

    int S=s.size();

    int ct[26]={};
    rep(i,S) ++ct[s[i]-'a'];

    string ans="First";
    if(s[0]==s[S-1])
    {
        if(S%2==1) ans="Second";
    }
    else
    {
        if(S%2==0) ans="Second";
    }

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


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

string s[100];
int cnt[26];
bool used[100][100];
signed main(){
	int h,w;cin>>h>>w;
	rep(i,h){
		cin>>s[i];
		for(char c:s[i])cnt[c-'a']++;
	}
	vector<int>v;
	rep(i,h)rep(j,w){
		if(used[i][j])continue;
		int x1=i,y1=j;
		int x2=h-i-1,y2=j;
		int x3=i,y3=w-j-1;
		int x4=h-i-1,y4=w-j-1;
		used[x1][y1]=used[x2][y2]=used[x3][y3]=used[x4][y4]=true;
		set<P>se{{x1,y1},{x2,y2},{x3,y3},{x4,y4}};
		v.push_back(se.size());
	}
	sort(v.begin(),v.end(),greater<>());
	for(auto p:v){
		rep(k,26){
			if(cnt[k]>=p){ 
				cnt[k]-=p;goto g;
			}
		}
		puts("No");return 0;
		g:;
	}
	puts("Yes");
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))
#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)
#define All(x) (x).begin(),(x).end()
#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))
#define End '\n'
#define Out(x) cout<<(x)<<End
template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair
#define X first
#define Y second

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

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

    int n;

    cin >> n;

    double ave = 0.0;
    int a[n];
    double diff;
    pair<double, int> table[n];

    int i;

    rep(i, n) {
        cin >> a[i];

        ave += a[i];
    }

    ave = ave / (double)n;

    rep(i, n) {
        diff = Abs(ave - (double)a[i]);

        table[i] = mp(diff, i);
    }

    sort(table, table + n);

    Out(table[0].Y);

    return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

fn main() {
  let a = read::<usize>();
  let s = read::<String>();

  match a >= 3200 {
    true => println!("{}", s),
    false => println!("red"),
  }
}


Measured memory_bytes: 4476
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <limits>
#include <cmath>
#include <numeric>

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
#define rep(i, a, b) for(int i = (a); i < (b); ++i )
#define rrep(i, a, b) for(int i = (a); i > (b); --i )
#define REP(i, a, b) for(int i = (a); i <= (b); ++i )
#define RREP(i, a, b) for(int i = (a); i >= (b); --i )
constexpr int MAXN = 100000 + 1;
ll N;
ll A[MAXN];
ll D[MAXN];
ll DD[MAXN];
int main() {
    ll cnt = 0;
    std::cin >> N;
    A[0] = 0;
    REP(i, 1, N){
        cin >> A[i];
    }
    D[0] = 0;
    REP(i, 1, N) {
        D[i] = abs(A[i] - A[i - 1]);
    }
    rep(i, 1, N) {
        DD[i] = abs(A[i+1] - A[i-1]) - D[i] - D[i+1];
    }
    DD[N] = -D[N] - abs(A[N]) + abs(A[N-1]);
    ll sum = std::accumulate(D, D+N+1, 0) + abs(A[N]);
    for (int i = 1; i <=N ;i++) {
        std::cout << sum + DD[i] << std::endl;
    }
}

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

int main()
{
    int n, k; cin>>n>>k;
    vector<int> h(n+1);
    for(int i=1; i<=n; ++i) cin>>h[i];

    vector<long> dp(n+1, LONG_MAX);
    dp[1]=0;
    for(int i=1; i<n; ++i)
        for(int j=1; j<=k; ++j)
            if (i+j<=n)
                dp[i+j]=min(dp[i+j], dp[i]+abs(h[i]-h[i+j]));
    cout<<dp[n]<<endl;
}


Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>
#include <map>
#include <set>

using namespace std;

class UnionFind {
public:
	// parents[i] >= 0 なら i の親
	// parents[i] < 0 で、根。abs(parents[i])がその木に属する頂点数
	vector<int> parents;
	int n_root;

public:
	UnionFind();
	UnionFind(int n) {
		parents.assign(n, -1);
		n_root = n;
	}
	~UnionFind() {
		parents.clear();
	};

	int find(int x) {
		if (parents[x] < 0) {
			return x;
		} else {
			return parents[x] = find(parents[x]);
		}
	}

	void unite(int x, int y) {
		x = find(x);
		y = find(y);

		if (x == y) {
			return;
		}

		if (size(x) < size(y)) {
			swap(x, y);
		}

		parents[x] += parents[y];
		parents[y] = x;
		n_root--;
		return ;
	}

	bool same(int x, int y) {
		return find(x) == find(y);
	}

	// xが属する集団のサイズ
	int size(int x) {
		return -parents[find(x)];
	}

	// いくつの集団があるか
	int get_n_root() {
		return n_root;
	}
};

int main() {
	int n, m, x, y;
	cin >> n >> m;

	vector<int> p(n+1);
	for (int i = 1; i <= n; i++) {
		cin >> p[i];
	}

	UnionFind uf(n+1);
	for (int i = 0; i < m; i++) {
		cin >> x >> y;
		uf.unite(x, y);
	}

	map<int, vector<int>> group;
	for (int i = 1; i <= n; i++) {
		int x = uf.find(i);
		group[x].push_back(i);
	}

	int ans = 0;
	for (auto pp: group) {
		set<int> nums;
		for (auto x: pp.second) {
			nums.insert(p[x]);
		}

		for (auto x: pp.second) {
			if (nums.count(x) > 0) {
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 11904
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<functional>
#include<string.h>
#include<vector>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<list>
#include<queue>
#include<deque>
#include<string>
#include<stack>
using namespace  std;

string a[52];
signed main() {
	int x, y; cin >> x >> y;
	for (int i = 0; i < x; i++) {
		cin >> a[i + 1];
		a[i + 1] = '.' + a[i + 1] + '.';
	}
	a[0] = a[x + 1] = "                                                                                                              ";
	for (int i = 1; i <= x; i++) {
		for (int j = 1; j <= y; j++) {
			if (a[i][j] == '#') {
				cout << '#';
			}
			else {
				int k = 0;
				for (int p = -1; p <= 1; p++) {
					for (int q = -1; q <= 1; q++) {
						if (a[i + p][j + q] == '#') {
							k++;
						}
					}
				}
				cout << k;
			}
		}
		cout << endl;
	}
}


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

int main() {
  int n;cin>>n;
  string s;cin>>s;
  string t = s;
  string::size_type pos = 0;
  while ((pos = s.find("()")) != string::npos) {
    s.replace(pos, 2, "");
  }
  int a=0,b=0;
  for (auto c: s) {
    if (c==')') a++;
    else b++;
  }
  cout << string(a, '(') + t + string(b, ')');
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

vector<ll> a,dp;
vector<vector<int>> e;

bool rec(int i,int p=-1){
    if(e[i].size()==1){
        dp[i]=a[i];
        return true;
    }
    ll s{},S{},x{};
    for(auto&j:e[i]){
        if(j==p) continue;
        if(!rec(j,i)) return false;
        s+=dp[j];
        x=max(x,dp[j]);
    }
    if(2*x>s){
        if(a[i]<x||s<a[i]) return false;
    }
    else if(a[i]<s/2+s%2||s<a[i]) return false;
    dp[i]=2*a[i]-s;
    return p!=-1||dp[i]==0;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int n,u,v;
    in>>n;
    a.resize(n);
    for(auto&i:a) in>>i;
    if(n==2) return cout<<(a[0]==a[1]?"YES":"NO")<<endl,0;
    e.resize(n);
    fr(i,n-1){
        in>>u>>v;
        --u,--v;
        e[u].emplace_back(v);
        e[v].emplace_back(u);
    }
    int r{};
    fr(i,n) if(e[i].size()>1) r=i;
    dp.resize(n);
    cout<<(rec(r)?"YES":"NO")<<endl;
}

Measured memory_bytes: 14464
#include<iostream>
using namespace std;
const int MAX_T = 3000, MAX_M=300;

int M, start, goal,dice[6], *N;
bool isPositionValid(int p){return 0<=p && p<M;}

void MakePathRoute(int *path, int* route, int from){
	static bool visit[MAX_M] = {};
	static auto checkPath = [&](int moveto)->int{
		if(!isPositionValid(moveto)){
			return 2*MAX_T;
		}
		else{
			int position = moveto+ N[moveto];
			if(!visit[position]) MakePathRoute(path, route, position);
			return  path[position]+1;
		}
	};
	
	if(from == start){
		for(int m=0; m<M; m++){
			path[m] = MAX_T+1;
			route[m] = 0;
		}
	}

	visit[from] = true;
	int bestPath = MAX_T, bestRoute = 0;
	if(from==goal){
		bestPath = 0;
		bestRoute = 0;
	}
	else{
		for(int r=0; r<6; r++){
			for(int s=-1; s<2; s+=2){
				int thisPath = checkPath(from + s*dice[r]);
				if(bestPath > thisPath){
					bestRoute = 1;
					bestPath = thisPath;
				}
				else if(bestPath==thisPath){
					bestRoute++;
				}
			}
		}
	}
	path[from] = bestPath;
	route[from] = bestRoute;
}

int main(){
	// 入力
	cin >> M;
	N = new int[M];
	for(int r=0; r<6; r++)	cin >> dice[r];
	cin >> start >> goal;
	for(int m=0; m<M; m++)	cin >> N[m];
	start--;
	goal--;

	int* path = new int[M];
	int* route = new int[M];
	MakePathRoute(path, route, start);
	
	//本番
	int position = start;
	int bestscore = 10*(MAX_T - path[start]) + route[start];
	for(int t=0; t<MAX_T; t++){
		if(position == goal) break;
	
		int r;
		cin >> r;
		int d = dice[r-1];

		static auto calcScore = [&](int moveto)->int{
			if(isPositionValid(moveto)){
				int path_new = path[moveto + N[moveto]];
				return 10*(MAX_T - path_new) + route[moveto + N[moveto]];
			}
			else{
				return -1;
			}
		};

		int output = 0;
		for(int s=-1; s<2; s+=2){
			int score = calcScore(position + s*d);
			if(score>bestscore){
				bestscore = score;
				output = s;
			}
		}
		position = position + output*d  + (output==0?0:N[position + output*d]);
		cout << output << endl;
	}

	delete[] N;
	delete[] path;
	delete[] route;
	return 0;
}

Measured memory_bytes: 1304
S = input()
if S[0]==S[1]:
    if S[0]!=S[2] and S[2]==S[3]:
        print('Yes')
    else:
        print('No')
elif S[0]==S[2]:
    if S[0]!=S[1] and S[1]==S[3]:
        print('Yes')
    else:
        print('No')
elif S[0]==S[3]:
    if S[0]!=S[1] and S[1]==S[2]:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<map>
using namespace std;
int main()
{
	map<string,int> mp;
	string a,b;
	cin>>a>>b;
	int a1,b1;
	cin>>a1>>b1;
	mp[a] = a1;
	mp[b] = b1;
	string cancel;
	cin>>cancel;
	mp[cancel]--;
	cout<<mp[a]<<" "<<mp[b]<<endl;
	return 0;
 } 

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>

#define MAX_H 100

using namespace std;

string S[MAX_H];

int main() {
  int H, W;
  cin >> H >> W;
  printf("\n");
  for (int i = 0; i < H; ++i) {
    cin >> S[i];
  }
  for (int j = 0; j < W + 2; ++j) {
    printf("#");
  }
  printf("\n");
  for (int i = 0; i < H; ++i) {
    printf("#%s#\n", S[i].c_str());
  }
  for (int j = 0; j < W + 2; ++j) {
    printf("#");
  }
  printf("\n");
}

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

typedef long long ll;

const ll MOD = ll(1e9 + 7);
const int MAX_N = int(1e5) + 5;
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)

ll power(ll x, ll n) {
    ll res = 1;
    while (n > 0) {
        if ((n & 1) == 1) {
            res = res * x % MOD;
        }
        x = x * x % MOD;
        n >>= 1;
    }
    return res;
}

ll N, Q, a[MAX_N]{}, c[MAX_N]{}, q[MAX_N];

int main() {
    string s;
    cin >> s;
    N = s.size();
    REP(i, N) {
        if (s[i] == 'A') a[i + 1]++;
        a[i + 1] += a[i];
        if (s[N - i - 1] == 'C') c[i + 1]++;
        c[i + 1] += c[i];
        if (s[i] == '?') q[i + 1]++;
        q[i + 1] += q[i];
    }
    ll ans = 0;
    Q = q[N];
    FOR(i, 1, N-1) {
        if (s[i] == 'B' || s[i] == '?') {
            ll X = Q - (s[i]=='?'?1:0);
            ans += (a[i])*(c[N-i])%MOD*power(3,X)%MOD;
            ans += (q[i])*(c[N-i])%MOD*power(3,X-1)%MOD;
            ans += (a[i])*(q[N]-q[i+1])%MOD*power(3,X-1)%MOD;
            ans += (q[i])*(q[N]-q[i+1])%MOD*power(3,X-2)%MOD;
            ans %= MOD;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2816
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <numeric>
#include <functional>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int M;
    ll K;
    cin >> M >> K;
    if (M == 1) {
        if (K == 0) {
            cout << "0 0 1 1" << endl;
        } else {
            cout << -1 << endl;
        }
    } else {
        if (K == 0) {
            for (int i = 0; i < (1<<M); ++i) {
                cout << i << ' ' << i;
                if (i != (1<<M)-1) cout << ' ';
            }
            cout << endl;
        } else if (K < (1<<M)) {
            cout << K << ' ' << '0' << ' ';
            for (int i = 1; i < (1<<M); ++i) {
                if (i == K) continue;
                cout << i << ' ';
            }
            cout << K << ' ';
            for (int i = (1<<M)-1; i >= 1; --i) {
                if (i == K) continue;
                cout << i << ' ';
            }
            cout << 0 << endl;
        } else {
            cout << -1 << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 1792
/****************************
    > File Name: d.cpp
    > Author: caoyu01
  	> Mail: yalecyu@gmail.com 
    > Created Time: 2016年10月15日 星期六 20时42分49秒
*****************************/
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define cle(x) memset(x,0,sizeof(x))
#define rep(i,x) for(int i=0;i<x;i++)
#define Rep(i,x) for(int i=1;i<=x;i++)
const int N = 1000+10;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
int main()
{
#ifndef ONLINE_JUDGE
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
#endif
	string s;
	int n;
	while(cin>>s){
		n=s.size();
		int ans=0;
		int gnum=0,pnum=0;
		rep(i,n){
			if(pnum==gnum){
				gnum++;
				if(s[i]=='p')ans--;
			}
			else{
				pnum++;
				if(s[i]=='g')ans++;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <random>
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 vvl = vector<vl>;
using Pt = pair<int, int>;

int main()
{
	int N;
	cin >> N;
	string S;
	cin >> S;
	int l = 0;
	int r = N - 1;
	int ct = 0;
	while (l < r)
	{
		while (S[l] == 'R' && l < r)
			++l;
		while (S[r] == 'W' && l < r)
			--r;
		if (l == r)
		{
			break;
		}
		++ct;
		swap(S[l], S[r]);
	}
	cout << ct << endl;
	return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ld long double
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define mp map<long, long>
#define um unordered_map<long, long>
#define st set<long> 
#define us unordered_set<long>
#define vt vector<long>
#define pll pair<long, long>
#define fl(i, x, y) for(long i=x;i<y;++i)
#define flr(i, x, y) for(long i=x;i>=y;--i)

int main()
{
    long n,m,a, wanum=0, acnum=0;
    string b;
    cin>>n>>m;
    bool ac[n+1]={0};
    long wa[n+1]={0};
    while(m--)
    {
        cin>>a>>b;
        if(ac[a])
        continue;
        if(b=="AC")
        {
            ac[a]=true;
            acnum++;
            wanum+=wa[a];
        }
        else
        wa[a]++;
    }
    cout<<acnum<<" "<<wanum<<endl;
	return 0;
}


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

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

typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;

const int mod = 998244353;
const ll inf = 3e18 + 5;

int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }  

int main(){
    int n;
    cin >> n;
    cout << (n / 2) + (n % 2);
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int a[200001];

int main() {
    ios_base::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    int mx = 0;
    forn (i, n) {
        int x;
        cin >> x;
        a[x]++;
        mx = max(x, mx);
    }
    mx++;
    int cnt = 0;
    forn (i, mx) {
        if (a[i] != 0) {
            cnt++;
        }
    }
    int ans = 0;
    if (cnt <= k) {
        cout << 0 << endl;
        return 0;
    } else {
        sort (a, a + mx);
        forn (i, mx) {
            if (a[i] != 0) {
                for (int j = i; j < i+cnt-k; ++j) {
                    ans+=a[j];
                }
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        n: i64,
        k: i64,
        h: [i64; n]
    }
    let mut v = h.clone();
    v.sort();
    println!("{}", v.iter().take(std::cmp::max(0, n - k) as usize).fold(0, |sum, a| sum + a));
}


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

using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)

typedef long long ll;
typedef long long int64;

int main() {
  int a1, a2, a3;
  cin >> a1 >> a2 >> a3;

  if(a1 + a2 + a3 >= 22){
    cout << "bust" << endl;
  } else {
    cout << "win" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from itertools import permutations

ary = map(int, input().split())

min_val = float('inf')
for vals in permutations(ary):
    tmp_val = 0
    for i, val in enumerate(vals):
        if i > 0:
            tmp_val += abs(val - vals[i - 1])

    if min_val > tmp_val:
        min_val = tmp_val

print(min_val)


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

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

long long lcm(long long a,long long b){
  long long g = gcd(a,b);
  return a/g*b;
}

int main(void){
	long long int  a,b,c[100010],d;
  cin >> a >>b;
  
  for(int i=0;i<a;i++)
    cin >> c[i];
  
  sort(c,c+a,greater<int>());
 int ans = c[0];
  
 for(int i=0;i<a;i++) ans = gcd(ans,c[i]);
  
  if(b%ans ==0 && b<=c[0]) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
}

  
  
 

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <utility>
//#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define MOD 1e9 + 7
#define INF 1e9
#define SENTINEsL 2e9
#define PIE 3.1415a926535

template <class T>
inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}
template <class T>
inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template <class T>
inline T GCD(T a, T b){if (b == 0) return a; else return GCD(b, a % b);}
template <class T>
inline T LCM(T a, T b) {return (a * b) / GCD(a, b);}

int main() {
    ll n, k;
    cin >> n >> k;
    vector<pair<ll, ll>> v;
    ll a, b;
    rep(i,n) {
        cin >> a >> b;
        v.push_back(make_pair(a, b));
    }
    sort(all(v));
    //rep(i, n) cout << v[i].first << endl;
    ll sum = 0;
    ll res;
    rep(i,n) {
        sum += v[i].second;
        if (sum>=k) {
            res = v[i].first;
            break;
        }
        else
        {
            
        }
        
    }
    cout << res << endl;
}

Measured memory_bytes: 2420
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
   string s; cin>>s;
   int ans=0;
   int a=0;
   for(int i=0;i<s.length();i++){
      if(s[i]=='A'||s[i]=='T'||s[i]=='C'||s[i]=='G') a++;
      else a=0;
      ans=max(a,ans);
   }
   cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ll q,h,s,d,n;
    cin>>q>>h>>s>>d>>n;
    if(d<2*s&&d<4*h&&d<8*q){
        ll ans=n/2*d;
        n=n%2;
        if(s<=2*h&&s<=4*q) cout<<ans+s*n;
        else if(h<=2*q) cout<<ans+h*2*n;
        else cout<<ans+q*4*n;
    }
    else{
        if(s<=2*h&&s<=4*q) cout<<s*n;
        else if(h<=2*q) cout<<h*2*n;
        else cout<<q*4*n;
    }
    cout<<"\n";
}

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

using namespace std;

const int M = 1e5 + 5;
const int MOD = 1e9 + 7;
long long n, k, dp[102][M], t[102];

int main () {
    cin >> n >> k;
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++) {
        cin >> t[i];
        dp[i][0] = 1;
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= k; j++) {
            dp[i][j] = (dp[i][j-1] + dp[i-1][j]) % MOD;
            if(j-t[i]-1 >= 0) dp[i][j] = ((dp[i][j] - dp[i-1][j-t[i]-1]) % MOD + MOD) % MOD;
        }
    }
    cout << dp[n][k];
}


Measured memory_bytes: 78336
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	int d, n;
	cin >> d >> n;
	switch(d)
	{
		case 0:
			if(n==100) cout << 101 << endl;
			else cout << n << endl;
			break;
		case 1:
			if(n==100) cout << 10100 << endl;
			else cout << n*100 << endl;
			break;
		case 2:
			if(n==100) cout << 1010000 << endl;
			else cout << n*10000 << endl;
			break;
	}
	return 0;
}

Measured memory_bytes: 256
require 'prime'
io = STDIN
n=io.gets.to_i

ct=0
(1..n).each do |i|
  next if i.even?
  pd=i.prime_division
  if pd.size==3 || pd.map{|ar|ar[1]}.sort==[1,3]
    ct+=1
  end
end
p ct


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

int main() {
    int N,M;
    cin >> N >> M;
    int ans = 0;
    int NN = 1;
    int NM = 1;
    
    NN = N*(N-1)/2;
    NM = M*(M-1)/2;
    
    ans = NN + NM;

    cout << ans << endl;
}

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


def CountingSort(A, k, n):
    B = [None]*(n+1)
    C = [0]*k
    for j in range(1, n+1):
        C[A[j]] += 1

    for i in range(1, k):
        C[i] = C[i] + C[i-1]
    
    for j in range(n, 0, -1):
        B[C[A[j]]] = A[j]
        C[A[j]] -= 1
    
    return B


if __name__ == '__main__':
    k = 10000
    n = int(input())
    A = [None] + [int(a) for a in input().split(" ")]
    
    B = CountingSort(A, k, n)
    print(" ".join(map(str, B[1:])))



Measured memory_bytes: 247696