akhauriyash/Code-Regression huggingface dataset:
import java.io.PrintWriter
import kotlin.math.pow

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun Int.pow(n: Int) = pow(n.toLong())
fun Int.pow(n: Long) = toDouble().pow(n.toDouble()).toLong()
fun Long.pow(n: Int) = pow(n.toLong())
fun Long.pow(n: Long) = toDouble().pow(n.toDouble()).toLong()

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val (A, B, C) = nextList()
    println(if (A.last() == B[0] && B.last() == C[0]) "YES" else "NO")
}

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

int main() {
    double n,t,a,x;
    cin>>n>>t>>a;
    int ans=1,i=1;
    double ans1=1000000000.0;
    while(i<=n){
        cin>>x;
        if(abs(t-x*0.006-a)<ans1){
            ans1=abs(t-x*0.006-a);
            ans=i;
        }
        i++;
    }
    cout<<ans;
    return 0;
}


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
	for(T& x: vec) is >> x;
	return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
	for(int i=0; i<vec.size(); i++){
		os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
	}
	return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

// 多重vector
// auto dp=make_v<int>(4,h,w) みたいに使える
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// 多重vectorのためのfill
// fill_v(dp,0) みたいに使える
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}

//main code


int main(int argc, char const* argv[])
{
	LL n,k;
	cin >> n >> k;
	VL a(n),f(n);
	cin >> a >> f;
	LL ng = -1, ok = INT64_MAX-1;
	sort(a.begin(), a.end());
	sort(f.rbegin(), f.rend());
	auto isOk = [&](LL mid){
		LL count = 0;
		for (int i = 0; i < n; i++) {
			count += max(a[i] - mid / f[i], 0LL);
		}
		return count <= k;
	};
	while (ok - ng > 1) {
		LL mid = (ng + ok) / 2;
		(isOk(mid) ? ok : ng) = mid;
	}
	if (ok == INT64_MAX)
		cout << "for all x, f(x) = false" << endl;
	else 
		cout << ok << endl;
	return 0;
}


Measured memory_bytes: 3328
INF = 10 ** 10

def merge(hoge, left, mid, right):
    c = 0
    n1 = mid - left
    n2 = right - mid
    Left = [hoge[left+i] for i in range(n1)]
    Right = [hoge[mid+i] for i in range(n2)]
    Left.append(INF)
    Right.append(INF)
    i = 0
    j = 0
    for k in range(left, right):
        if Left[i] <= Right[j]:
            hoge[k] = Left[i]
            i += 1
        else:
            hoge[k] = Right[j]
            j += 1
            c += n1 - i
    return c

def mergeSort(hoge, left, right):
    c = 0
    if left+1 < right:
        mid = (left + right) // 2
        c += mergeSort(hoge, left, mid)
        c += mergeSort(hoge, mid, right)
        c += merge(hoge, left, mid, right)
    return c

if __name__ == '__main__':
    _ = input()
    hoge = [int(x) for x in input().split()]
    print (mergeSort(hoge, 0, len(hoge)))


Measured memory_bytes: 27704
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, n) for(int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll INF=(1LL<<62);
const double inf=pow(10,10);
const ld pi=acosl(1);
const ll mod = 1000000007;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};

long long gcd(long long a,long long b){
	if(a<b)swap(a,b);
	if(a%b==0)return b;
	else return gcd(a%b,b);
}

long long lcm(long long a,long long b){
	return a*b/gcd(a,b);
}

int main(){
	ll n,k;cin>>n>>k;
	ll ans=1;
	while(n/k>0){
		n/=k;
		ans++;
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
    string a,b;
    cin>>a>>b;
    int l=a.size()-b.size();
    int ans=b.size();
    for(int i=0;i<=l;i++)
    {
        int c=0;
        for(int j=0;j<b.size();j++)
        {
           if(a.at(i+j)!=b.at(j))
                c++;
        }
        ans=min(ans,c);
    }
    cout<<ans;
}
   /* string s="";
    int mx=0;
    int i=0;
    while(i<a.size())
    {
        for(int j=0;j<b.size();j++)
        {
            if((a[i]!=b[j])&&j==0)
            {
                i++;
                break;
            }
            else if(a[i]==b[j])
            {
                s=s+a[i];
                i++;
            }
        }
            int l=s.size();
            s="";
            mx=max(mx,l);
            cout<<mx;
    }
    if(mx==0)
        cout<<b.size()<<endl;
    else if(mx!=0)
        cout<<b.size()-mx<<endl;*/



Measured memory_bytes: 3560
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  int N, M; cin >> N >> M;
  int K, A;
  int a[M]={};
  rep(i,N){
    cin >> K;
    rep(j,K){
      cin >> A;
      A--;
      a[A]++;
    }
  }

  int cnt = 0;
  rep(i,M) cnt += (a[i]==N);
  // rep(i,M) cout << a[i] << endl; 

  cout << cnt << endl;

  // cout << fixed << setprecision(6);
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stack>
using namespace std;
int a[15];
stack <int> l,r;
bool flag;
void dfs(int x)
{
	if(x>10)
	{
		flag=true;
		return;
	}
	if(flag)
	  return;
	if(a[x]>l.top())
	{
		l.push(a[x]);
		dfs(x+1);
		l.pop();
	}
	if(a[x]>r.top())
	{
		r.push(a[x]);
		dfs(x+1);
		r.pop();
	}
}
int main ()
{
	ios::sync_with_stdio(false);
	int T;
	cin>>T;
	while(T--)
	{
		l.push(0);r.push(0);
		for(int i=1;i<=10;i++)
		  cin>>a[i];
		dfs(1);
		if(flag==true)
		  cout<<"YES"<<endl;
		else
		  cout<<"NO"<<endl;
		flag=false;
		while(!l.empty())
		  l.pop();
		while(!r.empty())
		  r.pop();
	}
	return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
       
    using namespace std;
    #define ll long long
    #define ld long double
    #define pll pair<long long,long long>
    #define vll vector<long long>
    #define pb push_back
    #define mp make_pair
    #define ff first
    #define ss second
    #define deb(x) cout << #x << "=" << x << endl
    #define F(i,a,b) for(ll i=a;i<=b;i++)
    #define RF(i,a,b) for(ll i=a;i>=b;i--)
    #define in(a,n) F(i,0,n-1)cin>>a[i]
    #define vi vector<int>
    #define out(a,n) F(i,0,n-1)cout<<a[i]<<" ";cout<<endl
    #define mod 998244353
    #define trace1(x)                cerr<<#x<<": "<<x<<endl
    #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
    #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
    #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
    #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
    #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
    #define int long long
    set < ll> primes;
     
   // int n,m;
    
   
    int ans;
    vector<int>d;
    vector<vector<int>>v;
    vector<int>par;
    vector<int>tin,tout;
     
     
    void dfs(int u,int p,int dep)
    {
        //cout<<"h\n";
        //trace3(u,p,dep);
        par[u]=p;
        d[u]=dep;
        tin[u]=++ans;
        for(auto x:v[u])
        {
            if(x==p)continue;
            
          dfs(x,u,dep+1);
        }
        tout[u]=++ans;
    }
    
    bool isancesstor(int u,int v)
    {
        return (tin[u]<=tin[v] and tout[u]>=tout[v]);
    }
    int32_t main()
    {
    	ios::sync_with_stdio(false);
        cin.tie(NULL);
        
        int t=1;
        //cin>>t;
        while(t--)
        {
            int n;
            cin>>n;
            cout<<n+n*n+n*n*n<<'\n';
           
        }
        
        
       
    }

Measured memory_bytes: 3652
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <memory.h>
#include <stdio.h>
using namespace std;
map<int, int> g[10000];
set<pair<int, int> > mq;
map<pair<int, int>,  int> edges;
int dist[10000];
int cost[10000];
int father[10000];

void dijkstra(int s, int n){
	memset(father, -1, sizeof(int) * n);
	int i;
	for(i = 0; i < n; ++i){
	    dist[i] = 100000000;
	    cost[i] = 100000000;
	}
	
	mq.insert(make_pair(0, s));
	father[s] = -1;
	dist[s] = 0;

	while(mq.size()){
		int d = mq.begin()->first;
		int u = mq.begin()->second;
		mq.erase(mq.begin());
		if(g[u].size() == 0) continue;
		for(map<int, int>::iterator iter = g[u].begin(); iter != g[u].end(); iter++){
			int v = iter->first; int w = iter->second;
			int temp = dist[u] + w; 
			int c = edges[make_pair(min(u,v), max(u,v))];
			if(dist[v] > temp|| dist[v]==temp && cost[v] > c ){
				dist[v] = temp;
				cost[v] = c;
				father[v] = u;
				mq.insert(make_pair(dist[v], v));
			}
		}
	}
}
int main(){
	int n, m;
	int u,v,d,c,s;
	scanf("%d%d", &n, &m);

	int i,j;
	pair<int, int> edge;
	while(n !=0 || m != 0){
	for(i = 0; i < n; ++i){
		g[i].clear();
	}
	edges.clear();
	for(i = 0; i < m; ++i)
	{
		scanf("%d%d%d%d", &u, &v, &d, &c);
		u--; v--;
		if(i == 0) s = u;
		if(u > v) swap(u, v);
		g[u][v] = d;
		g[v][u] = d;
		edge.first = u; edge.second = v;
		edges[edge] = c;
	}
    s = 0;
	dijkstra(s, n);
	int cost = 0;
	for(i = 0; i < n; ++i){
		if(father[i] >= 0){
			edge.first = min(father[i], i);
			edge.second = max(father[i], i);
			cost += edges[edge];
		}
	}
	printf("%d\n", cost);
	scanf("%d%d", &n, &m);
	}
    return 0;
}

Measured memory_bytes: 6564
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.HashMap;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Eric
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskE {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            int[] s = new int[n + 1];
            s[0] = 0;
            for (int i = 1; i <= n; i++) {
                s[i] = in.nextInt() + s[i - 1];
                s[i] %= k;
            }

            for (int i = 1; i <= n; i++) {
                s[i] -= i;
                s[i] = Math.floorMod(s[i], k);
            }

            HashMap<Integer, Integer> list = new HashMap<>();
            for (int j = 0; j < Math.min(k, n + 1); j++) {
                int val = list.getOrDefault(s[j], 0);
                list.put(s[j], val + 1);
            }
            long res = 0;
            for (Integer id : list.keySet()) {
                long val = list.get(id);
                res += val * (val - 1) / 2;
            }

            for (int i = 0; i + k <= n; i++) {
                int val1 = list.get(s[i]);
                if (val1 == 1)
                    list.remove(s[i]);
                else
                    list.put(s[i], val1 - 1);

                int val2 = list.getOrDefault(s[i + k], 0);
                list.put(s[i + k], val2 + 1);

                res += (long) val2;
            }

            out.println(res);
        }

    }
}



Measured memory_bytes: 75320
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
ll n, m, x, s;
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    while(m--)
        cin >> x, s += x;
    cout << max(-1LL, n - s);
    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,ans;
cin >>n;
int n1 =n%10;
  int n2 =n%100;
    int n3=n%1000;
  int n4 = n%10000;
  int n5 = n%100000;
  if(n1==n) ans = n;
  else if(n2==n) ans = 9;
  else if(n3==n) ans = 9+n-99;
  else if(n4==n) ans = 999-99+9;
  else if(n5==n) ans = 999-99+9+n-9999;
  else ans =  90909;
  
  cout <<ans <<endl;

}

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline()[:-1]
n,k=map(int,input().split())
w = [int(input()) for i in range(n)][::-1]
def maxnumber(p): 
	wc=w.copy()
	for i in range(k):
		lim=p
		while len(wc):
			if wc[-1]<=lim:
				lim-=wc.pop()
			else:break
	return len(wc)

minp=float('inf')
left,right=1,10**9+1
while left<right:
	mid=(left+right)//2
	maxn=maxnumber(mid)
	if maxn>0:
		left=mid+1
	else:
		right=mid
		minp=min(mid,minp)
print(minp)






	



Measured memory_bytes: 10348
#include <iostream>

using namespace std;

int main(void) {
    int r, g, b;
    cin>>r>>g>>b;
    int num = r * 100 + g * 10 + b;
    if (num % 4 == 0) {
        cout<<"YES";
    } else {
        cout<<"NO";
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long eat(long long s,long long p,long long x){
    if(x==0)return 0;
    if(s==1)return 1;
    if(x<=s/2)return eat((s-3)/2,(p-1)/2,x-1);
    else return p/2+1+eat((s-3)/2,(p-1)/2,x-s/2-1);
}
int main(){
    int n;
    cin>>n;
    long long x;
    cin>>x;
    long long s=1,p=1;
    for(int i=0;i<n;i++){
        s=s*2+3;
        p=p*2+1;
    }
    cout<<eat(s,p,x)<<endl;
    return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

int main() {

    ll N;
    cin >> N;

    ll ans = 0;

    for(ll i = 0; i < N; i++){
        ll t; cin >> t;
        if(i == 0) ans = t;
        else ans = lcm(max(ans,t), min(ans, t));
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    x, a, b = LI()
    if b <= a:
        print("delicious")
    elif b <= a + x:
        print("safe")
    else:
        print("dangerous")

    return

#B
def B():
    n = II()
    a = IR(n)
    check = [False] * (n + 1)
    check[1] = True
    now = a[0]
    for i in range(1,n+1):
        if check[now]:
            break
        if now == 2:
            print(i)
            return
        check[now] = True
        now = a[now - 1]
    print(-1)
    return

#C
def C():
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    B()


Measured memory_bytes: 44764
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
from math import sqrt, pi
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

N, K = getNM()
L = [getList() for i in range(N)]

# 寿司を美味しさの順に並べる
various = defaultdict(int)
L.sort(key = lambda i: i[1], reverse = True)

pool_der = []
ans = 0
# 美味しい順にK個取る
for i in range(K):
    t, d = L[i]
    # 種類をレコードする
    various[t] += 1
    # もし同じ種類のものを既に取っていたら
    if various[t] > 1:
        pool_der.append(d)
    ans += d
# 美味しい順にソートする
pool_der.sort(reverse = True)

# 現在の種類の数
now = len(various.items())
ans += now ** 2
L = L[K:]

# まだ出ていない種類の寿司の中で最大値を取るものをレコードする
pool_var = []
for i in L:
    # まだ登場していないなら
    # 2番手以下は必要ない
    if various[i[0]] == 0:
        pool_var.append(i[1])
        various[i[0]] += 1
# 後ろから美味しい順にソートする
pool_var.sort()

# 取っても種類数が変わらない寿司を取り、新たな種類の寿司を取る
point = ans
M = min(len(pool_der), len(pool_var))

for _ in range(M):
    der = pool_der.pop()
    var = pool_var.pop()

    point += (var - der)
    point += 2 * now + 1
    now += 1
    ans = max(ans, point)
print(ans)

Measured memory_bytes: 119400
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG

int digit(int n) {
  int i=0;
  while(n > 0) {
    n /= 10;
    i++;
  }
  return i;
}

signed main() {
  int N, M, K; cin >> N >> M >> K;
  
  rep(i, N+1) rep(j, M+1) {
    if(N*j + M*i -2*i*j == K) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;

}


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

int main(){
  double A,B,C,D;
  cin>>A>>B>>C>>D;
  if (A+B>C+D){
    cout<<"Left"<<endl;
  }
 else if (A+B==C+D){
    cout<<"Balanced"<<endl;
  }
  else{
    cout<<"Right"<<endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <queue>
using namespace std;

priority_queue<pair<long long, int> > Q;
int N,L,par[100010],fr[100010],bg[100010]; long long len[100010]; bool chk[100010];

int find(int x)
{
	if (par[x] != x) par[x] = find(par[x]);
	return par[x];
}

void uni(int x, int y)
{
	x = find(x); y = find(y);
	if (x != y){
		par[y] = x; len[x] += len[y];
		fr[x] = min(fr[x],fr[y]);
		bg[x] = max(bg[x],bg[y]);
	}
}

int main()
{
	scanf ("%d %d",&N,&L);
	for (int i=1;i<=N;i++){
		scanf ("%lld",&len[i]);
		par[i] = fr[i] = bg[i] = i;
	}

	for (int i=1;i<N;i++){
		Q.push({len[i]+len[i+1],i});
	}

	vector<int> ans;
	while (Q.size() >= 1){
		auto p = Q.top(); Q.pop();
		if (chk[p.second]) continue;
		if (p.first < L){
			puts("Impossible");
			return 0;
		}
		int x = p.second;
		chk[x] = 1;
		ans.push_back(x);
		uni(x,x+1);
		x = find(x);
		if (fr[x] != 1){
			Q.push({len[find(fr[x]-1)]+len[x],fr[x]-1});
		}
		if (bg[x] != N){
			Q.push({len[find(bg[x]+1)]+len[x],bg[x]});
		}
	}

	puts("Possible");
	for (int i=N-2;i>=0;i--) printf ("%d\n",ans[i]);

	return 0;
}

Measured memory_bytes: 7788
a, b, c = raw_input().split()

def ITP1(a, b, c):
    if (a <= b):
        if (b <= c):
            print a, b, c
            return
        if (c <= b):
            if (c <= a):
                print c, a, b
                return
            if (a <= c):
                print a, c, b
                return
    if (b <= a):
        if (a <= c):
            print b, a, c
            return
        if (c <= a):
            if (c <= b):
                print c, b, a
                return
            if (b <= c):
                print b, c, a
                return

ITP1(a, b, c)

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

int main() {
  int sum = 0;
  int n,k;
  cin >> n >> k;
  vector<int> p(n);
  for(int i=0; i<n; i++) cin >> p[i];
  
  sort(p.begin(),p.end());
  
  for(int i=0; i<k; i++){
    sum += p[i];
  }
  
  cout << sum << endl;
	return 0;
}


Measured memory_bytes: 3596
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           ll                          long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100009;

inline ll bigmod(ll B,ll P){ll R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
inline ll ad(ll x,ll y){ll ret=(x%mod+y%mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline ll sub(ll x,ll y){ll ret=((x%mod)-(y%mod)+mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline ll gun(ll x,ll y){ll ret=((x%mod)*(y%mod))%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}

int n,m;
int p[M+2];
vector<int>adj[M+4];
int vis[M+4];
vector<int>yo;
int ses=0;
int dfs(int u)
{
    vis[u]=1;
    yo.pb(u);
    for(auto v:adj[u])
    {
        if(vis[v]==0)
        {
            dfs(v);
        }
    }
}
int cost()
{
   int ret=0;
   vector<int>Magic;
   map<int,int>vis;
   for(auto x:yo)
   {
       Magic.pb(p[x]);
       vis[x]=1;
   }
   for(auto x:Magic)
   {
       if(vis[x]==1)ret++;
   }
   return ret;
}
 main()

{
    fast
    cin>>n>>m;
    f(i,1,n)cin>>p[i];
    f(i,1,m)
    {
        int u,v;
        cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    for(int i=1;i<=n;i++)
    {
         if(vis[i]==0)
            {
                yo.clear();
                dfs(i);
                ses+=cost();
            }
    }
    cout<<ses<<endl;
    return 0;

}





































Measured memory_bytes: 14968
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;
 
void Main() {
  int n,k;
  cin >> n >> k;
  int x=1;
  rep(i,n) x=min(x*2,x+k);
  pr(x);
}
 
int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}

Measured memory_bytes: 256
class PQueue
  def initialize(n, opr)
    @ar = Array.new(n)
    @opr = opr
    @c = 0
  end
 
  def push(x)
    i = @c
    @c += 1
    while (i > 0)
      parent = (i - 1) / 2
      break unless x.send(@opr, @ar[parent])
      @ar[i] = @ar[parent]
      i = parent
    end
    @ar[i] = x
  end
 
  def pop
    ans = @ar[0]
    @c -= 1
    x = @ar[@c]
    i = 0
    while (i * 2 + 1 < @c)
      a = i * 2 + 1
      b = a + 1
      a = b if b < @c && @ar[b].send(@opr, @ar[a])
      break unless @ar[a].send(@opr, x)
      @ar[i] = @ar[a]
      i = a
    end
    @ar[i] = x
    ans
  end

  def first
    @ar[0]
  end
end


N = gets.to_i
A = gets.split.map(&:to_i)
 
q = PQueue.new(N, :<)
totB = 0
A.take(N).each do |a|
  q.push a
  totB += a
end

fs = [totB]
A[N, N].each do |a|
  q.push a
  fs << fs.last + a - q.pop
end

q = PQueue.new(N, :>)
totC = 0
A.drop(N * 2).each do |a|
  q.push a
  totC += a
end

ls = [totC]
A[N, N].reverse_each do |a|
  q.push a
  ls << ls.last + a - q.pop
end

puts fs.zip(ls.reverse).map{|a, b| a - b}.max


Measured memory_bytes: 32272
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

struct pnt{
    int y,x,cost;
};

vector<vector<int>> mv={{1,0},{-1,0},{0,1},{0,-1}};

int N;
void bfs(int y, int x, vector<vector<int>> &grid, vector<vector<int>> &attend){
    queue<pnt> que;
    attend[y][x]=0;
    que.push({y,x,grid[y][x]-1});
    while((int)que.size()>0){
        pnt now=que.front();
        que.pop();
        //cout << -2 << endl;
        //cout << now.y << ' ' << now.x << ' ' << now.cost << ' ' << grid[now.y][now.x] << endl;

        if(grid[now.y][now.x]>now.cost){
            grid[now.y][now.x]=now.cost;
        }else{
            continue;
        }
        //cout << -5 << endl;

        for(auto &m:mv){
            int ny, nx;
            ny=now.y+m[0];
            nx=now.x+m[1];
            //cout << -3 << endl;
    
            if(ny<0 || nx<0 || ny>N-1 || nx>N-1){
                continue;
            }else{
                //cout << ny << ' ' << nx << endl;
                que.push({ny,nx,now.cost+attend[ny][nx]});
            }
        }
    }
}

template<typename T>
void cout_vec(vector<T> &vec){
    for(int i=0; i<vec.size(); i++){
        if (i!=0){
            cout << ' ';
        }
        cout << vec[i];
    }
    cout << endl;
}

template<typename T>
void cout_mat(vector<vector<T>  > &mat){
    for(int i=0; i<mat.size(); i++){
        vector<T> vec = mat[i];
        cout_vec(mat[i]);
    }
}

int main(){
    cin >> N;
    
    vector<vector<int>> grid(N,vector<int>(N,0));
    vector<vector<int>> attend(N,vector<int>(N,1));
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            grid[i][j]=min(min(i,N-1-i),min(j,N-1-j));
        }
    }
    //cout_mat(grid);
    //cout_mat(attend);
    //cout << endl;

    int ans=0;
    for(int i=0; i<N*N; i++){
        int p;
        cin >> p;
        p--;
        
        int y, x;
        y=p/N;
        x=p%N;
        //cout << -4 << endl;
        ans+=grid[y][x];
        bfs(y,x,grid,attend);
        //cout_mat(grid);
        //cout_mat(attend);
        //cout<<endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5532
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	int a,b,x;
	cin>>a>>b>>x;
	if(x>=a && x<=a+b){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys
sys.setrecursionlimit(1000000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): #startline--------------------------------------------
    n,r = map(int,input().split())
    print(r if n>=10 else r+100*(10-n))

#endline===============================================
if __name__ == "__main__":
    main()

Measured memory_bytes: 66028
import numpy as np

n=int(input())
v_array=[]
c_array=[]
v_array=map(int,input().split())
c_array=map(int,input().split())


d_array = np.array(list(v_array))-np.array(list(c_array))

plus_array = d_array[d_array > 0]
plus_array = np.array(plus_array)
print(np.sum(plus_array))

Measured memory_bytes: 12504
import Data.Maybe
import Data.List

main :: IO ()
main = do
  input <- getContents
  putStrLn $ trim (solve (trim input))

--処理
solve :: String -> String
solve s | last a == b !! 0 && last b == c !! 0 = "YES"
        | otherwise                            = "NO"
  where [a, b, c] = words s

trimHead :: String -> String
trimHead = dropWhile (\s -> isJust (elemIndex s [' ', '\t', '\n', '\r']))

trim :: String -> String
trim = reverse . trimHead . reverse . trimHead

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

int main(){
	string S;
	cin >> S;
	ll index = 0, ans = 0;
	for(int i=0; i<S.size(); i++){
		if(S[i] == 'W'){
			index++;
			ans += i;
		}
	}
	ll x = index*(index-1)/2;
	cout << ans - x << endl;
	return 0;
}

Measured memory_bytes: 640
//17571@nith.ac.in @Ankit Verma
#include <bits/stdc++.h>
#define bolt ios::sync_with_stdio(false)
#define ull unsigned long long
#define ll long long
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
using namespace std;

int main() {

/*#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
#endif*/

	bolt;
	cin.tie(nullptr);
	cout.tie(nullptr);
	ll n, a, b; cin >> n >> a >> b;
	ll x = 0;
	if (a == 0) {
		cout << 0 << endl;
		return 0;
	}
	x = n / (a + b);
	x *= a;
	ll t = n % (a + b);
	if (t < a) {
		cout << x + t << endl;
	} else {
		cout << x + a << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int[] a = new int[3];
    int i,j,z;
    for(i=0;i<3;i++){
      a[i] = sc.nextInt();
    }
    for(i=0;i<3;i++){
      for(j=i+1;j<3;j++){
        if(a[i]>a[j]){
          z = a[i];
          a[i] = a[j];
          a[j] = z;
        }
      }
    }
    System.out.println(a[0] + " " + a[1] + " " + a[2]);
  }
}



Measured memory_bytes: 26160
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define MAXN 100005
#define INF 1000000000000000000LL
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll n,q,x,a[MAXN],sum[MAXN],even[MAXN];
int main()
{
    scanf("%lld%lld",&n,&q);
    for(ll i=1;i<=n;i++) scanf("%lld",&a[i]);
    a[0]=-INF;
    for(ll i=1;i<=n;i++) 
    {
        sum[i]=sum[i-1]+a[i];
        even[i]=even[i-1]+a[i]*(i&1?0:1);
    }
    for(ll i=0;i<q;i++)
    {
        scanf("%lld",&x);
        if(x>=a[n]) 
        {
            if(n&1) printf("%lld\n",sum[n]-even[n]);
            else printf("%lld\n",even[n]);
            continue;
        }
        ll pos=lower_bound(a+1,a+n+1,x)-a;
        ll l=pos-1,r=n;
        while(r-l>1)
        {
            ll mid=(l+r)/2;
            ll numr=n-mid+1;
            ll numl=mid-(lower_bound(a,a+n+1,2*x-a[mid])-a);
            if(numr-numl<=1) r=mid; else l=mid;  
        }
        ll ans=sum[n]-sum[r-1];
        ll pp=n-2*(n-r+1);
        if(pp&1) ans+=sum[pp]-even[pp]; else ans+=even[pp];
        printf("%lld\n",ans);
    }
    return 0;
}



Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define sz(x) ((ll)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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;
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> p(M);
  vector<string> S(M);
  rep(i, M) {
    cin >> p[i] >> S[i];
    p[i]--;
  }

  vector<bool> ac(N, false);
  vector<int> pena(N);

  rep(i, M) {
    if (S[i] == "AC")
      ac[p[i]] = true;
    if (S[i] == "WA" && (!ac[p[i]]))
      pena[p[i]]++;
  }


  int acs = 0;
  int penas = 0;
  rep(i, N) {
    if (ac[i]) {
      acs++;
      penas += pena[i];
    }
  }
  cout << acs << ' ' << penas << endl;
}

Measured memory_bytes: 6528
#include<stdio.h>
int main(void){
	int S[4];
	int a,n,dig;
	scanf("%d",&n);
	for(a=3;a>=0;a--){
		dig=n%10;
		S[a]=dig;
		n=n/10;
	}
	if((S[0]==0)&&(S[1]==0)){
		if((S[2]==0)&&(S[3]==0)){
			printf("NA");
		}else if(S[2]*10+S[3]<=12){
			printf("YYMM");
		}else{
			printf("NA");
		}
	}else if(S[0]*10+S[1]<=12){
		if((S[2]==0)&&(S[3]==0)){
			printf("MMYY");
		}else if(S[2]*10+S[3]<=12){
			printf("AMBIGUOUS");
		}else{
			printf("MMYY");
		}
	}else{
		if((S[2]==0)&&(S[3]==0)){
			printf("NA");
		}else if(S[2]*10+S[3]<=12){
			printf("YYMM");
		}else{
			printf("NA");
		}
	}
return 0;
}

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

int main() {

	int n, x, c;

	while (true) {
		cin >> n >> x;
		if ((n | x) == 0)
			break;

		c = 0;
		for (int i = 1; i < n - 1; ++i) {
			for (int j = 2; j < n; ++j) {
				for (int k = 3; k < n + 1; ++k) {
					if (i < j && j < k && i + j + k == x)
						c++;
				}
			}
		}
		cout << c << endl;

	}

	return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
#include<cstdio>
using namespace std;

int main() {
  int x[4], y[4];
  scanf("%d%d%d%d", &x[0], &y[0], &x[1], &y[1]);
  x[2] = x[1] - (y[1] - y[0]);
  y[2] = y[1] + (x[1] - x[0]);
  x[3] = x[0] - (y[1] - y[0]);
  y[3] = y[0] + (x[1] - x[0]);
  printf("%d %d %d %d\n", x[2], y[2], x[3], y[3]);
}

Measured memory_bytes: 128
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }
    

    Scanner cin;
    

    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int M = cin.nextInt();
        bool[] box = new bool[N];
        int[] num = new int[N];
        for (int i = 0; i < N; i++)
        {
            num[i] = 1;
        }
        box[0] = true;
        for (int i = 0; i < M; i++)
        {
            int A = cin.nextInt() - 1;
            int B = cin.nextInt() - 1;
            box[B] |= box[A];
            num[B]++;
            num[A]--;
            if (num[A] == 0) box[A] = false;
        }
        int ans = 0;
        for (int i = 0; i < N; i++)
        {
            if (box[i]) ans++;
        }
        Console.WriteLine(ans);

    }
    
}



class Scanner
{
    string[] s;
    int i;

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

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

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

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

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

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

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


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

Measured memory_bytes: 17284
#include <bits/stdc++.h>
#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 all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
int const INF = 1001001001;


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

int N,X,Y;
cin >> N >> X >> Y;
X--; Y--;
map<int, int> mp;
rrep(i,N-1) mp[i] = 0;

for(int i = 0; i < N-1; ++i) {
    for(int j = i + 1; j < N; ++j) {
        int ans = j - i;
        chmin(ans, abs(X-i) + abs(Y-j) + 1);
        mp[ans]++;
    }
}
for(auto x : mp) {
    cout << x.second << endl;
}
return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h> 
#define F(i,a,b) for(int i=a;i<=(b);++i)
#define dF(i,a,b) for(int i=a;i>=(b);--i)
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define pb push_back
#define maxnkp make_pair
#define fi first
#define se second
#define eps 1e-6
using namespace std;
typedef long long ll;
const int mods = 1e9+7;
const int maxn = 2e5+10;
const int N = 1e5+10;
const int E = 1e6+10; 
int n,m;
int a[maxn];
string s,t;

int main(){
	cin>>s;
	for(int i=0;i<s.size();i++) t+='x';
	cout<<t<<endl; 
}


Measured memory_bytes: 256
n = gets.chomp.to_i

cards = gets.chomp.split(" ").map(&:to_i)

puts cards.join(" ")

for a in 1..(n-1) do
  cards[a]
  while true
    if a-1 == -1
      break
    end
    if cards[a] < cards[a-1]
      tmp = cards[a]
      cards[a] = cards[a-1]
      cards[a-1] = tmp
      a -= 1
    else
      break
    end
  end
  puts cards.join(" ")
end




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

int main(){

    int n,m;
    cin>> n>> m;
    std::vector<int> v;
    int s = 0,x;
    for(int i = 0;i < m;i++){
        cin>> x;
        v.push_back(x);
    }
    for(int x: v){
        //cout<< x;
        s+= x;
    }
    if(s > n)
        cout<< "-1\n";
    else
        cout<< (n - s)<<endl;
}

Measured memory_bytes: 3684
from collections import Counter
n = int(input())
S = list(input())
C = Counter(S)
equ = 0
for i in range(1, (n - 1) // 2 + 1):
    for j in range(n - 2 * i):
        if S[j] != S[j + i] and S[j + i] != S[j + 2 * i] and S[j + 2 * i] != S[j]:
            equ += 1
print(C['R'] * C['G'] * C['B'] - equ)

Measured memory_bytes: 9376
#define DEBUG 0
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>using numr=std::numeric_limits<T>;
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; }
const int INF = 1e9;
const ll LLINF = 1e16;
const int MOD = 1000000007;
const int MOD2 = 998244353;
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if DEBUG
#define debug(...)\
    do {\,
        std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        std::cerr << std::noboolalpha;\
    } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
    { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
os << "{";
    for (auto it = v.begin(); it != v.end(); it++)
        {os << (it != v.begin() ? "," : "") << *it;}
    return os << "}";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    ll a,b;
    cin >> a >> b; 
    cout << a*b /__gcd(a,b) << endl;

}

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

int main()
{
    ll a, b;
    cin >> a >> b;
    ll cnt = 1, ans = 0;
    while (cnt < b)
    {
        cnt += a - 1;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636