akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const int N=5010,inf=1e9+10;
int n;
char S[N],T[N];
int s[N],t[N],s1[N],t1[N];
int ss,tt,c1,c2,ret=inf;
void solve()
{
	ss=tt=1;
	int ans=0;
	memcpy(s1,s,sizeof(s1));memcpy(t1,t,sizeof(t1));
	while (1)
	{
		while (!s1[ss]) ss++;
		while (!t1[tt]) tt++;
		if (ss>n||tt>n)break;
		s1[ss]--;t1[tt]--;ans+=abs(ss-tt);
	}
	for (int i=ss;i<=n;i++) ans+=s1[i]*(n-i+1);
	for (int i=tt;i<=n;i++) ans+=t1[i]*(n-i+1);
	ret=min(ret,ans);
}
int main()
{
	scanf("%d%s%s",&n,S+1,T+1);
	for (int i=2;i<=n;i++)
	{
		if (S[i]!=S[i-1])s[i]++;
		if (T[i]!=T[i-1])t[i]++;
	}
	if (S[1]!=T[1]) s[1]++;
	s[n+1]=t[n+1]=inf;
	for (int i=0;i<=n;i++)
	{
		s[1]+=2*i;solve();s[1]-=2*i;
	}
	for (int i=0;i<=n;i++)
	{
		t[1]+=2*i;solve();t[1]-=2*i;
	}		
	cout<<ret;
}

Measured memory_bytes: 384
/* ANTHOR KUMAR DAS
KUET ECE 2K18*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sc(a) scanf("%d",&a)
#define sc1(n) scanf("%lld",&n)
#define sc2(b,c) scanf("%lld%lld",&b,&c)
#define f(a,b) for(a=0;a<b;a++)
#define pb(a) push_back(a)
#define br break
int main()
{
    int n,i,j,c=1;
    cin>>n;
    char s[n];
    f(i,n)
    {
        cin>>s[i];
    }
    f(i,(n-1))
    {
        if(s[i]!=s[i+1])
        {
            c++;
        }
    }
    cout<<c<<endl;


    return 0;
}



Measured memory_bytes: 384
// BCC
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
#include <queue>

// GCC
// #include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define each(i, c) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define pb push_back
#define mp make_pair

typedef long long ll;

const int INF = 1 << 28;
const ll INFLL = 1ll << 56;

/**
 * UnionFind (????????§?????????)
 * 
 * root(x) : ?????? x ????±????????????????????????????
 * same(x, y) : x ??¨ y ???????????????????±???????????????????
 * unite(x, y) : x ??¨ y ????±????????????????????????????. ???????????\?????? true ?????????
 */
 
class UnionFind {
public:
	UnionFind(int n) : par(n, -1){}
	int root(int x){
		if (par[x] < 0) return x;
		return par[x] = root(par[x]);
	}
	bool same(int x, int y){
		return root(x) == root(y);
	}
	bool unite(int x, int y){
		x = root(x);
		y = root(y);
		if (x == y) return false;
		par[x] += par[y];
		par[y] = x;
		return true;
	}
	int size(int x){
		return -par[root(x)];
	}
	
private:
	vector<int> par;
};

typedef int Cost;

struct Edge {
	int src, dst;
	Cost cost;
	bool operator < (const Edge &e) const {
		return cost > e.cost; // ???????????£??????????????¨?????¨???
	}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;


/**
 * ????°???¨?????¨ (Kruskal ???)
 * (???????????????, ?????¨?????????) ??? pair ?????????
 * queue ??? include ???????????¨
 * UnionFind ??????????????¨
 */
 
pair<Cost, Edges> kruskal(const Graph &g){
	UnionFind uf(g.size());
	priority_queue<Edge> pq;
	
	each(es, g) each(e, *es) pq.push(*e);
	
	Cost total = 0;
	Edges used;
	while (pq.size()){
		Edge e = pq.top(); pq.pop();
		if (uf.unite(e.src, e.dst)){
			used.pb(e);
			total += e.cost;
		}
	}
	
	return mp(total, used);
}



int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	Graph g(n);
	rep(i, m){
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);
		g[a].pb({a, b, c});
	}
	int res = kruskal(g).first;
	printf("%d\n", res);
}

Measured memory_bytes: 4960
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=acos(-1);
const int inf=1e9;
const ll INF=1e18;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,cnt,ans=INF,x,i;
  cin >> n;
  for(i=1; i*i<=n; i++) {
    if(n%i==0) {
      cnt=to_string(n/i).size();
      ans=min(ans,cnt);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
using namespace std;

int main(){
    int a, b, c, r = 0, l = 0;
    while( scanf("%d,%d,%d", &a, &b, &c) != EOF ){
        if( a*a + b*b == c*c ) r++;
        if( a == b ) l++;
    }
    printf("%d\n%d\n", r, l);
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(const void *a, const void *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(const void* left, const void* right) {return strcmp((char *)left,(char *)right);}
int downchar(const void* left, const void* right) {return strcmp((char *)right,(char *)left);}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
    
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0;
  int a[LIMIT2]={0};
  char s[LIMIT1];
  
  scanf("%lld",&n);
  rep(i,n) scanf("%d",&a[i]);
  qsort(a,n,sizeof(int),upint);
  j=1;
  rep(i,n){
    if(i<n-1&&a[i]==a[i+1]){
      j++;
    }else{
      if(j<a[i]) result += j;
      else result += j-(ll)a[i];
      j=1;
    }
  }
  printf("%lld", result);
  
  return 0;
}



Measured memory_bytes: 2556
#include <stdio.h>

int main()
{
	int n, n2, sum = 0;
  	scanf("%d", &n2);
  	n = n2;
  	while(n > 0){
    	sum += n % 10;
      	n /= 10;
    }
  	if (n2 % sum == 0){
    	printf("Yes");
    } else{
    	printf("No");
    }
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<int, int>
#define pb push_back
#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 mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int> 
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second
#define INF 1e18

#define nax 100005


void solve(){
	
	int x,n;
	cin>>x>>n;
	set<int> s;
	rep(i,0,n){
		int u;
		cin>>u;
		s.insert(u);
	}

	int minm=INF;
	int ans=0;
	rep(i,0,102){
		if(s.find(i)==s.end() && abs(x-i)<minm){
			minm = abs(x-i);
			ans=i;
		}
	}

	cout<<ans<<endl;

}
signed main(){
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    srand (static_cast <unsigned> (time(0)));
    int t;
    t=1;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl '\n'
#define rep(i,n) for(int i=0;i<n;i++) 
#define all(v) v.begin(),v.end()
#define F first
#define S second
void solve()
{
	ll x,k,d;
	cin>>x>>k>>d;
	x=abs(x);
	if((x/d)>=k)
	{
		ll y=x/d;
		x-=k*d;
		cout<<x<<endl;
		
	}
	else
	{
		ll y=x/d;
		x=x-(y*d);
		k=k-y;
		if(k%2==0)
		{
			cout<<abs(x)<<endl;
		}
		else
		{
			cout<<min(abs(x+d),abs(x-d))<<endl;
		}
	}
}
int main()
{
//	ios_base::sync_with_stdio(false); 
  //  cin.tie(NULL);  
	int t;
	t=1;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 3568
import math
N=int(input())
S=input()
ans=0
R=[]
G=[]
B=[]
for i,s in enumerate(S):
  if s=="R":
    R.append(i)
  elif s=="G":
    G.append(i)
  else:
    B.append(i)
ans=len(R)*len(G)*len(B)

for r in R:
  for g in G:
    if (r+g)%2==0:
      if S[(r+g)//2]=="B":
        ans-=1
    
for r in R:
  for b in B:
    if(r+b)%2==0:
      if S[(r+b)//2]=="G":
        ans-=1
    
for g in G:
  for b in B:
    if (g+b)%2==0:
      if S[(g+b)//2]=="R":
        ans-=1
    
print(ans)
      
      

Measured memory_bytes: 68088
#include <cstdio>
#include <algorithm>

using namespace std;
typedef long long lint;

int main()
{
	int N;
	
	while (scanf("%d", &N) && N){
		lint maxi = -0x3fffffffffffffll;
		lint dist = maxi;
		for (int i = 0; i < N; i++){
			lint x;
			scanf("%lld", &x);
			dist = max(dist + x, x);
			maxi = max(maxi, dist);
		}
		printf("%lld\n", maxi);
	}
	
	return (0);
}

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

int main() {
    ll n,d;
    cin>>n>>d;
    cout<<(n+d*2+1-1)/(d*2+1)<<endl;
}

Measured memory_bytes: 256
n , m = map(int , input().split())
edge = [[] for _ in range(n) ]
#print(edge)
for _ in range(m):
    a , b = map(int , input().split())
    a -= 1 ; b -= 1
    edge[a].append(b)
    edge[b].append(a)
#print(edge)

def DFS(s):
    global visited
    #ret=1 if all(visited) else 0
    if all(visited):
        ret = 1
    else:
        ret = 0
    for e in edge[s]:
        #print("e",e)
        if visited[e] == True:
            continue
        visited[e] = True
        ret += DFS(e)
        visited[e] = False
    return ret

ans = 0
visited = [False] * n
visited[0] = True
ans += DFS(0)
print(ans)


Measured memory_bytes: 3064
// Reads multiple ints in a line, separate by a space.
// It works even if the actual number of ints is smaller than n.
// WARNING: This function does not work for -2^31.
// NOTE: This function does not handle error cases.
fun fastReadInts(n: Int): IntArray {
  val xs = IntArray(n)
  val s = readLine()!!
  var currentValue = 0
  var isNegative = false
  var currentIndex = 0
  for (c in s) {
    if (c == ' ') {
      xs[currentIndex] = currentValue * if (isNegative) -1 else 1
      currentValue = 0
      isNegative = false
      currentIndex++
    } else if (c == '-') {
      isNegative = true
    } else {
      currentValue *= 10
      currentValue += c - '0'
    }
  }
  xs[currentIndex] = currentValue * if (isNegative) -1 else 1
  return xs
}

fun countAtMost(xs: IntArray, z: Int): Int {
  if (xs[0] > z) return 0
  // Find largest m s.t. xs[m] <= z
  var l = 0
  var u = xs.size - 1
  while (l < u) {
    val m = (l + u + 1) / 2
    if (xs[m] <= z) {
      l = m

    } else {
      u = m - 1
    }
  }
  return l + 1
}

fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val xs = fastReadInts(n)
  val ys = fastReadInts(n)

  val mods = Array(30, { IntArray(n) })
  for (b in 0 until 30) {
    for (i in 0 until n) {
      mods[b][i] = xs[i] % (1 shl (b + 1))
    }
    mods[b].sort()
  }
  
  var ans = 0
  for (y in ys) {
    for (b in 0 until 30) {
      val dy = y % (1 shl (b + 1))
      var count = 0
      // m + dy in [2 ^ b, 2 ^ (b + 1))
      // i.e.
      // If dy <= 2 ^ b: m in [2 ^ b - dy, 2 ^ (b + 1) - dy)
      // If not: [0, 2 ^ (b + 1) - dy), [2 ^ b - dy + 2 ^ (b + 1), 2^ (b + 1))
      if (dy <= 1 shl b) {
        count += countAtMost(mods[b], (1 shl (b + 1)) - dy - 1) -
            countAtMost(mods[b], (1 shl b) - dy - 1)
      } else {
        count += countAtMost(mods[b], (1 shl (b + 1)) - dy - 1) +
            n -
            countAtMost(mods[b], (1 shl b) - dy + (1 shl (b + 1)) - 1)
      }

      if (count % 2 == 1) {
        // println("$y $b")
        ans = ans xor (1 shl b)
      }
    }
  }
  println(ans)
}


Measured memory_bytes: 89008
#include<stdio.h>
int main()
{
	int a, b, c, i, count = 0;
	scanf("%d %d %d", &a, &b, &c);
	for (i = a; i <= b; i++){
		if (c%i == 0){
			count++;
		}
	}
	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 596
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)

def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

def main():
    N,K = LI()
    H = sorted(LI(),reverse=True)
    H_removed = H[K:]
    print(sum(H_removed))


main()



Measured memory_bytes: 49592
#include <bits/stdc++.h>
#define ll long long
#define fast_read ios::sync_with_stdio(0);cin.tie(0);
using namespace std;
int main()
{
    fast_read;
    char a,b,c,d,e,f;
    cin>>a>>b>>c;
    cin>>d>>e>>f;
    if (f == a && e == b && d == c)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 100100100100100100;
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int main () {
    
    string s; cin >>s;
    string t; cin >>t;

    if (s < t) {
        cout << "<" << endl;
    } else if (s > t) {
        cout << ">" << endl;
    } else {
        cout << "=" << endl;
    } 
    
    return 0;
}


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

int main() {
    int a, b;
    cin >> a >> b;
    if (a + b == 15) cout << "+" << endl;
    else if (a * b == 15) cout << "*" << endl;
    else cout << "x" << endl;


    return 0;
}

Measured memory_bytes: 768
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;


class Program
{
    public static long Read()
    {
        return long.Parse(Console.ReadLine());
    }

    public static long[] Reads()
    {
        return Console.ReadLine().Split().Select(long.Parse).ToArray();
    }

   
    public static void Main()
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);

        var input = Reads();
        var a = input[0];
        var b = input[1];
        var c = input[2];
        Console.WriteLine(a * b / 2.0);





        Console.Out.Flush();
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define len(x) (int) (x.size())
using namespace std;
typedef long long ll;

int main() {
    ll total = 0;
    int n, value;
    cin >> n;
    vector<int> myvs;
    for(int i = 0; i < n; i++) {
        cin >> value;
        myvs.push_back(value);
    }

    for(int i = 0; i < n; i++) {
        for(int j = i+1; j < n; j++) {
            total += myvs[i]*myvs[j];
        }
    }
    cout << total << '\n';

    
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

S = input()

if S.islower():
    print('a')
else:
    print('A')

Measured memory_bytes: 9000
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MOD = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime MOD
    mint inv() const { return pow(MOD-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination MOD prime
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < MOD);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
    mint p(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[n-k];
    }
} comb(1000007);
// comb(5, 2) → 10, comb.p(5, 2) → 20
// comb.fact[4] → 24, 2のN乗 → mint(2).pow(N)

int main() {
    // 個数は限られている、最大700未満
    int S;
    cin >> S;
    mint ans = 0;
    int div = 1;
    while (div * 3 <= S) {
        int T = S - div * 3;
        mint add = comb((T + div - 1), (div-1));
        ans += add;
        div++;
    }
    cout << ans << '\n';
    return 0;
    // ll, 0, -, 1i, for s&g, debug
}

Measured memory_bytes: 18600
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,k;
    cin >> n >> k;
    vector<pair<ll,ll>> a;
    for(int i = 0; i < n; i++){
        ll x,y;
        cin >> x >> y;
        a.push_back(make_pair(x,y));
    }

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

    priority_queue<ll,vector<ll>,greater<ll>> pq;
    priority_queue<ll,vector<ll>> m;

    ll kind = 0;
    ll prev = -1;
    ll sum = 0;
    for(int i = n-1; i >= 0; i--){
        if(prev != a[i].first){
            prev = a[i].first;
            pq.push(a[i].second);
            sum += a[i].second;
            kind++;
        }else{
            m.push(a[i].second);
        }
    }

    while(kind > k){
        sum -= pq.top();
        pq.pop();
        kind--;
    }
    while(kind < k){
        sum += m.top();
        pq.push(m.top());
        m.pop();
        k--;
    }

    ll ans = sum + kind*kind;
    for(;!m.empty() && kind > 0;){
        kind--;
        sum-=pq.top();
        sum+=m.top();
        pq.pop();
        pq.push(m.top());
        m.pop();
        ans = max(ans,sum + kind*kind);
    }

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

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

int main() {
    int n, ans = 0;
    cin >> n;
    int a;
    map<int, int> mp;
    for(int i = 0; i < n; ++i) {
        cin >> a;
        mp[a]++;
    }
    int gusu = 0;
    for(auto i = mp.begin(); i != mp.end(); ++i) {
        if(i->second & 1) i->second = 1; 
        else {
            if(gusu) {
                mp[gusu] = 1;
                i->second = 1;
                gusu = 0;
            } else gusu = i->first;
        }
    }

    for(auto i = mp.begin(); i != mp.end(); ++i) {
        ans++;
    }
    if(gusu) ans = max(0, ans-1);
    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 4992
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int h,w,i,j;

        while(true){
            h = sc.nextInt();
            w = sc.nextInt();
            if(h*w == 0) break;
            for(i=0;i<h;i++){
                for(j=0;j<w;j++){
                    if((i+j)%2==0) System.out.print("#");
                    else System.out.print(".");
                }
                System.out.println("");
            }
            System.out.println("");
        }
    }
}


Measured memory_bytes: 34832
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define FOR1(i, n) FOR(i, 1, n+1)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));
#define myCeil(dividend, divisor) ceil((double)(dividend) / (double)(divisor))
#define myFloor(dividend, divisor) floor((double)(dividend) / (double)(divisor))
#define calcDigits(num) floor(log10(num))+1

#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl;
#define dv(name, value) cerr << (name) << " is " << (value) << endl;
#define da(v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl;
#define dpa(v) cerr << "[ " << endl;REPI(itr, v) { cerr << "  [" << (*itr).first << ", " << (*itr).second << ']' << (itr != --v.end() ? "," : "") << endl; } cerr << "]" << endl;


void solve(long long N, std::vector<long long> A){
  priority_queue<int> pq;
  REP(x, N) {
    pq.push(A.at(x));
  }
  REP(x, N) {
    if (pq.top() != A.at(x)) {
      cout << pq.top() << endl;;
    } else {
      int tmp = pq.top();
      pq.pop();
      cout << pq.top() << endl;;

      pq.push(tmp);
    }
  }
}

signed main(){
  long long N;
  scanf("%lld",&N);
  std::vector<long long> A(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&A[i]);
  }
  solve(N, std::move(A));
}


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

class Solve {
private:
	int n;
	std::vector<std::string> str;

	char boin[7] = "aiueo";

	bool isBoin(char c)
	{
		for (int i{}; i < 5; i++)
			if (c == boin[i])
				return true;
		return false;
	}

	bool able(int k)
	{
		std::set<std::string> st;
		for (auto& e: str)
		{
			std::string prefix;
			if (e.size() <= k) prefix = e;
			else prefix = e.substr(0, k);
			if (st.find(prefix) != st.end())
				return false;
			
			st.insert(prefix);
		}
		return true;
	}

public:
	bool is_last_query{};
	Solve()
	{
		scanf("%d", &n);
		if (n == 0)
		{
			is_last_query = true;
			return;
		}
		str.resize(n);
		int max{};
		for (auto& e: str)
		{
			std::string tmp;
			std::cin >> tmp;
			e += tmp.front();
			for (int i{1}; i < (int)tmp.size(); i++)
				if (isBoin(tmp[i - 1]))
					e += tmp[i];
			max = std::max(max, (int)e.size());
		}
		for (int i{1}; i <= max; i++)
			if (able(i))
			{
				printf("%d\n", i);
				return;
			}

		puts("-1");
		return;
	}
};

int main()
{
	while (!Solve().is_last_query);

	return 0;
}


Measured memory_bytes: 3308
n = int(input())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

cnt = 0
for i in reversed(range(n)):
    b = b_list[i]
    if a_list[i]+a_list[i+1] < b:
        cnt += a_list[i]+a_list[i+1]
        a_list[i+1] = 0
        a_list[i] = 0
    elif a_list[i+1] < b:
        cnt += b
        a_list[i] -= b - a_list[i+1]
        a_list[i+1] = 0
    else:
        cnt += b
        a_list[i+1] -= b
print(cnt)

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

ll MOD = 1e9+7;

class mint{
    ll n;
public:
    mint(ll m = 0){
        n = ((m % MOD) + MOD) % MOD;
    }
    mint operator-() const {
        return mint(-n);
    }
    mint& operator+=(const mint& m){
        n += m.n;
        if(n >= MOD) n -= MOD;
        return *this;
    }
    mint& operator-=(const mint& m){
        n += MOD - m.n;
        if(n >= MOD) n -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& m){
        n *= m.n;
        n %= MOD;
        return *this;
    }
    mint operator+(const mint& m) const{
        mint res(*this);
        res += m;
        return res;
    }
    mint operator-(const mint& m) const{
        mint res(*this);
        res -= m;
        return res;
    }
    mint operator*(const mint& m) const{
        mint res(*this);
        res *= m;
        return res;
    }
    mint pow(ll t) const{
        if(t == 0) return mint(1);
        mint m = pow(t>>1);
        m *= m;
        if(t & 1 == 1) m *= *this;
        return m;
    }
    // for prime modulo
    mint inv() const{
        return pow(MOD-2);
    }
    mint& operator/=(const mint& m){
        (*this) *= m.inv();
        n %= MOD;
        return *this;
    }
    mint operator/(const mint& m) const{
        mint res(*this);
        res /= m;
        return res;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.n;
        return os;
    }
};

ll N;
ll T[100000];
ll A[100000];
bool t[100000];
bool a[100000];

int main(){
    cin >> N;
    for(int i=0;i<N;i++) cin >> T[i];
    for(int i=0;i<N;i++) cin >> A[i];
    t[0] = true;
    for(int i=1;i<N;i++){
        t[i] = (T[i] > T[i-1]);
    }
    a[N-1] = true;
    for(int i=N-2;i>=0;i--){
        a[i] = (A[i] > A[i+1]);
    }
    mint ans = mint(1);
    for(int i=0;i<N;i++){
        if(a[i] && t[i]){
            if(A[i] != T[i]) ans *= mint(0);
        }else if(a[i]){
            if(A[i] > T[i]) ans *=  mint(0);
        }else if(t[i]){
            if(T[i] > A[i]) ans *= mint(0);
        }else{
            ans *= mint(min(A[i],T[i]));
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
//登録しよう！→ https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater //sortを降順にする
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示

void solve(long long N, long long X, long long Y){
  vector<ll>ans(114514,0);
  for (ll i = 1; i <= N; i++) {
    for (ll j = i; j <= N; j++) {
      ll x = min({abs(j-i),abs(Y-i)+1+abs(j-X),abs(X-i)+1+abs(j-Y)});
      ans[x]++;
    }
  }
 for (int i = 1; i <= N-1; i++) {
   cout << ans[i] << endl;
 } 
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    solve(N, X, Y);
}


Measured memory_bytes: 1152
#include<iostream>
using namespace std;
bool isPrime(int n){
  for(int i=2;i*i<=n;i++) if(n%i==0) return false;
  return true;
}

int main(){
  int d[10005]={};
  int i=2,k=1;
  while(k<10005) {
    while(!isPrime(i)) i++;
    d[k]=d[k-1]+i;
    i++;k++;
  }
  while(cin >> k,k) cout << d[k] << endl;
  return 0;
}

Measured memory_bytes: 1204
n=gets.to_i
a=n.times.map{gets.chomp}
m=a.sort
a.each{|e|
	idx1=(0...n).bsearch{|i|m[i]>=e}||n
	idx2=(0...n).bsearch{|i|m[i]>e}||n
	p idx1*3+(idx2-idx1-1)
}

Measured memory_bytes: 20168
#include <bits/stdc++.h>
using namespace std;
constexpr auto MOD = 1000000007;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VLL;

string s;
long long n, m,t;
ll dp[3010][3010];

int main()
{
  cin>>n>>t;
  VLL a(n), b(n);
  vector<PLL> c(n);
  rep(i, n) { cin >> c[i].first >> c[i].second; }
  sort(c.begin(), c.end());
  rep(i, n) { b[i] = c[i].second;
    a[i] = c[i].first;
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++)
  {
    for (int j = 0; j <= 3000; j++)
    {
      dp[i][j] = max(max(max(0LL, (j == 0 ? 0 : dp[i][j - 1])), (i == 0 ? 0 : dp[i - 1][j])), (j >= a[i-1] ? dp[i - 1][j - a[i-1]] + b[i-1] : 0));
    }
  }
  ans = dp[n][t];
  for (int i = 0; i < n; i++)
  {
    ans = max(ans, dp[i][t - 1] + b[i]);
  }
  cout << ans << endl;
}


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

int main(){
  int n;
  cin >> n;
  string s1,s2;
  cin >> s1 >> s2;
  for(int i=0;i<n;i++){
    cout << s1[i] << s2[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
A, B, C = gets.split.map(&:to_i)
K = gets.to_i

def judge(a, b, c)
  if a < b && b < c
    puts "Yes"
    exit
  end
end

def run(k, a, b, c)
  return if k == 0

  judge(a * 2, b, c)
  run(k - 1, a * 2, b, c)

  judge(a, b * 2, c)
  run(k - 1, a, b * 2, c)

  judge(a, b, c * 2)
  run(k - 1, a, b, c * 2)
end

run(K, A, B, C)
puts "No"

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

using ld=long double;

int main(){
    int n,m;
    cin>>n>>m;
    vector<int> vi(n),da(n),vo(n);
    for(int i=0;i<n;i++){
        cin>>vi[i]>>da[i]>>vo[i];
    }

    vector<vector<ld>> f(m+1,vector<ld>(m+1,0));
    ld p3=1;
    ld p23=1;
    for(int i=0;i<=m;i++){
        f[i][0]=p23;
        f[i][i]=p3;
        p3*=(1./3.);
        p23*=(2./3.);
    }
    for(int i=2;i<=m;i++){
        for(int j=1;j<i;j++){
            f[i][j]=2./3.*f[i-1][j]+1./3.*f[i-1][j-1];
        }
    }
    
    
    vector<ld> fsum(m+2,0);
    for(int i=0;i<=m;i++){
        fsum[i+1]=fsum[i]+f[m][i];
    }
    
    vector<ld> viexp(m+1);
    viexp[0]=-1;
    for(int i=1;i<=m;i++){
        int p=i*vi[0];
        vector<vector<ld>> top3(n,vector<ld>(3,0.0));
        vector<ld> worst(n,0);
        worst[0]=1.0;
        top3[0][0]=1.0;
        for(int j=0;j<n-1;j++){
            int wint=min(p/vi[j+1]+(int)(p%vi[j+1]!=0),m+1);
            //[0,wint) then win            
            ld posw=fsum[wint];
            ld posl=1-posw;
            worst[j+1]=worst[j]*posl;
            for(int k=0;k<3;k++){
                top3[j+1][k]+=top3[j][k]*posw;
                if(k+1<3) top3[j+1][k+1]+=top3[j][k]*posl;
            }
        }
        viexp[i]=(top3[n-1][0]+top3[n-1][1]+top3[n-1][2])*5.0-worst[n-1];
    }
    vector<ld> daexp(m+1);
    daexp[0]=-1;
    for(int i=1;i<=m;i++){
        int p=i*da[0];
        vector<vector<ld>> top3(n,vector<ld>(3,0.0));
        vector<ld> worst(n,0);
        worst[0]=1.0;
        top3[0][0]=1.0;
        for(int j=0;j<n-1;j++){
            int wint=min(p/da[j+1]+(int)(p%da[j+1]!=0),m+1);
            //[0,wint) then win            
            ld posw=fsum[wint];
            ld posl=1-posw;
            worst[j+1]=worst[j]*posl;
            for(int k=0;k<3;k++){
                top3[j+1][k]+=top3[j][k]*posw;
                if(k+1<3) top3[j+1][k+1]+=top3[j][k]*posl;
            }
        }
        daexp[i]=(top3[n-1][0]+top3[n-1][1]+top3[n-1][2])*3.0-worst[n-1];
    }


    vector<ld> voexp(m+1);
    voexp[0]=-1;
    for(int i=1;i<=m;i++){
        int p=i*vo[0];
        vector<vector<ld>> top3(n,vector<ld>(3,0.0));
        vector<ld> worst(n,0);
        worst[0]=1.0;
        top3[0][0]=1.0;
        for(int j=0;j<n-1;j++){
            int wint=min(p/vo[j+1]+(int)(p%vo[j+1]!=0),m+1);
            //[0,wint) then win            
            ld posw=fsum[wint];
            ld posl=1-posw;
            worst[j+1]=worst[j]*posl;
            for(int k=0;k<3;k++){
                top3[j+1][k]+=top3[j][k]*posw;
                if(k+1<3) top3[j+1][k+1]+=top3[j][k]*posl;
            }
        }
        voexp[i]=(top3[n-1][0]+top3[n-1][1]+top3[n-1][2])*2.0-worst[n-1];
    }

    ld res=-3;
    for(int vic=0;vic<=m;vic++){
        for(int voc=0;vic+voc<=m;voc++){
            int dac=m-vic-voc;
            res=max(res,viexp[vic]+voexp[voc]+daexp[dac]);
        }
    }
    cout<<fixed<<setprecision(10);
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 65980
from bisect import bisect_left
from itertools import combinations

n = int(input())
l = sorted(map(int, input().split()))
ans = 0

for (i1, a), (i2, b) in combinations(enumerate(l[:-1]), 2):
    i3s = i2 + 1
    i3e = bisect_left(l, a + b, i3s)
    ans += i3e - i3s

print(ans)

Measured memory_bytes: 44124
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll a,b;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>a>>b;
	if ((a+b)%2==1) cout<<"IMPOSSIBLE";
	else cout<<(a+b)/2;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<set>
#include<algorithm>

using namespace std;

int main() {
    long long N, K;
    cin >> N >> K;
    long t, t2;
    if (N > K) {
        t = N % K;
        t2 = K - t;
    }
    else {
        t = N;
        t2 = K - N;
    }
    if (t > t2) {
        cout << t2 << endl;
    }
    else cout << t << endl;

    return 0;
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int h, w; std::cin >> h >> w;
  vector<string> grid(h); rep(i, h) std::cin >> grid[i];
  vector<vi> cost(h, vi(w, inf));
  cost[0][0] = 0;
  rep(y, h) rep(x, w) {
    srep(dx, -1, 2) srep(dy, -1, 2) if (dx*dx + dy*dy == 1) {
      int sx = x + dx, sy = y + dy;
      if (sx < 0 || sx >= w || sy < 0 || sy >= h) continue;
      chmin(cost[y][x], cost[sy][sx]+(grid[y][x] != grid[sy][sx]));
    }
  }
  if (grid[0][0] == '#') cost[h-1][w-1]++;
  if (grid[h-1][w-1] == '#') cost[h-1][w-1]++;
  std::cout << cost[h-1][w-1]/2 << "\n";
}


Measured memory_bytes: 384
#include<iostream>
#include<sstream>
#include<fstream>
#include<cstring>/*The header <string> and
<string.h> does not contain the useful
function 'memset' and 'memcpy'.*/
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<utility>
#include<algorithm>
#include<functional>
#include<ctime>
#include<cmath>
#include<cstdlib>
#include<cstdio>
using namespace std;
long long dp[100100];
bool b[100100];
const long long md=1e9+7;
int main()
{
	int N,K;
	cin>>N>>K;
	while(K--)
	{
		int x;
		cin>>x;
		b[x]=true;
	}
	dp[0]=1;
	for(int i=1;i<=N;i++)
		if(!b[i])
			if(i>1)
				dp[i]=(dp[i-1]+dp[i-2])%md;
			else	dp[i]=dp[i-1]%md;
	cout<<dp[N]<<endl;
	return 0;
}

Measured memory_bytes: 1152
import java.util.*;
import java.io.*;

public class Main{
	public static void main(String[] args){
		new Main().solve();
	}

	void solve(){

		Scanner cin = new Scanner(System.in);
		int[] num = new int[10001];
		LinkedList<Integer> l = new LinkedList<Integer>();
		for(int i=2;i<=10000;i++){
			if(isPrime(i)){
				LinkedList<Integer> nl = new LinkedList<Integer>();
				nl.add(i);
				for(int a : l) if(a+i<=10000){
					nl.add(a + i);
				}
				l = nl;
				for(int a : l) num[a]++;
			}
		}

		while(true)
		{
			int n = cin.nextInt();
			if(n==0) return;
			System.out.println(num[n]);
		}
	}

	boolean isPrime(int a){
		if(a<2) return false;
		for(int i=2;i*i<=a;i++){
			if(a%i==0) return false;
		}
		return true;
	}
}

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

using namespace std;

#define F first
#define S second
#define modulo ll (1e9 + 7)

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

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

const int N = 2e5 + 9, M = 2e5 + 9, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;

int a[N], vis[N];

int main(){
    init();

    ll n, k;    cin >> n >> k;

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

    memset(vis, -1, sizeof vis);

    int vid = 0, cycle = -1, mod;
    for(int i = 1;;i = a[i]){
        if(vid == k)  return cout << i, 0;

        if(cycle == -1 && vis[i] != -1){
            cycle = vid - vis[i];
            k -= vid;
            vid = 0;
        }

        if(~cycle && vid % cycle == k % cycle)
            return cout << i, 0;

        vis[i] = vid++;
    }

}

Measured memory_bytes: 5188
#include <bits/stdc++.h>
using namespace std;
int a[200010];
int b[200010];
bool f[200010];
int main()
{
    int n,m;
    cin>>n>>m;
    memset(f,0,sizeof(f));
    for(int i=0;i<m;i++)
    {
        cin>>a[i]>>b[i];
        if(a[i]==1)
            f[b[i]]=1;
    }
    int flag=0;
    for(int i=0;i<m;i++)
    {
        if(b[i]==n&&f[a[i]]==1)
        {
            flag=1;
            break;
        }

    }
    if(flag)
        cout<<"POSSIBLE"<<endl;
    else
        cout<<"IMPOSSIBLE"<<endl;
}


Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
# define inf 0x3f3f3f3f
const int maxn = 1e5+100;
int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int s,w;
    cin>>s>>w;
    if(s<=w)
    cout<<"unsafe";
    else cout<<"safe";
    return 0;
}

Measured memory_bytes: 3652
n = int(input())
s = list(input())

r = 0
g = 0
b = 0
for c in s:
    if c == 'R':
        r += 1
    elif c == 'G':
        g += 1
    else:
        b += 1

ans = r * g * b

for i in range(n - 2):
    for j in range(i, n - 1):
        if s[i] == s[j]:
            continue
        k = 2 * j - i
        if k >= n:
            continue
        if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
            ans -= 1
print(ans)

Measured memory_bytes: 9212
from collections import defaultdict

N, M = map(int, input().split())
P = [None] * M
Y = [None] * M
Y_eachP = defaultdict(list)

for i in range(M):
    p, y = map(int, input().split())
    P[i] = p
    Y[i] = y
    Y_eachP[p].append(y)

# add rank to each p
ans = dict()
for p, years in Y_eachP.items():
    years_with_rank = dict(zip(sorted(years), range(1, len(years)+1)))
    ans[p] = years_with_rank

for p, y in zip(P, Y):
    print(str(p).zfill(6) + str(ans[p][y]).zfill(6))

Measured memory_bytes: 113240
N, K = map(int, input().split())
results = []
for i in range(N//2):
    results.append(((N+1)//2+i+1, 2*N-2*i-1, (N+1)//2+2*N-i))
for i in range((N+1)//2):
    results.append((i+1, 2*N-2*i, 2*N-i+1))
results = results[::-1]
for i, (x, y, z) in enumerate(results):
    if x+y+2*K-2 > 2*N+i+K:
        print(-1)
        break
    print(x + K - 1, y + K - 1, 2*N+i+K)


Measured memory_bytes: 61144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}


int main() {
  int N;
  ll a,b,c;
  cin >> N;
  vector<vector<vector<ll>>> g(N);
  rep(i,N-1) {
    cin >> a >> b >> c;
    a--;b--;
    g[a].push_back({b,c});
    g[b].push_back({a,c});
  }
  int Q,K;
  cin >> Q >> K;
  K--;

  queue<pair<int,ll>> que;
  vector<ll> ans(N,-1);
  que.push({K,0});
  while (!que.empty()) {
    auto t = que.front();
    que.pop();
    if (ans[t.first]<0) {
      ans[t.first] = t.second;
      for (auto k:g[t.first]) {
        que.push({k[0],t.second + k[1]});
      }
    }
  }
  int x,y;
  rep(i,Q) {
    cin >> x >> y;
    x--;y--;
    cout << ans[x] + ans[y] << endl;
  }
}

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

int main()
{
    int N;
    string S;
    int count;

    cin >> N >> S;

    count = 0;
    for(int i = 0; i < N-2; i++) {
        if(S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C') {
            count += 1;
        }
    }

    cout << count << endl;

    return 0;
}

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

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

    ll ans = 0;

    for (ll i = 1; i <= n; i++) {
        if (i % 3 == 0 && i % 5 == 0) {}
        else if(i % 3 ==0) {}
        else if (i % 5 == 0) {}
        else {
            ans += i;
        }
    }

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

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

int c=0;

void merge(vector<int>&s,int left,int mid,int right){
	int n1=mid-left,n2=right-mid;
	vector<int>L(n1),R(n2);
	for(int i=0;i<n1;++i)L.at(i)=s.at(left+i);
	for(int i=0;i<n2;++i)R.at(i)=s.at(mid+i);
	L.push_back(0x7FFFFFFF),R.push_back(0x7FFFFFFF);
	for(int k=left,i=0,j=0;k<right;++k){
		if(L.at(i)<=R.at(j)){
			s.at(k)=L.at(i);
			++i;
		}else{
			s.at(k)=R.at(j);
			++j;
		}
		++c;
	}
}

void mergesort(vector<int>&s,int left,int right){
	int mid=(left+right)/2;
	if(left+1<right){
		mergesort(s,left,mid);
		mergesort(s,mid,right);
		merge(s,left,mid,right);
	}
	return;
}

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<int>s(n);
	for(int i=0;i<n;++i)cin>>s.at(i);
	mergesort(s,0,n);
	cout<<s.at(0);
	for(int i=1;i<n;++i)cout<<" "s<<s.at(i);
	cout<<"\n"s<<c<<"\n"s;
}


Measured memory_bytes: 8644
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn get<T: FromStr>() -> T
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

fn main() {
    let nk: Vec<usize> = util::gets();
    let ab: Vec<(usize, usize)> = (0..nk[0])
        .map(|_| {
            let ab = util::gets();
            (ab[0], ab[1])
        })
        .collect();

    let k = nk[1];
    let vk = ab.iter()
        .filter(|t| t.0 | k == k)
        .map(|t| t.1)
        .sum::<usize>();
    let vr = (0usize..)
        .take_while(|i| (k >> i) > 0)
        .filter(|i| (k >> i) & 1 == 1)
        .map(|r| {
            ab.iter()
                .filter(|&&(a, _)| {
                    let uk = k >> (r + 1);
                    (a >> r) & 1 == 0 && uk | (a >> (r + 1)) == uk
                })
                .map(|t| t.1)
                .sum::<usize>()
        })
        .max();
    println!("{}", max(vk, vr.unwrap_or(0)));
}


Measured memory_bytes: 6524
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	int[] numbers = new int[3];
	for (int i = 0; i < numbers.length; i++) {
	    String input = scan.next();
	    numbers[i] = Integer.parseInt(input);
	}
	for (int i = 0; i < 3; i++) {
	    int point = i;
	    for (int j = point; j < 3; j++) {
		if (numbers[point] > numbers[j]) {
		    point = j;
		}
	    }
	    int tmp = numbers[point];
	    numbers[point] = numbers[i];
	    numbers[i] = tmp;
	}
	System.out.println(numbers[0] + " " + numbers[1] + " " + numbers[2]);
    }
}

Measured memory_bytes: 26052
#include <bits/stdc++.h>
#define rep(i,n1) for(int i=0;i<n1;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define yesno(flg) if(flg){cout<<'YES'<<endl;}else{cout<<'NO'<<endl;}
#define vi vector<int>
#define pb push_back
#define i197 1000000007
#define MAX_N 200002
#define PI 3.141592653589793
using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<Pii,int> Piii;
typedef pair<int,ll> Pil;
typedef pair<ll,ll> Pll;
typedef pair<string,int> Psi;
typedef pair<Psi,int> Psii;

const ll inf=1000000007;
struct edge{
	int myc,to,c,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

vector<Pii> v[100001];
ll dp2[300000][60]={};
double a[200001]={};
double t[200000];
int main() {
	int n,k;
	cin>>n>>k;
	double r=0;
	rep(i,n){
		double p;
		cin>>p;
		r+=(p+1)/2;
		a[i+1]=r;
	}
	double res=0;
	rep(i,n-k+1){
		double r2=a[i+k]-a[i];
		if(r2>=res)res=r2;
	}
	printf("%.9f",res);
	return 0;
}


Measured memory_bytes: 5504
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <unordered_map>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <memory>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
constexpr long long MOD = 1e9 + 7;
constexpr long long MAX = 1000000;

//long long MOD = 998244353;
constexpr ll INF = 1e17;
constexpr double PI = 3.141592653589793;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }



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

    int n;
    string s, t;
    cin >> n >> s >> t;

    string ans;
    for (int i = 0; i < n; i++)
    {
        ans += s[i];
        ans += t[i];
    }

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

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>

using namespace std;

int main(){
  int n;
  int t[100] = {0};
  cin >> n;
  for(int i = 0; i < n * (n - 1) / 2; i++){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    a--;b--;c--;d--;
    if(c > d)
      t[a] += 3;
    else if(c < d)
      t[b] += 3;
    else if(c == d){
      t[a]++;
      t[b]++;
    }
  }
  for(int i = 0; i < n; i++){
    int ans = 1;
    for(int j = 0; j < n; j++){
      if(t[i] < t[j])
	ans++;
    }
    printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 1144