akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int k;
    cin>>k;
    int r[k],c[k];
    rep(i,k){
        cin>>r[i]>>c[i];
    }

    vector<int> ord(8);
    rep(i,8) ord[i]=i;

    do{
        bool ok=true;
        rep(i,k){
            if(ord[r[i]]!=c[i]) ok=false;
        }

        int q[8][8];
        rep(i,8){
            rep(j,8){
                q[i][j]=0;
            }
        }
        rep(i,8){
            q[i][ord[i]]=1;
        }

        rep(i,8){
            rep(j,8){
                if(q[i][j]==1){
                    int k=i+1,l=j+1;
                    while(k<8 && l<8){
                        if(q[k][l]==1) ok=false;
                        k++,l++;
                    }
                    k=i+1,l=j-1;
                    while(k<8 && l>=0){
                        if(q[k][l]==1) ok=false;
                        k++,l--;
                    }
                    k=i-1,l=j-1;
                    while(k>=0 && l>=0){
                        if(q[k][l]==1) ok=false;
                        k--,l--;
                    }
                    k=i-1,l=j+1;
                    while(k>=0 && l<0){
                        if(q[k][l]==1) ok=false;
                        k--,l++;
                    }
                }
            }
        }
        if(ok){
            rep(i,8){
                rep(j,8){
                    if(q[i][j]==1) cout<<'Q';
                    else cout<<'.';
                }
                cout<<endl;
            }
            return 0;
        }

    }while(next_permutation(all(ord)));
}
    





Measured memory_bytes: 3112
sub f{$_[$i+1]=$_[$i++]^$_^$_[$i]for@s;$_[$i=0]^pop||$_[-1]^"@_"^$s^$_[1]||exit!print map$_?W:S,@_}<>;($s,@s)=`tr ox 01`=~/./g;f$_>>1,$_&1for 0..3;print-1

Measured memory_bytes: 31180
N,M=map(int,input().split())
H=list(map(int,input().split()))
MaxH=[0]*N
z=0
for i in range(M):
    a,b=map(int,input().split())
    MaxH[a-1]=max(MaxH[a-1],H[b-1])
    MaxH[b-1]=max(H[a-1],MaxH[b-1])

for i in range(N):
    if H[i]>MaxH[i]:
        z+=1
print(z)

Measured memory_bytes: 19920
n, k = map(int, input().split())
accept = input()
list = []
for i in range(n):
    list.append(accept[i])
if list[k-1] == "A":
    list[k-1] = "a"
elif list[k-1] == "B":
    list[k-1] = "b"
elif list[k-1] == "C":
    list[k-1] = "c"
    
ans = list[0]
for j in range(n-1):
    ans += list[j+1]
    
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
int n=scan.nextInt();
int k=scan.nextInt();
int[] p=new int[n];

int i=0;
for(i=0;i<n;i++){
    p[i]=scan.nextInt();
}

int max=0;
for(i=0;i<k;i++){
    max=max+p[i];
}
int temp=max;
if(n>k){
    for(i=1;i<=n-k;i++){
        temp=temp-p[i-1]+p[i+k-1];
        if(max<temp){
            max=temp;
        }
    }
}
double ma=(double)max;

System.out.println((ma+k)/2.0);
}
}

Measured memory_bytes: 74444
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;
 
#define sz(a) int(a.size())
 
#define dbg(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {
    cerr << str << " : " << t << "\n";
}
template <class T, class... S> void dbs(string str, T t, S... s) {
    int idx = str.find(',');
    cerr << str.substr(0, idx) << " : " << t << ",";
    dbs(str.substr(idx + 1), s...);
}
template <class S, class T>
ostream& operator <<(ostream& os, const pair<S, T>& p) {
    return os << "(" << p.first << ", " << p.second << ")";
}
template <class T> void debug(T a, T b) {
    cerr << "[";
    for (T i = a; i != b; ++i) {
        if (i != a) cerr << ", ";
        cerr << *i;
    }
    cerr << "]\n";
}
 
ll getCount(ll n, ll p) {
    ll ret = 0;
    ll q = p;
    while (n >= q) {
        ret += n / q;
        if (q <= n / p) {
            q *= p;
        } else {
            break;
        }
    }
    return ret;
}
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
   
    ll ai, ao, at, aj, al;
    cin >> ai >> ao >> at >> aj >> al;
    ll ans = ao;
    for (ll i = 0; i <= ai and i <= aj and i <= al and i <= 1; ++i) {
        ll x = ai - i;
        ll y = aj - i;
        ll z = al - i;
        ll cur = ao + i * 3 + x - (x & 1) + y - (y & 1) + z - (z & 1);
        ans = max(ans, cur);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
n = int(input())
ab = [list(map(int,input().split())) for _ in range(n)]

ab.sort(key=lambda x: x[1])
t = 0
flag = True
for i in range(n):
    t += ab[i][0]
    if t > ab[i][1]:
        flag = False
    #print(t,ab[i][1])
if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 53728
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
#define PI acos(-1)
#define oo LLONG_MAX
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
/*

N=2 M=2
1 2
2 1

2 1
1 2

M以下の整数
1 1
とかはもうない。

5 9とかだったら？
12345
34567
8通り
 23以外の7通り
  777


2 2 = 2通り
2 3 = 18通り

1 2 = 23,21,31
1 3 = 21,31,32
2 1
2 3
3 1
3 2
3*6=18

2 4
12 13 14
21 23 24
=12
212324,3134,4143=7通り
84通りかな

自分と同じ数字がM-1通り。自分と違う数字が(M-2)*(M-2)
それがmP2通り
mPn*(M-1)*(M-2)*(M-2)

3 3
123 231,312 2通り
132
213
..=6通り
6*2=12

mPn
3*2*2*1*1

5 9として
12345
5421
    5通り(3,6,7,8,9)
A軍にある数を使うか使わないか。
9-5=4個
1個使う場合。
1-5のどれかを5か所のどこかに1か所、6-9を4か所
(5-1) * 5C1 * 4P4+
2箇所/3箇所
(5-1) * (4-1) * 5C2 * 4P3+
(5-1)P3 * 5C3 * 4P2
iはNからM-Nまで（Nに含まれる数）
(n-1)Pi * nCi * (n-m)P(n-i)
これに、A軍の選び方,mPn


123 
124 134 234で構成
214 241 412
314 341 431
234 432 342=9通り
3* 3C2かな。123のうち2個を選ぶ。

Ai = Biも許容して、そこからほう助原理でひいてく。

M=12345
N=3

123

mPs*((m-s)P(n-s))^2
sはAs = Bsの個数。0からNまで動く。

(m-s)P(n-s)って
s=1だとして
1xxxx
1xxxx
が、
12345
12345も含まれてる。それが包除原理か。


M = 12345
N = 3

[123] (1,2), (2,1) (3,0)
(1,2) = 3C1 * (3-1)P1 * 2C2 * 3C2 +
(2,1) = 3C2 * (3-1)P2 * 

12345678
   5 1 4 2 3
   5 1 4 3 2
A={1,2,3,4,5}
B={1,2,3,4,5}
   4*3*2*1*1 //A群に含まれる数字を持ってきた場合
B={6,7,8,9,10}
   5*4*3*2*1 //A群にない数字を持ってきた場合


A={1,2,3,4,5}
B={1,2,6,7,8}

1,2の置き方 4*3 = 12通り
   5P5 - 5P4 + 5P3
A={1,2,3,4,5}
   2,1,x,x,x
   2,x,1,x,x
   2,x,x,1,x
   2,x,x,x,1
   x,1,2,x,x
   x,1,x,2,x
   x,1,x,x,2
   x,x,2,1,x
   x,x,2,x,1
   x,x,1,2,x
   x,x,1,x,2
   x,x,x,1,2
   x,x,x,2,1
   20 - 8 + 1 = 13
   //A群5個のなかから、2個をもってきた場合の組み合わせ
なんで12個じゃないんだろう。結局ほうじょ

i = 合致してる数
mPi * ((m-i)P(n-i))^2 * nCi * (-1)^i


[1]3457
[1]4532
3[1]456
3[1]427
3214[5]
3641[5]

7P4
*/

const int MAX = 500010;
const int MOD = 1000000007;

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;//逆元の階上
  }
}

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

ll EX(int n, int m){
  ll ans = fac[n];
  if(m > n)
    m == n;
  ans *= finv[n-m];
  ans %= MOD;
  if (ans == 0)
    ans = 1;
  return ans;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  COMinit();
  ll N, M, ans = 0; cin >> N >> M;
  //mPi * ((m-i)P(n-i))^2 * nCi * (-1)^i
  rep(i, N+1){
    ll tmp = EX(M, i);
    tmp *= EX(M-i, N-i);
    tmp %= MOD;
    tmp *= EX(M-i, N-i);
    tmp %= MOD;
    tmp *= COM(N, i);
    tmp %= MOD;
    if (i%2)
      tmp *= -1;
    ans += tmp;
    ans = (ans + MOD) % MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 15308
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<queue>
#include<functional>
#include<map>

using namespace std;

typedef pair<int,int> P;

struct edge{
  int to,cap,cost,rev;
};

const int N=6000;
const int INF=1<<29;
int V;
vector<vector<edge> > G;
int h[N];
int dist[N];
int prevv[N],preve[N];

void set_id(map<int,int> &m){
  int x=0;
  for(auto &e:m){
    e.second=x++;
  }
}

void add_edge(int from,int to,int cost=0,int cap=INF){
  G[from].push_back({to,cap,cost,(int)G[to].size()});
  G[to].push_back({from,0,-cost,(int)G[from].size()-1});
}

pair<int,int> min_cost_flow(int s,int t,int g){
  int res=0;
  fill(h,h+V,0);
  int f=0;
  while(f<g){
    priority_queue<P,vector<P>,greater<P> > que;
    fill(dist,dist+V,INF);
    dist[s]=0;
    que.push({0,s});
    while(!que.empty()){
      P p=que.top();
      que.pop();
      int v=p.second;
      if(dist[v]<p.first)continue;
      for(int i=0;i<G[v].size();i++){
	edge &e=G[v][i];
	if(e.cap>0&&dist[e.to]>dist[v]+e.cost+h[v]-h[e.to]){
	  dist[e.to]=dist[v]+e.cost+h[v]-h[e.to];
	  prevv[e.to]=v;
	  preve[e.to]=i;
	  que.push({dist[e.to],e.to});
	}
      }
    }
    if(dist[t]>=INF){
      return {f,res};
    }
    for(int v=0;v<V;v++){
      h[v]+=dist[v];
    }
    f++;
    res+=h[t];
    for(int v=t;v!=s;v=prevv[v]){
      edge &e=G[prevv[v]][preve[v]];
      e.cap--;
      G[v][e.rev].cap++;
    }
  }
  return {f,res};
}


int main(){
  for(int n;cin>>n,n;){
    map<int,int> in[100],out[100];
    int o[101]={2};
    int m[100];
    int x[100][20],y[100][20],c[100][20];
    G=vector<vector<edge> >(N);
    for(int i=0;i<n-1;i++){
      cin>>m[i];
      for(int j=0;j<m[i];j++){
	cin>>x[i][j]>>y[i][j]>>c[i][j];
	in[i][x[i][j]];
	out[i][y[i][j]];
      }
      set_id(in[i]);
      set_id(out[i]);
      for(int j=0;j<m[i];j++){
	add_edge(o[i]+in[i][x[i][j]],o[i]+in[i].size()+out[i][y[i][j]],c[i][j]);
      }
      if(i){
	for(auto e:out[i-1]){
	  for(auto f:in[i]){
	    if(e.first<=f.first){
	      add_edge(o[i-1]+in[i-1].size()+out[i-1].size()+e.second,o[i]+f.second);
	    }
	  }
	}
      }
      for(auto e:out[i]){
	add_edge(o[i]+in[i].size()+e.second,o[i]+in[i].size()+out[i].size()+e.second,0,1);
      }
      o[i+1]=o[i]+in[i].size()+2*out[i].size();
    }
    for(auto e:in[0]){
      add_edge(0,2+e.second);
    }
    for(auto f:out[n-2]){
      add_edge(o[n-2]+in[n-2].size()+out[n-2].size()+f.second,1);
    }
    V=o[n-1];
    int g;
    cin>>g;
    auto r=min_cost_flow(0,1,g);
    cout<<r.first<<' '<<r.second<<endl;
  }
}

    

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

public class C {
    public static void Main() {
        int k = int.Parse(Console.ReadLine().Split(' ')[1]);
        var h = Console.ReadLine().Split(' ').Select(long.Parse);

        Console.WriteLine(h.OrderByDescending(x => x).Skip(k).Sum());
    }
}

Measured memory_bytes: 40320
import sys
from collections import defaultdict

#+++++
		
def main():
	n, k = map(int, input().split())
	aal = list(map(int, input().split()))
	
	sss = [0]*(n+1)
	si=0
	for i, a in enumerate(aal):
		si+=a-1
		sss[i+1]=si%k
	
	count=0
	mkl_dict=defaultdict(lambda :0)
	for j in range(n+1):
		sj=sss[j]
		if j-k >= 0:
			mkl_dict[sss[j-k]]-=1
		count += mkl_dict[sj]
		mkl_dict[sj] += 1
			
	print(count)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 41344
N = int(input())
s = input()

pat1 = [-1] * N
pat2 = [-1] * N
pat3 = [-1] * N
pat4 = [-1] * N

pat1[1] = pat2[1] = 1
pat3[1] = pat4[1] = 0

if s[1] == 'o':
	pat1[0] = pat1[2] = 0
	pat2[0] = pat2[2] = 1
	pat3[0] = pat4[2] = 0
	pat3[2] = pat4[0] = 1

else:
	pat1[0] = pat2[2] = 0
	pat2[0] = pat1[2] = 1
	pat3[0] = pat3[2] = 0
	pat4[2] = pat4[0] = 1


#print([pat1,pat2,pat3,pat4])

for i in range(2,N-1):
	for lis in [pat1,pat2,pat3,pat4]:
		if lis[i] == 1:
			if s[i] == 'o':
				lis[i+1] = lis[i-1]

			else:
				lis[i+1] = (lis[i-1] + 1)%2
		else:
			if s[i] == 'x':
				lis[i+1] = lis[i-1]

			else:
				lis[i+1] = (lis[i-1] + 1)%2

#print([pat1,pat2,pat3,pat4])

def ok1(List):
	global s
	if List[N-1] == 1:
		if s[N-1] == 'o':
			return List[N-2] == List[0]
		else:
			return List[N-2] != List[0]

	else:
		if s[N-1] == 'x':
			return List[N-2] == List[0]
		else:
			return List[N-2] != List[0]

def ok2(List):
	global s
	if List[0] == 1:
		if s[0] == 'o':
			return List[N-1] == List[1]
		else:
			return List[N-1] != List[1]

	else:
		if s[0] == 'x':
			return List[N-1] == List[1]
		else:
			return List[N-1] != List[1]





flg = []
for lis in [pat1,pat2,pat3,pat4]:
	if ok1(lis) and ok2(lis):
		flg = lis
		break
	
#print(flg)
ans = ""
if flg != []:
	for num in flg:
		if num ==  0:
			ans += 'W'
		else:
			ans += 'S'

	print(ans)

else:
	print(-1)


Measured memory_bytes: 6772
#include<cstdio>
using namespace std;

int n, A[50];

// 入力値のMから選んだ要素を引いて行く再帰関数
int solve(int i, int m) {
    if (m == 0) return 1;
    if (i >= n) return 0;
    int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
    return res;
}

int main() {
    int q, M, i;

    scanf("%d", &n);
    for (i = 0; i < n; i++) scanf("%d", &A[i]);
    scanf("%d", &q);
    for (i = 0; i < q; i++) {
        scanf("%d", &M);
        if (solve(0, M)) printf("yes\n");
        else printf("no\n");
    }

    return 0;
}


Measured memory_bytes: 2612
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9
struct min_cost_flow
{
    struct edge{int to,cap,cost,rev;};
    int V;
    vector<vector<edge>> g;
public:
    min_cost_flow(int n)
    {
        V=n;
        g.resize(n,vector<edge>());
    }

    void add_edge(int from,int to,int cap ,int cost)
    {
	    g[from].push_back( (edge) { to,cap,cost,(int)g[to].size() } );
	    g[to].push_back( (edge){from,0, -cost,(int)g[from].size()-1});
    }
// s to t minmun flow 
// can't reach -1
    int run(int s,int t,int f)
    {
	    int res = 0;
	    int v = (int)g.size();
	    vector<int> prevv(v),preve(v);
	    while( f > 0 )
        {
		//bellmanford s-t周辺最短路を求める
		    vector<int> dist(v,INF);
		    dist[s] = 0;
		    bool update = true;
		    while(update)
            {
			    update = false;
			    for(int j= 0;j<v;j++)
                {
				    if(dist[j] == INF) continue;
				    for(int i= 0;i<g[j].size();i++)
                    {
					    edge &e = g[j][i];
					    if(e.cap > 0 && dist[e.to] > dist[j] + e.cost)
                        {
						    dist[e.to] = dist[j]  + e.cost;
						    prevv[e.to] = j;
						    preve[e.to] = i;
						    update = true;
					    }
				    }
			    }
		    }
		    if(dist[t] == INF ) return -1; //can't reach 
		    //s-t周辺に目いっぱい流す
		    int d = f;
		    for(int i = t; i!= s; i = prevv[i]) d = min(d,g[prevv[i]][preve[i]].cap);
		    f -= d;
		    res += d*dist[t];
		    for(int i = t; i!= s; i = prevv[i]){
		    	edge &e = g[prevv[i]][preve[i]];
		    	e.cap  -= d;
		    	g[i][e.rev].cap  += d;
		    }
	    }
	return res;
    }
};

int main()
{
	int v,e,f;
	cin>>v>>e>>f;
	min_cost_flow solve(v);
	for(int i=0;i<e;i++){
	int c,d,u,v;
	cin>>u>>v>>c>>d;
	solve.add_edge(u,v,c,d);
	}
	cout<<solve.run(0,v-1,f)<<endl;
	return 0;
}



Measured memory_bytes: 3224
N, K = map(int, input().split())
x = list(map(int, input().split()))

point= len(x) - 1
for i, v in enumerate(x):
    if v == 0:
        point = i
        break
    elif v > 0:
        point = i - 1
        break

start = max(0, point - K + 1)
end = start + K - 1

if x[point] != 0:
    point += 1
    
ans = float('inf')

while True:
    if x[start] >= 0:
        time = x[end]
    elif x[end] <= 0:
        time = abs(x[start])
    elif abs(x[start]) <= x[end]:
        time = abs(x[start] * 2) + x[end]
    else:
        time = abs(x[start]) + (x[end] * 2)
    ans = min(ans, time)
    
    start += 1
    end += 1

    if start > point or end == len(x):
        break
    
print(ans)

Measured memory_bytes: 14480
#include<bits/stdc++.h>
                using namespace std;
                typedef long long ll;
                #define MAX 55
                int arr[MAX];
                int n,x;
                ll dp[54][54][3005];
                ll recur(int idx , int taken , int sum)
                {
                    if(idx > n)
                    {
                        if(taken > 0 && sum == taken * x)return 1;
                        else return 0;
                    }
                    if(dp[idx][taken][sum] != -1)return dp[idx][taken][sum];
                    ll ans = 0;
                    ans += recur(idx+1,taken+1,sum + arr[idx]);
                    ans += recur(idx+1,taken,sum);
                    return dp[idx][taken][sum] = ans;
                }
                int main()
                {
                      scanf("%d%d",&n,&x);

                      for(int i = 1 ; i <= n ; i++)
                      {
                            scanf("%d",&arr[i]);
                      }
                      memset(dp,-1,sizeof(dp));
                      printf("%lld\n",recur(1,0,0));
                }


Measured memory_bytes: 68736
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  string S, T;
  cin >> N >> S >> T;
  long ans;
  for(int i = 0; i <= N; i++){
    if(S.substr(N - i,i) == T.substr(0, i)){
      ans =  2 * N - i;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <set>
#include <map>
#include <queue>
using namespace std;
using ll = long long;
const ll INF = 1<<30;
const ll MOD = (ll)1e9 + 7;
const ll MAX_N = (ll)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(ll i = 0; i < (ll) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

bool init_check(const string& s, const string& t)
{
    set<char> st;
    for(ll i = 0; i < s.size(); i++)
    {
        st.insert(s[i]);
    }
    for(ll i = 0; i < t.size(); i++)
    {
        if(st.count(t[i]) == 0) return true;
    }
    return false;
}

ll calc(const ll&pos, const vector<ll>& v)
{
    return *upper_bound(v.begin(), v.end(), pos);
}

void solve()
{
    string s, t; cin >> s >> t;
    if(init_check(s, t))
    {
        cout << -1 << endl;
        return;
    }

    map<char, vector<ll>> mp;
    ll n = (ll)s.size();
    s = s + s;
    for(ll i = 0; i < s.size(); i++)
    {
        mp[s[i]].push_back(i);
    }

    ll ans = 0;
    ll pre = -1;
    for(ll i = 0; i < t.size(); i++)
    {
        ll index = calc(pre, mp[t[i]]);
        if(index >= n)
        {
            index -= n;
            ans += n;
        }
        ans += index - pre;
        pre = index;
    }
    cout << ans << endl;
}

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

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

int k;
string s, t;
vector<string> a;
int main()
{
	int i, j;
	cin >> s >> k;
	for (i = 0; i < s.size(); i++) {
		t = "";
		for (j = i; j < min(i + k, (int)s.size()); j++) {
			t += s[j];
			a.push_back(t);
		}
	}
	sort(a.begin(), a.end());
	k--;
	for (i = 1; k && i < a.size(); i++) {
		if (a[i] != a[i - 1]) k--;
	}
    cout << a[i - 1] << endl;
    return 0;
}

Measured memory_bytes: 1660
#include<bits/stdc++.h>
const int MN=100000+5;
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
template<typename T>T&IN(T&in){
	in=0;char c=getchar();int f=1;
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c))in=in*10+c-'0',c=getchar();
	return in*=f;
}
int n,m;ll k;
int fr[MN],st[MN],vis[MN];
ll a[MN],ans[MN];
void input(){
	IN(n);
	for(int i=1;i<=n;++i)IN(a[i]),fr[i]=i;
	for(int i=n;i>=1;--i)a[i]-=a[i-1];
	IN(m),IN(k);
	for(int i=1,x;i<=m;++i)IN(x),swap(fr[x],fr[x+1]);
	for(int i=1;i<=n;++i)if(!vis[i]){
		st[0]=0;
		for(int j=i;!vis[j];j=fr[j])vis[j]=1,st[++st[0]]=j;
		for(int j=1;j<=st[0];++j)ans[st[j]]=a[st[(j+k-1)%st[0]+1]];
	}
	for(int i=1;i<=n;++i)ans[i]+=ans[i-1],printf("%lld.0\n",ans[i]);
}
int main(){
	input();
	return 0;
}

Measured memory_bytes: 4224
import math
INF = 10**18
n, x = [int(item) for item in input().split()]
blu = [[int(item) for item in input().split()] for _ in range(n)]

s_score_list = []
full_score_list = []
for i, (b, l, u) in enumerate(blu):
    s_score_list.append(b * l)
    full_score_list.append([(x-b) * u + b * l, i])
s_score = sum(s_score_list)
full_score_list.sort(reverse=True)

t_score = 0
full_score_set = set()
for i in range(n):
    full_score_set.add(full_score_list[i][1])
    t_score += full_score_list[i][0]
    if t_score >= s_score:
        last_index = full_score_list[i][1]
        surplus = t_score - s_score
        shortage = s_score - t_score + full_score_list[i][0]
        break

# Minimize time in full-score-set
max_reduction = 0
for i, (b, l, u) in enumerate(blu):
    if i in full_score_set:
        if (x-b) * u >= surplus:
            max_reduction = max(max_reduction, int(math.floor(surplus / u)))
        elif (x-b) * u + b * l >= surplus:
            max_reduction = max(max_reduction, (x-b) + int(math.floor((surplus - (x-b)*u) / l)))
ans = x * len(full_score_set) - max_reduction

# Take lest of score in not full_scores
full_score_set.remove(last_index)
min_promotion = INF
for i, (b, l, u) in enumerate(blu):
    if i in full_score_set:
        continue
    if b*l >= shortage:
        min_promotion = min(min_promotion, int(math.ceil(shortage / l)))
    elif b*l + (x-b)*u >= shortage:
        min_promotion = min(min_promotion, b + int(math.ceil((shortage - b*l) / u)))
ans = min(ans, min_promotion + x * len(full_score_set))
print(ans)

Measured memory_bytes: 51760
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

typedef long long ll;

int pos(int y, int x){
    return 1000 * y + x;
}

bool visited[1000000];

int main(){
    FOR(i,0,1000000) visited[i] = false;
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> vs;
    int S;
    FOR(i,0,H){
        string in;
        cin >> in;
        vs.push_back(in);
        FOR(j,0,in.length()){
            if(in[j]=='S'){
                S = pos(i, j);
            }
        }
    }
    int vx[4] = {0,1,0,-1};
    int vy[4] = {-1,0,1,0};
    queue<int> que;
    que.push(S);
    visited[S] = true;
    int MIN = min(min(S/1000, abs(H-1-S/1000)), min(S%1000, abs(W-1-S%1000)));
    queue<int> quek;
    quek.push(1);
    while(!que.empty()){
        int q = que.front();que.pop();
        int nowy = q / 1000;
        int nowx = q % 1000;
        int k = quek.front();quek.pop();
        if(k>K) continue;
        FOR(i,0,4){
            int nexty = nowy + vy[i];
            int nextx = nowx + vx[i];
            if(nexty >= H || nexty < 0 || nextx >= W || nextx < 0) continue;
            if(vs[nexty][nextx]=='#' || visited[pos(nexty, nextx)]) continue;
            que.push(pos(nexty, nextx));
            k++;
            quek.push(k);
            visited[pos(nexty, nextx)] = true;
            MIN = min(MIN, min(min(nexty, abs(H-1-nexty)),min(nextx, abs(W-1-nextx))));
        }
    }
    if(MIN==0) cout << 1 << endl;
    else cout << (MIN+K-1)/K + 1 << endl;
}


Measured memory_bytes: 2176
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def f(n):
        if n < 4:
            return [1,n]
        res = [1]
        i = 2
        while i*i <= n:
            if n%i == 0:
                res.append(i)
                m = n//i
                if m != i:
                    res.append(m)
            i += 1
        res.append(n)
        return res

    n = I()
    l = f(n)
    ans = float("inf")
    for x in l:
        m = x+n//x-2
        if m < ans:
            ans = m
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


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

int main() {
  int A, B, K, C;
  cin >> A >> B >> K;

  for (int i = A; i < A + K; i++) {
    if (i < B) {
      cout << i << endl;
      C = i;
    }
  }

  for (int i = B + 1 - K; i < B + 1; i++) {
    if (C < i && i <= B) {
      cout << i << endl;
    }
  }
}

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

int main()
{
    int N;
    cin >> N;
    if (N % 2 == 0)
    {
        cout << N / 2 << endl;
    }
    else
    {
        cout << N / 2 + 1 << endl;
    }
}


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

vector<pair<long long, long long> > prime_factors(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main(void){
    long long int N;
    cin >> N ;
    long long int count=0;
    auto pf = prime_factors(N);
    //map<long long int,long long int> res = prime_factors(N);
    for(auto p : pf) {
        int res1 = p.first;
        int res2 = p.second;
        //cout << res1 << " " << res2 << endl;
         
        long long int tmp = 0, cur = 1;
        while (res2 >= cur) res2 -= cur++, ++tmp;
        count += tmp;
        
    }
    cout << count << endl;

    return 0;
}

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

int main() {
  int x = 0;
  int N, t;
  cin >> N;
  t = N;
  while (t > 0) {
    x += t % 10;
    t /= 10;
  }
  if (N % x == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}
    

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

#define INF LLONG_MAX/3
#define inf INT_MAX/3
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> P;
typedef long long ll;

int gcd(int a, int b) {
	if (b == 0)return a;
	return gcd(b, a%b);
}
int lcm(int a, int b) {
	return a / gcd(a, b)*b;
}
int modpow(int a, int b) {
	if (b == 0)return 1;
	if (b == 1)return a % MOD;
	if (b % 2)return modpow(a, b - 1)*a%MOD;
	else return modpow(a, b / 2)*modpow(a, b / 2) % MOD;
}
int comb(int a, int b) {
	if (b == 0 || a == b)return 1;
	if (b == 1)return a % MOD;
	return (comb(a - 1, b - 1) + comb(a - 1, b)) % MOD;
}

int n,a;
queue<int>q;

int main() {
	cin>>n;
	rep(i,(1<<n)){
		cin>>a;
		q.push(a);
	}
	while(q.size()!=1){
		int x=q.front();
		q.pop();
		int y=q.front();
		q.pop();
		if(x==y)q.push(x);
		else q.push(abs(x-y));
	}
	cout<<q.front()<<endl;
	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

const int MAX_N = 110;
int dp[110];
bool used[110];
map<string, int> mp;
vector<string> s;

int dfs(int cur) {
	// cout << "in : " << cur << endl;
	if(used[cur]) return dp[cur];
	if(cur == s.size()) return 0;
	used[cur] = true;
	dp[cur] = 1e9;
	int& ret = dp[cur];
	if(s[cur].back() == ':') {
		chmin(ret, dfs(cur+1));
	}
	else {
		int nxt = mp[s[cur].substr(5)];
		chmin(ret, dfs(nxt));
		chmin(ret, dfs(cur+1)+1);
	}
	// cout << "out: " << cur << ", value: " << ret << endl;   
	return ret;
}

int main(){
	int n;
	cin >> n;
	cin.ignore();
	s.resize(n);
	rep(i, n) getline(cin, s[i]);
	rep(i, n) {
		if(s[i].back() == ':') {
			string tmp = s[i].substr(0, s[i].size()-1);
			tmp += ';';
			mp[tmp] = i;
		}
	}

	cout << dfs(0) << endl;
	return 0;
}

Measured memory_bytes: 3244
import java.util.Scanner;

public class Main {
    static Long N;
    static int count;

    private static void init() {
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextLong();
        scanner.close();
    }


    private static void dfs(long i, boolean is3, boolean is5, boolean is7) {
        if(N < i) return;

        if(is3 && is5 && is7) count++;

        dfs(i * 10 + 3, true, is5, is7);
        dfs(i * 10 + 5, is3, true, is7);
        dfs(i * 10 + 7, is3, is5, true);

    }

    public static void main(String[] args) {
        init();
        dfs(0, false, false, false);
        System.out.println(count);
    }
}

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

#define ll long long int
#define mp make_pair
#define pb push_back
using namespace std;

int main() {
    int n,m;
    cin>>n>>m;
    string s[n+2];
    for (int i = 0; i < n; ++i) {
        cin>>s[i];
    }
    vector<ll> rows,col;
    for (int i = 0; i < n; ++i) {
        int c =0 ;
        for (int j = 0; j < m; ++j) {
            if(s[i][j] == '.'){
                c++;
            }
        }
        if(c == m){
            rows.push_back(i);
        }
    }
    sort(rows.begin(), rows.end());
    for (int i = 0; i < m; ++i) {
        int c =0 ;
        for (int j = 0; j < n; ++j) {
            if(s[j][i] == '.'){
                c++;
            }
        }
        if(c == n){
            col.push_back(i);
        }
    }
    string s1[n];
    int j = 0;
    for (int i = 0; i < n; ++i) {
        if(!binary_search(rows.begin(), rows.end() , i)){
            s1[j] = s[i];
            j++;
        }
    }
    sort(col.begin(), col.end());
    for (int i = 0; i < j; ++i) {
        for (int k = 0; k < m; ++k) {
            if(!binary_search(col.begin(), col.end() , k)){
                cout << s1[i][k];
            }
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }

unordered_map<ll, int> dec(ll n) {
    ll a = 2;
    unordered_map<ll, int> res;
    while (n >= a * a) {

        if (n % a == 0) {
            res[a]++;
            n /= a;
        }
        else {
            a++;
        }
    }

    res[n]++;
    return  res;
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll N;
    cin >> N;
    if (N == 1) {
        cout << 0 << endl;
        return 0;
    }
    auto pmap = dec(N);
    ll ans = 0;
    for (auto& p : pmap) {
        int num = p.second;
        int x = 1;
        while(1) {
            if (num < x) {
                break;
            }
            ans++;
            num -= x;
            x++;
           
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3656
/*
  
                                _oo0oo_
                               088888880
                               88" . "88
                               (| -_- |)
                                0\ = /0
                             ___/'---'\___
                           .' \\\\|     |// '.
                          / \\\\|||  :  |||// \\
                         /_ ||||| -:- |||||- \\
                        |   | \\\\\\  -  /// |   |
                        | \_|  ''\---/''  |_/ |
                        \  .-\__  '-'  __/-.  /
                      ___'. .'  /--.--\  '. .'___
                   ."" '<  '.___\_<|>_/___.' >'  "".
                  | | : '-  \'.;'\ _ /';.'/ - ' : | |
                  \  \ '_.   \_ __\ /__ _/   .-' /  /
              ====='-.____'.___ \_____/___.-'____.-'=====
                                '=---='

            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
             AC  AC  AC  AC  AC  AC  AC  AC  AC  AC  AC  AC
     
*/
#define OJ
#include <bits/stdc++.h>
#define pb push_back
#define _1 first
#define _2 second
#define FOR(i,a,b) for(int i=a;i<(b);i++)
#define FORN(i,b) for(int i=0;i<(b);i++)
#define reset(a,b) memset(a,b,sizeof(a))
#define MAX(a,b)  a>b?a:b
#define MIN(a,b)  a>b?b:a
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int> > vii;

struct cmp
{
  bool operator()(const long int &a,const long int &b)
  {
    return a>b;
  }
};
int main()
{
	#ifndef OJ
	freopen("abc.in","r",stdin);
	freopen("abc.out","w",stdout);
	#endif
  long int n,ans=0;
  long int i,j,k,l;
  priority_queue <long int,vector <long int>,cmp>q;
  scanf("%ld",&n);
  for(i=1;i<=n;i++)
   {
    scanf("%ld",&j);
    ans+=j;
    q.push(j);
   }
   while(ans%10==0)
   {
    if(q.empty()) break;
    i=q.top();
    q.pop();
    if((ans-i)%10==0) continue;
    ans-=i;
   }
  if(ans%10==0) printf("0");
  else printf("%ld",ans);
	#ifndef OJ
	fclose(stdin);
	fclose(stdout);
	#endif
}

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

using namespace std;

#define int long long
#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define cint int t;cin>>t;while(t--)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define vint vector<int>
#define all(v) (v).begin(), (v).end()
#define pii pair<int,int>

int32_t main(){
    int n;
    cin>>n;

    map<string,int> mp;
    int ma=0;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        mp[s]++;
        ma=max(ma,mp[s]);
    }

    set<string> s;
    for(auto k:mp){
        if(k.second==ma){
            s.insert(k.first);
        }
    }

    for(auto j:s){
        cout<<j<<endl;
    }
}

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

int main() {
  int N, M;
  scanf("%d%d", &N, &M);

  priority_queue<int> que;
  for (int i = 0; i < N; i++) {
    int A = 0;
    scanf("%d", &A);
    que.push(A);
  }

  for (int i = 0; i < M; i++) {
    int discount_A = que.top() / 2;
    que.pop();
    que.push(discount_A);
  }

  long long ans = 0;
  for (int i = 0; i < N; i++) {
    ans += (long long)que.top();
    que.pop();
  }
  printf("%lld", ans);
  return 0;
}


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

int N;

long long prime[1050],pri[7920];
int tot;
void sieve(){
	for (int i=2;i<=7919;i++){
		if (!pri[i]){
			prime[++tot]=i;
			if (tot==1000) return;
		}
		for (int j=1;i*prime[j]<=7919;j++){
			pri[i*prime[j]]=prime[j];
			if (!(i%prime[j])) break;
		}
	}
}

long long ans[505][505];

int main(){
	sieve();
	scanf("%d",&N);
	for (int i=1;i<=N;i++)
		for (int j=1;j<=N;j++){
			if ((i^j)&1) ans[i][j]=prime[(i+j-1)>>1]*prime[(i+j+1)>>1]*prime[((i-j+N)>>1)+500]*prime[((i-j+N+2)>>1)+500]+1;
			else ans[i][j]=prime[(i+j)>>1]*prime[((i-j+N+1)>>1)+500];
		}
	for (int i=1;i<=N;i++){
		for (int j=1;j<=N;j++)
			printf("%lld ",ans[i][j]);
		putchar(10);
	}
}


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

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);++i)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);--i)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld=long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve(){
    ll x,y,z;
    cin>>x>>y>>z;
    ll n=x+y+z;
    Array a(n),b(n),c(n);
    REP(i,n) cin>>a[i]>>b[i]>>c[i];
    vec<P> ab(n);
    REP(i,n) ab[i]={a[i]-b[i],i};
    sort(all(ab),greater<P>());

    
    Array sum(n,0);
    {
        priority_queue<P> que;
        REP(i,x){
            int j=ab[i].second;
            que.push({c[j]-a[j],j});
            sum[i]+=a[j];
            if(i>0) sum[i]+=sum[i-1];
        }
        rep(i,x,x+z){
            int j=ab[i].second;
            que.push({c[j]-a[j],j});
            sum[i]+=a[j];
            if(i>0) sum[i]+=sum[i-1];
            int k=que.top().second;
            que.pop();
            sum[i]+=c[k]-a[k];
        }
    }

    
    Array sumb(n,0);
    {
        priority_queue<P> que2;
        rep2(i,x+z,n){
            int j=ab[i].second;
            que2.push({c[j]-b[j],j});
            sumb[i]+=b[j];
            if(i+1<n) sumb[i]+=sumb[i+1];
        }
        rep2(i,x,x+z){
            int j=ab[i].second;
            que2.push({c[j]-b[j],j});
            sumb[i]+=b[j];
            if(i<n) sumb[i]+=sumb[i+1];
            int k=que2.top().second;
            que2.pop();
            sumb[i]+=c[k]-b[k];
        }
    }

    ll ans=0;
    rep(i,x,x+z+1){
        chmax(ans, sum[i-1]+sumb[i]);
    }
    cout<<ans<<en;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	
	solve();
	//ll t;cin>>t;REP(i,t) solve();

    return 0;
}

Measured memory_bytes: 7924
import numpy as np

n = input()
n= int(n)
ta = input()
t,a = ta.split()
t = int(t)
a = int(a)
H = input()
H = H.split()
dif = [i for i in range(n)]
for i in range(len(H)):
    dif[i] = int(H[i])
    dif[i] = abs(t-dif[i]*0.006-a)

d = np.array(dif)
print(np.argmin(d)+1)


Measured memory_bytes: 21648
package main
import "fmt"


func gcd(a, b int) int {
	for b != 0 {
		return gcd(b, a%b)
	}
	return a
}

func main() {
	var n int
	fmt.Scan(&n)
	var a []int
	var ans int64 = 0
	for i := 0; i < n; i++ {
		var v int
		fmt.Scan(&v)
		a = append(a, v)
	}

	var g int = 1
	for _, v := range a{
		g = gcd(g, v)
	}

	for _, v := range a{
		ans += int64(v / g -1)
	}

	fmt.Println(ans)
}

Measured memory_bytes: 768
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}



int main(){
    string s;cin>>s;
    sort(ALL(s));
    cout<<(s=="abc"?"Yes":"No");
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
#include<bits/stdc++.h>
 
int main(){
  int x,n,t;
  cin>>n>>x>>t;
  if(n%x!=0){
    cout<<((n/x)+1)*t<<endl;
  }
  else{
    cout<<(n/x)*t<<endl;
  }
}


Measured memory_bytes: 3632
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
		int n;
		n = sc.nextInt();
		if(n==0) {
			break;
		}
		double[] num;
		double sum = 0;
		num = new double[n];
		for(int i = 0;i<n;i++) {
			num[i] = sc.nextInt();
			sum += num[i];
		}

		double ave = sum/n;
		double sum_2 = 0;
		for(int i = 0;i<n;i++) {
			sum_2 += (num[i]-ave)*(num[i]-ave);
		}
		double bunsan = sum_2/n;
		double ans = Math.sqrt(bunsan);
		System.out.printf("%f\n",ans);
	}
		sc.close();
	}
}


Measured memory_bytes: 31996
#include <iostream>
#include <string>
#include <cstdio>

using namespace std;

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

	double yen = 0;

	for (int i = 0; i < N; ++i) {
		double x;
		string u;
		cin >> x >> u;
		if (u == "JPY") {
			yen += x;
		}
		else if (u == "BTC") {
			yen += x * 380000.0;
		}
	}
	printf("%.8f\n", yen);
}


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

using namespace std;

const int mxk = 1e6 + 7;

struct node {
	int nxt, to;
}edge[mxk << 1];

int tot = 0, head[mxk], k;

void addedge(int u, int v) { edge[++tot].to = v; edge[tot].nxt = head[u]; head[u] = tot; }

int n, fa[mxk], ans = 0;

int dfs(int u, int depth) {
	int ret = depth; 
	for(int i = head[u]; i; i = edge[i].nxt) 
		ret = max(ret, dfs(edge[i].to, depth + 1));
	if(fa[u] != 1 && u != 1 && ret - depth == k - 1) {++ans; return 0;}
	else return ret;
}

int main() {
	ios :: sync_with_stdio(false); 
	cin >> n >> k >> fa[1]; ans += (fa[1] != 1);
	for(int i = 2; i <= n; ++i) cin >> fa[i], addedge(fa[i], i);
	dfs(1, 0); cout << ans << endl;
}
/*
Vocabulary Collections : 
facility
*/

Measured memory_bytes: 13024
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Scanner;

public class Main {
	static Scanner sc;

	public static void main(String[] args) throws Exception {
		//InputStream in = new FileInputStream("src/input.txt");
		InputStream in = System.in;

		sc = new Scanner(in);

		String a = sc.next();
		String b = sc.next();
		String answer = "YES";

		for(int i = 0; i < 3; i++){
			if(a.charAt(i) != b.charAt(2-i)){
				answer = "NO";
				break;
			}
		}
		System.out.println(answer);
	}
}

Measured memory_bytes: 22100
#include <iostream>
#include <climits>
#include<vector>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include<cmath>
#include <limits>
using namespace std;
typedef long long ll;

typedef pair<ll, ll> P;
const int INF = 100000000;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

#define REP(i, a,b) for(i=a;i<b;i++) 
#define REP1(i,b,a) for(i=b-1;i>=a;i--)
#define output(x) cout<<x<<endl;
#define pb(x) push_back(x);
const int MOD = 1000000007;


int main() {
	int N,i,j,K,ans;
	char S[100001];
	cin >> N >> K;
	vector<ll>H(N);
	ll sum = 0;
	REP(i, 0, N){
		cin >> H[i];
	}
	sort(H.begin(), H.end());
	REP(i, 0, N - K) {
		sum += H[i];
	}
	cout << sum << endl;
	return 0;
}



Measured memory_bytes: 1792
import sys,os,re
from collections import Counter,deque
from operator import itemgetter
from itertools import accumulate
sys.setrecursionlimit(10**6)

while True:
    m,f,r=map(int,input().split())
    if (m,f,r)==(-1,-1,-1):
        break
    if m==-1 or f==-1 or m+f<30:
        print("F")
    elif m+f>=80:
        print("A")
    elif m+f>=65:
        print("B")
    elif m+f>=50:
        print("C")
    elif m+f>=30:
        print("C" if r>=50 else "D")
    


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

int main() 
{
    long long ddd = 1e18;
    int N;
    cin >> N;
    
    long long ans = 1;
    bool flag = false;
    for (int i = 0; i < N; i++) {
        long long A;
        cin >> A;
        if (A == 0) {
            cout << 0 << endl;
            return 0;
        }
        if (flag || ddd/ans < A) {
            flag = true;
        }
        ans *= A;
    }
    
    if (flag) {
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
}

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

using namespace std;

int main()
{
    string s[100];
    int H, W;
    cin >> H >> W;
    for (int i = 0; i < H; i++)
    {
        cin >> s[i];
    }
    for (int i = 0; i < H; i++)
    {
        cout << s[i] << endl << s[i] << endl;
    }
    return (0);
}

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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x)  cerr << #x << " = " << x << endl
using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ld PI = 3.14159265359;

const ll MOD = (ll) 998244353ll;
const ll MAXN = (ll) 2e6 + 10;
const ll INF = (ll) 10000000000ll;
const ld EPS = (ld) 1e-8;

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	str s;
	cin >> s;
	ll n = s.size();
	str s1 = "keyence", s2 = "ecneyek";
	ll p1 = 0;
	ll p2 = 0;
	for(int i = 0; i < n;i++){
		if(s[i] == s1[p1]) p1++;
		else break;
		if(p1 == 7) break;
	}
	for(int i = n - 1; i >= 0; i--){
		if(s[i] == s2[p2]) p2++;
		else break;
		if(p2 == 7) break;
	}
	cout << (p1 + p2 >= 7 ? "YES" : "NO");
	return 0;
}


/*
6
7 3 4 2 3 1
                                 ____              ,----..               ,----..
   ,---,                       ,'  , `.           /   /   \             /   /   \
  '  .' \                   ,-+-,.' _ |          /   .     :           /   .     :
 /  ;    '.              ,-+-. ;   , ||         .   /   ;.  \         .   /   ;.  \
:  :       \            ,--.'|'   |  ;|        .   ;   /  ` ;        .   ;   /  ` ;
:  |   /\   \          |   |  ,', |  ':        ;   |  ; \ ; |        ;   |  ; \ ; |
|  :  ' ;.   :         |   | /  | |  ||        |   :  | ; | '        |   :  | ; | '
|  |  ;/  \   \        '   | :  | :  |,        .   |  ' ' ' :        .   |  ' ' ' :
'  :  | \  \ ,'        ;   . |  ; |--'         '   ;  \; /  |        '   ;  \; /  |
|  |  '  '--'          |   : |  | ,             \   \  ',  /          \   \  ',  /
|  :  :                |   : '  |/               ;   :    /            ;   :    /
|  | ,'                ;   | |`-'                 \   \ .'              \   \ .'
`--''                  |   ;/                      `---`                 `---`
                       '---'

*/


Measured memory_bytes: 256