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

using namespace std;

typedef long long ll;

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

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

// auto mod int
// ref. https://github.com/atcoder-live/library/blob/master/mint.cpp
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
struct mint {
  ll x; // typedef long long ll;
  ll MOD;
  mint(ll x, ll MOD):x((x%MOD+MOD)%MOD), MOD(MOD) {}
  mint operator-() const { return mint(-x, MOD);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return mint(1, MOD);
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

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

ll solve_for_two(const int N, const string S) {
    ll acc = 0;
    for (int i = 0; i < N; i++) {
        int d = S[i] - '0';
        if (d % 2 == 0) {
            acc += i + 1;
        }
    }
    return acc;
}

ll solve_for_five(const int N, const string S) {
    ll acc = 0;
    for (int i = 0; i < N; i++) {
        int d = S[i] - '0';
        if (d % 5 == 0) {
            acc += i + 1;
        }
    }
    return acc;
}

ll solve_for_others(const int N, const int P, const string S) {
    // {remain, nums}
    map<ll, ll> m;
    ll acc = 0;
    mint x(0, P);
    m[0]++;
    for (int i = 0; i < N; i++) {
        int d = S[i] - '0';
        x = (x + mint(d, P) * mint(10, P).pow(i));
        acc += m[x.x];
        m[x.x]++;
        // printf("i: %d, acc: %d, x: %lld\n", i, acc, x.x);
    }
    return acc;
}

int main(void) {
    int N, P;
    string S;
    cin >> N >> P >> S;

    if (P == 2) {
        cout << solve_for_two(N, S) << endl;
    } else if (P == 5) {
        cout << solve_for_five(N, S) << endl;
    } else {
        reverse(S.begin(), S.end());
        cout << solve_for_others(N, P, S) << endl;
    }

    return 0;
}


Measured memory_bytes: 1284
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define st(vvv) sort(vvv.begin(),vvv.end())
#define rvs(vvv) reverse(vvv.begin(),vvv.end())
int inf = 1000000007;

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> data(n+1);
	ff(i, 1, n + 1) {
		cin >> data.at(i);
	}
	int ans = 0;
	int cur = 1;
	int goal = 0;
	while (goal==0) {
		ans++;
		cur = data.at(cur);
		if (cur == 2)goal++;
		if (ans > n) {
			cout << -1 << endl;
			return 0;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 768
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	var a []int64
	for i := 0; i < n; i++ {
		var s int64
		fmt.Scan(&s)
		a = append(a, s)
	}
	sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })
	if a[0] == 0 {
		fmt.Println(0)
		return
	}
	ans := int64(1)
	for _, v := range a {
		if v > int64(1e18) / ans {
			fmt.Println("-1")
			return
		}
		ans *= v
	}
	fmt.Print(ans)
}


Measured memory_bytes: 7480
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
const ll mod = 1000000007;

const int D = 60;
const int MAX_N = 200005;
int to[D][MAX_N];

int main(){
    ll n, k;
    cin >> n >> k;
    
    rep(i, n) {
        cin >> to[0][i];
        to[0][i]--;
    }
    rep(i, D-1) rep(j, n) {
        to[i+1][j] = to[i][to[i][j]];
    }
    int ans = 0;
    

    for (int i=D-1; i>=0; i--) {
        ll l = 1LL<<i;
        
        if (l&k) ans = to[i][ans];
    }
    
    
    
    cout << ans+1 << endl;
    return 0;
}


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

const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

#define ALL(x) (x).begin(), (x).end()

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

int ans[200000];
vector<int> dp;
set<pair<int, int>> spii;
vector<int> nums;
void dfs(int idx)
{
    auto a = lower_bound(ALL(dp), nums[idx]);
    int temp = *a;
    *a = nums[idx];
    ans[idx] = lower_bound(ALL(dp), INF) - dp.begin();
    auto pii = spii.lower_bound({ idx, 0 });
    while ((pii->first) == idx) {
        pair<int, int> p = *pii;
        pii++;
        spii.erase({ p.first, p.second });
        spii.erase({ p.second, p.first });
        dfs(p.second);
    }
    *a = temp;
}

int main()
{
    dp.resize(200001, INF);
    int n;
    cin >> n;
    nums.resize(n);
    REP(i, n)
    cin >> nums[i];

    REP(i, n - 1)
    {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        spii.insert({ u, v });
        spii.insert({ v, u });
    }
    spii.insert({ n + 1, n + 1 });
    dfs(0);
    REP(i, n)
    {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 41352
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N, K;
  cin >> N >> K;
  ll a;
  map<int, int> m;
  for (int i = 0; i < N; i++) {
    cin >> a;
    m[a]++;
  }
  vector<pair<int, int>> ans_vec;
  for (auto p : m) {
    ans_vec.emplace_back(p.second, p.first);
  }
  sort(ans_vec.begin(), ans_vec.end());
  ll ans = 0;
  if ((ll)ans_vec.size() - K <= 0) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < (ll)ans_vec.size() - K; i++) {
    ans += ans_vec[i].first;
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
    int n,x,y;
    cin >> n >> x >> y;
    int ans[n-1];
    rep(i,n-1){
        ans[i] = 0;
    }
    for(int i=1;i<n;i++){
        for(int j=i+1;j<=n;j++){
            int l1 = abs(x-i) + abs(y-j);
            int l2 = j-i-1;
            ans[min(l1,l2)]+=1;
        }
    }
    rep(i,n-1){
        cout<<ans[i]<<endl;
    }
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> d(n + 1);
  vector<bool> b(n + 1, false);
  for (int i = 1; i <= n; ++i) cin >> d[i];
  int cur = 1, cnt = 0;
  while (!b[cur]) {
    b[cur] = true;
    cur = d[cur];
    cnt++;
    if (cur == 2) {
      cout << cnt << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(){
	
	int syako[11],n,i;
	i=0;
	while(0<=scanf("%d",&n)){
		if(n==0){
			printf("%d\n",syako[i]);
			i--;
		}else{
			i++;
			syako[i]=n;
		}
		
	}
	return 0;
}

Measured memory_bytes: 0
s = input()
while len(s) > 4:
    if s[-5:] == 'dream' or s[-5:] == 'erase':
        s = s[:-5]
        continue
    elif s[-7:] == 'dreamer':
        s = s[:-7]
        continue
    elif s[-6:] == 'eraser':
        s = s[:-6]
        continue
    else:
        break
if len(s) > 0:
    print('NO')
else:
    print('YES')

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

long long L, R, minx = (1LL << 60);

int main() {
	cin >> L >> R;
	for (long long i = L; i <= min(L + 7000, R); i++) {
		for (long long j = i + 1; j <= min(L + 7000, R); j++) {
			minx = min(minx, (i * j) % 2019LL);
		}
	}
	cout << minx << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int A, B; 
  cin >> A >> B;

  int N = 100000;
  vector<int> sum(N, 0);
  REP(i, N){
    string s = to_string(i);
    string t = s;
    reverse(ALL(t));
    if(s == t) sum[i]++;
  }

  REP(i, N-1) sum[i+1] += sum[i];

  cout << sum[B]-sum[A-1] << "\n";


  return 0;
}

Measured memory_bytes: 1024
#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
    #define ull unsigned long long
    #define ld long double
    #define ff first
    #define ss second
    #define null NULL
    #define MAX 1000000000  // 1x10^9
    #define all(c) (c).begin(),(c).end()
    #define eb emplace_back
    #define pb push_back
    #define pf push_front
    #define lb lower_bound   //used for sortted 
    #define ub upper_bound 
    #define m_p make_pair      
    #define mod 1000000007
    #define For(i,n) for(int i=(0);i<(n);++i)
    #define FOR(i,a,b) for(int i=(a);i<=(b);++i)
	#define ROF(i,a,b) for(int i=(a);i>=(b);--i)
    #define in(s3) inserter((s3), (s3).begin())  //	set_union(all(s1),all(s2),in(s3));
    typedef vector<ll> vl;
    typedef vector< vl > vvl;
    typedef pair< ll,ll> pll;
    typedef map< ll,ll> mll;
    
    //  A-65 Z-90 a-97 z-122   A-a = 32   Z-A = z-a = 35
    //	v.push_back(make_pair(min(2 * k[i], l[i]) - min(k[i], l[i]), i));      //int pos = v[i].second;
    //	floor(log10(no) + 1);                   //	to_string(no).length();             ----- length of a number
	//  llabs - long long of abs
	//  labs -long of abs
	//  sqrtf - sq root of float
	//  sqrtl - sq of long double    ( cout << fixed << setprecision(12) << sqrtl(val2) << endl; )
	//  it = find (all(vec), e);     if(it != vec.end());       it - vec.begin();
   	//	size_t found = str.find(str1);    if(found != string::npos); 	 cout<<found;
    	 
	/*	
		1. ^ is XOR and is used to to check odd occurance of number as a number XORed with itself results in zero so all even	occurrances result in zero.
		2.   & is used to check even or odd. (x & 1) ? printf("Odd") : printf("Even"); 
		3.   left shift(<<) - *         right shift(>>) - /
		4.   int a[] = { 1, 7, 2, 4, 8, 3 }; 
    		 int l = sizeof(a) / sizeof(a[0]); 
    		 sort(a, a + l);  reverse(a, a + l); accumulate(a, a + l, 0); *max_element(a, a + l);
	*/
	
	string to_string(char& x) {      
		string s(1,x);
		return s;    
	} 
	struct obj {
		ull val1;
		ull val2;
		ull pos;
	};
	bool cmp(const pair<int,int>&a,const pair<int,int>&b) {
		if(a.first==b.first)
		return a.second<b.second;
		return a.first<b.first;
	}

	int main() {
		ld n,x,t;
		cin>>n>>x>>t;
		ull sum=ceil(n/x)*t;
		cout<<sum;
		return 0;
	}





Measured memory_bytes: 3692
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    int A[100000];
    cin >> N;

    for(int i=0; i<N; i++) cin >> A[i];
    int ans = 1;
    int state = 0;
    for(int i=1; i<N; i++){
        if(A[i] > A[i-1]){
            if(state == 0) state = 1;
            else if(state == -1) {
                ans++;
                state = 0;
            }
        }else if(A[i] < A[i-1]){
            if(state == 0) state = -1;
            else if(state == 1){
                ans++;
                state = 0;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
n = int(input())
A = list(map(int, input().split()))
if n % 2 == 0:
	N = int(n / 2)
	for i in range(N):
		print(A[-1 - 2 * i], end = " ")
	for i in range(N - 1):
		print(A[2 * i], end = " ")
	print(A[-2])

else:
	N = int(n // 2)
	for i in range(N + 1):
		print(A[-1 - 2 * i], end = " ")
	for i in range(N - 1):
		print(A[1 + 2 * i], end = " ")
	if n == 1:
		pass
	else:
		print(A[-2])

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

namespace abc103_c
{
	class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
			Console.WriteLine(x.Sum() - n);
		}
	}
}

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

int main(){
  string n;
  while(1){
    cin >> n;
    if(n == "0000") break;
    int num[4];
    for(int i = 0;i < 4;i++) num[i] = n[i] - '0';

    if(n == "6174"){
      cout << 0 << endl;
    }else if(num[0] == num[1] && num[1] == num[2] && num[2] == num[3]){
      cout << "NA" << endl;
    }else{


      int cnt = 1;
      int tmpa,tmpb,tmpc;
      while(1){
        tmpa = tmpb = 0;
        sort(num,num+4);
        int tmp = 1;
        for(int i = 0;i < 4;i++){
          tmpa += num[i] * tmp;
          tmp *= 10;
        }
        tmp = 1;
        for(int i = 0;i < 4;i++){
          tmpb += num[3-i] * tmp;
          tmp *= 10;
        }
        tmpc = tmpa - tmpb;
        if(cnt == 10) break;
        if(tmpc == 6174){
          cout << cnt << endl;
          break;
        }
        for(int i = 0;i < 4;i++){
          num[i] = tmpc % 10 ;
          tmpc /= 10;
        }
        cnt++;
      }
    }
  }

  return 0;
}






Measured memory_bytes: 3144
import sys, math

def input():
    return sys.stdin.readline()[:-1]

def main():
    s = input()
    for k in range(1,len(s)):
        if s[k-1] == s[k]:
            print(k,k+1)
            exit(0)
    for k in range(1,len(s)-1):
        if s[k-1] == s[k+1]:
            print(k,k+2)
            exit(0)
    print("-1 -1")
if __name__ == '__main__':
    main()


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;

#define con continue
#define pb push_back
#define fi first
#define se second
#define INF 1000000000000000000
#define all(vl) vl.begin(),vl.end()
#define m_p make_pair 
#define sz(a) sizeof(a)
#define forn(mp,it) for(it = mp.begin();it!=mp.end();it++)
#define FOR(i,a,n) for(int i=a;i<n;i++) 
#define FORE(i,a,n) FOR(i,a,n+1)
#define Endl endl
#define eNdl endl
#define enDl endl
#define endL endl

int main()
{
	ll n;
	cin>>n;
	vector<ll> vl(n);
	map<ll,ll> mp;
	FOR(i,0,n)
	{
		cin>>vl[i];
		mp[vl[i]]++;
	}
	ll ans = 0;
	itll it;
	forn(mp,it)
	{
		ll cnt = it->se;
		ans+=(cnt*(cnt-1))/2;
	}
	FOR(i,0,n)
	{
		cout<<ans-mp[vl[i]]+1<<endl;
	}
	return 0;
}


Measured memory_bytes: 12760
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL <<60;
const long long Mo=1000000007;
     
long long gcn(long long x,long long y){
  if(x%y==0){
    return y;  
  }
  else{
    return gcn(y,x%y);
  }
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(void){
  long long tmp;
  long long n,k;
  long long i,j;
  long long res=0;

  cin>>n>>k;
  vector<pair<long,long>> x(n);

  for(i=0;i<n;i++){
    cin>>x[i].first>>x[i].second;
    //cout<<x[i].first<<" "<<x[i].second<<endl;
  }
  sort(x.begin(),x.end());
                 
  j=0;
  for(i=0;j<k;i++){
    res=x[i].first;
    j+=x[i].second;
  }
  
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 4720
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr_inv(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define rep(i,n) repr(i,0,n)
#define MOD 1000000007
#define PI 3.1415926535
using namespace std;
vector<vector<int>> Warshall_Floyd(vector<vector<int>>cost, int n)
{
	vector<vector<int>> dist; //dist[i][j]はiからjへの最短コスト

							  //初期化
	dist=cost;

	//最短コストの計算
	for(int k=0; k<n; k++){
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				if(dist[i][j]>dist[i][k]+dist[k][j]){
					dist[i][j]=dist[i][k]+dist[k][j];
				}
			}
		}
	}
	return dist;
}

int main(void)
{
	int n, m, rnum;
	
	long long ans=1e9, temp;

	cin>>n>>m>>rnum;

	vector<int> r(rnum);

	rep(i, rnum){
		cin>>r[i]; r[i]--;
	}

	vector<vector<int>> cost(n, vector<int>(n, 1e9)), dist;

	rep(i, m){
		int a, b, c;
		cin>>a>>b>>c;
		cost[a-1][b-1]=c; cost[b-1][a-1]=c;
	}
	rep(i, n){
		cost[i][i]=0;
	}

	dist=Warshall_Floyd(cost, n);

	sort(r.begin(), r.end());

	do{
		temp=0;
		rep(i, rnum-1) temp+=dist[r[i]][r[i+1]];
		if(ans>temp) ans=temp;
	} while(next_permutation(r.begin(), r.end()));

	cout<<ans<<endl;
}

Measured memory_bytes: 768
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	ls := make([]int, n)
	for i := range ls {
		fmt.Scan(&ls[i])
	}

	maxIdx := 0
	amount := 0
	maxL := ls[maxIdx]
	for i := 1; i < n; i++ {
		tmp := ls[i]
		if maxL < tmp {
			amount += maxL

			maxIdx = i
			maxL = tmp
		} else {
			amount += tmp
		}
	}

	if maxL < amount {
		fmt.Print("Yes")
	} else {
		fmt.Print("No")
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
//#include <unordered_map>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORD(i, a, b) for(int i = (a-1); i >= (b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
typedef long long int ll;
using namespace std;
ll mod=1000000007;
//ll mod=67280421310721;
//ll mod=998244353;
ll INF=1e18;
ll po(ll a,ll b)
{
	ll re=1;
	while(b)
	{
		if(b%2==1)
		{
			re=(re*a);
			re%=mod;
		}
		a=(a*a);
		a%=mod;
		b>>=1;
	}
	return re;
}
ll fac[2000005];
ll ifac[2000005];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
//	cin>>test;
	while(test--)
	{
		fac[0]=1;
		ifac[0]=1;
		FOR(i,1,2000005)
		{
			fac[i]=(i*fac[i-1])%mod;
			ifac[i]=po(fac[i],mod-2);
		}
		int k,n;
		string s;
		cin>>k>>s;
		n=s.size();
		ll ans=po(26,k+n),o;
		FOR(i,0,n)
		{
			o=(((((fac[n+k]*ifac[n+k-i])%mod)*ifac[i])%mod)*po(25,n+k-i))%mod;
			ans+=(mod-o);
		}
		cout<<ans%mod;
	}
	return 0;
}

Measured memory_bytes: 35516
#include <bits/stdc++.h>
//#pragma GCC optimize "-O3"
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned short us;
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll infll=(1ull<<63)-1,mod=1e9+7;
const int inf=(1ull<<31)-1;
int n,t=1;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);cout.precision(18);
	cin>>n;
	for (int i=0,y;i<n;i++){
		cin>>y;
		if (y==t)
			t++;
	}
	if (t==1)
		cout<<"-1";
	else 
		cout<<n-t+1;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    int n; cin >> n;
    vector<string> s, t;
    for(int i=1; i<=n; i++){
        string a; cin >> a;
        if(i%2==1) s.push_back(a);
        else t.push_back(a);
    }

    if(n%2==0){
        for(int i=t.size()-1; i>=0; i--) cout << t[i] + " ";
        rep(i, s.size()) cout << s[i] + " ";
    }else{
        for(int i=s.size()-1; i>=0; i--) cout << s[i] + " ";
        rep(i, t.size()) cout << t[i] + " ";    
    }
    cout << ln;
}

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

N = int(input())
K = int(input())
x = list(map(int, input().split()))

ans = 0
tmp_N = 0
tmp_K = 0
min_xi = 0

for xi in x:
    tmp_N = abs(xi - 0)
    tmp_K = abs(xi - K)
    min_xi = min(tmp_N, tmp_K)
    ans = ans + (min_xi * 2)

print(ans)

Measured memory_bytes: 8960
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s,s1;
    cin>>s>>s1;
    int x=s.length(),c=0;
    for(int i=0;i<x;i++)
    if(s[i]!=s1[i])
    c++;
    cout<<c;
}

Measured memory_bytes: 3916
def main():
    a = int(input())
    b = int(input())
    c = int(input())
    tt = int(input())
    total = 0

    for yen500 in range(a+1):
        for yen100 in range(b+1):
            for yen50 in range(c+1):
                if yen500 * 500 + yen100 * 100 + yen50 * 50 == tt:
                    total += 1

    print(total)

main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

int x,y,z;
int main(){
    cin >> x >> y >> z;
    int ans = (x - z) / (y + z);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

const int N(1e5 + 9);
typedef long long ll;

int n, m;
ll ans;
ll a[N], f[N];

int main()
{
	cin>>n;
	for (int i=1;i<=n;i++)
	{
		cin>>a[i];
		ans += abs(a[i]);
		if (a[i] < 0) m++;
	}
	if (m & 1)
	{
		ll Min = 1e10;
		for (int i=1;i<=n;i++)
		{
			if (abs(a[i]) < Min)
			{
				Min = abs(a[i]);
			}
		}
		cout<<ans - 2 * Min;
	}
	else
	{
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

import static java.lang.Math.*;

public class Main {
    static final int INF = 2147483647;
    static final int LAZYRANGE = 16;
    static int[] D;
    static int[] lazy;
    static int a_n;
    static int t_n;
    static int c = 0;


    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);

        a_n = Integer.parseInt(scanner.next());
        int q = Integer.parseInt(scanner.next());

       initRUQ(a_n);



        for(int i = 0; i < q; i++){
            int com = Integer.parseInt(scanner.next());

            if(com == 0){
                int s = Integer.parseInt(scanner.next());
                int t = Integer.parseInt(scanner.next());
                int x = Integer.parseInt(scanner.next());

                update(s, t, x);


            }

            if(com == 1){
                int k = Integer.parseInt(scanner.next());
                System.out.println(find(k));
            }


        }


    }

    public static void initRUQ(int a_n){

        D = new int[a_n];
        lazy = new int[a_n / LAZYRANGE + 1];

        for (int i = 0; i < a_n; i++){
            D[i] = INF;
        }

        for(int i = 0; i < lazy.length; i++){
            lazy[i] = INF;
        }

    }

    public static void update(int s, int t, int x){

        while (s <= t){

            if(s == 0 || s % LAZYRANGE != 0){
                if(lazy[s / LAZYRANGE] != INF){
                    propagate(s);
                }
                D[s] = x;
                s++;
            }else if(s % LAZYRANGE == 0){
                if(s + LAZYRANGE <= t){
                    lazy[s / LAZYRANGE] = x;
                    s += LAZYRANGE;
                }else {
                    if(lazy[s / LAZYRANGE] != INF){
                        propagate(s);
                    }
                    D[s] = x;
                    s++;
                }
            }
        }




    }

    public static int find(int k){
        if(lazy[k / LAZYRANGE] != INF){
            propagate(k);
        }
        return D[k];
    }

    public static void propagate(int k){
        for(int i = 0; i < LAZYRANGE; i++){
            D[k / LAZYRANGE * LAZYRANGE + i] = lazy[k / LAZYRANGE];
        }
        lazy[k / LAZYRANGE] = INF;
    }

    public static int query(int a, int b, int k, int l, int r){
        if(r <= a || b <= l) return INF;
        if(a <= l && r <= b) return D[k];


        int vl = query(a, b, k * 2 + 1, l, (l + r) / 2 );
        int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
        return min(vl, vr);

    }

    public static int findMin(int a, int b){
        return query(a, b + 1, 0, 0, t_n);
    }
}


Measured memory_bytes: 71104
#include<bits/stdc++.h>
using namespace std;
int n, m, sum, w[110];
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &w[i]);
        sum += w[i];
    }
    scanf("%d", &m);
    for (int i = 0; i < m; ++i) {
    	int p, x;
        scanf("%d%d", &p, &x);
        printf("%d\n", sum - w[p] + x);
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
#include <queue>
#define MOD 1000000007
#define REP(i,num)for(int i=0;i<(num);++i)
#define ll long long

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int N,K;
    cin>>N>>K;
    ll ans = 0;
    ans += pow(N / K, 3);
    if(K%2==0){
        ll temp=0;
        REP(i,N+1){
            if(i%K==K/2)temp++;
        }
        ans+=temp*temp*temp;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>

using namespace std;

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

  cin>>N;
  int a[N];
  for(int i=0;i<N;i++)
    cin>>a[i];

  cout<<endl;
  sort(a,a+N);

  for(int i=0;i<N;){
    int setn=a[i];
    int cnt=0;
    for(int j=i;a[j]==setn;j++)
      cnt++;
    
    if(cnt>setn)
      ans+=cnt-setn;
    else if(cnt<setn)
      ans+=cnt;

    i+=cnt;
  }

  cout<<ans<<endl;
  
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  string ans = "Yes";
  int sum = 0;
  int X = N;
  
  for(int i = 0; i < 9; i++){
    sum += X % 10;
    X /= 10;
  }
  
  if( N % sum != 0) {
    ans = "No";
  } 
  
  cout << ans << endl;
  
  return 0;
}

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

typedef long long ll;

ll merge(vector<int>& nums, int l, int m, int r)
{
    vector<int> left(m - l + 1);
    vector<int> right(r - m + 1);
    for (int i = 0; i < m - l; i++) {
        left[i] = nums[l + i];
    }
    left.back() = numeric_limits<int>::max();
    for (int i = 0; i < r - m; i++) {
        right[i] = nums[m + i];
    }
    right.back() = numeric_limits<int>::max();
    ll ans = 0;
    int i = 0;
    int j = 0;
    for (int k = l; k < r; k++) {
        if (left[i] <= right[j]) {
            nums[k] = left[i++];
        } else {
            nums[k] = right[j++];
            ans += m - l - i;
        }
    }
    return ans;
}

ll mergeSort(vector<int>& nums, int l, int r)
{
    if (r - l <= 1) {
        return 0;
    }
    int m = l + (r - l) / 2;
    ll ans = 0;
    ans += mergeSort(nums, l, m);
    ans += mergeSort(nums, m, r);
    ans += merge(nums, l, m, r);
    return ans;
}

int main()
{
    int n;
    cin >> n;
    vector<int> nums(n);
    for (int i = 0; i < n; i++) {
        cin >> nums[i];
    }
    ll ans = mergeSort(nums, 0, nums.size());
    cout << ans << endl;
}


Measured memory_bytes: 4396
import java.util.Scanner;
import java.lang.Math;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int h = scanner.nextInt();
        int m = scanner.nextInt();

        final double SHORT_HAND_ANGLE_PER_MINUTE = 0.5;
        final double LONG_HAND_ANGLE_PER_MINUTE = 6;

        double angleHour = (h * 60 + m) * SHORT_HAND_ANGLE_PER_MINUTE;
        double angleMinute = m * LONG_HAND_ANGLE_PER_MINUTE;

        double eggplantAngle = 0;
        if(angleHour <= angleMinute){
            eggplantAngle = angleMinute - angleHour;
        }else{
            eggplantAngle = angleHour - angleMinute;
        }

        if(eggplantAngle > 180){
            eggplantAngle = 360 - eggplantAngle;
        }

        double radian = Math.toRadians(eggplantAngle);

        double c = Math.sqrt(Math.pow(a,2) + Math.pow(b,2) - 2 * a * b * Math.cos(radian));
        System.out.println(c);
    }
}


Measured memory_bytes: 35820
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i < (n) ; i ++ )
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using vin=vector<int>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;


int main() {
  string s;
  cin>>s;
  map<char,int> m;
  rep(i,4){
   m[s[i]]++; 
  }
  bool ans=true;
  for(auto v:m){
    if(v.second!=2) ans=false;
  }
  if(ans) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ar array

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const int maxn = 105, mod = 1e9 + 7;

int f[maxn][maxn][505], a[maxn];
int N, X, l[maxn];

signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  #endif // LOCAL
  cin >> N >> X;
  for(int i = 1; i <= N; ++i)
    cin >> l[i];
  sort(l + 1, l + 1 + N, greater<int>());
  function<void(int &, int)>add = [&](int & x, int y)
  {
    x += y;
    if(x >= mod) x -= mod;
    if(x < 0) x += mod;
  };
  f[1][1][l[1]] = 1;
  for(int i = 2; i <= N; ++i){
    for(int j = 1; j <= i; ++j){
      for(int k = j * l[i - 1]; k <= X; ++k){
        int v = f[i - 1][j][k];
        add(f[i][j + 1][k + l[i]], 1ll * (j + 1) * v % mod);
        add(f[i][j][k], 1ll * (k - j * (l[i] - 1)) * v % mod);
        for(int t = 1; t < l[i]; ++t)
          add(f[i][j][k + l[i] - t], 2ll * j * v % mod);
        if(j > 1){
          for(int t = 2; t <= l[i]; ++t)
            add(f[i][j - 1][k + l[i] - t], 1ll * (j - 1) * (t - 1) % mod * v % mod);
        }
      }
    }
  }
  int res = 0;
  for(int i = 1; i <= N; ++i)
    add(res, f[N][i][X]);
  cout << res;
}


Measured memory_bytes: 14180
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>
#include <iomanip>
#include <tuple>

using namespace std;

int main(){
   int x,a;
   cin>>x>>a;
   if(x<a)cout<<0<<endl;
   else cout<<10<<endl;
}

   


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

using namespace std;
#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

inline void Input_Output () {
	//freopen(".in", "r", stdin);
   //freopen(".out", "w", stdout);
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

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

void add (int &a, int b) {
	a += b;
	if (a >= mod) a -= mod;
}

int mult (int a, int b) {
	return a * (ll)b % mod;
}
#define mat vector < vector < int > >
mat mul (mat &a, mat &b) {
	mat c;
	c.resize(n);
	for (int i = 0; i < n; i ++) {
		c[i].resize(n);
	}

	for (int i = 0; i < n; i ++) {
		for (int j = 0; j < n; j ++) {
			for (int k = 0; k < n; k++)
				add(c[i][j], mult(a[i][k], b[k][j])); 
		}
	}

	return c;
}

int main () {
   	SpeedForce;
   	ll k;
	cin >> n >> k;
	vector < vector < int > > a, res;
	a.resize(n);
	res.resize(n);
	for (int i = 0; i < n; i ++) {
		a[i].resize(n);
		res[i].resize(n);
		for (int j = 0; j < n; j ++) {
			cin >> a[i][j];
		}
		res[i][i] = 1;
	}
	while (k > 0) {
		if (k & 1) {
			res = mul(res, a);
		}
		a = mul(a, a);
		k /= 2;
	}
	
	int ans = 0;
	for (int i = 0; i < n; i ++) {
		for (int j = 0; j < n; j ++)
			add(ans, res[i][j]);
	}

	cout << ans << '\n';
   	return Accepted;
}

// B...a

Measured memory_bytes: 256
#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>

using namespace std;

long long a;

bool result=false;

int main() {
	cin >> a;
	for (int i = 111; i < 1000; i += 111) {
		if (a % 1000 == i) {
			result = true;
			break;
		}

		if (a/10==i) {
			result = true;
			break;
		}
	}
	for (int i = 1000; i < 10000; i += 1000) {
		if (a == i) {
			result = true;
			break;
		}
	}

	if (result == true) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

ll ceil(ll a, ll b) {  // a÷b以上の最小の整数
    if(b == 0) {
        return 0;
    }
    return (a+b-1)/b;
}
 
int main() {
    ll k;
    cin >> k;

    vl a(k);
    rep(i, k) {
        cin >> a[i];
    }

    if(a[k-1] != 2) {
        out(-1);
        re0;
    }

    vl y(k+1);  // y[i+1] : ラウンドi(iは0-index)終了時点での残り人数の最小値
    vl z(k+1);  // z[i+1] : ラウンドi(iは0-index)終了時点での残り人数の最大値
    y[k] = z[k] = 2;
    for(ll i = k-1; i >= 1; i--) {
        y[i] = a[i-1]*ceil(y[i+1], a[i-1]);
        ll m = (z[i+1] + a[i])/a[i-1];
        if((z[i+1] + a[i])%a[i-1] == 0) {
            m--;
        }
        z[i] = a[i-1]*m;
        if(y[i] > z[i]) {
            out(-1);
            re0;
        }
    }

    y[0] = y[1];
    z[0] = z[1] + a[0] - 1;
    
    cout << y[0] << " " << z[0] << endl;
    re0;
}

Measured memory_bytes: 2560
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		String s = sc.next();
		
		out.println(s.substring(0, 4) + " " + s.substring(4, s.length()));
		out.flush();
	}
	
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	
	private byte readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}
	
	private boolean isPrintableChar(int c) {
		return '!' <= c && c <= '~';
	}
	
	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
	}
	
	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}
	
	public String next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		byte b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    ll ans = 0;
    if (K == 0) {
        ans = N * N;
    }
    else {
        for (ll b = K + 1; b <= N; ++b) {
            ll k = b - K;
            ans += k * (N / b);
            ans += std::max(0LL, (N % b) - K + 1);
        }
    }

    cout << ans << endl;
    return 0;
}

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

int main(){
    int n;
    cin>>n;
    vector<int> p(n);
    int count = 0;
    int min_p = 10000000;


    
    for (size_t i = 0; i < n; i++)
    {
        cin>>p.at(i);
        min_p = min(min_p,p.at(i));
        if(p.at(i)==min_p){
            count++;
        }


    }

    cout << count;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof (x))
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define fi first
#define se second
#define kill _z_kill
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define outval(x) cerr<<#x" = "<<x<<endl
#define outv(x) cerr<<#x" = "<<x<<"  "
#define outtag(x) cerr<<"--------------"#x"---------------"<<endl
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
	For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
#define User_Time ((double)clock()/CLOCKS_PER_SEC)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned uint;
typedef long double LD;
typedef vector <int> vi;
typedef pair <int,int> pii;
LL read(){
	LL x=0,f=0;
	char ch=getchar();
	while (!isdigit(ch))
		f=ch=='-',ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
template <class T> void ckmax(T &x,T y){
	if (x<y)
		x=y;
}
template <class T> void ckmin(T &x,T y){
	if (y<x)
		x=y;
}
/*
int Pow(int x,int y){
	int ans=1;
	for (;y;y>>=1,x=(LL)x*x%mod)
		if (y&1)
			ans=(LL)ans*x%mod;
	return ans;
}
void Add(int &x,int y){
	if ((x+=y)>=mod)
		x-=mod;
}
void Del(int &x,int y){
	if ((x-=y)<0)
		x+=mod;
}
int Add(int x){
	return x>=mod?x-mod:x;
}
int Del(int x){
	return x<0?x+mod:x;
}
*/
const int N=1005;
int k,n;
int a[N],baka[N],b[N];
int check_permutation(int L,int R){
	if (R>n||L<1||R-L+1!=k)
		return 0;
	static int vis[N],Time=0;
	Time++;
	For(i,L,R)
		if (vis[b[i]]==Time)
			return 0;
		else
			vis[b[i]]=Time;
	return 1;
}
int checkpos(int *pos){
	int mi=n,mx=-1;
	For(i,1,k)
		ckmin(mi,a[i]),ckmax(mx,a[i]);
	if (mi*2+1<mx)
		return 0;
	if (mi*2>=mx)
		return 1;
	//mi * 2 + 1 == mx
	int mip=n+1,mxp=-1;
	For(i,1,k)
		if (a[i]==mi)
			ckmin(mip,pos[i]);
		else if (a[i]==mx)
			ckmax(mxp,pos[i]);
	return mxp<=mip;
}
int check(int p,int las){
	static int pos[N];
	For(i,1,k)
		pos[i]=p+1;
	if (las==p)
		return checkpos(pos);
	int cut=p;
	{
		vi vis(k+1,0);
		vis[b[cut]]=1;
		while (cut-1>0&&!vis[b[cut-1]])
			cut--,vis[b[cut]]=1;
	}
	if (cut>las+1)
		return 0;
	For(i,cut,p)
		pos[b[i]]=i;
	For(i,1,k)
		if (pos[i]==p+1)
			a[i]--;
	if (checkpos(pos))
		return 1;
	For(i,cut,las){
		a[b[i]]--;
		pos[b[i]]=p+1;
		if (checkpos(pos))
			return 1;
	}
	return 0;
}
int main(){
	k=read(),n=0;
	For(i,1,k)
		a[i]=read(),n+=a[i];
	{
		int mi=n,mx=0;
		For(i,1,k)
			ckmin(mi,a[i]),ckmax(mx,a[i]);
		if (mi*2<mx)
			return puts("-1"),0;
	}
	memset(b,-1,sizeof b);
	int las=0;
	For(i,1,n){
		For(j,1,k)
			if (a[j]){
				For(t,1,k)
					baka[t]=a[t];
				a[j]--,b[i]=j;
				int nextlas=check_permutation(i-k+1,i)?i:las;
				if (check(i,nextlas)){
					las=nextlas;
					For(t,1,k)
						a[t]=baka[t];
					a[j]--;
					break;
				}
				b[i]=-1;
				For(t,1,k)
					a[t]=baka[t];
			}
	}
	For(i,1,n)
		printf("%d ",b[i]);
	puts("");
	return 0;
}

Measured memory_bytes: 3796
n=int(input())
a,w,t,r=0,0,0,0
for i in range(n):
  g=input()
  if g=='AC':
    a+=1
  if g=='WA':
    w+=1
  if g=='TLE':
    t+=1
  if g=='RE':
    r+=1
print('AC x ' + str(a))
print('WA x ' + str(w))
print('TLE x ' + str(t))
print('RE x ' + str(r))

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

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int MOD=1e9+7;
ll INF=1e18;

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

int main(){
    int n; cin>>n;
    vector<int> v(n), ecnt(100010, 0), ocnt(100010, 0);
    for(int i=0; i<n; i++){
        cin>>v[i];
        if(i%2==0) ecnt[v[i]]++;
        else ocnt[v[i]]++;
    }

    int emax=0, enumb, omax=0, onumb;
    for(int i=1; i<=100000; i++){
        if(emax<ecnt[i]){
            emax=ecnt[i];
            enumb=i;
        }
        if(omax<ocnt[i]){
            omax=ocnt[i];
            onumb=i;
        }
    }

    if(enumb!=onumb){
        cout << n-(emax+omax) << endl;
    }
    else{
        int emax2=0, omax2=0;
        for(int i=1; i<=100000; i++){
            if(i==enumb) continue;

            if(emax2<ecnt[i]){
                emax2=ecnt[i];
            }
            if(omax2<ocnt[i]){
                omax2=ocnt[i];
            }
        }
        if(emax2>=omax2){
            cout << n-(emax2+omax) << endl;
        }
        else{
            cout << n-(emax+omax2) << endl;
        }
    }
}

Measured memory_bytes: 1408
var debug = false;

//for(var i =0;i<;i++)

var dx = [-1, 1, 0, 0];
var dy = [0, 0, -1, 1];

function Main(input) {

    var l = input.split("\n")[0];
    console.log((l / 3) * (l / 3) * (l / 3));
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
if (!debug)
    Main(require("fs").readFileSync("/dev/stdin", "utf8"));
else
    Main(require("fs").readFileSync("./input", "utf8"));

Measured memory_bytes: 21064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

signed main() {
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;

    vector<int> x, y;
    inputVector(x, N);
    inputVector(y, M);

    int xZ = *max_element(all(x));
    xZ = max(xZ, X);

    int yZ = *min_element(all(y));
    yZ = min(yZ, Y);

    cout << (xZ < yZ ? "No War" : "War") << endl;

    return 0;
}


Measured memory_bytes: 256
N,C=map(int,input().split())
D=[]
D.append([0 for i in range(C+1)])
for i in range(C):
    d=[0]+list(map(int,input().split()))
    D.append(d)
#print(D)
L=[]
for i in range(N):
    c=list(map(int,input().split()))
    L.append(c)

M0=[0 for i in range(C+1)]
M1=[0 for i in range(C+1)]
M2=[0 for i in range(C+1)]

for i in range(N):
    for j in range(N):
        if (i+j)%3==0:
            M0[L[i][j]]+=1
        elif (i+j)%3==1:
            M1[L[i][j]]+=1
        elif (i+j)%3==2:
            M2[L[i][j]]+=1
#print(M0,M1,M2)

Col=[i for i in range(1,C+1)]
#print(Col)
import itertools
Arr=list(itertools.permutations(Col,3))
#print(Arr)
ans=10**20
for i in range(len(Arr)):
    cnt=0
    for j in range(1,C+1):
        cnt+=M0[j]*D[j][Arr[i][0]]
        cnt+=M1[j]*D[j][Arr[i][1]]
        cnt+=M2[j]*D[j][Arr[i][2]]
    if ans>cnt:
        ans=cnt
    #print(cnt,Arr[i])
print(ans)



Measured memory_bytes: 46428
N=int(input())
T=False
k=0
for i in range(N):
    D1,D2=map(int,input().split())
    if D1==D2:
        k+=1
        if k>=3:
            T=True
    else:
        k=0
if T:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9176
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repp(i, m, n) for(int i = m; i < (int)n; i++)
#define reps(i, n) for(int i = 1; i <= (int)n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;



int main()
{
	int n, t;
	cin >> n >> t;
	int a[100010], kosu[100010]={};
	rep(i, n)
	{
		cin >> a[i];
		kosu[a[i]]++;
	}
	reps(i, 100000) kosu[i]+=kosu[i-1];
	sort(a, a+n);
	ll ans=1;
	rep(i, n)
	{
		ans*=(i+1-kosu[max(0, a[i]-t-1)]);
		ans%=MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3872
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int* R = new int[n];
	for (int i = 0; i < n; ++i)
		cin >> R[i];
	int maxv = R[1] - R[0];
	int minv = R[0];
	for (int i = 1; i < n; ++i)
	{
		maxv = max(maxv, R[i] - minv);
		minv = min(minv, R[i]);
	}
	cout << maxv << endl;
	delete[]R;
	return 0;
}


Measured memory_bytes: 3572
#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;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	string a, b;

	cin >> a >> b;

	if (a.size() > b.size()) {
		cout << "GREATER" << endl;
	}
	else if (a.size() < b.size()) {
		cout << "LESS" << endl;
	}
	else {
		REP(i, a.size()) {
			if ((a[i] - '0') > (b[i] - '0')) {
				cout << "GREATER" << endl;
				return 0;
			}
			else if ((a[i] - '0') < (b[i] - '0')) {
				cout << "LESS" << endl;
				return 0;
			}
		}

		cout << "EQUAL" << endl;
	}
}

Measured memory_bytes: 256