akhauriyash/Code-Regression huggingface dataset:
s = input()
q =int(input())  #数値入力 「N」だけの入力のとき

count=0
add_s=[]
add_e=[]
for i in range(q):
    qi= input()
    if qi=='1':
        add_s,add_e=add_e,add_s
        count+=1
    else:
        _t,f,c=qi.split()
        if f =='1':
            add_s.append(c)
        else:
            add_e.append(c)

if count%2==0:
    print(''.join(reversed(add_s))+s+''.join(add_e))
else:
    print(''.join(reversed(add_s))+''.join(reversed(list(s)))+''.join(add_e)) 

Measured memory_bytes: 6272
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
using ll = long long int;
const int MAX = 1001;
int dp[MAX][MAX];
string a[MAX];
int main() {
	int n,m,i,j;
	cin>>n>>m;
	for(i=0;i<n;++i)
		cin>>a[i];

	for(i=0;i<n;++i) {
		for(j=0;j<m;++j) {
			if(i == 0 and j == 0) {
				dp[i][j] = 1;
				continue;
			}
			if(a[i][j] == '#') continue;
			if(i-1 >= 0) dp[i][j] = (dp[i][j] + dp[i-1][j])%MOD;
			if(j-1 >= 0) dp[i][j] = (dp[i][j] + dp[i][j-1])%MOD;
		}
	}
	cout<<dp[n-1][m-1]<<endl;
	return 0;
}

Measured memory_bytes: 5248
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

bool compare_by_A(pair<ll, ll> a, pair<ll, ll> b){
    return a.first < b.first;
}

int main(void){
    ll n, buy; cin >> n >> buy;
    vector<pair<ll, ll> > pairs(n);
    REP(i, n) {
        ll a, b;
        cin >> a >> b;
        pairs[i] = make_pair(a, b);
    }
    whole(sort, pairs, compare_by_A);
    
    ll i = 0, ans = 0;
    while(buy > 0){
        if(pairs[i].second <= buy){
            ans += pairs[i].first * pairs[i].second;
            buy -= pairs[i].second;
        }
        else if(pairs[i].second > buy){
            ans += pairs[i].first * buy;
            buy = 0;
        }
        i++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ll x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class T>bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

vll dp(100010, 0);

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin >> n;
    vll h(n);
    rep(i, n){
        cin >> h[i];
    }
    dp[1] = abs(h[1]-h[0]);
    repr(i, 2, n){
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll=long long;
using vec=vector<ll>;
using vect=vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n;i>=0;i--)
#define Pool(i, m, n) for(ll i=n;i>=m;i--)
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout<<a<<endl
#define putout2(a,b) putout(a);putout(b)
#define putout3(a,b,c) putout(a);putout(b);putout(c)
#define putout4(a,b,c,d) putout(a);putout(b);putout(c);putout(d)
#define putout5(a,b,c,d,e) putout(a);putout(b);putout(c);putout(d);putout(e)
#define Gput(a,b) G[a].push_back(b)
#define cin1(a) cin>>a
#define cin2(a,b) cin>>a>>b
#define cin3(a,b,c) cin>>a>>b>>c
#define cin4(a,b,c,d) cin>>a>>b>>c>>d
#define cin5(a,b,c,d,e) cin>>a>>b>>c>>d>>e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x,y) __gcd(x,y)
#define erase(s) s.erase(s.end()-1) //文字列sの末尾削除
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll lcm(ll x,ll y){
  ll z=gcd(x,y);
  return x*y/z;
}
ll primejudge(ll n){
  if(n<2)return 0;
  else if(n==2)return 1;
  else if(n%2==0)return 0;
  double sqrtn=sqrt(n);
  Loop(i,3,sqrtn+1){
     if(n%i==0){
        return 0;
     }
     i++;
  }
  return 1;
}
string RLE(string s){
  ll n=s.size();
  char now='.';
  ll count=1;
  string press;
  loop(i,n){
    if(s[i]!=now){
      if(i){
        press+=now;
        press+=to_string(count);
      }
      now=s[i];
      count=1;
      continue;
    }
    else count++;
  }
  press+=now;
  press+=to_string(count);
  return press;
}
int main() {
  cout << fixed << setprecision(30);
  ll n;
  cin>>n;
  vec x(n);
  loop(i,n)cin>>x[i];
  ll preans=0;
  ll ans=1e9;
  Loop(i,1,101){
    preans=0;
    loop(j,n){
      preans+=pow(x[j]-i,2);
    }
    ans=min(ans,preans);
  }
  putout(ans);
}

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

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

    long long x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<long long> A(a), B(b), C(c);
    for(long long i = 0; i < a; i++){
        cin >> A[i];
    }
    for(long long i = 0; i < b; i++){
        cin >> B[i];
    }
    for(long long i = 0; i < c; i++){
        cin >> C[i];
    }

    sort(A.rbegin(), A.rend());
    sort(B.rbegin(), B.rend());
    sort(C.rbegin(), C.rend());

    vector<long long> CA(c + 1);
    for(long long i = 0; i < c; i++){
        CA[i + 1] += CA[i] + C[i];
    }

    vector<long long> AB;
    for(long long i = 0; i < x; i++){
        AB.push_back(A[i]);
    }
    for(long long i = 0; i < y; i++){
        AB.push_back(B[i]);
    }

    sort(AB.begin(), AB.end());
    
    vector<long long> ABA(AB.size() + 1);
    for(long long i = 0; i < AB.size(); i++){
        ABA[i + 1] += ABA[i] + AB[i];
    }

    long long ss = ABA.size();

    long long ans = 0;
    for(long long i = 0; i <= min(x + y, c); i++){
        long long cn = CA[i] - CA[0];
        long long tmp = (i <= ss - 1 ? ABA[ss - 1] - ABA[i] : ABA[ss - 1]);
        ans = max(ans, cn + tmp);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6384
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }

void main()
{
	auto N = RD;
	auto K = RD;
	auto S = RD;

	auto ans = new long[](N);
	foreach (i; 0..K)
	{
		ans[i] = S;
	}
	foreach (i; K..N)
	{
		ans[i] = S == 10^^9 ? 1 : S+1;
	}

	ans.map!(to!string).join(" ").writeln;
	stdout.flush;
	debug readln;
}


Measured memory_bytes: 6012
#include<stdio.h>
int main(void){
    int a,b;
    scanf("%d %d",&a,&b);
    if (a<b)
    printf("a < b\n");
    //printf("%d<%d",a,b);
    else if (a>b)
    printf("a > b\n");
    //printf("%d>%d",a,b);
    else
    printf("a == b\n");
    //printf("%d==%d",a,b);
    return 0;
}

Measured memory_bytes: 580
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr
  
def divisorize(n):
    ## 約数
    f = factorization(n)
    divisors = [1]
    for k in range(len(f)):
        num_divisors = len(divisors)
        for i in range(1, f[k][1] + 1):
            for j in range(num_divisors):
                divisors.append(divisors[j] * f[k][0] ** i)
    return sorted(divisors)
  
n = int(input())
ans = 0
chk = divisorize(n-1)
for i in divisorize(n)[1:]:
  m = n
  while True:
    if m == 1:
        ans += 1
        chk.append(i)
        break
    if m < i:
      break
    if m%i == 0:
      m = m//i
    else:
      m = m%i

chk = set(chk)
print(len(chk)-1)

Measured memory_bytes: 3316
def readinput():
    s,w=map(int,input().split())
    return s,w

def main(s,w):
    if w>=s:
        return 'unsafe'
    else:
        return 'safe'

if __name__=='__main__':
    s,w=readinput()
    ans=main(s,w)
    print(ans)


Measured memory_bytes: 9048
#include <iostream>
#include <vector>
#include <list>
#include <math.h>
#include <algorithm>
#include <functional>
#include <string>
#include <iomanip>
#include <queue>
#include <map>

int main()
{
	int N;
	std::cin >> N;

	std::vector<int> d;
	for (int i = 0; i < N; i++) {
		int tmp;
		std::cin >> tmp;
		d.emplace_back(tmp);
	}

	std::sort(d.begin(), d.end());//昇順ソート
	
/*	for (int i = 0; i < N; i++) {
		std::cout << d[i] << std::endl;
	}
*/
	int middle = N / 2 - 1;//0オリジンなので
	int middle_plus_1 = middle + 1;

//	std::cout << d[middle_plus_1] << " " << d[middle] << std::endl;
//	std::cout << d[middle_plus_1] << " " << d[middle] << std::endl;

	if (d[middle] == d[middle_plus_1]) {
		std::cout << 0;
		return 0;
	}
	else {
		int ans = d[middle_plus_1] - d[middle];
		std::cout << ans;
		return 0;
	}
}

Measured memory_bytes: 892
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        var o = Console.ReadLine();
        var e = Console.ReadLine();
        while(o.Any())
        {
            Console.Write(o.First());
            o = o.Substring(1);
            if (e.Any())
            {
                Console.Write(e.First());
                e = e.Substring(1);
            }
        }
        Console.WriteLine();
    }
}


Measured memory_bytes: 13268
#include<iostream>
#include<string>
#include<cstring>
#include<queue>
#include<algorithm>
#include<cmath>
#include<list>
using namespace std;

int main()
{
	string s;
	int sum = 0;
	cin >> s;
	int len = s.length();
	for (int i = 0; i < len; i++)
	{
		sum += s[i] - 48;
	}
	int a;
	a= std::stoi(s);
	if (a%sum == 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		int r=scan.nextInt();
		int c=scan.nextInt();
		int[][] matrix=new int[r+1][c+1];
		for(int i=0;i<r;i++){
			for(int j=0;j<c;j++){
				matrix[i][j]=scan.nextInt();
				matrix[i][c]+=matrix[i][j];
			}
		}
		for(int i=0;i<=c;i++){
			for(int j=0;j<r;j++){
				matrix[r][i]+=matrix[j][i];
			}
		}
		for(int i=0;i<=r;i++){
			System.out.print(matrix[i][0]);
			for(int j=1;j<=c;j++){
				System.out.print(" "+matrix[i][j]);
			}
			System.out.println();
		}
		scan.close();
	}
}

Measured memory_bytes: 39480
#include<bits/stdc++.h>
using namespace std;
int n,c;
int color[30][30];
int grid[500][500];
vector<int> v[3];
int ans[3][30]={0};
int res=INT_MAX;
int main()
{
	cin>>n>>c;
	for(int i=0;i<c;i++)
	{
		for(int j=0;j<c;j++)
		  cin>>color[i][j];
   }
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			cin>>grid[i][j];
			v[(i+1+j+1)%3].push_back(grid[i][j]-1);
		}
    }
    if(n==1)
    {
      cout<<0;
      return 0;
    }
      for(int i=0;i<c;i++)
        {
        	for(int m=0;m<v[0].size();m++)
        	{
        		ans[0][i]+=color[v[0][m]][i];
			}
		}
      for(int j=0;j<c;j++)
        {
        	for(int m=0;m<v[1].size();m++)
        	{
        		ans[1][j]+=color[v[1][m]][j];
			}
		}
      for(int k=0;k<c;k++)
        {
        	for(int m=0;m<v[2].size();m++)
        	{
        		ans[2][k]+=color[v[2][m]][k];
			}
	    }
	int cnt;
    for(int i=0;i<c;i++)
      for(int j=0;j<c;j++)
        for(int k=0;k<c;k++)
        {
        	if(i==j || i==k || j==k)
        	  continue;
        	cnt+=ans[0][i];
        	cnt+=ans[1][j];
        	cnt+=ans[2][k];
			res=min(res,cnt);
			cnt=0;
		}
	cout<<res;
	return 0;
}

Measured memory_bytes: 2416
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define takeline cin.ignore();
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l,n,v;
	cin>>n>>v;
	ll ar[n+1],sm[n+1];
	map<ll,ll> mp; sm[0]=0;
	for(i=1;i<=n;i++){
		cin>>ar[i];
		sm[i]=ar[i]+sm[i-1];
	//	cout<<i<<" "<<((ar[i]-i+v)%v)<<endl;
	}
	for(i=1;i<=n;i++){
		sm[i]=(sm[i]-i+v)%v;
	}
			
	ll an=0;
	mp[0]++;
	for(i=1;i<=n;i++){
		if(i>=v) mp[sm[i-v]]--;
		an+=mp[sm[i]];
		mp[sm[i]]++;
	}
	cout<<an;
	return 0;
}

Measured memory_bytes: 15872
import itertools

N = int(input())
p_list = list(input().split())
q_list = list(input().split())

a = 0
b = 0

p_str = "".join(p_list)
q_str = "".join(q_list)
cnt = 0

for n_list in itertools.permutations(range(1, N+1)) :
    n_str = "".join(map(str, n_list))
    if n_str == p_str :
        a = cnt
    if n_str == q_str :
        b = cnt
    cnt += 1

print(abs(a-b))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main() {FIN
    
    int a, b, r;
    char op;
    while (cin >> a >> op >> b, op != '?') {
        if (op == '+') r = a + b;
        else if (op == '-') r = a - b;
        else if (op == '*') r = a * b;
        else r = a / b;
        cout << r << "\n";
    }
    return 0;
}


Measured memory_bytes: 3172
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use nalgebra::max;

#[fastout]
fn main() {
    input! {
    n: usize,
    xy:[(i64, i64); n]
    }
    let rxy = (0..n).map(|i| (xy[i].0 - xy[i].1, xy[i].0 + xy[i].1)).collect::<Vec<_>>();
    let t1 = rxy.iter().max_by_key(|v| v.0).unwrap().0 - rxy.iter().min_by_key(|v| v.0).unwrap().0;
    let t2 = rxy.iter().max_by_key(|v| v.1).unwrap().1 - rxy.iter().min_by_key(|v| v.1).unwrap().1;
    let ans = max(t1, t2);
    println!("{}", ans);
}


Measured memory_bytes: 12096
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

int gcd(int m, int n) {
  while(n != 0) {
    int	r = m %	n;
    m =	n;
    n =	r;
  }
  return m;
}

int main() {
  int N, X; cin>>N>>X;
  vector<int> x(N+1), d(N);
  REP(i,N) {
    cin>>x[i];
  }
  x[N] = X;
  sort(x.begin(), x.end());
  REP(i,N) d[i] = x[i+1] - x[0];
  int ans = d[0];
  REP(i,d.size()) {
    ans	= gcd(ans, d[i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
// ConsoleApplication3.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int N;
    cin >> N;
    
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }

    int count = 0;
    while (true) {
        bool isAllEven = true;
        for (int i = 0; i < N; i++) {
            if (A.at(i) % 2 != 0) {
                isAllEven = false;
            }
        }
        if (isAllEven) {
            count++;
            for (int i = 0; i < N; i++) {
                A.at(i) /= 2;
            }
        }
        else {
            break;
        }
    }

    cout << count << endl;

    return 0;
}

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

class Main{
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st  = new StringTokenizer(br.readLine());

        int N = Integer.parseInt(st.nextToken());
        int M = Integer.parseInt(st.nextToken());

        List<List<Integer>> g = new ArrayList();

        for (int i=0; i<N; i++) {
        	g.add(new ArrayList());
        }

        for (int i=0; i<M; i++) {
        	st  = new StringTokenizer(br.readLine());

	        int A = Integer.parseInt(st.nextToken())-1;
	        int B = Integer.parseInt(st.nextToken())-1;

	        g.get(A).add(B);
	        g.get(B).add(A);
        }
        
        HashSet<Integer> vis = new HashSet();

        Queue<Integer> q = new LinkedList();
        q.offer(0);
        int[] signPost = new int[N];
        signPost[0]=1;
        vis.add(0);
        while(!q.isEmpty()){
        	int cur = q.poll();
        	for (int neigh: g.get(cur)) {
        		if(!vis.contains(neigh)){
        			vis.add(neigh);
        			q.offer(neigh);
        			signPost[neigh]=cur+1;
        		}
        	}
        }
        if (vis.size()<N) {
        	System.out.println("No");
        }
        else{
        	System.out.println("Yes");
        	for (int i=1; i<N; i++) {
        		System.out.println(signPost[i]);
        	}
        }

    }

}

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

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;

  --X;
  --Y;

  vector<int> c(N, 0);

  rep(i,N-1) {
    for(int j=i+1; j<N; ++j) {
      int mn = INT_MAX;
      if (mn > j-i) mn = j-i;
      if (mn > abs(Y-j) + abs(X-i) + 1) mn = abs(Y-j) + abs(X-i) + 1;
      if (mn != INT_MAX) c[mn]++;
    }
  }

  for(int i=1; i<=N-1; ++i) {
    cout << c[i] << endl;
  }
  return 0;
}


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

typedef long long int ll;

ll mod = 1e9 + 7;

ll mul(ll a, ll b){
	return (mod+(a*b)%mod)%mod;
}

ll diff(ll a, ll b){
	return (mod+(a-b)%mod)%mod;
}

ll add(ll a, ll b){
	return (mod+(a+b)%mod)%mod;
}


int main(){
	
	ll n;
	cin>>n;
	
	ll a = INT_MIN;
	ll b = INT_MAX;
	ll c = INT_MIN;
	ll d = INT_MAX;
	
	for(ll i=0;i<n;i++){
		ll aa, bb;
		cin>>aa>>bb;
		a = max(a, aa+bb);
		b = min(b, aa+bb);
		c = max(c, aa-bb);
		d = min(d, aa-bb); 
	}
	cout<<max(a-b, c-d); 
}


Measured memory_bytes: 3616
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cassert>
#define L first
#define R second
#define travel(x, i) for (int i = fir[x]; i; i = e[i].nxt)
#define fail {puts("No"); exit(0);}
using namespace std;
 
const int N = 1e5 + 5;
const int INF = 1e7;
 
struct Constraint {
  pair <int, int> range;
  bool o, u;
  Constraint() {u = 0; range.L = - INF; range.R = INF;}
} con[N];
 
struct edge {
  int nxt, to;
} e[N << 1];
 
int fir[N], cnt = 0;
int n, k, col[N];
bool done[N];
 
inline void add(int x, int y) {
  e[++ cnt] = (edge){fir[x], y};
  fir[x] = cnt;
}
 
inline void combine(Constraint &A, const Constraint &B) {
  if (!B.u) return;
  if (!A.u) {
A.u = 1;
    A.range = B.range;
    A.range.L --;
    A.range.R ++;
    return;
  }
  A.range.L = max(A.range.L, B.range.L - 1);
  A.range.R = min(A.range.R, B.range.R + 1);
}
 
inline void dfs(int x, int pa) {
  if (done[x]) {
    con[x].u = 1;
    con[x].range.L = con[x].range.R = col[x];
    con[x].o = col[x] & 1;
  }
  travel(x, i)
    if (e[i].to != pa) {
      dfs(e[i].to, x);
      if (con[x].u && con[e[i].to].u && con[x].o == con[e[i].to].o) fail
      if (con[e[i].to].u) con[x].o = con[e[i].to].o ^ 1;
      combine(con[x], con[e[i].to]);
      if (con[x].range.L > con[x].range.R) fail
    }
}
 
inline void solve(int x, int pa) {
  assert(con[x].range.L <= con[x].range.R);
  if (!done[x]) {
    if (con[x].range.L <= col[pa] + 1 && col[pa] + 1 <= con[x].range.R) col[x] = col[pa] + 1;
    else col[x] = col[pa] - 1;
    con[x].range.R = con[x].range.L = col[x];
    con[x].u = 1;
  }
  travel(x, i)
    if (e[i].to != pa) {
      combine(con[e[i].to], con[x]);
      solve(e[i].to, x);
    }
}
 
int main() {
  scanf("%d", &n);
  for (int i = 1, x, y; i < n; i ++) {
    scanf("%d%d", &x, &y);
    add(x, y); add(y, x);
  }
  scanf("%d", &k);
  int rt = 0;
  for (int i = 1, p, v; i <= k; i ++) {
    scanf("%d%d", &v, &p);
    if (i == 1) rt = v;
    col[v] = p;
    done[v] = 1;
  }
  dfs(rt, 0);
  puts("Yes");
  solve(rt, 0);
  for (int i = 1; i <= n; i ++) printf("%d\n", col[i]);
  return 0;
}

Measured memory_bytes: 8320
import java.util.*;

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

        if(N%10==3){
                System.out.println("bon");            
        }else if(N%10==0 || N%10==1 || N%10==6 ||  N%10==8){  
                System.out.println("pon");
        }else{
                System.out.println("hon");
            }      
	}
}

Measured memory_bytes: 35772
#!/usr/bin/env python
# coding: utf-8

# In[6]:


from collections import deque


# In[21]:


sa = input()
sb = input()
sc = input()


# In[30]:


def func(s_a, s_b, s_c, n):
    if n == 0:
        if len(s_a) == 0:
            print("A")
            return
        else:
            card = s_a.popleft()
    elif n == 1:
        if len(s_b) == 0:
            print("B")
            return
        else:
            card = s_b.popleft()
    elif n == 2:
        if len(s_c) == 0:
            print("C")
            return
        else:
            card = s_c.popleft()
    
    if card == "a":
        func(s_a,s_b,s_c,0)
    elif card == "b":
        func(s_a,s_b,s_c,1)
    elif card == "c":
        func(s_a,s_b,s_c,2)


# In[31]:


func(deque(sa),deque(sb),deque(sc),0)


# In[ ]:






Measured memory_bytes: 9316
-- うおおおおお競プロでHaskell勉強してやるううううううう

import Data.Char
import Data.List
import System.IO
import Control.Applicative
import Control.Monad
-- https://hoogle.haskell.org で関数検索

{- お客様の中でHaskellを書ける方はいらっしゃいますか？
    と、Haskellの例がなくて困っていたところを @tanakh さんに助けて頂きました。本当にありがとうございました。-}
main :: IO ()
main = do 
    [a,b,c] <- getIntegerList 
    yesno (not ((or2 same3 diff3) [a,b,c] ) )

    
 
 
 
or2 c1 c2 x 
    | c1 x ==True    = True
    | c2 x ==True    = True
    | otherwise        = False
 
same3 [a,b,c]
    | a==b && b==c = True
    | otherwise         = False       
       
diff3 [a,b,c] 
    | a==b = False
    | b==c = False
    | c==a = False
    | otherwise = True

yesno cond
    | cond         = putStrLn "Yes"
    | otherwise = putStrLn "No"
    
    
    
{-

main = readLn >>= print . ceiling . (/2) 


(+) 3 $ (*) 4 4
-> 19
pure (+) <*> (Just 1) <*> ( Just 3)
-> Just 4

main = do 
    [a,b] <- getIntegerList 
    print $ (a*(a-1)+b*(b-1)) `div` 2
    -- / じゃなくて'div' ！！！！！

main = do
    s <- getLine    
    samecoffee s

samecoffee [x,y,a,b,c,d] 
    | a==b && c==d = do putStrLn "Yes"
    | otherwise         = do putStrLn "No"
samecoffee s = do putStrLn ""
         
putStrLn $ (show c) ++ " " ++ (show a) ++ " " ++ (show b)


main :: IO ()
main = do
    -- 整数の入力
    a <- readLn
    -- スペース区切り整数の入力
    [b, c] <- getIntegerList

    --[b, c] <- map read . words <$> getLine
    -- 文字列の入力
    s <- getLine
    -- 出力
    putStrLn $ show (a + b + c) ++ " " ++ s
-}

-- レイアウト規則

fac 0 = 1
fac n = n * fac (n-1)

-- FileName   : 164a
-- CreatedDate: 2020-04-26 20:56:13

--------------------------------------------  https://atcoder.jp/contests/abc164/submissions/12342628

getIntList        = map (read :: String -> Int) . words <$> getLine
getIntegerList    = map (read :: String -> Integer) . words <$> getLine
getIntegerListN m = map (read :: String -> Integer) <$> replicateM m getLine


base :: Integer
base = 1000000007

plus :: Integer -> Integer -> Integer
plus a b = (a+b) `mod` base

times :: Integer -> Integer -> Integer
times a b = a * b `mod` base

minus :: Integer -> Integer -> Integer
minus a b
   | a < b     = a-b + base
   | otherwise = a-b

power :: Integer -> Integer -> Integer
power n k
   | k == 0         = 1
   | k `mod` 2 == 0 = power (times n n) (k`div`2)
   | otherwise      = times n $! power n (k-1)

inv :: Integer -> Integer
inv n = power n $ base - 2

binom :: Integer -> Integer -> Integer
binom n m
   | (n-m) < m = times (foldr times 1 [m+1..n]) $ inv $ foldr times 1 [1..n-m]
   | otherwise = times (foldr times 1 [n-m+1..n]) $ inv $ foldr times 1 [1..m]



















Measured memory_bytes: 508
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int H, W, A, B;
  cin>>H>>W>>A>>B;

  vector<vector<Int> > ans(H, vector<Int>(W, 0));
  for(Int i=0;i<H;i++)
    for(Int j=0;j<A;j++) ans[i][j] = 1;

  for(Int j=0;j<W;j++)
    for(Int i=0;i<B;i++) ans[i][j] ^= 1;

  for(Int i=0;i<H;i++){
    for(Int j=0;j<W;j++) cout<<ans[i][j];
    cout<<endl;
  }

  return 0;
}


Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
using ll = long long;
using VI = vector<int>;

int main(){
  int n,m,x;cin >> n >> m >> x;
  int a[n+1] = {0};
  for(int i=0;i<m;i++){
    int k;cin >> k;
    a[k] = 1;
  }
  /*for(int i=0;i<n+1;i++){
    cout << a[i] << endl;
  }*/
  int lans = 0;
  int rans = 0;
  for(int i=0;i<x;i++) lans+=a[i];
  for(int i=x;i<n+1;i++) rans += a[i];
  cout << min(lans,rans) << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

inline int GCD(int a,int b) {
	if (a > b) {//aの方が小さい
		int c = a; a = b; b = c;
	}
	if (a == 0) return b;
	return GCD(a,(b%a));
}

int main() {
	int N,X;
	cin >> N >> X;
	int *x = new int[N];

	for (int i = 0; i < N; i++) {
		cin >> x[i];
		x[i] -= X;
		if (x[i] < 0) { x[i] *= -1; }
	}

	int gcd = x[0];
	for (int i = 1; i < N; i++) {
		gcd = GCD(gcd, x[i]);
	}

	cout << gcd;

	delete[] x;
	return 0;
}

Measured memory_bytes: 640
use whiteread::parse_line;

fn main() {
    let (n, m): (usize, usize) = parse_line().unwrap();
    let (nn, mm);

    if n == 1 {
        nn = 1;
    } else {
        nn = n - 2;
    }
    if m == 1 {
        mm = 1;
    } else {
        mm = m - 2;
    }
    println!("{}", nn * mm);
}


Measured memory_bytes: 2152
from collections import deque

def main():
    divide = ["dream", "dreamer", "erase", "eraser"]

    S = input()

    q = deque([0])

    while(q):
        beg_i = q.popleft()

        if beg_i == len(S):
            print("YES")
            return
        
        for div_i in divide:
            end_i = beg_i + len(div_i)
            if S[beg_i:end_i] == div_i:
                q.append(end_i)
    
    print("NO")
    return

main()



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

int main(){
  int N,K;
  int n;
  cin>>N>>K;
  vector<vector<int>> A(K,vector<int>(N));
  for(int i=0;i<K;i++){
    cin>>n;
    for(int j=0;j<n;j++){
      cin>>A.at(i).at(j);
    }
  }
  for(int i=0;i<K;i++){
    for(int j=0;j<N;j++){
      if(A.at(i).at(j)=='\0'){
        A.at(i).at(j)=0;
      }
    }
  }
  
  vector<int> B(N);
  for(int i=0;i<N;i++){
    B.at(i)=1;
  }
   for(int i=0;i<K;i++){
    for(int j=0;j<N;j++){
      if(A.at(i).at(j)!=0){
        B.at(A.at(i).at(j)-1)=0;
      }
    }
   }
  int sum=0;
  for(int i=0;i<N;i++){
    sum+=B.at(i);
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 3596
#include <stdio.h>
#include <stdlib.h>


// チェス盤面の配列
int BOARD[8][8];


// クイーンの動ける範囲にフラグを立てる（フラグのある場所にクイーンは置けない）
void Put(int gyou, int retu, int bango){
	int i, j;

	for(i = 0; i < 8; i++)	// 横
		if(BOARD[gyou][i] == -1)
			BOARD[gyou][i] = bango;

	for(i = 0; i < 8; i++)	// 縦
		if(BOARD[i][retu] == -1)
			BOARD[i][retu] = bango;

	// 左斜め
	i = gyou; j = retu;
	while(i > 0 && j > 0){
		i--; j--;
	}
//printf("i:%d j:%d\n", i, j);
	while(i < 8 && j < 8){
		if(BOARD[i][j] == -1)
			BOARD[i][j] = bango;
		i++;	j++;
	}

	// 右斜め
	i = gyou; j = retu;
	while(i > 0 && j < 7){
		i--; j++;
	}
//printf("i:%d j:%d\n", i, j);
	while(i < 8 && j >= 0){
		if(BOARD[i][j] == -1)
			BOARD[i][j] = bango;
		i++;	j--;
	}
}




void Remove(int gyou, int retu, int bango){
	int i, j;

	for(i = 0; i < 8; i++)	// 横
		if(BOARD[gyou][i] == bango)
			BOARD[gyou][i] = -1;

	for(i = 0; i < 8; i++)	// 縦
		if(BOARD[i][retu] == bango)
			BOARD[i][retu] = -1;

	// 左斜め
	i = gyou; j = retu;
	while(i > 0 && j > 0){
		i--; j--;
	}
//printf("i:%d j:%d\n", i, j);
	while(i < 8 && j < 8){
		if(BOARD[i][j] == bango)
			BOARD[i][j] = -1;
		i++;	j++;
	}

	// 右斜め
	i = gyou; j = retu;
	while(i > 0 && j < 7){
		i--; j++;
	}
//rintf("i:%d j:%d\n", i, j);
	while(i < 8 && j >= 0){
		if(BOARD[i][j] == bango)
			BOARD[i][j] = -1;
		i++;	j--;
	}

	BOARD[gyou][retu] = -1;
}


void Disp_board()
{
	int i, j;

	for(i = 0; i < 8; i++){
		for(j = 0; j < 8; j++){
			if(BOARD[i][j] == 9)
				printf("Q");
			else
				printf(".");
		}
		printf("\n");
	}
}


int Queen_puzzle(int gyou, int retu, int bango)
{
	int i, j;

	for(i = 0; i < 8; i++){
		for(j = 0; j < 8; j++){
			if(BOARD[i][j] == -1){
				Put(i, j, bango);
				BOARD[i][j] = 9;
				if(bango == 8)
					return 1;
				if(Queen_puzzle(0, 0, bango + 1))
					return 1;
				else
					Remove(i, j, bango);
			}
		}
	}

	return 0;
}


int main()
{
	int n;
	int gyou, retu;
	int i, j, k;

	for(i = 0; i < 8; i++)
		for(j = 0; j < 8; j++)
			BOARD[i][j] = -1;

	scanf("%d", &n);

	for(i = 0; i < n; i++){
		scanf("%d %d", &gyou, &retu);
		Put(gyou, retu, i + 1);
		BOARD[gyou][retu] = 9;
	}

	Queen_puzzle(0, 0, i + 1);

	Disp_board();

	return 0;
}


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

using namespace std;

using ll = long long;

const ll INF = 4e18;

int main() {
   ios_base::sync_with_stdio(false); cin.tie(nullptr);
   int T;
   cin >> T;
   while (T--) {
      ll N, A, B, C, D; cin >> N >> A >> B >> C >> D;
      vector<pair<int, ll>> keks = {{2, A}, {3, B}, {5, C}};
      map<ll, ll> dp;
      function<ll(ll)> solve = [&](ll N) {
         if (N == 0) return 0LL;
         if (N == 1) return D;
         if (dp.count(N)) {
            return dp[N];
         }
         ll ans = INF;
         if (ans / D >= N) ans = min(ans, N * D);
         for (auto z : keks) {
            int num; ll cost;
            tie(num, cost) = z;
            ans = min(ans, solve(N / num) + D * (N % num) + cost);
            if (N % num) {
               ans = min(ans, solve((N / num) + 1) + D * (num - (N % num)) + cost);
            }
         }
         return dp[N] = ans;
      };
      cout << solve(N) << "\n";
   }
}


Measured memory_bytes: 4424
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#define int long long
#define double long double
#define oku7 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用

using namespace std;
std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位

vector<int> input;

struct uf_tree {
	std::vector<int> parent;
	int __size;
	uf_tree(int size_) : parent(size_, -1), __size(size_) {}
	void unite(int x, int y) {
		if ((x = find(x)) != (y = find(y))) {
			if (parent[y] < parent[x]) std::swap(x, y);
			parent[x] += parent[y];
			parent[y] = x;
			__size--;
		}
	}
	bool is_same(int x, int y) { return find(x) == find(y); }
	int find(int x) { return parent[x] < 0 ? x : parent[x] = find(parent[x]); }
	int size(int x) { return -parent[find(x)]; }
	int size() { return __size; }
};

signed main() {
	int N, K, L;
	cin >> N >> K >> L;
	uf_tree road(1000000), train(1000000);
	for (int i = 0; i < K; i++) {
		int p, q;
		cin >> p >> q;
		road.unite(p, q);
	}
	for (int i = 0; i < L; i++) {
		int r, s;
		cin >> r >> s;
		train.unite(r, s);
	}
	map<pair<int, int>, int> ma;
	//道でも線路でも同じボスに属しているヤツの個数を数える
	for (int i = 1; i <= N; i++) {
		ma[make_pair(road.find(i), train.find(i))]++;
	}
	for (int i = 1; i <= N; i++) {
		cout<< ma[make_pair(road.find(i), train.find(i))];
		if (i == N) break;
		cout << " ";
	}

	return 0;
}

Measured memory_bytes: 27776
#include <algorithm>
#include <climits>
#include <iostream>
#include <iomanip>
#include <random>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using std::cin;
using std::cerr;
using std::cout;
using std::endl;
using std::make_pair;
using std::pair;
using std::stack;
using std::string;
using std::unordered_map;
using std::unordered_set;
using std::vector;
using std::lower_bound;
using std::upper_bound;

int gcd(int a, int b) {
  int c = std::max(a, b);
  int d = std::min(a, b);
  while (c % d != 0) {
    int tmp = c;
    c = d;
    d = tmp % d;
  }
  return d;
}

int gcd(int a, int b, int c) {
  return gcd(gcd(a, b), c);
}

int main(int argc, char* argv[]) {
  int k;
  cin >> k;
  long result = 0;
  for (int i = 1; i <= k; ++i) {
    for (int j = 1; j <= k; ++j) {
      for (int l = 1; l <= k; ++l) {
        result += gcd(i, j, l);
      }
    }
  }
  cout << result;
  return 0;
}


Measured memory_bytes: 3648
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int l = scan.nextInt();
		List<String> s = new ArrayList<String>();

		for (int i = 0; i < n; i++) {
			s.add(scan.next());
		}
		s.sort(Comparator.naturalOrder());
		System.out.println(String.join("", s));
	}

}


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

using namespace std;
bool isW(char c){
    return c=='W';
}
bool isX(char c){
    return c=='x';
}
int main(){//D問題
    int n;
    string s;
    cin >> n >> s;
    vector<char> t(n);
    char assum[4][2] = {{'S', 'S'}, {'S', 'W'}, {'W', 'S'}, {'W', 'W'}};
    for(int i=0;i<4;++i){
        t[0] = assum[i][0];
        t[1] = assum[i][1];
        for(int j=1;j<n-1;++j){
            t[j+1] = isW(t[j-1])^isX(s[j])^isW(t[j]) ? 'W' : 'S';
        }
        if(!(isW(t[n-2])^isX(s[n-1])^isW(t[n-1])^isW(t[0]) || isW(t[n-1])^isX(s[0])^isW(t[0])^isW(t[1]))){
            for(char c : t){
                cout << c;
            }
            return 0;
        }
    }
    cout << "-1";
    return 0;
}

Measured memory_bytes: 512
n,q = [int(i) for i in input().split()]
s = input()
cumsum = [0]*n
ans = 0
flag = False

for i in range(n):
    if flag:
        if s[i] == "C":
            ans += 1

    cumsum[i] = ans     

    flag = False

    if s[i] == "A":
        flag = True
    


for i in range(q):
    l,r = [int(i) for i in input().split()]
    ans = cumsum[r-1] - cumsum[l-1]
    print(ans)

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

int main() {
  int N,K,X,Y;
  cin >> N >> K >> X >> Y;
  if (N <= K) {
    cout << N * X << endl;
  }
  else {
    cout << K * X + (N - K) * Y << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)




int main() {

	int N;
	cin >> N;
	vector<int> C(N);
	vector<int> S(N);
	vector<int> F(N);
	for (int i = 0; i < N-1; i++) {
		cin >> C.at(i);
		cin >> S.at(i);
		cin >> F.at(i);
	}
	
	rep(i, N - 1) {
		int time = 0;
		for (int j = i; j < N-1; j++) {
			int check = S.at(j);
			while (time > check) {
				check += F.at(j);
			}
			time = check;
			time += C.at(j);
		}
		cout << time << endl;
	}
	cout << 0 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-3;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef vector<vector<ll>> mat;
typedef vector<ll> vec;
mat mtmul(mat &A, mat &B) {
	mat C(A.size(), vec(B[0].size()));
	rep(i, (int)A.size()) {
		rep(k, (int)B.size()) {
			rep(j, (int)B[0].size()) {
				C[i][j] = (C[i][j] + (A[i][k] * B[k][j]) % mod) % mod;
			}
		}
	}
	return C;
}
mat mtpow(mat A, ll n) {
	mat B(A.size(), vec(A.size()));
	rep(i, (int)A.size()) {
		B[i][i] = 1;
	}
	while (n > 0) {
		if (n&(ll)1)B = mtmul(B, A);
		A = mtmul(A, A);
		n >>= 1;
	}
	return B;
}
int main() {
	int n; ll k; cin >> n >> k;
	mat A;
	rep(i, n) {
		vec v; v.resize(n);
		rep(j, n) {
			cin >> v[j];
		}
		A.push_back(v);
	}
	A = mtpow(A, k);
	ll ans = 0;
	rep(i, n) {
		rep(j, n) {
			ans = (ans + A[i][j]) % mod;
		}
	}
	cout << ans << endl;
	//stop
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<map>
#include<cstring>
using namespace std;
#define NUM 10000
int hashs[102];
int N,K;
long long int dp[5][5][102];


long long int check(int i,int j,int k)
{
  //  cerr<<"#"<<i<<" "<<j<<" "<<k<<endl;

  long long int sum=0;
  if(k==N)
    return 1;
  if(dp[i][j][k]!=-1)
    return dp[i][j][k];

  for(int x=1;x<4;x++)
    {
      if(!(i==x && j==x) && (hashs[k+1]==-1 || hashs[k+1]==x))
        sum+=check(j,x,k+1)%NUM;
    }
  dp[i][j][k]=sum;
  return sum;

}



int main()
{
  memset(dp,-1,sizeof(dp));
    memset(hashs,-1,sizeof(hashs));

  cin>>N>>K;
  for(int i=0;i<K;i++)
    {
      int a,b;
      cin>>a>>b;

      hashs[a]=b;
    }
  long long int ans=check(0,0,0);
  cout<<ans%NUM<<endl;


}

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

using namespace std;

typedef long long ll;

#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < ll(b); i++)
#define FORD(i, a, b) for (ll i = b - 1; i >= ll(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

#define ALL(x) (x).begin(), (x).end()

int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}
int dx[4] ={ 1, 0, -1, 0 };
int dy[4] ={ 0, 1, 0, -1 };

int main()
{
    int n;
    cin>>n;
    ll ans=0;
    FOR(i,1,n+1){
        ans+=(n/i)*(2*i+((n/i)-1)*i)/2;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3576
while True:
    try:
        a,b,c,d,e,f=map(float,input().split())
    except:
        break
    x=(b*f-c*e)/(b*d-a*e)
    (c*d-a*f)/(b*d-a*e)
    y=(c-a*x)/b
    if x==-0:
        x=0
    if y==-0:
        y=0
    print("{:.3f} {:.3f}".format(x,y))


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

int main(void){
    int n;
    cin >> n;
    map<string,int> mp;
    rep(i,n) {
        string s;
        cin >> s;
        mp[s] ++;
    }
    int mx =0;
    for(auto p:mp) mx = max(mx,p.second);
    for(auto p:mp){
        if(p.second != mx) continue;
        cout << p.first << endl;
    }
    return 0;
}

Measured memory_bytes: 25216
#include <bits/stdc++.h>
using namespace std;
 
#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << (a) << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair
 
typedef long long int ll;
typedef deque<int> vi;
typedef pair<int,int> pii;
 
const int MOD = 1e9 + 7;
const int HALF = MOD/2 + 1;
const int N = 2e5 + 10;
 
int n;
vi adj[N];
 
int merge(deque<pii> &a, deque<pii> &b) {
    if (si(a) < si(b)) swap(a,b);
    forn(t,si(b)) {
        a[t].second = ((ll)a[t].first * b[t].second % MOD) + ((ll)a[t].second * b[t].first % MOD);
        if (a[t].second >= MOD) a[t].second -= MOD;
        a[t].first = (ll)a[t].first*b[t].first%MOD;
    }
    return si(b);
}
 
deque<pii> dp[N];
void dfs(int u, int p) {
    dp[u].eb(HALF,HALF);
    int fix = 0;
    for (int v : adj[u]) if (v != p) {
        dfs(v,u);
        dp[v].push_front(mp(1,0));
        fix = max(fix, merge(dp[u], dp[v]));
    }
    forn(t,fix) {
        dp[u][t].first = 1 - dp[u][t].second;
        if (dp[u][t].first < 0) dp[u][t].first += MOD;
    }
 
}
 
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
 
    cin >> n;
    forn(i,n) {
        int p; cin >> p;
        adj[p].pb(i+1);
    }
    n++;
    dfs(0,0);
 
    int ans = 0;
    for (auto xy : dp[0]) {
        ans += xy.second;
        if (ans >= MOD) ans -= MOD;
    }
    forn(_,n) ans = 2*ans%MOD;
    cout << ans << endl;
 
    return 0;
}


Measured memory_bytes: 372992