akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, A, B, C, D;
  cin >> N;
  A= N/1000;
  B= (N%1000)/100;
  C= (N%100)/10;
  D= N%10;
  if (B==C) {
    if (A==B || C==D) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
  else {
    cout << "No" << endl;
  }
}

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

int n;
int t[10002];
int dp[2][5002][2];

int solve(){
  memset(dp, 0x7f, sizeof(dp));
  dp[1][1][0] = dp[1][0][1] = 0;

  for(int i = 1; i < n; i++){
    int to = min(i, n / 2);
    int ni = (i + 1) % 2;

    for(int j = 0; j <= to; j++){
      dp[ni][j + 1][0] = min(dp[i % 2][j][0], dp[i % 2][j][1] + t[i - 1]);
      dp[ni][j][1] = min(dp[i % 2][j][0] + t[i - 1], dp[i % 2][j][1]);
      dp[i % 2][j][0] = dp[i % 2][j][1] = 0x7f7f;
    }
  }

  return min(dp[0][n / 2][0], dp[0][n / 2][1]);
}

int main(){
  scanf("%d", &n);
  for(int i = 0; i < n - 1; i++){
    scanf("%d", &t[i]);
  }
  printf("%d\n", solve());
}

Measured memory_bytes: 952
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.util.List;
import java.util.Scanner;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
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);
        Multiplication2 solver = new Multiplication2();
        solver.solve(1, in, out);
        out.close();
    }

    static class Multiplication2 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int num = in.nextInt();
            long ans = 1;

            BigDecimal border = new BigDecimal(pow(10, 18));
            List<Long> lists = new ArrayList<>();

            for (int i = 0; i < num; i++) {
                long a = in.nextLong();
                lists.add(a);
            }

            if (lists.contains(0L)) {
                out.append("0\n");
                return;
            }

            for (Long a : lists) {
                BigDecimal judge = border.divide(new BigDecimal(a), 40, BigDecimal.ROUND_CEILING);
                if ((new BigDecimal(ans)).compareTo(judge) > 0) {
                    out.append("-1\n");
                    return;
                }
                ans *= a;
            }
            out.append(String.valueOf(ans));
        }

        static long pow(long x, long n) {

            if (n == 0) {
                return 1;
            }
            long result = pow(x, n / 2);

            if (n % 2 == 0) {
                return (result * result);
            }
            return ((result * result)) * x;
        }

    }
}



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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  string s;
  cin>>s;
  string ans;
  for(auto it:s){
    if(it=='B'&&ans.size()!=0)ans.erase(ans.size()-1);
    if(it=='0')ans.push_back('0');
    if(it=='1')ans.push_back('1');
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
D, E = [], []
t,l = 0, 0
res = 0
for _ in range(N):
    S = input().rstrip()
    x,y = 0,0
    for s in S:
        if s=="(": x+=1
        else: x=max(x-1,0)
    for s in reversed(S):
        if s==")": y+=1
        else: y=max(y-1,0)
    D.append((x,y))
D.sort(key=lambda x:x[1])
t = 0
for x,y in D:
    if x-y>=0:
        if t>=y: t+=x-y
        else: print("No"); exit()
D.sort(key=lambda x:x[0])
s = 0
for x,y in D:
    if y-x>=0:
        if s>=x: s+=y-x
        else: print("No"); exit()
if t!=s: print("No")
else: print("Yes")


Measured memory_bytes: 234984
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b,c,k;
    cin>>a>>b>>c>>k;
    long long int ans=min(a,k);
    long long int cn=ans;
    if(cn<k)
    {
        cn=min(a+b,k);
    }
    if(cn<k)
    {
        ans-=(k-cn);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3620
#include <stdio.h>

int main(){
  int x,y,num,d;
  int i;
  int gn,ln;
  
  scanf("%d%d",&x,&y);

  /*if(x>=y) gn=x;
  
  for(i=1;i<=gn;i++){
    if(x%i==0&&y%i==0) num=i;
    }*/

  if(x>=y){
    gn=x;
    ln=y;
  }else {
    gn=y;
    ln=x;
  }
  while(1){
    d=gn%ln;
    if(d==0){
      num=ln;
      break;
    }
    else {
      gn=ln;
      ln=d;
    }
  }
  
  printf("%d\n",num);
  return 0;
}



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

#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define MAXX 100005

#define PI 3.14159265358979323846264338327950

#define ll signed long long int

ll t , n, a[MAXX], b[MAXX], c[MAXX];

signed main()
{
	FAST;
	string str;
	ll k;
	cin >> n >> k;
	cin >> str;
	str[k-1] += ' ';
	cout << str;
	
}

Measured memory_bytes: 256
a=input()
n=a.split(" ")[0]
y=a.split(" ")[1]
n=int(n)
y=int(y)
flag=True
for i in range(0,n+1): #10000
    for j in range(0,n+1-i): #5000
        k=n-j-i
        if i*10000+j*5000+k*1000==y and i+j+k==n:
            print(str(i)+" "+str(j)+" "+str(k))
            flag=False
            break
    if not flag:
        break
        
if flag:
    print("-1 -1 -1")

Measured memory_bytes: 3064
n,m = map(int, input().split())
T = list(map(int, input().split()))

if n >= m:
    print(0)
    exit()

T.sort()
diff = []
for i in range(1,m):
    diff.append(T[i]-T[i-1])
diff.sort(reverse=True)
print(sum(diff[n-1:]))


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

signed main(){

  int n,k;
  cin>>n>>k;

  vector<vector<int>> a;

  for(int b=0;b<(1<<n);++b){
    bitset<20> bit(b);
    if(bit.count()!=k)continue;
    vector<int> ai(1);
    ai[0] = bit.to_ulong();
    for(int i=0;i<n;++i)if(bit[i])ai.emplace_back(i);
    a.emplace_back(ai);
  }
  sort(a.begin(),a.end(),[](auto& a,auto& b){return a[0]<b[0];});

  for(auto v:a){
    cout<<v[0]<<":";
    for(int i=1;i<v.size();++i){
      cout<<" "<<v[i];
    }
    cout<<endl;
  }

}


Measured memory_bytes: 6548
# This program computes GCD and LCM
# -*- coding: utf-8
import sys


def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


for i in sys.stdin:
    try:
        line = [int(k) for k in i.split(" ")]
        g = gcd(min(line), max(line))
        print(str(g) + " " + str(line[0]*line[1]//g))
    except:
        exit()

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

int main(){
	int n1,n2,n3,n4,n5;
	string s1,s2,s3,s4,s5;

	cin >> n1 ;

    if(n1 < 1200){
      cout <<  "ABC" << endl;
    }
    else if(n1 < 2800){ 
      cout <<  "ARC" << endl;
    }
    else{
      cout <<  "AGC"<< endl;
    }
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <climits>
using namespace std;

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

struct Read {
	long long operator()(void) {
		long long d;
		std::cin >> d;
		return d;
	}
}read;
struct ReadReal {
	double operator()(void) {
		double d;
		std::cin >> d;
		return d;
	}
}readReal;
struct ReadString {
	std::string operator()(void) {
		std::string s;
		std::cin >> s;
		return s;
	}
}readString;

struct Print {
	void operator()(double d, int digit) {
		std::cout << std::fixed << std::setprecision(digit) << d;
	}
	template <typename T>
	void operator()(T t) {
		std::cout << t;
	}
	template <typename T>
	void operator()(const std::vector<T> &v, const std::string &sep = " ") {
		if (v.empty()) return;
		Print()(v[0]);
		for(int i = 1;  i < v.size(); ++i) {
			Print()(sep);
			Print()(v[i]);
		}
		return;
	}
}print;
struct Println {
	void operator()(void) {
		std::cout << std::endl;
	}
	void operator()(double d, int digit) {
		print(d, digit);
		Println()();
	}
	template <typename T>
	void operator()(T t) {
		print(t);
		Println()();
	}
	template <typename T>
	void operator()(const std::vector<T> &v, const std::string &sep = " ") {
		print(v, sep);
		Println()();
		return;
	}
}println;

int SelectionSort(vector<int> *vec) {
	auto &v = *vec;
	int count = 0;
	REP(i, v.size()) {
		int minj = i;
		FOR(j, i, v.size()) {
			if (v[minj] > v[j]) {
				minj = j;
			}
		}
		if (i != minj) {
			int tmp = v[minj];
			v[minj] = v[i];
			v[i] = tmp;
			count++;
		}
	}
	return count;
}

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

	auto size = read();
	vector<int> v(size);
	REP(i, size) {
		v[i] = read();
	}
	int count = SelectionSort(&v);
	println(v);
	println(count);

	return 0;
}



Measured memory_bytes: 3216
using System;
using System.Text;
using System.Diagnostics;
using System.Numerics;
using System.Collections.Generic;

class Myon

{
    public Myon() { }
    public static int Main()
    {
        cin = new Scanner();
        new Myon().calc();
        return 0;
    }
    static Scanner cin;


    void calc()
    {
        int A, B, C, X, Y;
        A = cin.nextInt();
        B = cin.nextInt();
        C = cin.nextInt();
        X = cin.nextInt();
        Y = cin.nextInt();

        int ab = 0;
        if (A + B > 2 * C)
        {
            ab = Math.Min(X, Y);
        }
        int ans = (X - ab) * A + (Y - ab) * B + 2 * ab * C;
        int abmax = Math.Max(X, Y);
        ans = Math.Min(ans, abmax * 2 * C);
        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: 13140
var input = '';
var readable = process.stdin;
readable.resume();
readable.setEncoding( 'utf-8' );
readable.on( 'data', function( chunk ) {
  input += chunk;
});

readable.on( 'end', function() {
  var data = input.split( " " );
  var x1 = parseFloat( data[0] );
  var y1 = parseFloat( data[1] );
  var x2 = parseFloat( data[2] );
  var y2 = parseFloat( data[3] );
  
  var d = Math.sqrt( Math.pow( x1-x2, 2 )+Math.pow( y1-y2, 2 ) );
  console.log( d );
});

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

int main()
{
	long n, i, temp, num = 0, loc, over = 0;
	long long a[100000];
	cin >> n;
	for(i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	sort(a, a+n);
	/*for(i = 0; i < n; i++)
	{
		cout << a[i] << endl;
	}*/
	temp = a[0];
	loc = 0;
	for(i = 0; i < n; i++)
	{
//		cout << i << " " << temp << " " << loc << " " << over << endl;
		if((a[i] == temp) && (loc < temp))
		{
			loc++;
		}
		else if((a[i] == temp) && (loc >= temp))
		{
			over++;
		}
		else if((a[i] > temp) && (loc == temp))
		{
//			cout << i << " " << temp << " " << loc << " " << over << endl;
			temp = a[i];
			loc = 1;
//			cout << i << " " << temp << " " << loc << " " << over << endl;
		}
		else if((a[i] > temp) && (loc < temp))
		{
//			cout << i << " " << temp << " " << loc << " " << over << endl;
				num += loc;
				loc = 1; 
				temp = a[i];	
		}
//		cout << i << " " << temp << " " << loc << " " << over << endl;
	}
//	cout <<"loc = "<< loc << endl;
//	cout <<"num = "<< num << endl;
//	cout <<"over = "<< over << endl;
	if(temp > loc)
	{
		num += loc;
	}
	num += over; 
	cout << num << endl;
	return 0;
} 

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


int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int ans = min ({
    abs(a-b)+abs(b-c),
    abs(a-c)+abs(c-b),
    abs(b-a)+abs(a-c),
    abs(b-c)+abs(c-a),
    abs(c-a)+abs(a-b),
    abs(c-b)+abs(b-a)});
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }

struct Tmp
{
public:
  int N;
  Tmp(int N)
  : N(N)
  {}
};

void solve(void)
{
  int N, M; cin >> N >> M;
  vector<ll> A(N);
  for (auto& a : A) { cin >> a; }
  boost::sort(A, std::greater<ll>());
  auto S = boost::accumulate(A, 0);

  for (int i = 0; i < M; ++i) {
    auto isOk = 4 * M * A[i] >= S;
    if (!isOk) {
      cout << "No" << CRLF;
      return;
    }
  }
  cout << "Yes" << CRLF;

  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 256
prime=[True]*1000000
np=[0]*1000000
for i in range(2,1000000):
    if prime[i]:
        for j in range(i*2,1000000,i):
            prime[j]=False
    np[i]=np[i-1]+prime[i]

while True:
    try:
        n=int(input())
    except:
        break
    print(np[n])

Measured memory_bytes: 54456
#include<iostream>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include <algorithm> 
using namespace std;

# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;

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

    int c_z=0,c_o=0;
    for(int i=0;i<s.size();i++){
        char tmp=s.at(i);
        if(tmp=='0') c_z++;
        else if(tmp=='1') c_o++;
    }
    p(min(c_z,c_o)*2)
}

Measured memory_bytes: 512
object Main extends App {

  val Array(n, a, b) = io.StdIn.readLine.split(" ").map(_.toInt)

  val ans = (1 to n).map( i => {
      val sum = String.valueOf(i).map(_.asDigit).sum
      if(a <= sum && sum <= b ) i else 0
    }).sum

  println(ans)
}

Measured memory_bytes: 32860
X_str = input()
X  = int(X_str)

if 400<=X<=599:
    print("8")
elif 600<=X<=799:
    print("7")
elif 800<=X<=999:
    print("6")
elif 1000<=X<=1199:
    print("5")
elif 1200<=X<=1399:
    print("4")
elif 1400<=X<=1599:
    print("3")
elif 1600<=X<=1799:
    print("2")
else :
    print("1")

Measured memory_bytes: 9192
N, M = map(int, input().split())
surveys = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for i in range(1, M+1):
    flag = True
    for survey in surveys:
        if i not in survey[1:]:
            flag = False
            break
    if flag:
        ans += 1
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=3e5+5;
char s[N],a[N],b[N],c[5];
int main() {
    //freopen("in.txt","r",stdin);
    int n,q,t=0,ta=0,tb=0;
    scanf("%s%d",s,&q),n=strlen(s);
    for(int i=0,op;i<q;i++) {
        scanf("%d",&op);
        if(op==1) t^=1;
        else {
            scanf("%d%s",&op,c),op--;
            if(op^t) b[tb++]=c[0];
            else a[ta++]=c[0];
        }
    }
    if(!t) {
        for(int i=ta-1;i>=0;i--) printf("%c",a[i]);
        for(int i=0;i<n;i++) printf("%c",s[i]);
        for(int i=0;i<tb;i++) printf("%c",b[i]);
    }
    else {
        for(int i=tb-1;i>=0;i--) printf("%c",b[i]);
        for(int i=n-1;i>=0;i--) printf("%c",s[i]);
        for(int i=0;i<ta;i++) printf("%c",a[i]);
    }
    return 0;
}

Measured memory_bytes: 896
package main

import (
	"fmt"
)

func main() {
	var n int
	var s string
	fmt.Scan(&n,&s)
	
	ans := ""
	past := ""
	for _,v := range s {
		stv := string(v)
		if past != stv {
			ans += stv
		}
		past = stv
	}
	fmt.Println(len(ans))
}

Measured memory_bytes: 8704
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const long double EPS = 1e-10;

ll modpow(ll a,ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

ll nCr(ll n, ll r) {
  r = min(n-r, r);
  if (r == 0) return 1;
  ll ans = 1;
  FOR(i, n-r+1, n+1) ans = ans * i % mod;
  ll a = 1;
  FOR(i, 1, r+1) a = a * i % mod;
  ans = ans * modpow(a, mod-2) % mod;
  return ans;
}

int main() {
  ll x, y;
  cin >> x >> y;

  if ((x + y) % 3 != 0) {
    cout << 0 << endl;
  }
  else {
    ll n = (x + y) / 3;
    ll r = x - n;
    if (r < 0 || r > n) cout << 0 << endl;
    else {
      cout << nCr(n, r) << endl;
    }
  }


  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

//??????????´????????????????
class DisjoinSet {
	public :
		vector<int> rank, p;

		DisjoinSet() {}
		
		//n????????????????´?????????????????????????
		DisjoinSet(int size) {
			rank.resize(size,0);
			p.resize(size,0);
			for (int i = 0; i < size; i++) {
				makeSet(i);
			}
		}

		void makeSet(int x) {
			p[x] = x;
			rank[x] = 0;
		}

		//?????????????´??????????????????????ture ??§???????????°false
		bool same(int x, int y) {
			return findSet(x) == findSet(y);
		}


		//x?????????????????¨y??????????????????????????????
		void unite(int x, int y) {
			link(findSet(x), findSet(y));
		}


		//??£??¨x?????¨??¨??£??¨y?????¨???????????????
		void link(int x, int y) {
			if (rank[x] > rank[y]) {
				p[y] = x;
			}
			else {
				p[x] = y;
				if (rank[x] == rank[y]) {
					rank[y]++;
				}
			}
		}


		//??¨(??????)?????£??¨?????????????????????????????§?????????????????????????????´??\??£??¨???????????????????????????
		int findSet(int x) {
			if (x != p[x]) {
				p[x] = findSet(p[x]);
			}

			return p[x];
		}

};

int main(void)
{
	int n, a, b, q;
	int t;

	cin >> n >> q;
	DisjoinSet ds = DisjoinSet(n);

	for (int i = 0; i < q; i++) {
		cin >> t >> a >> b;
		if (t == 0) {
			ds.unite(a,b);
		}
		else if (t == 1) {
			if (ds.same(a, b)) {
				cout << 1 << endl;
			}
			else {
				cout << 0 << endl;
			}

		}
	}

	return 0;

}

Measured memory_bytes: 3176
from heapq import heappop, heapify

s = input()
N = len(s)
K = int(input())

sub = set()
for i in range(N):
  for j in range(5):
    if i+j+1 <= N:
      sub.add(s[i:i+j+1])

sub = list(sub)
heapify(sub)
for i in range(K-1):
  _ = heappop(sub)
print(heappop(sub))


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

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

	int N=in(),K=in();
  vector<int> h(N);
	for(auto& x:h){
      x=in();
    }
  sort(ALL(h),greater<int>());
  int hmin=1e9+7;
  for(int i=0;i+K-1<N;i++){
    hmin = min(hmin,h[i]-h[i+K-1]);
  }
  
  cout << hmin << endl;
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
using namespace std;
int main(){
	int a[100]={0},b,c=1;
	while(cin>>b){
		a[b-1]++;
		if(a[b-1]>c)
			c=a[b-1];
	}
	for(int i=0;i<100;i++){
		if(a[i]==c)
			cout<<i+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=j; i<=k; i++)
#define FFOR(i, j, k) for(int i=j; i<k; i++)
#define DFOR(i, j, k) for(int i=j; i>=k; i--)
#define bug(x) cerr<<#x<<" = "<<x<<'\n'
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
template <typename T> inline void read(T &x){
    char c;
    bool nega=0;
    while((!isdigit(c=getchar()))&&(c!='-'));
    if(c=='-'){
        nega=1;
        c=getchar();
    }
    x=c-48;
    while(isdigit(c=getchar())) x=x*10+c-48;
    if(nega) x=-x;
}
template <typename T> inline void writep(T x){
    if(x>9) writep(x/10);
    putchar(x%10+48);
}
template <typename T> inline void write(T x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    writep(x);
}
template <typename T> inline void writeln(T x){
    write(x);
    putchar('\n');
}
#define taskname "D"
const ll inf=(1e9)+1;
priority_queue <pair <ll, pair <int, int> > > q;
int n;
ll a[301][301];
ll c[301][301];
int u, v;
int main(){
    #ifdef Megumin
        if(fopen(taskname".inp", "r"))
            freopen(taskname".inp", "r", stdin);
    #endif // Megumin
    read(n);
    FOR(i, 1, n) FOR(j, 1, n) read(a[i][j]);
    FOR(i, 1, n) FOR(j, i+1, n) q.push(mp(-a[i][j], mp(i, j)));
    FOR(i, 1, n) FOR(j, 1, n) c[i][j]=inf;
    FOR(i, 1, n) c[i][i]=0;
    ll ans=0;
    while(!q.empty()){
        u=q.top().second.first;
        v=q.top().second.second;
        q.pop();
        if(c[u][v]<a[u][v]){
            puts("-1");
            return 0;
        }
        if(c[u][v]>a[u][v]){
            FOR(i, 1, n) FOR(j, 1, n){
                c[i][j]=min(c[i][j], c[i][u]+a[u][v]+c[v][j]);
                c[i][j]=min(c[i][j], c[i][v]+a[u][v]+c[u][j]);
            }
            ans+=a[u][v];
        }
    }
    write(ans);
}

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

signed main() {
  string S;
  cin >> S;
  vector<regex> Re(8);
  Re[0] = (".*keyence");
  Re[1] = ("k.*eyence");
  Re[2] = ("ke.*yence");
  Re[3] = ("key.*ence");
  Re[4] = ("keye.*nce");
  Re[5] = ("keyen.*ce");
  Re[6] = ("keyenc.*e");
  Re[7] = ("keyence.*");
  bool ans = false;
  for(auto r : Re) ans |= regex_match(S, r);
  cout << (ans ? "YES" : "NO") << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
using namespace std;
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INFTY 999999

int n,M[N][N];
int d[N];
queue<int> q;

void bfs(int s)
{
   q.push(s);
   for(int i=0;i<n;i++)
   {
       d[i]=INFTY;
   }
   d[s]=0;
   int u;
   while(!q.empty())
   {
       u=q.front();q.pop();
       for(int v=0;v<n;v++)
       {
           if(M[u][v]==0)continue;
           if(d[v]!=INFTY)continue;
           d[v]=d[u]+1;
           q.push(v);
       }
   }
   for(int i=0;i<n;i++)
   {
       cout << i+1 << " " << (d[i]==INFTY? (-1):d[i] ) << endl;
   }
}

int main()
{
    int u,k,v,node;
    cin >> n;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            M[i][j]=0;
        }
    }

    for(int i=0;i<n;i++)
    {
        cin >> u;//row
        if(i==u-1)
        {
            cin >> node;//number of node
            for(int j=0;j<node;j++)
            {
                cin >> v;
                M[i][v-1]=1;
            }
        }
    }

    /*
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            cout << M[i][j] << " " ;
        }
        cout << endl;
    }*/

    bfs(0);
    return 0;
}



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

int main(){
	long long n; cin >> n;
  	string s = "";
  
  	while(n > 0){
      	n -= 1;
    	s += 'a' + n%26;
      	n = n/26;
    }
  	
  	reverse(s.begin(), s.end());
  	cout << s << endl;
}

Measured memory_bytes: 3628
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
const long long int exa = 1000000000000000000;
//const int MOD = 1000000007;
//const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R;


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

	cin >> N >> M;
	string s;
	cin >> s;
	vector<pair<char, char>>v(M);
	for (auto &i : v)cin >> i.first >> i.second;
	int l = -1, r = N;
	while (r - l > 1) {
		int mid = (r + l) / 2;
		int p = mid;
		for (auto i : v) {
			if (s[p] == i.first) {
				if (i.second == 'L')p--;
				else p++;
			}
			if (p < 0 || p >= N)break;
		}
		if (p < 0)l = mid;
		else r = mid;
	}
	L = -1, R = N;
	while (R - L > 1) {
		int mid = (R + L) / 2;
		int p = mid;
		for (auto i : v) {
			if (s[p] == i.first) {
				if (i.second == 'L')p--;
				else p++;
			}
			if (p < 0 || p >= N)break;
		}
		if (p >= N)R = mid;
		else L = mid;
	}
	cout << L - r + 1 << endl;
	//cout << r << " " << L << endl;
	//cout << N - L + r + 1 << endl;
	return 0;
}

Measured memory_bytes: 976
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> xs(n);
    for (int i = 0; i < n; ++i) {
        cin >> xs[i];
    }
    sort(xs.begin(), xs.end());
    int ans = numeric_limits<int>::max();
    for (int p = xs[0]; p <= xs[n - 1]; ++p) {
        int sum = 0;
        for (int i = 0; i < n; ++i) {
            sum += (xs[i] - p) * (xs[i] - p);
        }
        ans = min(ans, sum);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define rrep(i,n) for(int i=(n);i>=0;--i)
#define ssort(n) sort((n).begin(),(n).end())
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define INF 10101010

int main()
{
    int n,m;
    cin >> n >> m;
    vector<vector<int>> s(m,vector<int>(n));
    vector<int> p(m);
    vector<int> bit(n);
    vector<int> k_m(m);
    ll count=0;
    ll ans=0;
    ll count_sw=0;
    int k;
    rep(i,m){
        rep(j,n){
            s[i][j]=-1;
        }
    }
    rep(i,m){
        cin >> k_m[i];

        rep(j,k_m[i]){
            cin >> s[i][j];
        }
    }
    rep(i,m)cin >> p[i];

    rep(i,(1<<n)){
        rep(j,n){
            int div=(1<<j);
            bit[j]=(i/div)%2;
        }
        rep(j,m){
            for(int l=0;l<k_m[j];++l){
                if(bit[s[j][l]-1]==1)
                    count_sw++;
                    
                
            }
            if(count_sw%2==p[j]%2){
                count++;
            }else{
                count_sw=0;
                count=0;
                break;
            }
            count_sw=0;
        }
        if(count==m){
            ans++;
            count=0;
            count_sw=0;
        }else{
            count=0;
            count_sw=0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;
typedef std::pair<double, double> pdd;
using namespace std;


#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define loope(i,a,b) for(ll i=a;i<=b;i++)
#define test() ull testcase;cin>>testcase;while(testcase--)
#define pb push_back
#define mp make_pair
#define nl cout<<"\n"
#define prime 1000000007
#define debug(x) cout<<(#x)<<" : "<<x,nl
#define debug2(x,y) cout<<(#x)<<" : "<<x<<" "<<(#y)<<" : "<<y,nl
#define debug3(x,y,z) cout<<(#x)<<" : "<<x<<" "<<(#y)<<" : "<<y<<" "<<(#z)<<" : "<<z,nl
#define f first
#define s second
#define oa(a,n) loop(i,0,n)cout<<a[i]<<" ";nl;
#define ov(a) loop(i,0,a.size()) cout<<a[i]<<" ";nl;
#define MOD(a) (((a%prime)+prime)%prime)

int main()
{

    ll r,d,x,i,j;

    cin >> r >> d >> x;

    for(i=1;i<=10;i++)
    {
        x = r*x-d;
        cout << x << endl;
    }

}

Measured memory_bytes: 256
import sys
H,W,K=map(int,input().split())
if W==1:
    print(1)
    sys.exit()
L=[1,1,2,3,5,8,13,21,34]
mod=10**9+7
dp=[[0]*W for i in range(H+1)]
dp[0][0]=1
for i in range(H):
    for j in range(W):
        if j==0:
            dp[i+1][j]+=dp[i][j]*L[W-1]
            dp[i+1][j]+=dp[i][j+1]*L[W-2]
            dp[i+1][j]%=mod
        elif j==W-1:
            dp[i+1][j]+=dp[i][j]*L[W-1]
            dp[i+1][j]+=dp[i][j-1]*L[W-2]
            dp[i+1][j]%=mod
        else:
            dp[i+1][j]+=dp[i][j-1]*L[j-1]*L[W-j-1]
            dp[i+1][j]+=dp[i][j]*L[j]*L[W-j-1]
            dp[i+1][j]+=dp[i][j+1]*L[j]*L[W-j-2]
            dp[i+1][j]%=mod
print(dp[H][K-1])

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
    long long int ans = 0;
    for(int i = n-1; i >= 0; i--){
        if((a[i]+ans)%b[i] != 0){
            ans += b[i] - (a[i]+ans)%b[i];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3984
#include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<math.h>
#include<map>
#include <unordered_map> 
#include<vector>
#include<queue>
#include<set>
#include <bits/stdc++.h> 
#include<string>
#define N 405
#define K 200005
#define MOD 1e9+7
#define ll long long int
using namespace std;
ll no = 1e18-10;
	// dp[i][j] stores the cost of combining position i to j//ans is dp[0][n]
int main(){
	int n;
	cin>>n;
	ll a[n+1];
	ll b[n+1] = {0};
	
	ll x;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		b[i] = b[i-1] +a[i];
	}
	vector<vector<ll>>dp(N,vector<ll>(N,no));
	for(int g=0;g<=n;g++){
		for(int i = 1;i+g<=n;i++){
			int j = i+g;
			ll s = b[j] - b[i-1];
			if(i==j)
				dp[i][j] = 0;
			else{
				for(int sp = i+1;sp<=j;sp++){
				    //if(i==1 && j==2)
				      //  cout<<i;
					dp[i][j] = min(dp[i][j],dp[i][sp-1]+dp[sp][j] + s);
				}
			}
		}
	}
	/*
	for(int i=1;i<=n;i++){
	    for(int j=1;j<=n;j++){
	        cout<<dp[i][j]<<" ";
	    }
	    cout<<endl;
	}*/
	cout<<dp[1][n];
}	


Measured memory_bytes: 1536
n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
	a[i] -= 1

city_position = {}
step = 0
city = 0

while city not in city_position:
	city_position[city] = step
	city = a[city]
	step += 1

steps_before_cycle = city_position[city]
cycle_len = step - steps_before_cycle

# k %= cycle_len

city = 0
for i in range(min(k, steps_before_cycle)):
	city = a[city]

k -= steps_before_cycle
if k > 0:
	k %= cycle_len

	for i in range(k):
		city = a[city]


print(city+1)


Measured memory_bytes: 111652
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<bool>prime(100005);
    vector<ll>p;
    for(ll i = 2; i <= 100000; i++){
        if(!prime[i]){
            p.push_back(i);
            for(ll j = i; i * j <= 10000; j++){
                prime[i * j] = true;
            }
        }
    }
    int N;
    cin >> N;
    vector<ll>A(N);
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    vector<ll>B(N);
    vector<ll>C(N, 1);
    for(int i = 0; i < N; i++){
        for(ll x : p){
            ll y = x * x * x;
            if(A[i] < y)break;
            while(A[i] % y == 0)A[i] /= y;
        }
        B[i] = A[i];
        __int128_t k = 1;
        for(int j = 0; j < p.size() and p[j] <= 2500; j++){
            if(A[i] % p[j] == 0){
                A[i] /= p[j];
                if(A[i] % p[j] == 0){
                    k *= p[j];
                    A[i] /= p[j];
                }else{
                    k *= p[j] * p[j];
                }
            }
        }
        if(k > 1e10){
            C[i] = -1;
            continue;
        }
        if(A[i] == 1){
            C[i] = k;
            continue;
        }
        ll t = sqrt(A[i]);
        while(t * t < A[i])t++;
        while(t * t > A[i])t--;
        if(t *t == A[i] and !prime[t])k *= t;
        else{
            k *= A[i];
            k *= A[i];
        }
        assert(k > 0);
        if(k > 1e10){
            C[i] = -1;
        }else{
            C[i] = k;
        }
    }
    show(B,C);
    map<ll, int> mp;
    map<ll, ll> mp2;
    ll ans = 0;
    for(int i = 0; i < N; i++){
        mp[B[i]]++;
        mp2[B[i]] = C[i];
    }
    map<ll, bool>used;
    for(auto x : mp){
        if(used[x.first])continue;
        if(x.first == 1){
            ans++;
            continue;
        }
        ans += max(x.second, mp.count(mp2[x.first]) ? mp[mp2[x.first]] : 0);
        used[x.first] = used[mp2[x.first]] = true;
    }
    cout << ans << endl;
}

Measured memory_bytes: 24052
#include<bits/stdc++.h>
using namespace std;
const int N=105;
queue<int>q;int n,m;
int dx[]={0,1};
int dy[]={1,0};
inline bool ok(int x,int y){return (x>=0&&y>=0&&x<n&&y<m);}
int dist[N][N][2];char c[N][N];
void BFS()
{
	q.push(0);
	q.push(0);
	q.push(c[0][0]=='#');
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			for(int k=0;k<2;k++)
				dist[i][j][k]=1e9;
	dist[0][0][c[0][0]=='#']=(c[0][0]=='#');
	while(!q.empty())
	{
		int x=q.front();q.pop();
		int y=q.front();q.pop();
		bool f=q.front();q.pop();
		int now=dist[x][y][f];
		for(int i=0;i<2;i++)
		{
			int x2=x+dx[i];
			int y2=y+dy[i];
			int qwq=now;
			bool f2=f;
			if(c[x2][y2]=='#')
				if(!f)qwq++,f2=true;
			if(c[x2][y2]=='.')
				if(f)f2=false;
			if(ok(x2,y2)&&dist[x2][y2][f2]>qwq)
			{
				dist[x2][y2][f2]=qwq;
				q.push(x2);
				q.push(y2);
				q.push(f2);
			}
		}
	}
}
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)cin>>c[i];
	BFS();
	cout<<min(dist[n-1][m-1][0],dist[n-1][m-1][1])<<"\n";
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

vector<vector<int>> to(200000);
vector<int> cnt(200000, 0);
vector<int> ans(200000, 0);
vector<bool> vis(200000, false);
void dfs(int v, int c){
    vis[v] = true;
    ans[v] = c;
    for(int t : to[v]){
        if(vis[t])continue;
        dfs(t, c + cnt[t]);
    }
}

int main() {
    int n, q;
    cin >> n >> q;
    rep(i, n - 1){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    
    rep(i, q){
        int p, x;
        cin >> p >> x;
        p--;
        cnt[p] += x;
    }

    dfs(0, cnt[0]);
    rep(i, n)cout << ans[i] << ' ';
    cout << endl;
}

Measured memory_bytes: 24320
#include <bits/stdc++.h>
using namespace std;
 
bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}
 
int n, d, x;
int a[101];

int main(){
    cin >> n >> d >> x;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }

    for(int i = 1; i <= n; i++){
        x += (d-1)/a[i] + 1;
    }

    cout << x << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
int N, X, Y, A[100];

int main(void){
	//IO("test.in", "test.out");
	scanf("%d", &N);
	for(int i = 0; i < N; i++) scanf("%d", &A[i]);
	sort(A, A + N, greater<int>());
	for(int i = 0; i < N; i++)
		if(i % 2 == 1) X += A[i];
		else Y += A[i];
	printf("%d\n", abs(X - Y));
}

Measured memory_bytes: 256
s= input()

if s == "SUN":
  ans = 7
elif s == "MON":
  ans = 6
elif s == "TUE":
  ans = 5
elif s == "WED":
  ans = 4
elif s == "THU":
  ans = 3
elif s == "FRI":
  ans = 2
elif s == "SAT":
  ans = 1
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int int64_t
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define REPR(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i=(m)-1; i>=(n); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<int>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define pa cout << ans << endl
#define p(x) cout << x << endl
#define pall(x) for(auto iter : x) p(iter)
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define yn(x) cout << (x ? "Yes" : "No") << endl
using namespace std;
using Graph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
typedef long double LD;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const int MOD = 1000000007;
const int INF = 2000000000;
const long double PI = acosl(-1);
void print() {cout << endl;}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " ";print(forward<Tail>(tail)...);}
template <class T> void print(vector<T> &vec) {for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " ";} cout << endl;}
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec);}}
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; }

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int N;
    cin >> N;
    vector<int> A(N);
    map<int,int> mp;
    REP (i, N) {
        cin >> A[i];
        mp[A[i]]++;
    }
    int ans = 0;
    for (auto i : mp) ans += i.second*(i.second-1)/2;

    REP(i,N) {
        p(ans - mp[A[i]]*(mp[A[i]]-1)/2 + (mp[A[i]]-2)*(mp[A[i]]-1)/2);
    }
    


    

    
    
    return 0;
}

/*
cd ~/Desktop/Programming/AtCoder/contest/abc159/abc159_d && sh test.sh
cd ~/Desktop/Programming/AtCoder/contest/abc159/abc159_d && sh etest.sh
cd ~/Desktop/Programming/AtCoder/contest/abc159/abc159_d && sh submit.sh
*/


Measured memory_bytes: 11136
import Control.Monad (replicateM)

main :: IO ()
main = do
  [n, limit] <- map read . words <$> getLine
  cts <- map ((\[x, y] -> (x, y)) . map read . words) <$> replicateM n getLine
  putStrLn $ maybe "TLE" show $ f limit cts

f :: Int -> [(Int, Int)] -> Maybe Int
f limit =
  (\xs -> if null xs then Nothing else Just (minimum xs)) .
  map fst .
  filter ((<= limit) . snd)

tests, test1, test2, test3 :: Bool
tests = test1 && test2 && test3
test1 = f 70 [(7, 60), (1, 80), (4, 50)] == Just 4
test2 = f 3 [(1, 1000), (2, 4), (3, 1000), (4, 500)] == Nothing
test3 = f 9 [(25, 8), (5, 9), (4, 10), (1000, 1000), (6, 1)] == Just 5


Measured memory_bytes: 1020
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 1 << 21;
using pii = std::pair<int, int>;
#define SORT(v) std::sort(v.begin(), v.end())
int main(void) {
	std::string s;
	int N, e_sum = 0, w_sum = 0, e_i = 0,w_i=0,ans=1000000;
	std::cin >> N>> s;
	for (int i = 0; i < N; ++i) {
		if (s[i] == 'E')e_sum++;
		else w_sum++;
	}
	if (s[0] == 'E') {
		ans = e_sum - 1;
		e_i++;
		e_sum--;
	}
	else if (s[0] == 'W') {
		ans = e_sum;
		w_i++;
		w_sum--;
	}
	int tempe=0, tempw=0;
	for (int i = 1; i < N; ++i) {
		if (i==N-1) {
			ans = std::min(ans, w_i);
		}
		
		if (s[i] == 'E') {
			e_sum--;
			ans = std::min(ans, e_sum + w_i);
			e_i++;
		}
		else if(s[i] == 'W'){
			w_sum--;
			ans = std::min(ans, e_sum + w_i);
			w_i++;
		}
		//std::cout << e_i << " " << w_i <<" " <<ans<<std::endl;
	}
	
	std::cout << ans << std::endl;
	return 0;
	
}


Measured memory_bytes: 900
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

S = B[A[0]-1]
for i in range(1, N):
  if A[i] == A[i-1] + 1:
    S += B[A[i]-1] + C[A[i-1]-1]
  else:
    S += B[A[i]-1]
print(S)

Measured memory_bytes: 3060
package main
 
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)
 
var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  var line, buffer []byte
  var isPrefix bool = true
  var err error
  for isPrefix {
    line, isPrefix, err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
  }
  return string(buffer)
}
func NextInt() int {
  var n int
  n, _ = strconv.Atoi(NextLine())
  return n
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func Output() {
  _ = writer.Flush()
}

func main() {
  N := NextInt()
  S := NextLine()
  W := make([]int, N + 1)
  B := make([]int, N + 1)
  cnt := N
  for i := N; 0 < i; i-- {
    W[i - 1] = W[i]
    if S[i - 1] == '.' { W[i - 1]++ }
  }
  for i, s := range S {
    B[i + 1] = B[i]
    if s == '#' { B[i + 1]++ }
    if W[i] + B[i] < cnt { cnt = W[i] + B[i] }
  }
  if W[N] + B[N] < cnt { cnt = W[N] + B[N] }
  Write(cnt)
  Output()
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    int cnt=1;
    rep(i,n){
        if(a[i]==cnt) cnt++;
    }
    if(cnt==1) cout<<-1;
    else cout<<n-cnt+1;
}

Measured memory_bytes: 4036
#include <cstdio>

int main()
{
	int x;
	int h, m, s;
	scanf("%d", &x);

	if (x < 60){
		h = 0;
		m = 0;
		s = x;
		printf("%d:%d:%d\n", h ,m, s);
	}
	else if (x < 3600){
		h = 0;
		m = x/60;
		s = x%60;
		printf("%d:%d:%d\n", h ,m, s);
	}
	else if (x < 86400){
		h = x/3600;
		m = (x % 3600)/60;
		s = (x % 3600)%60;
		printf("%d:%d:%d\n", h ,m, s);
	}
	return 0;
}

Measured memory_bytes: 1024
package main

import "fmt"

func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)
	if a * b > c * d {
		fmt.Println(a * b)
	} else if a * b < c * d {
		fmt.Println(c * d)
	} else {
		fmt.Println(a * b)
	}
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef pair<int, int> ii;
typedef pair<ll, ll> pll;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	cin >> s;
	int c = count(s.begin(), s.end(), 'R');
	if (c == 3)
		cout << 3 << "\n";
	else if (c == 2 && s[1] != 'S')
		cout << 2 << "\n";
	else if (c == 0)
		cout << 0 << "\n";
	else
		cout << 1 << "\n";

	return 0;
}


Measured memory_bytes: 3576
//
// Created by moono on 2018/10/27.
//

#include <iostream>
#include <string>
#include <set>
#include <vector>
using namespace std;


int main() {
//    int N = 6;
//    string S = "aabbca";
    int N;
    string S;
    cin >> N;
    cin >> S;

    //
    const char* S_cstr = S.c_str();

    //
    int nums_max = 0;
    for (int i = 1; i < N-1; ++i) {
        set<char> set_right, set_left;

        for (int j = 0; j < i; ++j){
            set_right.insert(S_cstr[j]);
        }

        int num_char = 0;
        for (int j = i; j < N; ++j) {
            char c = S_cstr[j];
            if(set_left.find(c) == set_left.end() && set_right.find(c) != set_right.end()){
                num_char++;
            }
            set_left.insert(c);
        }
//        cout << num_char << endl;

        if(nums_max < num_char) {
            nums_max = num_char;
        }
    }


    cout << nums_max << endl;
    return 0;
}

Measured memory_bytes: 256