akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>

namespace lib 
{
	template<std::uint64_t Mod>struct modnum;
	template<class T>constexpr T pow(T base, std::size_t p)
	{
		if (p == 0)
		{
			return T(1);
		}
		else if (p == 1)
		{
			return base;
		}
		else if (p == 2)
		{
			return base*base;
		}
		else if (p % 2 == 0)
		{
			return pow(pow(base, p / 2), 2);
		}
		else
		{
			return pow(pow(base, p / 2), 2)*base;
		}
	}
	template<std::uint64_t Mod>constexpr auto inverse(modnum<Mod> const&);

	template<std::uint64_t Mod>struct modnum
	{
		static constexpr auto mod = Mod;
		std::uint64_t val;
		modnum() = default;
		constexpr modnum(std::uint64_t v) :val(v)
		{

		}

		constexpr modnum& operator+=(modnum const& v)
		{
			val += v.val;
			val %= mod;
			return *this;
		}
		constexpr modnum& operator-=(modnum const& v)
		{
			val += mod - v.val;
			val %= mod;
			return *this;
		}
		constexpr modnum& operator*=(modnum const& v)
		{
			val *= v.val;
			val %= mod;
			return *this;
		}
		constexpr modnum& operator/=(modnum const& v)
		{
			return operator*=(inverse(v));
		}
	};
	template<std::uint64_t Mod>constexpr auto operator+(modnum<Mod> lhs, modnum<Mod>const& rhs)
	{
		return lhs += rhs;
	}
	template<std::uint64_t Mod>constexpr auto operator-(modnum<Mod> lhs, modnum<Mod>const& rhs)
	{
		return lhs -= rhs;
	}
	template<std::uint64_t Mod>constexpr auto operator*(modnum<Mod> lhs, modnum<Mod>const& rhs)
	{
		return lhs *= rhs;
	}
	template<std::uint64_t Mod>constexpr auto operator/(modnum<Mod> lhs, modnum<Mod>const& rhs)
	{
		return lhs /= rhs;
	}

	template<std::uint64_t Mod>constexpr auto inverse(modnum<Mod>const& base)
	{
		return pow(base, Mod - 2);
	}


}

void Main();
int main()	
{
	std::cin.sync_with_stdio(false);
	Main();
}

void Main()
{
	int N;
	std::cin >> N;
	long long c{};
	int prev;
	int count = 1;
	std::cin >> prev;
	for (int i = 1; i < N; ++i)
	{
		int x;
		std::cin >> x;
		auto v = x - prev;
		if (c == 0)
		{
			c = v;
		}
		else if (c*v < 0)
		{
			c = 0;
			++count;
		}
		prev = x;
	}
	std::cout << count << std::endl;
}

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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long N, std::vector<std::string> S){
    unordered_map<string, int> cnt;
    rep(i,0,N) {
        cnt[S[i]]++;
    }
    for (const auto& key : {"AC", "WA", "TLE", "RE"}) {
        cout << key << " x " << cnt[key] << endl;
    }
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long N;
    scanf("%lld",&N);
    std::vector<std::string> S(N);
    for(int i = 0 ; i < N ; i++){
        std::cin >> S[i];
    }
    solve(N, std::move(S));
    return 0;
}


Measured memory_bytes: 6452
#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define int long long
#define pb push_back
#define mod 1000000007
#define pll pair<long long,long long>
using namespace std;
long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a)%mod;}
                a=(a*a)%mod;
                b>>=1;
        }
    return ans;
        
}
bool prime(int n){
    for(int i=2;i*i<=n;i++){
        if(n%i==0)return false;
    }
    return true;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int a;
    cin>>a;
    cout<<a+power(a,2)+power(a,3);
    return 0;
}

Measured memory_bytes: 3648
H = []
W = []
while True:
    h, w = map(int, input().split())
    if h == 0 and w == 0:
        break
    else:
        H.append(h)
        W.append(w)
for hh, ww in zip(H, W):
    for i in range(hh):
        for j in range(ww):
            print('#',end="")
        print("")
    print("",end="\n")


Measured memory_bytes: 7016
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1e9+1;


void solve(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << max(10*a+b+c, max(a+10*b+c, a+b+10*c)) << endl;
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define sort(a) sort(a.begin(), a.end())
#define loop(n) for(ll i = 0; i<n; i++)
using namespace std;

int main(){
    ll n = 0, a = 0, b = 0;
    cin>>n>>a>>b;
    ll rep = n/(a+b), rem = n%(a+b);
    ll count = rep*a;
    rem>a?(count+=a):(count+=rem);
    cout<<count<<"\n";
    return 0;
}

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int s, n = 0;
    int mx = 0, mn = 0, sum = 0;
    while (1)
    {
        cin >> n;
        mx = -1;
        mn = 1001;
        sum = 0;
        if (n == 0)
            return 0;
        REP(i, n)
        {
            cin >> s;
            mx = max(mx, s);
            mn = min(mn, s);
            sum += s;
        }
        cout << (sum - mx - mn) / (n - 2) << endl;
    }
}


Measured memory_bytes: 3108
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int a[100];
int b[100];
int c[100];
int d[100];
int f[100];
pair<int, int> blue[100];

int main()
{
	int N, ans = 0;

	cin >> N;
	rep(i, N) cin >> a[i] >> b[i];
	rep(i, N) cin >> blue[i].first >> blue[i].second;

	sort(blue, blue + N);
	rep(i, N) c[i] = blue[i].first, d[i] = blue[i].second;

	rep(i, N) {
		int ymax = -1;
		int index = -1;

		rep(j, N) {
			if (f[j]) continue;
			if (a[j] < c[i] && b[j] < d[i] && b[j] > ymax) {
				index = j;
				ymax = b[j];
			}
		}

		if (index == -1) continue;

		f[index] = true;
		ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
# define ll  long long int
# define ld  long double
# define pb push_back
# define pp pop_back
# define ff first
# define ss second
# define mp make_pair
# define ac accumulate
# define mod 1000000007
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int  main()
{
    #ifndef ONLINE_JUDGE
       freopen("input.txt", "r", stdin);
       freopen("output.txt", "w", stdout);
    #endif
     IOS;
     int n;
     cin >> n;
     string s;
     cin >> s;
     int i = 0, j = 0;
     int cnt = 0;
     while(i < n && j < n){
     	if(s[i] == s[j] && s[i] == 'R'){
     		j++;
     		i++;
     	}
     	else if(s[i] == s[j] && s[i] == 'W')
     		i++;
     	else{
     		if(s[i] == 'R'){
     			cnt++;
     			i++;
     			j++;
     		}
     		else{
     			i++;
     		}
     	}
     }
     cout << cnt;
     return 0;
}

Measured memory_bytes: 3776
#include <iostream>
#include <vector>
#include <queue>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(void){
    string s;
    cin >> s;
    
    int r[3];
    r[0] = r[1] = r[2] = 0;
    for (int i = 0; i < s.size(); i++) r[char(s[i]) - 'a']++;
    
    sort(r, r + 3);
    
    if (r[2] - r[0] <= 1) cout << "YES" << endl;
    else cout << "NO" << endl;
    
    
}

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

#define ONE 0x1
#define NINE 0x2
#define SEVEN 0x4
#define FOUR 0x8
#define ALL 0xF

int main(){
  string S;
  string str ="keyence";
  cin >> S;
  int n = S.size();
//  cout << n << endl;
  if(S[0] != 'k'){
    if(strncmp(&S[0] + n - 7, &str[0],7) == 0){
      cout << "YES" << endl;
    }else {
      cout << "NO" << endl;
    }
  } else if(S[n-1] != 'e'){
    if(strncmp(&S[0], &str[0],7) == 0){
      cout << "YES" << endl;
    }else {
      cout << "NO" << endl;
    }
  } else{
    int f_cnt = 0;
    int b_cnt = 0;
    for(int i = 0; i < 7; i++){
      if(S[i] != str[i]) break;
      f_cnt++;
    }
    for(int i = 0; i < 7; i++){
      if(S[n - 1 - i] != str[7 -1 -i]) break;
      b_cnt++;
    }
    if( f_cnt + b_cnt >= 7){
      cout << "YES" << endl;
    }else {
      cout << "NO" << endl;
    }
  }
//  cout << S << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;

const int INF = INT_MAX;
const long long INFL =LONG_LONG_MAX;
const double PI = atan(1)*4;
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

ll gcb(ll a, ll b){/// ユークリッドの互除法: O(log)
    
    if(b == 0) return a;
    
    return gcb(b,a%b);
}


ll lcm(ll a, ll b){
    
    return  a/gcb(a,b) * b; ///gcbは約数
}

int getDigit(ll num){
    return log10(abs(num))+1;
}


int main() {
    ll a,b,c,k;cin>>a>>b>>c>>k;
    
    if(k%2==0){
        cout<<a-b<<endl;
    }else{
        cout<<b-a<<endl;
    }
    
    return 0;
}










Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
typedef long long int lli;
typedef struct{
    int num;
    lli a,b;
    lli goal;
}student;
int main(void)
{
    int n,m;
    lli c[50],d[50];
    int cd[50]={0};
    lli min,tmpj;
    student list[50];

    scanf("%d %d",&n,&m);
    for(int i=0;i<n;i++){
        scanf("%lld %lld",&list[i].a,&list[i].b);
        list[i].num=i;
    }
    for(int i=0;i<m;i++){
        scanf("%lld %lld",&c[i],&d[i]);
    }
    for(int i=0;i<n;i++){
        min=LLONG_MAX;
        tmpj=0;
        for(int j=0;j<m;j++){
            lli tmp=llabs(list[i].a-c[j])+llabs(list[i].b-d[j]);
            if(min>tmp){
                min=tmp;
                tmpj=j;
            }
        }
        list[i].goal=tmpj;
    }
    for(int i=0;i<n;i++){
        printf("%d\n",list[i].goal+1);
    }
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (n, t) = readLine()!!.split(' ').map(String::toInt)
    val a = readLine()!!.split(' ').map(String::toInt)
    var blank = 0
    for (i in 1 until a.size) {
        val interval = a[i] - a[i - 1]
        if (t < interval) {
            blank += interval - t
        }
    }
    println(a.last() + t  - blank)
}


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

int main()
{
    int n;
    cin >> n;
    const char* hon = "hon";
    const char* pon = "pon";
    const char* bon = "bon";
    switch (n%10)
    {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
        cout << hon << endl;
        break;
    case 0:
    case 1:
    case 6:
    case 8:
        cout << pon << endl;
        break;
    case 3:
        cout << bon << endl;
        break;
    }
    return 0;
}

Measured memory_bytes: 3128
#include<bits/stdc++.h>
#define ll long long 
#define int ll
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

int32_t main(){
    fast;
    string s;   cin>>s;
    int a{},z{};
    for(int i=0;i<s.length();i++){
        if(s[i]=='A'){
            a = i;
            break;
        }
    }
    for(int i=s.length()-1;i>=0;i--){
        if(s[i]=='Z'){
            z = i;
            break;
        }
    }
    cout<<z-a+1<<endl;
    return 0;
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
#include <cstring>
#include <ctype.h>
#include<stdlib.h>

#define flin            freopen("input.txt", "r", stdin); 
#define flout           freopen("output.txt", "w", stdout);
#define ll              long long
#define ull             unsigned long long
#define fastio          ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define nl              '\n'
#define nll             '\0'
#define pb              push_back
#define bdyptb          return 0;
#define sorted(x)       sort(x.begin(), x.end())
#define reversed(x)     reverse(x.begin(), x.end())
#define all(x)          x.begin(), x.end()
#define mset(a, b)      memset(a, b, sizeof(a));
#define testcase        ll t,tt; cin>>tt; for(t=1;t<=tt;t++)

#define pi acos(-1.00)   
#define mx 1000007

using namespace std; 

const int MAX = 1000001; 

// array to store prime factors 
int factor[MAX] = { 0 }; 

// function to generate all prime factors 
// of numbers from 1 to 10^6 
void generatePrimeFactors() 
{ 
	factor[1] = 1; 

	// Initializes all the positions with their value. 
	for (int i = 2; i < MAX; i++) 
		factor[i] = i; 

	// Initializes all multiples of 2 with 2 
	for (int i = 4; i < MAX; i += 2) 
		factor[i] = 2; 

	// A modified version of Sieve of Eratosthenes to 
	// store the smallest prime factor that divides 
	// every number. 
	for (int i = 3; i * i < MAX; i++) { 
		// check if it has no prime factor. 
		if (factor[i] == i) { 
			// Initializes of j starting from i*i 
			for (int j = i * i; j < MAX; j += i) { 
				// if it has no prime factor before, then 
				// stores the smallest prime divisor 
				if (factor[j] == j) 
					factor[j] = i; 
			} 
		} 
	} 
} 

// function to calculate number of factors 
int calculateNoOFactors(int n) 
{ 
	if (n == 1) 
		return 1; 

	int ans = 1; 

	// stores the smallest prime number 
	// that divides n 
	int dup = factor[n]; 

	// stores the count of number of times 
	// a prime number divides n. 
	int c = 1; 

	// reduces to the next number after prime 
	// factorization of n 
	int j = n / factor[n]; 

	// false when prime factorization is done 
	while (j != 1) { 
		// if the same prime number is dividing n, 
		// then we increase the count 
		if (factor[j] == dup) 
			c += 1; 

		/* if its a new prime factor that is factorizing n, 
		then we again set c=1 and change dup to the new 
		prime factor, and apply the formula explained 
		above. */
		else { 
			dup = factor[j]; 
			ans = ans * (c + 1); 
			c = 1; 
		} 

		// prime factorizes a number 
		j = j / factor[j]; 
	} 

	// for the last prime factor 
	ans = ans * (c + 1); 

	return ans; 
} 

// Driver program to test above function 
int main() 
{ 
	// generate prime factors of number 
	// upto 10^6 
	generatePrimeFactors(); 

	int n;
	cin>>n;

	
	ll out=0;
	for(int i=n-1; i>0; i--)
	{
		int x = calculateNoOFactors(i);
		
		// cout<<x<<nl;
		out+=x;
	}


	cout<<out<<nl;
	

	return 0; 
} 


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

int main(){
  int n;
  cin >> n;
  vector<int> data(n);
  for(int i = 0; i < n; i++){
    cin >> data.at(i);
  }
  for(int i = 1; i < n + 1; i++){
    if(i == n){
      cout << data.at(n - i) << endl;
    }
    else{ 
      cout << data.at(n - i) << " ";
    }
  }
}



Measured memory_bytes: 3064
def count(a, t):
    ans = 0
    for i in range(len(t)):
        if a[i] == t[i]:
            ans += 0
        elif a[i] == "g" and t[i] == "p":
            ans -= 1
        elif a[i] == "p" and t[i] == "g":
            ans += 1
    return ans


def main():
    s = input()
    a = "gp" * (len(s) // 2 + 1)
    print(count(a, s))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
n, a, b = map(int, input().split())
if a % 2 == b % 2:
    print((b - a) // 2)
else:
    if a > n - b + 1:
        rest = (b - a) // 2
        print(n - a - rest)
    else:
        rest = (b - a) // 2
        print(b - 1 - rest)
    #print(max(a, n - b + 1) - 1)

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

void insertionSort(int a[], int n){
    int i,j,k,v;
    
    // print
    for(k=0; k<n; k++){
        // cout << a[k] << " ";
        cout << a[k];
        if(k != n-1){cout << " ";}
    }
    cout << endl;
    
    for(i=1; i<n; i++){
        v = a[i];
        j = i-1;
        while( j>=0 && a[j]>v){
            a[j+1] = a[j];
            j--;
        }
        a[j+1] = v;

        // print
        for(k=0; k<n; k++){
            // cout << a[k] << " ";
            cout << a[k];
            if(k != n-1){cout << " ";}
        }
        // if(i != n-1){cout << endl;}
        cout << endl;
    }
}

int main(){
    int n;
    int a[100];
    cin >> n;
    // input
    for(int i=0; i<n; i++){
        cin >> a[i];
    }

    insertionSort(a,n);

    return 0;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define endl '\n'
#define debug(n1) cout<<n1<<endl
const int N = 1e5;  // limit for array size
ll n;  // array size

int main(){
	int a,b;cin>>a>>b;
	
	if(a>8||b>8){
		cout<<":("<<endl;
	}
	else{
		cout<<"Yay!"<<endl;
	}
	return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

int main()
{
    ll a, b, k;
    cin >> a >> b >> k;
    if (k < a) {
        a -= k;
    } else {
        k -= a;
        a = 0;
        if (k < b) {
            b -= k;
        } else {
            b = 0;
        }
    }
    cout << a << " " << b << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<iostream>
#include<cstdio>
using namespace std;
int gcd(int a,int b){if(a<b){swap(a,b);}if(b==0){return a;}return gcd(a%b,b);}
int main(void){
	int N,i,q,am=0;
	vector<bool> a;
	scanf("%d",&N);
	a.resize(100000);
	for(i=0;i<N;i++){
		scanf("%d",&q);
		if(a[q]){am++;}
		a[q]=true;
	}
	if(am%2){am++;}
	cout<<(N-am)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<deque>
#include<set>
#include<map>
#include<bitset>
#include<ctime>
#include<queue>
using namespace std;
#define int long long
#define pii pair <int, int>
#define XX first
#define YY second

// constants:
const int mn = 200005;
const int mod = 1000000007;
const long long inf = 4444444444444444444;
const int sminf = 1111111111;
const bool is_multitest = 0;
const bool is_interactive = 0;

// i/o methods:
const bool input_from_file = 0;
const bool output_to_file = 0;
#define filename ""
#define in_extension "inp"
#define out_extension "out"

// data preprocessing: (e.g.: divisor generating, prime sieve)
void preprocess()
{
    
}

// global variables:
int a, b, k;   
// main solution goes here:
void execute(int test_number)
{
    cin>>a>>b>>k;
    int m = min(a, k);
    a-=m;
    k-=m;
    b-=k;
    cout<<a<<" "<<max(b, 0ll)<<"\n";
}
// REMEMBER TO CHOOSE TEST METHODS
// PLEASE REMOVE cout AND cerr DEBUG LINES BEFORE SUBMITTING PROBLEMS
// Solution by low_



















signed main()
{
#ifdef lowie
    if (!is_interactive)
    {
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
#else
    if (input_from_file) freopen(filename"."in_extension, "r", stdin);
    if (output_to_file) freopen(filename"."out_extension, "w", stdout);
#endif
    if (!is_interactive)
    {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }

    preprocess();
    int ntest;
    if (is_multitest) cin >> ntest;
    else ntest = 1;

    for (int testno = 1; testno <= ntest; testno++)
    // use for instead of while to serve facebook hacker cup test format
    {
        execute(testno); // only start coding in this function, not in main
    }
}
// Template by low_
// Contact me via mail: ttuandung1803@gmail.com
// ...or codeforces: www.codeforces.com/profiles/low_
// ...or if you're interested in food: www.instagram.com/lowie.exe/

Measured memory_bytes: 3644
package main

import (
	"fmt"
	"math"
)

var H, W int

func main() {
	fmt.Scan(&H, &W)
	S := make([][]string, H+2)
	m := make([][]int, H+2)
	S[0], S[H+1] = make([]string, W+2), make([]string, W+2)
	m[0], m[H+1] = make([]int, W+2), make([]int, W+2)

	for i := 1; i <= H; i++ {
		S[i] = make([]string, W+2)
		m[i] = make([]int, W+2)
		var t string
		fmt.Scan(&t)

		for j := 1; j <= W; j++ {
			S[i][j] = string(t[j-1])
			if string(t[j-1]) == "#" {
				m[i][j] = 999
			}
		}
	}

	for i := 1; i <= H; i++ {
		for j := 1; j <= W; j++ {
			if S[i][j] == "#" {
				m[i-1][j-1]++
				m[i-1][j]++
				m[i-1][j+1]++
				m[i][j-1]++
				m[i][j+1]++
				m[i+1][j-1]++
				m[i+1][j]++
				m[i+1][j+1]++
			}
		}
	}

	for i := 1; i <= H; i++ {
		for j := 1; j <= W; j++ {
			if 999 <= m[i][j] {
				fmt.Printf("%s", "#")
			} else {
				fmt.Printf("%d", m[i][j])
			}
		}
		fmt.Printf("\n")
	}
}

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

func combination(x, y int) int {
	return permutation(x, y) / permutation(y, y)
}

func permutation(x, y int) int {
	var ans int = 1
	for i := x - y; 0 < i; i-- {
		ans *= i
	}
	return ans
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }

type XY struct {
	x int
	y int
}

type SortBy []XY

func (a SortBy) Len() int      { return len(a) }
func (a SortBy) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool {
	if a[i].x == a[j].x {
		return a[i].y > a[j].y
	}
	return a[i].x > a[j].x
}


Measured memory_bytes: 640
import scala.io.StdIn.readInt

object Main extends App {
  val n = readInt
  var minv = readInt
  var maxv = Int.MinValue

  for(i<-1 until n) {
    val r = readInt
    val m = r-minv

    if(m > maxv) {
      maxv = m
      if(m < 0) minv = r
    }
    else if(m < 0) minv = r
  }
  println(maxv)
}

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

int main(){
	//cin.tie(0),ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<int>a(n);
	map<int,int>m;
	for(auto&i:a){
		cin>>i;
		++m[i];
	}
	int64_t ans=0,tmp,tmp2;
	for(auto&i:m)ans+=(int64_t)i.second*(i.second-1)/2;
	for(auto&i:a){
		tmp=m.at(i);
		tmp=tmp*(tmp-1)/2;
		tmp2=m.at(i)-1;
		tmp2=tmp2*(tmp2-1)/2;
		cout<<ans-tmp+tmp2<<"\n"s;
	}
}

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

using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using ll = long long int;
using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>;
using vd = vector<double>; using vvd = vector<vd>; using vvvd = vector<vvd>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using cdouble = complex<double>;

const double eps = 1e-7;
#define Loop(i, n) for(int i = 0; i < int(n); i++)
#define Loopll(i, n) for(ll i = 0; i < ll(n); i++)
#define Loop1(i, n) for(int i = 1; i <= int(n); i++)
#define Loopll1(i, n) for(ll i = 1; i <= ll(n); i++)
#define Loopr(i, n) for(int i = int(n) - 1; i >= 0; i--)
#define Looprll(i, n) for(ll i = ll(n) - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = int(n); i >= 1; i--)
#define Looprll1(i, n) for(ll i = ll(n); i >= 1; i--)
#define Foreach(buf, container) for(auto buf : container)
#define Loopdiag(i, j, h, w, sum) for(int i = ((sum) >= (h) ? (h) - 1 : (sum)), j = (sum) - i; i >= 0 && j < (w); i--, j++)
#define Loopdiagr(i, j, h, w, sum) for(int j = ((sum) >= (w) ? (w) - 1 : (sum)), i = (sum) - j; j >= 0 && i < (h); j--, i++)
#define Loopdiagsym(i, j, h, w, gap) for (int i = ((gap) >= 0 ? (gap) : 0), j = i - (gap); i < (h) && j < (w); i++, j++)
#define Loopdiagsymr(i, j, h, w, gap) for (int i = ((gap) > (h) - (w) - 1 ? (h) - 1 : (w) - 1 + (gap)), j = i - (gap); i >= 0 && j >= 0; i--, j--)
#define Loopitr(itr, container) for(auto itr = container.begin(); itr != container.end(); itr++)
#define printv(vector) Loop(ex_i, vector.size()) { cout << vector[ex_i] << " "; } cout << endl;
#define printmx(matrix) Loop(ex_i, matrix.size()) { Loop(ex_j, matrix[ex_i].size()) { cout << matrix[ex_i][ex_j] << " "; } cout << endl; }
#define quickio() ios::sync_with_stdio(false); cin.tie(0);
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
#define Comp(type_t) bool operator<(const type_t &another) const
#define fst first
#define snd second
#define INF INFINITY
bool feq(double x, double y) { return abs(x - y) <= eps; }
bool inrange(ll x, ll t) { return x >= 0 && x < t; }
bool inrange(vll xs, ll t) { Foreach(x, xs) if (!(x >= 0 && x < t)) return false; return true; }
int ceillog2(ll x) { int ret = 0;	x--; while (x > 0) { ret++; x >>= 1; } return ret; }
ll rndf(double x) { return (ll)(x + (x >= 0 ? 0.5 : -0.5)); }
ll floorsqrt(ll x) { ll m = (ll)sqrt((double)x); return m + (m * m <= x ? 0 : -1); }
ll ceilsqrt(ll x) { ll m = (ll)sqrt((double)x); return m + (x <= m * m ? 0 : 1); }
ll rnddiv(ll a, ll b) { return (a / b + (a % b * 2 >= b ? 1 : 0)); }
ll ceildiv(ll a, ll b) { return (a / b + (a % b == 0 ? 0 : 1)); }
ll gcd(ll m, ll n) { if (n == 0) return m; else return gcd(n, m % n); }
ll lcm(ll m, ll n) { return m * n / gcd(m, n); }

//========================================================================//

int main() {
	int n, a, b; cin >> n >> a >> b;
	cout << min(n * a, b) << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <set>

const int maxn = 2e5 + 20;
const int inf = 0x3f3f3f3f;

struct Data
{
	int len;
	int min[2];
	
	friend Data operator + (Data a,Data b)
	{
		return (Data)
		{
			a.len + b.len,
			{
				std::min(a.min[0], b.min[0 ^ (a.len & 1)]),
				std::min(a.min[1], b.min[1 ^ (a.len & 1)])
			}
		};
		
	}
	
	friend bool operator < (const Data &a,const Data &b)
	{
		return a.min[1] < b.min[1];
	}
	
} T[maxn << 2];

int N, P[maxn];
int pos[maxn];

std::set<std::pair<int,std::pair<int,int> > > set;

void build(int l,int r,int x)
{
	if(l == r)
	{
		T[x] = (Data){1, {inf, P[l]}};
	}
	else
	{
		int mid = (l + r) >> 1;
		
		build(l, mid, x << 1);
		build(mid + 1, r, x << 1 | 1);
		
		T[x] = T[x << 1] + T[x << 1 | 1];
	}
}
Data query(int l,int r,int ll,int rr,int x)
{
	if(l == ll && r == rr)
	{
		return T[x];
	}
	else
	{
		int mid = (ll + rr) >> 1;
		
		if(r <= mid) return query(l, r, ll, mid, x << 1);
		else if(l > mid) return query(l, r, mid + 1, rr, x << 1 | 1);
		else
		{
			return query(l, mid, ll, mid, x << 1) + query(mid + 1, r, mid + 1, rr, x << 1 | 1);
		}
	}
}
std::pair<int,std::pair<int,int> > get(int l,int r)
{
	return std::make_pair(query(l, r, 1, N, 1).min[1], std::make_pair(l, r));
}
int main()
{
	scanf("%d", &N);
	for(int i = 1; i <= N; i++) scanf("%d", &P[i]);
	for(int i = 1; i <= N; i++) pos[P[i]] = i;
	
	build(1, N, 1);
	
	set.insert(get(1, N));

	while(!set.empty())
	{
		auto it = set.begin();
		int l = (it->second).first;
		int r = (it->second).second;
		
		int x = pos[it->first];
		int y = pos[query(x, r, 1, N, 1).min[0]];
		
		printf("%d %d ", P[x], P[y]);
		
		set.erase(it);
		
		if(l < x - 1) set.insert(get(l, x - 1));
		if(x + 1 < y - 1) set.insert(get(x + 1, y - 1));
		if(y + 1 < r) set.insert(get(y + 1, r));
	}
	
	return 0;
}

Measured memory_bytes: 12160
s = input()
a = "keyence"
b = 0
if s[:7] == a:
  b = 1
for i in range(7):
  if s[:i] == a[:i] and s[i-7:] == a[i:]:
    b = 1
    break
if b:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3060
n=int(input())
c=list(input())

import math

rkosu=c.count("R")
wkosu=n-rkosu

ca=["R"]*rkosu+["W"]*wkosu

count=0
for i in range(n):
    if c[i] != ca[i]:
        count+=1

ans=math.ceil(count/2)
print(ans)

Measured memory_bytes: 77904
# Node
class Node
  attr_accessor :id, :parent, :left, :right

  def initialize(id, parent = nil, left = nil, right = nil)
    @id, @parent, @left, @right = id, parent, left, right
  end
end

# BinaryTree
class BinaryTree
  attr_accessor :nodes

  def initialize(data)
    @nodes = data.each_with_object({}) do |(key, value), hash|
      hash[key] = Node.new(key, value[:parent], value[:left], value[:right])
    end
  end

  def depth(id)
    node = @nodes[id]
    unless node.parent.nil?
      return depth(node.parent) + 1
    else
      return 0
    end
  end

  def root?(id)
    node = @nodes[id]
    node.parent.nil?
  end

  def leaf?(id)
    children(id).empty?
  end

  def sibling(id)
    parent = @nodes[id].parent
    unless parent.nil?
      s = children(parent).select { |child| id != child }
      return s.any? ? s.shift : -1
    end
    -1
  end

  def degree(id)
    children(id).length
  end

  def height(id)
    c = children(id)
    unless c.empty?
      heights = []
      c.each do |child|
        heights << height(child) + 1
      end
      return heights.max
    else
      return 0
    end
  end

  def root
    @nodes.values.find { |node| root?(node.id) }
  end

  def preorder(id)
    stack, list = [id], []

    until stack.empty?
      node = @nodes[stack.pop]
      list << node
      stack << node.right unless node.right == -1
      stack << node.left unless node.left == -1
    end

    list
  end

  def inorder(id)
    stack, list = [], []

    until stack.empty? && id == -1
      if id != -1
        stack << id
        id = @nodes[id].left
      else
        node = @nodes[stack.pop]
        list << node
        id = node.right
      end
    end

    list
  end

  def postorder(id)
    stack, list = [], []
    last = -1

    until stack.empty? && id == -1
      if id != -1
        stack << id
        id = @nodes[id].left
      else
        peek_node = @nodes[stack.last]
        if peek_node.right != -1 && last != peek_node.right
          id = peek_node.right
        else
          list << peek_node
          last = @nodes[stack.pop].id
        end
      end
    end

    list
  end

  private

  def children(id)
    node = @nodes[id]
    [node.left, node.right].select { |i| i != -1 }
  end
end

data = {}
parent = {}

n = gets.chop.to_i

n.times do
  id, left, right = gets.chop.split.map(&:to_i)
  data[id] = { :left => left, :right => right }
  parent[left] = parent[right] = id
end

data.each do |key, value|
  value[:parent] = parent[key]
end

data = Hash[data.sort]

t = BinaryTree.new(data)
root = t.root

puts 'Preorder'
out = []
t.preorder(root.id).each do |node|
  out << node.id
end
puts " #{out.join(' ')}"
puts 'Inorder'
out = []
t.inorder(root.id).each do |node|
  out << node.id
end
puts " #{out.join(' ')}"
puts 'Postorder'
out = []
t.postorder(root.id).each do |node|
  out << node.id
end
puts " #{out.join(' ')}"

Measured memory_bytes: 6104
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int>a(n+1),b(n+1),c(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
    a[i]--;
  }
  for(int i=0;i<n;i++)cin>>b[i];
  for(int i=0;i<n-1;i++)cin>>c[i];
  int ans=0;
  for(int i=0;i<n;i++){
   ans+=b[a[i]];
    if(a[i]+1==a[i+1])ans+=c[a[i]];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
function main(input) {
    var r = Number(input);
    var areaOfCircle = (Math.PI * r * r);
    var circumference = (2 * Math.PI * r);
    output = [areaOfCircle.toFixed(6),circumference.toFixed(6)].join(' ');
    console.log(output);
}

process.stdin.resume();
var input = '';  
process.stdin.setEncoding('utf-8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  main(input);
});

Measured memory_bytes: 15584
/* Author : Aaryan Srivastava ^__^ */ 
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second   
#define rep(i,n) for(int i = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define setval(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define trav(x , a) for(auto &x : a)
#define sz(a) ((int)a.size())
typedef long long ll ; 
#define int ll
using namespace std;

const int N = 3e5 + 5 ;
const int mod = 1e9 + 7 ;
const ll inf = 1e18 ;
const int SZ = 101 ;
const long double eps = 1e-9 ;

using namespace __gnu_pbds;
using ordered_set =  tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ;

typedef pair<int, int> pii; 
typedef pair<int , pii> ipii ;
typedef pair<pii , int> piii ; 
typedef unsigned long long ull ;
typedef long double ld;

ll po(ll x,ll y,ll p = mod) {ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}

void solve()
{
    int a[5] , ans = -1;
    rep(i , 5){
        cin >> a[i];
        if(!a[i]) ans = i + 1;
    }
    cout << ans ;
}
     
int32_t main(int32_t argc, char *argv[])
{
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
    //cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case #" << t << ": " ;
        solve();
        cout << "\n" ;
    }
    return 0;
}


Measured memory_bytes: 3596
#include <iostream>

using namespace std;
int isPrime(int n);
int main(){
  int memo[1000000]={},i;
  for(i=2;i<1000000;i++){
    memo[i]=isPrime(i);
  }
  int a,d,n,o;
  cin >> a >> d >> n;
  while(a!=0){
    o=0;
    i=0;
    while(o!=n){
      o+=memo[a+d*i];
      i++;
    }
    cout << a+d*(i-1) << endl;
    cin >> a >> d >> n;
  }
  return 0;
}
int isPrime(int n){
  int i;
  for(i=2;i*i<=n;i++) if(n%i==0) return 0;
  return 1;
}

Measured memory_bytes: 5072
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# 価値 x 以上の握手を全て行うとする
# 握手回数が決まる。左手ごとに集計できる。

import numpy as np

N,M = map(int,readline().split())
A = np.array(read().split(),np.int64)

A.sort()

def shake_cnt(x):
    # x 以上の握手を全て行うとして、握手の回数を数える
    # 行わない握手を数える
    X = np.searchsorted(A,x-A)
    return N * N - X.sum()

left = 0 # 握手の回数がM以上
right = 10 ** 6 # 握手の回数がM未満
while left + 1 < right:
    x = (left + right) // 2
    if shake_cnt(x) >= M:
        left = x
    else:
        right = x

left,right

# right 以上の握手を全て行ったとして、回数と総和を計算

X = np.searchsorted(A,right-A) # 行わない人数
Acum = np.zeros(N+1,np.int64) # 人数 -> 累積和
Acum[1:] = np.cumsum(A)

shake = N * N - X.sum()
happy = (Acum[-1] - Acum[X]).sum() + (A * (N - X)).sum()

happy += (M - shake) *left
print(happy)

Measured memory_bytes: 18236
#include <bits/stdc++.h>
//#include "Header.h"

#define pi 3.14159265358979323846264

#define ll long long
#define fori(n) for(long long i=0;i<n;i++)
#define forj(n) for(long long j=0;j<n;j++)

#define sp(n) setprecision(n)
#define d7 1000000007
#define mkp make_pair
#define mkt make_tuple

using namespace std;

bool isPrime(long long k){
    if(k<=1){return false;}
    if(k==2){return true;}
    if(k%2==0){return false;}
    long long i = 3;
   while (i*i <= k) {if (k % i == 0) {return false;}i += 2;}
return true;
}

ll binomialCoeff(ll n, ll k){
    ll C[n + 1][k + 1];ll i, j;
    for (i = 0; i <= n; i++){
        for (j = 0; j <= min(i, k); j++){
            if (j == 0 || j == i){C[i][j] = 1;}
            else{C[i][j] = (C[i - 1][j - 1]%d7 + C[i - 1][j]%d7)%d7;}}}
    return C[n][k]%d7;
 }

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

ll srihrg(ll n,ll k,ll m){
    ll ans;
    ans=1;
    fori(k){
        ans=(ans*n)%m;
    }
    return ans;
}

ll kk=1;
void dfsi(vector<bool> &vis, vector<ll> adj1[], ll n, ll start, vector<ll> &pre, vector<ll> &pos){
    vis[start]=true;
    pre[start]=kk;kk++;
    for(ll i: adj1[start]){
        if(!vis[i]){
            vis[i]=true;
            dfsi(vis,adj1,n,i,pre,pos);
        }
    }
    pos[start]=kk;kk++;
}

void bfsi(vector<ll> &dis, vector<ll> adj[], ll s, vector<ll> &parent){
    dis[s]=-1;
    queue<ll> q;
    q.push(s);
    while(!q.empty()){
        ll z=q.front();
        q.pop();
        for(ll v:adj[z]){
            if(dis[v]==0){
            q.push(v);
            dis[v]=-dis[z];
                parent[v]=z;}
        }
    }
}

void make_set(ll v, vector<ll> &parent, vector<ll> &krank) {
    parent[v] = v;
    krank[v] = 0;
}

ll find_set(ll v,vector<ll> &parent, vector<ll> &krank) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v], parent, krank);
}

void union_sets(ll a, ll b,vector<ll> &parent, vector<ll> &krank) {
    a = find_set(a,parent,krank);
    b = find_set(b,parent,krank);
    if (a != b) {
        if (krank[a] < krank[b])
            swap(a, b);
        parent[b] = a;
        if (krank[a] == krank[b])
            krank[a]++;
    }
}

void dijkstra(ll s, vector<ll> &dist, vector<ll> &parent, ll n, vector<pair<ll,ll>> adj[]){
    dist[s]=0;
    vector<bool> u(n,false);
    fori(n){
        ll v=-1;
        forj(n){
            if(!u[j] &&(v==-1||(dist[j]<dist[v]))) v=j;
        }
        if(dist[v]==d7) break;
        u[v]=true;
        for(auto j:adj[v]){
            ll a,b;
            a=j.first;
            b=j.second;
            if(dist[v]+b<dist[a]){
                dist[a]=dist[v]+b;
                parent[a]=v;
            }
        }
    }
}

int main(int argc, const char * argv[]) {
 //cout<<"Om\n";
 //Praise to Lord
 //make cin/cout faster
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);cout.tie(NULL);
// code now
   
    ll n;
    cin>>n;
    cout<<((n%2==0)? (n/2):(n/2)+1);
        
//code ends
    return 0;
}


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

using namespace std;

const int N = 200010;

int n, a[N], b[N], fa[N], fb[N], st[N], en[N], ans[N];

int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    ++fa[a[i]];
  }
  for (int i = 1; i <= n; ++i) {
    scanf("%d", b + i);
    ++fb[b[i]];
  }
  for (int i = 1; i <= n; ++i) {
    if (fa[i] + fb[i] > n) {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  for (int i = 1; i <= n; ++i) {
    st[i] = n + 69, en[i] = -69;
  }
  for (int i = 1; i <= n;) {
    int x = a[i];
    st[x] = i;
    while (i <= n and a[i] == x) ++i;
    en[x] = i - 1;
  }
  set <int> alive;
  for (int i = 1; i <= n; ++i) {
    alive.emplace(i);
  }
  int badValue = -1;
  vector <pair <int, int>> done;
  for (int i = 1; i <= n; ++i) {
    if (!fb[i]) continue;
    while (fb[i] > 0) {
      if (*alive.begin() < st[i]) {
        int at = *alive.begin();
        alive.erase(alive.begin());
        ans[at] = i;
        done.emplace_back(at, i);
      } else {
        auto it = alive.upper_bound(en[i]);
        if (it == alive.end()) {
          badValue = i;
          break;
        } else { 
          int at = *it;
          alive.erase(at);
          ans[at] = i;
          done.emplace_back(at, i);
        }
      }
      --fb[i];
    }
  }
  if (~badValue) {
    for (auto it : done) {
      if (alive.empty()) break;
      if (a[it.first] != badValue and it.second != badValue) {
        int at = *alive.begin(); 
        alive.erase(alive.begin());
        ans[it.first] = badValue;
        ans[at] = it.second;
      }
    }
  }
  for (int i = 1; i <= n; ++i) printf("%d ", ans[i]);
  cout << '\n';
  return 0;
}

// 1 1 1 2 2 4 5
// 1 1 1 2 6 7 8
// 6 7 8 1 1 1 2
// 1 1 1 2 6 7 8


Measured memory_bytes: 18564
N, M = map(int, input().split())

arr = []

for i in range(N):
    thisArr = input().split()
    appArr = []
    for i in range(len(thisArr)):
        appArr.append(int(thisArr[i]))
    arr.append(appArr)


rankArr = [[] for _ in range(8)]
for i in range(N):
    rankArr[0].append(arr[i][0]*1 + arr[i][1]*1 + arr[i][2]*1)
    rankArr[1].append(arr[i][0]*1 + arr[i][1]*1 + arr[i][2]*(-1))
    rankArr[2].append(arr[i][0]*1 + arr[i][1]*(-1) + arr[i][2]*1)
    rankArr[3].append(arr[i][0]*1 + arr[i][1]*(-1) + arr[i][2]*(-1))
    rankArr[4].append(arr[i][0]*(-1) + arr[i][1]*1 + arr[i][2]*1)
    rankArr[5].append(arr[i][0]*(-1) + arr[i][1]*1 + arr[i][2]*(-1))
    rankArr[6].append(arr[i][0]*(-1) + arr[i][1]*(-1) + arr[i][2]*1)
    rankArr[7].append(arr[i][0]*(-1) + arr[i][1]*(-1) + arr[i][2]*(-1))

sums = [0 for _ in range(8)]
for i in range(8):
    rankArr[i] = sorted(rankArr[i], reverse=True)
    for j in range(M):
        sums[i] += rankArr[i][j]

# print(rankArr)
print(sorted(sums, reverse=True)[0])


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

ll f(ll b, ll n) {
	return n < b ? n : f(b, n / b) + n % b;
}

int main()
{
	ll n, s;
	cin >> n >> s;
	if (s > n) {
		cout << -1 << endl;
		return 0;
	}
	else if (s == n) {
		cout << n + 1 << endl;
		return 0;
	}
	for (ll b = 2; b * b <= n; b++) {
		if (f(b, n) == s) {
			cout << b << endl;
			return 0;
		}
	}
	for (ll u = ceil(sqrt(n)); u >= 1; u--) {
		if ((n - s + u) % u == 0) {
			ll b = (n - s + u) / u;
			if (b >= 2 && f(b, n) == s) {
				cout << b << endl;
				return 0;
			}
		}
	}
	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int H, W;
	int h, w;

	while (1) {
		scanf("%d%d", &H, &W);
		if (H == 0 && W == 0) break;
		
		for (w = 0; w < W; w++) putchar('#');
		putchar('\n');

		for (h = 2; h < H; h++) {
			putchar('#');
			for (w = 2; w < W; w++) putchar('.');
			putchar('#');
			putchar('\n');
		}

		for (w = 0; w < W; w++) putchar('#');
		putchar('\n');

		putchar('\n');
	}
	return 0;
}



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

using namespace std;
typedef long long ll;
#define INF (ll)1e17 + 177
vector<ll> a((ll)1e5 + 5), b((ll)1e5 + 5), c((ll)1e5 + 5);
vector<vector<ll>> dp((ll)1e5 + 5, vector<ll>(3, INF));
ll func(ll n, int index)
{
    if (n == 0)
    {
        return 0;
    }
    if (dp[n][index] != INF)
    {
        return dp[n][index];
    }
    else
    {
        ll t0 = a[n] + func(n - 1, 0); //  cost of taking a as the task here.
        ll t1 = b[n] + func(n - 1, 1); // cost of taking b as the task here.
        ll t2 = c[n] + func(n - 1, 2); // cost of taking c as the task here
        dp[n][0] = max(t1, t2);
        dp[n][1] = max(t2, t0);
        dp[n][2] = max(t0, t1);
        
        return dp[n][index];
    }
}

int main()
{
    ll n;
    cin >> n;
    dp[0] = vector<ll>((ll)1e5 + 55, INF);
    dp[1] = vector<ll>((ll)1e5 + 55, INF);
    dp[2] = vector<ll>((ll)1e5 + 55, INF);
    for (int x = 1; x <= n; x++)
    {
        cin >> a[x] >> b[x] >> c[x];
    }
    dp[0][0] = 0;
    dp[0][2] = 0;
    dp[0][1] = 0;
    dp[n][0] = func(n, 0);
    dp[n][1] = func(n, 1);
    dp[n][2] = func(n, 2);
    cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << endl;
}

Measured memory_bytes: 16640
using System;
using System.Collections.Generic;
using System.Linq;

namespace Contest
{
    class Program
    {
        static void Main()
        {
            string s = Console.ReadLine();
            long n = int.Parse(Console.ReadLine());

            var list = new List<long>();
            var old = ' ';
            int cnt = 0;
            for (int i = 0; i < s.Length; i++)
            {
                if(old != s[i] && cnt > 0)
                {
                    list.Add(cnt);
                    cnt = 0;
                }
                cnt++;
                old = s[i];

            }
            if (cnt != 0) list.Add(cnt);

            if(n == 1)
            {
                Console.WriteLine(list.Sum(e => e / 2));
            }
            else
            {
                if(list.Count == 1)
                {
                    Console.WriteLine(list.First() * n / 2);
                }
                else if (s.First() == s.Last())
                {
                    var fo = list.Take(list.Count - 1).Sum(e => e / 2);
                    var lfo = list.Skip(1).Take(list.Count - 2).Sum(e => e / 2) + (list.First() + list.Last()) / 2;
                    var l = list.Last() / 2;
                    Console.WriteLine(fo + lfo * (n - 1) + l);
                }
                else
                {
                    Console.WriteLine(list.Sum(e => e / 2) * n);
                }
            }
            Console.ReadLine();
        }
    }
}


Measured memory_bytes: 13396