akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int mod=998244353;
const int N=3e5+5;
const int inf=1e9+7;
ll da[N],bo[N];

int main()
{

    int n,p,q,s,x;
    scanf("%d",&n);
    for(int i=0; i<n; i++){
        scanf("%lld",&da[i]);
        bo[da[i]]++;
    }

    ll ans=0;
    for(int i=1;i<=n;i++){
        ans+=bo[i]*(bo[i]-1)/2;
    }
    for(int i=0; i<n; i++){
        ll tmp = ans - bo[da[i]]*(bo[da[i]]-1)/2 + (bo[da[i]]-1)*(bo[da[i]]-2)/2;
        printf("%lld\n",(tmp));
    }

    return 0;
}


Measured memory_bytes: 5248
// ABEY SAALE
// QUESTION KHUD KR SOLUTION KYU DEKH RHA H
 
 
 
 
 
 
 
 
//MAAF KIJIYEGA ME GUSSE ME IDHAR UDHAR NIKAL JATA HU
#include<bits/stdc++.h>
#define mod 1000000007
#define fr first
#define se second
#define ll long long
#define PI 3.1415926535 
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define senky_bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;

ll fac[2000005];
void pre(){ fac[0]=1; fac[1]=1; for(int i=2;i<200005;i++) fac[i]=(i*fac[i-1])%mod;}
ll power(ll a,ll b){ll res=1;while(b){if(b&1) res=(res*a)%mod;a=(a*a)%mod;b=b/2;}return res%mod;}
ll ncr(ll n,ll r){return ((fac[n]*power(fac[r],mod-2))%mod*power(fac[n-r],mod-2))%mod;}
// DEKHIYE JI  WALID JO THE ABBA HAMARE WO YEH function CHHOD KR GYE THE

signed main()
{   



      
      senky_bansal
      IIIT_ALLAHABAD
      
      // pre();
      ll t;
      // cin>>t;
      t=1;
      while(t--)
      { 
        ll a,b;
        cin>>a>>b;
        cout<<a*b/__gcd(a,b);
         

      }
      






}












Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    ll n,m,s=0;
    cin>>n;
    m=n;
    while(m>0){
        s+=m%10;
        m/=10;
    }
    if(n%s==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

    return 0;
}


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

int main(){
    string s; cin >> s;
    int N=s.size(), cnt=0;
    for(int i=0;i<N;i++){
        if(s[i]=='p') cnt++;
    }
    cout << N/2-cnt << endl;
    return 0;
}

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


class StringSearch {
	const int n;
	string S;
	vector<int> SA, Rank;
public:
	StringSearch(const string &S_)
		: n(S_.size()), S(S_), SA(n + 1), Rank(n + 1)
	{
		for (int i = 0; i <= n; i++) {
			SA[i] = i;
			Rank[i] = i < n ? S[i] : -1;
		}

		vector<int> tmp(n + 1);
		for (int k = 1; k <= n; k *= 2) {
			auto Compare_SA = [=](int i, int j) {
				if (Rank[i] != Rank[j]) return Rank[i] < Rank[j];
				else {
					int ri = i + k <= n ? Rank[i + k] : -1;
					int rj = j + k <= n ? Rank[j + k] : -1;
					return ri < rj;
				}
			};
			sort(SA.begin(), SA.end(), Compare_SA);

			tmp[SA[0]] = 0;
			for (int i = 1; i <= n; i++) {
				tmp[SA[i]] = tmp[SA[i - 1]] + (Compare_SA(SA[i - 1], SA[i]) ? 1 : 0);
			}
			for (int i = 0; i <= n; i++) {
				Rank[i] = tmp[i];
			}
		}
	}

	bool Contain(const string &T) {
		int a = 0, b = n;
		while (b - a > 1) {
			int c = (a + b) / 2;
			if (S.compare(SA[c], T.length(), T) < 0) a = c;
			else b = c;
		}
		return S.compare(SA[b], T.length(), T) == 0;
	}
};

int main()
{
	int Q;
	string T, P;
	cin >> T;
	StringSearch SS(T);
	cin >> Q;
	while (Q--) {
		cin >> P;
		cout << SS.Contain(P) << endl;
	}
	return 0;
}

Measured memory_bytes: 16524
#include<bits/stdc++.h>
#include<math.h>
#include<vector>
#include <iostream>
#include <algorithm>
#include <limits>
using namespace std;
/*void search(int nowleft,int num){
	if(num==K-1){
		long long xmax = numeric_limits<long long>::max();
		long long ymax = numeric_limits<long long>::max();
		long long xmin = numeric_limits<long long>::min();
		long long ymin = numeric_limits<long long>::min();
		for(int i=0;i<K;i++){
			xmax = max(xmax,x[record[i]]);
			ymax = max(ymax,y[record[i]]);
			xmin = min(xmin,x[record[i]]);
			ymin = min(ymin,y[record[i]]);
		}
		minarea =min(minarea,(xmax-xmin)*(ymax-ymin));
		return
	}else{
		record[num] = nowleft;
		for(int i=nowleft+1;i<=N-(K-num)-1;i++){
			search(i,num+1);
		}
	}
	return;
}*/
int main(void){
	int K,N,ncount;
	long long minarea;
	int i,j,Q,W,M,R;
	cin >> N >> K;
	long long x[N],y[N],x2[N],y2[N];
	for(i=0;i<N;i++){
		cin >> x[i] >> y[i];
		x2[i] = x[i];
		y2[i] = y[i];
	}
	/*for(i=0;i<N;i++){
		record[i] = false;
	}*/
	//search(0,0);
	for(i=0;i<N-1;i++){
		for(j=N-1;j>i;j--){
			if(x[j]<x[j-1]){
				swap(x[j],x[j-1]);
				//cout << j << endl;
			}
		}
	}
	for(i=0;i<N-1;i++){
		for(j=N-1;j>i;j--){
			if(y[j]<y[j-1]){
				swap(y[j],y[j-1]);
				//cout << j << endl;
			}
		}
	}
	minarea =(x[N-1]-x[0])*(y[N-1]-y[0]);
	for(int xi=0;xi<N;xi++){
		for(int xj=xi+1;xj<N;xj++){
			for(int yi=0;yi<N;yi++){
				for(int yj=yi+1;yj<N;yj++){
					ncount =0;
					for(i=0;i<N;i++){
						if(x2[i]>=x[xi]&&x2[i]<=x[xj]&&y2[i]>=y[yi]&&y2[i]<=y[yj]){
							ncount +=1;
						}
					}
					if(ncount>=K){
						minarea=min(minarea,(x[xj]-x[xi])*(y[yj]-y[yi]));
					}
				}
			}
		}
	}
	cout << minarea <<endl;
	return 0;
}

Measured memory_bytes: 256
#include  <bits/stdc++.h>
using namespace std;
#define ll long long
int main ()
{
   ll a,b,c,s;
   cin>>a>>b;
   s=0;
   while (b--)
{
   cin>>c;
   s+=c;
}
 if (s>=a)  cout <<"Yes" <<endl;
 else cout <<"No" <<endl;
return 0;
}

Measured memory_bytes: 256
n=int(input())
lista = [int(i) for i in input().split()]

list0 = [0]*30
list1 = [0]*30

for mm in range(n):
    m = lista[mm]
    bin_str = format(m, '030b')
    #print(bin_str)

    for i in range(30):
        t = bin_str[i]
        if t == "1":
            list1[i] += 1
        else:
            list0[i] += 1

#print(list0)
#print(list1)

ans = "Yes"
for i in range(30):
    if list1[i]==0:
        continue
    
    num0 = list0[i]
    num1 = list1[i]
    if num0*2 != num1:
        ans = "No" 
        break
print(ans)

Measured memory_bytes: 60784
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N; cin>>N;
  vector<int>A(N);
  long long count=0;
  long long ans=0;
  for(int i=0;i<N;i++){
    cin>>A[i];
    if(count<A[i])count=A[i];
    else ans+=count-A[i];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4044
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
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; }
//const ll INF = 1LL << 60;
//const int INF = 1001001001;

int main(void){
    int r;
    cin >> r;
    cout << r*r;

    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <cmath>
#include <utility>
#include <string>

using namespace std;

int main(){

    int A,B,C,X = 0;
    cin >> A >> B >> C >> X;

    if(!(X % 50 == 0)){
        std::cout << 0 << std::endl;
        return 0;
    }

    int total = 0;

    for(int i = 0; i <= A; i++){
        for(int j = 0; j <= B; j++){
            for(int k = 0; k <= C; k++){
                if(X == 500 * i + 100 * j + 50 * k){
                    total++;
                }
            }
        }
    }
    

    cout << total;


}

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include<queue>
#include<cmath>
#include<math.h>
using namespace std;


int x, y, a, b, c;
int p[200005], q[200005], r[100005];
int cmp(int i, int j)
{
	return i > j;
}
int main() 
{
	cin >> x >> y >> a >> b >> c;
	for (int i = 1; i <= a; i++)
		cin >> p[i];
	for (int i = 1; i <= b; i++)
		cin >> q[i];
	for (int i = 1; i <= c; i++)
		cin >> r[i];
	long long ans = 0;
	sort(p + 1, p + 1 + a, cmp);
	sort(q + 1, q + 1 + b, cmp);
	sort(r + 1, r + 1 + c, cmp);
	for (int i = 1; i <= x; i++)
		ans += p[i];
	for (int i = 1; i <= y; i++)
		ans += q[i];
	int j = x, k = y;
	for (int i = 1; i <= x + y; i++)
	{
		if (j >= 1 && k >= 1 && r[i] - p[j] > 0 && r[i] - q[k] > 0)
		{
			if (r[i] - p[j] > r[i] - q[k])
				ans = ans - p[j--] + r[i];
			else
				ans = ans - q[k--] + r[i];
		}
		else if (r[i] - p[j] < 0 && r[i] - q[k] < 0)
			break;
		else if (r[i] - p[j] > 0 && j >= 1)
			ans = ans - p[j--] + r[i];
		else if (r[i] - q[k] > 0 && k >= 1)
			ans = ans - q[k--] + r[i];
	}

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

Measured memory_bytes: 1408
from math import *
import sys,bisect,copyreg,copy,statistics,os
def inp(): return sys.stdin.readline().strip()
def IIX(): return (int(x) for x in sys.stdin.readline().split())
def II(): return (int(inp()))
def LI(): return list(map(int, inp().split()))
def LS(): return list(map(str, inp().split()))
def L(x):return list(x)
def out(var): return sys.stdout.write(str(var))
def binary_search(arr, x): 
    left = 0
    right = len(arr) - 1
    mid = 0
    while left <= right:   
        mid = (left + left) // 2
        if arr[mid] < x: 
            left = mid + 1
        elif arr[mid] > x: 
            right = mid - 1
        else: 
            return mid
    return -1

s=inp()
c=0
if s.count("R")==1:
    out(1)
else:
    for i in range(3):
        if s[i]=='R':
            c+=1
        elif s[i]=='S' and i!=2:
            c= 0
    out(c)














 










Measured memory_bytes: 72796
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define MAXI INT_MAX
#define MINI INT_MIN
#define din(t) long long t;cin>>t; 
#define fi(i,l,r,d) for(i = l; i < r; i+=d)
#define fd(i,l,r,d) for(i = l-1; i >= r; i-=d)

 
int main(){
	din(a) din(b)
	cout<<(1+(b-a))*(b-a)/2-b;
}



/*
stayinghomesaveslife


*/

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)

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

    int dp[n+1][2][n+1]; //[remain][turn][card_id]
    rep(i,n+1) rep(j,2) rep(k,n+1) dp[i][j][k] = 0;
    rep(j,2)
        rep(k,n+1)
        {
            int a_opp = k==0 ? (j==0 ? w : z) : a[k-1];
            dp[1][j][k] = abs(a[n-1]-a_opp);
        }

    rep2(i,2,n+1)
        rep(k,n+1)
        {
            dp[i][0][k] = max(dp[i-1][0][k],dp[i-1][1][n-i+1]);
            dp[i][1][k] = min(dp[i-1][1][k],dp[i-1][0][n-i+1]);  
        }

    cout << dp[n][0][0] << endl;
    return 0;
}

Measured memory_bytes: 31488
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define re(i,a,b) for(int i=(a);i<(b);i++)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define run(v) for(int k=head[v];k;k=e[k].ne)
#define v e[k].t
#define clr(a) memset(a,0,sizeof(a));
#define il inline
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back 
#define w1 first
#define w2 second
#define adm(a,b,c) {a=a+b;if(a>=c)a-=c;else if(a<0)a+=c;}
typedef long long ll;typedef long double ld;typedef unsigned long long ull;
typedef pair<ll,ll> pa;
const int N=5e5+5,M=1e7+5,INF=1e9,mod=1e9+7;
const ll linf=1e18;const double eps=1e-8,pi=acos(-1);
il int gmin(int &a,int b){if(a>b)a=b;}il ll gmin(ll &a,ll b){if(a>b)a=b;}il int gmax(int &a,int b){if(a<b)a=b;}il ll gmax(ll &a,ll b){if(a<b)a=b;}
il void read(ll&x){ll f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il ll read(ll&x,ll&y){read(x);read(y);}
il void read(int&x){int f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il int read(int&x,int&y){read(x);read(y);}
il void read(int&a,int&b,int&c){read(a);read(b);read(c);}il void read(ll&a,ll&b,ll&c){read(a);read(b);read(c);}
il int read(){int x;read(x);return x;}
il ll qpow(ll a,ll b,ll p){ll ret=1;for(;b;b>>=1,a=a*a%p)if(b&1)ret=ret*a%p;return ret;}il ll qpow(ll a,ll b){ll ret=1;for(;b;b>>=1,a=a*a%mod)if(b&1)ret=ret*a%mod;return ret;}
il ll qmul(ll a,ll b,ll p){ll ret=0;for(;b;b>>=1,a=(a<<1)%p)if(b&1)adm(ret,a,p);return ret;}il ll qmul(ll a,ll b){ll ret=0;for(;b;b>>=1,a=(a<<1)%mod)if(b&1)adm(ret,a,mod);return ret;}
il void judge(){
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);}
il void gen(){freopen("data.in","w",stdout);}
vector<int>e[N],er[N];
ll ans=0;
int cv,ce,no3p,n,m,col[N];;
ll c[N];
int nex(int x){return x%3+1;}
int las(int x){x--;if(x==0)x=3;return x;}
void dfs(int x,int co){
	if(col[x]){if(col[x]!=co)no3p=1;return;}
	cv++;ce+=e[x].size();
	c[col[x]=co]++;
	re(i,0,e[x].size())dfs(e[x][i],nex(co));
	re(i,0,er[x].size())dfs(er[x][i],las(co));
}
int main(){
	read(n,m);
	rep(i,1,m){
		int a,b;read(a,b);
		e[a].pb(b);
		er[b].pb(a);
	}
	rep(i,1,n)if(!col[i]){
		rep(j,1,3)c[j]=0;
		cv=ce=no3p=0;
		dfs(i,1);
		if(no3p)ans+=1ll*cv*cv;else
		if(c[1]&&c[2]&&c[3])ans+=c[1]*c[2]+c[2]*c[3]+c[3]*c[1];
		else ans+=ce;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 40064
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <map>
#include <iomanip>
using namespace std;

typedef long long ll;

ll a[55];
ll dp[55][55];
map<ll, ll, std::greater<ll> >mp;
int main(int argc, char const *argv[])
{
    // freopen("input.txt", "r", stdin);
    int N, A, B;
    memset(dp, 0, sizeof(dp));
    cin >> N >> A >> B;
    for (int i = 0; i < N; ++i)
    {
        cin >> a[i];
    }
    sort(a, a+N, greater<ll>());
    double sum = 0.;
    for (int i = 0; i < A; ++i)
    {
        sum += a[i];
    }
    double ave = sum / A;
    int to = 0;
    for(int i = 0; i < N; ++i){
        if(a[i] == a[A-1])to++;
    }
    int m = 0;
    for (int i = 0; i < A; ++i)
    {
        if(a[i] == a[A-1])m++;
    }
    for(int i = 1; i <= N; ++i){
        for(int j = 0; j <= i; ++j){
            dp[i][j] = (i == j || j == 0 ? 1 : dp[i-1][j-1] + dp[i-1][j]);
        }
    }
    // cout << dp[4][2] << endl;
    ll res = 0;
    if(a[0] == a[A-1]){
        res += dp[to][m];
        for (int i = A; i < B; ++i)
        {
            if(a[i] == a[A-1])m++;
            else break;
            res += dp[to][m];
        }
    }
    else {
        res = dp[to][m];
    }
    cout << fixed << setprecision(6);
    cout << ave << endl;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
A, B, M = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
mini = 2*10**5
for i in range(M):
  num = list(map(int, input().split()))
  tmp = a[num[0]-1] + b[num[1]-1] - num[2]
  if tmp < mini:
    mini = tmp
mini = min(mini, min(a)+min(b))
      
print(mini)


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

class D
{
	static void Main()
	{
		var h = Console.ReadLine().Split().Select(long.Parse).ToArray();
		Console.WriteLine(Factorize(Gcd(h[0], h[1])).Distinct().Count() + 1);
	}

	static long Gcd(long x, long y) { for (long r; (r = x % y) > 0; x = y, y = r) ; return y; }

	static long[] Factorize(long n)
	{
		long x = 2;
		var r = new List<long>();
		while (n % x == 0) { r.Add(x); n /= x; }
		for (x++; x * x <= n && n > 1; x += 2)
			while (n % x == 0) { r.Add(x); n /= x; }
		if (n > 1) r.Add(n);
		return r.ToArray();
	}
}


Measured memory_bytes: 13396
#include "bits/stdc++.h"
using namespace std;

int main() {
	
	int n;
	cin >> n;
	int p[n];
	int sm = 0;
	for (int i=0; i<n; i++) {
		cin >> p[i];
		sm += p[i];
	}
	int m;
	cin >> m;
	for (int i=0; i<m; i++) {
		int f, t;
		cin >> f >> t;
		cout << sm - p[f-1] + t << endl;
	}
	
	
	
}


Measured memory_bytes: 256
import sys

def main():
    x, y, z = map(int, input().split())

    tmp = y
    y = x
    x = tmp

    tmp = z
    z = x
    x = tmp
    print("{} {} {}".format(x, y, z))

    return 0

if __name__ == '__main__':
    sys.exit(main())


Measured memory_bytes: 2940
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Diagnostics;
using Enu = System.Linq.Enumerable;

public class Program
{
    public void Solve()
    {
        Console.WriteLine(Reader.String().Insert(4, " "));
    }
}


class Entry { static void Main() { new Program().Solve(); } }
class Reader
{
    static TextReader reader = Console.In;
    static readonly char[] separator = { ' ' };
    static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries;
    static string[] A = new string[0];
    static int i;
    static void Init() { A = new string[0]; }
    public static void Set(TextReader r) { reader = r; Init(); }
    public static void Set(string file) { reader = new StreamReader(file); Init(); }
    public static bool HasNext() { return CheckNext(); }
    public static string String() { return Next(); }
    public static int Int() { return int.Parse(Next()); }
    public static long Long() { return long.Parse(Next()); }
    public static double Double() { return double.Parse(Next()); }
    public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); }
    public static int[] IntArray(int N) { return Range(N, Int); }
    public static int[][] IntTable(int H) { return Range(H, IntLine); }
    public static string[] StringArray(int N) { return Range(N, Next); }
    public static string[][] StringTable(int N) { return Range(N, () => Split(Line())); }
    public static string Line() { return reader.ReadLine().Trim(); }
    static string[] Split(string s) { return s.Split(separator, op); }
    static T[] Range<T>(int N, Func<T> f) { var r = new T[N]; for (int i = 0; i < N; r[i++] = f()) ; return r; }
    static string Next() { CheckNext(); return A[i++]; }
    static bool CheckNext()
    {
        if (i < A.Length) return true;
        string line = reader.ReadLine();
        if (line == null) return false;
        if (line == "") return CheckNext();
        A = Split(line);
        i = 0;
        return true;
    }
}

Measured memory_bytes: 2648
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

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

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

    int A, B, m; cin>>A>>B>>m;
    vector<int> a(A), b(B);
    for(int i=0; i<A; i++) cin>>a[i];
    for(int i=0; i<B; i++) cin>>b[i];

    int ans = *min_element(all(a)) + *min_element(all(b));
    while(m--){
        int x, y, c; cin>>x>>y>>c;
        x--, y--;
        chmin(ans, a[x] + b[y] - c);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    long long c;
    cin>>n>>c;
    long long x[100002]={0};
    long long v[100002]={0};
    x[0]=0;
    v[0]=0;
    x[n+1]=c;
    v[n+1]=0;
    for(int i=1;i<=n;i++){
        cin>>x[i]>>v[i];
    }
    long long a[100002]={0};
    for(int i=1;i<=n;i++){
        a[i]=a[i-1]+v[i]-(x[i]-x[i-1]);
    }
    for(int i=1;i<=n;i++){
        a[i]=max(a[i-1],a[i]);
    }
    long long b[100002]={0};
    for(int i=n;i>=1;i--){
        b[i]=b[i+1]+v[i]-(x[i+1]-x[i]);
    }
    for(int i=n;i>=1;i--){
        b[i]=max(b[i],b[i+1]);
    }
    long long ans=0;
    for(int i=1;i<=n;i++){
        ans=max(ans,a[i]);
        ans=max(ans,a[i]-x[i]+b[i+1]);
        ans=max(ans,b[i]);
        ans=max(ans,a[i-1]+b[i]-(c-x[i]));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3328
import sys

def main():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    
    ans = 0
    for i in range(N):
        coin = 1 / N
        bai = i + 1
        
        while bai < K:
            bai = bai * 2
            coin = coin / 2
        
        ans = ans + coin
    
    print(ans)

if __name__ == '__main__':
    main()



Measured memory_bytes: 2940
import itertools
import bisect
n = int(input())
a = list(map(int, input().split()))
a.sort()
acc = list(itertools.accumulate(a))
ans = 0
for i in range(n):
    index = bisect.bisect_right(a, acc[i]* 2)
    #print("index > {} i > {}  value > {}".format(index, i, acc[i] * 2))
    if index <= i + 1 and index < n:
        ans = i+1
print(n - ans)

Measured memory_bytes: 14528
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

vi dx = { 1, 0, -1,  0 };
vi dy = { 0, 1,  0, -1 };

vvi board;
int start_x, start_y;
int h, w, k;

int min_distance(int y, int x) {
  int ret = 1e9;
  ret = min(ret, x);
  ret = min(ret, w-1 - x);
  ret = min(ret, y);
  ret = min(ret, h-1 - y);
  return ret;
}

int main() {
  cin >> h >> w >> k;
  board.assign(h, vi(w, 0));
  rep (i, h) {
    char tmp;
    rep (j, w) {
      scanf(" %c", &tmp);
      if (tmp == '#') {
        board[i][j] = -1;
      }
      if (tmp == 'S') {
        start_y = i;
        start_x = j;
      }
    }
  }

  vvi cost(h, vi(w, 1e9));
  vv<bool> reached(h, vector<bool>(w, false));
  deque<pii> stk;
  stk.push_back((pii){start_y, start_x});
  cost[start_y][start_x] = 0;
  reached[start_y][start_x] = true;
  while (!stk.empty()) {
    auto u = stk.front();
    stk.pop_front();
    rep (i, 4) {
      int y = u.first + dy[i];
      int x = u.second + dx[i];
      if (x < 0 || w <= x || y < 0 || h <= y) { continue; }
      if (board[y][x] == -1) { continue; }
      if (reached[y][x]) { continue; }
      cost[y][x] = min(cost[y][x], cost[u.first][u.second] + 1);
      reached[y][x] = true;
      stk.push_back((pii){y, x});
    }
  }

  int min_cost = 1e9;

  rep (i, h) {
    rep (j, w) {
      if (cost[i][j] <= k) {
        min_cost = min(min_cost, min_distance(i, j));
      }
    }
  }

  int ans = 1 + (min_cost + k - 1) / k;
  printf("%d\n", ans);


  return 0;
}


Measured memory_bytes: 6008
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<map>

typedef long long LL;
typedef unsigned long long ull;

const int N=40;
const int seed=2333;

int n,a[N],col[N];
char str[N];
ull po[N];
LL ans;
std::map<ull,int> ma;

void check()
{
	ull x=0,y=0;
	int p=1,q=n;
	for (int i=1;i<=n;i++)
		if (!col[i]) x+=(ull)a[i]*po[p],p++;
		else y+=(ull)a[i]*po[q],q--;
	ma[x-y]++;
}

void calc()
{
	ull x=0,y=0;
	int p=n,q=1;
	for (int i=n*2;i>n;i--)
		if (col[i]) y+=(ull)a[i]*po[q],q++;
		else x+=(ull)a[i]*po[p],p--;
	ans+=ma[y-x];
}

void dfs1(int x)
{
	if (x>n) {check();return;}
	col[x]=0;dfs1(x+1);
	col[x]=1;dfs1(x+1);
}

void dfs2(int x)
{
	if (x>n*2) {calc();return;}
	col[x]=0;dfs2(x+1);
	col[x]=1;dfs2(x+1);
}

int main()
{
	scanf("%d",&n);
	scanf("%s",str+1);
	for (int i=1;i<=n*2;i++) a[i]=str[i]-'a'+1;
	po[0]=1;
	for (int i=1;i<=n;i++) po[i]=(ull)po[i-1]*seed;
	dfs1(1);
	dfs2(n+1);
	printf("%lld",ans);
	return 0;
}

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


int main(void) {
	int N,tmp;
	cin >> N;
	int i,s,f=0;
	tmp = N;
	for (i = 0;i < 10;i++) {
		if (N > 10) {
			s = N % 10;
			f =f+s;
			N = (N - s) / 10;
		}
		else {
			f =f + N ;
			break;
		}
	}
	if (tmp%f == 0)cout << "Yes";
	else cout << "No";

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 1005
#define f first
#define s second
using namespace std;

int x, y, z, k;

typedef long long ll;

ll a[maxn], b[maxn], c[maxn];

int main()
{
    //freopen("a.inp","r",stdin);
    cin >> x >> y >> z >> k;
    for(int i=1;i<=x;i++) cin >> a[i];
    for(int i=1;i<=y;i++) cin >> b[i];
    for(int i=1;i<=z;i++) cin >> c[i];
    sort(a+1,a+x+1);
    sort(b+1,b+y+1);
    sort(c+1,c+z+1);

    vector< ll > cur;
    for(int i=1;i<=x;i++)
    {
        for(int j=1;j<=y;j++)
        {
            cur.push_back({a[i]+b[j]});
        }
    }
    sort(cur.begin(),cur.end(), greater<ll>());
    cur.resize(k);

    vector< ll > V2;
    for(auto v : cur)
    {
        for(int i=1;i<=z;i++)
        {
            V2.push_back({v + c[i]});
        }
    }
    sort(V2.begin(), V2.end(), greater<ll>());
    V2.resize(k);
    for(auto v : V2) cout << v << endl;
}


Measured memory_bytes: 43236
s = input()
n = len(s) - 1  # スキマの数
for i in range(2**n):  # +, -の組み合わせ数
    p_or_m = ["-"] * n
    for j in range(n):
        if ((i >> j) & 1) == 1:
            p_or_m[n - 1 - j] = "+"

    formula = ""
    for k in range(n):
        formula += s[k] + p_or_m[k]
    formula += s[3]
    if eval(formula) == 7:
        print(formula+"=7")
        break

Measured memory_bytes: 38384
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
double dot(complex<double> a, complex<double> b) {
	return a.real() * b.real() + a.imag() * b.imag();
}
double gyaku_dot(complex<double> a, complex<double> b) {
	return a.real() * b.imag() - a.imag() * b.real();
}
double leng(complex<double> a) {
	return sqrt(a.real() * a.real() + a.imag() * a.imag());
}
double angles(complex<double> a, complex<double> b) {
	double cosine = dot(a, b) / (leng(a) * leng(b));
	double sine = gyaku_dot(a, b) / (leng(a) * leng(b));
	double kaku = acos(cosine);
	if (sine <= 0) {
		kaku = 2 * Ma_PI - kaku;
	}
	return kaku;
}
vector<int> convex_hull(vector<complex<double>> a) {
	vector<int> ans;
	double now_minnest = a[0].real();
	int now_itr = 0;
	REP(i, a.size()) {
		if (now_minnest > a[i].real()) {
			now_minnest = a[i].real();
			now_itr = i;
		}
	}
	ans.push_back(now_itr);
	complex<double> ba(0, 1);
	while (true) {
		int now_go = 0;
		double now_min = 0;
		int starter = ans[ans.size() - 1];
		for (int i = 0; i < a.size(); ++i) {
			if (i != starter) {
				double goa = angles(ba, a[i] - a[starter]);
				if (goa > now_min) {
					now_min = goa;
					now_go = i;
				}
			}
		}
		if (now_go == ans[0]) break;
		ans.push_back(now_go);
		ba = complex<double>(a[now_go] - a[starter]);
	}
	return ans;
}
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int main() {
	long long n, k;
	cin >> n >> k;
	int ans = 0;
	REP(i, n) {
		long long x;
		cin >> x;
		ans += 2 * min(x, llabs(k - x));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){

  int n,i,j,tmp,minj,t;
  char x;

  scanf("%d",&n);

  int a1[n],a2[n];

  char b1[n],b2[n];

  for(i=0;i<n;i++){
    scanf(" %c%d",&b1[i],&a1[i]);
    a2[i]=a1[i];
    b2[i]=b1[i];
  }

for(i=0;i<n;i++){
  for(j=n-1;j>=i+1;j--){
      if(a1[j]<a1[j-1]){
        tmp=a1[j];
        a1[j]=a1[j-1];
        a1[j-1]=tmp;
        x=b1[j];
        b1[j]=b1[j-1];
        b1[j-1]=x;
          }
    }
  }

for(i=0;i<n;i++){
  printf("%c%d",b1[i],a1[i]);
  if(i!=n-1){
    printf(" ");
  }
}

printf("\n");
printf("Stable\n");


for(i=0;i<n;i++){
minj=i;
for(j=i;j<n;j++){
  if(a2[j]<a2[minj]){
    minj=j;
    }
  }
  tmp=a2[i];
  a2[i]=a2[minj];
  a2[minj]=tmp;
  x=b2[i];
  b2[i]=b2[minj];
  b2[minj]=x;
  }


  for(i=0;i<n;i++){
   printf("%c%d",b2[i],a2[i]);
   if(i!=n-1){
     printf(" ");
   }
  }

  printf("\n");

  t=0;
  for(i=0;i<n;i++){
    if(b2[i]!=b1[i]){
      printf("Not stable\n");
      t=1;
      break;
    }
  }
  if(t==0){
    printf("Stable\n");
  }

  return 0;
}



Measured memory_bytes: 1928
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

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

    int n, m;
    cin >> n >> m;
    bool M[n][n];
    rep (i, n) rep (j, n) M[i][j] = false;

    int a, b;
    rep (i, m)
    {
        cin >> a >> b;
        --a; --b;
        M[a][b] = M[b][a] = true;
    }

    int ans = 0;
    vs32 v(n);
    rep (i, n) v[i] = i;
    do {
        bool ok = true;
        rep (i, n - 1)
        {
            int s = v[i];
            int t = v[i + 1];
            if (!M[s][t]) ok = false;
        }
        if (ok)
        {
            ++ans;
        }
    } while (next_permutation(v.begin() + 1, v.end()));

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 256
import core.bitop;
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.format;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
  int n = readln.chomp.to!int;
  int[] p = readln.chomp.split.map!(to!int).array;
  int cnt = 0;
  for (int i = 0; i < n - 1; ++i) {
    if (p[i] == i + 1) {
      swap(p[i], p[i + 1]);
      ++cnt;
    }
  }
  if (p[$ - 1] == n) {
    swap(p[$ - 1], p[$ - 2]);
    ++cnt;
  }
  cnt.writeln;
}


Measured memory_bytes: 4412
#include<bits/stdc++.h>
using namespace std;
int kou,sou=114514810,H,W;
int main(){
    cin>>H>>W;
    char HW[H][W];
    for(int i=0;i<H;i++){ for(int o=0;o<W;o++){ scanf(" %c",&HW[i][o]); }}
    for(int i=1;i<H-1;i++){
        for(int j=1;j<H-i;j++){
            kou=0;
            for(int o=0;o<i;  o++){ for(int f=0;f<W;f++){ if(HW[o][f]!='W'){kou++;} } }
            for(int o=i;o<i+j;o++){ for(int f=0;f<W;f++){ if(HW[o][f]!='B'){kou++;} } }
            for(int o=i+j;o<H;o++){ for(int f=0;f<W;f++){ if(HW[o][f]!='R'){kou++;} } }
            if(kou<sou){sou=kou;}
        }
    }
    cout<<sou<<endl;
}

Measured memory_bytes: 3156
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
LL f5(LL x) {
    return x * x * x * x * x;
}
LL s5(LL x) {
    LL ret = 0;
    while (f5(ret + 1) <= abs(x))
        ret++;
    return ret * (x < 0 ? -1 : 1);
}
bool check(LL x) {
    return f5(s5(x)) == x;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    LL x; cin >> x;
    for (LL A = -4000 ; A <= 4000 ; A++) {
        for (LL B = -4000 ; B <= 4000 ; B++) {
            if (f5(A) - f5(B) == x) {
                cout << A << ' ' << B << '\n';
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int main(){
	int rate[8] = { 0 };
	int N, min, max; cin >> N;
	vector<int> a;
	
	min = max = 0;

	REP(i, N){
		int n; cin >> n;
		a.push_back(n);
	}

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

	REP(i, N){
		if(a[i] <= 399){
			rate[0] = 1;
		}else if(a[i] <= 799){
			rate[1] = 1;
		}else if(a[i] <= 1199){
			rate[2] = 1;
		}else if(a[i] <= 1599){
			rate[3] = 1;
		}else if(a[i] <= 1999){
			rate[4] = 1;
		}else if(a[i] <= 2399){
			rate[5] = 1;
		}else if(a[i] <= 2799){
			rate[6] = 1;
		}else if(a[i] <= 3199){
			rate[7] = 1;
		}else{
			max++;
		}
		
		/*
		cout << "[DEB] ";
		REP(j, 8) cout << rate[j] << " ";
		cout << endl;
		*/
	}

	REP(j, 8) if(rate[j]) min++;

	//cout << "[DEB] min: " << min << endl;
	//cout << "[DEB] max: " << max << endl;

	if(min == 0) cout << 1 << " " <<  max << endl;
	else cout << min << " " << min + max << endl;

	return 0;
}

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

using namespace std;

int main(){
  int N;
  while(cin >> N){
    int x = 0,r = 1;
    for(int i = 0,j = 0 ; i < N ; i++,j++){
      if(j == 2){ r *= 3; j = 0; }
      x += r;
    }
    cout << x << endl;
  }
  return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
#define ll long long int
#define pragi(a,b) for(ll i = a;i<b;i++)
#define pragj(a,b) for(ll j = a;j<b;j++)
#define pragk(a,b) for(ll k = a;k>=b;k--)
#define all(v) (v.begin(),v.end())
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define KAKA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int mod = 1e9 + 7;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef long double ld;
typedef pair<int, int> pii;
//typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ll, ll> pll;

void Compute(ll n)
{
	KAKA
	vector<ll> v(n);
	map<ll,ll> mp;
	ll sum = 0;
	pragi(0,n)
	{
		cin>>v[i];
		mp[v[i]]++;
		sum += v[i];
	}
	ll q;
	cin>>q;
	while(q--)
	{
		ll b,c;
		cin>>b>>c;
		sum -= mp[b] * b;
		sum += mp[b] * c;
		mp[c]+= mp[b];
		mp[b] = 0;
		cout<<sum<<"\n";
	}
}
int main()
{
	KAKA
	ll n;
	cin>>n;
	Compute(n);
}

Measured memory_bytes: 10068
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

int main()
{
	long long int x, y;
	cin >> x >> y;
	if(x % y == 0) cout << -1 << endl;
	else cout << x * (y + 1) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cstdlib>
#include <stdexcept>
#include <algorithm>
#include <set>
#include <map>
#include <stdlib.h>
using namespace std;
int main(){
    int K,S,i,j,a;
    cin >> K >> S;
    a = 0;
    for(i = 0;i <= K;i++){
        for(j = 0;j <= K;j++){
            if(S - i - j <= K && S - i - j >= 0){
                a++;
            }
        }
    }
    cout << a << endl;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define INF 1e9+7
#define pf2 pop_front
#define pb2 pop_back
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define sz size
#define eps 1e-7
#define fod find_by_order
#define fastio ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ofk order_of_key
#define val(x) cout << "Value dari "<< #x << " adalah " << x  << "\n"
#define tr tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
typedef long long ll;
using namespace __gnu_pbds;
using namespace std;

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

void readf(string x){
	freopen((x+".in").c_str(),"r",stdin);
	freopen((x+".out").c_str(),"w",stdout);
}

void pr(string x){
	freopen((x+".in").c_str(),"w",stdout);
}


int read()
{
	bool min = 0;
	int  result = 0;
	char ch;
	ch = getchar();
	while(1)
	{
		if(ch == '-') break;
		if(ch >='0' && ch <= '9') break;
		ch = getchar();
	}
	if(ch == '-') min = 1;else result = ch-'0';
	while(1)
	{
		ch =getchar();
		if(ch< '0' || ch>'9') break;
		result = result * 10 + (ch-'0');
	}
	if(min) return -result;
	return result;
}
//Reynaldo's Template

int main(){
	int N;
	cin >> N;
	string y;
	cin >> y;
	int x[N+5];
	for(int i=0;i<(1<<2);i++){
		if(1 & i) x[1] = 0;
		else x[1] = 1;
		if(2 & i) x[2] = 0;
		else x[2] = 1;
	
		bool ok = 0;
		for(int j=2;j<=N;j++){
			int a;
			if(y[j-1] == 'o'){
				if(x[j] == 0){
					a = x[j-1] ^ 1;
				}
				else{
					a = x[j-1];
				}
			}
			else{
				if(x[j] == 1){
					a = x[j-1] ^ 1;
				}
				else{
					a = x[j-1];
				}	
			}
			if(j == N){
				if(a != x[1]){
					ok = 1;
					break;
				}
			}	
			x[j+1] = a;
		}
	//	cout << x[1] << " " << x[2] << " " << x[N] << " " << y[0] << "\n";
		if(x[1] == 1){ // 1 harus sama 
			if(y[0] == 'o'){
				if(x[N] != x[2]) {
					continue;
				//	break;
				}
			}
			else{
				if(x[N] == x[2]) {
					continue;
				}
			}
		}
		else{
			if(y[0] == 'o')
			{
			if(x[N] == x[2]){ // 0 harus beda
			//	break;
				continue;
			}
			}
			else{
				if(x[N] != x[2]) continue;
			}
		}
		if(!ok){
			for(int j=1;j<=N;j++){
				if(x[j] == 1) {
					cout << "S";
				}
				else cout << "W";
			}
			cout << "\n";
			return 0;
		}
	}
	cout << -1 << "\n";
}



Measured memory_bytes: 896
import java.util.*;


public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    PriorityQueue<Integer[]> queue = new PriorityQueue<Integer[]>((a,b)->{
        return a[0]!=b[0]?a[0]-b[0]:a[1]-b[1];
    });
    int l = 0,r = 0;
    for(int i=0;i<M;i++){
      l = sc.nextInt();
      r = sc.nextInt();
      queue.add(new Integer[]{l,0});
      queue.add(new Integer[]{r,1});
    }
    int ans = 0;
    int tmp = 0;
    int pre = 0;
    while(!queue.isEmpty()){
        Integer[] tp = queue.poll();
        if(tp[1] == 0){
          tmp++;
          pre=tp[0];
        }else{
          if(tmp==M){
            ans += tp[0]-pre+1;
          }
          tmp--;
        }
    }
    System.out.println(ans);
  }
}


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

int main(){
    int N;
    cin >> N;
    vector<long long> X(N);
    rep(i,N) cin >> X[i];
    long long res = LONG_LONG_MAX;
    for(int i=1;i<=100;i++){
        long long sum = 0;
        rep(j,N){
            sum += (i - X[j]) * (i - X[j]);
        }
        res = min(res,sum);
    }
    cout << res << endl;

    return 0;
}

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

int main(){
	string s;cin>>s;
    int win=0;
    for(int i=0;i<s.size();i++){
      if(s[i]=='o'){
        win+=1;
      }
    }
    if((win+7-int(s.size()))>=0){
      cout<<"YES"<<endl;
    }else{
      cout<<"NO"<<endl;
    }
  return 0;
}

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

using namespace std;
#define X first
#define Y second
#define pb push_back
typedef double db;
typedef long long ll;
typedef pair<int,int> P;
const int MAXN=1e6+10;
const ll INF=1ll<<60;
int n,q,a,b,x[MAXN];

#define mid ((l+r)>>1)
#define ls k<<1
#define rs k<<1|1
#define lc k<<1,l,mid
#define rc k<<1|1,mid+1,r
ll mn[MAXN][2],dp[MAXN],tag[MAXN];
void add(int k,ll v)
{if(dp[k]==INF) return;tag[k]+=v;dp[k]+=v;mn[k][0]+=v;mn[k][1]+=v;}
void pushdown(int k)
{
    if(!tag[k]) return;
    add(ls,tag[k]);add(rs,tag[k]);tag[k]=0;
}
void pushup(int k)
{
    dp[k]=min(dp[ls],dp[rs]);
    mn[k][0]=min(mn[ls][0],mn[rs][0]);
    mn[k][1]=min(mn[ls][1],mn[rs][1]);
}
void update(int x,ll v,int k,int l,int r)
{
    if(l==r)
    {
        if(dp[k]>v) dp[k]=v,mn[k][0]=v-l,mn[k][1]=v+l;
        return;
    }
    pushdown(k);
    if(x<=mid) update(x,v,lc);
    else update(x,v,rc);
    pushup(k);
}
ll query(int a,int b,int op,int k,int l,int r)
{
    if(a>b) return INF;
    if(a<=l&&r<=b) return mn[k][op];
    ll ret=INF;
    pushdown(k);
    if(a<=mid) ret=min(ret,query(a,b,op,lc));
    if(b>mid) ret=min(ret,query(a,b,op,rc));
    return ret;
}

int main()
{
    scanf("%d%d%d%d",&n,&q,&a,&b);
    for(int i=0;i<MAXN;i++)
        dp[i]=mn[i][0]=mn[i][1]=INF;
    for(int i=1;i<=q;i++) scanf("%d",&x[i]);
    update(a,abs(b-x[1]),1,1,n);
    update(b,abs(a-x[1]),1,1,n);
    
    for(int i=2;i<=q;i++)
    {
        ll t1=query(1,x[i],0,1,1,n)+x[i];
        ll t2=query(x[i]+1,n,1,1,1,n)-x[i];
        add(1,abs(x[i]-x[i-1]));
        update(x[i-1],min(t1,t2),1,1,n);
    }
    printf("%lld",dp[1]);
    return 0;
}

Measured memory_bytes: 33024
n, m, c = gets.split.map(&:to_i)
limits = gets.split.map(&:to_i)
balls = Array.new(c).map { [] }
n.times do
  color, value = gets.split.map(&:to_i)
  balls[color - 1] << value
end
balls.each.with_index do |a, i|
  a.sort!
  a.shift until a.size <= limits[i]
end
balls.flatten!
balls.sort!
p balls.size >= m ? balls[-m..-1].inject(:+) : balls.inject(:+)



Measured memory_bytes: 16772
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, A, B;
    cin >> N >> A >> B;
    string S; cin >> S;
    int pass = 0;
    int b = 0;
    rep(i, N) {
        if (S[i] == 'a' && pass < A+B) {
            cout << "Yes" << endl;
            pass++;
        } else if (S[i] == 'b'){
            if (b < B && pass < A+B) {
                cout << "Yes" << endl;
                pass++;
            } else {
                cout << "No" << endl;
            }
            b++;
        } else {
            cout << "No" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 848
import java.util.*;

class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long a = sc.nextInt();
        long b = sc.nextInt();
        long c = sc.nextInt();
        long d = sc.nextInt();

        boolean bl = false;
        for(int i = 0; i < n; i++){
            if( a + c * i - d * (n - i - 1) <= b && b <= a + d * i - c * (n - i - 1)){
                bl = true;
            }
        }

        String ans = (bl == true)? "YES" : "NO";
        System.out.println(ans);

    }
}

Measured memory_bytes: 23252
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = int64_t;
using ull = uint64_t;
using PLL = pair<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
// #include "../debug/debug.cpp"
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

template <typename T>
class Bit {
private:
    V<T> data;
    T identity_ele;

public:
    Bit(ll size, T identity_ele) : identity_ele(identity_ele) {
        ll newsize = 1;
        while(newsize < size) {
            newsize = newsize << 1;
        }
        data = V<T>(newsize + 1, identity_ele);
    }

    /*
     * 0-origin
     * sum of [0, pos)
     */
    T sum(ll pos) {
        T ret = identity_ele;
        while(pos > 0) {
            ret += data[pos];
            pos -= pos & -pos;
        }
        return ret;
    }

    /*
     * 0-origin
     * sum of [l, r)
     */
    T sum(ll l, ll r) {
        return sum(r) - sum(l);
    }

    /*
     * 0-origin
     */
    void add(ll pos, T delta) {
        pos++;
        while(pos <= data.size()) {
            data[pos] = data[pos] + delta;
            pos += pos & -pos;
        }
    }
};

int main() {
    ll N;
    cin >> N;
    V<ll> L(N);
    for(auto &&ele : L) cin >> ele;
    sort(ALL(L));
    ll ans = 0;
    V<ll> cnt(2e3 + 10, 0);
    size_t size = 4e3 + 10;
    Bit<ll> bt(size, 0);
    for(ll e : L) {
        ans += bt.sum(e + 1, size);
        for(ll i = 1; i < cnt.size(); i++) bt.add(i + e, cnt[i]);
        cnt[e]++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
package main

import "fmt"

type info struct {
	x, y, h int
}

func main() {
	var n int
	fmt.Scan(&n)
	s := make([]info, n)
	for i := range s {
		fmt.Scan(&s[i].x)
		fmt.Scan(&s[i].y)
		fmt.Scan(&s[i].h)
	}

	for cy := 0; cy <= 100; cy++ {
		for cx := 0; cx <= 100; cx++ {
			toph := -1
			for _, elem := range s {
				if elem.h > 0 {
					tmph := elem.h + abs(elem.x-cx) + abs(elem.y-cy)
					if toph == -1 {
						toph = tmph
					}
					if toph != tmph {
						toph = -2
						break
					}
				}
			}
			if toph == -2 {
				continue
			}
			for _, elem := range s {
				if elem.h == 0 {
					if d := abs(elem.x-cx) + abs(elem.y-cy); d < toph {
						toph = -2
						break
					}
				}
			}
			if toph == -2 {
				continue
			}

			fmt.Println(cx, cy, toph)
			return
		}
	}
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}


Measured memory_bytes: 512
a, b, c = map(int, input().split())
d = []
for i in range(1,a+1):
    if a%i == 0:
        d.append(i)

e = []
for i in range(1,b+1):
    if b%i == 0:
        e.append(i)

f = set(d) & set(e)
f = list(f)
f = sorted(f,reverse=True)

print(f[c-1])

Measured memory_bytes: 3064