akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(ll i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<ll, ll>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    ll n;
    cin >> n;
    vector<P> ab(n);
    vector<ll> a(n);
    vector<ll> b(n);
    
    rep(i, n) {
        cin >> ab[i].first >> ab[i].second;
        a[i] = ab[i].first;
        b[i] = ab[i].second;
    }
    ll l;
    ll r;
    sort(whole(a));
    sort(whole(b));
    if (n%2==1) {
        l = a[n/2];
        r = b[n/2];
    }
    else {
        l = a[n/2-1]+a[n/2];
        r = b[n/2-1]+b[n/2];
    }



    ll ans = r-l+1;
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9596
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < n ; i++)
struct NODE{
int to , dist , cost;
NODE(int a,int b,int c){
to = a , dist = b , cost = c;
}
};
bool operator < (const NODE &a,const NODE &b){
return a.dist != b.dist ? a.dist > b.dist : a.cost > b.cost;
}
int main(){
int n,m;
while(cin >> n >> m && (n||m) ){
vector< vector<NODE> > g(n);
bool done[10000] = {0};
int ans = 0;
rep(i,m){
int a,b,c,d;
cin >> a >> b >> c >> d;
a--,b--;
g[a].push_back(NODE(b,c,d));
g[b].push_back(NODE(a,c,d));
}
priority_queue <NODE> Q;
Q.push(NODE(0,0,0));
while(Q.size()){
NODE q = Q.top(); Q.pop();
if(done[q.to])continue;
else done[q.to] = true , ans += q.cost;
rep(i,g[q.to].size()) Q.push(NODE(g[q.to][i].to,q.dist+g[q.to][i].dist,g[q.to][i].cost));
}
cout << ans << endl;
}
}

Measured memory_bytes: 0
S = input()
N = len(S)
words = ['dream', 'dreamer', 'erase', 'eraser']
stack = [0]
ans = "NO"
while stack:
  ind = stack.pop()
  if ind == N:
    ans = 'YES'
    break
  for w in words:
    end = ind+len(w)
    if S[ind:end] == w:
      stack.append(end)
print(ans)

Measured memory_bytes: 73560
import random
D=int(input())
c=input().split()
c=[int(a) for a in c]
S=[]
for _ in range(D):
    s=input().split()
    s=[int(a) for a in s]
    S.append(s)
answers=[]
scores=[]
numbers=[]
for _ in range(100000):
    d=random.randrange(0,26,1)
    q=random.randrange(0,26,1)
    numbers.append([d,q])
whole=sum(c)
suuji=1
T=[]
while suuji<=365:
    T.append(random.randrange(0,26,1))
    suuji+=1
for m in range(100000):
    anss=[]
    ans = 0
    held = [0 for _ in range(26)]
    e=numbers[m][0]
    q=numbers[m][1]
    a=T[e]
    T[e]=q
    wholes=0
    for d in range(D):
        s = S[d]
        place = T[d]
        ans += s[place]
        wholes+=whole
        wholes-=c[place]*((d+1)-held[place])
        held[place] = d + 1
        ans-=wholes
    scores.append(ans)
    answers.append(T)
saidai=max(scores)
basho=scores.index(saidai)

answer=answers[basho]
for answer_ in answer:
    print(answer_+1)


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

using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

using ll = long long;
using P = pair<int, int>;

const int mod = 998244353;

int main(int, char**)
{
    int a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;

    if (v <= w) { cout << "NO" << endl; return 0; }
    ll d = v - w;
    if (d * t >= abs(a-b)) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 3624
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()


int main()
{
	ll N, M;
	cin >> N >> M;

	set<int> acp;
	map<int, int> wap;

	rep(i, M)
	{
		int p;
		string s;

		cin >> p >> s;

		//すでにACの場合はスキップ
		if (acp.count(p) > 0) continue;

		if (s == "WA")
		{
			wap[p]++;
		}
		else
		{
			acp.insert(p);
		}
	}

	//WA数を合計
	ll wa = 0;
	for (auto x : wap)
	{
		if(acp.count(x.first) > 0) wa += x.second;
	}

	cout << acp.size() << " " << wa << endl;

	return 0;
}

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

using namespace std;

typedef long long ll;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define inn(x, y) int x,y;cin>>x>>y
#define innn(x, y, z) int x,y,z;cin>>x>>y>>z
#define bit(n) (1<<(n))

#define out(x) cout<<(x)<<endl;
#define outt(x,y) cout<<(x)<<" "<<(y)<<endl;
#define err(x) cerr<<(x)<<endl;
#define errr(x,y) cerr<<(x)<<" "<<(y)<<endl;
#define errrr(x,y,z) cerr<<(x)<<" "<<(y)<<" "<<(z)<<endl;

#define rep(i,n) for (int i=0;i<(n);i++)
#define repp(i,n) for (int i=1;i<=(n);i++)
#define reppp(j, i, n) for (int j=i+1; j<n; j++)

#define lim5 100002
#define lim9 1000000002

#define deg(rad) (((rad)/2/M_PI)*360)
#define mid(min, max) ((min + max) / 2)

int main() {
	ll n, b, r;
	cin >> n >> b >> r;

	ll ans = 0;
	ans += n / (b + r) * b;

	if (n % (b + r) < b) {
		ans += n % (b + r);
	}
	else {
		ans += b;
	}

	out(ans);


	return 0;
}


Measured memory_bytes: 256
n = int(input())
b = list(map(int, input().split()))
a = []
for i in range(len(b)+1):
    if i == 0:
        a.append(b[0])
    elif i == len(b):
        a.append(b[i-1])
    else:
        a.append(min(b[i], b[i-1]))   
print(sum(a))

Measured memory_bytes: 3064
from collections import deque

H, W, K = map(int,input().split())
S = []
for _ in range(H):
    S.append(list(input()))

D = [[1 for i in range(W)] for j in range(H)]

for x in range(H):
    for y in range(W):
        if S[x][y] == 'S':
            sx = x
            sy = y

D[sx][sy] = 0

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

ans = float('inf')

q = deque([[sx, sy, 0]])

while len(q) != 0:
    x, y, cnt = q.popleft()
    if cnt > K:
        break
    tmp = min(x, y , H - x - 1, W - y - 1)
    if tmp != 0:
        tmp = (tmp - 1) // K
        tmp += 2
    else:
        tmp = 1
    ans = min(ans, tmp)
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        if 0 <= nx < H and 0 <= ny < W and S[nx][ny] != '#' and D[nx][ny]:
            D[nx][ny] = 0
            q.append([nx, ny, cnt + 1])

print(ans)

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

void funcu(vector<int> &level,vector<int> *edgo,int i)
{
    if(edgo[i].size()==0)
    level[i]=0; 
    else
    {
        int maxi=0;
        for( int p=0;p<edgo[i].size();p++)
        {
            if(level[edgo[i][p]]==-1)
            {funcu(level,edgo,edgo[i][p]);}
            maxi=max(maxi,level[edgo[i][p]]);
        }
        
        level[i]=1+maxi;
    }
}

int main() {
	int n,m;
	cin>>n>>m;
	vector<int> edgo[n],edcm[n];
	int x,y;
	for( int i=0;i<m ;i++)
	{
	    cin>>x>>y;
	    edgo[x-1].push_back(y-1);
	    edcm[y-1].push_back(x-1);
	}
	
	vector<int> level;
	for( int i=0;i<n ;i++) level.push_back(-1);

	for( int i=0;i<n ;i++)
	{
	    if(edcm[i].size()==0)
	    {
	        funcu(level,edgo,i);
	    }
	}
	
	int maxi=0;
	for( int i=0;i<n ;i++)
	maxi=max(maxi,level[i]);
	
	cout<<maxi<<endl;
	return 0;
}

Measured memory_bytes: 21116
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)

type kakko struct {
	str string
	min int
	max int
}

func main() {
	N := getStdinInt()
	F := make([]kakko, 0, N)
	L := make([]kakko, 0, N)
	for i := 0; i < N; i++ {
		s := getStdin()
		min, max := minmaxKakko(s)
		if min >= 0 {
			F = append(F, kakko{s, min, max})
		} else {
			L = append(L, kakko{s, min, max})
		}
	}
	sort.Slice(F, func(i, j int) bool { return F[i].max-F[i].min < F[j].max-F[j].min })
	sort.Slice(L, func(i, j int) bool { return L[i].max > L[j].max })

	K := make([]kakko, N)
	for i := 0; i < len(F); i++ {
		K[i] = F[i]
	}
	for i := 0; i < len(L); i++ {
		K[i+len(F)] = L[i]
	}

	first := -1
	last := -1
	for i := 0; i < len(K); i++ {
		if K[i].str[0] == '(' {
			first = i
			break
		}
	}
	for i := len(K) - 1; i >= 0; i-- {
		if first != i && K[i].str[len(K[i].str)-1] == ')' {
			last = i
			break
		}
	}

	if first == -1 || last == -1 {
		fmt.Printf("No\n")
		return
	}

	stack := 0
	stack = okKakko(K[first].str, stack)
	if stack < 0 {
		fmt.Printf("No\n")
		return
	}
	for i := 0; i < len(K); i++ {
		if first == i || last == i {
			continue
		}
		stack = okKakko(K[i].str, stack)
		if stack < 0 {
			fmt.Printf("No\n")
			return
		}
	}
	stack = okKakko(K[last].str, stack)
	if stack < 0 {
		fmt.Printf("No\n")
		return
	}

	if stack == 0 {
		fmt.Printf("Yes\n")
	} else {
		fmt.Printf("No\n")
	}
}

func minmaxKakko(s string) (int, int) {
	stack := 0
	max := math.MinInt32
	min := math.MaxInt32
	for i := 0; i < len(s); i++ {
		if s[i] == '(' {
			stack++
			if stack > max {
				max = stack
			}
		}
		if s[i] == ')' {
			stack--
			if stack < min {
				min = stack
			}
		}
	}
	return min, max
}

func okKakko(s string, stack int) int {
	for i := 0; i < len(s); i++ {
		if s[i] == '(' {
			stack++
		}
		if s[i] == ')' {
			stack--
		}
		if stack < 0 {
			return -1
		}
	}
	return stack
}

var sc = bufio.NewScanner(os.Stdin)

func getStdin() string {
	sc.Scan()
	return sc.Text()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}


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

#define FOR(i,a,n) for (int i = a; i < (int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define whole(f,x,...) ([&](decltype((x)) whole) { \
    return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
template<typename T> bool chmin(T &a, const T &b) {if (a > b) { a = b; return true; }return false;}
template<typename T> bool chmax(T &a, const T &b) {if (a < b) { a = b; return true; }return false;}

using ll = int_fast64_t;

constexpr ll INF = (1e9);
constexpr ll MOD = (1e9+7);

int main() {
  int a, b; cin >> a >> b;
  if (a <= 8 && b <= 8) cout << "Yay!\n";
  else cout << ":(" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;

const int N = 1505;
vector<pii> adj[N];
int n, m, d[N][N], ans, vis[N], f[N], ck[N];

void dijkstra(int S) {
	eFOR(i, 1, n)d[S][i] = INF; d[S][S] = 0;
	priority_queue<pii, vector<pii>, greater<pii> >mp;
	mp.push(pii(d[S][S], S));
	while (mp.size()) {
		pii z = mp.top();
		mp.pop();
		int u = z.second, val = z.first;
		if (val != d[S][u])continue;
		ans = max(ans, val);
		REP(i, adj[u].size()) {
			int v = adj[u][i].first, cost = adj[u][i].second;
			if (d[S][v] > d[S][u] + cost) {
				d[S][v] = d[S][u] + cost;
				mp.push(pii(d[S][v], v));
			}
		}
	}
}

void dfs(int u, int root) {
	if (vis[u])return;
	vis[u] = true;
	f[u] = d[root][u];
	REP(i, adj[u].size()) {
		int v = adj[u][i].first, cost = adj[u][i].second;
		if (d[root][v] == d[root][u] + cost) {
			dfs(v, root);
			f[u] = max(f[u], f[v]);
		}
	}
	if (f[u] == ans)ck[u] = 1;
}

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

	cin >> n >> m;
	eFOR(i, 1, m) {
		int u, v, d;
		cin >> u >> v >> d;
		adj[u].push_back(pii(v, d));
		adj[v].push_back(pii(u, d));
	}
	eFOR(i, 1, n)dijkstra(i);
	eFOR(i, 1, n) {
		eFOR(j, 1, n)vis[j] = 0;
		dfs(i, i);
	}
	int cnt = 0;
	eFOR(i, 1, n)if (!ck[i])cnt++;
	cout << cnt << endl;
	eFOR(i, 1, n)if (!ck[i])cout << i << endl;
	return 0;
}




Measured memory_bytes: 21048
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
signed main() {
  int N;
  while (cin>>N,N!=0){
    int ma = 0, mi = INF;
    int ans=0;
    for(int i=0;i<N;i++){
      int t;cin>>t;
      ma=max(ma,t);
      mi=min(mi,t);
      ans+=t;
    }
    ans-=ma+mi;
    N-=2;
    ans/=N;
    cout<<ans<<endl;
  }
}




Measured memory_bytes: 3000
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	for {
		sc.Scan()
		cards := sc.Text()
		if cards == "-" {
			break
		}
		sc.Scan()
		times, _ := strconv.Atoi(sc.Text())
		for i := 0; i < times; i++ {
			sc.Scan()
			h, _ := strconv.Atoi(sc.Text())
			cards = cards[h:] + cards[:h]
		}
		fmt.Println(cards)
	}
	return
}



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

int main()
{
    string s;
    getline(cin,s);
    for(int i=0;i<s.length();i++){
        if(s[i]>='a'&&s[i]<='z')
            s[i]+='A'-'a';
    }
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 1172
#include<stdio.h>
#include<iostream>
using namespace std;
typedef long long ll;
const ll N=100;
ll a[N];
int main()
{
	ll n,i,j;
	ll num=1000;
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	for(i=1;i<=n;)
	{
		bool sum=0;
		int j;
		if(a[i]>=a[i+1]&&i+1<=n)
		{
			while(a[i]>=a[i+1]&&i+1<=n)
			{
				i=i+1;
			}
			continue;
		}
		for(j=i+1;j<=n;j++)
		{
			if(a[j]>=a[j-1])
			{
				sum=1;
			}
			else break;
		}
		if(sum)
		{
			num=num%a[i]+num/a[i]*a[j-1];
			i=j;
		} 
		else break;
	}
	printf("%lld\n",num);
	return 0;
}

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

using ll = long long int;
using P = pair<int, int>;
using P3 = pair<int,P>;
using PP = pair<P, P>;
constexpr int INF = 1<<29;
constexpr ll MOD = ll(1e9)+7;
constexpr int di[] = {0,1,0,-1};
constexpr int dj[] = {1,0,-1,0};


int main(){
    int h, w;
    cin >> w >> h;
    vector<vector<int> > a(h, vector<int>(w));
    int cnt = 0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> a[i][j];
            if(a[i][j]) cnt++;
            else cnt--;
        }
    }
    bool ok = abs(cnt) <= 1;
    for(int i=0;i<h-1;i++){
        for(int j=0;j<w-1;j++){
            int x = 0;
            for(int k=0;k<4;k++){
                x += a[i+k/2][j+k%2];
            }
            if(x&1) ok = false;
        }
    }
    for(int i=0;i<h;i++){
        int x = 0;
        for(int j=0;j<w;j++){
            if(a[i][j]) x++;
            else x--;
        }
        ok &= abs(x) <= 1;
    }
    for(int j=0;j<w;j++){
        int x = 0;
        for(int i=0;i<h;i++){
            if(a[i][j]) x++;
            else x--;
        }
        ok &= abs(x) <= 1;
    }
    cout << (ok ? "yes" : "no") << endl;
    return 0;
}




Measured memory_bytes: 6792
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
  int N,K;
  cin>>N>>K;
  int a,b,ans;
  vector<int>v(100001);
  for(int i=0;i<100001;i++)v[i]=0;
  for(int i=0;i<N;i++){
    cin>>a>>b;
    v[a]+=b;
  }
  for(int i=0;i<100001;i++){
    K-=v[i];
    if(v[i]!=0)ans=i;
    if(K<=0)break;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
void qsort(
	void* base, size_t num, size_t size,
	int(*compare)(const void* a, const void* b)
);
int desc(const void* a, const void* b) {
	return *(int*)b - *(int*)a;
}
int main(void) {
	int n;

	scanf("%d", &n);

	int i, j;
	int point[200000];
	
	

	for (i = 0; i < n; i++) {
		scanf("%d", &point[i]);
	}


	/*for (i = 0; i < n/2; i++) {
		kizyun[i] = point[i];
	}

	qsort(point, sizeof(point) / sizeof(*point), sizeof(*point), desc);
	

	for (i = 0; i < n/2; i++) {
		printf("%d\n", kizyun[i]);
	}

	for (i = 0; i < n; i++) {
		if (point[i] != kizyun[i]){
			printf("%d\n", point[i]);
	}else{
			for (int j = i; j < n; j++) {
				if (point[j] != kizyun[i]) {
					printf("%d\n", point[i]);
					break;
				}
			}
		
	}*/

	int max = 0;
	int nextmax = 0;
	int a = 0;
	int b = 0;
	int temp;
	for (i = 0; i < n; i++) {
	
		if (max < point[i]) {
		
			temp = max;
			max = point[i];
			nextmax = temp;
			temp = a;
			a = i;
			b = temp;
		}
		else if (nextmax < point[i]) {
			
			nextmax = point[i];
		}
	}


	for (i = 0; i < n; i++) {
		if (a != i) {
		
			printf("%d\n", max);
		}
		else {
			printf("%d\n", nextmax);
		}
	}



	

	
	return 0;
}

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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const ll MOD2 = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main()
{
  //input
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int H, W, h, w; cin >> H >> W >> h >> w;
  
  //main
  
  
  // output
  cout << (H-h)*(W-w) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
map<int, int> mp;
void prime_factorize(ll n, vector<ll> &ret)
{
	if (n <= 1)	return;
	ll last = sqrt(n);
	for (ll i = 2; i <= last; i++) {
		if (n % i == 0) {
			prime_factorize(i, ret);
			prime_factorize(n / i, ret);
			return;
		}
	}
	ret.push_back(n);
	return;
}
int getDig(ll i)
{
	int dig = 0;
	while (i != 0) {
		i /= ll(10);
		dig++;
	}
	return dig;
}
int main()
{
	ll n;
	cin >> n;
	vector<ll> fac;
	prime_factorize(n, fac);
	int s = fac.size();
	ll fac1, fac2;
	fac1 = fac2 = 1;
	int ans, dig;
	ans = iINF;
	rep(i, 1 << s) {
		fac1 = fac2 = 1;
		rep(j, s) {
			if (i >> j & 1)	fac1 *= fac[j];
			else fac2 *= fac[j];
		}
		dig = max(getDig(fac1), getDig(fac2));
		ans = min(ans, dig);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3720
import java.util.*;
public class Main{
	public static void main(String[]agrs){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] list = new int[n];
		for(int i = 0; i < n; i++) {
			list[i] = sc.nextInt();
		}
		
		long[][] dp = new long[n-1][21];
		dp[0][list[0]] = 1;
		for(int i = 1; i < n-1; i++ ) {
			for(int j = 0; j < 21; j++) {
				if(j + list[i] >= 0 && j + list[i] <= 20) {
					dp[i][j + list[i]] += dp[i-1][j];
				}
				if(j - list[i] >= 0 && j - list[i] <= 20) {
					dp[i][j - list[i]] += dp[i-1][j];
				}
			}
		}
		System.out.println(dp[n-2][list[n-1]]);
		
	}
}

Measured memory_bytes: 18172
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    int A,B,C;
    cin>>A>>B>>C;
    int count=0;
    for(int i=101;i>=1;i--){
        if(A%i==0 && B%i==0){
            count++;
        }
        if(count==C){
            cout<<i<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
int64_t MOD=1000000007;

int main() {
  int N,temp=0,ans;
  cin>>N;
  vector<int64_t> S(N);
  for(int i=0;i<N;i++)cin>>S.at(i);
  sort(S.begin(),S.end());
  int k=S.at(N-1);
  for(int i=0;i<N;i++){
    int t=min(k-S.at(i),S.at(i));
    if(t>temp){
      temp=t;
      ans=S.at(i);
    }
  }
  cout<<k<<' '<<ans;
    
      
}


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

int a[4];
char c[4];

void dfs(int d,int s,vector<char> v){
    if(d==4){
        if(s==7){
            cout<<a[0];
            for(int i=1;i<4;i++){
                cout<<v[i-1]<<a[i];
            }
            cout<<"=7"<<endl;
            exit(0);
        }
        return;
    }
    v.push_back('-');
    dfs(d+1,s-a[d],v);
    v[v.size()-1]='+';
    dfs(d+1,s+a[d],v);
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    for(int i=0;i<4;i++){
        cin>>c[i];
        a[i]=c[i]-'0';
    }
    vector<char> v;
    dfs(1,a[0],v);

    return 0;
}

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

int H, W, N;
int ix, iy;
string S, T;

bool solve() {
    // left, right
    int left = 0, right = W;
    if (S[N-1] == 'L') ++left;
    if (S[N-1] == 'R') --right;
    for (int i = N-2; i >= 0; --i) {
        if (T[i] == 'L') right = min(right+1, W);
        else if (T[i] == 'R') left = max(0, left-1);
        if (S[i] == 'L') left = left + 1;
        else if (S[i] == 'R') right = right - 1;
        if (left >= right) return false;
    }
    if (iy < left || iy >= right) return false; 

    // up, down
    left = 0, right = H;
    if (S[N-1] == 'U') ++left;
    if (S[N-1] == 'D') --right;
    for (int i = N-2; i >= 0; --i) {
        if (T[i] == 'U') right = min(right+1, H);
        else if (T[i] == 'D') left = max(0, left-1);
        if (S[i] == 'U') left = left + 1;
        else if (S[i] == 'D') right = right - 1; 
        if (left >= right) return false;
    }
    if (ix < left || ix >= right) return false;

    return true;
}

int main() {
    while (cin >> H >> W >> N >> ix >> iy >> S >> T) {
        --ix, --iy;
        if (solve()) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

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

int main() {
    int n,m;
    cin >> n >> m;
    int a[50],b[50];
    int result[50] = {0};
    for(int i=0;i<m;i++){
        cin >> a[i] >> b[i];
    }
    for(int i=0;i<m;i++){
        result[a[i]]++;
        result[b[i]]++;
    }
    for(int i=1;i<=n;i++){
        cout << result[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <cstdio>

using namespace std;

int N, M;
int A[100][100], B[100];

int main(void) {

    cin >> N >> M;

    for (int n = 0; n < N; ++n) {
        for (int m = 0; m < M; ++m) {
            cin >> A[n][m];
        }
    }

    for (int m = 0; m < M; ++m) {
        cin >> B[m];
    }

    for (int n = 0; n < N; ++n) {
        int result = 0;
        for (int m = 0; m < M; ++m) {
            result += A[n][m] * B[m];
        }
        printf("%d\n", result);
    }

    return 0;
}

Measured memory_bytes: 1184
#include<iostream>
#include<cstdio>

using namespace std;

int n,q;
int tree[100050];

int Find(int x)
{
    if(tree[x]==x)
        return x;
    return Find(tree[x]);
}

int main()
{
    while(scanf("%d %d",&n,&q)==2)
    {
        if(n==0&&q==0)
            break;
        tree[1]=1;
        for(int i=2;i<=n;i++)
            scanf("%d",&tree[i]);
        getchar();
        long long ans=0;
        for(int i=1;i<=q;i++)
        {
            int temp;
            char s;    
            scanf("%c %d",&s, &temp);
            if(s=='M')
                tree[temp]=temp;
            else if(s=='Q')
                ans+=Find(temp);
             cin.ignore();    
        }
        cout<<ans<<endl;
    }

    return 0;
}

Measured memory_bytes: 3524
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>

using namespace std;

//conversion
//------------------------------------------
inline long toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline long toLong(string s) {long v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-6;
const long INF = 1e10;
int sum;
int dfs(int maxi,int ss,int cnt){
	if(cnt==0){
		if(ss==0)sum++;
		return 0;
	}
	for(int i=maxi;i>=1;i--){
		if(ss-i>=0)dfs(i-1,ss-i,cnt-1);
	}
	return 0;
}
int main(){
	int n,k,s;
	while(cin>>n>>k>>s){
		if(n==0&&k==0&&s==0)break;
		sum=0;
		dfs(n,s,k);
		cout<<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;

int main()
{
    int n, k;
    std::cin >> n >> k;

    std::vector<int> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }

    long long ans = 0;

    for (int num_dequeue = 0; num_dequeue <= k; num_dequeue++) {
        for (int right_dequeue = 0; right_dequeue <= num_dequeue; right_dequeue++) {
            std::priority_queue<long long, std::vector<long long>, std::greater<long long>> q;
            std::vector<int> copied_a = a;

            for (int i = 0; i < right_dequeue && copied_a.size(); i++) {
                q.push(copied_a.back());
                copied_a.pop_back();
            }

            std::reverse(copied_a.begin(), copied_a.end());
            for (int i = 0; i < num_dequeue - right_dequeue && copied_a.size(); i++) {
                q.push(copied_a.back());
                copied_a.pop_back();
            }

            for (int i = 0; i < k - num_dequeue && q.size() && q.top() < 0; i++) {
                q.pop();
            }

            long long sum_value = 0;
            while (q.size()) {
                sum_value += q.top();
                q.pop();
            }

            ans = std::max(ans, sum_value);
        }
    }

    std::cout << ans << std::endl;
}


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

using namespace std;

#define ll  long long
#define ld  double

#define sz(x)   (int)x.size()
#define all(x)  x.begin(),x.end()

#define pb  emplace_back
#define X   first
#define Y   second

const int   N   = 2e5 + 5;

typedef pair<int,int>   ii;

set<ii> E;

void addEdge(int u,int v)   {   if (u > v)  swap(u,v);  E.insert(ii(u,v));  }
void remEdge(int u,int v)   {   if (u > v)  swap(u,v);  E.erase (ii(u,v));  }

int main()  {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int n;  cin >> n;

    if((n & -n) == n)   {
        cout << "No";
        return  0;
    }
    int s = (n + 1) / 4 * 4;

    for(int i = 0 ; i < s ; i += 4) {
        if (i)  {
            addEdge(i,i + 1);   i += n;
            addEdge(i,i + 1);   i -= n;
        }

        for(int j = 1 ; j < 3 ; ++j)    {
            addEdge(i + j,i + j + 1);   j += n;
            addEdge(i + j,i + j + 1);   j -= n;
        }
        addEdge(i + 3,n + max(i,1));
        addEdge(i + 3 + n,i + 4);
    }
    remEdge(s + n - 1,s);

    if (n == s) {
        int u = n & -n;
        int v = n ^ u;

        assert(u % 4 == 0);
        assert(v % 4 == 0);

        remEdge(u + n - 1,u);

        if (u + 4 < s)  {
            remEdge(u + n + 3,u + 4);
            addEdge(u + n - 1,u + 4);
        }
        addEdge(u,v);
        addEdge(u,n);
        addEdge(v,n + n);
    }
    if (n == s + 1) {
        addEdge(n,1);   addEdge(s + n,1);
        addEdge(s,n);   addEdge(n + n,s + n);
    }
    if (n == s + 2) {
        addEdge(n,1);
        addEdge(n,s + 1);
        addEdge(s,s + 1 + n);
        addEdge(s + 1 + n,2);
        addEdge(s + 1 + n,n + n);
        addEdge(s + n,3);
    }
    cout << "Yes\n";

    for(ii  e : E)
        cout << e.X << " " << e.Y << "\n";
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
   string s;cin >>s;
   bool flg=true;
   if(s[0]!='A')flg=false;
   ll cnt=0;
    for (int i = 2; i <s.size()-1; ++i) {
        if(s[i]=='C')cnt++;
    }
    if(cnt!=1)flg=false;
    for (int i = 1; i < s.size(); ++i) {
        if(s[i]<'a'||s[i]>'z'){
            if(i==s.size()-1||i==1)flg=false;
            if(s[i]!='C')flg=false;
        }
    }
    if(flg)puts("AC");
    else puts("WA");
   return 0;
}

Measured memory_bytes: 256
s = input()[::-1]

sum_of_digits = 0

cnts = [0] * 2019

cnts[0] = 1

d = 1

for c in s:
    sum_of_digits += int(c) * d
    sum_of_digits %= 2019
    d *= 10
    d %= 2019
    cnts[sum_of_digits] += 1

ans = 0
    
for cnt in cnts:
    ans += cnt * (cnt - 1) // 2

print(ans)


Measured memory_bytes: 9364
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
#define inputv(v, n)                                                           \
    vl v;                                                                      \
    rep(i, n) {                                                                \
        ll x;                                                                  \
        cin >> x;                                                              \
        v.push_back(x);                                                        \
    }
bool chmin(ll& a, ll& b) { if (b < a) { a = b; return 1; } return 0; }
bool chmax(ll& a, ll& b) { if (b > a) { a = b; return 1; } return 0; }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
#include <cstdint>                                                                                                              

template <std::uint_fast64_t Modulus> class modint {
	using u64 = std::uint_fast64_t;

public:
	u64 a;

	constexpr modint(const u64 x = 0) noexcept : a(x% Modulus) {}
	constexpr u64& value() noexcept { return a; }
	constexpr const u64& value() const noexcept { return a; }
	constexpr modint operator+(const modint rhs) const noexcept {
		return modint(*this) += rhs;
	}
	constexpr modint operator-(const modint rhs) const noexcept {
		return modint(*this) -= rhs;
	}
	constexpr modint operator*(const modint rhs) const noexcept {
		return modint(*this) *= rhs;
	}
	constexpr modint operator/(const modint rhs) const noexcept {
		return modint(*this) /= rhs;
	}
	constexpr modint& operator+=(const modint rhs) noexcept {
		a += rhs.a;
		if (a >= Modulus) {
			a -= Modulus;
		}
		return *this;
	}
	constexpr modint& operator-=(const modint rhs) noexcept {
		if (a < rhs.a) {
			a += Modulus;
		}
		a -= rhs.a;
		return *this;
	}
	constexpr modint& operator*=(const modint rhs) noexcept {
		a = a * rhs.a % Modulus;
		return *this;
	}
	constexpr modint& operator/=(modint rhs) noexcept {
		u64 exp = Modulus - 2;
		while (exp) {
			if (exp % 2) {
				*this *= rhs;
			}
			rhs *= rhs;
			exp /= 2;
		}
		return *this;
	}
};

using mint = modint<MOD>;
int main(){
    cin >> n;
	vector<PP> vp;
    rep(i, n) {
        cin >> x;
		vp.push_back({ x,1 });
    }

	rep(i, n) {
		cin >> x;
		vp.push_back({ x,-1 });
	}

	sort(all(vp));

	mint ans = 1;
	a=0;
	rep(i, n * 2) {
		if(a*vp[i].second<0)ans*= abs(a);
		a += vp[i].second;
	}

	cout << ans.a << endl;
}


Measured memory_bytes: 6384
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int a[]=new int[N];
		int z=0,y=1;
		while(z<N){
			a[z]=stdIn.nextInt();
			z++;
		}z=0;
		Arrays.sort(a);
		while(z<N-1){
			if(a[z]!=a[z+1])
				y++;
			z++;
		}
		System.out.println(y);
	}
}


Measured memory_bytes: 22740
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

n = int(readline())
data = read().split()
x = 10**9

a = []
for si in data:
    if('.' in si):
        num1,num2 = si.split('.')
        a.append(int(num1)*x + int(num2) * 10**(9- len(num2)))
    else:
        a.append(int(si) * x)

fac_25 = [[0]*19 for _ in range(19)]
for ai in a:
    # print(ai)

    num = 2
    cnt2 = 0
    while(ai%num == 0)&(cnt2<18):
        ai //= num
        cnt2 += 1

    num = 5
    cnt5 = 0
    while(ai%num == 0)&(cnt5<18):
        ai //= num
        cnt5 += 1

    fac_25[cnt2][cnt5] += 1

    # print(cnt2,cnt5)

fac_cs = [[0]*19 for _ in range(19)]
for i in range(18,-1,-1):
    for j in range(18,-1,-1):
        fac_cs[i][j] = fac_25[i][j]
for i in range(18,-1,-1):
    for j in range(17,-1,-1):
        fac_cs[i][j] += fac_cs[i][j+1]

for i in range(17,-1,-1):
    for j in range(18,-1,-1):
        fac_cs[i][j] += fac_cs[i+1][j]

ans = 0
for i in range(18,-1,-1):
    for j in range(18,-1,-1):
        ans += fac_25[i][j] * fac_cs[18-i][18-j]

# print(ans)
ans -= fac_cs[9][9]
# print(ans)
ans //=2
print(ans)

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

using namespace std;
using ll = long long int;
using P = pair<int, int>;

#define loop(i, n) for(int i = 0;i < n;i++)

int main(void){

    string str;
    cin >> str;

    if(str.back()-'0' == 2 || str.back()-'0' == 4 || str.back()-'0' == 5 || str.back()-'0' == 7 || str.back()-'0' ==  9) cout << "hon" << endl;
    else if(str.back()-'0' == 0 || str.back()-'0' == 1 || str.back()-'0' == 6 || str.back()-'0' == 8) cout << "pon" << endl;
    else cout << "bon" << endl;

    return 0;
}


Measured memory_bytes: 3620
from collections import Counter

def read_input():
    
    return n, slist


def submit():
    n = int(input())
    slist = []
    for _ in range(n):
        s = list(input())
        s.sort()
        slist.append("".join(s))
    s_count = Counter(slist)

    pair_count = 0
    for s, c in s_count.items():
        pair_count += c * (c - 1) // 2

    print(pair_count)

    
if __name__ == "__main__":
    submit()



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

using namespace std;

#define int long long

constexpr double EPS = 1e-9;

void solve(int b) {
    int l = (int)((-1+sqrt(1+8*b))/2.0)+2;
    while(1) {
        l--;

        double dx = (2.0*b-l*l-l)/2.0/l;
        int x = (int)(dx+0.5);
        if (EPS < abs(dx-x)) continue;

        cout << x + 1 << " " << l << endl;
        break;
    }
}

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

    while(1) {
        int b;
        cin >> b;
        if (!b) break;

        solve(b);
    }
}



Measured memory_bytes: 3180
#include <stdio.h>

int main(void){
    int n = 0,
        a = 0,
        maximum = -1000000,
        minimum = 1000000;
    long sum = 0;
    
    scanf("%d", &n);
    
    while(scanf("%d", &a) != EOF){
        sum += a;
        if ( a >= maximum ) {
            maximum = a;
        }
        if ( a <= minimum ) {
            minimum = a;
        }
    }
    
    printf("%d %d %ld\n", minimum, maximum, sum);
}

Measured memory_bytes: 1808
#include <iostream>
#include <map>
#include <utility>
#include <vector>
#include <string>
#include <set>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>

typedef long long int ll;
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
using namespace std;
int main(void){
    string s;
    int n;
    while(cin>>s>>n&&(n||s!="0")){
        map<string,int> mp;
        for(int i=1;;i++){
            if(mp[s]==0)mp[s]=i;
            else {
                cout<<mp[s]-1<<" "<<s<<" "<<i-(mp[s])<<endl;
                break;
            }
            while(s.size()<n)s+="0";
            sort(s.begin(),s.end());
            ll mi=stol(s);
            sort(s.rbegin(),s.rend());
            ll ma=stol(s);
            
            ll next=ma-mi;
            s=to_string(next);
        }
    }
    
}



Measured memory_bytes: 3212
#include<bits/stdc++.h>
using namespace std;
int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);cout.tie(NULL);
        int l,r,d;
        cin>>l>>r>>d;
        cout<<(r/d)-ceil(float(l)/d)+1;
return 0;
}
/*

        creation time:  13.09.2020 09:23:27

*/                      



Measured memory_bytes: 3740
#include<bits/stdc++.h>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
typedef long long ll;
typedef unsigned long long ull;
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
inline                                              void out(double p){printf("%.10f\n",p);}
template<class T>inline                             void outs(T p){for_each(all(p),out<decltype(p[0])>);}

inline void solve(void){
  int N;
  string S;
  in(N,S);
  if(N&1)out("No");
  else {
    out(S.substr(0,N/2)==S.substr(N/2,N/2)?"Yes":"No");
  }
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


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

bool comp(pair<int, string> a, pair<int, string> b){
    if(a.first != b.first) return a.first > b.first;
    else return a.second < b.second;
}

int main(){
    long int a,b,x;
    cin >> a >> b >> x;

    long int count = 0;

    cout << (a != 0 ? b/x - (a-1)/x : b/x+1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    int x,y;
    int a1[]={1,3,5,7,8,10,12},a2[]={4,6,9,11};
    cin>>x>>y;
    if(find(a1,a1+7,x)!=a1+7){
        if(find(a1,a1+7,y)!=a1+7){
            cout<<"Yes"<<endl;return 0;
        }
    }
    if(find(a2,a2+4,x)!=a2+4){
        if(find(a2,a2+4,y)!=a2+4){
            cout<<"Yes"<<endl;return 0;
        }
    }
    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);

        final int w = scan.nextInt();
        final int h = scan.nextInt();
        final int n = scan.nextInt();

        int beginX = 0;
        int endX = w;
        int beginY = 0;
        int endY = h;

        for (int i = 0; i < n; i++) {
            int x = scan.nextInt();
            int y = scan.nextInt();
            int a = scan.nextInt();

            switch (a) {
                case 1:
                    if (beginX < x) {
                        beginX = x;
                    }
                    break;
                case 2:
                    if (endX > x) {
                        endX = x;
                    }
                    break;
                case 3:
                    if (beginY < y) {
                        beginY = y;
                    }
                    break;
                case 4:
                    if (endY > y) {
                        endY = y;
                    }
                    break;
            }
        }

        int ans = (endX - beginX > 0 ? endX - beginX : 0) * (endY - beginY > 0 ? endY - beginY : 0);
        System.out.println(ans > 0 ? ans : 0);

    }
}


Measured memory_bytes: 22100
let _ = Scanf.sscanf (read_line ()) "%d %d" (fun a b ->
  match a with
  | a when a = b -> print_endline (string_of_int (a * 2))
  | a when a > b -> print_endline (string_of_int (a + (a-1)))
  | _ -> print_endline (string_of_int (b + (b-1)))
)

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

void solve(long long N, long long i){
    cout << N - i + 1 << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long N;
    scanf("%lld",&N);
    long long i;
    scanf("%lld",&i);
    solve(N, i);
    return 0;
}


Measured memory_bytes: 256
n = gets.to_i
n_ar = []
n.times do
  n_ar << gets.chomp
end

m_ar = []
m = gets.to_i
m.times do
  m_ar << gets.chomp
end

sum_ar = []
n_ar.uniq.each do |v|
  sum_ar << (n_ar.count{|o|o == v} - m_ar.count{|t| t == v})
end

if sum_ar.max <= 0
  puts 0
else
  puts sum_ar.max
end


Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		
		while(scan.hasNext()){
			int a = scan.nextInt();
			int b = scan.nextInt();
			int c = scan.nextInt();
			
			if(a*a == b*b + c*c || b*b == a*a + c*c || c*c == b*b + a*a){
				System.out.println("YES");
			}else{
				System.out.println("NO");
			}
			
		}
	}
}

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

int main(){
    int H, W;
    
    for(;;){
        cin >> H >> W;
        if(H == 0 && W == 0){
            break;
        }
    for(int i = 0; i < H; i++){
        for(int i = 0; i < W; i++){
            cout << "#";
        }
      cout << endl;
    }
    cout << endl;
    }
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ms memset
#define MOD 1000000007
#define MOD2 1000000009
#define sp fixed<<setprecision
#define sz(x) (int)(x).size()
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
ll fpow(ll x,ll y,ll p=MOD){x=x%p;ll sum=1;while(y){if(y&1)sum=sum*x;sum%=p;y=y>>1;x=x*x;x%=p;}return sum;}
ll inv(ll a,ll m=MOD){ll c=m;ll y=0,x=1;if(m==1)return 0;while(a>1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=c;return x;}
ll add(ll a, ll b) {if(a<0)a+=MOD; if(b<0)b+=MOD; return (a%MOD + b%MOD + MOD)%MOD;}
ll sub(ll a, ll b) {if(a<0)a+=MOD; if(b<0)b+=MOD; return (a%MOD - b%MOD + MOD)%MOD;}
ll mul(ll a, ll b) {if(a<0)a+=MOD; if(b<0)b+=MOD; return ((a%MOD)*(b%MOD) + MOD)%MOD;}
void setIO(string name = "") {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (sz(name)) {
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}
int main(){
    setIO();
    ll n;
    cin>>n;
    vector<ll>a(n),b(n);
    map<ll,ll>m;
    bool ok = true;
    for(int i=0;i<n;i++){
      cin>>a[i];
      m[a[i]]++;
      if(m[a[i]]>n)
        ok=false;
    }
    for(int i=0;i<n;i++){
      cin>>b[i];
      m[b[i]]++;
      if(m[b[i]]>n)
        ok=false;
    }
    if(!ok)
    cout<<"No";
    else{
      cout<<"Yes\n";
      reverse(all(b));
      ll l=0,r=n-1;
      for(int i=0;i<n;i++){
        if(a[i]==b[i]){
          if(a[l]!=a[i] && b[l]!=a[i]){
            swap(b[i],b[l]);
            l++;
          }
          else{
            swap(b[i],b[r]);
            r--;
          }
        }
      }
      for(int i=0;i<n;i++)
        cout<<b[i]<<" ";
    }

}


Measured memory_bytes: 18708
from itertools import permutations

N = int(input())
Pn = tuple(map(int, input().split()))
Qn = tuple(map(int, input().split()))

p, q = 0, 0
for i, t in enumerate(permutations(range(1, N+1), N)):
    if t == Pn:
        p = i
    if t == Qn:
        q = i

print(abs(p - q))


Measured memory_bytes: 3060
def solve(string):
    x = int(string)
    for i in range(x, 2 * x):
        for j in range(2, int(i**0.5) + 1):
            if i % j == 0:
                break
        else:
            return str(i)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


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

int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}

int main(){
    int k;
    cin>>k;
    ll int sum=0;
    for(int i=1;i<=k;++i){
        for(int j=1;j<=k;++j){
            for(int l=1;l<=k;++l){
                sum+=gcd(gcd(i,j),l);
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define reps(i,x) for(ll i=1;i<=(int)(x);i++)
#define rrep(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=((int)(x) - 1 * 100);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
using namespace std;
ll n;
int main() {
	cin >> n;
	int res = 10000000000;
	reps(i, sqrt(n)+1) {
		if (n % i == 0) {
			res = min(res, int(max(to_string(i).size(), to_string(n / i).size())));
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256