akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize (2)
#pragma G++ optimize (2)
#include<bits/stdc++.h>
#define INF (1ll<<61)
#define MAX 5005
using namespace std;
//char nc()
//{
//	static char buf[100000],*p1=buf,*p2=buf;
//	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
//}
char nc(){return getchar();}
int read()
{
	int x=0,y=1;
	char c=nc();
	while(!isdigit(c))
	{
		if(c=='-')y=-1;
		c=nc();
	}
	while(isdigit(c))
	{
		x=(x<<1)+(x<<3)+(c^48);
		c=nc();
	}
	return x*y;
}
int n,a[MAX];
long long A,B,f[MAX];
int main()
{
	n=read();A=read();B=read();
	for(int i=1;i<=n;i++)
		a[i]=read();
	a[0]=0;a[n+1]=n+1;
	f[0]=0;
	for(int i=1;i<=n+1;i++)
	{
		int s1=0,s2=0;
		f[i]=INF;
		for(int j=i-1;j>=0;j--)
		{
			if(a[j]<a[i]) f[i]=min(f[i],f[j]+A*s1+B*s2),s2++;
			else s1++;
		}
	}
	printf("%lld",f[n+1]);
	return 0;
}


Measured memory_bytes: 3800
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

	int n;
	cin >> n;
	V<V<bool>> f(n, V<bool>(10, false));
	rep(i, n)rep(j, 10) {
		int k;
		cin >> k;
		if (k)f[i][j] = true;
	}
	vvi p(n, vi(11));
	rep(i, n)rep(j, 11)cin >> p[i][j];

	ll ans = -LINF;
	rep(i, 1 << 10) {
		if (i == 0)continue;

		vi c(n, 0);

		rep(j, 10) {
			if (!((i >> j) & 1))continue;
			rep(k, n)if (f[k][j])c[k]++;
		}

		ll prof = 0;
		rep(j, n)prof += p[j][c[j]];
		ans = max(ans, prof);

	}

	cout << ans << endl;

}

Measured memory_bytes: 256
/*input
*/
#include <bits/stdc++.h>
using namespace std;
 
#define all(a) a.begin(), a.end()
#define ff first
#define ss second
#define pb push_back
 
using ll = long long;
using pii = pair<int, int>;
 
template<typename T> using V = vector<T>;

const int N = 1e5 + 5;
int ans[N];

int main() {
	ios::sync_with_stdio(false);cin.tie(nullptr);
	string s; cin >> s;
	int n = s.length();
	// for 'L' if ((i - prevR) & 1) ans[prevR + 1]++ else ans[prevR]++
	// for 'R' if ((nxtL - i) & 1) ans[nxtL - 1]++ else ans[nxtL]++
	int prevR = 0, nxtL = 0;
	int i = 0;
	while (i < n) {
		if (s[i] == 'R') {
			while (nxtL < i)
				++nxtL;
			while (nxtL < n and s[nxtL] == 'R')
				++nxtL;
			if ((nxtL - i) & 1)
				++ans[nxtL - 1];
			else
				++ans[nxtL];
			prevR = i;
		} else {
			if ((i - prevR) & 1)
				++ans[prevR + 1];
			else
				++ans[prevR];
		}
		++i;
	}
	for (int i = 0; i < n; ++i)
		cout << ans[i] << " \n"[i == n - 1];
	return 0;
}

Measured memory_bytes: 1104
#include<iostream>
#include <stdint.h>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if(a==1){
		a=14;
	}
	if(b==1){
		b=14;
	}
	if(a>b){
	cout<<"Alice"<<endl;
	}
	if(a<b){
		cout<<"Bob"<<endl;

	}
	if(a==b){
		cout<<"Draw"<<endl;

	}

}

Measured memory_bytes: 256
from decimal import *

N,K = map(int, input().split())
A = list(map(int, input().split()))
Ans = 0

a = Decimal(str(K - 1))
b = Decimal(str(K))
c = Decimal(str(K + 1))

d = Decimal(a*b/2)
e = Decimal(b*c/2)

#print(a)
#print(b)
#print(c)
#print(d)
#print(e)

d = d % 1000000007
e = e % 1000000007

#print(d)
#print(e)

#count1 = (K * (K+1) / 2) % 1000000007
#count2 = ((K-1) * K / 2) % 1000000007
count1 = int(e)
count2 = int(d)

#print(count1)
#print(count2)

for i in range(N):

  for j in range(N):

    if A[i] > A[j]:
      if i < j:
        Ans = Ans + count1
      else:
        Ans = Ans + count2
      
      if Ans > 1000000007:
        Ans = Ans % 1000000007  


print(int(Ans))

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

int main(){
	int n,m,p;
	string s;
	cin >> n >> m;
	vector<P> a(n+1,mp(0,0));
	for(int i = 0; i < m; i++) {
		cin >> p >> s;
		if (a[p].fs == 0 && s == "WA"){
			a[p].sc++;
		}
		else if(a[p].fs == 0 && s == "AC"){
			a[p].fs = 1;
		}
	}
	int ans = 0;
	int penalty = 0;
	for (int i = 1;i <= n;i++){
		if (a[i].fs == 1){
			ans++;
			penalty += a[i].sc;
		}
	}
	cout << ans << " " << penalty << endl;



	
	return 0;
}

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

int main(){
  int a[3], result = 0;
  cin >> a[0] >> a[1] >> a[2];
  sort(a, a + 3);
  result += a[1] - a[0];
  result += a[2] - a[1];
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <list>
#include <bitset>
#include <vector>
using namespace std;

#define I64d_OJ

//#ifdef I64d_OJ
//#define LL __int64
//#endif // I64d_OJ
#ifdef I64d_OJ
#define LL long long
#endif // I64d_OJ

typedef unsigned LL ULL;
typedef unsigned uint;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;
typedef vector<int> vi;

inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-f; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define ls rt<<1
#define rs rt<<1|1
#define MID(a,b) (((LL)(a)+(LL)(b))>>1)
#define absx(a) ((a)<0?-(a):(a))
#define MK(a,b) make_pair(a,b)
#define PB(a) push_back(a)
#define lowbit(x) ((x)&-(x))

#define lc c[x][0]
#define rc c[x][1]

template< typename T >
inline void Max(T &a,T &b){if(a<b) a=b;}
template< typename T>
inline void Min(T &a,T &b){if(a>b) a=b;}

const double pi=(double)acos(-1.0);
const double eps=(double)1e-8;
const int INF = (int) 0x3f3f3f3f;
const int MOD = (int) 1e9+7;
const int MAXN =(int) 2e5+10;
const int MAXM = (int) 3e6+10;

///--------------------START-------------------------
int N,P;
char a[MAXN];
int s[MAXN];
int cnt[MAXN];

void work(){
    scanf("%d%d",&N,&P);
    scanf("%s",a+1);
    LL ans=0;
    if(P==2){
        for(int i=1;i<=N;i++){
            if((a[i]-'0')%2==0) ans+=i;
        }
        printf("%lld\n",ans);
        return;
    }
    if(P==5){
        for(int i=1;i<=N;i++){
            if((a[i]-'0')%5==0) ans+=i;
        }
        printf("%lld\n",ans);
        return;
    }
    int tmp=1;
    for(int i=N;i>=1;i--){
        s[i]=(s[i+1]+(a[i]-'0')*tmp)%P;
        tmp=tmp*10%P;
    }
//    for(int i=1;i<=N;i++) printf("%d ",s[i]);
//    printf("\n");
    for(int i=1;i<=N;i++){
        if(s[i]==0) ans+=cnt[s[i]]+1;
        else ans+=cnt[s[i]];
        cnt[s[i]]++;
    }
    printf("%lld\n",ans);
}

///--------------------END-------------------------
int main(){
#ifdef NNever
//freopen("data.in","r",stdin);
///freopen("out.txt","w",stdout);
#endif // NNever
    work();
    return 0;
}









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

const long long maxn = 2e5 + 10;
const long long mod = 1e9 + 7;

long long n;
vector<long long> adj[maxn];
long long sub[maxn];
bool mark[maxn];
long long ans;

void in();
void solve();
void findsub(long long u);
void findans(long long u);
long long pwr(long long a, long long b);
void out();

int main(){
    in();
    solve();
    out();
}

void in(){
    ios::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    cin >> n;
    for(long long i = 1; i < n; i++){
        long long u, v;
        cin >> u >> v;
        u--;
        v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
}

void solve(){
    findsub(0);
    findans(0);
}

void findsub(long long u){
    sub[u] = 1;
    mark[u] = 1;
    for(auto v: adj[u]){
        if(!mark[v]){
            findsub(v);
            sub[u] += sub[v];
        }
    }
}

void findans(long long u){
    mark[u] = 0;
    long long p = (pwr(2, - n) + pwr(2, -1))% mod;
    for(auto v: adj[u]){
        if(mark[v]){
            long long soorat = (pwr(2, sub[v]) - 1 + mod) % mod;
            long long makhraj = pwr(2, - n);
            p += soorat * makhraj % mod;
            findans(v);
        }
        else{
            long long soorat = (pwr(2, n - sub[u]) - 1 + mod) % mod;
            long long makhraj = pwr(2, - n);
            p += soorat * makhraj % mod;
        }
        p %= mod;
    }
    ans += mod - p + 1;
    ans %= mod;
}

long long pwr(long long a, long long b){
    if(b < 0)
        return pwr(a, b + mod - 1);
    if(b == 0)
        return 1;
    long long c = pwr(a, b / 2);
    if(b % 2)
        return c * c % mod * a % mod;
    return c * c % mod;
}

void out(){
    cout << ans;
}


Measured memory_bytes: 19968
N = int(input())
csf = [tuple(map(int, input().split())) for _ in range(N-1)]

if N >= 2:
    for i in range(N-1):
        ans = 0
        for j in range(i, N-1):
            c, s, f = csf[j]
            if ans < s:
                ans = s + c
            else:
                if ans % f == 0:
                    ans += c
                else:
                    ans += f - ans % f + c
        print(ans)
print(0)

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

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

  vector<int> F(N + 1, 0);
  for (ll i = 1; i <= N; i++) {
    ll j = 1;
    while (i * j <= N) {
      F.at(i * j)++;
      j++;
    }
  }
  ll ans = 0;
  for (ll i = 1; i <= N; i++) {
    ans += i * F.at(i);
  }

  cout << ans << endl;
}


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

// 基本テンプレート
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// 型
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// 定数
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion

int main()
{
    int K, T;
    cin >> K >> T;
    int a[111];
    rep(i,T) cin >> a[i];
    int mx = *max_element(a, a+T);
    if(2*mx>K) P(K-(K-mx)*2-1);
    else P(0);
    return 0;
}



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

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

    Scanner cin;

    public Program() { }

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

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

        long n = cin.nextLong();
        long k = cin.nextLong();
        long[] h = cin.ArrayLong((int)n);

        if (n <= k)
        {
            WriteLine(0);
        }
        else
        {
            var dst = h.OrderBy(a => -a).ToArray();
            long ans = 0;
            for (int i = (int) k; i < (int) n; ++i)
            {
                ans += dst[i];
            }

            WriteLine(ans);
        }

    }
}

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

class Scanner
{
    string[] s;
    int i;

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

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

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

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

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

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

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


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


Measured memory_bytes: 42368
#include<bits/stdc++.h>
	using namespace std;
	typedef long long int ll;
	#define pb push_back
	#define mp make_pair
	#define sz(a) ll(a.size())
	#define trace(c,x) for(auto &x:c)
	#define F first
	#define S second		
	ll mod = 1e9 + 7;   //change acc to question

ll fastexpo(ll x,ll y)
{
	ll a=1;
	while(y>0)
	{
		if(y&1)a = (a*x)%mod;
		y/=2;
		x=(x*x)%mod;
	}	
	return a;
}

ll memo[3003][3003][2];
ll a[3003];
int n;

ll dp(int i,int j,int turn)
{
	if(i==j)
	{
		if(turn==0)
			return a[i];
		else
			return -a[i];
	}

	if(memo[i][j][turn]!=-1)
		return memo[i][j][turn];
	if(turn==0)
		memo[i][j][turn] =  max(a[i]+dp(i+1,j,1),a[j]+dp(i,j-1,1));
	else
		memo[i][j][turn] = min(-a[i]+dp(i+1,j,0),-a[j]+dp(i,j-1,0));
	
	return memo[i][j][turn];
}


int main()
{

	ios::sync_with_stdio(false);

	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	
	for(int i=0;i<3003;i++)
		for(int j=0;j<3003;j++)
			for(int k=0;k<2;k++)
				memo[i][j][k] = -1;

	cout<<dp(0,n-1,0)<<endl;

	return 0;

	}	

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

const int N = 500;

int n;
int a[N];

int need(int d)
{
    vector<int> v;
    for (int i = 0; i < n; ++i)
        if (a[i] % d) v.push_back(a[i] % d);
    sort(v.begin(), v.end());

    /*
    printf("%d\n", d);
    for (int x : v)
        printf("%d ", x);
    printf("\n");
    */

    int l = 0, r = (int)v.size() - 1;
    int res = 0;
    while(l < r)
    {
        //printf("%d %d\n", l, r);
        if (v[l] < d - v[r])
        {
            res += v[l];
            v[r] += v[l];
            ++l;
        }
        else if (v[l] > d - v[r])
        {
            res += d - v[r];
            v[l] -= d - v[r];
            --r;
        }
        else
        {
            res += v[l];
            ++l;
            --r;
        }
    }

    //printf("%d\n\n", res);
    return res;
}

int main()
{
    int k;
    scanf("%d%d", &n, &k);

    int sum = 0;
    for (int i = 0; i < n; ++i)
    {
        scanf("%d", a + i);
        sum += a[i];
    }

    int ans = 1;
    for (int x = 1; x * x <= sum; ++x)
    {
        if (sum % x) continue;

        if (need(x) <= k) ans = max(ans, x);
        if (need(sum / x) <= k) ans = max(ans, sum / x);
    }

    printf("%d", ans);
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <string>
#include <iostream>
#define SIZE 100005
#define INF 100000000000000000LL

using namespace std;
int main()
{

	set<string> s;
	string t;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> t;
		s.insert(t);
	}
	if (s.size() == 3) {
		cout << "Three";
	}
	else {
		cout << "Four";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.*;

class Main {
	public static void main(String args[]) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {
			String buf = br.readLine();
			String ans = "";

			for (int i=0;i<buf.length();i++) {
				if (buf.charAt(i)=='p') {
					String t = "";
					for (int j=0;j<5;j++) t = t+buf.charAt(i+j);
					if (t.equals("peach")) {
						ans = ans+"apple";
						i += 4;
					} else {
						ans = ans+buf.charAt(i);
					}
				} else if (buf.charAt(i)=='a') {
					String t = "";
					for (int j=0;j<5;j++) t = t+buf.charAt(i+j);
					if (t.equals("apple")) {
						ans = ans+"peach";
						i += 4;
					} else {
						ans = ans+buf.charAt(i);
					}
				} else {
					ans = ans+buf.charAt(i);
				}
			}
			System.out.println(ans);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 17488
#include <stdio.h>
int main(){
	int a, b, c;
	char op;
	
	while(1){
		scanf("%d %c %d", &a, &op, &b);
		if(op=='+'){
			printf("%d\n", a+b);
		}else if(op=='-'){
			printf("%d\n", a-b);
		}else if(op=='*'){
			c = a*b;
			printf("%d\n", c);
		}else if(op=='/'){
			c = a/b;
			printf("%d\n", c);
		}else break;
	}
	
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    vector<vector<int>> A(3,vector<int>(3));
    rep(i,0,3)rep(j,0,3) cin>>A.at(i).at(j);
    int N;
    cin>>N;

    vector<vector<bool>> hit(3,vector<bool>(3,false));
    rep(n,0,N){
        int b;
        cin>>b;
        rep(i,0,3)rep(j,0,3) if(A.at(i).at(j)==b) hit.at(i).at(j)=true;
    }

    string ans="No";
    if(hit.at(0).at(0) && hit.at(0).at(1) && hit.at(0).at(2)) ans="Yes";
    if(hit.at(1).at(0) && hit.at(1).at(1) && hit.at(1).at(2)) ans="Yes";
    if(hit.at(2).at(0) && hit.at(2).at(1) && hit.at(2).at(2)) ans="Yes";
    if(hit.at(0).at(0) && hit.at(1).at(0) && hit.at(2).at(0)) ans="Yes";
    if(hit.at(0).at(1) && hit.at(1).at(1) && hit.at(2).at(1)) ans="Yes";
    if(hit.at(0).at(2) && hit.at(1).at(2) && hit.at(2).at(2)) ans="Yes";
    if(hit.at(0).at(0) && hit.at(1).at(1) && hit.at(2).at(2)) ans="Yes";
    if(hit.at(0).at(2) && hit.at(1).at(1) && hit.at(2).at(0)) ans="Yes";

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
const int maxN = 1e5 + 10;
ll a[maxN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    ll sum = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    ll coef = (1LL * n * (n + 1)) / 2;
    if (sum % coef != 0) {
        cout << "NO\n";
        return 0;
    }
    sum /= coef;
    a[n + 1] = a[1];
    for (int i = 1; i <= n; i++) {
        ll p = a[i + 1] - (a[i]);
        ll val = sum - p;
        if (val < 0 || val % n != 0) {
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
    return 0;
}

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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 60;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    int A[N]; rep(i, N) cin >> A[i];
    sort(A, A+N);
    if(N % 2) cout << 0 << endl;
    else{
        int mid = N/2;
        cout << A[mid]-A[mid-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 640
import java.util.*;
import java.lang.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		String S = sc.next();
		if( S.charAt(2)==S.charAt(3) && S.charAt(4)==S.charAt(5) ){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

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

int main(void) {
  string S;
  cin >> S;

  int Ans = 0;
  for (uint i = 1; i < S.size(); i++) {
    if (S[i - 1] != S[i]) Ans++;
  }
  cout << Ans << endl;
  return 0;
}


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

A, B = 1, 1
for t, a in TA:
    n = max((A-1)//t+1, (B-1)//a+1)
    A = n*t
    B = n*a

print(A+B)

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

typedef long long ll;

int n,k;
ll a[100005];
ll dp[100005];

ll solve(int idx){
    ll ans;
    if(idx==n)
        return 0;
    if(dp[idx]!=-1) return dp[idx];

    ans=abs(a[idx]-a[idx+1])+solve(idx+1);

    for(int i=2;i<=min(k,n);i++){
        if(idx+i<=n){
            ans=min(ans,abs(a[idx+i]-a[idx])+solve(idx+i));
        }
    }
    return dp[idx]=ans;
}


int main()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    memset(dp,-1,sizeof(dp));
    cout<<solve(1);

    return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define PI acos(-1.0)

typedef long long ll;
const int maxn=100;
ll a[100],n,k;

int main()
{
    cin >> n;
    for(int i=0;i<n;i++)
        cin >> a[i];
    while(1)
    {
        ll maxx=-1,index=0;
        for(int i=0;i<n;i++)
            if(maxx<a[i])
                maxx=a[i],index=i;
        if(maxx<n)
            break;
        for(int i=0;i<n;i++)
        {
            if(index==i)
                a[i]%=n;
            else
                a[i]+=(maxx/n);
        }
        k+=(maxx/n);
    }
    cout << k << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <cassert>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define RREP(i,n) for(int i=(n)-1; i>=0; --i)
#define SREP(i,s,n) for(int i=(s), i##_len=(n); i<i##_len; ++i)


using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    if (b == 1) return 1;
    T r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

bool comp(pair<int, int> a, pair<int, int> b) {
    return a.second > b.second;
}

struct UnionFind {
    vector<int> par;
    vector<int> rank;
    
    UnionFind(int n = 1) {
        init(n);
    }
    
    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
        }
    }
    
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};

#define MOD (1000000007)

int main(int argc, const char * argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ull N, K;
    cin >> N >> K;
    
    vector<int> A(N);
    
    ull cnt = 0;
    REP(i, N) {
        cin >> A[i];
    }
    REP(i, N) {
        ull a = 0, b = 0;
        REP(j, N) {
            if (A[i]>A[j]) a++;
            if (A[i]>A[j] && i<j) b++;
        }
        cnt = ((cnt + (K*b)%MOD)%MOD + ((((K-1)*K/2)%MOD)*a)%MOD)%MOD;
    }
    
    cout << cnt << endl;
}


Measured memory_bytes: 256
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
// #include<deque>
// #include<multiset>
// #include<bitset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n, m;
  cin >> n >> m;
  set<int> st;
  for(int i = 0; i < n; i++) {
    int x;
    cin >> x;
    st.insert(x);
  }
  auto OR = st;
  set<int> AND;
  for(int i = 0; i < m; i++) {
    int x;
    cin >> x;
    OR.insert(x);
    if(st.count(x)) AND.insert(x);
  }
  cout << AND.size() << " " << OR.size() << "\n";
  for(auto a : AND) cout << a << "\n";
  for(auto a : OR) cout << a << "\n";
  return 0;
}



Measured memory_bytes: 20060
from operator import itemgetter

n = int(input())
info = []
for i in range(n):
    a, b = input().split()
    info.append([a, int(b), i])

info = sorted(info, key = itemgetter(1), reverse =  True)
info = sorted(info, key = itemgetter(0))

for i in range(n):
    print(info[i][2] + 1)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int a,b;
  cin>>a>>b;
  if(abs(a-b)%2==0){
    cout<<abs(a-b)/2+min(a,b)<<endl;    
  }
  else{
    cout<<"IMPOSSIBLE"<<endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n,i,j,cnt=0;
  cin >> n;
  vector<int>a(n);
  for(i=0; i<n; i++){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  for(i=0; i<n-1; i++){
    j=i+1;
    if(a.at(i)==a.at(j)){
      cout << "NO" << endl;
      return 0;
    }

  }
  cout << "YES" << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include<queue>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef pair<string,string> Pstring;
typedef pair<double,double> Pdouble;

#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define Precision13 cout << fixed << setprecision(13)
const double PI=3.14159265358979323846;
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
char maze[310][310];
ll ans[310][310];
int main() {

  string s;
  cin >> s;
  ll k;
  cin >> k;

  REP(i,s.size()){
    ll di = 'z'-s.at(i)+1;
    if(s.at(i)=='a'){
      continue;
    }
    if(k>=di){
      s.at(i) = 'a';
      k -= di;
    }
  }

  k %= 26;
  ll dl = 'z'- s.at(s.size()-1)+1;
  if(k>=dl){
    s.at(s.size()-1)='a'+k-dl;
  }else{
    s.at(s.size()-1)= s.at(s.size()-1)+k; 
  }
  cout << s << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

int main(){
    ll n; cin >> n;
    vector<string> s(n);
    ll ab = 0, a = 0, b = 0;
    vector<pair<char, char>> sp;
    rep(i, n){
        cin >> s[i];
        char f = s[i][0], e = s[i][s[i].size()-1];
        if(s[i][0] == 'B' || s[i][s[i].size() - 1] == 'A'){
            sp.emplace_back(f, e);
            if(f == 'B') b++;
            if(e == 'A') a++;
        }
        
        ll in = 0;
        while(in != string::npos){
            in = s[i].find("AB", in);
            if(in != string::npos){
                ab++;
                in++;
            }
        }
    }
    ll cat = min(a, b);
    if(a > 0 && a == b && sp.size() == a) cat--;
    //printf("%lld %lld %lld %lld %d\n", ab, a, b, cat, (int)sp.size());
    cout << ab + cat << endl;
    return 0;
}

Measured memory_bytes: 3768
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
#include<ext/pb_ds/priority_queue.hpp>
using namespace std;

const int maxn = 1E5 + 10;
typedef long long LL;
const LL mo = 1000000007;

int n,m,A,B,x[maxn],y[maxn],suf[maxn];

inline int Mul(const LL &x,const LL &y) {return x * y % mo;}
inline int Add(const int &x,const int &y) {return x + y < mo ? x + y : x + y - mo;}
inline int Dec(const int &x,const int &y) {return x - y >= 0 ? x - y : x - y + mo;}

void Calc(int N,int &G)
{
	for (int i = 1; i <= N; i++)
	{
		scanf("%d",&x[i]);
		if (x[i] < 0) x[i] += mo;
	}
	suf[N + 1] = 0;
	for (int i = N; i; i--) suf[i] = Add(x[i],suf[i + 1]);
	for (int i = 1; i < N; i++)
	{
		int a = Mul(x[i],N - i);
		G = Add(G,Dec(suf[i + 1],a));
	}
}

int main()
{
	#ifdef DMC
		freopen("DMC.txt","r",stdin);
	#endif
	
	cin >> n >> m;
	Calc(n,A); Calc(m,B);
	cout << Mul(A,B) << endl;
	return 0;
}


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

int main() {
  int a, b;
  string s;
  cin >> a >> b >> s;
  bool ok = true;
  rep(i, s.size()) {
    if (i == a && s[i] != '-') ok = false;
    if (i != a && (s[i] < '0' || s[i] > '9')) ok = false;
  }
  if (ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

using namespace std;


#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;


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


	return 0;
}



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

int main() {
  string n;
  cin >> n;
  int sum=0;

  for(int i=0; i<n.length(); ++i) {
    if (n[i] == '0') sum += 0;
    else if (n[i] == '1') sum += 1;
    else if (n[i] == '2') sum += 2;
    else if (n[i] == '3') sum += 3;
    else if (n[i] == '4') sum += 4;
    else if (n[i] == '5') sum += 5;
    else if (n[i] == '6') sum += 6;
    else if (n[i] == '7') sum += 7;
    else if (n[i] == '8') sum += 8;
    else if (n[i] == '9') sum += 9;
  }

  if (sum % 9 ==0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	if(a == b + c){
		cout << "Yes" << endl;
	} else if (b == a + c){
		cout << "Yes" << endl;
	} else if (c == a + b){
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())

sys.setrecursionlimit(10 ** 9)


def main():
    N = INT()
    l = []
    for _ in range(N):
        X, L = MAP()
        l.append([X-L, X+L])

    q = deque(sorted(l, key=lambda x: (x[0], x[1])))

    cnt = N
    xm, xl = q.popleft()
    for i in range(N-1):
        nm, nl = q.popleft()
        if nm < xl:
            cnt -= 1
            if nl < xl:
                xm = nm
                xl = nl
        else:
            xm = nm
            xl = nl

    print(cnt)


if __name__ == '__main__':
    main()

Measured memory_bytes: 62552
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

score(pc::Array{Int, 2}, i::Int) = pc[i,1] * 100i

function rec(d::Int, pc::Array{Int, 2}, g::Int)
    if g <= 0 return(0) end
    ret = typemax(Int)
    for i in d:-1:1
        if pc[i,1]==0 continue end
        if g <= score(pc, i)
            ret = min(ret, ceil(Int, g / 100i))
        else
            pcNext = copy(pc)
            pcNext[i, 1] = 0
            ret = min(ret, pc[i,1] + rec(d, pcNext, g - (score(pc, i) + pc[i,2])))
        end
    end
    return(ret)
end

function main()
    d, g = readline() |> split |> parseMap

    pc = zeros(Int, d, 2)
    for i in 1:d
        pc[i, 1], pc[i, 2] = readline() |> split |> parseMap
    end

    ans = rec(d, pc, g)
    println(ans)

end

main()


Measured memory_bytes: 166256
/*input
*/
#define debug 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; typedef double db;
const int N = 1e5 + 5, M = 998244353; const db eps = 1e-8;
typedef vector<ll> vi; typedef vector<vi> vii;
void solve();
void print(){cout<<'\n';}template<class T,class ...U>void print(T x, U ...y){cout<<x<<' ';print(y...);}
int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  cout << setprecision(3) << fixed;
  if(debug){freopen("main.cpp","r",stdin);string x;cin>>x;}
  solve();
}
//

void solve() {
  ll k, x;
  cin >> k >> x;
  if (k * 500 >= x) puts("Yes");
  else puts("No");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define pi pair<int,int>

int main()
{
ll n;
cin>>n;
ll a[n+1],b[n+1],c[n];
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++) cin>>b[i];
for(int i=1;i<=n-1;i++) cin>>c[i];
ll ans=0;
for(int i=1;i<=n;i++)
{
    ans+=b[a[i]];
    if( i> 1 && a[i]==a[i-1]+1) ans+=c[a[i-1]];
}
cout<<ans;
}

Measured memory_bytes: 256
cnt=0
ans=0
n,m=gets.split.map(&:to_i)
d=(1..n).map{gets.split.map(&:to_i)}
d.sort!{|s,t|s[0]<=>t[0]}
d.each{|a,b|
    if cnt + b > m
        p  ans + a*(m-cnt)
        break
    elsif cnt + b == m
        p ans + a*b
        break
    else
        cnt = cnt + b
        ans = ans + a*b
    end
}

Measured memory_bytes: 10488
n, k = map(int, input().split())
a = tuple(map(int, input().split()))

i = 0
aa = 0
visited = {}
for i in range(k):
    aa = a[aa] - 1
    if aa in visited:
        s, e = visited[aa], i
        loop = e - s
        k = s + (((k-1) - s) % loop)
        print(list(visited.keys())[k] + 1)
        exit(0)
    visited[aa] = i

print(aa+1)


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

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

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

  vector<int> color(8, 0);
  int free = 0;

  for (int i = 0; i < n; i++) {
    if (a[i] < 400)
      color[0]++;
    else if (a[i] < 800)
      color[1]++;
    else if (a[i] < 1200)
      color[2]++;
    else if (a[i] < 1600)
      color[3]++;
    else if (a[i] < 2000)
      color[4]++;
    else if (a[i] < 2400)
      color[5]++;
    else if (a[i] < 2800)
      color[6]++;
    else if (a[i] < 3200)
      color[7]++;
    else
      free++;
  }
  int ans(0);
  for (int i = 0; i < 8; i++) {
    if (color[i] > 0) ans++;
  }
  int min = max(ans, 1);
  int max = ans + free;

  cout << min << " " << max << endl;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
#pragma GCC optimize ("-O3")
    using namespace std;
    #define ll long long
    #define ld long double
    #define vll vector<ll>
    #define mll map<ll,ll>
    #define pll pair<ll,ll>
    #define ff first
    #define ss second
    #define pb push_back
    #define deb(x) cout<<#x<<" : "<<x<<endl;
    #define deb2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
    #define deb3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
    #define deb4(w,x,y,z) cout<<#w<<" : "<<w<<"\t"<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
    #define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define printv(a)  for(ll i=0;i<a.size();i++)  cout<<a[i]<<" ";
   
   
    const int mod=1e9+7;
    const int N=1e6+5; 
   
    bool sortbysec(const pair<pair<ll,ll>,ll> &a, 
                      const pair<pair<ll,ll>,ll> &b) 
        { 
            return (a.second > b.second); 
        } 
        ll powermod(ll x, ll y, ll p)
        {
            ll res = 1;
            x = x % p;
            while (y > 0)
            {
                if (y & 1) res = (res*x) % p;
                y = y>>1;
                x = (x*x) % p;
            }
            return res;
        }
       
        bool isprime(int n) 
        { 
            if (n <= 1)  return false; 
            if (n <= 3)  return true; 
            if (n%2 == 0 || n%3 == 0) return false; 
            for (int i=5; i*i<=n; i=i+6) 
                if (n%i == 0 || n%(i+2) == 0) 
                   return false; 
           return true; 
        }
       
        
     
        int main()
    {
        FAST;
        ll n,k;
        cin>>n>>k;
        vll dp(k+1);
        dp[0]=1;
        for(ll child=0;child<n;child++)
        {
            ll x;
            cin>>x;
            ll L,R;
            vll fake(k+1);
            for(ll used=k;used>=0;used--)
            {   ll temp=dp[used];
                L=used+1;
                R=used+min(x,k-used);
                if(L<=R)
                {
                    fake[L]=(fake[L]+temp)%mod;
                    if(R+1<=k)
                    {
                        fake[R+1]=(fake[R+1]-temp)%mod;
                        if(fake[R+1]<0)
                        fake[R+1]+=mod;
                        fake[R+1]%=mod;
                    }
            }
            }
            ll prefix_sum=0;
          for(ll i=0;i<=k;i++)
          {
              prefix_sum=(prefix_sum+fake[i])%mod;
              dp[i]=(dp[i]+prefix_sum)%mod;
          }
        }
        
        cout<<dp[k];
        return 0;
    }

Measured memory_bytes: 1792
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);

  bool is_prime[111111];

  memset(is_prime, 1, sizeof(is_prime));

 is_prime[0] = is_prime[1] = false;

  for (int i = 2; i * i <= 111111; i ++)
    if (is_prime[i])
      for (int k = i + i; k <= 111111; k += i)
        is_prime[k] = false;

  int acc[111111] = {0};

  for (int i = 0; i < 111111; i ++)
    if (i % 2) {
      acc[i + 1] = (is_prime[i] && is_prime[(i + 1) / 2] ? 1 : 0) + acc[i];
    }
    else {
      acc[i + 1] = acc[i];
    }

  int Q, l, r;

  std::cin >> Q;

  for (int i = 0; i < Q; i ++) {
    std::cin >> l >> r;

    std::cout << acc[r + 1] - acc[l] << std::endl;
  }

  return 0;
}


Measured memory_bytes: 1152
v, e = gets.split.map(&:to_i)
ret = []
set = Array.new(v){ |i| i }
g = Array.new(v){ Array.new }
rg = Array.new(v){ Array.new }
e.times do
  s,t = gets.split.map(&:to_i)
  g[s] << t
  rg[t] << s
end
empset = rg.map.each_with_index{|a, i| i if a.empty? }.compact
until set.empty?
  n = empset.shift
  set.delete(n)
  ret << n
  g[n].each do |m|
    rg[m].delete(n)
    empset << m if rg[m].empty?
  end
end
ret.each{|v| p v}

Measured memory_bytes: 13332
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb push_back
#define mp make_pair
#define nt _ll128
#define ld double
long double PI =3.14159265;
using ll = long long;

const ll modo=1e9+7;
const ll ms=2e5+5;
const ll inf=1e17;

unordered_map<int,int> m1;
unordered_map<int,int> m2;


vector<int> vv[ms];
vector<pair<int,int>> ar;
int ans[ms];
int main()
{
    idfc;
    int n;
    cin>>n;
    int i;
    int e;
    int N=n;
    for(i=1;i<=n;i++)
    {
        cin>>e;
        m1[e]+=1;
        vv[e].pb(i);
    }
    for(i=1;i<=n;i++)
    {
        cin>>e;
        m2[e]+=1;
    }
    int x;
    for(auto it:m1)
    {
        x=min(it.second,m2[it.first]);
        ar.pb({x,it.first});
    }

    queue<int> q;

    sort(ar.rbegin(),ar.rend());
    int y;
    n=ar.size();
    int sz;
    for(i=0;i<n;i++)
    {
        y=ar[i].second;
        x=m2[y];
        while(x--)
        {
            q.push(y);
        }
        m2.erase(y);
    }
    for(auto it:m2)
    {
        x=it.first;
        y=it.second;
        while(y--)q.push(x);
    }
    for(i=0;i<n;i++)
    {
        x=ar[i].second;

        for(int ii:vv[x])
        {
            if(q.front()!=x)
            {
                ans[ii]=q.front();
                q.pop();
            }
            else{
                sz=q.size();
                while(sz&&q.front()==x)
                {
                    sz--;
                    q.pop();
                    q.push(x);
                }
                if(q.front()==x)
                {
                    cout<<"No";
                    return 0;
                }
                ans[ii]=q.front();
                q.pop();
            }
        }
    }
    cout<<"Yes"<<"\n";
    for(i=1;i<=N;i++)cout<<ans[i]<<" ";
    return 0;
}

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

int main(void){
    int n = 0, m = 0; 
    long int a[51], b[51], c[51], d[51];
    int ans[51];

    scanf("%d%d", &n, &m);

    for(int i = 0; i < n; i++){
        scanf("%ld%ld", &a[i], &b[i]);
    }

    for(int i = 0; i < m; i++){
        scanf("%ld%ld", &c[i], &d[i]);
    }



    for(int i = 0; i < n; i++){
        long int min = 300000000;
        long int len = 0;
        for(int j = 0; j< m; j++){
            len = abs(a[i] - c[j]) + abs(b[i] - d[j]);
//            printf("len = %d\n", len);
            if(len < min){
                min = len;
                ans[i] = j + 1;
            }
        }
//        ans[i] = min;
    }

    for(int i = 0; i < n; i++){
        printf("%d\n", ans[i]);
    }

    return 0;

} 


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    int n,k;
    cin >> n>>k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    for(int i=k+1; i<=n; ++i){
        if(a[i-1] > a[i-k-1]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;
}


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

int main () {
  int H, W;
  cin >> H >> W;
  
  vector<string> vec(H);
  
  
  for (int i=0; i<H; i++){
      cin >> vec[i];
  }
  
  vector<bool> row(H, false);
  vector<bool> col(W, false);
  
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(vec[i][j] == '#'){
        row[i] = true;
        col[j] = true;
      }
    }
  }
  
  for (int i=0; i<H; i++){
    if(row[i]){
      for(int j = 0; j<W; j++){
        if(col[j]){
          cout << vec[i][j];
        }
      }
    cout << endl;
    }
  }
}
      



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

using namespace std;

int L;
stack<int> CatInfo;
bool Exist[101];

int main() {
	int c;

	memset(Exist, false, sizeof(Exist));
	cin >> L;
	for (int i = 0; i < L; ++i) {
		cin >> c;
		if (c > 0) {
			if (Exist[c]) {
				cout << i + 1 << endl;
				return 0;
			}
			Exist[c] = true;
			CatInfo.push(c);
			continue;
		}
		if (CatInfo.empty() || CatInfo.top() != -c) {
			cout << i + 1 << endl;
			return 0;
		}
		Exist[CatInfo.top()] = false;
		CatInfo.pop();
	}
	cout << "OK" << endl;

	return 0;
}


Measured memory_bytes: 3120
#include<stdio.h>
#include<string.h>

int main(){
  char ring[101],ch[101];
  int i,j,n,m,X,N=0;
  scanf(" %s",ring);
  scanf(" %s",ch);
  n=strlen(ring);
  m=strlen(ch);
  for(i=0;i<n;i++){
      if(ch[0]==ring[i]){
          if(m==1){
            printf("Yes\n");
            N=1;
            break;}
          else{
            for(j=1;j<m;j++){
               X=i+j;
               if(X>=n) X=X-n;
               if(!(ch[j]==ring[X])) break;
               if(j==m-1){
                 printf("Yes\n");
                 N=1;
                 break;}
             } 
           }
       if(N==1) break;}}
  if(N==0) printf("No\n");
  return 0;}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
ll ans = 0;
int N, M, Q;
vll a(51), b(51), c(51), d(51);
void dfs(vint A)
{
    if (A.size() == N)
    {
        ll point = 0;
        for (size_t i = 0; i < Q; i++)
        {
            if ((A[b[i]] - A[a[i]]) == c[i])
            {
                point += d[i];
            }
        }
        chmax(ans, point);
        return;
    }
    int x = 1;
    if (!A.empty())
    {
        x = A.back();
    }
    for (size_t i = x; i <= M; i++)
    {
        auto tmp = A;
        tmp.push_back(i);
        dfs(tmp);
    }
}
int main()
{

    cin >> N >> M >> Q;

    vint emp(0);
    for (size_t i = 0; i < Q; i++)
    {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        b[i]--;
        a[i]--;
    }
    dfs(emp);
    cout << ans;
    return 0;
}

Measured memory_bytes: 3620
def solve(A,N,K):
    ans_max,ans_min = max(A),1

    while True:
        if cutable(A,N,K,(ans_max+ans_min)//2):
            if ans_max > (ans_max+ans_min)//2:
                ans_max = (ans_max+ans_min)//2
            else:
                return ans_max
        else:
            if ans_min < (ans_max+ans_min)//2:
                ans_min = (ans_max+ans_min)//2
            else:
                return ans_max

def cutable(A,N,K,div):
    #K回までの切断で全部を長さdiv以下にできるかどうか
    cnt = 0
    for i in range(N):
        cnt += A[i]//div
        if A[i] % div == 0:
            cnt -= 1
        if cnt > K:
            return False

    return True

def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))

    ans = solve(A,N,K)
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 30628