akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <stdlib.h>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef vector<double> Vec;
typedef vector<Vec> Mat;
typedef pair<ll,ll> P;
typedef pair<double,ll> Pd;
typedef pair<double,double> PD;
typedef priority_queue<P,vector<P>,greater<P> > P_queue;
typedef priority_queue<Pd,vector<Pd>,greater<Pd> > Pd_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const double DEL=1e-6;

#define _GLIBCXX_DEBUG
#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end())

void Add(ll &a, ll b){a=(a+b)%mod;}
void Pro(ll &a, ll b){a=(a*b)%mod;}

ll op(ll a, ll b){
    return max(a,b);
}
ll e(){
    return (ll)0;
}

int main(){
    ll N,K; cin>>N>>K;
    vec d(N);
    rep(i,N) cin>>d[i];
    segtree<ll,op,e> seg(700000);
    ll ans=0;
    rep(i,N){
        ll a=max((ll)0,d[i]-K), b=d[i]+K+1;
        ll f=seg.prod(a,b)+1;
        ans=max(ans,f);
        seg.set(d[i],f);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 27596
#include<bits/stdc++.h>
#define mp make_pair
#define pii pair<int,int>
#define inf 0x3f3f3f3f
using namespace std;
const int N=3e3,M=2e4;
bitset<M> b[N];
pii p[2][N];
int n,k,sz[N];
char s[N][M],ans[M];
int main(){
	scanf("%d%d",&n,&k);
	int i,j;
	for(i=1;i<=n;++i){
		scanf("%s",s[i]);
		sz[i]=strlen(s[i]);
	}
	b[n+1][0]=1;
	for(i=n;i;--i) b[i]=b[i+1]|(b[i+1]<<sz[i]);
	int t=0,c=0,tc=0;
	for(i=1;i<=n;++i) if(b[i+1][k-sz[i]]) p[t][++c]=mp(i,0);
	int mn;
	for(i=0;i<k;++i,c=tc,t^=1){
		char mc='z';
		for(j=1;j<=c;++j) mc=min(mc,s[p[t][j].first][p[t][j].second]);
		ans[i]=mc;
		tc=0,mn=inf;
		for(j=1;j<=c;++j){
			int x=p[t][j].first,y=p[t][j].second;
			if(s[x][y]!=mc) continue;
			if(y==sz[x]-1) mn=min(mn,x);
			else p[t^1][++tc]=mp(x,y+1);
		}
		if(mn^inf) for(j=mn+1;j<=n;++j) if(k-sz[j]-i-1>=0 and b[j+1][k-sz[j]-i-1]) p[t^1][++tc]=mp(j,0);
	}
	for(i=0;i<k;++i) putchar(ans[i]);
	return 0;
}
///www

Measured memory_bytes: 47872
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;

int magicTable[16][16]={0},memo[16][16]={0};
int n,x,y;

int main(void){
	
	while(cin>>n,n){
		
		memset(magicTable,0,sizeof(magicTable));
				
		x=n/2;
		y=n/2+1;
		
		for(int i=1;i<=n*n;i++){
			magicTable[y][x]=i;
			x++;
			y++;
			
			if(y==n){
				y=0;
			}
			if(x==n){
				x=0;
			}
			
			if(magicTable[y][x]!=0){
				x--;
				y++;
				if(y==n){
					y=0;
				}
				if(x==-1){
					x=n-1;
				}
			}
		}
		
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				printf("%4d",magicTable[i][j]);
			}
			printf("\n");
		}
	}
}

Measured memory_bytes: 1164
import sys

sys.setrecursionlimit(200000)


def dfs(i):
    global visited, edges, counter, finish_order
    visited[i] = True
    for edge in edges[i]:
        if visited[edge]:
            continue
        dfs(edge)
    finish_order[i] = (counter, i)
    counter += 1


n, m = map(int, input().split())

edges = [set() for _ in range(n)]

for _ in range(m):
    s, t = map(int, input().split())
    edges[s].add(t)

visited = [False] * n
finish_order = [None] * n
counter = 0

for i in range(n):
    if not visited[i]:
        dfs(i)

for d, i in sorted(finish_order, reverse=True):
    print(i)

Measured memory_bytes: 14992
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using Pt = pair<int, int>;


namespace
{
	class Calculater
	{
	public:
		Calculater(vi c, vvi s)
			: c_(c), s_(s), D_((int)s.size()), selection_(D_) {
			Initialize();
		}

		void Initialize()
		{
			vi ld(26, -1);
			for (int i = 0; i < D_; ++i)
			{
				vi u = s_[i];
				vi v(26);
				for (int j = 0; j < 26; ++j)
					v[j] = c_[j] * (i - ld[j]);
				int ttl = accumulate(v.cbegin(), v.cend(), 0);
				transform(v.begin(), v.end(), v.begin(), [ttl](int x) {return x - ttl; });
				for (int j = 0; j < 26; ++j)
					u[j] += v[j];
				int j = (int)distance(u.cbegin(), max_element(u.cbegin(), u.cend()));
				selection_[i] = j;
				ld[j] = i;
			}
			sat_ = CalcSatisfaction();
		}
		int CalcSatisfaction()
		{
			int v = 0;
			vi ld(26, -1);
			for (int i = 0; i < D_; ++i)
			{
				int x = selection_[i];
				for (int j = 0; j < 26; ++j)
				{
					if (j == x)
					{
						v += s_[i][j];
						ld[j] = i;
					}
					else
						v -= c_[j] * (i - ld[j]);
				}
			}
			return v;
		}

		const vi& Selections() const
		{
			return selection_;
		}
		int Selection(int i) const
		{
			return selection_[i];
		}

		void Change(int d, int q)
		{
			int p = selection_[d];
			int d0 = 1;
			for (int i = d - 1; i > -1; --i)
			{
				if (selection_[i] == p)
					break;
				++d0;
			}
			int x = d0* c_[p];
			int d1 = 1;
			for (int i = d + 1; i < D_; ++i)
			{
				if (selection_[i] == p)
					break;
				++d1;
			}
			sat_ -= d1 * x;
			sat_ -= s_[d][p];


			d0 = 1;
			for (int i = d - 1; i > -1; --i)
			{
				if (selection_[i] == q)
					break;
				++d0;
			}
			x = d0 * c_[q];
			d1 = 1;
			for (int i = d + 1; i < D_; ++i)
			{
				if (selection_[i] == q)
					break;
				++d1;
			}
			sat_ += s_[d][q];
			sat_ += d1 * x;
			selection_[d] = q;
		}
		int Satisfaction() const { return sat_; }
	private:
		vi c_;
		vvi s_;
		int D_;
		vi selection_;

		int sat_;
	};

}
void Heuristics_Introduction_A()
{
	int D;
	cin >> D;
	vi c(26);
	for (auto& x : c)
		cin >> x;

	vvi s(D, vi(26));
	for (int i = 0; i < D; ++i)
	{
		for (int j = 0; j < 26; ++j)
			cin >> s[i][j];
	}


	Calculater x(c, s);

	//for (int i = 0; i < D; ++i)
	//{
	//	int t;
	//	cin >> t;
	//	x.Change(i, t - 1);
	//}

	//int M;
	//cin >> M;
	//for (int i = 0; i < M; ++i)
	//{
	//	int d, q;
	//	cin >> d >> q;
	//	--d; --q;
	//	x.Change(d, q);

	//	cout << x.Satisfaction() << endl;
	//}


	for (int i = 0; i < D; ++i)
	{
		int sat0 = x.Satisfaction();
		int q = x.Selection(i);
		for (int j = 0; j < 26; ++j)
		{
			x.Change(i, j);
			int sat1 = x.Satisfaction();
			if (sat1 > sat0)
			{
				sat0 = sat1;
				q = j;
			}
		}
		x.Change(i, q);
	}

	for (int i = 0; i < D; ++i)
	{
		cout << x.Selection(i) + 1 << endl;
	}
//	cout << x.Satisfaction() << endl;
}



int main()
{
	Heuristics_Introduction_A();
	return 0;
}


Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;


vector<int> par(100010); //親
vector<int> tree_rank(100010); // 木の深さ

//n要素で初期化
void init(int n) {
    rep(i,n) {
        par[i] = i;
        tree_rank[i] = 0;
    }
}

//木の根を求める
int find(int x) {
    if (par[x] == x) {
        return x;
    } else {
        return par[x] = find(par[x]);
    }
}

//xとyの属する集合を併合
void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;

    if (tree_rank[x] < tree_rank[y]) {
        par[x] = y;
    } else {
        par[y] = x;
        if (tree_rank[x] == tree_rank[y]) tree_rank[x]++;
    }
}

//xとyが同じ集合に属するか否か
bool same(int x, int y) {
    return find(x) == find(y);
}


int main(){ 

    Int N, M, K;
    cin >> N >> M >> K;
    vector<vector<Int>> friends(N);
    vector<vector<Int>> blocks(N);
    vector<Int> friend_of_friend(N,1);
    vector<Int> friend_of_friend2(N);
    vector<Int> kouho(N);

    init(N);

    rep(i,M) {
        Int a,b;
        cin >> a >> b;
        a--;
        b--;
        friends[a].push_back(b);
        friends[b].push_back(a);
        if (!same(a,b)) {
            Int x, y;
            x = friend_of_friend[find(a)];
            y = friend_of_friend[find(b)];
            unite(a,b);
            friend_of_friend[find(a)] = x + y;
        }
    }

    /*rep(i,N) cout << friend_of_friend[find(i)] << endl;*/

    rep(i,N) friend_of_friend2[i] = friend_of_friend[find(i)];

    rep(i,K) {
        Int c,d;
        cin >> c >> d;
        c--;
        d--;
        blocks[c].push_back(d);
        blocks[d].push_back(c);
        if (same(c,d)) {
            friend_of_friend2[c]--;
            friend_of_friend2[d]--;
        }
    }

    rep(i,N) kouho[i] = friend_of_friend2[i] - friends[i].size() - 1;

    rep(i,N-1) cout << kouho[i] << " ";
    cout << kouho[N-1] << endl;
}


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

int main() {
  // ここにプログラムを追記
  int a1;
  int s1;
  int s2;
  int s3;
  cin >> a1 ;
  s1 =a1 /100;
  s2 = (a1 - s1*100)/10;
  s3 = a1 - s1 * 100 - s2 * 10;
  cout << s1+s2+s3<< endl;
}


Measured memory_bytes: 256
V,E,Start = map(int,input().split())
INF = 10**20
Edge = []
D = [INF]*V
for _ in range(E):
    Edge.append(list(map(int,input().split())))

D[Start] = 0
while True:
    update = False
    for i in range(E):
        fr   = Edge[i][0]
        to   = Edge[i][1]
        cost = Edge[i][2]

        if D[fr] != INF and D[to] > D[fr] + cost:
            D[to] = D[fr] + cost
            update = True
    if update == False:
        break
for d in D:
    if d == INF:
        print('INF')
    else:
        print(d)



Measured memory_bytes: 114248
#include<algorithm>
#include<cstdio>
#define mxn 1000010
#define pii pair<int,int>
#define fr first
#define sc second
#define mp make_pair
#define LL long long
using namespace std;
const int mod=1e9+7;
int n,m,sl,fh,ans[1010][1010];
const int s4[4][4]={{1,1,3,1},
					{2,2,3,1},
					{1,3,2,2},
					{1,3,1,1}};
const int s5[5][5]={{1,1,3,1,1},
					{2,2,3,2,0},
					{0,1,1,2,1},
					{1,0,2,0,1},
					{1,0,2,3,3}};
const int s6[6][6]={{1,1,0,0,1,2},
					{2,2,0,0,1,2},
					{1,3,1,1,0,0},
					{1,3,2,2,0,0},
					{0,0,1,3,1,1},
					{0,0,1,3,2,2}};
const int s7[7][7]={{0,1,0,1,0,1,1},
					{0,1,3,1,0,0,0},
					{2,2,3,0,0,1,1},
					{1,4,4,0,2,0,0},
					{1,0,1,1,2,0,0},
					{2,0,0,3,3,0,2},
					{2,0,0,0,1,1,2}};
int rd()
{
	sl=0;fh=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch) {if(ch=='-') fh=-1; ch=getchar();}
	while('0'<=ch&&ch<='9') sl=sl*10+ch-'0',ch=getchar();
	return sl*fh;
}
int main()
{
	n=rd();
	if(n<=2) return puts("-1"),0;
	else if(n==3)
	{
		puts("aa.");
		puts("..a");
		puts("..a");
		return 0;
	}
	else
	{
		m=n%4+4;
		if(m==4)
			for(int i=0;i<4;++i)
				for(int j=0;j<4;++j)
					ans[i][j]=s4[i][j];
		if(m==5)
			for(int i=0;i<5;++i)
				for(int j=0;j<5;++j)
					ans[i][j]=s5[i][j];
		if(m==6)
			for(int i=0;i<6;++i)
				for(int j=0;j<6;++j)
					ans[i][j]=s6[i][j];
		if(m==7)
			for(int i=0;i<7;++i)
				for(int j=0;j<7;++j)
					ans[i][j]=s7[i][j];
		for(int i=m;i<n;i+=4)
			for(int x=0;x<4;++x)
				for(int y=0;y<4;++y)
					ans[i+x][i+y]=s4[x][y];
		for(int i=0;i<n;++i,puts(""))
			for(int j=0;j<n;++j)
				if(ans[i][j]) putchar(ans[i][j]+'a'-1);
				else putchar('.');
		return 0;
	}
	return 0;
}

Measured memory_bytes: 5120
#include <iostream>

int main()
{
    unsigned int a, b, c, d;
    std::cin >> a >> b >> c >> d;

    unsigned int area_ab { a * b }, area_cd { c * d};

    if (area_ab > area_cd) std::cout << area_ab << std::endl;
    else                   std::cout << area_cd << std::endl;

    // Another way (require <algorithm> header):
    // std::max(area_ab, area_cd);

    return 0;
}

Measured memory_bytes: 256
import heapq
n,m = map(int,input().split())
a=  list(map(int,input().split()))
h = list(map(lambda x:-1*x,a))
heapq.heapify(h)
for i in range(m):
    heapq.heapreplace(h,-(-h[0]//2))
print(-1*sum(h))

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

using namespace std;

using ll = long long;
using ull = unsigned long long;
using D = double;
using ld = long double;
using ii = pair<int, int>;
using vi = vector <int>;
using vii = vector <ii>;

#define pb push_back
#define re return 
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fi first
#define se second
#define re return
#define sz(x) ((int) x.size())
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rei(i, n) for (int i = 0; i < (n); i++) 

const int inf = 2e9;

int main() {
 	ios::sync_with_stdio(0);
 	cin.tie(NULL);
 	cout.tie(NULL);
	vector <string> a;
	a.pb("Sunny");
	a.pb("Cloudy");
	a.pb("Rainy");
	string s;
	cin >> s;
	int n = 3;
	for (int i = 0; i < n; i++) {
	 	if (a[i] == s) {
	 	 	cout << a[(i + 1) % 3];
	 	 	re 0;
	 	}
	}
 	re 0;
}


Measured memory_bytes: 256
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    
    if temp!=1:
        arr.append([temp, 1])
    
    if arr==[]:
        arr.append([n, 1])
    
    return arr

g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
MOD = 10**9+7
for i in range(2, 2*10**5):
    g1.append((g1[-1] * i) % MOD)
    inverse.append((-inverse[MOD % i] * (MOD // i)) % MOD)
    g2.append((g2[-1] * inverse[-1]) % MOD)

def memo_comb(n, r, mod=MOD):
    if r < 0 or r > n:
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n-r] % mod


N, M = map(int, input().split())
if M == 1:
  print(1)
  quit()

n = N - 1
fac_m = factorization(M)
ans = 1
for _, m in fac_m:
  ans *= memo_comb(m+n, n)
  ans %= MOD

print(ans)

Measured memory_bytes: 27092
#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first setprecision

#if MYDEBUG
#include "lib/cp_debug.h"
#else
#define DBG(...) ;
#endif

using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL  MOD=1E9+7;


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    long long n=0,a,b;
    cin >> n >> a >>b;
    if(n==1){
        cout << (a==b?1:0)<<"\n";
    }else{
        if(a>b){
            cout<< 0 <<"\n";
        }else{
            cout << 1+(n-2)*(b-a)<<"\n";
        }
    }

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ar array
 
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
 
	int a, b;
	cin >> a >> b;
	for(int i=1; i<=1e4; ++i) {
		int a2=i*8/100, b2=i*10/100;
		if(a2==a&&b2==b) {
			cout << i;
			return 0;
		}
	}
	cout << -1;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#include<stack>
#include<string.h>
#include <iomanip>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;
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,m;
	cin >> n >> m;
	vector<int>x(m);
	rep(i,m) cin >> x[i];
	sort(x.begin(),x.end());
	
	vector<int>dist(m-1);
	rep(i,m-1) {
		dist[i] = x[i+1]-x[i];
		
	}
	sort(dist.rbegin(),dist.rend());
	
	int ans = 0;
	for(int i = n-1;i<m-1;i++) {
		ans += dist[i];
	}
	cout << ans << endl;

}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
const int maxn=4e4+5,maxm=1e5+5;
const ll inf=1e18;
inline int fa(int u){ return u/2; }
inline int ls(int u){ return u*2; }
inline int rs(int u){ return u*2+1; }
struct heap{
	int hea[maxn],pos[maxn],siz;
	ll *dis;
	heap(ll a[],int n){
		dis=a; siz=n;
		int i;
		for (i=1;i<=n;i++){
			dis[i]=inf; hea[i]=i; pos[i]=i;
		}
	}
	void hswap(int u,int v){
		swap(hea[u],hea[v]);
		pos[hea[u]]=u; pos[hea[v]]=v;
	}
	void update(int u){
		if (u==1) return;
		if (dis[hea[fa(u)]]<=dis[hea[u]]) return;
		hswap(u,fa(u));
		update(fa(u));
	}
	void pushdown(int u){
		int v=u;
		if (ls(u)<=siz&&dis[hea[ls(u)]]<dis[hea[v]]) v=ls(u);
		if (rs(u)<=siz&&dis[hea[rs(u)]]<dis[hea[v]]) v=rs(u);
		if (u==v) return;
		hswap(u,v);
		pushdown(v);
	}
	void change(int u,ll val){
		dis[u]=val;
		update(pos[u]);
		pushdown(pos[u]);
	}
	int pop(){
		hswap(1,siz);
		siz--;
		pushdown(1);
		return hea[siz+1];
	}
};
struct gragh{
	int head[maxn],next[maxm],to[maxm],tot;
	ll wei[maxm],cost[maxn];
	gragh(){
		memset(head,-1,sizeof(head));
		tot=0;
	}
	void clear(){
		memset(head,-1,sizeof(head));
		tot=0;
	}
	void add(int u,int v,ll w,ll c){
		next[tot]=head[u];
		head[u]=tot;
		to[tot]=v;
		wei[tot]=w;
		cost[tot]=c;
		tot++;
	}
	void dijkstra(ll dis[],ll val[],int st,int n){
		heap hp(dis,n);
		hp.change(st,0);
		int i,u,v,ed;
		for (i=1;i<=n;i++) val[i]=inf;
		val[st]=0;
		while (hp.siz){
			u=hp.pop();
			for (ed=head[u];ed!=-1;ed=next[ed])
				if (dis[v=to[ed]]>dis[u]+wei[ed])
					hp.change(v,dis[u]+wei[ed]);
		}
		for (u=1;u<=n;u++) for (ed=head[u];ed!=-1;ed=next[ed])
			if (dis[v=to[ed]]==dis[u]+wei[ed])
			val[v]=min(val[v],cost[ed]);
	}
};
gragh g;
ll dis[maxn],val[maxn];
int main(){
	int n,m,i,u,v;
	ll w,c,ans;
	while (scanf("%d%d",&n,&m)&&(n||m)){
		g.clear();
		for (i=0;i<m;i++){
			scanf("%d%d%lld%lld",&u,&v,&w,&c);
			g.add(u,v,w,c);
			g.add(v,u,w,c);
		}
		g.dijkstra(dis,val,1,n);
		ans=0;
		for (i=1;i<=n;i++) ans+=val[i];
		printf("%lld\n",ans);
	}
	return 0;
}


Measured memory_bytes: 4548
'use strict'

const main = (INPUT) => {
  const [A, B] = INPUT.split('\n')[0].split(' ').map(n => Number(n))
  const ans = A + B
  console.log(ans >= 10 ? 'error' : ans)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


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

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

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  string S;
  ll K;
  cin >> S;
  cin >> K;

  string ans = "";
  for(char c: S){
    if(c == 'a'){
      ans += "a";
    } else {
      ll tmp = 'z' - c + 1;
      if(K >= tmp){
        K -= tmp;
        ans += "a";
      } else {
        ans += c;
      }
    }
  }
  if(K > 0){
    char c = ans[ans.size()-1];
    K %= 26;
    char add;
    if('z' - c >= K){
      add = c + K;
    } else { 
      K -= 'z' - c - 1;
      add = 'a' + K;
    }

    ans[ans.size()-1] = add;
  }
  cout << ans << endl;

}


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

int main(){
    int S;
    int h;
    int m;
    int s;

    cin >> S;

    h = S / 3600;
    m = ( S - h * 3600 ) / 60;
    s = S - h * 3600 - m * 60;

    cout << h << ":" << m << ":" << s << endl;
}

Measured memory_bytes: 1164
#include"bits/stdc++.h"
#include<valarray>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
 

#define MAX 200002

int n;
long long int k;

vector<int> v;

map<long long int,int> mp;

long long int len[MAX];

vector<int> c;

set<int> ex;

bool us[MAX];
vector<int> ret;
void make(int star,long long int A){
	while(A--){
		if(us[v[star]]){
			while(true){
				us[ret.back()]=false;
				int z=ret.back();
				ret.pop_back();
				if(z==v[star]){
					break;
				}
			}
		}
		else{
			us[v[star]]=true;
			ret.push_back(v[star]);
		}
		star++;
		star%=n;
	}
	for(int i=0;i<ret.size();i++){
		if(i)printf(" ");
		printf("%d",ret[i]);
	}
	puts("");
	exit(0);
}

int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++){
		int a;
		scanf("%d",&a);
		v.push_back(a);
	}
	for(int i=0;i<n;i++){
		v.push_back(v[i]);
	}
	for(int i=v.size()-1;i>=0;i--){
		if(i<n){
			int nex=mp[v[i]];
			nex++;
			len[i]=nex-i;
		}
		mp[v[i]]=i;
	}
	int pos=0;
	long long int len2=0;
	long long int A=n*k;
	while(true){
		ex.insert(pos);
		c.push_back(pos);
		if(A-len[pos]<=0){
			make(pos,A);
		}
		len2+=len[pos];
		A-=len[pos];
		pos+=len[pos];
		pos%=n;
		if(ex.count(pos)==0){
			continue;
		}
		long long int w=len2;
		for(int j=0;j<c.size();j++){
			if(c[j]==pos)break;
			w-=len[pos];
		}
		A%=w;
		if(A<n){
			make(pos,A);
		}
		break;
	}
	len2=0;
	ex.clear();
	c.clear();
	while(true){
		ex.insert(pos);
		c.push_back(pos);
		if(A-len[pos]<=0){
			make(pos,A);
		}
		len2+=len[pos];
		A-=len[pos];
		pos+=len[pos];
		pos%=n;
		if(ex.count(pos)==0){
			continue;
		}
		long long int w=len2;
		for(int j=0;j<c.size();j++){
			if(c[j]==pos)break;
			w-=len[pos];
		}
		A%=w;
		make(pos,A);
		break;
	}
	return 0;
}


Measured memory_bytes: 26224
#include <stdio.h>

int main() {
  int A;
  int B;
  int C;
  int D;
  

  scanf("%d %d %d %d", &A, &B, &C, &D);
  if(A<B) {
	  if(C < D) {
       printf("%d\n",A+C);
	  }
	  else {
	   printf("%d\n",A+D);
	  }  
  } 
  else {
	  if(C < D) {
       printf("%d\n",B+C);
	  }
	  else {
	   printf("%d\n",B+D);
	  }
  }

  return 0;
  
  
  
  
  
  
}

Measured memory_bytes: 128
// I/O
#include <iostream>
#include <iomanip>

// data structures
#include <set>
#include <queue>
#include <vector>

// manipulations
#include <algorithm>

#define rep(i,n) for(int i=0;i< (n);++i)
#define REP(i,n) for(int i=1;i<=(n);++i)
#define for_lowercase(c) for(int c='a';c<='z';++c)
#define for_uppercase(c) for(int c='A';c<='Z';++c)
#define ALL(a) (a).begin(),(a).end()
using LLI = long long int;
LLI GCD(LLI a,LLI b){ if(a<b) return GCD(b,a); else if(a%b==0) return b; else return GCD(b,a%b); }
LLI LCM(LLI a,LLI b){ return (a/GCD(a,b))*b; }
using VI  = std::vector<LLI>;
using PI  = std::pair<LLI,LLI>;
using VVI = std::vector<VI>;
using VPI = std::vector<PI>;
template<class T> bool is_odd (T x){ return   x%2 ; }
template<class T> bool is_even(T x){ return !(x%2); }
LLI combination(LLI n,LLI k,bool reset=false){
    static VVI C; static LLI n_hashed = -1;
    if(n<0){ std::cerr << "[ERROR] n must be non-negative in combination()" << std::endl; exit(1); }
    if(!(0<=k&&k<=n)){ std::cerr << "[WARNING] k should be in range [0,n] in combination()" << std::endl; return 0; }
    if(n_hashed<n || reset){
        C.resize(n+1);
        for(int i=0;i<=n;++i) C[i].resize(i+1,1); // filled with 1
        for(int i=1;i<=n;++i)for(int j=1;j<i;++j) C[i][j] = C[i-1][j-1] + C[i-1][j];
        n_hashed = n;
    }
    return C[n][k];
}

int main() {
    std::ios::sync_with_stdio(false);

    LLI X;
    std::cin >> X;

    LLI ans = 1;
    while(ans*(ans+1)<2*X) ++ans;
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 256
a, b, c, d = [int(i) for i in input().split()]

def calc():
    if a <= c:
        if b < c:
            return 0
        if b >= d:
            return (d - c)
        return b - c
    else:
        if d < a:
            return 0
        if d >= b:
            return b - a
        return d - a

print(calc())


Measured memory_bytes: 2940
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
 
namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			var ny = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
			int n = ny[0];
			int y = ny[1];

			int yy = y / 1000;
			for (int i = 0; i <= yy; i++) {
				for (int j = 0; j <= yy; j++) {
					int k = n - i - j;
					if (k < 0) {
						continue;
					}

					long sum = 1000L * i + 5000L * j + 10000L * k;
					if (sum == y) {
						Console.WriteLine($"{k} {j} {i}");
						return;
					}
				}
			}

			Console.WriteLine($"{-1} {-1} {-1}");
		}		
	}
}

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

const int di[] = { 0, 1,-1, 0};
const int dj[] = { 1, 0, 0,-1};
int main() {
	// input
	int h,w;
	cin >> h >> w;
	int si,sj;
	cin >> si >> sj;
	int ti,tj;
	cin >> ti >> tj;
	si--;	sj--;	ti--;	tj--;
	vector<string> s(h);
	rep(i,h) cin >> s[i];
	const int INF = 1e9;
	vector<vector<int>> dist(h, vector<int>(w, INF));
	deque<P> q;
	dist[si][sj] = 0;
	q.emplace_back(si,sj);
	while(!q.empty()) {
		int i = q.front().first;
		int j = q.front().second;
		int d = dist[i][j];
		q.pop_front();
		rep(v,4) {
			int ni = i+di[v], nj = j+dj[v];
			if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
			if (s[ni][nj]=='#')	continue;
			if (dist[ni][nj] <= d) continue;
			dist[ni][nj] = d;
			// printf("nx: %d, ny: %d,cost: %d\n",nx,ny,d[ny][nx]);
			q.emplace_front(ni,nj);
		}
		for (int ei = -2; ei <= 2; ++ei) {
			for (int ej = -2; ej <= 2; ++ej) {
				int ni = i+ei, nj = j+ej;
				if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
				// printf("B nx: %d, ny: %d, s: %c\n", nx, ny, s[ny][nx]);
				if (s[ni][nj]=='#') continue;
				if (dist[ni][nj] <= d+1) continue;
				dist[ni][nj] = d+1;
				q.emplace_back(ni,nj);
			}
		}
	}
	int ans = dist[ti][tj];
	if (ans == INF ) ans = -1;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 9548
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
//#define int long long
//#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
char toSmall(char c) { // 大文字を小文字へ
    return (c + 0x20);
}
char toLarge(char c) { // 小文字を大文字へ
    return (c - 0x20);
}
float myPower(int a, int n) { // aのn乗の計算
    float x = 1;
    while (n > 0) { // 全てのbitが捨てられるまで
        if (n & 1) { // 一番右のbitが１のとき
            x *= a;
        }
        a *= a;
        n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
    }
    return x;
}
int a, b;
int main(void) {
    cin >> a >> b;
    cout << (a + b) % 24 << endl;
    return 0;
}

Measured memory_bytes: 3604
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int A = in.nextInt();
        int B = in.nextInt();

        System.out.println(A * B);
        in.close();
    }
}

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

using namespace std;

const int N = 1e6 + 6;

// int lis[N], lcs[N];
int ans[N];
int main() {
  int n;
  scanf("%d", &n);
  // map<pair<int, int>, vector<int> > mp;
  // vector<int> v;
  // for (int i = 0; i < n; ++i)
  //   v.push_back(i);
  // do {
  //   int a = 0, b = 0;
  //   for (int i = 0; i < n; ++i) {
  //     int r = lower_bound(lis, lis+a, v[i]) - lis;
  //     lis[r] = v[i];
  //     a += r == a;
  //     r = lower_bound(lcs, lcs+b, -v[i]) - lcs;
  //     lcs[r] = -v[i];
  //     b += r == b;
  //   }
  //   mp[make_pair(a, b)] = v;
  // } while (next_permutation(v.begin(), v.end()));
  // for (auto it : mp) {
  //   cout << it.first.first << " & " << it.first.second << endl;
  //   for (int x : it.second)
  //     cout << x << " ";
  //   cout << endl;
  // }
  int a, b;
  scanf("%d %d", &a, &b);
  if (a + b > n+1) {
    puts("-1");
    return 0;
  }
  if ((n + a - 1) / a > b) {
    puts("-1");
    return 0;
  }
  int k = 0;
  while (1) {
    int cnt = k + (n-k + a-1)/a;
    if (cnt >= b)
      break;
    ++k;
  }
  int now = 0;
  for (int i = 0; i < k; ++i)
    ans[i] = n-i;
  for (int i = n-1; i >= k; i -= a) {
    for (int j = max(k, i-a+1); j <= i; ++j)
      ans[j] = ++now;
  }
  for (int i = 0; i < n; ++i)
    printf("%d%c", ans[i], i == n-1 ? '\n' : ' ');
  return 0;
}

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

int gcd(int x, int y){
  if(y==0) return x;
  return gcd(y, x%y);
}

int main()
{
  long a,b;
  long res=0;
  cin >> a >> b;

  res = a*b / gcd(a,b);

  cout << res << endl;
}


Measured memory_bytes: 256
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, N);
    string ans;
    ll x = 26;
    ll k = 1;
    while (N > x)
    {
        N -= x;
        x *= 26;
        ++k;
    }
    --N;
    REP(i, k)
    {
        ans.insert(ans.begin(), 'a' + N % 26);
        N /= 26;
    }
    OUT(ans);
}


Measured memory_bytes: 3608
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <set>
#include <vector>
#include <cmath>
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;


int main(){
  double n,m,d;
  cin>>n>>m>>d;

  double t=(n-(d));
  double res=0.0;
  res=t*((double)m-1.0)/pow(n,2)*2.0;
  if(d==0) res/=2.0;

  printf("%.10f\n",res);

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <cassert>
#include <algorithm>
using namespace std;

const long long mod = 1e9+7;

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int N, M;
  cin >> N >> M;
  int Gate_L = 0, Gate_R = 1e7;
  for(int i = 0; i < M; i++) {
    int L, R;
    cin >> L >> R;
    Gate_L = max(Gate_L, L);
    Gate_R = min(Gate_R, R);
  }

  if(Gate_L <= Gate_R) {
    cout << Gate_R - Gate_L + 1 << endl;
  }
  else {
    cout << 0 << endl;
  }

  return 0;
}


Measured memory_bytes: 3640
#include<stdio.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
int max(int a,int b){return (a<b)?b:a;}
int main(void)
{
  int N,M,A,B,count,H[100001]={0},peak[100001]={0};
  count=scanf("%d %d",&N,&M);
  rep(i,N)count=scanf("%d",&H[i]);
  rep(i,M){count=scanf("%d %d",&A,&B);A--,B--;peak[A]=max(peak[A],H[B]);peak[B]=max(H[A],peak[B]);}
  count=0;
  rep(i,N)count+=H[i]>peak[i];
  return printf("%d\n",count),0;
}

Measured memory_bytes: 2472
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(long long i = 0; i < (long long)(N); i++)
#define repr(i,N) for(long long i = (long long)(N) - 1; i >= 0; i--)
#define rep1(i,N) for(long long i = 1; i <= (long long)(N) ; i++)
#define repr1(i,N) for(long long i = (N) ; (long long)(i) > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; template<class T = ll> using V = vector<T>;
using vi = V<int>; using vl = V<>; using vvi = V< V<int> >;
constexpr int inf = 1001001001; constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif

using P = pair<int,int>; using vp = V<P>;
constexpr int MOD = /**/ 1000000007; //*/ 998244353;
//////////

void solve(){
  ini(N , Q);
  vl cnt(N + 1 , 0);
  ll ac = 0 , wa = 0;
  rep(i , Q){
    ini(N); ins(S);
    if(S == "AC"){
      if(cnt[N] == -1) continue;
      ac ++; wa += cnt[N] ; cnt[N] = -1;
    }
    else {
      if(cnt[N] == -1) continue;
      cnt[N]++;
    }
  }
  out(ac , wa);
}

Measured memory_bytes: 1024
from functools import reduce
from fractions import gcd
import sys
input = sys.stdin.readline


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    M = max(A)
    G = reduce(gcd, A)
    if K<=M and K%G==0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")   


if __name__ == '__main__':
    main()

Measured memory_bytes: 84332
#include<iostream>

using namespace std;

#define MOD 1000000007L

typedef long long ll;

ll factorialCache[2000010];
ll factorialInverseCache[2000010];

ll add(ll a, ll b) {
  return (a + b) % MOD;
}

ll sub(ll a, ll b) {
  return (a - b + MOD) % MOD;
}

ll mul(ll a, ll b) {
  return (a * b) % MOD;
}

ll pow(long a, long b) {
  if (b == 0) {
    return 1;
  }
  long v = pow(mul(a, a), b / 2);
  if (b % 2 == 1) {
    return mul(v, a);
  } else {
    return v;
  }
}

ll inverse(long a) {
  return pow(a, MOD - 2);
}

ll getC(int n, int k) {
    return mul(factorialCache[n], mul(factorialInverseCache[k], factorialInverseCache[n-k]));
}

ll solve(int r1, int c1, int r2, int c2) {
    factorialCache[0] = 1;
    factorialInverseCache[0] = 1;
    for (int i = 1; i <= r2 + c2; i++) {
      factorialCache[i] = mul(i, factorialCache[i - 1]);
      factorialInverseCache[i] = inverse(factorialCache[i]);
    }
    
    
    long answer = 0;
    long pathCount = getC(r1 + c1, r1);
    answer = add(answer, pathCount);
    for (int i = r1 + c1 + 1; i <= r2 + c2; i++) {
//      System.err.println(answer);
      
      pathCount = mul(pathCount, 2);
      if (i - r1 <= c2) {
        pathCount = add(pathCount, getC(i - 1, r1 - 1));
      } else {
        pathCount = sub(pathCount, getC(i - 1, c2));
      }
      if (i - c1 <= r2) {
        pathCount = add(pathCount, getC(i - 1, c1 - 1));
      } else {
        pathCount = sub(pathCount, getC(i - 1, r2));
      }
//      System.err.printf("pathCount: %d\n", pathCount);
      
      answer = add(answer, pathCount);
    }
    return answer;
}

int main() {
  int r1, c1, r2, c2;
  cin >> r1 >> c1 >> r2 >> c2;
  cout << solve(r1, c1, r2, c2) << endl;
}


Measured memory_bytes: 31488
s = list(map(int,list(input())))
k = int(input())

li = [2,3,4,5,6,7,8,9]
ans = 1
for i in range(len(s)):
    if k == i+1:
        ans = s[i]
        break
    if s[i] in li:
        ans = s[i]
        break
print(ans)


Measured memory_bytes: 3060
N , K = map(int,input().split())

sushi = []

for _ in range(N) :
    t, d = map(int,input().split())
    sushi.append((t,d))

sushi.sort(key=lambda A : A[1], reverse=True)

# 美味しいものから順にK個選ぶ
nowSushi = []
sumTaste = 0
numKind = 0
take = [0] * N  # 種類は高々N

for i in range(K) :
    t, d = sushi[i]
    nowSushi.append((t,d))
    sumTaste += d
    if take[t-1] == 0 :
        numKind += 1
    take[t-1] += 1

addSushi = []  # 種類を増やせる寿司
for i in range(K,N) :
    t, d = sushi[i]
    if take[t-1] > 0 :  # すでに選択済み
        continue
    addSushi.append((t,d))
    take[t-1] += 1

ans = sumTaste + numKind**2
L = len(addSushi)
changeCount = 0

while nowSushi :
    removeSushiT, removeSushiD = nowSushi.pop()
    if take[removeSushiT-1] <= 1 :
        continue
    if changeCount >= L :
        break

    addSushiT, addSushiD = addSushi[changeCount]
    changeCount += 1

    sumTaste = sumTaste - removeSushiD + addSushiD
    numKind = numKind + 1

    if (sumTaste + numKind**2) > ans :
        ans = sumTaste + numKind**2

print(ans)

Measured memory_bytes: 24348
// ORZ YJZ
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define rep(i,a,b) for(int (i) = (a); (i) <= (b); i++)
#define repd(i,a,b) for(int (i) = (a); (i) >= (b); i--)
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++)
#define mp make_pair
#define pb push_back
using namespace std;
#define is_digit(c) ((c) >= '0' && (c) <= '9')
#define is_upper(c) ((c) >= 'A' && (c) <= 'Z')
#define is_lower(c) ((c) >= 'a' && (c) <= 'z')
#define readchar() ((char)fgetc(stdin))
#define printchar(c) fputc((c), stdout)
void readline(char *s) {int len=0;char c;for(c=readchar(); c!='\n'; s[len++]=c, c=readchar());s[len]=0;}
void readstr(char *s) {int len=0;char c;for(c=readchar(); c!=' '&&c!='\n'; s[len++]=c, c=readchar());s[len]=0;}
void printstr(const char *s) {int len=strlen(s);rep(i,0,len-1) printchar(s[i]);}
void to_lower(char *s, int L, int R) {rep(i,L,R) if (is_upper(s[i])) s[i]=s[i]-'A'+'a';}
void to_upper(char *s, int L, int R) {rep(i,L,R) if (is_lower(s[i])) s[i]=s[i]-'a'+'A';}
ll readll() {
	char c;ll ans=0, x=1;for (c=readchar(); !is_digit(c)&&c!='-'; c=readchar());
	if (c=='-') x=-1, c=readchar();for (; is_digit(c); ans=ans*10+c-'0', c=readchar());return ans*x;
}
void printll(ll x) {
	int a[25], cnt=0;if (x==0) { printchar('0'); return; }if (x<0) printchar('-'), x=-x;
	for (; x; a[cnt++]=x-x/10*10, x/=10);repd(i,cnt-1,0) printchar(a[i]+'0');
}
#define readint() ((int)readll())
#define printint(x) printll((ll)(x))
int n;
ll a[100005], b[100005];
int main() {
	n=readint();
	rep(i,1,n) a[i]=readint(),b[i]=readint();
	ll nw=0, ans=0;
	repd(i,n,1) {
		ll x=nw+a[i], y=((x+b[i]-1)/b[i])*b[i];
//		cerr<<x<<" "<<y<<endl;
		nw+=y-x;
		ans+=y-x;
	}
	printll(ans);
	return 0;
}


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

int main(void) {
    int N,K;cin>>N>>K;
    vector<int> p(N);
    for (int i = 0; i < N; i++) {
        cin >> p[i];
    }
    sort(p.begin(),p.end());
    int result = 0;
    for (int i = 0; i < K; i++) {
        result += p[i];
    }
    cout << result << endl;
    return 0;
}

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

int main() {
  ll n; cin >> n;
  vector<ll> a(n); rep(i, n) cin >> a[i];
  ll t = a[0]; 
  for (int i = 1; i < n; i++) {
    t ^= a[i];
  }
  rep(i, n) {
    cout << (t ^ a[i]) << endl;
  }
  return 0;
}

Measured memory_bytes: 4752
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		String n = sc.next();
		int s = 0;
		for (int i = 0; i < n.length(); i++) {
			s += n.charAt(i) - '0';
		}
		if (Integer.parseInt(n) % s == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 21716
n = gets.to_i
index = {}
input = gets.strip.split(' ').each{|v|
    index[v] = 0 if index[v].nil?
    index[v] += 1
}
sum = 0
index.each_pair{|key, val|
    sum += key.to_i * val
}

c = gets.to_i
c.times{|i|
    from, to = gets.strip.split(' ')
    froms = index.delete(from)
    unless froms.nil?
        index[to] = 0 if index[to].nil?
        index[to] += froms
        new_sum = sum + (to.to_i - from.to_i) * froms
        sum = new_sum
    end
    puts sum
}

Measured memory_bytes: 32360
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int x;
bool a[1001];
int main()
{
	a[1]=true;
	scanf("%d",&x);
	for (int i=2;i<=31;i++)
	{
		int j=i;
		while (j*i<=x)
		{
			j=j*i;
			a[j]=true;
		}
	}
	for (int i=x;i>0;i--)
		if (a[i])
		{
			printf("%d",i);
			break;
		}
//	system("pause");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <functional>

using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
int A[500000];
int acum[500001];
bool S[500001];
int zero[500001];
long DP[500001];
long DP2[500001];
vector<pair<int,int>> Data;
void Calc(){
	int N = rei();
	for(int i=0;i<N;i++){
		A[i] = rei();
	}
	for(int i=0;i<N;i++){
		acum[i+1] = acum[i] ^ A[i];
	}
	if(acum[N] == 0){
		int z = 0;
		for(int i=0;i<=N;i++){
			if(acum[i] == 0){
				z++;
			}
			else{
				Data.push_back({acum[i],i});
			}
			zero[i] = z;
		}
		sort(Data.begin(),Data.end());
		long ans = 1;
		for(int i=0;i<z-2;i++){
			ans <<= 1;
			ans %= mod;
		}
		int p = 0;
		while(p < Data.size()){
			long c = 1;
			long d = 1;
			while(p+1 < Data.size() && Data[p].first == Data[p+1].first){
				p++;
				d += c * (zero[Data[p].second] - zero[Data[p-1].second]);
				d %= mod;
				c += d;
				c %= mod;
			}
			p++;
			ans += c;
			ans %= mod;
		}
		cout << ans << endl;
	}
	else{
		int c = 0;
		for(int i=0;i<=N;i++){
			if(acum[i] == 0){
				S[c++] = false;
			}
			else if(acum[i] == acum[N]){
				S[c++] = true;
			}
		}
		DP[0] = 1;
		for(int i=1;i<c;i++){
			if(S[i]){
				DP[i] = DP[i-1];
				DP2[i] = (DP[i-1] + DP2[i-1]) % mod;
			}
			else{
				DP[i] = (DP[i-1] + DP2[i-1]) % mod;
				DP2[i] = DP2[i-1];
			}
		}
		cout << DP[c-1] << endl;
	}
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 14464
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
#else
	#define DBG(X)
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline void goodbye(const T& val) { cout << val << endl; exit(0); }

const int MAXN = 543;

ll D[MAXN][MAXN], L;
int n, m;

void init() {
	for(int i = 0; i < MAXN; ++i) {
		for(int j = 0; j < MAXN; ++j) {
			D[i][j] = (i == j ? 0 : LL_INF);
		}
	}
}

void floyd() {
	for(int mid = 0; mid < n; ++mid) {
		for(int v = 0; v < n; ++v) {
			if(D[v][mid] == LL_INF) {
				continue;
			}

			for(int u = 0; u < n; ++u) {
				if(D[mid][u] == LL_INF) {
					continue;
				}

				D[v][u] = min(D[v][u], D[v][mid] + D[mid][u]);
			}
		}
	}
}

void solve() {
	cin >> n >> m >> L;

	for(int i = 0; i < m; ++i) {
		int v = fetch<int>() - 1;
		int u = fetch<int>() - 1;
		ll  c = fetch<ll>();

		D[v][u] = min(D[v][u], c);
		D[u][v] = min(D[u][v], c);
	}

	floyd();

	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < n; ++j) {
			if(i == j) {
				D[i][j] = 0;
			} else {
				D[i][j] = (D[i][j] <= L ? 1 : LL_INF);
			}
		}
	}

	floyd();

	for(int q = fetch<int>(); q > 0; --q) {
		int s = fetch<int>() - 1;
		int t = fetch<int>() - 1;

		cout << (D[s][t] == LL_INF ? -1 : D[s][t] - 1) << '\n';
	}
}

int main() {
	fast_io();

	init();
	solve();

	return 0;
}


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

int main() {
    int A,B,C=0; cin>>A>>B>>C;
    bool can=false;
    for(int i=0;i<1000;i++){
        if(i*A%B==C){
            can=true;
        }
    }
    if(can)cout<<"YES";
    else cout<<"NO";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(){
  int n,m;
  int x;
  int score=0;
  cin >>n>>m;
  for(int i=0;i<m;i++){
	cin >>x;
    score+=x;
  }
  if (score<=n){
    cout<<n-score<<endl;
  }
  else{
    cout<<"-1"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3636