akhauriyash/Code-Regression huggingface dataset:
#! /usr/bin/python
# -*- coding: utf-8 -*-

def plen(prime, val, pos, left, right):
    if pos == len(prime)-1:
        if val == Max:
            return 0
        else:
            return prime[len(prime)-1]-prime[len(prime)-2]
    if prime[pos] == val:
        return 0
    elif prime[pos] < val < prime[pos+1]:
        return prime[pos+1]-prime[pos]
    else:
        if val < prime[pos]:
            return plen(prime, val, (pos+left)/2, left, pos)
        else:
            return plen(prime, val, (pos+right+1)/2, pos, right)

Max = 1299709
used = [True]*(Max+1)
used[0] = False
used[1] = False
for i in range(2, Max+1):
    if used[i] == True:
        for j in range(i+i, Max+1, i):
            used[j] = False

prime = []
for i in range(2, Max+1):
    if used[i] == True:
        prime.append(i)

#print prime
n = int(raw_input())
while n!=0:
    print plen(prime, n, len(prime)/2, 0, len(prime)-1)
    n = int(raw_input())

Measured memory_bytes: 76236
#include <stdio.h>
int main(void){
  int N, x = 0, y = 0;

  scanf("%d", &N);

  x = N*800;

  while(1){
    if(N - 15 >= 0){
      N -= 15;
      y += 200;
    } else break;
  }

  printf("%d\n", x-y);

  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
const int yuzu=2e5,mod=1e9+7;
typedef ll fuko[yuzu|10];
int n=read(),m=read();
fuko a,b;
ll ans1,ans2;
int main(){
int i,j;
for (i=1;i<=n;++i){
  ll x=read();
  ans1=(ans1+(i-1)*x-(n-i)*x+mod)%mod;
  }
for (i=1;i<=m;++i){
  ll x=read();
  ans2=(ans2+(i-1)*x-(m-i)*x+mod)%mod;
  }write(ans1*ans2%mod);
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <tuple>
#include <string.h>


using namespace std;

int A[402][402];
int dx[] = {1, -1, 0 ,0};
int dy[] = {0 ,0, 1, -1};
long d,p;

void dfs (int x, int y, int c){
	if(c == 1){
		d++;
	} else {
		p++;
	}
	A[x][y] = 0;
	for(int i = 0;i < 4; i++){
		int nx = x + dx[i];
		int ny = y + dy[i];
		if(A[nx][ny] == -c) dfs(nx, ny, -c);
	}
}

int main(){

	int H, W;
	cin >> H >>  W;

	int x=0, y=0;

	for(int i = 0; i < 402; i++)
		for(int j = 0; j < 402; j++)
			A[i][j]=0;

	for(int i = 1; i<=H; i++){
		string S;
		cin >> S;
		for(int j = 1;j<=W;j++){
			if(S[j-1] == '#'){
				A[i][j] = 1;
				x++;
			} else {
				A[i][j] = -1;
				y++;
			}
		}
	}

	long long sum = 0;
	for(int i = 1; i<=H; i++){
		for(int j = 1;j <=W;j++){
			if(A[i][j] != 1) continue;
			d=0; p=0;
			dfs(i, j, 1);
			sum += d * p;
		}
	}
	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 8320
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
1 1 1 2
)");
#define cin input
#endif

ll inv_mod( ll a, ll m )
{
  ll b, x, u, q, abs_m, tmp; 

  abs_m = ( m < 0 ) ? -m : m;
  b = m; x = 1; u = 0; 
  while ( b > 0 ) {
    q = a / b; 
    tmp = u; u = x - q * u; x = tmp;
    tmp = b; b = a - q * b; a = tmp;
  }

  return ( x < 0 ) ? abs_m + x : x;
}

int main()
{
	const ll mod = 998244353;
	ll n, a, b, k;
	cin >> n >> a >> b >> k;

    vector<ll> frac(n + 1);
    frac[0] = 1;
    REP(i, n)
        frac[i + 1] = frac[i] * (i + 1) % mod;

    vector<ll> fraci(n + 1);
    fraci[n] = inv_mod(frac[n], mod);
    for (int i = n; i > 0; --i)
        fraci[i - 1] = fraci[i] * i % mod;

	ll ans = 0;
	REP (i, n + 1)
	{
		if ((k - a * i) % b != 0)
			continue;
		auto j = (k - a * i) / b;
		if (j < 0 || j > n)
			continue;
		ans += frac[n] * fraci[n - i] % mod * fraci[i] % mod * frac[n] % mod * fraci[n - j] % mod * fraci[j] % mod;
		ans %= mod;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4992
let () =
  Scanf.scanf "%d" @@ fun n ->
  Array.init n (fun _ -> Scanf.scanf " %d" ((+) 0))
  |> Array.fold_left (fun (z, p) x -> if p <= x then (z+1, x) else (z, p)) (0, 0)
  |> fst |> Printf.printf "%d\n"


Measured memory_bytes: 384
#include <stdio.h>
#define N 500000



typedef struct{
  int key, lk, rk, pk;
}Node;

void Insert(int);
void MaxHeapify(int);
void buildMaxHeap();

Node node[N];
int n, size;
	    
int main () {
  int i, m = 0;


  scanf("%d",&n);

  for(i = 1 ; i <= n ; i++) {
    scanf("%d",&m);
    Insert(m);
  }


  buildMaxHeap();

  for(i = 1 ; i <= n ; i++) {
    printf(" %d",node[i].key);
  }

  printf("\n");


  return 0;
}


void Insert(int x) {
  int i;

  size++;

  node[size].key = x;
  node[size].lk = size * 2;
  node[size].rk = size * 2 + 1;
  node[size].pk = size / 2;
}


void MaxHeapify(int x) {
  int left = 2 * x, right = 2 * x + 1, large = 0, tmp = 0;


  if(left <= n && node[left].key > node[x].key) large = left;
  
  else large = x;
  
  if(right <= n && node[right].key > node[large].key) large = right;

  if(large != x) {
    tmp = node[x].key;
    node[x].key = node[large].key;
    node[large].key = tmp;
    MaxHeapify(large);
  }
 
}


void buildMaxHeap() {
  int i;
  
  for(i = n/2 ; i >= 1 ; i--) MaxHeapify(i);
}



Measured memory_bytes: 9612
#[allow(unused_imports)]
use itertools::Itertools;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
    input! {
        x: i64,
    }
    let y = num::integer::lcm(x, 360);
    println!("{}", y / x);
}


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

yen = 1000
stocks = 0

for i in range(N):
  if i == N-1:
    yen += stocks * A[i]
    stocks = 0
    break
  
  if A[i] > A[i+1]:
    # sell everything
    yen += stocks * A[i]
    stocks = 0
  else:
    # buy everything
    num = yen // A[i]
    stocks += num
    yen -= A[i] * num

print(yen)


Measured memory_bytes: 9188
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  queue<char>x,y,z;
  rep(i,3){
    string s;
    cin >> s;
    int n = s.size();
    if(i==0)rep(j,n)x.push(s[j]);
    if(i==1)rep(j,n)y.push(s[j]);
    if(i==2)rep(j,n)z.push(s[j]);
  }
  
  int now=0;
  while(true){
    if(now==0){
      if(x.empty()){
        cout << 'A' << endl;
        return 0;
      }
      char c=x.front();
      x.pop();
      if(c=='a')now=0;
      if(c=='b')now=1;
      if(c=='c')now=2;

      continue;
    }
    else if(now==1){
      if(y.empty()){
        cout << 'B' << endl;
        return 0;
      }
      char c=y.front();
      y.pop();
      if(c=='a')now=0;
      if(c=='b')now=1;
      if(c=='c')now=2;
  
      continue;
    }
    else{
      if(z.empty()){
        cout << 'C' << endl;
        return 0;
      }
      char c=z.front();
      z.pop();
      if(c=='a')now=0;
      if(c=='b')now=1;
      if(c=='c')now=2;
      continue;
    }
  }
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        new Program().Calc();
    }

    Scanner cin;

    public Program() { }

    bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; }

    void Calc()
    {
        cin = new Scanner();

        int h = cin.nextInt();
        int a = cin.nextInt();

        int ans = (int)Math.Ceiling(h / (float)a);

        WriteLine(ans);
    }
}

public static class StringExtension
{
    public static char GetChar1(this string str, int indexOneBase)
    {
        return str[indexOneBase - 1];
    }
}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 13140
W = str(input()).lower() 

table = []
count = 0

while True:
    
    T = str(input())
    if T == "END_OF_TEXT":
        break
    else:
        T = T.lower().split()
    
    for j in range(len(T)):
        table.append(T[j])
    
    
for i in table:
    if i == W:
        count += 1
    
print(count)


Measured memory_bytes: 5560
#include <bits/stdc++.h>
using namespace std;
#define input istream_iterator<ll>(cin)
using ll = long long;

const ll N = 1e5;

ll h[N];
ll n;
// min cost to stone i
ll dp[N];

static inline
ll cost(ll a, ll b) {
    return abs(h[a] - h[b]);
}

int main() {
    cin >> n;
    copy_n(input, n, h);
    dp[0] = 0;
    dp[1] = cost(0, 1);
    for (ll i = 2; i < n; i++) {
        dp[i] = min(dp[i - 1] + cost(i, i - 1), dp[i - 2] + cost(i, i - 2));
    }
    cout << dp[n - 1] << endl;
    return 0;
}


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

int main() {
	int A, B, C, X, Y;
	long long ans, tmp;
	cin >> A >> B >> C >> X >> Y;
	int n;
	if (X >= Y)n = X;
	else n = Y;
	int i;
	tmp = 0;
	ans = 2 * C * n;
	for (i = n - 1;i >= 0;i--) { //cを2i枚
		tmp += 2 * i * C;
		if (X - i > 0)tmp += A * (X - i);
		if (Y - i > 0)tmp += B * (Y - i);
		if (tmp < ans) ans = tmp;
		tmp = 0;
	}
	cout << ans << endl;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	string s;
	string t;
	cin >> s >> t;

	int n = s.size();

	rep(i, n){
		bool ok = true;
		rep(j, n){
			if(s[(i+j)%n] != t[j]) {
				// cout << i << "," << j << "," << s[(i+j)%n] << "," << t[i] << endl;
				ok = false;
				break;
			}
		}
		if(ok){
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){

  int sum, in, i;


  while(1){
    scanf("%d",&sum);

    if(sum == 0){
      return 0;
    }
    for(i = 0; i < 9; i++){
      scanf("%d",&in);
      sum -= in;
    }
    
    printf("%d\n",sum);
  }
    
}

Measured memory_bytes: 0
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>

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

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

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

  int A[2][101];
  REP(i, 2) {
    REP(j, N) {
      cin >> A[i][j];
    }
    A[i][N] = 0;
  }

  // 累積和を取る
  for (int i = 1; i < N; i++) {
    A[0][i] += A[0][i - 1];
  }

  for (int i = N - 2; i >= 0; i--) {
    A[1][i] += A[1][i + 1];
  }

  int max = 0;

  REP(i, N) {
    if (max < A[0][i] + A[1][i]) {
      max = A[0][i] + A[1][i];
    }
  }

  cout << max << endl;
  return 0;
}

Measured memory_bytes: 256
/*input
15
*/
#include <bits/stdc++.h>
using namespace std;
const long long md=1e9+7;
long long a[1000005],n;
int get(int x){
	int ret = 0;
	while(x){
		ret += x%10;
		x/=10;
	}
	return ret;
}
int main(){
	#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	#endif
	int q,m,k,h,ans=1e8,sum=0,p,x,y;
	cin>>n;
	for(int a=1;a<n;++a){
		ans = min(ans,get(a)+get(n-a));
	}
	cout<<ans;
}

Measured memory_bytes: 764
#include<stdio.h>

#define N 100000
#define NIL -1

struct Node{
  int parent;
  int right;
  int left;
};

void preorder (int);

void inorder (int);

void postorder(int);


struct Node T[N];

int main(){
  int v,l,r;
  int num,i,j;
  int root;
  

  
  scanf("%d",&num);

  for(i=0;i<num;i++) T[i].parent = NIL;

  for(i=0;i<num;i++){
    scanf("%d%d%d",&v,&l,&r);
    T[v].left = l;
    T[v].right = r;
    if(l != NIL) T[l].parent = v;
    if(r != NIL) T[r].parent = v;
  }

  for(i=0;i<num;i++) if(T[i].parent == NIL) root = i;

  printf("Preorder\n");
  preorder(root);
  printf("\n");
  printf("Inorder\n");
  
  inorder(root);
  printf("\n");
  printf("Postorder\n");
  postorder(root);
  printf("\n");
  
  return 0;
}

void preorder(int n){


  
  if (n == NIL) return;

  printf(" %d",n);

  preorder(T[n].left);

  preorder(T[n].right);
  
}

void inorder(int n){


  if(n == NIL) return;



  inorder(T[n].left);
  printf(" %d",n);
  inorder(T[n].right);
  
}

void postorder(int n){
  if(n == NIL) return;

  postorder(T[n].left);
  postorder(T[n].right);
  printf(" %d",n);

}




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

int main(){
	string S;
	cin >> S;
	for (int i = 0; i < S.size(); i++) {
		for (int j = i+1; j < S.size(); j++) {
			if (S[i] == S[j]) {
				cout << "no" << endl;
				return 0;
			}
		}
	}
	cout << "yes" << endl;

	return 0;
}


Measured memory_bytes: 3600
//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <stack>
#include <deque>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <time.h>
#include <cassert>
#include <fstream>
#include <stdio.h>
#include<unordered_map>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

template<typename T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }
template<typename T>
void vdeb(std::vector<T> &da) {
	for (int i = 0;i < da.size();i++) {
		if (i == da.size() - 1) std::cout << da[i];
		else std::cout << da[i] << ' ';
	}
	std::cout << std::endl;
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
	for (int i = 0;i < da.size();i++) vdeb(da[i]);
	std::cout << std::endl;
}

using namespace std;

int main(){
	int x,y,a,b,c;
	cin >> x >> y >> a >> b >> c;
	vector<ll> p(a),q(b),r(c);
	rip(i,a,0) cin >> p[i];
	rip(i,b,0) cin >> q[i];
	rip(i,c,0) cin >> r[i];
	sort(all(q));reverse(all(q));
	sort(all(p));reverse(all(p));
	sort(all(r));reverse(all(r));
	ll ans = 0;
	MinHeap<ll> pq;
	rip(i,x,0){
		pq.push(p[i]);
		ans += p[i];
	}
	rip(i,y,0){
		pq.push(q[i]);
		ans += q[i];
	}
	ll kk = ans;
	rip(i,min(x+y, c),0){
		ll now = pq.top();
		pq.pop();
		kk -= now;
		kk += r[i];
		chmax(ans, kk);
	}
	cout << ans << endl;
}

Measured memory_bytes: 4724
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <algorithm>

int main()
{
	int64_t A, B, N;
	std::cin >> A >> B >> N;
	if (N < B) {
		std::cout << A * N / B << std::endl;
	}
	else{
		int64_t x = B-1;
		std::cout << (A * x) / B - A * (x / B) << std::endl;
	}
	return 0;
}

Measured memory_bytes: 3500
#include <iostream>
#include<algorithm>
#include<string.h>
#include<stdlib.h>

using namespace std;

int compare_char(const void* left, const void* right)
{
	char *left_char = (char *)left;
	char *right_char = (char *)right;

	return strcmp(left_char,right_char);
}

int main()
{	
	char str[100][110];
	int n, l, i;

	cin >> n >> l;

	for (i = 0; i < n; i++) 
		cin >> str[i];
	
	qsort(str, n, sizeof(str[0]), compare_char);
	
	for (i = 0; i < n; i++)
		cout << str[i];
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 256
import collections
N = int(input())
a = list(map(int, input().split()))

i_a = list(map(lambda x: x+1, a))
d_a = list(map(lambda x: x-1, a))

new_a = a + i_a + d_a
c = collections.Counter(new_a)

sorted_c = sorted(c.values())
print(sorted_c[-1])



Measured memory_bytes: 30024
import io.StdIn._

object Main extends App {
  readInt
  val a = readLine.split(" ").map(_.toLong).toList
  val b = readLine.split(" ").map(_.toLong).toList

  def solve(a: List[Long], b: List[Long], res: Long): Long = b match {
    case Nil => res
    case x :: xs if x < a.head => solve(a.tail, xs, res + x)
    case x :: xs => {
      val rest = math.max(0, a.tail.head - (x - a.head))
      val m = math.min(x, a.head + a.tail.head)
      solve(rest :: a.tail.tail, xs, res + m)
    }
  }
  println(solve(a,b,0))
}


Measured memory_bytes: 76856
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
using namespace std;

using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define N  100005

typedef complex < double > base ;
#define PI 3.141592653589793l
void fft(vector<base> &a,bool invert){
    int i,j,n=sz(a);
    for(i=1,j=0;i<n;++i){
        int bit=n>>1;
        for(;j>=bit;bit>>=1){
            j-=bit;
        }
        j+=bit;
        if(i<j){
            swap(a[i],a[j]);
        }
    }
    for(int len=2;len<=n;len<<= 1){
        double ang=2*PI/len*(invert?-1:1);
        base wlen(cos(ang),sin(ang));
        for(i=0;i<n;i+=len){
            base w(1);
            for(j=0;j<len/2;++j){
                base u=a[i+j],v=a[i+j+len/2]*w;
                a[i+j]=u+v;
                a[i+j+len/2]=u-v;
                w*=wlen;
            }
        }
    }
    if(invert){
        for(i=0;i<n;++i){
            a[i]/=n;
        }
    }
}
void multiply(const vector<ll> &a,const vector<ll> &b,vector <ll> &res){
    vector<base> fa(a.begin(),a.end()),fb(b.begin(),b.end());
    size_t n=1;
    while(n<max(a.size(),b.size())) n<<=1;
    n<<= 1;
    fa.resize(n),fb.resize(n);
    fft(fa,false),fft(fb,false);
    for(size_t i=0;i<n;++i){
        fa[i]*=fb[i];
    }
    fft(fa,true);
    res.resize(n);
    for(size_t i=0;i<n;++i){
        res[i]=(ll)(fa[i].real()+0.5);
    }
}
void solve()
{
    vi v1(N,0),v2(N,0),res;
    ll n,m,x;
    cin>>n>>m;
    rep(i,0,n)
    {
        cin>>x;
        v1[x]++;
        v2[x]++;
    }
    multiply(v1,v2,res);
    ll ans=0,i=res.size()-1;
    while(i>=0&&m>0)
    {
        if(res[i]>0)
        {
            if(m>=res[i])
            {
                m-=res[i];
                ans+=res[i]*i;
            }
            else
            {
                
                ans+=m*i;
                m-=m;
            }
        }

        i--;

    }
    cout<<ans<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 15304
import numpy as np
def solve(n, k, r, s, p, t):
    dp = np.zeros((n, 3), dtype=int)
    win_hand_mapping = {
        "r": "p",
        "s": "r",
        "p": "s"
    }
    score_mapping = {
        "r": r,
        "s": s,
        "p": p
    }
    hand_index_mapping = {
        "r": 0,
        "s": 1,
        "p": 2
    }
    legal_hands_mapping = {
        i: [j for j in range(3) if i!=j] for i in range(3)
    }
    for i0 in range(k):
        for i in range(i0, n, k):
            win_hand = win_hand_mapping[t[i]]
            win_hand_index = hand_index_mapping[win_hand]
            win_hand_score = score_mapping[win_hand]
            for current in range(3):
                point = (current == win_hand_index) * win_hand_score
                if i < k:
                    dp[i][current] = max(dp[i][current], point)
                else:
                    for before in legal_hands_mapping[current]:
                        dp[i][current] = max(dp[i][current], dp[i-k][before] + point)
    return np.max(dp, axis=1)[-k:].sum()

n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
print(solve(n, k, r, s, p, t))

Measured memory_bytes: 15800
#include<iostream>
#include<vector>
#include<string>
#include<stdlib.h>
#include<algorithm>
#include<math.h>
using namespace std;


int main() {
	int P, Q, R;

	int a[3];
	cin >> a[0]>> a[1] >> a[2];

	sort(a,a+3);

	cout << a[0] + a[1] << endl;


}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

int32_t main(){
	int k, x;
	cin >> x >> k;
	for(int i = k-x+1; i < k+x; i++){
		cout << i << " ";
	}
	
	return 0;
}



Measured memory_bytes: 256
"""Counting Sort."""

def countingSort(A, n):
    """Sort the elements of list A with Counting Sort algorithm.

    n is the length of A.
    The elements of A are intergers between 0 and 10000, inclusive.
    B is the output list where the sorted elements will be arranged.
    
    Print the elements of B in a line separated by a space character.
    """

    C = [0 for i in range(10001)]

    for i in A:
        C[i] += 1

    for i in range(1, 10001):
        C[i] = C[i] + C[i - 1]

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

    print(*B[1:])


n = int(input())

A = list(map(int, input().split()))

countingSort(A, n)

Measured memory_bytes: 233776
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

int n;
pair<int, int> p[200005];
long long MOD = 1000000007;

int dir(long long a){
	if(a > 0) return 1;
	else if(a < 0) return -1;
	else return 0;
}

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		int pp; cin>>pp;
		p[i] = make_pair(pp,1);
	}
	for(int i=0;i<n;i++){
		int pp; cin>>pp;
		p[i+n] = make_pair(pp,-1);
	}
	sort(p,p+2*n);

	long long ans = 1;
	long long tmp = 0;

	for(int i=0;i<2*n;i++){
		if(tmp == 0) tmp += p[i].second;
		else {
			if(dir(tmp) == dir(p[i].second)) tmp += p[i].second;
			else {
				ans *= abs(tmp);
				ans %= MOD;
				tmp += p[i].second;
			}
		}
	}

	cout<<ans<<endl;
	return 0;

}


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

int main(){

    while(1){
        int m,n;
        cin >> m >> n;
        if(m==0&&n==0)break;
        vector<bool> f(8000000,true);
        int cnt=0;
        for(int i=m;cnt<n;i++){
            if(f[i]){
                cnt++;
                for(int j=1;j*i<8000000;j++){
                    f[i*j]=false;
                }
            }
        }
        int id=m;
        while(!f[id]){
            id++;
        }
        cout << id << endl;
    }

    return 0;
}


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

int main(){
  int n;
  cin >> n;
  int *arr = new int[n];
  int p = 0;
  for (int i = 0; i < n; i++){
    cin >> arr[i];
    if (arr[i] > p){
      p = arr[i];
    }
  }
  int r = 0, temp = p;
  for (int i = 0; i < n;i++){
    if (abs(p - arr[i] * 2) < temp){
      r = arr[i];
      temp = abs(p - arr[i] *2);
    }
  }
  cout << p << " " << r;
  delete[] arr;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
# define M_PI           3.14159265358979323846  /* pi */
using namespace std;

int main() {
	int A, B, C;
	int X;
	cin >> A >> B >> C >> X;
	int count = 0;

	vector<int>a(A + 1);
	vector<int>b(B + 1);
	vector<int>c(C + 1);

	for (int i = 0; i < A + 1; i++) {
		a.at(i) = (i) * 500;
	}
	for (int i = 0; i < B + 1; i++) {
		b.at(i) = (i) * 100;
	}
	for (int i = 0; i < C + 1; i++) {
		c.at(i) = (i) * 50;
	}

	for (int i = 0; i < A + 1; i++) {
		for (int j = 0; j < B + 1; j++) {
			for (int k = 0; k < C + 1; k++) {
				if (a.at(i) + b.at(j) + c.at(k) == X)count++;
			}
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 3580
import java.util.Scanner;
import java.util.Arrays;
import java.util.Collections;
public class Main{
  public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    long sum  =0;
    Long[] HP = new Long[N];
    for(int i=0; i<N; i++)
      HP[i] = sc.nextLong();
    
    if(K >= N)
      sum = 0;
    else{
		Arrays.sort(HP, Collections.reverseOrder());
       for(int i = K; i<N; i++){
         sum += HP[i];
       }
    }
    System.out.println(sum);
    
    
  }
}


Measured memory_bytes: 96544
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	puts(a+b>=c?"Yes":"No");
}


Measured memory_bytes: 256
#include <stdio.h>
#define min(x, y) ((x)>(y) ? (y) : (x))

int main(){
  int n;  scanf("%d", &n);
  char s[300005];  scanf("%s", s);
  int left[300005] = {0}, right[300005] = {0};
  for(int i=1; i<=n; i++)
    left[i] = left[i-1] + (s[i-1]=='W');
  for(int i=n; i>=1; i--)
    right[i] = right[i+1] + (s[i-1]=='E');

  int ans = 300005;
  for(int i=1; i<=n; i++)
    ans = min(ans, left[i-1]+right[i+1]);
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define pb push_back
#define fe first
#define se second
#define pii pair<int,int>
#define PI  3.14159265358979323846

const int N=35;
int h[N],baap[N],tot;

int n,m;


void solve()
{ cin>>n>>m;
	int puch=n;
  while(n--)
  { int k;
  	cin>>k;
  	for(int i=1;i<=k;i++)
  		 { int x;
  		 	cin>>x;
  				baap[x]++;
  		 } 		
  }

  /*for(int i=1;i<=m;i++)
  	cout<<baap[i]<<" ";
      cout<<endl;
      */
  for(int i=1;i<=m;i++)
  	 { if(baap[i]==puch)
  	 	 tot++;
  	 }
  	 cout<<tot;
}


int main()
{ cool;
	 int t=1;
	 while(t--)
        { solve();
        }

        return 0;
}


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

int H;
int a[10][5];

int main() {
    while (cin >> H, H) {
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < 5; j++) {
                cin >> a[i][j];
            }
        }
        bool update = true;
        int ans = 0;
        while (update) {
            update = false;
            for (int i = 0; i < H; i++) {
                int l = 0, r = 0;
                while (l < 5) {
                    while (r < 5 && a[i][r] == a[i][l]) {
                        r++;
                    }
                    if (a[i][l] && r - l >= 3) {
                        ans += (r - l) * a[i][l];
                        for (int j = l; j < r; j++) {
                            a[i][j] = 0;
                        }
                        update = true;
                    }
                    l = r;
                }
            }
            for (int j = 0; j < 5; j++) {
                vector<int> tmp;
                for (int i = H - 1; i >= 0; i--) {
                    if (a[i][j]) {
                        tmp.emplace_back(a[i][j]);
                    }
                    a[i][j] = 0;
                }
                for (int i = 0; i < (int)tmp.size(); i++) {
                    a[H - 1 - i][j] = tmp[i];
                }
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3144
N, W = map(int, raw_input().split())
v = [0]*N
w = [0]*N
for i in xrange(N):
    v[i], w[i] = map(int, raw_input().split())
dp = [0] * (W+1)
for i in xrange(N):
    for j in xrange(w[i], W+1):
        dp[j] = max(dp[j-w[i]] + v[i], dp[j])
print dp[W]

Measured memory_bytes: 6628
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int a,b;
    Scd2(a,b);

    int ans = INF;
    if( a <= b ){
        ans = min( b-a, ans );
        if( a<0 && b>=0 ){
            ans = min( abs(b+a)+1, ans );
        }
    }else{
        ans = min( a-b+2, ans );
        if( a>0 && b<=0 ){
            ans = min( abs(a+b)+1, ans );
        }
    }
    if( a == 0 ) ans = min( abs(b)+(b<0), ans );
    if( b == 0 ) ans = min( abs(a)+(a>0), ans );

    printf ("%d\n", ans );

    return 0;
}



Measured memory_bytes: 256
def selectionSort(A, N):
    c = 0
    for i in range(N):
        minj = i
        for j in range(i, N):
            if A[j] < A[minj]:
                minj = j

        if i != minj:
            A[i], A[minj] = A[minj], A[i]
            c += 1

    print " ".join(map(str, A))
    print c


N = int(raw_input())
L = map(int, raw_input().split())

selectionSort(L, N)

Measured memory_bytes: 6460
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<double,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
const LL INF=1<<30;

LL f(LL s){
    LL ret=0;
    while(s){
        ret+=s%10;
        s/=10;
    }
    return ret;
}

int main(){
    LL K;
    cin >> K;
    LL t=1,k=0;
    vector<LL> ans;
    for(int i=1;i<10;i++){
        ans.pb(i);
    }
    for(int s=0;s<=12;s++){
        k+=9*t;
        t*=10;
        vector<P> v;
        for(LL p=1;p<=1000;p++){
            v.pb(mp((double)(p*t+k)/f(p*t+k),p*t+k));
        }
        for(int i=0;i<v.size();i++){
            for(int j=i+1;j<v.size();j++){
                if(v[i].fs>v[j].fs) break;
                if(j==v.size()-1) ans.pb(v[i].sc);
            }
        }
    }
    sort(ALL(ans));
    ans.erase(unique(ALL(ans)),ans.end());
    for(int i=0;i<K;i++){
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define maxn 200005 /*rem*/
#define mod 998244353
#define db double
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define fi first
#define se second
using namespace std;
ll ksm(ll a, ll b) {
   if (!b) return 1;
   ll ns = ksm(a, b >> 1);
   ns = ns * ns % mod;
   if (b & 1) ns = ns * a % mod;
   return ns;
}
ll b2 = (mod + 1) / 2;
int d[2][maxn];
map<pi, int> hv[2];
int u[2][maxn], v[2][maxn];
ll p[10];
int main() {
	int n;
	cin >> n;
	for (int j = 0; j < 2; j++)
		for (int k = 0; k < n - 1; k++) {
			int a, b;
			scanf("%d%d", &a, &b);
			u[j][k] = a, v[j][k] = b;
			hv[j][mp(a, b)] = 1;
			hv[j][mp(b, a)] = 1;
			d[j][a]++, d[j][b]++;
		}
	p[0] = 1;
	for (int i = 1; i < 10; i++)
		p[i] = p[i - 1] * b2 % mod;
	ll ans = 0;
	for (int i = 1; i <= n; i++) {
		// 遍数
		ll cu = d[0][i] - 1;
		ll nr = p[1] + 1ll * p[2] * (n - 2 - (d[1][i] - 1)) - 1ll * p[3] * (n - 1 - d[1][i]);
		nr %= mod;
		ans = (ans + cu * nr) % mod;
	}
	for (int i = 0; i < n - 1; i++) {
		int a = u[0][i], b = v[0][i];
		ll cu = -1;
		int es = n - 1 - d[1][a] - d[1][b];
		if (hv[1][mp(a, b)]) es++;
		ll nr = p[2] + 1ll * p[3] * (n - 2 - (d[1][a] - 1) - (d[1][b] - 1)) - 1ll * p[4] * es;
		nr %= mod;
		ans = (ans + cu * nr) % mod;
	}
	ll cu = 1;
	ll nr = p[0] + p[1] * (n - 2) - p[2] * (n - 1);
	nr %= mod;
	ans = (ans + cu * nr) % mod;
	if (ans < 0) ans += mod;
	cout << ans << endl; 
	return 0;
}



Measured memory_bytes: 70324
//Program.cpp
//Problem Statement - 

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

//Author: Varun Goyal (@govarun)

#define f(i, n) for(int i=0;i<(n);++i)
#define fa(i, a, n) for(int i=(a);i<=(n);++i)
#define fd(i, a, n) for(int i=(a);i>=(n);--i)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define popb pop_back
#define ull unsigned long long
#define debug if(GOVARUN) cerr
#define d0(x) debug <<#x<<" = "<<x<<' '
#define d1(x) debug <<"> "<<#x<<" = "<<x<<'\n'
#define d2(x, y) debug <<"> "<<#x<<" = "<<x<<' '<<#y<<" = "<<y<<'\n'
#define d3(x, y, z) debug <<"> "<<#x<<" = "<<x<<' '<<#y<<" = "<<y<<' '<<#z<<" = "<<z<<'\n'
#define endl '\n'
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector< pair<int, int> > vpii;
inline bool EQ(double a, double b) { 
return fabs(a-b) < 1e-9; }
inline int two(int n) { return 1 << n; }

const int mod = 1e9 + 7;
const int maxn = 1e5 + 5;

void pre(){

    
}


void solve();

int main(){
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    #ifdef GOVARUN
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #else 
    #define GOVARUN 0
    #endif
    int TC = 1;
    // cin >> TC;
    while(TC--){    
        solve();
    }

    return 0;
}

void solve(){
    int n, k; cin >> n >> k;
    int h[n]; 
    f (i, n) cin >> h[i];
    ll cost[n]; fill(cost);
    cost[0] = 0;
    if (n == 1)  cout << 0;
    else if (n == 2) cout << abs(h[1] - h[0]);
    else {
        cost[0] = 0;
        
        fa (i, 1, n - 1) {
            cost[i] = mod;
            for (int j = i - 1, k1 = k; j >= 0 && k1 >= 1; k1--, j--){
               cost[i] = min (cost[i], cost[j] + abs(h[i] - h[j])); 
            }
        }
        cout << cost[n - 1]; 
    }
    
}

Measured memory_bytes: 1408
INF = float('inf')
def bellmanford(n, edges, r):  # r : start
    d = [INF] * n
    d[r] = 0
    for i in range(n):
        for (u, v, c) in edges:
            if d[u] != INF and d[u] + c < d[v]:
                d[v] = d[u] + c
                if i == n-1 and v == n-1:
                    return 'inf'
    return -d[n-1]


N, M = map(int, input().split())
edges = [None] * M
for i in range(M):
    a, b, c = map(int, input().split())
    edges[i] = (a-1, b-1, -c)
ans = bellmanford(N, edges, 0)
print(ans)

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

int main() {
    ll R, C, K; cin >> R >> C >> K;
    vector<vector<ll>> grid(R+1, vector<ll>(C+1, 0));
    for (int i = 0; i < K; ++i) {
        int r, c, v; cin >> r >> c >> v;
        grid[r][c] = v;
    }
    vector<vector<vector<ll>>> dp(R+1, vector<vector<ll>>(C+1, vector<ll>(4, 0)));
    for (int i = 1; i <= R; ++i) {
        for (int j = 1; j <= C; ++j) {
            dp[i][j][0] = max({dp[i][j-1][0], dp[i-1][j][0], dp[i-1][j][1], dp[i-1][j][2], dp[i-1][j][3]});
            dp[i][j][1] = max(dp[i][j][0] + grid[i][j], dp[i][j-1][1]);
            dp[i][j][2] = max(dp[i][j-1][1] + grid[i][j], dp[i][j-1][2]);
            dp[i][j][3] = max(dp[i][j-1][2] + grid[i][j], dp[i][j-1][3]);
        }
    }
    cout << max({dp[R][C][0], dp[R][C][1], dp[R][C][2], dp[R][C][3]}) << endl;
}

Measured memory_bytes: 706536
//Mahir Ratanpara (DA-IICT)
#include<bits/stdc++.h>
using namespace std;
#define Ff(i,a,n) for(i=a;i<n;i++)
#define Fr(i,a,n) for(i=a;i>n;i--)
#define ll long long
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef pair<ll, ll>	pa;
typedef vector<ll>		vc;
typedef vector<pa>		vp;
typedef vector<vc>		vvc;
int mpow(int base, int exp); 
void ipgraph(ll n,ll m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vc g[N];

int main() {
    FAST;
    ll t, i, j, k, p, q, r, x, y, u, v, n, m;
    cin>>n;
	// x=0;
	// i=1;
	// while(1)
	// {
	// 	x=pow(26,i);
	// 	if(n-x<=0)
	// 	break;
	// 	else{
	// 		n-=pow(26,i);
	// 	}
	// 	i++;
	// }

	vector<char> ans; 
	// cout<<n;
	while(n>0)
	{
		n--;
		ans.pb('a'+n%26);
		n/=26;
	}
	reverse(all(ans));
	Ff(i,0,ans.size())
	cout<<ans[i];
    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(ll n, ll m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
		g[u-1].pb(v-1);
		g[v-1].pb(u-1);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}

Measured memory_bytes: 10684
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var n=Arr.shift()-0;
var xy=[];
for(var i=0;i<n;i++){
   xy[i]=[];
   for(var j=0;j<n;j++){
      xy[i][j]=0;
   }
}
for(var i=0;i<n;i++){
   var arr=Arr.shift().split(" ").map(Number);
   var x=arr.shift();
   arr.shift();
   arr.forEach(function(v){xy[x-1][v-1]=1;});
}
console.log(xy.join("\n").replace(/,/g," "));

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define ull unsigned long long
#define ld long double

template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) rep2(i, 0, n)
#define rep1(i, n) rep1(i, 1, n + 1)

// #define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
// #define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()  //

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

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

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(15);
    //    cout << std::setfill('0') << std::setw(2);

    int h, w;
    cin >> h >> w;
    V<string> s(h);
    rep(i, h) cin >> s[i];

    VV<int> r(h, (V<int>(w, INF)));  // ctrl + Dで複数選択可能
    r[0][0] = 1;

    int ini_kuro = 0;
    rep(i, h) rep(j, w) {
        if(s[i][j] == '#') ini_kuro++;
    }

    queue<pii> q;
    q.push(make_pair(0, 0));
    while (!q.empty()) {
        pii p = q.front();
        int x = p.second, y = p.first;
        q.pop();
        if (y == h - 1 && x == w - 1) {
            break;
        }
        auto update = [&](int x, int y, int d) {
            if (r[y][x] != INF) return;
            r[y][x] = d;
            q.push(make_pair(y, x));
        };
        rep(i, 4) {
            int xx = x + dx[i];
            int yy = y + dy[i];
            if (xx < 0 || yy < 0 || xx >= w || yy >= h) continue;
            if (s[yy][xx] == '#') continue;
            update(xx, yy, r[y][x] + 1);
        }
    }
    if(r[h-1][w-1] == INF) cout << -1 << endl;
    else cout << w * h - ini_kuro - r[h - 1][w - 1] << endl;

    return 0;
}


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

#define fo(i,s,t) for(int i = s; i <= t; ++ i)
#define fd(i,s,t) for(int i = s; i >= t; -- i)
#define bf(i,s) for(int i = head[s]; i; i = e[i].next)
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
#define VI vector<int>
#define sf scanf
#define pf printf
#define fp freopen
#define SZ(x) ((int)(x).size())
#ifdef MPS
#define D(x...) printf(x)
#else
#define D(x...)
#endif
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
const int inf = 1<<30;
const ll INF = 1ll<<60;
const db Inf = 1e20;
const db eps = 1e-9;

void gmax(int &a,int b){a = (a > b ? a : b);}
void gmin(int &a,int b){a = (a < b ? a : b);}

const int maxn = 100050;

int n, A[maxn], B[maxn];

int main()
{
	#ifdef MPS
		fp("1.in","r",stdin);
		fp("1.out","w",stdout);
		double mps = clock();
	#endif
	sf("%d",&n);
	ll s1 = 0, s2 = 0;
	fo(i,1,n) 
	{
		sf("%d",&A[i]);
		s1 += A[i];
	}
	fo(i,1,n) sf("%d",&B[i]), s2 += B[i];
	if(s2 > s1) return 0 * pf("-1\n");
	ll C = s1 - s2;
	vector<int> cur;
	fo(i,1,n) if(A[i] >= B[i]) cur.pb(abs(A[i]-B[i]));
	sort(cur.begin(), cur.end());
	int ans = 0;
	for(auto p : cur)
	{
		if(C < p) break;
		C -= p;
		++ ans;
	}
	pf("%d\n",n-ans);
	return 0;
}

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

int main(){
	int a[5];
	for(int i = 0; i<5; i++){
		cin >> a[i];
	}
	sort(a, a + 5);
	for(int i = 4; i>0; i--){
		cout << a[i] << " ";
	}
	cout << a[0] << endl;
	return 0;
}

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

int main()
{
  int N;

  cin >> N;

  vector<ll> A(N);

  for(auto& a : A){
    cin >> a;
  }

  vector<ll> buf(N);

  ll tmp = 0;

  for(int i=0; i<N; ++i){
    buf[i] = tmp;
    tmp = max(tmp, A[i]);
  }

  ll ans = 0;

  for(int i=0; i<N; ++i){
    ans += (A[i] > buf[i] ? 0 : buf[i]-A[i]);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 6332
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
typedef long long ll;
using namespace std;
int main()
{
  int n;
  cin >> n;
  string s;
  cin >> s;
  string s1, s2;
  if(n %2 == 0){
    s1 = s.substr(0,n/2);
    s2 = s.substr(n/2,n/2);
    if(s1 == s2){
      cout << "Yes" << endl;
    }else{
      cout <<"No" << endl;
    }
  }else{
    cout <<"No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define c(n) cin>>n
#define c2(n,m) cin>>n>>m
#define c3(n,m,k) cin>>n>>m>>k
#define c4(n,m,k,l) cin>>n>>m>>k>>l
#define co(n) cout<<n<<endl
using namespace std;

int main(){
  long a,b=0,c=0,d=0,e,n,m,x;
  c4(a,b,c,n);
  m=max(a,b); m=max(m,c);
  co(a+b+c+m*pow(2,n)-m);
  
  
  return 0;
}

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

int N;
vector<int> a;

int main(){
    cin >> N;
    a.resize(N);

    int cnt = 0;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        if((i+1)%2!=0 && a[i]%2!=0){
            cnt++;
        }
    }

    cout << cnt << endl;
    return 0;
}

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

#define ll long long



int main()
{
    ll h,w;
    cin>>h>>w;
    if(h%3==0||w%3==0) {puts("0"); exit(0);}
    ll ans=min(h,w);
    for(int i=1;i<=h;++i)
    {
        ll x1=i*w;
        ll x2=(h-i)*(w/2LL);
        ll x3=(h-i)*(w-w/2LL);
        ans=min(ans,max(x1,max(x2,x3))-min(x1,min(x2,x3)));
    }
    swap(h,w);
    for(int i=1;i<=h;++i)
    {
        ll x1=i*w;
        ll x2=(h-i)*(w/2LL);
        ll x3=(h-i)*(w-w/2LL);
        ans=min(ans,max(x1,max(x2,x3))-min(x1,min(x2,x3)));
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 256
import collections

N = int(input())

data = []
val = [0]*N

for i in range(N):
    data.append(input())

data.sort()
c = collections.Counter(data)

mostc = c.most_common()
mostv = mostc[0][1]

ans = []
for x in mostc:
    if x[1] == mostv:
        ans.append(x[0])

ans.sort()

for y in ans:
    print(y)


Measured memory_bytes: 49200