akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std; 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define int long long int
#define rep(i,a,b) for(int i=a;i<b;i++)
#define reprev(i,a,b) for(int i=b-1;i>=a;i--)
#define all(c) c.begin(),c.end()
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define vin(a,n) vi a(n); rep(i,0,n) cin>>a[i];
#define vout(a,n) rep(i,0,n) cout<<a[i]<<" "; cout<<endl;
#define mapp map<int,int>
#define pb push_back
#define mp  make_pair
#define mod 1000000007
#define mod2 998244353
#define tr(container, it) \
for(auto it = container.begin(); it != container.end(); it++)
 
bool comps(const pair<int,int> &a, const pair<int,int> &b) {return (a.second<b.second);} 

int fac[100001];
int power(int x, unsigned int y)
{ 
    int temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2); 
    if (y%2 == 0) 
        return temp*temp; 
    else
        return x*temp*temp; 
}

int powerp(int x, unsigned int y, int p)  
{  
    int res = 1;     // Initialize result  
  
    x = x % p; // Update x if it is more than or  
                // equal to p 
   
    if (x == 0) return 0; // In case x is divisible by p; 
  
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}

int binomialCoeff(int n, int k)
{  
    // Base Cases  
    if (k == 0 || k == n)  
        return 1;  
  
    // Recur  
    return binomialCoeff(n - 1, k - 1) +  
                binomialCoeff(n - 1, k);  
}
void precomp()
{ 
    fac[0] = 1; 
    for (int i=1 ; i<=100000; i++) 
        fac[i] = fac[i-1]*i%mod;
}
int modInverse(int n, int p) {return powerp(n, p-2, p);}
int nCrModPFermat(int n, int r, int p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
  
    // Fill factorial array so that we 
    // can find all factorial of r, n 
    // and n-r   
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
} 
signed main()
{
  
    IOS
    int a[401];
    rep(i,0,401)
    {
        a[i]=power(i-200,5);
    }
    int x;
    cin>>x;
    rep(i,0,401)
    {
        rep(j,0,401)
        {
            if(a[i]-a[j]==x)
            {
                cout<<i-200<<" "<<j-200;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3644
#include<stdio.h>
#define MAX 10000
#define NIL -1

typedef struct{
  int p, l, r;
}Node;

Node T[MAX];
int n;

void preParse(int);
void inParse(int);
void postParse(int);

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

  scanf("%d", &n);
  for( i = 0; i < n; i++)
    {
      T[i].p = NIL;
    }

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

  for( i = 0; i < n; i++)
    {
      if( T[i].p == NIL ) root = i;
    }

  printf("Preorder\n");
  preParse(root);
  printf("\nInorder\n");
  inParse(root);
  printf("\nPostorder\n");
  postParse(root);
  printf("\n");
  return 0;
}

void preParse(int u)
{
  if( u == NIL ) return;
  printf(" %d", u);
  preParse(T[u].l);
  preParse(T[u].r);
}

void inParse(int u)
{
  if( u == NIL ) return;
  inParse(T[u].l);
  printf(" %d", u);
  inParse(T[u].r);
}

void postParse(int u)
{
  if( u == NIL ) return;
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d", u);
}



Measured memory_bytes: 1988
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
unordered_map<ll,ll> H[4];
ll a,b,c,d;
ll solve(ll x,int z)
{
	if(x<=1)
		return d*x;
	if(H[z].find(x)!=H[z].end())
		return H[z][x];
	ll res=1e18;
	if(x<=(ll)1e18/d)
		res=x*d;
	// cout<<x<<" "<<z<<endl;
	if(z)
	{
		// category of 2
		if(x%2==0)
		{
			res=min(res,a+solve(x/2,1));
		}		
		else
		{
			res=min(res,d+a+min(solve((x+1)/2,1),solve((x-1)/2,1)));
		}
	}
	if(z)
	{
		// res=min(res,solve(x,1));
		ll r=x%3;
		if(1)
		{
			res=min(res,b+r*d+solve(x/3,2));
		}
		if(1)
		{
			if(x/3+1!=x)
				res=min(res,b+(3-r)*d+solve(x/3+1,2));
		}
	}
	if(z)
	{
		// res=min(res,solve(x,2));
		ll r=x%5;
		if(1)
		{
			res=min(res,c+r*d+solve(x/5,3));
		}
		if(1)
		{
			if(x/5+1!=x)
				res=min(res,c+(5-r)*d+solve(x/5+1,3));
		}
	}
	// cout<<z<<" "<<x<<" "<<res<<endl;
	return H[z][x]=res;
}
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll test;
	cin>>test;
	while(test--)
	{
		for(int i=1;i<=3;i++)
			H[i].clear();
		ll tn;
		cin>>tn>>a>>b>>c>>d;
		cout<<solve(tn,3)<<"\n";
	}
	return 0;
}

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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

int main() {
	ll a, b, k;

	cin >> a >> b >> k;

	if (b - a + 1 < k * 2) {
		REP(i, b - a + 1) {
			cout << a + i << endl;
		}
	}
	else {
		REP(i, k) {
			cout << a + i << endl;
		}

		REP(i, k) {
			cout << b - k + i + 1 << endl;
		}
	}
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main{
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int d = Integer.parseInt(sc.next());
		int t = Integer.parseInt(sc.next());
		int s = Integer.parseInt(sc.next());
		if(d <= t * s) ou.print("Yes\n");
		else ou.print("No\n");
		ou.flush();
    }
}

Measured memory_bytes: 35772
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

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

int main(){
    string s;
    cin >> s;
    long int k;
    cin >> k;
    int ans = 0;
    while (s[ans] == '1' && ans < k - 1){
        ans++;
    }
    cout << s[ans] << endl;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

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

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

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

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

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

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  input! {
    h: usize,
    w: usize,
    n: usize,
    aa: [usize; n],
  }
  let mut aa = aa;
  let mut p = 0;
  let mut ans = vec![vec![0; w]; h];
  for y in 0 .. h {
    if y % 2 == 0 {
      for x in 0 .. w {
        ans[y][x] = p + 1;
        aa[p] -= 1;
        if aa[p] == 0 {
          p += 1;
        }
      }
    } else {
      for x in (0 .. w).rev() {
        ans[y][x] = p + 1;
        aa[p] -= 1;
        if aa[p] == 0 {
          p += 1;
        }
      }
    }
  }
  for v in &ans {
    for &x in v {
      print!("{} ", x);
    }
    println!("");
  }
}


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

#define F first
#define S second
#define pb push_back

using namespace std;

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

const int N = 110, K = 100010;
const int MOD = 1000000007;

int n, k, a[N], dp[N][K], ps[N][K];

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> k;
	for (int i = 1; i <= n; i++) cin >> a[i];
	dp[0][0] = 1;
	for (int i = 0; i <= k; i++){
		ps[0][i] = 1;
	}
	for (int i = 1; i <= n; i++){
		for (int j = 0; j <= k; j++){
			if (j - a[i] - 1 < 0) dp[i][j] = ps[i - 1][j];
			else dp[i][j] = ps[i - 1][j] - ps[i - 1][j - a[i] - 1];
			dp[i][j] %= MOD;
			dp[i][j] += MOD;
			dp[i][j] %= MOD;
		}
		ps[i][0] = dp[i][0];
		for (int j = 1; j <= k; j++) ps[i][j] = ps[i][j - 1] + dp[i][j], ps[i][j] %= MOD;
	}
	cout << dp[n][k];

}

Measured memory_bytes: 84224
N, W = map(int, input().split())
WV = [list(map(int, input().split())) for _ in range(N)]

V = 10**3
dp = [[float('INF')]*(N*(V+1)) for _ in range(N+1)]  # Nとv≦10**3の制約から取りうるvの範囲
dp[0][0] = 0

for i in range(N):
    for v in range((i+1)*(V+1)):
        if v - WV[i][1] >= 0:  # 品物を追加できるとき
            dp[i+1][v] = min(dp[i+1][v], dp[i][v-WV[i][1]] + WV[i][0])
        # できないとき
        dp[i+1][v] = min(dp[i+1][v], dp[i][v])

ans = 0
for i in range(N*(V+1)):
    if dp[N][i] <= W:
        ans = i
print(ans)


Measured memory_bytes: 311272
#include<bits/stdc++.h>
using namespace std;
int n,k,a[111111];

int solve(int m){
  int ak[111111]={};
  for(int i=0;i<n;i++){
    ak[a[i]]++;
    if(i<m-1)continue;
    int t=1;
    for(int j=1;j<=k;j++)
      if(ak[j]==0){
	t=0;
	break;
      }
    ak[a[i-(m-1)]]--;
    if(t)return 1;
  }
  return 0;
}

int main(){
  cin>>n>>k;
  int kk[111111]={},f=0;
  for(int i=0;i<n;i++)cin>>a[i],kk[a[i]]++;
  for(int i=1;i<=k;i++)if(kk[i]==0)f=1;
  int l=0,m,r=n;
  while(r-l>1){
    m=(l+r)/2;
    //cout<<solve(m)<<" "<<m<<endl;
    if(solve(m))r=m;
    else l=m;
  }
  if(f)cout<<0<<endl;
  else cout<<r<<endl;
  return 0;
}



Measured memory_bytes: 4368
#include <iostream>

using namespace std;

typedef long long ll;

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

ll extgcd(ll a, ll b, ll &x, ll &y) {
    ll d = a;

    if (b != 0) {
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }
    else {
        x = 1, y = 0;
    }
    return d;
}

int main() {
    ll a, b, x, y;
    cin >> a >> b;
    extgcd(a, b, x, y);

    cout << x << " " << y << endl;

    return 0;
}


Measured memory_bytes: 3092
/******************
*  Writer: BD747  *
******************/
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<vector>
using namespace std;

int n;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n;
	if(n==1){
		cout<<"Hello World";
		return 0;
	}
	int a,b;
	cin>>a>>b;
	cout<<a+b;
	
	return 0;
}


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

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

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

int main() {
	int y;
	int a[5];
	while(cin>>y){
		if (y==0) break;
		a[0]=y;
		for(int i=1;i<5;i++) cin>>a[i];
		
//		for(int i=0;i<5;i++) cout<<a[i];
//		cout<<endl;
		
		int shu[4]={0};
		for(int i=0;i<5;i++) shu[a[i]]=1;
		int kazu=shu[1]+shu[2]+shu[3];
		
		if(kazu==3 || kazu==1){
			for (int i=0;i<5;i++) cout<<"3"<<endl;
		}
		else if(shu[1]==0){
	//		cout<<"aiko1"<<endl;
			for (int i=0;i<5;i++){
				if(a[i]==2) cout<<"1"<<endl;
				else cout<<"2"<<endl;
			}
		}
		else if(shu[2]==0){
	//		cout<<"aiko2"<<endl;
			for (int i=0;i<5;i++){
				if(a[i]==3) cout<<"1"<<endl;
				else cout<<"2"<<endl;
			}
		}
		else if(shu[3]==0){
	//		cout<<"aiko3"<<endl;
			for (int i=0;i<5;i++){
				if(a[i]==1) cout<<"1"<<endl;
				else cout<<"2"<<endl;
			}
		}
		
		a[0]=0;
	}


}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
#define int long long
#define x first
#define y second
#define pb push_back

#define speed ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
signed main()
{
    speed
    int a,b;cin>>a>>b;
    int mini=min(a,b);
    int maxi=max(a,b);
    if((maxi-mini)%2){cout<<"IMPOSSIBLE";}
    else{cout<<(mini+((maxi-mini)/2));}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int N, M;
vector<int> p;

//UnionFind
vector<int> parent;

//根を探す
int find(int x) {
	//自分が根である場合
	if (parent[x] < 0) return x;
	//自分が根ではない場合、根の情報を探して代入したあとで、根を返す
	return parent[x] = find(parent[x]);
}

int size(int x) {
	return -parent[find(x)];
}

//統合する
void unite(int x, int y) {
	//親を探す
	x = find(x);
	y = find(y);
	//既に統合済み
	if (x == y) return;

	//サイズが小さい根のものを大きい根のものにくっつける
	if (size(x) > size(y)) swap(x, y);
	//xをｙにくっつける
	parent[y] += parent[x];
	parent[x] = y;
}

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


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

	p.resize(N);
	for (int i = 0; i < N; i++) {
		cin >> p[i];
		p[i]--;
	}

	parent.resize(N);
	for (int i = 0; i < N; i++)
		parent[i] = -1;

	for (int i = 0; i < M; i++) {
		int x, y;
		cin >> x >> y;
		unite(x - 1, y - 1);
	}

	int ans = 0;

	for (int i = 0; i < N; i++) {
		if (same(p[i], i))
			ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cmath>
#include<deque>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<tuple>
#include<utility>
#include<vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<vector<int>> vvi;

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define REP(i, n)  for(int i=0; i<(int)(n); i++)
#define REPS(i, n)  for(int i=1; i<=(int)(n); i++)
#define PER(i, n) for(int i=(int)(n)-1; i>= 0; i--)
#define PERS(i, n)  for(int i=(int)(n); i>0; i--)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i!=(c).end(); i++)
#define RFOR(i, c)  for(__typeof((c).rbegin()) i=(c).rbegin(); i!=(c).end(); i++)
#define ALL(container)  (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) (container).size()
#define FILL0(n)  setfill('0') << right << setw(n)
#define mp(a, b)  make_pair(a, b)
#define toLower(c)  c+0x20
#define toUpper(c)  c-0x20
#define pb  push_back
#define eb  emplace_back

const int INF = 1e9;
const long long LLINF = 1e18;
const ll MOD = 1000000007;
const int MSIZE = 100007;
const double Pi = 3.14159265358979323146;

int main(){
  int k;  cin >> k;
  string s; cin >> s;
  int n = s.length();
  for(int i=0; i<min(n, k); i++){
    cout << s[i];
  }
  if(n>k){
    cout << "...";
  }
  cout << endl;
}


Measured memory_bytes: 3632
/*
 Sarthak Jain
*/
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
int mod=1e9+7;
int min(int a,int b){
  return (a<b)?a:b;
}
int max(int a,int b){
  return (a>b)?a:b;
}
int fp(int a,int b){
  if(b==0) return 1;
  int x=fp(a,b/2);
  x=(x*x)%mod;
  if(b&1) x=(x*a)%mod;
  return x;
}
const int N=2e5+5;
vector<vector<int>> v(N);
vector<int> ans(N);



signed main() {
 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

 int n,x;
 cin>>n;
 for(int i=2;i<=n;i++)
 {
  cin>>x;
  v[x].push_back(i);
 }

 for(int i=1;i<=n;i++)
 {
  cout<<v[i].size()<<"\n";
 }
}

Measured memory_bytes: 15596
fun main(args: Array<String>) {
    // 全体一括ソートは遅いはずだが，StringBuilder を使っている部分で実行速度が上がっている？？

    val (n, m) = readLine()!!.split(" ").map { it.toInt() }

    // 各県の初期ランクを定義
    var rank = IntArray(n + 1) { 1 }


    // 全ての市を year で一括並び替え
    val cities=(1..m).map {
        // map の中で複数の式を定義している
        val (p, y) = readLine()!!.split(" ").map { it.toInt() }

        // map の lambda式でのローカルリターンを定義（@map が付いていないと main でのリターンになってしまう)
        // Kotlinのラムダでreturnする : https://qiita.com/MasanoriMT/items/f5e814737479ff8d6fec
        // return が明示的に書かれているとわかりやすいが， return を書かなくても最後の式の評価結果が戻り値となる
        return@map Triple(it, p, y)
    }.sortedBy { it.third }

    val sb=StringBuilder()

    // 各市に県内で何番目かの情報を付与した後に，入力順にソート
    cities.map {
        // 同じ県内で何番目かの情報付与
        Pair(it,rank[it.second]++)
    }.sortedBy {
        // データの入力順にソート
        it.first.first
    }.forEach {
        // 出力文字列を StringBuilder に格納
        sb.append(it.first.second.toString().padStart(6,'0'))
        sb.append(it.second.toString().padStart(6,'0'))
        sb.append("\n")
    }

    // まとめて出力
    println(sb)
}


Measured memory_bytes: 129028
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int> 
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int h,n;
int a[1005],b[1005],c[1005];
int dp[20005];
int main(){
    scanf("%d %d",&h,&n);
    for(int i=1;i<=n;i++) scanf("%d %d",&a[i],&b[i]);
    int mx=0;for(int i=0;i<n;i++) mx=max(mx,b[i]);
    memset(dp,63,sizeof(dp));
    dp[0]=0;
    for(int i=1;i<=n;i++)
        for(int j=a[i];j<=h+mx;j++)
            dp[j]=min(dp[j],dp[j-a[i]]+b[i]);
    int ans=2000000000;
    for(int j=h;j<=h+mx;j++)
        if(dp[j]<1000000000)
            ans=min(ans,dp[j]);
    cout<<ans<<endl;
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<string> s(n);
  for(int i = 0; i < n; i++) {
    cin >> s.at(i);
  }
  int alp = 26;
  vector<string> ans;
  for(int i = 0; i < alp; i++) {
    int cnt = 10000;
    for(int j = 0; j < n; j++) {
      int tmp = 0;
      for(int k = 0; k < s.at(j).size(); k++) {
        if('a' + i == s.at(j).at(k)) {
          tmp++;
        }
      }
      cnt = min(tmp, cnt);
    }
    for(int l = 0; l < cnt; l++) {
      cout << char('a' + i);
    }
  }
  cout << endl;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
cd=[list(map(int,input().split())) for _ in range(m)]
for i in range(n):
  mn=1000000000
  ans=0
  for j in range(m):
    d=abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
    if d<mn:
      mn=d
      ans=j+1
  print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t a,b,k,counter = 0,res=0;
    cin >> a >> b >> k;
    for(int64_t i=min(a,b); i>=1; i--) {
        if(a%i==0&&b%i==0) counter++;
        if(counter==k){
            res = i;
            break;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>

using namespace std;

int main(){
	int n, y, ans = 0;
	cin >> n >> y;
	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= n - i; j++){
			int sum = i * 10000 + j * 5000 + (n - i - j) * 1000;
			if(sum == y){
				cout << i << " " << j << " " << (n - i - j) << endl;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>
#include <random>
#include <list>
#include <numeric>
#include <chrono>
#include <set>


#define rep(i,p,q) for(ll i = p;i < q;i++)
#define ll long long

using namespace std;

vector<vector<ll>> graph;
vector<ll> query;
vector<ll> ans;
vector<ll> visited;


const long long MAX_N = 1 << 17;

long long dat[2 * MAX_N - 1];

ll ecd(ll a, ll b) {
	if (a < b) swap(a, b);
	if (b == 0) return a;
	else {
		return ecd(b, a % b);
	}
}

//143 B
int main(void) {
	ll n;
	cin >> n;
	vector <ll> t = vector<ll>(n);
	rep(i, 0, n) cin >> t[i];
	ll ans = 0;
	rep(i, 0, n) {
		rep(j, i + 1, n) {
			ans += t[i] * t[j];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define For(i,n,k) for(int i=(n);i<(k);i++)
int ans=0;
vector<int> h(100);
int solve(int l,int r){
    if(l+1==r) return h[l];
    int watering=0;
    int M=128;
    For(i,l,r){
        M=min(M,h[i]);
    }
    For(i,l,r){
        h[i]-=M;
    }
    watering+=M;
    int L=-1,R=-1;
    For(i,l,r){
        if(h[i]>0){
            if(L<0){
                L=i;
                R=i+1;
            }
            else{
                R++;
            }
        }
        else if(h[i]==0){
            if(L<0) continue;
            else{
                watering+=solve(L,R);
                L=-1;
                R=-1;
            }
        }
    }
    if(L<R) watering+=solve(L,R);
    return watering;
}
void Main(){
    int n;cin>>n;
    For(i,0,n) cin>>h[i];
    ans=solve(0,n);
    cout<<ans<<endl;
}
int main(){
    Main();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;using namespace std;int main(){cin.tie(0);ios::sync_with_stdio(false);ll n,k;cin>>n>>k;vector<ll> v(n);ll sum=0;for(int i=0;i<n;i++){cin>>v[i];sum+=v[i];}set<ll> s;for(ll i=1LL;i*i<=sum;i++){if(sum%i==0){s.insert(i);s.insert(sum/i);}}ll d[n];ll suma,sumi;set<ll>::iterator itr=s.end();itr--;for(;;itr--){suma=0,sumi=0;vector<ll> a=v;for(int i=0;i<n;i++){a[i]%=*itr;}sort(a.begin(),a.end());for(int i=0;i<n;i++){if(a[i])d[i]=*itr-a[i];else d[i]=0;suma+=d[i];}for(int i=0;i<=n;i++){if(sumi==suma && sumi<=k){cout << *itr<<endl;return 0;}if(i!=n){sumi+=a[i];suma-=d[i];}}if(itr==s.begin())break;}return 0;}

Measured memory_bytes: 384
#include<bits/stdc++.h>
//#include<boost\lexical_cast.hpp> 
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int> 
#define vl vector<ll>
#define vpi vector<pi> 
#define vpl vector<pl>
#define pb push_back
#define mp make_pair
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define ss second
#define ff first
#define endl "\n"
#define mod 1000000007
#define MAX 100010
#define fill(a,x) memset(x,a,sizeof x)
#define all(x) x.begin(),x.end()
#define clr(x) memset(x,0,sizeof x)
#define rep(i,a,n) for(ll i=a;i<n;++i)
#define repr(i,n,b) for(ll i=n;i>=b;i--)
#define repit(itr,x) for(auto itr=x.begin();itr!=x.end();itr++)
using namespace std;
//using boost::lexical_cast;
//using boost::bad_lexical_cast;
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int test=1;
//	cin>>test;
	while(test--){
		int n; cin>>n;
		string str; cin>>str;

		if(n<3200)
			cout<<"red"<<endl;
		else{
			cout<<str<<endl;
		}
	}
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3,unroll-loops")
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
#define spIO ios::sync_with_stdio(false);cin.tie(0)
int arr[2 * 100000 + 5], n, k;
void solve()
{
	ll maxx = 0, now;
	for (int i = 0; i < k; i++) maxx += arr[i] + 1;
	now = maxx;
	for (int i = 1; i + k - 1 < n; i++)
	{
		now += arr[i + k - 1] - arr[i - 1];
		maxx = max(maxx, now);
	}
	cout << fixed << setprecision(10) << (ld)maxx / 2;
}
int main()
{
	spIO;
	cin >> n >> k;
	for (int i = 0; i < n; i++) cin >> arr[i];
	solve();
	
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
const ll INF=1e9+7;
const ll N = 100002;
const ll MAX_N = 131072;
ll n,q;
ll dat[MAX_N*2-1];
//par (n-1)/2
//chaild 2n+1,2n+2

void init(){
    for(ll i=0;i<2*n-1;i++)dat[i] = INT_MAX;
}

void update(ll i,ll x){
    i += n-1;
    dat[i] = x;
    while(i>0){
        i = (i-1)/2;
        dat[i] = min(dat[i*2+1],dat[i*2+2]);
    }
}

ll query(ll a,ll b,ll k,ll l,ll r){
    if(a<=l && r<=b)return dat[k];
    if(r<=a || b<=l)return INT_MAX;
    else{
        ll vl = query(a,b,k*2+1,l,(l+r)/2);
        ll vr = query(a,b,k*2+2,(l+r)/2,r);
        return min(vl,vr);
    }
}


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
    cin>>n>>q;
    if(n==1){
        ll k=INT_MAX;
        FOR(i,0,q){
            ll c,x,y;
            cin>>c>>x>>y;
            if(c==0)k=y;
            else pri(k);
        }
        return 0;
    }
    ll k=1;
    while(1){
        k*=2;
        if(n<=k){
            n=k;
            break;
        }
    }
    init();
    FOR(i,0,q){
        ll x,y,c;
        cin>>c>>x>>y;
        if(c==0)update(x,y);
        else{
            cout<<query(x,y+1,0ll,0ll,n)<<endl;
        }
    }
	return 0;
}


Measured memory_bytes: 5100
from operator import itemgetter

N, M = map(int, input().split())

A = []
for i in range(N):
    A.append(list(map(int, input().split())))

A.sort(key=itemgetter(0))

num = 0
sum = 0

for i in range(N):
    num += A[i][1]
    sum += A[i][0] * A[i][1]
    if num > M:
        sum -= (num - M) * A[i][0]
        break

print(sum)

Measured memory_bytes: 28972
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
  ll X;
  cin >>X;
  ll a=1;
  while(true) {
    if((a*(a+1))/2>=X) {
      cout<<a<<endl;
      break;
    }
    else if ((a*(a+1))/2<X) {
      a++;
      continue;
    }
  }
  
  
  
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mem(a,n) memset(a,n,sizeof(a))
#define rep(i,a,b) for(int i=a;i<b;i++)
typedef long long ll;
typedef unsigned long long ull;
const int N=43+5;
const double eps=1e-6;
const int MOD=1e5+3;
const int INF=0x3f3f3f3f;
set<int>st;
int main()
{
    int n;
    while(cin>>n)
    {
        st.clear();
        int x;
        rep(i,0,n)
        {
            cin>>x;
            if(!st.count(x)) st.insert(x);
        }
        cout<<st.size()<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll md = 1000000007;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k, res = 0;
    cin >> n >> k;
    vl cnt(k+1, 0);
    for(int i = k; i >= 1; i--) {
    	cnt[i] = power(k/i, n);
    	for(int j = 2*i; j <= k; j += i) {
    		cnt[i] = (cnt[i] - cnt[j] + md)%md;
    	}
    	res = (res + (i*cnt[i])%md)%md;
    }
    cout << res << "\n";
    return 0;
}


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

int main(){
  long long N, W;
  cin >> N >> W;
  map<long long, long long> D;
  D[0] = 0;
  long long w, v;
  vector<pair<long long, long long>> tmp(0);
  for (int i=0;i<N;i++){
    cin >> w >> v;
    for (pair<long long, long long> p : D){
      tmp.push_back(p);
    }
    for (pair<long long, long long> p : tmp){
      if (D.count(p.first+v)){
        D[p.first+v] = min(p.second + w, D[p.first+v]);
      }
      else{
        D[p.first+v] = p.second + w;
      }
    }
    tmp = {};
  }
  bool flg = true;
  long long pointer = 100001;
  while (flg){
    pointer -= 1;
    if (D.count(pointer)){
      if (D[pointer] <= W){
        flg = false;
      }
    }
  }
  cout << pointer << endl;
}

Measured memory_bytes: 4344
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

N=II()
HS=LI()

if N == 1:
    print("Yes")
elif N == 2:
    print("Yes" if abs(HS[0] - HS[1]) <= 1 else "No")
else:
    for i in range(1, N)[::-1]:
        if HS[i] >= HS[i-1]:
            continue
        elif HS[i-1] - HS[i] == 1:
            HS[i-1] -= 1
        else:
            print("No")
            exit()
    print("Yes")


Measured memory_bytes: 14380
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}

int a[4][44];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int n,m;
    cin>>n>>m;
    int d[m][m],c[n][n];
    for(int i=0;i<m;i++){
        for(int j=0;j<m;j++){
            cin>>d[i][j];
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>c[i][j];
            c[i][j]--;
            a[(i+j)%3][c[i][j]]++;
        }
    }
    ll ans = 1e18;
    for(int i=0;i<m;i++){
        ll r1 = 0;
        for(int x=0;x<m;x++){
            if(x==i)continue;
            r1 += a[0][x]*d[x][i];
        }
        for(int j=0;j<m;j++){
            if(j == i) continue;
            ll r2 = 0;
            for(int x=0;x<m;x++){
                if(x == j)continue;
                r2 += a[1][x] * d[x][j];
            }
            for(int k=0;k<m;k++){
                if(k==i || k==j)continue;
                ll r3 = 0;
                for(int x=0;x<m;x++){
                    if(x == k)continue;
                    r3 += a[2][x] * d[x][k];
                }
                chmin(ans,r1+r2+r3);
            }
        }
    }
    cout << ans << endl;
    



}

Measured memory_bytes: 1280
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
    int n,k,t;
    int x[100010],sa[100010];
    
    scanf("%d",&t);
    
    while(t--){
        
        scanf("%d %d",&n,&k);
        for(int i=0;i<n;i++) scanf("%d",&x[i]);

        int ans = x[n-1]-x[0];
        for(int i=0;i<n-1;i++) sa[i] = x[i+1]-x[i];
    
        sort(sa,sa+n-1);
        reverse(sa,sa+n-1);
        for(int i=0;i<k-1;i++) ans -= sa[i];

        ans = max(ans,0);

        printf("%d\n",ans);
    }
    
    return(0);
}



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

using namespace std;

int n[4];

void solve(){
    int i,j;
    string str;
    cin >> n[0] >> n[1] >> n[2] >> n[3];
    int f[4];
    memset(f,0,sizeof(f));
    for(i = 0;i < 4;i++){
        if(n[i] == 1) f[0] = 1;
        if(n[i] == 9) f[1] = 1;
        if(n[i] == 7) f[2] = 1;
        if(n[i] == 4) f[3] = 1;
    }
    if(f[0] && f[1] && f[2] && f[3]) cout << "YES" << endl;
    else cout << "NO" << endl;
}

int main(){
    solve();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    long long d;
    cin>>n>>d;
    long long x[n],y[n];
    int ans=0;
    for(int i=0;i<n;i++){
        cin>>x[i]>>y[i];
        if(x[i]*x[i]+y[i]*y[i]<=d*d)ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6756
<?php


    $shiki = fgets(STDIN);

    $shiki_list = explode(" ",$shiki);

    $a = $shiki_list[0];
    $b = $shiki_list[1];
    $c = $shiki_list[2];


    if(4*$a*$b<(($c-$a-$b)**2) && ($c-$a-$b)>0){
        echo "Yes\n";
    }else{
        echo "No\n";
    }





Measured memory_bytes: 4604
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <utility>
#include <cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)

template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int func(int n){
    if(n%2==0){
        return n/2;
    }else{
        return 3*n+1;
    }
}

int main()
{
    int k,even,odd;
    cin>>k;
    cout<< k*k/4 <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>                        
#define pb push_back                            
#define mp make_pair                            
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)((x).size())
#define jonathan ios_base::sync_with_stdio(0)
#define livingston cin.tie(0)
using namespace std;                            
                                                
void yes() {cout << "Yes" << endl;}                                               
void no() {cout << "No" << endl;}                                                        
                                                
int dx[] = {1, 0, -1, 0, -1, -1, 1, 1};         
int dy[] = {0, 1, 0, -1, -1, 1, -1, 1}; 

const int INF = 1e9 + 9;
const long long LINF = 1e18 + 8;
const double EPS = 1e-9;
const long long MOD = 1e9 + 7; //998244353
const double PI = acos(-1);

vector<pair<int, long long> > g[200010];
long long le, ri;
long long x[200010];
int R, C, N;

bool dfs(int v) {
    if (v <= R) le = max(le, -x[v]);
    else ri = min(ri, x[v]);
    for (int i = 0; i < sz(g[v]); i++) {
        int to = g[v][i].first;
        long long w = g[v][i].second;
        if (x[to] == -LINF) {
            x[to] = w - x[v];
            if (!dfs(to)) return false;
        } else {
            if (x[to] + x[v] != w) return false;
        }
    }
    return true;
}

void solve() {
    cin >> R >> C >> N;
    for (int i = 0; i <= R + C + 5; i++) x[i] = -LINF;
    for (int i = 0; i < N; i++) {
        int r, c; cin >> r >> c;
        long long w; cin >> w;
        g[r].push_back(make_pair(R + c, w));
        g[R + c].push_back(make_pair(r, w));
    }
    for (int i = 1; i <= R; i++) {
        if (x[i] == -LINF) {
            x[i] = 0;
            le = -LINF, ri = LINF;
            if (!dfs(i) or le > ri) {
                no(); return;
            }
        }
    }   
    yes();
} 

int main() {
    jonathan; 
    livingston;
    solve();
    return 0;
}

Measured memory_bytes: 19696
require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7
n,m = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)

ans = n - a.sum
if ans >= 0
  puts ans
else
  puts -1
end

Measured memory_bytes: 15016
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

    static int N;
    static int[] P;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        N = sc.nextInt();
        P = sc.nextIntArray(N);

        System.out.println( solve() );
    }

    private static int solve() {
        int times = 0;
        for (int i = 0; i < N-1; i++) {
            int n = i+1;
            if( P[i] == n ) {
                int t = P[i];
                P[i] = P[i+1];
                P[i+1] = t;
                times++;
            }
        }
        if( P[N-1] == N ) {
            times++;
        }
        return times;
    }

    static class FastScanner {

        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}



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

#define int long long

const int N = 2e3 + 10, lg = 15;
int n, x, ar[N], rmq[N][lg], dp[N][N];

int get(int a, int b) {
	int ans = a;
	for (int i = 0; i < lg; i++) {
		if ((b>>i) & 1)	{
			if (ar[ans] > ar[rmq[a][i]])
				ans = rmq[a][i];
			a -= (1<<i);
		}
	}
	return ans;
}

int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
		
	cin >> n >> x;
	for (int i = 0; i < n; i++)
		cin >> ar[i];
	
	for (int i = 1; i <= n - 1; i++) {
		rmq[i][0] = i - 1;
	}
	
	for (int j = 1; j < lg; j++)
		for (int i = 0; i < n; i++) {
			if (i - (1<<j) >= 0) {
				if (ar[rmq[i][j-1]] > ar[rmq[i- (1<<(j-1))][j-1]])
					rmq[i][j] = rmq[i - (1<<(j-1))][j-1];
				else
					rmq[i][j] = rmq[i][j-1];
			}
		}
	
	int ans = (int)1e15 + 10;
	
	for (int j = 0; j < n; j++) {
		int ansq = 0;
		for (int i = 0; i < n; i++) {
			if (j <= i)
				ansq += ar[get(i, j)];
			else
				ansq += min(ar[get(n-1, j - (i+1))] , ar[get(i, i)]);
		}
		ans = min(ans, ansq + j * x);
	}
	cout << ans;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ins insert
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define up_b upper_bound
#define low_b lower_bound
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define rev(i,a,b) for(int i=b;i>=a;i--)
#define boost ios_base::sync_with_stdio(NULL),cin.tie(NULL),cout.tie(NULL)
#define nl '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<pii> vii;

const int N=5001;
const int MXN=1000001;
const int inf=1e9;
const ll INF=1e18;

ll a[N][N];

ll p[N];

int main(){
  boost;
  int n;
  string s;
  cin>>n;
  cin>>s;
  p[0]=1;
  for(int i=1;i<=n;i++){
    p[i]=p[i-1]*31;
  }
  int res=0;
  for(int i=0;i<n;i++){
    for(int j=i;j<n;j++){
      a[i][j-i+1]=a[i][j-i]+p[j-i]*s[j];
    }
  }
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      int l=1,r=min(j-i,n-j);
      int ans=0;
      while(l<=r){
        int m=(l+r)/2;
        if(a[i][m]==a[j][m])ans=m,l=m+1;
        else r=m-1;
      }
      res=max(res,ans);
    }
  }
  cout<<res;
  return 0;
}



Measured memory_bytes: 194944
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll mod = 1000000007 ;
bool prime(ll n)
{
  bool cnt = 0;
  for(ll i=2; i*i<=n; i++)
  {
      if(n%i==0)
      {
          return 0;
      }
  }
  return 1 ;
}

    int main()
{
    string s;
    getline(cin,s);
    for(int i=0; i<s.size(); i++)
    {
        if(s[i] == ',')s[i] = ' ' ;
    }
    cout << s << endl;





    }


Measured memory_bytes: 3572
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPL(i,f,n) for(int i=f, i##_len=(n); i<i##_len; ++i)
typedef long long ll;

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
	if (n < 10)return n;
	return findSumOfDigits(n / 10) + n % 10;
}

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

	int N;
	cin >> N;

	int s = findSumOfDigits(N);
	cout << (s==1?10:s) << endl;
	return 0;
}


Measured memory_bytes: 256
while True:
    (m,f,r) = [int(i) for i in input().split()]
    if m == f == r == -1:
        break
 
    total = m + f
    if m == -1 or f == -1 or total < 30:
        print('F')
    elif total < 50 and r < 50:
        print('D')
    elif total < 65:
        print('C')
    elif total < 80:
        print('B')
    else:
        print('A')

Measured memory_bytes: 6720
import math
from functools import reduce
l = [int(input()) for _ in range(5)]
r = 9
n = 0
for i, j in zip([I % 10 for I in l], range(5)):
    if i != 0 and i < r:
        r = i
        n = j
ceil = lambda n: math.ceil(n / 10) * 10
print(l.pop(n) + reduce(lambda a, b: ceil(a) + ceil(b), l))


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

int main(){
  string o, e;
  cin >> o;
  cin >> e;
  for(int i=0;i<o.size()+e.size();i++){
    if(i%2==0)cout << o[i/2];
    else cout << e[i/2];
  }
  cout << endl;
  return 0;
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n; cin >> n;
  vector<char> cand = {'M', 'A', 'R', 'C', 'H'};
  unordered_map<char, int> c;
  for (auto ch : cand) c[ch] = 0;
  for (int i = 0; i < n; i++) {
    string s; cin >> s;
    (c.find(s[0]) != c.end()) ? c[s[0]]++ : c[s[0]] = 1;
  }
  long long res = 0;
  for (int i = 0; i < 3; i++) {
    for (int j = i + 1; j < 4; j++) {
      for (int k = j + 1; k < 5; k++) {
        res += (long long)c[cand[i]] * c[cand[j]] * c[cand[k]];
      }
    }
  }
  cout << res << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize "03"
#pragma GCC target("sse4")

#define ll long long int
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define FRE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define f(i,n) for(ll i=0;i<n;i++)
#define fa(i,a,n) for(ll i=a;a<n?i<n:i>=n;a<n?i+=1:i-=1)
#define loop(i,a, n) for(ll i = a; i <= n; i++)
#define loopb(i,a, n) for(ll i = a; i >= n; i--)
#define pb push_back
#define pf push_front
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define setmem(x, k) memset(x, k, sizeof(x))
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define PI 3.1415926535897932384626
#define MOD 1000000007
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int>	vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef long double ld;
// const ll N = 1e6+5;	
// ll a[N], b[N], dp[N], in[N], out[N], level[N], vis[N];
// vl g[N];
ll n, m, W;

ll weight[101], value[101];
ll dp[105][100005];

ll fun(ll pos, ll W){
	if(pos > n || W == 0) return 0;

	if(dp[pos][W] != -1) return dp[pos][W];

	if(weight[pos] > W) return dp[pos][W] = fun(pos+1, W);

	return dp[pos][W] = max(value[pos] + fun(pos+1, W - weight[pos]), fun(pos + 1, W));
}

void solve() {
	ll x, y, z, p, q, r;
	cin >> n >> W;
	f(i,n) cin >> weight[i] >> value[i];
	setmem(dp, -1);
	cout << fun(0, W);
}

int32_t main() {
	IOS
	ll T;
	// cin >> T;
	// while(T--)
		solve();
	cerr<<"Time elapsed : "<<clock()*1000.0/CLOCKS_PER_SEC<<"ms"<<'\n'; 
	return 0;
}

Measured memory_bytes: 82304
// finish date: 2018/07/16
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>>
        vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>>
        vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


//足し算
int add(int a, int b) {
    return (int)(((ll)a + b + bigmod) % bigmod);
}

//引き算
int sub(int a, int b) {
    return (int)(((ll)a - b + bigmod) % bigmod);
}

//掛け算
int mul(int a, int b) {
    return (int) (((ll) (a % bigmod) * (b % bigmod)) % bigmod);
}

int makeSum(vi a) {
    int ans = 0;
    int n = a.size();
    rep(i, n) {
        ans = add(ans, mul(a[i], i + 1));
        ans = sub(ans, mul(a[i], n - i));
    }
    return ans;
}

int main() {
    int n, m;
    cin >> n >> m;
    vi x(n), y(m);
    rep(i, n) cin >> x[i];
    rep(i, m) cin >> y[i];

    cout << mul(makeSum(x), makeSum(y)) << endl;

    return 0;
}



Measured memory_bytes: 1792
#include <stdio.h>
int main(){
	int num = 0;
	char a,b,c;
	scanf("%c%c%c",&a,&b,&c);
	if(a=='o') num++;
	if(b=='o') num++;
	if(c=='o') num++;
	printf("%d\n",700+num*100);
	return 0;
}

Measured memory_bytes: 128
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let s = read::<String>().chars().collect::<Vec<_>>();
    if (s[0] == s[1] && s[1] == s[2]) || (s[2] == s[3] && s[1] == s[2]) {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
n = int(input())
*a, = map(int, input().split())
*b, = map(int, input().split())
k = l = 0
for i, j in zip(a, b):
	k += j - i
	l += max(0, i - j) + max(0, j - i) % 2
if k >= l and (k - l) % 2 == 0:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 4596