akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
int N, X, Y, Z;
long long O;
std::pair < long long, long long > p[100001], q[100001];
std::pair < long long, std::pair < int, int > > check(long long mid)
{
	int i = 1, j = 1, gi = 0, gj = 0;
	long long s = 0;
	while (gi + gj < X + Y)
	{
		while (i <= N && p[i].first + mid < p[i].second)
			i++;
		if (i > N)
			break;
		while (j <= N && q[j].first + mid >= q[j].second)
			j++;
		if (j > N)
			break;
		if (p[i].first + mid >= q[j].second)
		{
			gi++;
			s += p[i++].first;
		}
		else
		{
			gj++;
			s += q[j++].second;
		}
	}
	while (gi + gj < X + Y)
	{
		while (i <= N && p[i].first + mid < p[i].second)
			i++;
		if (i > N)
			break;
		gi++;
		s += p[i++].first;
	}
	while (gi + gj < X + Y)
	{
		while (j <= N && q[j].first + mid >= q[j].second)
			j++;
		if (j > N)
			break;
		gj++;
		s += q[j++].second;
	}
	i = 1, j = 1;
	int Gi = 0, Gj = 0;
	long long S = 0;
	while (Gi + Gj < X + Y)
	{
		while (i <= N && p[i].first + mid <= p[i].second)
			i++;
		if (i > N)
			break;
		while (j <= N && q[j].first + mid > q[j].second)
			j++;
		if (j > N)
			break;
		if (p[i].first + mid > q[j].second)
		{
			Gi++;
			S += p[i++].first;
		}
		else
		{
			Gj++;
			S += q[j++].second;
		}
	}
	while (Gi + Gj < X + Y)
	{
		while (i <= N && p[i].first + mid <= p[i].second)
			i++;
		if (i > N)
			break;
		Gi++;
		S += p[i++].first;
	}
	while (Gi + Gj < X + Y)
	{
		while (j <= N && q[j].first + mid > q[j].second)
			j++;
		if (j > N)
			break;
		Gj++;
		S += q[j++].second;
	}
	return { S - mid * (X - Gi), { Gi, gi } };
}
int main()
{
	scanf("%d%d%d", &X, &Y, &Z);
	N = X + Y + Z;
	for (int i = 1; i <= N; i++)
	{
		long long a, b, c;
		scanf("%lld%lld%lld", &a, &b, &c);
		O += c;
		p[i] = q[i] = std::make_pair(a - c, b - c);
	}
	std::sort(p + 1, p + N + 1, [] (const auto &i, const auto &j) { return i.first > j.first; });
	std::sort(q + 1, q + N + 1, [] (const auto &i, const auto &j) { return i.second > j.second; });
	long long l = -1000000000, r = 1000000000;
	while (l < r)
	{
		long long m = l + r >> 1;
		std::pair < long long, std::pair < int, int > > ans = check(m);
		if (ans.second.first <= X && X <= ans.second.second)
		{
			printf("%lld\n", O + ans.first);
			return 0;
		}
		if (ans.second.second < X)
			l = m + 1;
		else
			r = m - 1;
	}
	while (1);
}


Measured memory_bytes: 3328
#include <algorithm>
#include <climits>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map> //pair is also included in this library
#include <queue>
#include <stack>
#include <string>
#include <vector>

#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

using namespace std;

typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;

//prefer define statement
//for reason that const int ver. of INF will raise a silly warning (unused variable)
#define INF (INT_MAX/3)
#define LIM_INF (INT_MAX)
//const int INF = INT_MAX/3;

/*------------------------------------------------------------------------------*/

int main(){
  REP(i, 1, 10){
    REP(j, 1, 10){
      cout << i << "x" << j << "=" << i*j << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3080
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <unordered_set>
using namespace std;

int main()
{
	int h, w;
	cin >> h >> w;

	int ch, cw;
	cin >> ch >> cw;
	ch--;
	cw--;

	int dh, dw;
	cin >> dh >> dw;
	dh--;
	dw--;

	vector<string> mat(h);
	for (auto& i : mat) {
		cin >> i;
	}

	vector<vector<int>> fm(h, vector<int>(w, 0));

	//.の領域ごとに値をつける 1,2...# は -1 にする
	int region = 1;
	for (int y = 0; y < h; ++y) {
		for (int x = 0; x < w; ++x) {

			if (fm[y][x] != 0) {
				//調査済み
				continue;
			}
			else if (mat[y][x] == '#') {
				fm[y][x] = -1;
				continue;
			}

			queue<pair<int, int>> q;
			q.push({y,x});
			while (!q.empty()) {

				const pair<int,int>& fr = q.front();

				if (fm[fr.first][fr.second] != 0) {
					q.pop();
					continue;
				}

				if (mat[fr.first][fr.second] == '#') {
					fm[fr.first][fr.second] = -1;
				}
				else {
					fm[fr.first][fr.second] = region;
					if (0 < fr.first) {
						q.push({ fr.first - 1,fr.second });
					}
					if (fr.first < h - 1) {
						q.push({ fr.first + 1,fr.second });
					}
					if (0 < fr.second) {
						q.push({ fr.first,fr.second - 1 });
					}
					if (fr.second < w - 1) {
						q.push({ fr.first,fr.second + 1 });
					}
				}
				q.pop();
			}

			region++;
		}
	}

	//c と d が同じ領域ならば答えは０
	if (fm[ch][cw] == fm[dh][dw]) {
		cout << 0 << endl;
		return 0;
	}

	//#の周辺８つの場所で違う領域があれば、そこはワープ可能
	//あとはどこからどこへワープできるか調べて回数を求める
	vector<unordered_set<int>> gf(region + 1);
	for (int y = 0; y < h; ++y) {
		for (int x = 0; x < w; ++x) {
			if (fm[y][x] == -1) {
				continue;
			}
			unordered_set<int> temp;
			for (int i = y - 2; i <= y + 2; ++i) {
				for (int j = x - 2; j <= x + 2; ++j) {
					if (i < 0 || h <= i || j < 0 || w <= j) {
						continue;
					}
					if (fm[i][j] == -1) {
						continue;
					}
					temp.insert(fm[i][j]);
				}
			}
			for (auto i : temp) {
				gf[fm[y][x]].insert(i);
			}
		}
	}

	int ret = -1;
	{
		vector<bool> check(region + 1, false);
		queue<pair<int, int>> q;
		q.push({fm[ch][cw], 0});
		check[fm[ch][cw]] = true;
		while (!q.empty())
		{
			pair<int,int> fr = q.front();
			if (fr.first == fm[dh][dw]) {
				ret = fr.second;
				break;
			}
			for (auto i : gf[fr.first]) {
				if (!check[i]) {
					q.push({ i, fr.second + 1 });
					check[i] = true;
				}
			}
			q.pop();
		}
	}
	cout << ret << endl;

	return 0;
}

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

int main() {
	int n,k;cin>>n>>k;int a[n];map<int,int> m;
	for(int i=0;i<n;i++){
		cin>>a[i];
		m[a[i]]++;
//		cout<<a[i]<<' '<<m[a[i]]<<endl;
	}
	vector<int> v;
	map<int,int>::iterator itr;
	for(itr=m.begin();itr!=m.end();itr++){
		v.push_back((*itr).second);
//		cout<<(*itr).second;
	}
	int ans=0;
	sort(v.begin(),v.end(),greater<int>());
	for(int i=k;i<v.size();i++){
		ans+=v[i];
	}
	cout<<ans<<endl;


	return 0;
}

Measured memory_bytes: 11516
#include<bits/stdc++.h>
#define ll long long
#define all(a) a.begin(),a.end()
#define sz(a) a.size()
#define re return 
#define MP make_pair
#define pb push_back
#define pii pair<int,int>
#define se second
#define fi first
using namespace std;

signed main(){
	ios_base::sync_with_stdio(0);
	char x,y;
	cin>>x>>y;
	if(x<y) cout<<'<';
	else if(x>y) cout<<'>';
	else cout<<'='; 
	re 0;
}

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

#define PI 3.14159265358979323846264338327950L
#define ll long long
#define lli long long int

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s, t;
    ll answer = 0;
    cin >> s >> t;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] != t[i]) {
            answer++;
        }
    }
    cout << answer << "\n";

    return 0;
}


Measured memory_bytes: 3776
#include<iostream>

using namespace std;
typedef long long ll;

ll n,a[330][330]={0};
ll res=0;

signed main(){
    cin>>n;
    for(int i=0;i<n;++i){
        for(int j=0;j<n;++j)cin>>a[i][j];
    }

    bool f;
    for(int i=0;i<n-1;++i){
        for(int j=i+1;j<n;++j){
            f=true;
            for(int k=0;k<n;++k){
                if(k!=i&&k!=j){
                    if(a[i][j]>a[i][k]+a[k][j]){
                        cout<<-1<<endl;
                        return 0;
                    }
                    if(a[i][j]==a[i][k]+a[k][j])f=false;
                }
            }
            if(f)res+=a[i][j];
        }
    }

    cout<<res<<endl;

    return 0;
}

Measured memory_bytes: 1024
N,D = gets.chomp.split(' ').map(&:to_i)
datas = []
N.times do
  datas << gets.chomp.split(' ').map(&:to_i)
end
count = 0
datas.each do |data|
  a = data[0]
  b = data[1]
  count += 1 if a**2 + b ** 2 <= D**2
end
puts count

Measured memory_bytes: 28648
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var a = cin.ArrayLong(4);            
            Console.WriteLine(Math.Min(a[0],a[1]) + Math.Min(a[2], a[3]));
        }
    }

    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 int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            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 long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            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;
        }
    }

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main(){
int64_t N;
cin >> N ;
int64_t ans = 11;

for(int64_t i = 1; i*i<=N; i++){
  if(N %i == 0){
    int64_t B = N/i;
    int64_t loga = log10(i)+1; 
    int64_t logb = log10(B)+1;
     ans = min(ans,max(loga,logb));
  }

  }
  

cout << ans << endl;
}

Measured memory_bytes: 256
import math
from math import gcd,pi
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n,m = i_map()
    box = [1 for _ in range(n+1)]
    red = [0 for _ in range(n+1)]
    red[1] = 1

    for i in range(m):
        x,y = i_map()
        box[x] -= 1
        box[y] += 1
        if red[x] == 1:
            red[y] = 1
        if box[x] == 0:
            red[x] = 0

    print(sum(red))

if __name__=="__main__":
    main()


Measured memory_bytes: 10976
#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
#define rep(i,a,b) for(uint32 i = (a); i < (b); ++i)
#define bitget(a,b) (((a) >> (b)) & 1)
#define ALL(x) (x).begin(),(x).end()
#define C(x) std::cout << #x << " : " << x << std::endl
#define scanf scanf_s

using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;

#define MAX 100000

bool isp(uint32 n) {
	if (n == 1) return false;
	for (uint32 i = 2;i*i <= n;++i) {
		if (!(n%i)) return false;
	}
	return true;
}

int main(void) {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	uint32 q;
	std::cin >> q;
	uint32 l, r;
	uint32 num[MAX] = {};
	rep(i, 0, MAX) {
		if (!(i & 1)) continue;
		if (isp(i) && isp((i + 1) / 2)) {
			num[i] = 1;
		}
	}
	rep(i, 1, MAX) num[i] += num[i - 1];
	rep(i, 0, q) {
		std::cin >> l >> r;
		std::cout << num[r] - num[l - 1] << "\n";
	}
	return 0;
}

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

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    string s;
    cin >> s;
    int ans = 0;
    for (int b = 0, bound = pow(2, sz(s) - 1); b < bound; b++) {
        int mask = b;
        vector<bool> bits(sz(s) - 1);
        for (int i = 0; i < sz(bits); i++) {
            if(mask % 2) bits[i] = 1;
            else bits[i] = 0;
            mask >>= 1;
        }
        string buff = string(1, s[0]);
        for (int i = 0; i < sz(bits); i++) {
            if (bits[i]) {
                ans += stoll(buff);
                buff = string(1, s[i + 1]);
            } else {
                buff += string(1, s[i + 1]);
            }
        }
        ans += stoll(buff);
    }
    cout << ans << "\n";
}


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

int max(int a,int b){
  if(a>b) return a;
  else return b;
}
double min(double a,double b){
  if(a<b) return a;
  else return b;
}
int absolute(int a,int b){
  if(a-b<0) return -(a-b);
  else return a-b;
}
int main(void){
  int N; cin >> N;
  vector<string> w(N);
  
  for(int i=0;i<N;i++){
  	cin >> w.at(i);
  }
  
  bool flag = true;
  for(int i = 0 ; i<N-1 ; i++){
    if( w.at(i).at(w.at(i).size()-1) != w.at(i+1).at(0) ) flag = false;
    for(int j=i+1;j<N;j++){
      if(w.at(i) == w.at(j)) flag = false;
    }
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
S_dush = input()
T = input()

if len(S_dush) < len(T):
    print("UNRESTORABLE")
    exit()

S_dush_list = []
for i in range(len(S_dush)):
    S_dush_list.append(S_dush[i])

def judge():
    for i in range(len(S_dush)-len(T),-1,-1):
        T_index = 0
        for j in range(i,i+len(T)):
            if S_dush_list[j] != "?":
                if S_dush_list[j] != T[T_index]:
                    break
            T_index += 1
            if len(T) == T_index:
                return j
    return -1

index = judge()
if index == -1:
    print("UNRESTORABLE")
    exit()

for i in range(index-len(T)+1,index+1):
    S_dush_list[i] = T[i-index+len(T)-1]

for i in range(len(S_dush)):
    if S_dush_list[i] == "?":
        S_dush_list[i] = "a"

print(''.join(S_dush_list))

Measured memory_bytes: 3064
import java.io.*;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
   
class Main{
       
static final PrintWriter out=new PrintWriter(System.out);
static final int INF=Integer.MAX_VALUE;
   
public static class Edge{
int to;
int cost;
public Edge(int to){
this.to=to; cost=0;
}
public Edge(int to,int cost){
this.to=to; this.cost=cost;
}
}
   
public static class Pair{
int x;
int y;
public Pair(int x,int y){
this.x=x; this.y=y;
}
public static final Comparator<Pair> DISTANCE_ORDER=new Comp();
private static class Comp implements Comparator<Pair>{
public int compare(Pair p1,Pair p2){
return (p1.x>p2.x)?1:(p1.x<p2.x)?-1:0;
}
}
}
   
public static class MyArrayList extends ArrayList<Edge>{}
   
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
String line="";
while((line=br.readLine())!=null&&!line.isEmpty()){
st=new StringTokenizer(line);
int n=Integer.parseInt(st.nextToken());
int k=Integer.parseInt(st.nextToken());
int[] c=new int[n];
int[] r=new int[n];
int[] dist=new int[n];
boolean[][] visited=new boolean[n][n];
MyArrayList[] array=new MyArrayList[n];
MyArrayList[] carray=new MyArrayList[n];
for(int i=0;i<n;i++){
st=new StringTokenizer(br.readLine());
c[i]=Integer.parseInt(st.nextToken());
r[i]=Integer.parseInt(st.nextToken());
array[i]=new MyArrayList();
carray[i]=new MyArrayList();
}
for(int i=0;i<k;i++){
st=new StringTokenizer(br.readLine());
int a=Integer.parseInt(st.nextToken())-1;
int b=Integer.parseInt(st.nextToken())-1;
array[a].add(new Edge(b));
array[b].add(new Edge(a));
}
for(int i=0;i<n-1;i++){
bfs(i,r[i],visited,array);
for(int j=0;j<n;j++){
if(i!=j&&visited[i][j]) carray[i].add(new Edge(j,c[i]));
}
}
dijkstra(dist,carray);
out.println(dist[n-1]);
}
out.flush();
}
   
public static void bfs(int s,int t,boolean[][] visited,MyArrayList[] array){
Arrays.fill(visited[s],false);
Deque<Pair> que=new ArrayDeque<Pair>();
que.offerLast(new Pair(s,0));
while(!que.isEmpty()){
Pair p=que.pollFirst();
int ns=p.x;
visited[s][ns]=true;
ArrayList<Edge> list=array[ns];
if(p.y==t) continue;
for(int i=0;i<list.size();i++){
Edge e=list.get(i);
if(!visited[s][e.to]) que.offerLast(new Pair(e.to,p.y+1));
}
}
}
   
public static void dijkstra(int[] dist,MyArrayList[] array){
PriorityQueue<Pair> pque=new PriorityQueue<Pair>(1,Pair.DISTANCE_ORDER);
Arrays.fill(dist,INF);
dist[0]=0;
pque.offer(new Pair(0,0));
while(!pque.isEmpty()){
Pair p=pque.poll();
int v=p.y;
ArrayList<Edge> list=array[v];
if(dist[v]<p.x||list.size()==0) continue;
for(int i=0;i<list.size();i++){
Edge e=list.get(i);
if(dist[e.to]>dist[v]+e.cost){
dist[e.to]=dist[v]+e.cost;
pque.offer(new Pair(dist[e.to],e.to));
}
}
}
}
}

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

#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(x) cout << x << endl;

int main() {
    int x; cin >> x;

    int ans = 0;
    for(int i = x; i <= 1000000; i++){
        bool flag = true;
        for(int j = 2; j * j < i; j++){
            if(i % j == 0){
                flag = false;
                break;
            }
        }
        if(flag){
            ans = i;
            break;
        }
    }
    OP(ans);
}


Measured memory_bytes: 256
def resolve():
    import itertools
    A = [i for i in input().split()] + ["+"]
    maxA = 0
    for a in itertools.permutations(A):
        if a[0] != "+" and a[-1] != "+":
            maxA = max(maxA, eval("".join(a)))
    print(maxA)


resolve()


Measured memory_bytes: 8864
#include<bits/extc++.h>
#ifndef __unix__
#define readchar _getchar_nolock
#define fread_unlocked _fread_nolock
#else
#define readchar getchar_unlocked
#endif
#ifdef _debug 
#define dout(i) cout << #i << ' ' << i << ' '
#else 
#include<bits/stdc++.h>
#define dout(i) 0&&0
#endif
#pragma GCC optimize("unroll-loops,no-stack-protector,O3")
#define priority_queue __gnu_pbds::priority_queue
#define unordered_map __gnu_pbds::gp_hash_table
#define rep(_n) for(int __i = _n;__i--;)
#define rep0(_i, _n) for(int _i = 0; (_i)<(_n) ;++_i)
#define rep1(_i, _n) for(int _i = 1; (_i)<=(_n) ;++_i)
#define yn(i) ((i)?"Yes" : "No")
#define eout(i) {cout << (i) << '\n';exit(0);}
#define rout(i) {return cout << (i) << '\n', 0;}
#define multi int _T;for(read(_T);_T--;)
using namespace std;
using ll = long long;using ull = unsigned long long;using ul = unsigned;using db = double;
using __gnu_pbds::null_type;
// inline char readchar(){static const size_t bufsize = 1 << 16; static size_t p = 0, end = 0; static char buf[bufsize]; if (p == end) end = fread_unlocked(buf, sizeof(char), bufsize, stdin), p = 0; return p == end ? EOF : buf[p++]; }
inline void read(char &a){static char p; while(isspace(p = readchar())); a = p; }
inline void read(char *a){static char p; while(isspace(p = readchar())); *a = p, ++a; while(isgraph(p = readchar()))*a = p, ++a;}
inline void read(string &a){static char p; while(isspace(p = readchar())); a = p; while(isgraph(p = readchar()))a.push_back(p);}
template<typename T> inline void read(T& a){static char p; static bool b;while (!isdigit(p = readchar()))b = p == '-'; a = p ^ '0'; while (isdigit(p = readchar())) a *= 10, a += p ^ '0'; if(b)a *= -1; }
template<typename T1, typename T2> inline void read(pair<T1, T2> &a){read(a.first), read(a.second);}
template<typename T> inline void read(T begin, const T &end){while(begin != end)read(*begin), ++begin;}
inline void R(){} template<class T1, class... T2> inline void R(T1 &h, T2 &... e){read(h), R(e...);}
template<typename T> inline void write(T begin, const T &end){while(begin != end)cout << *begin << " \n"[next(begin) == end], ++begin;}
template<typename T> using rbtree = __gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T> inline ostream& operator << (ostream &ou, const vector<T> &a){for(auto it = a.begin();it != a.end();++it)ou << (it != a.begin() ? " " : "") << *it;return ou;}
template<typename T1, typename T2>inline istream& operator >> (istream &in, pair<T1, T2> &a){return in >> a.first >> a.second;}
template<typename T1, typename T2>inline ostream& operator << (ostream &ou, const pair<T1, T2> &b){return ou << b.first << ' ' << b.second;}
template<typename T> inline long long pow(long long v, long long t, const T &p){long long res = 1;for(;t;t >>= 1, v = v * v % p)if(t & 1)res = res * v % p;return res;}
const int maxn = 300010;
string w;
int n;
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> w;
	for(auto &i : w){
		i += n;
		if(i > 'Z')i -= 26;
	}	
	cout << w << '\n';
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<complex>
#include<stack>
#include<cmath>

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)

int main(){
	
	string s;
	while(cin>>s){
		char m[3][3];
		rep(i,9){
			m[i/3][i%3]=s[i];
		}
		
		char win = 'd';
		rep(i,3){
			if(m[i][0]==m[i][1]&&m[i][1]==m[i][2] && m[i][0]!='s')win=m[i][0];
			if(m[0][i]==m[1][i]&&m[1][i]==m[2][i] && m[0][i]!='s')win=m[0][i];
		}
		
		if(m[0][0]==m[1][1] && m[1][1]==m[2][2] && m[1][1]!='s')win=m[1][1];
		if(m[2][0]==m[1][1] && m[1][1]==m[0][2] && m[1][1]!='s')win=m[1][1];
		
		cout<<win<<endl;
	}
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
 
using namespace std;
 
int a[100005],n;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",a+i);
int ans=0;
for(int i=1;i<=n;i++) if (a[i]>i&&a[a[i]]==i) ans++;
cout<<ans<<'\n';
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ui unsigned int
#define ull unsigned ll
#define pii pair<int,int>
#define pll pair<ll,ll>
#define db double
#define mp make_pair
#define X first
#define Y second
#define FR first
#define vi vector<int>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,b,a) for(int i=(b);i>=(a);--i)
#define rep0(i,a,b) for(int i=(a);i<(b);++i)
#define fore(i,a) for(int i=0;i<(a).size();++i)
#define ls x<<1,l,m
#define rs x<<1|1,m+1,r
#define gc getchar
inline ll rd()
{
	ll x=0,w=1;char c=gc();while(!isdigit(c)&&c!='-')c=gc();
	if(c=='-')c=gc(),w=-1;while(isdigit(c))x=x*10+c-48,c=gc();return x*w;
}
const ll inf=1ll<<60;
int S,T,tt,cc;
namespace F
{
	const int N=1e3+7;
	struct E{int to,rev;ll cap,w;};
	typedef vector<E>::iterator iter;
	vector<E> G[N];iter cur[N];
	inline void add(int u,int v,ll cap,ll cost)
	{
		G[u].push_back((E){v,(int)G[v].size(),cap,cost});
		G[v].push_back((E){u,(int)G[u].size()-1,0,-cost});
	}
	ll dis[N];bool vs[N];
	bool spfa(){
		memset(dis,0x3f,sizeof dis);
		memset(vs,0,sizeof vs);
		deque<int> q;q.push_back(S);dis[S]=0;
		while(!q.empty()){
			int u=q.front();q.pop_front();
			vs[u]=false;cur[u]=G[u].begin();
			fore(i,G[u])
			{
//				for(E &e:G[u])
				E&e=G[u][i];
				if(e.cap&&dis[e.to]>dis[u]+e.w)
				{
					dis[e.to]=dis[u]+e.w;
					if(!vs[e.to]){
						if(!q.empty()&&dis[e.to]<dis[q.front()])
							q.push_front(e.to);
						else q.push_back(e.to);
						vs[e.to]=true;
					}
				}
			}
		}return dis[T]<inf;
	}
	ll sf;
	ll dfs(int u,ll f){
		if(u==T){sf+=f;return f;}
		ll ans=0;vs[u]=true;
		for(iter &e=cur[u];e!=G[u].end();++e)
			if(e->cap&&dis[e->to]==dis[u]+e->w&&!vs[e->to]){
			ll dlt=dfs(e->to,min(f-ans,e->cap));
			e->cap-=dlt;G[e->to][e->rev].cap+=dlt;
			vs[e->to]=dlt==0;if((ans+=dlt)==f)break;
		}vs[u]=false;return ans;
	}

	void flw(vector<pll>&p)
	{
		while(spfa())
		{
			sf=0;dfs(S,inf);
//			cout<<dis[T]<<" "<<sf<<endl;
			p.push_back({dis[T],sf});
			if(sf>(1ll<<50))break;
		}
	}

}
const int N=35;
int n,m,o[N][N],c[N];
struct st{int s,p;ll c;}a[N][N];
inline bool cmp(st a,st b){return a.s<b.s;}
int main()
{
	n=rd();
	rep(i,1,n)
	{
		c[i]=rd();rep(j,1,c[i])a[i][j]=(st){rd(),rd(),rd()};
		sort(a[i]+1,a[i]+c[i]+1,cmp);
	}
	S=1;T=2;tt=2;cc=1;
	rep(i,1,n)
	{
		o[i][0]=S;o[i][c[i]]=T;
		rep0(j,1,c[i])o[i][j]=++tt;
		rep(j,1,c[i])
		{
			F::add(o[i][j-1],o[i][j],a[i][j].p,0);
			//	F::add(o[i][j],o[i][j-1],inf,0);
			F::add(o[i][j-1],o[i][j],inf,a[i][j].c);
		}
	}
	m=rd();
	while(m--)
	{
		int u=rd(),v=rd(),w=rd();
		for(int j=1,k=1;j<=c[v];j++)
		{
			while(k<=c[u]&&a[u][k].s+w<a[v][j].s)k++;
			F::add(o[v][j-1],o[u][k-1],inf,0);
		}
	}
	vector<pll>p;p.clear();F::flw(p);m=rd();
	vector<pll>q;q.clear();ll x=0,y=0;
	fore(i,p){q.pb(mp(x,y));x+=p[i].Y;y+=p[i].X*p[i].Y;}
	while(m--)
	{
		ll A=rd();int x=lb(p.begin(),p.end(),mp(A,-inf))-p.begin();
		if(x==p.size())puts("-1");else printf("%lld\n",q[x].X*A-q[x].Y);
	}
	return 0;
}


Measured memory_bytes: 4044
import java.util.Scanner;

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

		int sum = a + b;
		int sub = a - b;
		int mul = a * b;

		if (sum < sub) {
			if (sub < mul) {
				System.out.println(mul);
			} else {
				System.out.println(sub);
			}
		} else {
			if (sum < mul) {
				System.out.println(mul);
			} else {
				System.out.println(sum);
			}
		}
	}
}


Measured memory_bytes: 21972
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[][] A = new int[2][N];
        for (int i = 0; i < 2; ++i) {
            for (int j = 0; j < N; ++j) {
                A[i][j] = sc.nextInt();
            }
        }

        System.out.println(solve(A));

        sc.close();
    }

    static int solve(int[][] A) {
        return IntStream.range(0, A[0].length).map(i -> IntStream.rangeClosed(0, i).map(j -> A[0][j]).sum()
                + IntStream.range(i, A[0].length).map(j -> A[1][j]).sum()).max().getAsInt();
    }
}

Measured memory_bytes: 28756
def xgcd(a, b):
  x0, y0, x1, y1 = 1, 0, 0, 1
  while b != 0:
    q, a, b = a // b, b, a % b
    x0, x1 = x1, x0 - q * x1
    y0, y1 = y1, y0 - q * y1
  return a, x0, y0
def modinv(a, m):
  g, x, y = xgcd(a, m)
  if g != 1:
    raise Exception('modular inverse does not exist')
  else:
    return x % m
def combination(n, k, mod=1e9+7) -> int:
  ret = 1
  for i in range(1, k+1):
    ret = (ret * (n-k+i) * modinv(i, mod))%mod
  return int(ret)

N,M = list(map(int,input().split()))

Na = combination(N,2) if N >=2 else 0
Ma = combination(M,2) if M >=2 else 0

print(Na+Ma)

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

typedef long long ll;

const ll MOD = 1e9 + 7;
ll N, K;
ll M;
vector<ll> Mult;
vector<vector<ll>> Dp;

void init() {
  set<ll> s_values;
  for (ll i = 1; i * i <= N; ++i) {
    s_values.insert(i);
    s_values.insert(N / i);
  }
  vector<ll> values;
  for (ll v : s_values) values.push_back(v);
  M = values.size();
  Mult.resize(M);
  for (ll i = 0; i < M; ++i) Mult[i] = values[i] - (i == 0 ? 0 : values[i - 1]);
}
int main() {
  cin >> N >> K;
  init();
  Dp.resize(K + 1);
  for (auto &dp : Dp) dp.resize(M);
  fill(Dp[0].begin(), Dp[0].end(), 1);
  for (ll k = 0; k < K; ++k) {
    for (ll i = 0; i < M; ++i) {
      Dp[k + 1][i] = Mult[i] * Dp[k][M - 1 - i] % MOD;
      if (i > 0) (Dp[k + 1][i] += Dp[k + 1][i - 1]) %= MOD;
    }
  }
  cout << Dp[K][M - 1] << endl;
  return 0;
}


Measured memory_bytes: 50700
n,m=map(int,input().split())

X=[[] for _ in range(n)]

for i in range(m):
    a,b=map(int,input().split())
    X[a-1].append(b-1)
    X[b-1].append(a-1)


path=[i for i in range(2,n+1)]

visited=[1]+[0]*(n-1)

def dfs(v):
    if visited==[1]*n:
        return 1
    res=0
    for x in X[v]:
        if visited[x]==0:
            visited[x]=1
            res+=dfs(x)
            visited[x]=0
    return res

print(dfs(0))

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

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

    for(int is=0;is<s.size();is++) {
        if(s.at(is)!=t.at(is)) { 
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<numeric>

using namespace std;

#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define INF 11111111111111111
#define MOD 1000000007
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef pair<ll, ll> pll;

ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, temp = 0;
string s;
bool flag;

//-------------------------------------------------------------------------------

#define MAX 10000

ll gcd(ll x, ll y) {
  if (x < y) swap(x, y);
  return y ? gcd(y, x%y) : x;
}


int main(void) {
  cin >> n >> m;
  vll a;
  ll g = 0;
  ll mx = -1;

  FOR(i, 0, n) {
	cin >> temp;
	a.push_back(temp);
	g = gcd(g, temp);
	mx = max(mx, temp);
  }

  if (m <= mx && m%g == 0) {
	cout << "POSSIBLE" << endl;
  }
  else {
	cout << "IMPOSSIBLE" << endl;
  }

  return 0;
}

Measured memory_bytes: 1400
#include <stdio.h> 
int main(void){    
int a;    
int b;    
int z;    
int min;    
int max;    
long int sum;    
min = 1000000;    
max = -1000000;     
sum = 0;     
scanf("%d",&a);     
for(b=0; b<a; b++)    {        
scanf("%d",&z);                 
if(min > z)        {            
min = z;        }        
if(max < z)        {            
max =z;        }        
sum = sum + z;    }         
printf("%d %d %ld\n",min,max,sum);     
return 0;
}

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

int main(){
  string s;
  cin >> s;
  
  if(s[5] == s[4] && s[3] == s[2])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;


}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n;
  i64 k;
  cin >> n >> k;
  vi32 a(n);
  cin >> a;
  sort(all(a));
  auto f = [&](i64 x) {
    i64 ret = 0;
    rep(i, n) {
      auto g = [&](int y) {
        return (i64) y * a[i] <= x;
      };
      if (a[i] < 0) {
        ret += partition_point(a.rbegin(), a.rend() - i - 1, g) - a.rbegin();
      } else if (a[i] > 0) {
        ret += partition_point(a.begin() + i + 1, a.end(), g) - (a.begin() + i + 1);
      } else {
        if (x >= 0) ret += n - (i + 1);
      }
    }
    return ret;
  };
  i64 ok = 2e18, ng = -2e18;
  while (abs(ok - ng) > 1) {
    i64 md = (ok + ng) / 2;
    (f(md) >= k ? ok : ng) = md;
  }
  cout << ok << endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
 
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int a = sc.nextInt();
			
			int tmp = 0;
			int before = -1;
			int cnt = 0;
			for (int i = 0; i < 4; i++) {
				before = tmp;
				tmp = a % 10;
				a /= 10;
				if (before == tmp) {
					cnt++;
					if (cnt >= 2) {
						System.out.println("Yes");
						return;
					}
				}
				else cnt = 0;
			}
 
			if (cnt >= 2) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}
	}
}

Measured memory_bytes: 21844
#include "bits/stdc++.h"
using namespace std;
int main(){
    double a,b,c,d,r;
    cin >> a >> b >> c >> d;
    r = (a-c)*(a-c)+(b-d)*(b-d);
    printf("%.4lf\n",sqrt(r));
    return 0;
}


Measured memory_bytes: 3212
#include <iostream>
#include <sstream>
#include <string>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

template <typename T>
class Dijkstra {
    struct edge { int to; T cost; };
    typedef pair<T, int> P; // <最短距離, 頂点番号>

private:
    int m_V;
    vector<vector<edge> > m_G;
public:
    T INF;
    vector<int> m_prev_path; // 最短パスを辿るため

    Dijkstra(int V)
        : INF(std::numeric_limits<T>::max())
        , m_V(V)
    {
        m_G.resize(m_V);
    }

    // a -> bに片方向のエッジを張る
    void add_dir_edge(int a, int b, T cost) {
        m_G[a].push_back( edge{ b, cost } );
    }

    // a <-> bに両方向のエッジを張る
    void add_undir_edge(int a, int b, T cost) {
        add_dir_edge(a, b, cost);
        add_dir_edge(b, a, cost);
    }

    // 頂点sから各頂点までの距離を計算して返す
    vector<T> shortest_path(int s) {
        m_prev_path.clear(); m_prev_path.resize(m_V, -1);

        vector<T> d(m_V, INF);
        priority_queue<P, vector<P>, greater<P> > que;
        d[s] = 0;
        que.push(P(0, s));

        while(!que.empty()) {
            P p = que.top();
            que.pop();

            auto dist = p.first;
            auto v = p.second;
            if (d[v] < dist) continue;
            REP(i, m_G[v].size()) {
                edge e = m_G[v][i];
                if (d[e.to] > d[v] + e.cost) {
                    d[e.to] = d[v] + e.cost;
                    que.push(P(d[e.to], e.to));
                    m_prev_path[e.to] = v;
                }
            }
        }

        return d;
    }

    // shortest_path()が呼ばれた後に呼ばれることを期待する
    // s -> v1 -> v2 -> v3 -> t の場合、{s, v1, v2, v3, t} からなるvectorを返す
    vector<int> get_path(int t)
    {
        vector<int> path;
        for(; t != -1; t = m_prev_path[t]) path.push_back(t);
        reverse(ALL(path));
        return path;
    }

};

int main(void)
{
    cin.sync_with_stdio(false);
    int H, W;
    cin >> H >> W;

    Dijkstra<int> dij(10);
    REP(h, 10) {
        REP(w, 10) {
            int cost;
            cin >> cost;
            dij.add_dir_edge(h, w, cost);
        }
    }

    vector<int> costs(10);
    REP(i, 10) {
        costs[i] = dij.shortest_path(i)[1];
    }

    int ans = 0;
    REP(h, H) {
        REP(w, W) {
            int a;
            cin >> a;
            if (a != -1) {
                ans += costs[a];
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import numpy as np
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))

A.sort()
F.sort(reverse = True)
sa = sum(A) 
A = np.array(A)
F = np.array(F)

l = -1 
r = A[N-1] * F[0]
while l+1 < r: 
    m = (l + r) //2
    S = sa - np.sum(np.minimum(m // F, A)) 
    if S <= K:
        r = m
    else:
        l = m
         
print(r)

Measured memory_bytes: 43524
a = gets().split("")
b = gets().split("")

check = Array.new(3,0)

for i in 0..2
	if a[i] == b[2-i]
		check[i] = 1
	else
		check[i] = -1
	end
end

if check[0]==1 && check[1] == 1 && check[2] == 1
	puts("YES")
else
	puts("NO")
end

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

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

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  int N; cin >> N;
  ll A[N]; rep(i,N) cin >> A[i];
  set<ll> count; rep(i,N) count.insert(A[i]);
  string result = count.size()==N ? "YES" : "NO";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 11136
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <list>
#define long long long
#define LF '\n'
using namespace std;

list<int> ls[1005];

void dump(const list<int> &ls)
{
  for (auto itr = ls.cbegin(); itr != ls.cend(); ++itr) {
    if(itr != ls.cbegin()) cout << ' ';
    cout << *itr;
  }
  cout << LF;
}

signed main()
{
  cin.tie(nullptr), ios::sync_with_stdio(false);

  int n, q;
  cin >> n >> q;

  while(q--) {
    int com, t, x;
    cin >> com;

    if (com == 0) {
      cin >> t >> x;
      ls[t].emplace_back(x);
    }
    else if (com == 1) {
      cin >> t;
      dump(ls[t]);
    }
    else {
      cin >> x >> t;
      ls[t].splice(ls[t].end(), move(ls[x]));
    }
  }

  return 0;
}




Measured memory_bytes: 18728
#include<iostream>
#include<map>
#include<cstring>
using namespace std;

int main(){
  int n;
  string s;
  int C[1000000];
  map<string, int> S;
  int max = 0;

  cin >> n;
  for (int i = 0; i < n; i++){
    cin >> s;
    S[string(s)] += 1;
  }

  for (map<string, int>::iterator it = S.begin(); it != S.end(); it++){
    pair<string, int> data = *it;
    if (data.second > max){
      max = data.second;
    }
  }

  for (map<string, int>::iterator it = S.begin(); it != S.end(); it++){
    pair<string, int> data = *it;
    if (max == data.second){
      cout << data.first << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 25216
import java.util.*;


public class Main {
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			String s = sc.next();
			int n = s.length();
			char [] data = s.toCharArray();
			String t = s.replaceAll("x", "");
			char [] data2 = t.toCharArray();
			
			StringBuilder tt = new StringBuilder(t);
			if(! tt.reverse().toString().equals(t)){
				System.out.println(-1);
				continue;
			}
			int [] calc = new int[t.length() + 1];
			
			for(int i = 0, j = 0; i < n; i++){
				if(j == t.length()){
					calc[t.length()]++;
					continue;
				}
				if(data[i] == data2[j]){
					j++;
				}
				else{
					calc[j]++;
				}
			}
			
			int count = 0;
			for(int i = 0; i <= t.length() / 2; i++){
				int ind = t.length()-i;
				count += Math.abs(calc[i]-calc[ind]);
			}
			System.out.println(count);
			
			
		}
	}



	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

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

}


Measured memory_bytes: 36332
h,w = map(int,input().split())
C = [list(map(int,input().split())) for i in range(10)]
A = [list(map(int,input().split())) for i in range(h)]
INF = float('inf')
cost = 0
for k in range(10):
    for i in range(10):
        for j in range(10):
            C[i][j] = min(C[i][j],C[i][k]+C[k][j])

for y in range(h):
    for x in range(w):
        if A[y][x] != -1:
            cost += C[A[y][x]][1]
print(cost)


Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define f(i, a, b) for(int i=a; i<b; i++)
#define fr(i, a, b) for(int i=a; i>=b; i--)
#define l long int
using namespace std;

int main()
{
   FAST
   string s;
   cin>>s;
   int cnt=0;
 
 if(s[0]==s[1] && s[0]=='R' && s[2]==s[1])
 {
 	cnt=3;
 }
 else
 if((s[0]==s[1] && s[0]=='R') ||(s[1]==s[2] && s[1]=='R') )
 {
cnt=2;
 }
 else
 if(s[1]=='R' || s[0]=='R' || s[2]=='R')
 cnt=1;
 
 cout<<cnt;
}


Measured memory_bytes: 3576
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <bitset>

using namespace std;
typedef long long ll;

int N;
ll table[300000][60];

int main() {
	int H, W; cin >> H >> W;
	
	int** A = new int*[H];
	bitset<6400>** dp = new bitset<6400>* [H];

	for (int i = 0; i < H; i++) {
		A[i] = new int[W];
		dp[i] = new bitset<6400> [W];
		for (int j = 0; j < W; j++) {
			cin >> A[i][j];
		}
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			int b; cin >> b;
			A[i][j] -= b;
			A[i][j] = abs(A[i][j]);
		}
	}

	dp[0][0][A[0][0]] = true;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (i > 0) {
				dp[i][j] |= (dp[i - 1][j] >> A[i][j]) | (dp[i - 1][j] << A[i][j]);
				for (int k = 0; k < A[i][j]; k++) {
					dp[i][j][abs(A[i][j] - k)] = dp[i][j][abs(A[i][j] - k)] | dp[i - 1][j][k];
				}
			}
			if (j > 0) {
				dp[i][j] |= (dp[i][j - 1] >> A[i][j]) | (dp[i][j - 1] << A[i][j]);
				for (int k = 0; k < A[i][j]; k++) {
					dp[i][j][abs(A[i][j] - k)] = dp[i][j][abs(A[i][j] - k)] | dp[i][j - 1][k];
				}
			}
		}
	}

	for (int i = 0; i < 6400; i++) {
		if (dp[H - 1][W - 1][i] == true) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 5248
package main

import "fmt"

func main() {
	var S string
	ans := "Yes"
	fmt.Scanf("%s", &S)
	for i, s := range S {
		if (i+1)%2 == 1 && s == 'L' {
			ans = "No"
			break
		}
		if (i+1)%2 == 0 && s == 'R' {
			ans = "No"
			break
		}
	}

	fmt.Println(ans)
}

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

int main(){
  int N, M; cin >> N >> M;
  vector<int> A(N);
  int sum=0;
  for(int i=0;i<N;i++){
    cin >> A[i];
    sum+=A[i];
  }
  int count=0;
  for(int i=0;i<N;i++){
    if(sum<=4*M*A[i]){
      count++;
    }
  }
  if(count>=M){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
import sys

n=int(input())
wli=[]
w=input()
wli.append(w)

for i in range(n-1):
    w=input()
    if w in wli:
        print("No")
        sys.exit()
    elif wli[i][-1:]!=w[0]:
        print("No")
        sys.exit()
    else:
        wli.append(w)

print("Yes")
        


Measured memory_bytes: 3060
import numpy as np

N = int(input())
A = np.fromiter(map(int, input().split()), np.int64)

result = 0
for bit in range(60):
  c = int((A & 1).sum())
  A >>= 1
  result = (result + c * (N - c) * (1 << bit)) % 1000000007
print(result)


Measured memory_bytes: 44560
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
	int h, w;
	cin >> h >> w;
	bool answer = false;
	bool answer2 = true;
	string board[50];

	for(int i = 0; i < h; i++) cin >> board[i];

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

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			answer = false;
			if (board[i][j] == '.') continue;

			int num = 0;
			for (int d = 0; d < 4; d++) {
				const int ni = i + dy[d];
				const int nj = j + dx[d];

				if (ni < 0 or h <= ni) continue;
				if (nj < 0 or w <= nj) continue;
				if (board[ni][nj] == '#') answer = true;
			}
			if(answer==false){
				answer2 = false;
			}
		}
	}

	if(answer2==true){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256