akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
using namespace std;
int main(){
    int N;
    int a[104];
    bool co[8]={};
    int ans=0;
    int pro=0;
    cin >> N;
    REP(i,N){
        cin >> a[i];
        if(1<=a[i]&&a[i]<400){
            co[0]=1;
        }else if(400<=a[i]&&a[i]<800){
            co[1]=1;
        }else if(800<=a[i]&&a[i]<1200){
            co[2]=1;
        }else if(1200<=a[i]&&a[i]<1600){
            co[3]=1;
        }else if(1600<=a[i]&&a[i]<2000){
            co[4]=1;
        }else if(2000<=a[i]&&a[i]<2400){
            co[5]=1;
        }else if(2400<=a[i]&&a[i]<2800){
            co[6]=1;
        }else if(2800<=a[i]&&a[i]<3200){
            co[7]=1;
        }else if(3200<=a[i]){
            pro++;
        }
    }
    REP(i,8){
        if(co[i]==1){
            ans++;
        }
    }
    if(ans==0){cout << ans+1 << " " << ans+pro << endl;}
    else{cout << ans << " " << ans+pro << endl;}
    
    
    return 0;
}

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

int main()
{
	int N;
	cin >>N;
	int watchable=0;
	vector<int> H(N);//動的配列．標準入力によって確保する配列の量変化0
	for(int i=0;i<N;i++)
	{
		cin >> H[i];
	}

	for(int i=0;i<N;i++)
	{
		bool falg=true;
		for(int j=i;j>=0;j--)
		{
			if(H[i]<H[j])
				falg=false;
		}
		if(falg)
		{
			watchable++;
		}
	}
	cout << watchable << endl;
}

Measured memory_bytes: 256
#include <iostream>

int main()
{
	int N = 0;
	std::cin >> N;

	bool isAnswer = false;
	for (int i = 1; i <= 9; ++i)
	{
		if (N % i == 0 && (N / i) <= 9)
		{
			isAnswer = true;
		}
	}

	if (isAnswer)
	{
		std::cout << "Yes\n";
	}
	else
	{
		std::cout << "No\n";
	}

	return 0;
}

Measured memory_bytes: 256
using System;

namespace ITP1_5_A
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                var input = Console.ReadLine();
                var values = input.Split(' ');
                int H = int.Parse(values[0]);
                int W = int.Parse(values[1]);
                if (H == 0 && W == 0) break;

                for(int i=1;i<=H;i++)
                {
                    for(int j=1;j<=W;j++)
                    {
                        Console.Write("#");
                    }
                    Console.Write("\n");
                }
                Console.Write("\n");
            }
        }
    }
}

Measured memory_bytes: 5288
#include <stdio.h>

int main()
{
	int input;

	int A, Ab, B, Bb, C, Cb, D;

	scanf("%d", &input);

	Ab = input % 10000;
	A = Ab / 1000;
	Bb = input % 1000;
	B = Bb / 100;
	Cb = input % 100;
	C = Cb / 10;
	D = input % 10;



	if (A + B + C + D == 7)
		printf("%d+%d+%d+%d=7", A, B, C, D);

	else if (A - B + C + D == 7)
		printf("%d-%d+%d+%d=7", A, B, C, D);

	else if (A + B - C + D == 7)
		printf("%d+%d-%d+%d=7", A, B, C, D);

	else if (A + B + C - D == 7)
		printf("%d+%d+%d-%d=7", A, B, C, D);

	else if (A - B - C + D == 7)
		printf("%d-%d-%d+%d=7", A, B, C, D);

	else if (A + B - C - D == 7)
		printf("%d+%d-%d-%d=7", A, B, C, D);

	else if (A - B + C - D == 7)
		printf("%d-%d+%d-%d=7", A, B, C, D);

	else if (A - B - C - D == 7)
		printf("%d+%d+%d+%d=7", A, B, C, D);

	getchar(); getchar();
	return 0;

}

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

int main(){
  int i = 1, n;
  cin >> n;

  for(int k=0; k < n; ++k){
    int x = i;
    if( x % 3 == 0){
      cout << " " << i;
    }else if( x % 10 == 3 ){
      cout << " " << i;
    }else while( x /= 10 ){
	if ( x % 10 == 3 && i % 3 != 0 ){
	  cout << " " << i;
	  break;
	}
      }

    
    ++i;
  }
  cout << endl;
  

  return 0;
}



Measured memory_bytes: 3104
#include <set>
#include <cstdio>
#include <string>
#include <iostream>

using namespace std;

int main()
{
	int N; string S1, S2;

	cin >> N;

	set<string> dictionary;

	for (int i = 0; i < N; i++)
	{
		cin >> S1 >> S2;

		if (S1[0] == 'i')
		{
			dictionary.insert(S2);
		}
		else
		{
			if (dictionary.find(S2) != dictionary.end())
			{
				printf("yes\n");
			}
			else
			{
				printf("no\n");
			}
		}
	}

	return 0;
}

Measured memory_bytes: 32480
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <limits>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;

long long N, K, S, A[1 << 18], B[1 << 18];

void simulation() {
	for (int i = 1; i <= N; i++) {
		int cl = i - A[i], cr = i + A[i];
		cl = max(cl, 1);
		cr = min(cr, (int)N);
		B[cl]++; B[cr + 1]--;
	}
	for (int i = 1; i <= N + 1; i++) B[i] += B[i - 1];
	for (int i = 1; i <= N; i++) { A[i] = B[i]; B[i] = 0; }
}

int main() {
	cin >> N >> K;
	for (int i = 1; i <= N; i++) cin >> A[i];
	for (int i = 1; i <= N; i++) S += A[i];

	for (int i = 1; i <= K; i++) {
		simulation();
		bool flag = false;
		for (int j = 1; j <= N; j++) { if (A[j] != N) flag = true; }
		if (flag == false) {
			break;
		}
	}
	for (int i = 1; i <= N; i++) {
		if (i >= 2) cout << " "; cout << A[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 6748
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N,K;
    cin >> N >> K;
    if(K>(N-1)*(N-2)/2){
        cout << -1 << endl;
        return 0;
    }
    else{
        cout << N*(N-1)/2-K << endl;
        FOR(i,2,N+1){
            cout << 1 << " " << i << endl;
        }
        ll cnt=0;
        ll i=2,j=2;
        while(cnt<(N-2)*(N-1)/2-K){
            cnt++;
            if(j<N){
                j++;
            }
            else if(j==N){
                i++;
                j=i+1;
            }
            cout << i << " " << j << endl;
        }
    }
}


Measured memory_bytes: 3632
#include<stdio.h>
int main(void)
{
	int n,a[51],b[51],c[50],i,sat;
	scanf("%d",&n);
	for(i=1;i<=n;i++)	scanf("%d",&a[i]);
	for(i=1;i<=n;i++)	scanf("%d",&b[i]);
	for(i=1;i<=n-1;i++)	scanf("%d",&c[i]);
	sat=0;
	for(i=1;i<=n;i++){
		sat+=b[a[i]];
		if(a[i+1]-a[i]==1)	sat+=c[a[i]];
	}
	printf("%d\n",sat);
	return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

using P = pair<int, int>;

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

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int H, W;
  while (cin >> H >> W) {
    vector<string> grid(H);
    for (auto& x : grid) cin >> x;
    queue<P> q;
    vec<int, 2> dist = make_v(H, W, 1 << 25); 
    for (int y = 0; y < H; y++) {
      for (int x = 0; x < W; x++) {
        if (grid[y][x] == '#') {
          dist[y][x] = 0;
          q.emplace(y, x);
        }
      }
    }
    while (!q.empty()) {
      auto p = q.front();
      q.pop();
      for (int k = 0; k < 4; k++) {
        int ny = p.fst + dy[k];
        int nx = p.snd + dx[k];
        if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
        if (dist[p.fst][p.snd] + 1 < dist[ny][nx]) {
          dist[ny][nx] = dist[p.fst][p.snd] + 1;
          q.emplace(ny, nx);
        }
      }
    }
    int res = 0;
    for (int y = 0; y < H; y++) {
      for (int x = 0; x < W; x++) {
        chmax(res, dist[y][x]);
      }
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 13456
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 10000009+7

ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll lcm(ll a, ll b){return a*b/gcd(a, b);}
ll fexp(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%MOD; b/=2;a=a*a%MOD;}return ans;}
//ll inverse(ll a, ll p){return fexp(a, p-2);}

int main() {
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t=1;
    //cin>>t;
	while(t--)
	{
	  ll n,maxw;
	  cin>>n>>maxw;
	  ll dp[maxw+1]={0};
	  for(ll j=0;j<n;j++)
	  {
	      ll w,v;
	      cin>>w>>v;
	      
	      
	      for(ll i=maxw;i-w>=0;i--)
	      {
	     //  cout<<"dp[i-w] is "<<dp[i-w]<<' '<<"i-w is "<<i-w<<endl;
	        if(dp[i-w]!=0)
	         dp[i]=max(dp[i],dp[i-w]+v);
	         else  if(i-w==0)
	          dp[i]=max(dp[i],dp[i-w]+v);
	         
	         
	      }
	   //   for(ll i=0;i<maxw+1;i++)
	   //   cout<<dp[i]<<" ";
	   //   cout<<endl;
	  }
	 ll mx=0;
	 for(int i=0;i<maxw+1;i++)
	 {
	     mx=max(mx,dp[i]);
	 }
	 cout<<mx<<endl;
	  
	  
	  
	   
	}
	
	return 0;
}


Measured memory_bytes: 1024
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include<iomanip>

#define mod 1000000007
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)

using namespace std;

ll power(ll a, ll b, ll m)
{
	if (b == 0)
		return(1);
	ll sol = power(a, b / 2, m);
	sol = (sol * sol) % m;
	if (b % 2 == 1)
		sol = (sol * a) % m;
	return(sol);
}

ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	else
	{
		return gcd(b, a % b);
	}
}
vector<int>g[200001];
int val[200001];
void dfs(int u, int p)
{
	for (auto v : g[u])
	{
		if (v != p)
		{
			val[v] += val[u];
			dfs(v, u);
		}
	}
}
void solve()
{
	int n, q;
	cin >> n >> q;
	for (int i = 0; i < n - 1; i++)
	{
		int u, v;
		cin >> u >> v;
		u--, v--;
		g[u].pb(v);
		g[v].pb(u);
	}
	while (q--)
	{
		int a, b;
		cin >> a >> b;
		a--;
		val[a] += b;
	}
	dfs(0, -1);
	for (int i = 0; i < n; i++)
	{
		cout << val[i] << " ";
	}
}
int main()
{
	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 23424
#include<bits/stdc++.h>
using namespace std;
int main(){
    int h, w;
    while(1){
        cin >> h >> w;
        if(h == 0 && w == 0){
            return 0;
        }
        for(int j = 0;j < w;j++){
            cout << "#";
        }
        cout << endl;
        for(int i = 0;i < h-2;i++){
            cout << "#";
            for(int j = 0;j < w-2;j++){
                cout << ".";
            }
            cout << "#" << endl;
        }
        for(int j = 0;j < w;j++){
            cout << "#";
        }
        cout << endl << endl;
    }
}


Measured memory_bytes: 3104
class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)

    def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]

n,m,k = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(m)]
cd = [list(map(int, input().split())) for i in range(k)]
ans = [0] * n
u = UnionFind(n)
for a,b in ab:
  a-=1
  b-=1
  u.union(a,b)
for i in range(n):
  ans[i] = u.get_size(i)-1
for a,b in ab:
  a-=1
  b-=1
  if u.is_same(a,b):
    ans[a] -= 1
    ans[b] -= 1
for c,d in cd:
  c-=1
  d-=1
  if u.is_same(c,d):
    ans[c] -= 1
    ans[d] -= 1	
print(*ans)
  

Measured memory_bytes: 124376
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int MOD = 1000000007;
const ll INF = 1LL << 60;
int main() {
   cin.tie(0);
   ios::sync_with_stdio(false);
   int a, b;
   cin >> a >> b;
   cout << a * b << endl;
}

Measured memory_bytes: 3648
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
using namespace std;
   
typedef long long ll;
const int N = 100010;
int num[40];
ll a[N];

int main()
{
    int n;
    ll k;
    scanf("%d %lld", &n, &k);
    for (int i = 1; i <= n; ++i) {
        scanf("%lld", &a[i]);
    }
    for (int i = 0; i <= 39; ++i) {
        for (int j = 1; j <= n; ++j) {
            if ((a[j] >> i) & 1) {
                ++num[i];
            }
        }
    }
    ll ret = 0, ans = 0;
    for (int i = 39; i >= 0; --i) {
        if ((ret | (1LL << i)) > k) {
            ans += (ll)num[i] * (1LL << i);
        } else {
            ans += (ll)max(num[i], n - num[i]) * (1LL << i);
            if (n - num[i] > num[i]) ret += (1LL << i);
        }
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

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;
}

vector<vector<int>> board;
// required magic from a to b

// {y, x}
vector<pair<int, int>> n_to_pos;

vector<vector<ll>> memo;

void prepare(const int H, const int W, const int D) {
    memo.resize(D);
    for (int i = 0; i < D; i++) {
        memo[i].push_back(0);
        memo[i].push_back(0);
        for (int j = i + D; j <= H * W; j += D) {
            int cur = j;
            int prev = j - D;

            if (j == D) {
                continue;
            }

            pair<int, int> cur_pos = n_to_pos[cur];
            pair<int, int> prev_pos = n_to_pos[prev];
            ll cost = memo[i][(int) memo[i].size() - 1]
                + abs(cur_pos.first - prev_pos.first) + abs(cur_pos.second - prev_pos.second);
            memo[i].push_back(cost);
        }
    }
}

ll solve(const int L, const int R, const int H, const int W, const int D) {
    const int rem = L % D;
    const int ind_L = (L + D - 1) / D;
    const int ind_R = (R + D - 1) / D;
    return memo[rem][ind_R] - memo[rem][ind_L];

    // ll ans = 0;
    // for (int i = L; i < R; i+= D) {
    //     int cur = i;
    //     int next = i + D;
    //     pair<int, int> cur_pos = n_to_pos[cur];
    //     pair<int, int> next_pos = n_to_pos[next];
    //     ans += abs(cur_pos.first - next_pos.first) + abs(cur_pos.second - next_pos.second);
    // }
    // return ans;
}

int main(void) {
    int H, W, D;
    cin >> H >> W >> D;

    board.resize(H, vector<int>(W));
    n_to_pos.resize(H * W + 1);
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> board[i][j];
            n_to_pos[board[i][j]] = {i, j};
        }
    }

    prepare(H, W, D);
    // for (auto a : memo) {
    //     for (auto b : a) {
    //         cout << b << " ";
    //     }
    //     cout << endl;
    // }

    int Q;
    cin >> Q;
    for (int i = 0; i < Q; i++) {
        int L, R;
        cin >> L >> R;
        cout << solve(L, R, H, W, D) << endl;
    }

    return 0;
}


Measured memory_bytes: 9176
#!/usr/bin/env python3
import sys
import numpy as np


def solve(N: int, T: "List[int]", V: "List[int]"):
    t_period = [0 for i in range(N+1)]
    for i in range(N):
        t_period[i+1] = t_period[i] + T[i]*2

    limit = np.zeros((t_period[N]+1,))
    for i in range(1, N):
        limit[t_period[i]] = min((V[i-1], V[i]))
    for i in range(N):
        limit[t_period[i]+1:t_period[i+1]] = V[i]
    
    speed = np.zeros((t_period[N]+1,))

    for v in range(1, 201):
        speed[1:t_period[N]] = np.min([limit[1:t_period[N]], speed[0:t_period[N]-1]+0.5, speed[2:t_period[N]+1]+0.5], axis=0)

    total = 0
    for t in range(t_period[N]):
        total += (speed[t] + speed[t+1]) * 0.5 * 0.5
    
    print(total)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    t = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    v = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, t, v)

if __name__ == '__main__':
    main()


Measured memory_bytes: 15376
#include<bits/stdc++.h>
#define pi acos(-1.0)
#define N 200005
#define inf 100000005
using namespace std;
int n,X1,Y1,X2,Y2,b[N],ly,dp[N];
int val[10000005],ls[10000005],rs[10000005],cnt,Rt;
struct T
{
	int x,y;
}a[N];
bool cmp(T a,T b)
{
	return a.x<b.x;
}

int Get(int &k,int l,int r,int x,int y)
{
	//cout<<l<<r<<endl;
	if (!k) return 0;
	if (x<=l&&r<=y)
		return val[k];
	int mid=l+(r-l)/2,ans=0;
	if (x<=mid) ans=max(Get(ls[k],l,mid,x,y),ans);
	if (y>mid) ans=max(Get(rs[k],mid+1,r,x,y),ans);
	return ans;
}
void mdy(int &k,int l,int r,int x,int y)
{
	if (!k) k=++cnt;
	val[k]=max(val[k],y);
	if (l==r)return;
	int mid=l+(r-l)/2;
	if (x<=mid) mdy(ls[k],l,mid,x,y);
	else mdy(rs[k],mid+1,r,x,y);
}


int main()
{
	scanf("%d%d%d%d%d",&X1,&Y1,&X2,&Y2,&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d%d",&a[i].x,&a[i].y);
	}
	if (X2<X1)
	{
		X2=-X2;X1=-X1;
		for (int i=1;i<=n;i++)
			a[i].x=-a[i].x;
	}
	if (Y2<Y1)
	{
		Y2=-Y2;Y1=-Y1;
		for (int i=1;i<=n;i++)
			a[i].y=-a[i].y;
	}
	sort(a+1,a+n+1,cmp);
	int ans=0;
	for (int i=1;i<=n;i++)
	if (a[i].x>=X1&&a[i].x<=X2&&a[i].y>=Y1&&a[i].y<=Y2)
	{
		dp[i]=Get(Rt,-inf,inf,-inf,a[i].y)+1;
		mdy(Rt,-inf,inf,a[i].y,dp[i]);
		ans=max(ans,dp[i]);
	}
	if (ans==min(X2-X1+1,Y2-Y1+1))
		printf("%.15f\n",100.0*(X2-X1+Y2-Y1)-ans*(20-5*pi)+5*pi);
	else
		printf("%.15f\n",100.0*(X2-X1+Y2-Y1)-ans*(20-5*pi));
}

Measured memory_bytes: 33792
"""
author : halo2halo
date : 25,Oct,2019
"""

import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

N = int(readline().rstrip())
lis = list(map(int, readline().rstrip().split()))
a = sorted(lis)

print(a[-1]-a[0])


Measured memory_bytes: 3060
def main():
  from collections import deque
  n,m=map(int,input().split())
  ab=[[] for _ in range(n+1)]
  for _ in range(m):
    a,b=map(int,input().split())
    ab[a].append(b)
    ab[b].append(a)
  
  l=deque([1])
  ans=[-1]*n
  while l:
    x=l.popleft()
    for i in ab[x]:
      if ans[i-1]==-1:
        ans[i-1]=x
        l.append(i)
  print('Yes')
  for i in ans[1:]:
    print(i) 
    
if __name__=='__main__':
  main()

Measured memory_bytes: 34796
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i,l,r) for (ll i = (ll)l; i < (ll)(r); i++)
using Graph  = vector<vector<ll> >;

ll N,K; 
vector<bool> seen;
vector<ll> fseen;
ll loopsz = 0;
ll startloop = 0;

int main(){
    cin >> N >> K;
    Graph G(N+1);
    seen.assign(N+10,false);
    fseen.assign(N+10,0);

    rep(i,0,N){
        ll a; cin >> a; a--;
        G[i].push_back(a);
    }

    ll v = 0; ll s = 0;
    int k = K;
    int cnt = 0;
    while(k--){
        seen[v] = true;
        fseen[v] = cnt;
        cnt++;
 
        int nv = G[v][0];
        if(K == cnt){
            cout << nv + 1 << endl;
            return 0;
        }
        if(seen[nv]){
            loopsz = cnt - fseen[nv];
            startloop = fseen[nv];
            s = nv;
            break;
        }
        v = nv;
    }

    v = s;
    k = ((K-startloop)%loopsz);
    while(k--){
        v = G[v][0];
    }
    cout << v+1 << endl;
}

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

int main()
{
    long n, k;
    cin >> n >> k;

    long r = n % k;
    long d = abs(k - r);

    if (r < d) {
        cout << r << endl;
    } else {
        cout << d << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n;
  int v[100010] = {};
  int count_odd[100010] = {};//count1[i]:v[0],v[2],...におけるiの出現数
  int count_even[100010] = {};//count1[i]:v[1],v[3],...におけるiの出現数

  scanf("%d", &n);
  for(int i = 0; i < n; i++){
    scanf("%d", &v[i]);
  }

  for(int i = 0; i < n/2; i++){
    count_odd[v[2*i]]++;
    count_even[v[2*i+1]]++;
  }

  //count_odd[], count_even[]の最大値max_odd, max_evenを求める．
  int max_odd = 0, max_even = 0;
  for(int i = 1; i <= 100000; i++){
    if(count_odd[i] > max_odd){
      max_odd = count_odd[i];
    }
    if(count_even[i] > max_even){
      max_even = count_even[i];
    }
  }

  //v[0],v[2],...およびv[1],v[3],...における最小の最頻値v_odd, v_maxを求める．
  int v_odd, v_even;
  for(int i = 1; i <= 100000; i++){
    if(count_odd[i] == max_odd){
      v_odd = i;
      break;
    }
  }
  for(int i = 1; i <= 100000; i++){
    if(count_even[i] == max_even){
      v_even = i;
      break;
    }
  }

  if(v_odd == v_even){
    //count_odd[], count_even[]からv_odd, v_maxを除いた中での最大値max_odd_dash, max_even_dashを求める．
    int max_odd_dash = 0, max_even_dash = 0;
    for(int i = 1; i <= 100000; i++){
      if(i != v_odd && count_odd[i] > max_odd_dash){
        max_odd_dash = count_odd[i];
      }
      if(i != v_even && count_even[i] > max_even_dash){
        max_even_dash = count_even[i];
      }
    }

    if(max_odd_dash == 0 && max_even_dash == 0){
      printf("%d\n", n/2);
    }else if(max_odd_dash > max_even_dash){
      printf("%d\n", n - max_odd_dash - max_even);
    }else{
      printf("%d\n", n - max_odd - max_even_dash);
    }

  }else{
    printf("%d\n", n - max_odd - max_even);
  }

  return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
 
#define  rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i>=0; i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

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; }
typedef long long ll;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int N; std::cin >> N;
  std::cout << N * N * N << std::endl;
  return 0;
}


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 K;
  string S;
  cin>>K>>S;

  if(S.size()<=K){cout<<S<<endl;}
  else{rep(i,K){cout<<S.at(i);}cout<<"..."<<endl;}
}


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

#include <iostream>
int main(){
    string s;
    int a,b,c,d,e;

    cin>>a>>b;
    cout<<(a-1)*(b-1)<<endl;

    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const double eps = 1E-18;

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

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

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	mint operator^(const ll& t)const {
		if (!t) return 1;
		mint a = *this^(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;


///////////////////////////
bool prime(ll n) {
	for (ll i = 2; i * i <= n; i++) {
		if (n % i == 0) { return false; }
	}
	return true;
}

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

	vector<ll> p;

	rep(i, 10000) {
		if (i>2&&prime(i)) { p.push_back(i); }
	}

	ll M = (N + 1) / 2+1;

	vvll a(N + 2, vll(N + 2, 1));

	set<ll> st;

	rep(i, N+2) {
		rep(j, N+2) {
			if ((i + j) % 2 == 1) {
				a[i][j] = p[i / 2] * p[j / 2 + M];
				if (i % 2 == 0) { a[i][j] *= 2; }
				st.insert(a[i][j]);
			}
		}
	}

	
	repn(i, N)repn(j, N) {
		if ((i + j) % 2 == 0) {
			ll X = lcm(a[i - 1][j], lcm(a[i + 1][j], lcm(a[i][j - 1], a[i][j + 1])));

			for (ll k = X + 1; k >= 0; k += X) {
				if (!st.count(k)) {
					a[i][j] = k;
					st.insert(k);
					break;
				}
			}
		}
	}

	repn(i, N) {
		repn(j, N) {
			cout << a[i][j] << " ";
		}
		cout << endl;
	}


}


Measured memory_bytes: 16640
#include<iostream>
#include<cstdio>

using namespace std;

int main(){
  int w,h;
  char cmap[200][200];
  bool used[200][200];

  while(true){
    cin >> w >> h;
    if(w+h == 0)break;
    for(int i=0;i<200;i++)for(int j=0;j<200;j++)used[i][j]=false;

    for(int i=0;i<w;i++){
      for(int j=0;j<h;j++){
	cin >> cmap[i][j];
	used[i][j]=false;
      }
    }

    int x,y;
    x=y=0;
    bool fin=false;

    while(!used[y][x] && cmap[y][x] != '.'){
      used[y][x] = true;
      if(cmap[y][x] == '>' && x+1 <h){
	x++;
      }
      else if(cmap[y][x] == 'v' && y+1 < w){
	y++;
      }
      else if(cmap[y][x] == '^' && y-1 >= 0){
	y--;
      }
      else if(cmap[y][x] == '<' && x-1 >= 0){
	x--;
      }

      if(used[y][x]){
	cout << "LOOP" << endl;
 	fin = true;
      }
    }
    if(!fin){
      cout << x << " " << y << endl;
    }






  }

  return 0;
}

Measured memory_bytes: 0
N, M = map(int, input().split())
l = []
for i in range(N):
  l.append(list(map(int, input().split())))
  
l.sort()
cnt, ans = 0, 0
for i in range(N):
  if cnt+l[i][1] <= M:
    cnt += l[i][1]
    ans += l[i][0] * l[i][1]
  else:
    ans += (M-cnt) * l[i][0]
    break
print(ans)

Measured memory_bytes: 90324
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,n) for(ll i=0;i<n;i++)
#define repp(i,a,b) for(ll i=a;i<=b;i++)
#define reff(i,a,b) for(ll i=a;i>=b;i--)
#define ll long long int
#define pll pair<ll,ll>
#define fill(a,x) memset(a,x,sizeof(a))
#define mb make_pair
#define pb push_back
#define F first
#define S second
#define M 1000000007
#define sc(x) scanf("%d",&x)
#define scc(x1,x2) scanf("%d%d",&x1,&x2)
#define sccc(x1,x2,x3) scanf("%d%d%d",&x1,&x2,&x3)
#define pr(x) printf("%lld ",x)
#define dbg(a)          std::cerr<<#a<<"="<<(a)<<"\n"
#define dbg1(a,b)       std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define dbg2(a,b,c)     std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define dbg3(a,b,c,d)   std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define all(v) v.begin(),v.end()
#define PI 3.14159265
#define co cout<<"fuck"<<endl
const int INF = 2034567891;
const ll INF64 = 4234567890123456789ll;
long long nc3(long long v){return (v * (v - 1ll) * (v - 2ll)) / 6ll;}
long long nc2(long long v){return (v * (v - 1ll)) / 2ll;}
ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return (a * (b / gcd(a, b))); }
const int N = 10+2e5;
bool isprime(ll n) {
    if (n < 2) return 0;
    if (n == 2) return 1;
    if (n % 2 == 0) return 0;
    for (ll i = 3; i*i <= n; i++) if (n%i == 0) return 0;
    return 1;
}
double dist(pll p1, pll p2)
 {
    return (p1. F - p2.F)*(p1.F - p2.F) +
          (p1.S - p2.S)*(p1.S - p2.S);
 }
ll power(ll x,ll y)
{
    ll ans=1;
    while(y>0){
        if(y&1)
            ans=(ans*x)%M;
        x=(x*x)%M;
        y/=2;
    } 
    return ans;
}
ll E[10];
ll A[50],B[50],C[50],D[50];
ll n,m,q;
ll ans;
void dfs(ll id, ll pre)
{
    //dbg1(id,pre);
    if(id==n)
    {
        ll cnt=0;
        rep(i,q) 
        {
           if((E[B[i]-1]-E[A[i]-1]) == C[i])
           cnt+=D[i];
		}
		if(ans<cnt) ans=cnt;
	}
	else
	{
	    repp(j,pre,m)
	    {
	        E[id]=j;
	        dfs(id+1,j);
		}
	}
}
int main()
{
     fast;
     cin>>n>>m>>q;
     rep(i,q) cin>>A[i]>>B[i]>>C[i]>>D[i];
     dfs(0,1);
	 cout<<ans;     
}   

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


#define n_max llong(2e5 + 5)



llong fac[n_max];  /// fac[n] = n!
llong finv[n_max]; /// (fac[n] * finv[n]) % MOD = 1
llong inv[n_max];  /// (n * inv[n]) % MOD = 1
 
void init() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  FOR (i, 2, n_max) {
    fac[i] = fac[i-1]*i % MOD;
    inv[i] = MOD - inv[MOD%i]*(MOD/i) % MOD;
    finv[i] = finv[i-1]*inv[i] % MOD;
  }
}
 
llong nCk (int n, int k) {
  if (n < k || k < 0 || n < 0) return 0;
  return fac[n]*finv[k]%MOD*finv[n-k]%MOD;
}


signed main(){
    init();
    int n,m,k;
    cin >> n >> m >> k;
    int yoko_ki = m * m % MOD;
    int yokowa = 0;
    int tmp = 0;
    REP(i,n){
        tmp += i;
        yokowa += tmp;
        tmp %= MOD;
        yokowa %= MOD;
    }
    yoko_ki = yoko_ki * yokowa % MOD;

    int tate_ki = n * n % MOD;
    int tatewa = 0;
    tmp = 0;
    REP(i,m){
        tmp += i;
        tatewa += tmp;
        tmp %= MOD;
        tatewa %= MOD;
    }
    tate_ki = tate_ki * tatewa % MOD;
    


    int ki = tate_ki + yoko_ki;
    if(k == 2){
        cout << ki << endl;
    }
    else{
        ki *= nCk(n * m - 2,k-2);

        cout << ki % MOD << endl;
    }
}


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

const long long MAXN = 100010;

int dp[MAXN];
int arr[MAXN];

int main() {
    int n,k;
    cin>>n>>k;
    int mine = 1000000000;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        mine = min(arr[i],mine);
    }
    for(int i=mine;i<=k;i++){
        for(int j=0;j<n;j++){
            if(i-arr[j]>=0){
                if(!dp[i-arr[j]]){
                    dp[i] = 1;
                }
            }
        }
    }
    if(dp[k]){
        cout<<"First";
    }else{
        cout<<"Second";
    }
}


Measured memory_bytes: 640
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <ctime>
#include <algorithm>
#define N 201000
typedef long long ll;
template <typename T> inline void read(T &x) {
	x = 0; char c = getchar(); bool flag = false;
	while (!isdigit(c)) { if (c == '-')	flag = true; c = getchar(); }
	while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); }
	if (flag)	x = -x;
}
using namespace std;
const int P = 1e9 + 7;
const int inf = 987654321;
inline void MIN(int &a, int b) {
	if (b < a)	a = b;
}
int n, m;
char s[N];
namespace jzp1 {
	ll jie[N], jieni[N];
	inline ll get_c(int n, int m) {
//		printf("get_c(%d, %d)\n", n, m);
		if (n < 0 || m < 0 || n - m < 0)	return 0;
//		printf("get_c(%d, %d)\n", n, m);
		return jie[n] * jieni[m] % P * jieni[n - m] % P;
	}
	inline ll quickpow(ll x, int k) {
		ll res = 1;
		while (k) {
			if (k & 1)	res = res * x % P;
			x = x * x % P;
			k >>= 1;
		}
		return res;
	}
	inline void sol() {
//		while(1);
		if (n == 1) { puts("1"); return ; }
		jie[0] = jieni[0] = 1;
		int up = n + 1;
		for (int i = 1; i <= up; ++i)	jie[i] = jie[i - 1] * i % P;
		jieni[up] = quickpow(jie[up], P - 2);
		for (int i = up - 1; i; --i)	jieni[i] = jieni[i + 1] * (i + 1) % P;
		ll res = 0;
		for (int i = 0; i <= n; ++i) {
			res = (res + get_c(n - i + 1, i) - get_c(n - i - 1, i - 2)) % P;
//			printf("res = %lld\n", res);
		}
		printf("%lld\n", (res % P + P) % P);
	}
}
ll f[N];
ll sum[N];
int main() {
	read(n), read(m);
	scanf("%s", s + 1);
	bool flag = false;
	int tmp = 0;
	for (int i = 1; i <= m; ++i)	if (s[i] != s[1]) { flag = true; tmp = i - 1; break; }
	if (!flag) { jzp1::sol(); return 0; }
	if (n & 1) { puts("0"); return 0; }
	int lst = 1, mn = tmp | 1;
	for (int i = 2; i <= m; ++i) {
//		printf("i = %d, mn = %d\n", i, mn);
		if (s[i] != s[1]) {
			if (lst & 1)	MIN(mn, lst);
			lst = 0;
			continue;
		}
		if (s[i] == s[i - 1])	++lst;
		else {
			if (lst & 1) MIN(mn, lst);
			lst = 1;
		}
	}
	if (mn == inf) {
//		while (1);
		int memo = 1;
		for (int i = 1; s[i] == s[1]; ++i) memo = i;
		mn = memo + 1;
		printf("memo = %d\n", memo);
	}
	n >>= 1;
	int k = (mn + 1) >> 1;
	MIN(k, n);
	f[0] = 1; sum[0] = 1;
//	printf("n = %d, k = %d\n", n, k);
	for (int i = 1; i <= n; ++i) {
		if (i <= k)	f[i] = sum[i - 1];
		else f[i] = (sum[i - 1] - sum[i - k - 1]) % P;
		sum[i] = (sum[i - 1] + f[i]) % P;
	}
	ll ans = 0, mx = k;
	const int mod = 1e9 + 7;
		for(int i = 0 ; i <= n ; ++i)
		if(n - i <= mx) (ans += (ll)f[i] * (n - i) % mod * 2 % mod) %= mod;
//	ll ans = 0;
//	for (int i = 1; i <= k; ++i) {
//		ans = (ans + f[n - i] * i) % P;
//	}
//	ans = (ans << 1) % P;
	printf("%lld\n", (ans % P + P) % P);
	return 0;
}

/*
3 3
BBB
//4

1 1
B
//1

12 10
RRRRBRRRRB
//78

6 5
RRBBR
//8
*/

Measured memory_bytes: 6516
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
      
     Scanner sc = new Scanner(System.in);
		int D = sc.nextInt(); 
		int N = sc.nextInt();

        if (N == 100) {
			N = 101;
		}
      
		if (D == 0) {
			System.out.println(N);
		} else if (D == 1) {
			System.out.println(100 * N);
		} else if (D == 2) {
			System.out.println(10000 * N);
		}
	}
}


Measured memory_bytes: 21972
#include <iostream>
#include <string>
#include <set>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

std::string s;
int K;
std::set<std::string> S;

int main()
{
  std::cin >> s >> K;

  S.insert( s );

  int N = s.size();
  rep( i, N ) rep( j, 100 )
    S.insert( s.substr( i, j+1 ) );
  
  int cnt = 0;
  for( auto it = S.begin(); it != S.end(); ++it )
  {
    ++cnt;

    if( cnt == K )
    { std::cout << *it << std::endl; break; }
  }

  return 0;
}


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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############
N,D = inputIL()
X  = inputILL(N)

ans = 0
for i in range(N):
  for j in range(i+1,N):
    d = pow(sum((X[i][d]-X[j][d])**2 for d in range(D)),1/2)
    if d == int(d):
      ans += 1
print(ans)


Measured memory_bytes: 63980
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <chrono>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T>inline bool chmax(T &a, T b){return (a < b ? a = b, true : false);}
template<typename T>inline bool chmin(T &a, T b){return (a > b ? a = b, true : false);}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;
const long double EPS = 1e-9;


int main() {
    string a, b;
    cin >> a >> b;
    cout << (a == b ? "H" : "D") << endl;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
l=[]
tmp=0
for i in range(n):
    tmp+=a[i]
    l.append(tmp)
ans=[]
for k in range(n-1):
    ans.append(abs(l[k]-(l[-1]-l[k])))
print(min(ans))


Measured memory_bytes: 28728
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

const int MAX = 710000;
long long fac[MAX], finv[MAX], inv[MAX];
 
//使う前に実行
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}
 
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

int main() {
    ll n, k, ans = 0;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n)cin >> a[i];
    sort(all(a));
    COMinit();
    rep(i, n-k+1){
        ans = ans - (COM(n-i-1, k-1) % mod) * (a[i] % mod) % mod;
    }
    reverse(all(a));
    rep(i, n-k+1){
        ans = ans + (COM(n-i-1, k-1) % mod) * (a[i] % mod) % mod;
    }
    cout << ans % mod << endl;
}


Measured memory_bytes: 17280
#include <stdio.h>
#include <string.h>

int main()
{
    int ans = 0;
    int i,j;
    char s[101];
    // 整数の入力
    scanf("%s",s);
    // 解析
    for (i=0;i<strlen(s);++i)
    {
        if (s[i]=='C')
        {
            for (j=i+1;j<strlen(s);++j)
            {
                if (s[j]=='F')
                {
                    ans = 1;
                }
            }
        }
    }
    // 出力
    printf("%s\n", ans? "Yes":"No");
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define Fast_cin ios::sync_with_stdio(false), cin.tie(0);
#define rep(i, a, b) for(register int i = a; i <= b; i++)
#define per(i, a, b) for(register int i = a; i >= b; i--)
using namespace std;
 
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long long ll;
 
template <typename _T>
inline void read(_T &f) {
    f = 0; _T fu = 1; char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') fu = -1; c = getchar(); }
    while(c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
    f *= fu;
}
 
template <typename T>
void print(T x) {
    if(x < 0) putchar('-'), x = -x;
    if(x < 10) putchar(x + 48);
    else print(x / 10), putchar(x % 10 + 48);
}
 
template <typename T>
void print(T x, char t) {
    print(x); putchar(t);
}
 
template <typename T>
struct hash_map_t {
    vector <T> v, val, nxt;
    vector <int> head;
    int mod, tot, lastv;
    T lastans;
    bool have_ans;
 
    hash_map_t (int md = 0) {
        head.clear(); v.clear(); val.clear(); nxt.clear(); tot = 0; mod = md;
        nxt.resize(1); v.resize(1); val.resize(1); head.resize(mod);
        have_ans = 0;
    }
 
    void clear() { *this = hash_map_t(mod); }
 
    bool count(int x) {
        int u = x % mod;
        for(register int i = head[u]; i; i = nxt[i]) {
            if(v[i] == x) {
                have_ans = 1;
                lastv = x;
                lastans = val[i];
                return 1;
            }
        }
        return 0;
    }
 
    void ins(int x, int y) {
        int u = x % mod;
        nxt.push_back(head[u]); head[u] = ++tot;
        v.push_back(x); val.push_back(y);
    }
 
    int qry(int x) {
        if(have_ans && lastv == x) return lastans;
        count(x);
        return lastans;
    }
};

const int N = 2e5 + 5;

vector <int> t[N];
int a[N], id[N], cnt[N], st[N];
int n, val, top;
ll k;

pii find_next(int x) {
    pii ans;
    if(id[x] == (int)t[a[x]].size() - 1) {
        ans.first = t[a[x]][0] + 1;
        ans.second = 1;
        if(ans.first == n + 1) ans.first = 1, ++ans.second;
    } else {
        ans.first = t[a[x]][id[x] + 1] + 1;
        ans.second = 0;
        if(ans.first == n + 1) ans.first = 1, ++ans.second;
    }
    return ans;
}

int main() {
    read(n); read(k);
    for(register int i = 1; i <= n; i++) read(a[i]), t[a[i]].push_back(i), id[i] = t[a[i]].size() - 1;
    pii ans = find_next(1);
    int now = ans.first; val = ans.second;
    while(now != 1) {
        ans = find_next(now);
        now = ans.first;
        val += ans.second;
    }
    k %= val; now = 1; int nowid = 1;
    if(!k) return 0;
    while(nowid <= k) {
        ans = find_next(now);
        if(nowid + ans.second <= k) {
            now = ans.first;
            nowid += ans.second;
        } else if(nowid + ans.second == k + 1 && ans.first == 1) {
            return 0;
        } else break;
    }
    for(register int i = now; i <= n; i++) {
        if(!cnt[a[i]]) st[++top] = a[i], ++cnt[a[i]];
        else { while(cnt[a[i]]) --cnt[st[top]], --top; }
    }
    for(register int i = 1; i <= top; i++) print(st[i], i == top ? '\n' : ' ');
    return 0;
}

Measured memory_bytes: 15616