akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
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); }

//CODE

void solve(void)
{
  string S,T;
  cin>>S>>T;
  cout<<T+S<<endl;
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  

 
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
A = list(map(int,input().split()))
C = collections.Counter()
for i ,ai in enumerate(A):
  ans += C[i-ai]
  C[ai+i] += 1
print(ans)

Measured memory_bytes: 110948
n, m = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))

sum_x = 0
for i in range(0, n):
    sum_x += i * x[i] - (n - (i + 1)) * x[i]

sum_y = 0
for i in range(0, m):
    sum_y += i * y[i] - (m - (i + 1)) * y[i]

ans = sum_x * sum_y

divide_num = pow(10, 9) + 7
print(ans % divide_num)


Measured memory_bytes: 18556
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int a, b;
    scanf("%d %d",&a,&b);
    if(a>b)
    {
        printf("a > b\n");
    }
    else if(a<b)
        printf("a < b\n");
    else
        printf("a == b\n");
    return 0;
}



Measured memory_bytes: 2604
#include<iostream>
int main() {
	int a, b, c;
	std::cin >> a >> b >> c;
	if (a < b) {
		if (b < c) {
			std::cout << a << " " << b << " " << c << std::endl;
		}
		else if (b > c) {
			if (a < c) {
				std::cout << a << " " << c << " " << b << std::endl;
			}
			else {
				std::cout << c << " " << a << " " << b << std::endl;
			}
		}
	}
	else {
		if (a < c) {
			std::cout << b << " " << a << " " << c << std::endl;
		}
		else if (b < c) {
			std::cout << b << " " << c << " " << a << std::endl;
		}
		else {
			std::cout << c << " " << b << " " << a << std::endl;
		}
	}
}

Measured memory_bytes: 1164
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;
const long double PI = 3.1415926535897932384626433;

long long int N, M, K, H, W, L, R;


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

	cin >> N >> M >> K;
	while (N) {
		vector<vector<int>>line(N + 1, vector<int>(1001,0));
		for (int i = 0; i < M; i++) {
			cin >> H >> L >> R;
			line[L][H] = R;
			line[R][H] = L;
		}
		for (int i = 1000; i >= 1; i--) {
			if (line[K][i]) {
				K = line[K][i];
			}
		}
		cout << K << endl;
		cin >> N >> M >> K;
	}
	return 0;
}

Measured memory_bytes: 3388
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = 0;
        ArrayList<ArrayList<Integer[]>> arr = new ArrayList<>();
        for(int i = 0; i < n; i++) {
            arr.add(new ArrayList<>());
            int a = sc.nextInt();
            for(int j = 0; j < a; j++) {
                arr.get(i).add(new Integer[2]);
                arr.get(i).get(j)[0] = sc.nextInt();
                arr.get(i).get(j)[1] = sc.nextInt();
            }
        }
        int num = (1 << n) - 1;
        while(num > 0) {
            int[] list = new int[n];
            int m = num;
            for(int i = 0; i < n; i++) {
                list[i] = m % 2;
                m >>= 1;
            }
            boolean flag = true;
            int i = 0;
            for(ArrayList<Integer[]> array : arr) {
                for(Integer[] ar : array) {
                    if(list[i] == 1 && list[ar[0] - 1] != ar[1]) {
                        flag = false;
                        break;
                    }
                }
                i++;
            }
            if(flag) ans = Math.max(ans, Integer.bitCount(num));
            num -= 1;
        }
        System.out.println(ans);
    }
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

ll SUM[510][510];


int N, M, Q;
void print(){
    for(int i = N-1; i >= 0; i--){
        for(int j = 0; j < N; j++){
            printf("%lld ", SUM[j][i]);
        }
        printf("\n");
    }
}

int main(){
    cin >> N >> M >> Q;
    REP(i, M){
        int l, r;
        cin >> l >> r;
        l--, r--;
        SUM[r][l]++;
    }

    for(int r = 1; r < N; r++){
        SUM[r][0] += SUM[r-1][0];
    }
    for(int l = 1; l < N; l++){
        SUM[0][l] += SUM[0][l-1];
    }

    for(int r = 1; r < N; r++){
        for(int l = 1; l < N; l++){
            SUM[r][l] += SUM[r][l-1] + SUM[r-1][l] - SUM[r-1][l-1];
        }
    }

    //print();

    REP(i, Q){
        int p, q;
        cin >> p >> q;
        p--, q--;
        ll ans = 0;
        ans += SUM[q][q];
        if(p-1 >= 0){
            ans -= SUM[p-1][q];
            ans -= SUM[q][p-1];
            if(q-1 >= 0)
                ans += SUM[p-1][q-1];
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 2944
#include <cstdio>

int main()
{
	int N, Y;

	scanf("%d %d", &N, &Y);

	for (int x = 0; x <= N && 10000 * x <= Y; ++x)
	{
		for (int y = 0; x + y <= N; ++y)
		{
			if (10000 * x + 5000 * y + 1000 * (N - x - y) == Y)
			{
				printf("%d %d %d\n", x, y, N - x - y);
				return 0;
			}
		}
	}

	printf("-1 -1 -1\n");
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
int dp[40];
int main(){
	for(int i=0;i<=9;i++){
		for(int j=0;j<=9;j++){
			for(int k=0;k<=9;k++){
				for(int l=0;l<=9;l++){
					dp[i+j+k+l]++;
				}
			}
		}
	}
	int n;
	while(cin>>n){
		if(n==0){break;}
		cout<<dp[n]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forenska(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
#define randIn(L,R) (((LL)rand()*rand())%(R-L)+L)
#define __lcm(a,b) ((a)/__gcd(a,b)*(b))
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.14159265358979323846264338327950288419716939937510582097;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read()
{
    int x=0;
    char ch=' ';
    bool flag=false;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')flag=true;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return flag?-x:x;
}

int main()
{
	int n;
	cin>>n;
	vecP a(n);
	rep(i,0,n)a[i]=mp(read(),i);
	sort(all(a));
	int mid=n/2;
	vec B(n);
	rep(i,0,n)
	{
		if(i<mid)B[a[i].se]=a[mid].fi;
		else B[a[i].se]=a[mid-1].fi;
	}
	rep(i,0,n)cout<<B[i]<<endl;
	return 0;
}



Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = 1e9;
const ll INFLL = 1e18;
const ll MOD = 1e9+7;
const double PI = acos(-1.0);

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

int H,W,K;
vector<string> s;
int ans[324][324];
/*------------------------------------/
for library*/
void debug(){
    cerr<<endl;
    rep(i,H){
        cout<<s[i]<<endl;
    }
}
void debug_ans(){
    cerr<<endl;
    rep(i,H)rep(j,W){
        cerr<<ans[i][j];
        if(j == W-1)cerr<<endl;
        else cerr<<" ";
    }
    cerr<<endl;
}

void out_ans(){
    rep(i,H)rep(j,W){
        cout<<ans[i][j];
        if(j == W-1)cout<<endl;
        else cout<<" ";
    }
}
bool IsIn(int x,int y){
    return 0<=x&&x<H&&0<=y&&y<W;
}


/*------------------------------------*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cin>>H>>W>>K;
    s.resize(H);
    rep(i,H){
        cin>>s[i];
    }
    vector<bool> kara(H,false);
    rep(i,H){
        int cnt = 0;
        rep(j,W){
            if(s[i][j] == '#')cnt++;
        }
        if(cnt == 0){
            kara[i] = true;
        }
    }
    //debug();
    int cnt = 0;
    rep(i,H)rep(j,W){
        if(s[i][j] == '#'){
            cnt++;
            ans[i][j] = cnt;
            for(int k = j+1;k<W;k++){
                if(s[i][k] == '.'){
                    ans[i][k] = cnt;
                }
                else{
                    break;
                }
            }
        }
    }
    //debug_ans();
    rep(i,H){
        for(int j = W-1;j >= 0;j--){
            if(ans[i][j] == 0){
                if(ans[i][j+1] == 0)continue;
                ans[i][j] = ans[i][j+1];
            }
        }
    }
    //debug_ans();;

    rep(i,H){
        if(kara[i]&&!kara[i+1]){
            while(i >= 0 && kara[i]){
                rep(j,W){
                    ans[i][j] = ans[i+1][j];
                }
                kara[i] = false;
                i--;
            }
        }
    }
    //debug_ans();
    rep(i,H)kara[i] = false;
    rep(i,H){
        rep(j,W){
            if(ans[i][j] == 0)kara[i] = true;
        }
    }
    rep1(i,H){
        if(!kara[i-1]&&kara[i]){
            while(i < H && kara[i]){
                rep(j,W){
                    ans[i][j] = ans[i-1][j];
                }
                kara[i] = false;
                i++;
            }
        }
    }
    //debug_ans();
    out_ans();
}

Measured memory_bytes: 1280
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

is_ok_a = [False] * n
max_a = [0]*n
pre = -1
for i, j in enumerate(a):
    if j != pre:
        pre = j
        is_ok_a[i] = True
    max_a[i] = pre

is_ok_b = [False] * n
max_b = [0]*n
pre = -1
for i, j in reversed(list(enumerate(b))):
    if j != pre:
        pre = j
        is_ok_b[i] = True
    max_b[i] = pre
mod = 10**9+7
ans = 1
for i in range(n):
    if is_ok_a[i] and is_ok_b[i]:
        if max_a[i] == max_b[i]:
            ans *= 1
        else:
            ans *= 0
    elif is_ok_a[i]:
        if max_a[i] <= max_b[i]:
            ans *= 1
        else:
            ans *= 0
    elif is_ok_b[i]:
        if max_a[i] >= max_b[i]:
            ans *= 1
        else:
            ans *= 0
    else:
        ans *= min(max_a[i], max_b[i])
    ans %= mod
print(ans)


Measured memory_bytes: 25152
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k = int(input())

ans = 0
for i in range(1, k+1):
  for j in range(1, k+1):
    for k in range(1, k+1):
      ans += gcd(i, j, k)
print(ans)

Measured memory_bytes: 69644
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int i[114514];
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	double a,b,c,d=0,e,f;
	string s[114514],u;
	cin >>a;
	for(int n=0;n<a;n++){
		cin >>b;
		d+=1/b;
	}
	cout <<fixed<<1/d<<'\n';
	return 0;
}

Measured memory_bytes: 1152
//   PIGMEISTER™   //

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

#define ll long long
#define ld long double
#define sidha(i,x,n) for(ll i=(ll)(x);i<(ll)(n);++i)
#define ulta(i,x,n) for(ll i=(ll)(x);i>=(ll)(n);--i)
#define sab(a) a.begin(),a.end()
#define bas(a) a.rbegin(),a.rend()
#define test ll _;cin>>_;while(_--)
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD (ll)1000000007
//#define MOD (ll)998244353
#define PI (ld)3.141592653589793238
#define MAX 100005

int main()
{
    jaldi;
    
    ll n;
    cin >> n;
    string a;
    ll q = 0, w = 0, e = 0, r = 0;
    while (n--) {
        cin >> a;
        if (a == "AC") q++;
        else if (a == "WA") w++;
        else if (a == "TLE") e++;
        else r++;
    }

    cout << "AC x " << q << '\n';
    cout << "WA x " << w << '\n';
    cout << "TLE x " << e << '\n';
    cout << "RE x " << r << '\n';
    
    return 0;
}


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

#define INF 1e9

int main(void){
  while(true){
    int n;
    cin >> n;
    if(n == 0){ break; }

    // ???????????????????????¢???????????±???????????????
    int bit;
    vector<vector<int> > t(n, vector<int>(1 << n, INF));
    for(int i = 0; i < n; i++){
      for(int j = 0; j <= n; j++){
        bit = (j == 0) ? 0 : (1 << (j - 1));
        cin >> t[i][bit];
      }
    }

    // ???????????????????????¢????????????????????????????????????
    for(int i = 0; i < n; i++){
      for(int j = 0; j < (1 << n); j++){
        for(int b = 0; b < n; b++){
          t[i][j | (1 << b)] = min(t[i][j | (1 << b)], t[i][j]);
        }
      }
    }

    // ????????????????????????
    vector<int> result(1 << n, INF);
    priority_queue<pair<int, int> > wait;
    result[0] = 0;
    wait.push(make_pair(0, 0));

    while(!wait.empty()){
      int nowstate = wait.top().second;
      int nowcost = -wait.top().first;
      wait.pop();
      if(result[nowstate] < nowcost){ continue; }

      for(int i = 0; i < n; i++){
        int nextstate = nowstate | (1 << i);
        int nextcost = nowcost + t[i][nowstate];
        if(result[nextstate] > nextcost){
          result[nextstate] = nextcost;
          wait.push(make_pair(-nextcost, nextstate));
        }        
      }      
    }

    // ??????
    cout << result[(1 << n) - 1] << endl;
  }

  return 0;
}

Measured memory_bytes: 6344
import java.util.*;
public class Main {
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);
	String s = scan.next();
	String m ="CODEFESTIVAL2016";
	int k = 0;
	for(int i=0;i<16;i++){
	    if(s.charAt(i)!=m.charAt(i))
		k++;
		//String.valueOf(s.charAt(i));
	}
	System.out.println(k);
    }
}

Measured memory_bytes: 9044
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using P = pair<int, int>;
int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    const ll k = 1e9 + 7;
    ll sum = 0;
    for(int i = 0; i < n; i++){
        sum += a[i];
    }

    ll sum_2 = 0;
    rep(i,n){
        sum -= (ll)a[i];
        sum_2 += (ll)(sum % k) * (ll)(a[i]%k);
        sum_2 %= k;
    }
    ll ans = sum_2%k;

    cout << ans << endl;
    // cout << k << endl;

return 0;
}

Measured memory_bytes: 4828
#!/usr/bin/env python3


def zr(x):
    return x


def ev(x):
    return x % 2 if x > 0 else 2


def od(x):
    return (x + 1) % 2 if x > 0 else 1


INF = 10**9 + 1

L = int(input())
A = [int(input()) for _ in range(L)]

dp = [[0] * 5] + [[INF] * 5 for _ in range(L)]
for i, x in enumerate(A):
    for t, f in enumerate([zr, ev, od, ev, zr]):
        dp[i + 1][t] = min(dp[i + 1][t], min(dp[i][:t + 1]) + f(x))

print(min(dp[L]))


Measured memory_bytes: 59912
#include <iostream>
#include<algorithm>
#include<string>
#include<vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
using namespace std;

int main()
{
	int n, m, cnt=0;
	cin >> n >> m;
	vector<int>a(m), b(m) ,c;
	for (int i = 0; i < m; i++)cin >> a[i] >> b[i];
	for (int i = 1; i <= n; i++) {
		cnt += count(a.begin(), a.end(), i);
		cnt += count(b.begin(), b.end(), i);
		c.push_back(cnt);
		cnt = 0;
	}
	/*for (int i = 0; i < m; i++) {
		for (int j = 0; j < m; j++) {
			if (a[i] == b[j]) {
				if (a[j] == b[i])c[a[i]-1]--;
			}
		}
	}*/
	for (int& x : c)cout << x << endl;
}


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

#define st first
#define nd second
#define ll long long
#define ld long double
#define pb push_back
#define emp emplace_back
#define pii pair<int, int>
#define usg unsigned
#define sg signed
#define mp make_pair

using namespace std;

void setIO(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

const ld PI = 4*atan((ld)1);
const int INF = 1e9+7;

set<int>s;

int main(){
	setIO();
	int x, n;
	cin >> x >> n;
	for (int i = 0; i < n; i++){
		int y; cin >> y;
		s.insert(y);
	}
	if (!s.count(x)) {cout << x << endl; return 0;}
	int l = x-1, r = x+1;
	while (1){
		if (!s.count(l)){
			cout << l << endl;
			return 0;
		}
		if (!s.count(r)){
			cout << r << endl;
			return 0;
		}
		l--; r++;
	}
}

Measured memory_bytes: 3696
#include <iostream>

using namespace std;

int main()
{
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  while(true) {
    c -= b; // Attack
    if(c <= 0) {
      cout << "Yes" << endl;
      break;
    }
    a -= d; // Attack
    if(a <= 0) {
      cout << "No" << endl;
      break;
    }
  }
}

Measured memory_bytes: 3600
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <cmath>
#include <tuple>
#include <map>
#include <unordered_map>
#include <queue>
using namespace std;
typedef long long ll;

int main(int argc, char *argv[])
{
	string prev;
	cin >> prev;

	if (prev == "ARC")
		cout << "ABC" << endl;
	else
		cout << "ARC" << endl;

	return 0;
}


Measured memory_bytes: 3628
n = gets.to_i
nums = gets.split
as = []
n.times do |i|
  as << nums[i].to_i
end

def division(array)
  count_even = 0
  array.each do |num|
    if num.even?
      count_even += 1
    end
  end
  return false if count_even != array.length
  array.map! do |num|
    num / 2
  end
  return true
end

count_divide = 0
30.times do |i|
  flag = division(as)
  if flag
    count_divide += 1
  else
    break
  end
end

puts count_divide


Measured memory_bytes: 14340
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define fore(x, a) for(auto &x : a)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
template<class T>using vv = vector<T>;
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; }
template<class T>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};

int n, w_cnt[300005], e_cnt[300005]; 
string s; 
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n >> s;
    rep(i, 0, n) if (s[i] == 'W') w_cnt[i]++;
    eper(i, n-1, 0) if (s[i] == 'E') e_cnt[i]++;
    rep(i, 0, n-1) w_cnt[i+1] += w_cnt[i];
    eper(i, n-1, 1) e_cnt[i-1] += e_cnt[i];
    int ans = inf;
    rep(i, 0, n) {
      ans = min(ans, w_cnt[i] + e_cnt[i] - 1);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 2964
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	int n;
	cin >> n;
	
	vector<int> cnt(9, 0);
	for(int i = 0; i < n; ++i) {
		int a;
		cin >> a;
		
		if( a / 400 >= 8 ) cnt[8]++;
		else cnt[a / 400]++;
	}
	
	int minans = 0;
	for(int i = 0; i < 8; ++i) {
		if( cnt[i] ) minans++;
	}
	
	int maxans = minans + cnt.back();
	if( minans == 0 ) {
		minans++;
	}
	
	cout << minans << " " << maxans << endl;
	
	return 0;
}


Measured memory_bytes: 3628
#include<stdio.h>
#include<string.h>
int main(){
    int i;
    int pos=2;
    int cnt=0;
    char str[50];
    char map[]="yuiophjklnm";
    while (1) {
        scanf("%s",str);
        if(str[0]=='#'){
            break;
        }
        i=0;
        pos=2;
        cnt=0;
        while (str[i]!='\0') {
            if(strchr(map,str[i])==NULL){
                if(pos==1)cnt++;
                pos=0;
            }else{
                if(pos==0)cnt++;
                pos=1;
            }
            i++;
        }
        printf("%d\n",cnt);
    }
    return 0;
}

Measured memory_bytes: 544
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s1,s2;
  int ans=0;
  cin>>s1>>s2;
  for(int i=0;i<3;i++)
  {
   if(s1[i]==s2[i])
     ans++;
  }
  cout<<ans;
  
 return 0; 
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int m=0,ans[100000],i=0;
void solve(int a[],int c[],int l,int r){
    if(l>r){
        return;
    }
    int x=a[m];
    m++;
    solve(a,c,l,c[x]-1);
    solve(a,c,c[x]+1,r);
    ans[i]=x;
    i++;
}
int main(){
    int n,m,a[10000]={},b[100000]={},c[100000]={};
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cin>>m;
        b[i]=m;
        c[m]=i;
    }
    solve(a,c,0,n-1);
    for(int i=0;i<n-1;i++){
        cout<<ans[i]<<" ";
    }
    cout<<ans[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 3552
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

template<int mod>
struct ModInt {
    int x;

    ModInt() : x(0) {}
    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    ModInt &operator+=(const ModInt &p) {
        if((x += p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator-=(const ModInt &p) {
        if((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator*=(const ModInt &p) {
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }
    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }

    ModInt inverse() const{
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) {
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return ModInt(u);
    }

    ModInt pow(int e){
        long long a = 1, p = x;
        while(e > 0) {
            if(e%2 == 0) {p = (p*p) % mod; e /= 2;}
            else {a = (a*p) % mod; e--;}
        }
        return ModInt(a);
    }

    friend ostream &operator<<(ostream &os, const ModInt<mod> &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt<mod> &a) {
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};

const int mod = 1e9 + 7;
using modint = ModInt<mod>;

modint fact[200010];

modint nCr(int n, int r){
    return fact[n]/(fact[n-r]*fact[r]);
}

int main(){
    int H, W, A, B;
    cin >> H >> W >> A >> B;
    fact[0] = 1;
    for(LL i=1; i<=200000; i++){
        fact[i] = (fact[i-1] * i);
    }

    modint ans = 0;
    for(int i=B; i<W; i++){
        modint tmp = nCr((H-A-1)+i, H-A-1) * nCr((A-1)+(W-i-1), A-1);
        ans += tmp;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
double n,k,a[200005],mn,res;
double func(double x)
{
	return (x+1.0)/2.0;
}
int main()
{
	cin>>n>>k;
	for (int i=0;i<n;i++) cin>>a[i];
	for (int i=0;i<k;i++) res+=func(a[i]);
	mn=res;
	for (int l=1,r=l+k-1;r<n;l++,r++)
	{
		res-=func(a[l-1]);
		res+=func(a[r]);
		mn=max(res,mn);
	}
	printf("%.12f",mn);
	return 0;
}

Measured memory_bytes: 1792
n = map(int, raw_input().split())

W = n[0]
H = n[1]
x = n[2]
y = n[3]
r = n[4]

if ((x-r)<0 or (x+r)>W or (y-r)<0 or (y+r)>H):
	print "No"
else:
	print "Yes"

Measured memory_bytes: 4208
#include<bits/stdc++.h>
typedef long long ll;
#define exp puts("-1"),exit(0);
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
std::mt19937 rnd(time(NULL));
#define rand rnd
#define pr std::pair<int,int>
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
template<class T>void cxk(T&a,T b){a=a>b?a:b;}
template<class T>void cnk(T&a,T b){a=a<b?a:b;}
#ifdef mod
int pow(int x,int y){
	int ret=1;
	while(y){
		if(y&1)ret=1ll*ret*x%mod;
		x=1ll*x*x%mod;y>>=1;
	}
	return ret;
}
template<class Ta,class Tb>void inc(Ta&a,Tb b){a=a+b>=mod?a+b-mod:a+b;}
template<class Ta,class Tb>void dec(Ta&a,Tb b){a=a>=b?a-b:a+mod-b;}
#endif
ll D[100010];
int fa[100010],st[100010],siz[100010];
std::unordered_map<ll,int>M;
int main(){
#ifdef LOCAL
	freopen("in.in","r",stdin);
	//freopen("out.out","w",stdout);
#endif
	int n=gi();
	for(int i=1;i<=n;++i)D[i]=gi(),st[i]=i,M[D[i]]=i,siz[i]=1;
	std::sort(st+1,st+n+1,[&](int a,int b){return D[a]<D[b];});
	ll ssiz=0;
	for(int _=n,i;_>1;--_){
		i=st[_];
		if(!(fa[i]=M[D[i]-n+2*siz[i]]))exp;
		siz[fa[i]]+=siz[i];ssiz+=siz[i];
	}
	if(D[st[1]]!=ssiz)exp;
	for(int i=1;i<=n;++i)if(fa[i])printf("%d %d\n",i,fa[i]);
	return 0;
}


Measured memory_bytes: 7460
import sys
 
def main():
    S = str(input())
 
    if(S=="SUN"):
        print('7')
 
    if(S=="MON"):
        print('6')
 
    if(S=="TUE"):
        print('5')
 
    if(S=="WED"):
        print('4')
 
    if(S=="THU"):
        print('3')
 
    if(S=="FRI"):
        print('2')
 
    if(S=="SAT"):
        print('1')
 
    sys.exit()
 
main()

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int A[] = new int[N];
        double beneath = 0;
        for (int i = 0;i<N;i++){
            beneath = beneath + 1.0/sc.nextInt();
        }
        System.out.println(1.0/beneath);

    }
}


Measured memory_bytes: 21076
#include<bits/stdc++.h>
#define    ll      unsigned long long int
#define    Fori(a,b) for (ll i = a ; i<b ;i++ )
#define    Forj(a,b) for (ll j = a ; j<b ;j++ )
#define    Fork(a,b) for (ll k = a ; k<b ;k++ )
#define    W       while
#define    pb      push_back
#define    nl      cout<<endl
#define    mod     1000000007
#define    I       cin>>
#define    Out     cout<<
#define    DOD(i)  cout<<setprecision(i)<<fixed<<
#define    XXX     return 0
#define    Fast    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;
int main()
{
   Fast;
   ll n,k;I n>>k;
   if(k>n){
       cout<<1<<endl;
   }else{
       ll ans=0;
       for(int i=k;i<=n+1;i++){
           ans += i*(n-i+1) + 1; 
       }
       cout<<(ans)%mod<<endl;
   }
   XXX;
}




Measured memory_bytes: 3652
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

int main() {
	int n;
	cin >> n;
	REP(g, n) {
		vi a(9), b(9);
		REP(i, 9) {
			cin >> a[i];
		}
		REP(i, 9) {
			cin >> b[i];
		}
		sort(ALL(a));
		double win_a = 0, win_b = 0;
		do {
			int score_a = 0, score_b = 0;
			REP(i, 9) {
				if(a[i] < b[i]) {
					score_b += a[i]+b[i];
				} else {
					score_a += a[i]+b[i];
				}
			}
			if(score_a < score_b) {
				win_b++;
			} else {
				win_a++;
			}
		}while(next_permutation(ALL(a)));

		FOR(i, 2, 9) {
			win_a /= i;
			win_b /= i;
		}

		printf("%.5f %.5f\n", win_a, win_b);
	}

    return 0;
}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define in insert
#define mp make_pair
#define F first
#define pb push_back
#define speed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
ll exp(ll x,ll y,ll p){ ll res=1; while(y) {if(y%2) res=(res*x%p)%p; x=(x*x)%p; y/=2; } return res;}
ll exp(ll x,ll y){ ll res=1; while(y) {if(y%2) res=(res*x); x=(x*x); y/=2; } return res;}

int main(){
    ll n; cin>>n;
    double len=(double)n/3;
    double k=(double)n;
    k-=len;
    double brea=(double)(k)/2;
    double height=k-brea;
    cout<<fixed<<setprecision(10)<<len*brea*height;

    
    return 0;
}


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

long long gcd(long long c,long long d){
  long long r;

  if(c<d) swap(c,d);
 
  r = c % d;
  while(r!=0){
    c = d;
    d = r;
    r = c % d;
  }
  return d;
}

int main(){
  long long a,b,c,d;
  cin >> a >> b >> c >> d;
  
  long long delta = b-a+1;
  long long res=c*d/gcd(c,d);
  long long ans = delta - (b/c - (a-1)/c) - (b/d - (a-1)/d) + (b/res - (a-1)/res);
  cout << ans << endl;
}

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

int main(void){
    int h=0,w=0;
    cin>>h>>w;
    h+=2;w+=2;
    int sqr[h][w];
    string str;
    
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            sqr[i][j]=0;
        }
    }
    
    for(int i=1;i<h-1;i++){
        cin>>str;
        for(int j=0;j<w;j++){
            if(str[j]=='#'){
                sqr[i][j+1]=9;
                //cout<<i<<j+1<<endl;
            }
        }
    }
    
    for(int i=1;i<h-1;i++){
        for(int j=1;j<w-1;j++){
            int c=0;
            if(sqr[i-1][j-1]==9) c++;
            if(sqr[i-1][j]==9) c++;
            if(sqr[i-1][j+1]==9) c++;
            if(sqr[i][j-1]==9) c++;
            if(sqr[i][j+1]==9) c++;
            if(sqr[i+1][j-1]==9) c++;
            if(sqr[i+1][j]==9) c++;
            if(sqr[i+1][j+1]==9) c++;
            sqr[i][j]=(sqr[i][j]==9)?9:c;
        }
    }
    
    for(int i=1;i<h-1;i++){
        for(int j=1;j<w-1;j++){
            if(sqr[i][j]==9){
                cout<<'#';
            }else{
                cout<<sqr[i][j];
            }
        }
            cout<<endl;
    }
}


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

int main(){
    int a,b;

    cin >> a >> b;

    if(a == b){
        cout << "Draw" << endl;
    }
    else if(a > b){
        if(b == 1){
            cout << "Bob" << endl;
        }
        else{
            cout << "Alice" << endl;
        }
    }
    else{
        if(a == 1){
            cout << "Alice" << endl;
        }
        else{
            cout << "Bob" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int INF = 1 << 29;

int main() {
  string s;
  cin >> s;
  int N = s.size();
  for (char c = 'a'; c <= 'z'; c++) {
    int mx = -INF, j;
    int cnt = 0;
    for (int i = 0; i < N; i++) {
      if (s[i] != c) {
        continue;
      }
      ++cnt;
      int s = i - 2 * cnt;
      if (mx > s - 1) {
        cout << (j + 1) << " " << (i + 1) << endl;
        return 0;
      }
      if (s > mx) {
        mx = s;
        j = i;
      }
    }
  }
  cout << "-1 -1" << endl;
  return 0;
}


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

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

    int n;
    cin >> n;

    int nin = 1e9;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int p;
        cin >> p;
        if (p < nin) {
            ans++;
            nin = p;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int x,y,z,k,n,e,w,s;
char st[10005];
int main()
{
	scanf(" %s",st+1);
	int qw=strlen(st+1);
	for(int i=1;i<=qw;i++)
	{
		if(st[i]=='N')
			n=1;
		else if(st[i]=='E')
			e=1;
		else if(st[i]=='W')
			w=1;
		else if(st[i]=='S')
			s=1;
	}
	if(w==1 && e!=1)
	{
		printf("No");
		return 0;
	}
	if(e==1 && w!=1)
	{
		printf("No");
		return 0;
	}
	if(s==1 && n!=1)
	{
		printf("No");
		return 0;
	}
	if(n==1 && s!=1)
	{
		printf("No");
		return 0;
	}
	printf("Yes");
}
	


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

typedef long long lli;

lli n, k;

string toString(lli x){
  if(x == 0) return "0";
  string res;
  while(x != 0){
    res += x % 10 + '0';
    x /= 10;
  }
  reverse(res.begin(), res.end());
  return res;
}

main(){
  while(cin >> n >> k && (n|k)){
    lli sum = 1, r = 1, i;
    for(i=1;;i++,r*=10){
      lli t = (r * 9) * i;
      if(sum + t > n) break;
      sum += t;
    }

    string ans = "";
    lli num = r + (n - sum) / max(i, 1LL);
    lli off = (n - sum) % max(i, 1LL);
    for(;(lli)ans.size()-off<k;num++) ans += toString(num);
    cout << ans.substr(off, k) << endl;
  }
}

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

long int modpow(long int a,long int n,long int mod){
  long int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}

long int modinv(long int a,long int mod){
  return modpow(a,mod-2,mod);
}


/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/

int main(void){
  /*
  解法1

  all:=A[1]+...+A[n]として
  与式を変形すると

  (答え)=(((all-A[i])*A[i])の総和)/2
  ということがわかるので，それを実装

  「2で割る」というのは「2の逆元を掛ける」ということに言い換えられるから
  mod上での逆元を求める関数(53行目，modinv)を書いて，それを最後に掛ければよい
  
  
  */

  long int n;
  scanf("%ld",&n);

  long int A[n];
  long int all=0;

  long int MOD=1e9+7;

  for(int i=0;i<n;i++){
    scanf("%ld",&A[i]);
    all+=A[i];

    //常にMODを取る！
    all%=MOD;
  }

  long int ans=0;
  for(int i=0;i<n;i++){
    /*
    allは常にMODを取っていて，all<A[i]の可能性があるので
    MODを足して正にしないといけない

    (all-A[i])>=-(1e9+7)がいえるので，足す数は1回でいいけど
    別の問題で心配だったら2,3回足しても問題ナシ
    */
    ans+=(all-A[i]+MOD)*A[i];

    //常にMODを取る！
    ans%=MOD;
  }


  //MOD上の2の逆元
  long int v=modinv(2,MOD);

  //常にMODを取る！
  printf("%ld\n",ans*v%MOD);

  return 0;
}

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

signed main(){
  
  int A, B, C, D;
  cin>>A>>B>>C>>D;
  
  int CD = C * D / __gcd( C, D );
  
  A--;
  
  int c = B / C - A / C;
  int d = B / D - A / D;
  int cd = B / CD - A / CD;
  
  cout<<(B-A)-(c+d-cd)<<endl;
  
  return 0;
}


Measured memory_bytes: 256
// practice with Dukkha
#include <algorithm>
#include <iostream>

using namespace std;

const int N = 100000, MD = 1000000007;

int ii[N + 1];
int ff[N + 2], gg[N + 2];

int power(long long a, int k) {
	long long p = 1;
	while (k) {
		if (k & 1)
			p = p * a % MD;
		a = a * a % MD;
		k >>= 1;
	}
	return p;
}

void init(int n) {
	for (int f = 1, i = 0; i <= n; i++) {
		gg[i] = power(ff[i] = f, MD - 2);
		f = (long long) f * (i + 1) % MD;
	}
}

int ch(int n, int k) {
	return n < k ? 0 : (long long) ff[n] * gg[k] % MD * gg[n - k] % MD;
}

int main() {
	int n; cin >> n;
	init(n + 1);
	int m = 0;
	for (int i = 1; i <= n; i++) {
		int a; cin >> a;
		if (ii[a]) {
			m = n + 1 - (i - ii[a] + 1);
			break;
		}
		ii[a] = i;
	}
	for (int k = 1; k <= n + 1; k++)
		cout << (ch(n + 1, k) - ch(m, k - 1) + MD) % MD << '\n';
	return 0;
}


Measured memory_bytes: 4668
#include <string>
#include <iostream>

using namespace std;

int main()
{
	pair<int, string> prev, now; prev = make_pair(1, "kogakubu10gokan");

	int N, Q;

	cin >> N >> Q;

	for (int i = 0; i < N; i++)
	{
		cin >> now.first >> now.second;

		if (prev.first <= Q && Q < now.first)
		{
			cout << prev.second << endl; return 0;
		}

		prev = now;
	}

	cout << now.second << endl;

	return 0;
}

Measured memory_bytes: 3224
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int getid(int a, int b, int c, int d, int e) {
  int res = e, keta = 27;
  res += keta * d;
  keta *= 27;
  res += keta * c;
  keta *= 27;
  res += keta * b;
  keta *= 27;
  res += keta * a;
  keta *= 27;

  return res;
}

void print(int x) {
  vector<char> c;
  rep(i, 5) {
    int t = x % 27;
    if (t) c.push_back(t - 1 + 'a');
    x /= 27;
  }
  int m = c.size();
  repr(i, m - 1) cout << c[i];
  cout << endl;
}

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

  int n = s.size();
  vector<int> id(n);
  rep(i, n) id[i] = s[i] - 'a' + 1;

  vector<int> dict;
  rep(i, n) dict.push_back(getid(id[i], 0, 0, 0, 0));
  rep(i, n - 1) dict.push_back(getid(id[i], id[i + 1], 0, 0, 0));
  rep(i, n - 2) dict.push_back(getid(id[i], id[i + 1], id[i + 2], 0, 0));
  rep(i, n - 3) dict.push_back(getid(id[i], id[i + 1], id[i + 2], id[i + 3], 0));
  rep(i, n - 4) dict.push_back(getid(id[i], id[i + 1], id[i + 2], id[i + 3], id[i + 4]));

  sort(dict.begin(), dict.end());
  int res = 0, cnt = 0, m = dict.size();
  rep(i, m) {
    if (dict[i] != res) {
      cnt++;
      res = dict[i];
    }
    if (cnt == k) {
      print(res);
      return 0;
    }
  }






  
  return 0;
}

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

using namespace std;

const long long MOD = 1000000007;

map<long long, long long> primeFactorization(long long n) {
    map<long long, long long> ret;
    for (long long i = 2; i * i <= n; ++i) {
        if (n % i == 0) {
            ret.insert(make_pair(i, 0));
        }
        while (n % i == 0) {
            n /= i;
            ret[i] += 1;
        }
    }
    if (n != 1) {
        ret.insert(make_pair(n, 1));
    }
    return ret;
}

void Main() {
    long long N;
    cin >> N;

    map<long long, long long> factors;
    for (long long n = 2; n <= N; ++n) {
        map<long long, long long> fn = primeFactorization(n);
        for (auto e : fn) {
            if (factors.count(e.first) == 0) {
                factors.insert(make_pair(e.first, 0));
            }
            factors[e.first] += e.second;
        }
    }

    long long ans = 1LL;
    for (auto e : factors) {
        ans *= (e.second + 1LL);
        ans %= MOD;
    }
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> x(N);
  for (int i = 0; i < N; i++ ){
   cin >> x.at(i); 
  }
  
  int sum = 0;
  for (int i = 0; i < N; i++){
     if (x.at(i) < (K - x.at(i)) ){
       sum += x.at(i);
     }
    else {
      sum += (K - x.at(i)); 
    }
  }
  cout << sum*2 << endl;
  }


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <cinttypes>
#include <string.h>
#include <bits/stdc++.h>

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi vector<int>
#define vvi vector<vector<int> >
#define pi pair<int,int>
#define fi first
#define se second

#define FOR(var, to)          for (register s64 var = 0; var < (s64)to; var++)
#define FROMTO(var, from, to) for (register s64 var = from; var <= (s64)to; var++)

#define INIT(var) FOR(i,countof(var)) var[i] = 0
#define INPUT(var) FOR(i,countof(var)) var[i] = ri()

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)

#define MOD 1000000007
#define INF (1 << 30)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

using namespace std;

static inline int ri() {
  int a;
  scanf("%d", &a);
  return a;
}

static inline s64 rs64() {
  s64 a;
  scanf("%" SCNd64, &a);
  return a;
}

static inline void wi(int a) {
  printf("%d", a);
}

static inline void wu64(u64 a) {
  printf("%" PRIu64, a);
}

static inline void ws64(s64 a) {
  printf("%" PRId64, a);
}

int int_less(const void *a, const void *b) {
  return (*((const int*)a) - *((const int*)b));
}
int int_greater(const void *a, const void *b) {
  return (*((const int*)b) - *((const int*)a));
}

/* originally written by SugarDragon5 */
struct UnionFind{
    vi data;
    UnionFind(int size):data(size,-1){}
    bool unite(int x,int y){
        x=root(x);y=root(y);
        if(x!=y){
            if(data[y]<data[x])swap(x,y);
            data[x]+=data[y];data[y]=x;
        }
        return x!=y;
    }
    bool find(int x,int y){
        return root(x)==root(y);
    }
    int root(int x){
        return data[x]<0?x:data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};

int main() {
    int a = ri();
    int b = ri();
    char s[10];
    snprintf(s,10,"%d%d",a,b);
    int c = atoi(s);
    bool res = false;
    FOR(i,c) if (i*i == c) res = true;
    cout << (res?"Yes":"No") << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val argList = Scanner(System.`in`)


    val n = argList.nextLine().toInt()
    val a = mutableListOf<Int>()

    while (argList.hasNext()) {
        a.add(argList.nextLine().toInt())
    }

    val e = ExceptionHandling()
    e.execute(n, a)

}

class ExceptionHandling {
    fun execute(n: Int, a: List<Int>) {
        val firstMaxAmout = a.max()
        val secondMaxAmout = when(a.filter { it == firstMaxAmout }.size) {
            1 -> a.filter { it != firstMaxAmout }.max()
            else -> firstMaxAmout
        }

        a.forEach {
            if (it == firstMaxAmout) {
                println(secondMaxAmout)
            } else {
                println(firstMaxAmout)
            }
        }
    }
}

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

typedef long long ll;
using namespace std;
#define REP(i,n) for(int i=0; i<n;i++)

int main(){
    int n;
    double tmp,r = 0;
    char unit[4];
    
    cin >> n;
    
    REP(i,n){
        cin >> tmp >> unit;
        if(strcmp(unit,"JPY") != 0)
            tmp *= 380000;
        r += tmp;
    }
    
    cout << r << endl;
    
    return 0;
}

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

int main(){

  int W,H,x,y,r;

  cin >> W >> H >> x >> y >> r;

  if (x < 0 || y < 0){

    cout << "No" << endl;
  }

 else if (x+r > W || y+r > H){

    cout << "No" << endl;
  }

  else {
    cout << "Yes" <<endl;
  }
  return 0;
  
}

Measured memory_bytes: 1156
N = int(input())
A = list(map(int,input().split()))

X = []
for i in range(N):
    X.append(A[i]-(i+1))

X = sorted(X)
#bは数列Xの中央値
if N%2==1:
    b = X[N//2]
else:
    b = (X[N//2-1] + X[N//2]) / 2

out=0
for i in range(N):
    out+=abs(X[i] - b)

print(int(out))


Measured memory_bytes: 109320
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    ll n,i;
    cin >> n;
    ll mod=1000000007;
    ll ans=1;
    for(i=1;i<=n;i++){
      ans=ans*i%mod;
    }
    cout <<ans;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long r[10001];
char str[500001];
int qpow(int x,int y,int M){
    int rnt=1;
    while (y){
        if (y&1) rnt=(rnt*x)%M;
        y>>=1;
        x=x*x%M;
    }
    return rnt;
}
int main(){
    int len,p;
    scanf("%d%d",&len,&p);
    scanf("%s",str);
    if (p==2 || p==5){
        long long ans=0;
        for (int i=0;i<len;++i){
            int n=str[i]-'0';
            if (n%p==0) ans+=i+1;
        }
        printf("%lld",ans);
    } else {
        int s=0;
        for (int i=0;i<len;++i){
            int n=(str[i]-'0')%p;
            s=(s*10%p+n)%p;
            int val=s*qpow(10,len-i-1,p)%p;
            r[val]++;
        }
        long long ans=0;
        r[0]++;
        for (int i=0;i<p;++i) ans+=r[i]*(r[i]-1)/2;
        printf("%lld",ans);
    }
}

Measured memory_bytes: 512
from collections import deque

def dfs(graph, start, n):
    stack = deque()
    push, pop = stack.append, stack.pop
    inf = float('INF')
    costs = [inf for i in range(n)]
    visited = [False] * n
    push((start, 0))
    visited[start] = True
    costs[start] = 0

    while stack:
        a,c = pop()
        for b,cc in graph[a].items():
            if visited[b]:
                continue
            if cc + c < costs[b]:
                push((b, cc+c))
                visited[b] = True
                costs[b] = cc + c
    return costs

n = int(input())
graph = {}
for i in range(n-1):
    a,b,c = map(int, input().split())
    a -= 1
    b -= 1
    if a not in graph:
        graph[a] = {}
    if b not in graph:
        graph[b] = {}
    graph[a][b] = graph[b][a] = c

q,k = map(int, input().split())
costs = dfs(graph, k-1, n)
for _ in range(q):
    x,y = map(int, input().split())
    print(costs[x-1] + costs[y-1])
# print(costs)
    

Measured memory_bytes: 67976