akhauriyash/Code-Regression huggingface dataset:
/*2019/08/25 */
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define MOD 1000000007
#define MIN 999999999
#define MAX -999999999
typedef long long int ll;
typedef unsigned long long int ull;
void llswap(ll *x,ll *y){ll temp;temp=*x;*x=*y;*y=temp;}
void swap(int *x,int *y){int tmp;tmp=*x;*x=*y;*y=tmp;}
int rmax(int x,int y){return x>y?x:y;}
int rmin(int x,int y){return x>y?y:x;}
ll llrmax(ll x,ll y){return x>y?x:y;}
ll llrmin(ll x,ll y){return x>y?y:x;}
int asc(const void *a,const void *b){return *(int*)a-*(int*)b;}
int desc(const void *a,const void *b){return *(int*)b-*(int*)a;}
int llasc(const void *a,const void *b){return *(ll*)a-*(ll*)b;}
int lldesc(const void *a,const void *b){return *(ll*)b-*(ll*)a;}
/*
int asc_t(const void *a,const void *b){return ((struct_t*)a)->member - ((struct_t*)b)->member;}
int desc_t(const void *a,const void *b){return ((struct_t*)b)->member - ((struct_t*)a)->member;}
*/

int main(){
    ull n;
    scanf("%llu",&n);

    ull sum=0;
    
    sum=(n-1)*(1+n-1)/2;

    printf("%llu\n",sum);

    return 0;
}

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

using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    map<int, ll> M;
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        M[A[i]] += 1;
    }

    ll Sum = 0;
    for (auto d : M) {
        ll n = d.second;
        Sum += n * (n - 1) / 2;
    }
    for(int i = 0; i < N; ++i)
    {
        ll n = M[A[i]];
        cout << Sum - (n - 1) << endl;
    }
}


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

#define fr                first
#define se                second
#define int               long long
#define pb                push_back
#define mp                make_pair
#define pii               pair<int,int>
#define vi                vector<int>
#define mi                map<int,int>
#define pqb               priority_queue<int>
#define set_bits(x)       __builtin_popcountll(x)
#define mod               1000000007
#define inf               1e18                        //Defining infinity the overflow of int
#define ps(x,y)           fixed<<setprecision(y)<<x   //fir defining the precision int the decimal upto y places. 
#define zrosetbits(x)     __builtin_ctzll(x)         //it will give no of 0's before the first 1 from the right.
#define mk(a,n,type)     type *a=new type[n];
#define test(t)            int t; cin>>t; while(t--)


void io()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin.tie(0);


}

int32_t main()
{
	io();
	clock_t begin = clock();

	// test(t)
	// {

	int n;
	cin >> n ;

	int val = 1000;

	while (val < n)
	{
		val += 1000;
	}

	cout << val - n   << "\n";





	// double c_time = (double) (clock() - begin) / CLOCKS_PER_SEC;
	// cout << ps(c_time, 4) << " seconds\n";

	// }
	return 0;
}



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

int main() {
  int h, w, x; cin >> h >> w >> x;
  char a[h][w];
  for(int i = 0; i < h; i++) {
    for(int j = 0; j < w; j++) {
      cin >> a[i][j];
    }
  }
  int ans = 0;
  for(int i = 0; i < (1 << h); i++) {
    for(int j = 0; j < (1 << w); j++) {
      int track = 0;
      for(int k = 0; k < h; k++) {
        for(int l = 0; l < w; l++) {
          if((i & (1 << k)) == 0) continue;
          if((j & (1 << l)) == 0) continue;
          if(a[k][l] == '#') track ++;
        }
      }

      if(track == x) ans++;
    }
  }

  cout << ans << endl;
  return 0;

}


Measured memory_bytes: 3568
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
int main()
{
	int n,l;
	bool x[105]={};
	cin >> n >> l;
	for(int i=0;i<l;i++)
	{
		int a,b;cin >> a >> b;
		
		for(int j=0;j<b;j++)
		{
			x[(a+j)%n]=true;
		}
	}
	map<int,int>ma;
	
	int cur = -1;
	for(int i=0;i<n;i++)
	{
		if(!x[i])
		{
			cur = i; break;
		}
	}
	if(cur == -1)
	{
		cout << n << " " << 1 << endl;
		return 0;
	}
	else
	{
		int f = cur;
		while(1)
		{
			while(!x[cur])
			{
				cur = (cur+1)%n; if(cur == f) goto en;
			}
			int cnt = 0;
			while(x[cur])
			{
				cur = (cur+1)%n; if(cur == f){ma[++cnt]++;goto en;}
				cnt++;
			}
			ma[cnt]++;
			if(cur == f) break;
		}
		en:; vector<P>vec;
		for(map<int,int>::iterator it=ma.begin();it!=ma.end();++it)
		{
			vec.pb(mp(it->fi,it->sc));
		}
		for(int i=vec.size()-1;i>=0;i--)
		{
			cout << vec[i].fi << " " << vec[i].sc << endl;
		}
	}
}


Measured memory_bytes: 1200
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#include <bitset>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i <(int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i,k,n) for (int i = (int)(n)-1; i >= k; i--)
#define inf 100100100
int dp[(1<<15)+1][110];
int main(){
    int n,m;
    while(cin >> n >> m,n){
        int s[20];
        int d[110];

        rep(i,(1<<15)+1)REP(j,1,110) dp[i][j]=inf;
        rep(i,(1<<15)+1) dp[i][0] = 0;
        rep(i,n) cin >> s[i];
        rep(i,m) cin >> d[i];
        sort(d,d+m);
        rep(t,m){
            dp[0][t+1] = dp[0][t]+d[t];
            rep(i,1<<n){
                int sum=0;
                rep(j,n){
                    if(i&(1<<j)) sum += s[j];
                }
                rep(j,n){
                    if(i &(1<<j) ) continue;

                    dp[i|(1<<j)][t+1] =
                     min({
                         dp[i][t]+abs(d[t]-sum),
                         dp[i][t]+abs(d[t]-(s[j]+sum)),
                         dp[i|(1<<j)][t]+abs(d[t]-(s[j]+sum)),
                        dp[i][t+1],
                        dp[i|(1<<j)][t+1]
                    });
                }
            }
        }
        cout << dp[(1<<n)-1][m] << endl;
        // rep(i,4){
        // rep(j,6){
        //     cout << dp[i][j] << " ";
        // }
        // cout << endl;
        // }


    }
    return 0;
}



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

vector<vector<int>> G;
vector<long long> cnt, visited;

void dfs(int i, int prev = -1) {
    if (visited[i]) return;
    visited[i] = 1;
    if (prev != -1) cnt[i] += cnt[prev];
    for (int j : G[i]) dfs(j, i);
}

int main() {
    int N, Q;  cin >> N >> Q;
    G.resize(N);
    for (int i = 0; i < N - 1; ++i) {
        int a, b;  cin >> a >> b;  --a; --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    cnt.resize(N);
    visited.resize(N);
    for (int i = 0; i < Q; ++i) {
        int p, x;  cin >> p >> x;  --p;
        cnt[p] += x;
    }
    dfs(0);
    for (int i = 0; i < N; ++i) cout << cnt[i] << " ";
    cout << endl;
}


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

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

    string S;
    cin  >> S;

    rep(i,0,S.size()){
    	S[i] = 'x';
    }
    cout << S << "\n";


}

Measured memory_bytes: 256
N, M = map(int,input().split())
lr = [tuple(map(int,input().split())) for _ in range(M)]
ls = []
rs = []
for i in range(M):
  ls.append(lr[i][0])
  rs.append(lr[i][1])

print(max(0,min(rs) - max(ls) + 1))

Measured memory_bytes: 18188
# coding: utf-8
# Your code here!

abc_list = list(map(int, input().split()))
# print(abc_list)

abc_list.sort()

# print(abc_list)

a, b, c = abc_list

# print(a)
# print(b)
# print(c)

result = ((a + b) == c )
if result:
    print('Yes')
else:
    print('No')

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

typedef long long ll;
typedef pair<ll, ll> P;

const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const int int_inf = 100000000;
const double eps = 1e-9;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

    ll now = 100, cnt = 0;
    while (now < x) {
        cnt++;
        now *= 1.01;
    }
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 3648
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::collections::HashSet;

fn main() {
    input! {
        n: usize,
        a: [u32;n]
    }
    let tbl = [
        (3200, 0),
        (2800, 1),
        (2400, 2),
        (2000, 3),
        (1600, 4),
        (1200, 5),
        ( 800, 6),
        ( 400, 7),
        (   1, 8),
    ];
    let s: HashSet<u32> = a.iter().map(|&x|{
        tbl.iter().find(|&t| t.0 <= x).unwrap().1
    }).filter(|&x| x != 0).collect();
    let r = a.iter().filter(|&&x| 3200 <= x).count();
    println!("{} {}", std::cmp::max(s.len(),1), s.len()+r);
}

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

int main() {
  int N, X;
  cin >> N >> X;
  vector<int> L_distance(N+1);
  for (int i=0 ; i< N+1 ; i++){
    if (i == 0){
      L_distance.at(i) = 0;
      continue;
    }
    cin >> L_distance.at(i);
  }
  
  int distance = 0;
  int count = 0;
  for (int i=0 ; i<N+1 ; i++){
    if (i == 0){
      distance = 0;
      continue;
    }
    if (X == distance){
      cout << i << endl;
      break;
    }
    if (X < distance){
      cout << i-1 << endl;
      break;
    }
    if (i == N && X > distance ){
      cout << N + 1 << endl;
    }
    
    distance = distance + L_distance.at(i);
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <utility>

using namespace std;

int main(void){
	int n, C;

	cin >> n >> C;

	int k = 2*100000;
	vector<int> a(k + 1, 0);
	vector< vector< pair<int, int> > > s1(C+1, vector< pair<int, int> >(0));

	int s, t, c;

	for (int i = 0; i < n; i++){
		cin >> s >> t >> c;
		s1[c].push_back(pair<int, int>(2*s - 1, 2*t));
	}

	for (int i = 0; i < C; i++){
		sort(s1[i+1].begin(), s1[i+1].end());
	}

	for (int i = 1; i < C+1; i++){
		for (int j = 0; j < s1[i].size(); j++){
			if (j == s1[i].size()-1){
				a[s1[i][j].first]++;
				a[s1[i][j].second]--;
			}
			else {
				if (s1[i][j].second > s1[i][j+1].first){
					a[s1[i][j].first]++;
					a[s1[i][j+1].second]--;
					j++;
					while (j < s1[i].size() - 1 && s1[i][j].second > s1[i][j+1].first){
						a[s1[i][j].second]++;
						a[s1[i][j+1].second]--;
						j++;
					}
				}
				else {
					a[s1[i][j].first]++;
					a[s1[i][j].second]--;
				}
			}
		}
	}

	int M = 0;
	for (int i = 1; i < k + 1; i++){
		a[i] += a[i-1];
		M = max(M, a[i]);
	}

	cout << M << endl;

	return 0;
}

Measured memory_bytes: 2304
def monthable(str)
    num = str.to_i
    num >= 1 && num <= 12 ? 'y' : 'n'
end

s = gets.chomp
head = s[0,2]
tail = s[2,2]

puts({
    'yy' => 'AMBIGUOUS',
    'yn' => 'MMYY',
    'ny' => 'YYMM',
    'nn' => 'NA',
}[monthable(head) + monthable(tail)])


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

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

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

vector<vector<ll>> matrix_time(vector<vector<ll>> A,vector<vector<ll>> B,ll mo){
  int m = A.size(),n=B[0].size(),l = A[0].size();
  vector<vector<ll>> ans(m,vector<ll>(n,0LL));
  for(int i = 0;i<m;i++){
    for(int j = 0; j < n; j++){
      for(int k = 0; k < l; k++){
        ans[i][j]=(ans[i][j]+A[i][k]*B[k][j])%mo;
      }
    }
  }
  return ans;
}

vector<vector<ll>> matrix_pow(vector<vector<ll>> g, ll n, ll m) {
  int l = g.size();
  vector<vector<ll>> ret(l,vector<ll>(l,0LL));
  for(int i = 0; i < l; i++) ret[i][i]=1LL;
  for (; n > 0LL; n >>= 1LL, g = matrix_time(g,g,m)) {
	if (n % 2LL == 1LL) {
	  ret = matrix_time(ret,g,m);
	}
  }
  return ret;
}

int main() {
  ll N, K;
  cin>>N>>K;
  vector<vector<ll>> ans(N,vector<ll>(N));
  for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) cin>>ans[i][j];
  ans = matrix_pow(ans,K,mod);
  ll t = 0;
  for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) t=(t+ans[i][j])%mod;
  cout<<t<<endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */
bool solve(void){
    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    --a;
    --b;
    --c;
    --d;
 
    string s;
    cin >> s;
 
    forr(i, a, c){
        if(s[i] == '#' && s[i + 1] == '#'){
            return false;
        }
    }
    forr(i, b, d){
        if(s[i] == '#' && s[i + 1] == '#'){
            return false;
        }
    }
 
    if(c < d){
        return true;
    }
 
    forr(i, b, d + 1){
        if(s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.'){
            return true;
        }
    }
 
    return false;
}
 
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    if(solve()){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
 
    return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll<<(x))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	string s, t;
	cin >> s >> t;
	int flag = 0;
	int len = s.size();
	int len1 = t.size();
	if(len == len1 - 1){
		rep(i, 0, len){
			if(s[i] != t[i]) {
				cout << "No" <<endl;
				return 0;
			}
		}
		cout<<"Yes" <<endl;
		return 0;
	}
	cout << "No" <<endl;
	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>  // clang-format off
using namespace std;
using Int = long long;
#define REP2(i, n) for (Int i = 0, max_i = (n); i < max_i; i++)
#define REP3(i, a, b) for (Int i = (a), max_i = (b); i < max_i; i++)
#define OVERLOAD2(_1, _2, _3, name, ...) name
#define REP(...) OVERLOAD2(__VA_ARGS__, REP3, REP2)(__VA_ARGS__)
struct in {
    int n; in() {} in(int n_) : n(n_){}
    template <class T> operator T() { T ret; cin >> ret; return ret; }
    template <class T> operator vector<T>() { vector<T> ret(n); for (int i = 0; i < n; i++) cin >> ret[i]; return ret; }
};
struct SetupIO { SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sat Jan 18 21:00:13 JST 2020
 **/

signed main() {
    int n = in(), m = in();
    vector<Int> D = in(n);
    struct Edge {
        Int to, idx;
    };
    vector<vector<Edge>> g(n);
    for (int i = 0; i < m; i++) {
        int u = in(), v = in();
        u--, v--;
        g[u].push_back({v, i});
        g[v].push_back({u, i});
    }
    vector<Int> ord(n);
    REP(i, n) ord[i] = i;
    sort(ord.begin(), ord.end(), [&D](Int i, Int j) { return D[i] < D[j]; });
    vector<Int> ans(m, 1e9), color(n, -1);
    REP(k, n) {
        Int i = ord[k];
        bool ok = false;
        if (color[i] != -1) continue;
        for (Edge& e : g[i]) {
            if (D[e.to] <= D[i]) {
                if (color[e.to] == -1) {
                    color[e.to] = 0, color[i] = 1;
                    assert(D[e.to] == D[i]);
                } else {
                    color[i] = !color[e.to];
                }
                ans[e.idx] = D[i];
                ok = true;
                break;
            }
        }
        if (!ok) {
            cout << -1 << endl;
            return 0;
        }
    }
    for (Int x : color) {
        assert(0 <= x && x <= 1);
        cout << (x ? 'B' : 'W');
    }
    cout << endl;
    for (Int x : ans) cout << x << endl;
}


Measured memory_bytes: 18304
#include <iostream>
#include <stdio.h>
#include <string>
#include <cmath>
using namespace std;

 int kaibun(string T) {
    int a=0,t = T.size()/2;
    for (int i = 0; i < t; ++i) {
        if (T[i] == T[T.size() - i - 1]) a+=1;
    }
    if (a == t) return 0;
    else return 1;
}
int main() {
    string S, U, V;
    cin >> S;
    int N = S.size() / 2;
    for (int i = 0; i < N; ++i) {
        U += S[i];
        V+= S[N + 1 + i];
    }
    if (kaibun(S) == 0 && kaibun(U) == 0 && kaibun(V) == 0) cout << "Yes" << endl;
    else cout << "No" << endl;

    

    
}

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

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

int main() {
	// freopen("in.txt","r",stdin);
	int n,m,k;
	cin >> n >> m >> k;
	for (int a = 0; a <= n; ++a)
		for (int b = 0; b <= m; ++b)
			if (a*m + b*n - 2*a*b == k) {
				cout << "Yes" << endl;
				return 0;
			}
	cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(int i = (a); i<(b); ++i)
#define rep(i, n) for (int i=0; i<(n); ++i)
#define out(x) cout << x << endl

int main() {
    int N,R;
    cin >> N >> R;
    if (N < 10){
        out(R + (100*(10-N)));
    } else{
        out(R);
    }
}


Measured memory_bytes: 256
//good luck
# include <iostream>
# include <cstdio>
# include <cmath>
# include <cstdlib>
# include <cstring>
# include <string>
# include <algorithm>
# include <vector>
# include <queue>
# include <ctime>
# include <map>

#define LL long long
#define maxn (int)4e5+5
#define inf  (int)2147483640
#define is(a) (a>='0'&&a<='9')
#define iabs(a) ((a)>0?(a):(-a))
#define imax(a,b) ((a)>(b)?(a):(b))
#define imin(a,b) ((a)<(b)?(a):(b))
 
using namespace std;

LL a[maxn],b[maxn],p,q;
LL f[maxn][30],k,ans;

void reada()
{
	char ch = getchar();
	if (!(ch >= 'a' && ch <= 'z')) ch = getchar();
	while (ch >= 'a' && ch <= 'z') a[++p] = ch - 'a' + 1 , ch = getchar();
}

void readb()
{
	char ch = getchar();
	if (!(ch >= 'a' && ch <= 'z')) ch = getchar();
	while (ch >= 'a' && ch <= 'z') b[++q] = ch - 'a' + 1 , ch = getchar();
}

int main()
{
	reada(); readb();
	for (int i = 1; i <= p; ++i) a[i+p] = a[i];
	for (int i = p*2-1; i >= 1; --i)
	{
		for (int j = 1; j <= 26; ++j)	f[i][j]=f[i+1][j];
		f[i][a[i+1]] = i+1;
	}
	k = p;
	for (int i = 1; i <= q; ++i)
	{
		LL cache = f[k][b[i]];
		if (cache == 0) {cout << -1;return 0;}
		else {ans += cache - k;k = (cache > p)?cache - p:cache;}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 53632
#include <stdio.h>

int main(void) {
	
	int i, n, s, f, count = 0;
	int a[100];
	
	scanf("%d", &n);
	for( i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}
	
	f = 1;
	while(f){
		f = 0;
			for( i = n-1; i > 0; i--){
				if( a[i] < a[i-1]){
					s = a[i];
					a[i] = a[i-1];
					a[i-1]= s;
					f = 1;
					count = count + 1;
				}
			}
	}
	
	for(i = 0; i < n-1; i++){
		printf("%d ", a[i]);
	}
		printf("%d\n",a[n-1]);
		printf("%d\n", count);
		
	return 0;
	
}

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

#define sz(x) (int)x.size()
#define ld long double
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second

using namespace std;

int n;
vector<int> num(3, 0), res;
vector<vector<int>> op;
void add(int a, int b){
    num[a]++;
    num[b]--;
    res.pb(a);
}
bool check(){
    return (num[0] >= 0 && num[1] >= 0 && num[2] >= 0);
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> num[0] >> num[1] >> num[2];
    op.assign(n, vector<int>());
    for(int i = 0; i < n; ++i){
        string s; 
        cin >> s;
        op[i].pb(s[0] - 'A');
        op[i].pb(s[1] - 'A');
    }
    if(!num[op[0][0]] && !num[op[0][1]]){
        cout << "No";
        return 0;
    }
    for(int i = 0; i < n - 1; ++i){
        vector<int> cur(3, 0);
        cur[op[i][0]]++;
        cur[op[i][1]]++;
        cur[op[i + 1][0]]++;
        cur[op[i + 1][1]]++;
        if(cur[op[i][0]] > cur[op[i][1]]){
            if(num[op[i][1]]) add(op[i][0], op[i][1]);
            else add(op[i][1], op[i][0]);
        }
        else{
            if(num[op[i][0]]) add(op[i][1], op[i][0]);
            else add(op[i][0], op[i][1]);
        }
        if(!check()){
            cout << "No";
            return 0;
        }
    }
    int i  = n - 1;
    if(num[op[i][1]]) add(op[i][0], op[i][1]);
    else add(op[i][1], op[i][0]);
    if(!check()){
        cout << "No";
        return 0;
    }
    cout << "Yes\n";
    for(auto j : res){
        cout << (char)(j + 'A') << "\n";
    }
    return 0;
}

Measured memory_bytes: 9336
#include<stdio.h>
#include<string.h>

int main(){
	char *seikai="CODEFESTIVAL2016";
	char in[256];
	int i,j=strlen(seikai);
	int diff=0;
	
	scanf("%s",in);
	
	for(i=0;i<j;i++){
		if(seikai[i]!=in[i]){
			diff++;
		}
	}
	printf("%d\n",diff);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
//long long
using ll = long long;
 
// pair<int, int>
using PII = pair<int, int>;
 
//最大値、mod
const int MOD = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;
 
//出力系
#define print(x) cout << x << endl
#define prints(x) cout << fixed << setprecision(10) << x << endl
#define printc(x) cout << setw(2) << setfill('0') << x << endl;
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()
 
//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
 
//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
 
// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}
 
// a = max(a, b), a = min(a, b)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
// 階乗(MODをとる)
ll pow_mod(ll num, ll pow, ll mod) {
    ll prod = 1;
    num %= mod;
    while (pow > 0) {
        if (pow & 1) prod = prod * num % mod;
        num = num * num % mod;
        pow >>= 1;
    }
    return prod;
}
 
 
 
// 二項係数(MODとる、1 ≦ k ≦ n ≦ 10^7 程度)
// COMinit()
// COM(x, y)
// とコンビで使う
 
// テーブルを作る前処理
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

int main(){
  ll N;
  cin >> N;
  vector<ll>a(N);
  map<ll, ll>mp;
  REP(i, N) {
    cin >> a[i];
    mp[a[i]]++;
  }
  
  ll sum = 0;
  for(auto x : mp){
    REP(i, x.second) sum += i;
  }

  REP(i, N){
    ll ans = max((ll)0, sum - (mp[a[i]] - 1));
    print(ans);
  }
return 0;

}


Measured memory_bytes: 11008
import sys, math
from collections import defaultdict, deque, Counter
# from bisect import bisect_left, bisect_right
# from itertools import combinations, permutations, product
# from heapq import heappush, heappop
# from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

N = ri()
to = defaultdict(list)
V = 100005
X = []
for i in range(N):
	x, y = rl()
	X.append(x)
	y += V
	to[x].append(y)
	to[y].append(x)

ans = 0
visited = {}
for x in X:
	if x in visited: continue
	nx, ny = 0, 0
	queue = deque()
	queue.append(x)
	visited[x] = 1
	while queue:
		n = queue.pop()
		if n < V:
			nx += 1
		else:
			ny += 1
		for m in to[n]:
			if m in visited:
				continue
			visited[m] = 1
			queue.append(m)
	ans += nx*ny
print(ans-N)



Measured memory_bytes: 110380
n,x=[int(i) for i in input().split()]
a=[0]+[int(i) for i in input().split()]
ans=0
for i in range(n):
    if a[i]+a[i+1]>x:
        ans+=a[i]+a[i+1]-x
        a[i+1]-=a[i]+a[i+1]-x
print(ans)

Measured memory_bytes: 63984
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		solver.readS(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
		// solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
	}

	public void readS(String str) {
		int r = 0;
		int b = 0;
		for (int i = 0; i < N; i++) {
			if (str.charAt(i) == 'R')
				r++;
			else
				b++;
		}
		if (r > b)
			System.out.println("Yes");
		else
			System.out.println("No");
	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}

	public void solve() {

	}
}


Measured memory_bytes: 22484
#include <iostream>

using namespace std;
const int MAXN = 110;
int n;
int h[MAXN];

void solve() {
  bool didSubtract = true;
  int cnt = 0;
  while (didSubtract) {
    didSubtract = false;
    int left = 0;
    while (h[left] == 0 && left < n) {
      left++;
    }
    int right = left;
    int minValue = h[left];
    while(h[right] != 0) {
      minValue = min(minValue, h[right]);
      right++;
    }
    for (int i=left;i<right;i++) {
      h[i] -= minValue;
    }
    cnt += minValue;
    didSubtract = minValue > 0;
  }
  cout << cnt << endl;
}

int main() {
  cin >> n;
  for (int i=0;i<n;i++) {
    cin >> h[i];
  }
  solve();
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

class Program
{
    public static void Main()
    {
        char[] line = Console.ReadLine().ToCharArray();
        char[] target = Console.ReadLine().ToCharArray();
        List<int> startPoint =new List<int>();

        for(int i=0; i<line.Length;i++)
        {
            if (target[0] == line[i]) startPoint.Add(i);
        }

        bool no = false;
        if (startPoint.Count == 0) no = true;
        for(int j=0;j<startPoint.Count;j++)
        {
            int match = 0;
            for (int k=0;k<target.Length;k++)
            {
                if (line[startPoint[j]] == target[k]) match++;
                startPoint[j]++;
                if (startPoint[j] == line.Length) startPoint[j] = 0;
            }
            if(match==target.Length)
            {
                Console.WriteLine("Yes");
                no = false;
                break;
            }else
            {
                no = true;
            }
        }
        if(no) Console.WriteLine("No");
    }
}


Measured memory_bytes: 17840
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef long long ll;

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

int main(){
	ios::sync_with_stdio(false);

	string str1, str2, str3;

	str2="Hoshino";
	str3="Hoshina";

	int n;
	cin>>n;
	cin.ignore();

	while(n--){

		getline(cin, str1);

		string::size_type pos = str1.find(str2);

		while(pos!=string::npos){
			str1.replace(pos, str2.size(), str3);
			pos=str1.find(str2, pos+str3.size());
		}

		cout<<str1<<endl;
	}

}

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

int main() {

    int n, l;

    scanf("%d %d", &n, &l);

    int arr[n];

    int mysum = 0;
    int mindata = 300;
    for (int i = 0; i < n; i++) {

        arr[i] = i + l;
        mysum += arr[i];

    }

    int temp = mindata;

    for (int j = 0; j < n; j++) {

        if (abs(0 - arr[j]) < temp) {
            temp = abs(0 - arr[j]);
            mindata = arr[j];
        }
    }

    printf("%d", mysum-mindata);

    return 0;

}

Measured memory_bytes: 1724
#include <bits/stdc++.h>
#define eps 1e-3
#define pi acos(-1.0)
#define inf 0x3f
#define INF 0x3f3f3f3f
#define pb push_back
#define debug1 cout<<"&&";
#define debug2 cout<<"**";
#define ms(a, x) memset(a, x, sizeof(a))
#define for0(i, n) for(int i = 0; i < n; ++i)
#define for1(i, n) for(int i = 1; i <= n; ++i)
using namespace std;
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, int> pli;
typedef pair<long long, long long> pll;
const int mod = 1e9 + 7;
const int N = 2e5+10;
const int M = 1e6+10;
/*=================================================================================*/

char chr;
bool pd;

int main() {
   pd = 0;
   for1(i, 3) {
      cin >> chr;
      if(chr=='7') pd = 1;
   }
   pd ? puts("Yes") : puts("No");
}

Measured memory_bytes: 3604
function Main(input){
	input = input.split(" ");
  input = input.map(a=>~~a).sort().reverse();
  return input[0] * 10 + input[1] + input[2];
}

// If you are interested in the algorithms I used, 
// there is no need to read down from this line.

((b,c,d)=>"undefined"!=typeof require?console.log(Main(require("fs").readFileSync("/dev/stdin","utf8"))):[b=b.split("\n").slice(1,-1).join("\n"),c=function(){try{return Main(b)}catch(f){return f.stack||f.message}}(),d=typeof c,"string"==d||(c=JSON.stringify(c)),$("<form>").append([[10,b],0,[1,d],0,[10,c]].map(f=>$(f?"<textarea>":"<br>",f&&{rows:f[0],cols:40,text:f[1]}))).appendTo("body")])(`
5 2 1
`);

Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int a;
	cin>>a;
	double b=a/3.0;
	cout<<fixed<<setprecision(12)<<b*b*b<<"\n";
	return 0;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    char c;
    cin >> c;

    if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o'){
        cout << "vowel" << endl;
    }
    else{
        cout << "consonant" << endl;
    }
    return 0;
}

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

using namespace std;

vector<int> djset, szset;

int root(int x)
{
    int v = djset[x];
    while (v != djset[v]) v = djset[v];
    djset[x] = v;
    return v;
}

int main(void)
{
    int v[2];
    int N, Q;
    int C, X[2];
    cin >> N >> Q;
    djset.resize(N);
    szset.resize(N, 1);
    for (int i = 0; i < N; i++) djset[i] = i;
    while(Q)
    {
        cin >> C >> X[0] >> X[1];
        if (C)
        {
            for (int i = 0; i < 2; i++) v[i] = root(X[i]);
            cout << (int)(v[0] == v[1]) << endl;
        }
        else
        {
            for (int i = 0; i < 2; i++) v[i] = root(X[i]);
            if (szset[v[1]] > szset[v[0]]) swap(v[0], v[1]);
            djset[v[1]] = v[0];
            szset[v[0]] += szset[v[1]];
            szset[v[1]] = 0;
        }
        Q--;
    }
    return 0;
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(0), cin.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 1e5 + 5;
const int inf = ~0u >> 1;
typedef pair<int, int> P;
#define REP(i, a, n) for (int i = a; i < (n); ++i)
#define PER(i, a, n) for (int i = (n)-1; i >= a; --i)
const ll mod = 1e9 + 7;
int main() {
    IO;
    ll d, s, t;
    cin >> d  >> s >> t;
    if (s * t >= d) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}



Measured memory_bytes: 3564
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<queue>
#include<deque>
#include<string>
#include<utility>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<set>
#include<map>
#include<bitset>
#include<stack>
#include<ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<pli> vpli;

inline ll read(){
    ll Hashimoto=0;
	bool Kanna=1;
    char I_Love=getchar();
    while(I_Love<'0'||I_Love>'9'){
        if(I_Love=='-')Kanna=0;
        I_Love=getchar();
    }
    while(I_Love>='0'&&I_Love<='9'){
        Hashimoto=Hashimoto*10+I_Love-'0';
        I_Love=getchar();
    }
    return (Kanna?Hashimoto:-Hashimoto);
}
template<typename T1,typename T2> inline void Umax(T1 &a,T2 b){
	if(a<b)a=b;
}
template<typename T1,typename T2> inline void Umin(T1 &a,T2 b){
	if(a>b)a=b;
}

#define I_Love_Hashimoto_Kanna main
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define filein(s) freopen(s,"r",stdin);
#define fileout(s) freopen(s,"w",stdout);
#define file freopen("I_Love_Hashimoto_Kanna.out","w",stdout);
#define RE cout<<"I_Love_Hashimoto_Kanna"<<endl;
#define Tone(Kanna) cout<<Kanna<<endl;
#define Tall(Hashimoto,Kanna) for(int I_Love=0;I_Love<(Kanna);++I_Love)cout<<Hashimoto[I_Love]<<(I_Love==(Kanna)-1?"\n":" ");
#define FOR(I_Love,Hashimoto,Kanna) for(int I_Love=Hashimoto;I_Love<(Kanna);++I_Love)
#define MP(Hashimoto,Kanna) make_pair(Hashimoto,Kanna)
#define REV(Kanna) reverse(Kanna.begin(),Kanna.end());
#define SORT(Kanna) sort(Kanna.begin(),Kanna.end());
#define UNIQUE(Kanna) Kanna.erase(unique(Kanna.begin(),Kanna.end()),Kanna.end());
#define inf (1000000000)
#define linf (1000000000000000000ll)
#define mod (1000000007)

int a,b,c;

int I_Love_Hashimoto_Kanna() {
	//完全想清楚了再开始写。
	//写不顺、不知道怎么写、很乱的时候，停下来好好想想。
	//做得慢总比做不出好。
	fastio;
	cin>>a>>b>>c;
	cout<<max(0,c-(a-b))<<endl;
	
	
	return 0;
}


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

int main(){
	int day, a[4], ans=-1;

	scanf(" %d", &day);
	for(int i=0; i<4; ++i) scanf(" %d", &a[i]);
	
	for(int i=0; i<2; ++i){
		int p=a[i]/a[i+2];
		if(a[i]%a[i+2]==0){
			if(ans<p) ans=p;
		}
		else {
			if(ans<p) ans=p+1;
		}
		//printf("%d\n", ans);
	}
	printf("%d\n", day-ans);

	return 0;
}

Measured memory_bytes: 1188
n = int(input())
list_c = [9 ** i for i in range(6)]
list_c += [6 ** i for i in range(1, 7)]
list_c.sort()

dp = [float('inf')] * (n + 1)
dp[0] = 0
for i in range(n):
    for c in list_c:
        if i + c <= n:
            dp[i + c] = min(dp[i + c], dp[i] + 1)

print(dp[-1])

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

const int maxn = 305;
int f[maxn][maxn][maxn], g[maxn][maxn], n, K, ans;
char s[maxn];

int main() {
	scanf("%s%d", s + 1, &K);
	n = strlen(s + 1);
	for (int l=n; l>=1; l--) {
		f[l][l][0] = 1;
		for (int r=l+1; r<=n; r++) 
			for (int k=0; k<=K; k++) {
				f[l][r][k] = max(f[l+1][r][k], f[l][r-1][k]);
				if (s[l] == s[r]) f[l][r][k] = max(f[l][r][k], f[l+1][r-1][k] + 2);
				else if (k) f[l][r][k] = max(f[l][r][k], f[l+1][r-1][k-1] + 2);
			}
	}
	for (int k=0; k<=K; k++) ans = max(ans, f[1][n][k]);
	printf("%d", ans);
	return 0;
}

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

int main(){
    int n, m, l;
    cin >> n >> m >> l;
    long int A[n][m], B[m][l], C[n][l];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> A[i][j];
        }
    }
    for(int i = 0; i < m; i++){
        for(int j = 0; j < l; j++){
            cin >> B[i][j];
        }
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < l; j++){
            C[i][j] = 0;
        }
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < l; j++){
            for(int k = 0; k < m; k++){
                C[i][j] += A[i][k] * B[k][j];
            }
        }
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < l; j++){
            cout << C[i][j];
            if(j != l - 1){
                cout << " ";
            }
            if(j == l - 1){
                cout << endl;
            }
        }
    }
}


Measured memory_bytes: 3320
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    cin>>s;
    int flag=0,count=0,ans=0;
    for (int i=0;i<s.size();i++) {
        if (flag==0) {
            if (s[i]=='R') {
                flag=1;
                count++;
            }
        } else {
            if (s[i]=='R') {
                count++;
            } else {
                flag=0;
                ans=max(ans,count);
                count=0;
            }
        }
    }
    ans=max(ans,count);
    cout<<ans<<endl;
}


Measured memory_bytes: 3576
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Arrays;
import java.util.Collections;
import java.lang.*;
import java.io.*;

public class Main {
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        //ArrayList<Integer> list;
        int n = sc.nextInt();
        int l = sc.nextInt();
        List<String> list = new ArrayList<>();

        for(int i = 0; i < n; i++){
            list.add(sc.next());
        }
        Collections.sort(list);
        //System.out.println(list);
        System.out.println(String.join("", list));

	}
}

Measured memory_bytes: 23636
s=input()
ans=''
if 0<int(s[:2])<=12 and 0<int(s[2:])<=12:
  ans='AMBIGUOUS'
elif 0<int(s[2:])<=12:
  if int(s[:2])>12 or int(s[:2])==0:
    ans='YYMM'
elif 0<int(s[:2])<=12:
  if int(s[2:])>12 or int(s[2:])==0:
    ans='MMYY'
else:
  ans='NA'
print(ans)

Measured memory_bytes: 3064
S = input()

R=''.join(list(reversed(S)))
#print(R)
N=len(S)

cursol=0

while True:
    if R[cursol:cursol+5] == 'maerd':
        cursol += 5
    elif R[cursol:cursol+5] == 'esare':
        cursol += 5
    elif R[cursol:cursol+7] == 'remaerd':
        cursol += 7
    elif R[cursol:cursol+6] == 'resare':
        cursol += 6
    else:
        print('NO')
        break
    if cursol == N:
        print('YES')
        break


Measured memory_bytes: 44272
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#define llint long long
#define mod 1000000007

using namespace std;
typedef pair<llint, llint> P;

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

llint n;
vector<llint> G[200005];
vector<llint> vec[200005];
llint inv2;

llint dfs(llint v)
{
	llint ret = v;
	vector<P> tmp;
	for(int i = 0; i < G[v].size(); i++){
		llint res = dfs(G[v][i]);
		tmp.push_back(make_pair((llint)vec[res].size(), res));
	}
	sort(tmp.rbegin(), tmp.rend());
	
	if(tmp.size() > 0){
		ret = tmp[0].second;
		
		if(tmp.size() > 1){
			llint pos = (llint)tmp.size()-1;
			for(int i = 1; i <= vec[tmp[1].second].size(); i++){
				llint sum = 0, mul = 1;
				for(int j = pos; j >= 0; j--){
					vector<llint> &cvec = vec[tmp[j].second];
					if(cvec.size() < i){
						pos--;
						continue;
					}
					llint p = cvec[(llint)cvec.size()-i];
					mul *= (1-p+mod) % mod, mul %= mod;
					sum += p * modpow((1-p+mod) % mod, mod-2) % mod, sum %= mod;
				}
				vec[ret][(llint)vec[ret].size()-i] = sum * mul % mod;
			}
		}
	}
	
	vec[ret].push_back(inv2);
	return ret;
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	inv2 = modpow(2, mod-2);
	
	cin >> n;
	llint p;
	for(int i = 1; i <= n; i++){
		cin >> p;
		G[p].push_back(i);
	}
	
	llint res = dfs(0);
	
	llint ans = 0;
	for(int i = 0; i < vec[res].size(); i++) ans += vec[res][i], ans %= mod;
	ans *= modpow(2, n+1), ans %= mod;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 49272
N, K = map(int, input().split())
ans = [0 for _ in range(K+10)]

MOD = 10**9+7

ts = 0
for i in range(K, 1, -1):
    t = K//i
    ans[i] = (pow(t, N, MOD)+MOD) % MOD
    for j in range(2*i, K+1, i):
        ans[i] -= ans[j]
    ans[i] %= MOD
    ts += ans[i]
ans[1] = (pow(K, N, MOD)-ts+MOD) % MOD

print(sum([i * ans[i] for i in range(K+10)])%MOD)

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

using namespace std;

typedef long long ll;

const int N = 1e5;
const int INF = 1e9;

int dp[N + 1];

int main() {
    int n, k;
    cin >> n >> k;
    int h[n];
    for (int& x : h)
        cin >> x;
    fill(dp, dp + N + 1, INF);
    dp[0] = 0;
    for (int i = 1; i < n; i++)
        for(int j = i - k; j < i; j++)
            if (j >= 0)
                dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
    cout << dp[n - 1];
}



Measured memory_bytes: 1024
// C - Walk on Multiplication Table
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	ll N; cin>>N;
	ll ans = LLONG_MAX;
	ll n = sqrt(N);
	rp(a, 1, n+1){
		if(N%a) continue;
		ll b = N/a, s;
		if(a == 1) s = (b-1);
		else if(b == 1) s = (a-1);
		else s = (a-1) + (b-1);
		ans = min(ans, s);
	}
	cout<< ans <<endl;
}

Measured memory_bytes: 256
let n, d = Scanf.scanf " %d %d" @@ fun a b -> a, b
let xss = Array.init n @@ fun _ -> Array.init d @@ fun _ -> Scanf.scanf " %d" (+) 0
let g x = x * x
let f ys zs = Array.fold_left (+) 0 @@ Array.init d @@ fun i -> g @@ ys.(i) - zs.(i)
let ans = ref 0
let _ =
  for i = 0 to n - 1 do
    for j = i + 1 to n - 1 do
      let x = ref 0 in
      let b = f xss.(i) xss.(j) in
      while !x * !x < b do incr x done;
      if !x * !x = b then incr ans done done;
  Printf.printf "%d\n" !ans

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

using namespace std;

const int max_n = 10011, inf = 1000111222;

int n, sum, ans[max_n], a[max_n], sz[max_n];
priority_queue<pair<int, int>> q;
vector<int> g[max_n];

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    scanf("%d", &n);
    for (int i = 1; i < n; ++i) {
        int u, v;
        scanf("%d%d", &u, &v);
        --u;
        --v;
        ++sz[u];
        ++sz[v];
        g[u].push_back(v);
        g[v].push_back(u);
    }
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
        q.push({-sz[i], i});
    }
    sort(a, a + n);
    int cur = 0;
    while (!q.empty()) {
        pair<int, int> p = q.top();
        q.pop();
        int v = p.second;
        if (sz[v] != -p.first) {
            continue;
        }
        ans[v] = a[cur++];
        sum += sz[v] * ans[v];
        sz[v] = 0;
        for (int to : g[v]) {
            if (sz[to]) {
                --sz[to];
                q.push({-sz[to], to});
            }
        }
    }
    printf("%d\n", sum);
    for (int i = 0; i < n; ++i) {
        printf("%d ", ans[i]);
    }
    puts("");
    return 0;
}


Measured memory_bytes: 1152
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#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 <ctime>
#include <cstring>

using namespace std;

#define MAX 100000
#define INF 2140000000
#define MOD 1000000007

long long gcd(long long a, long long b){ 
	return a == 0? b : gcd(b % a, a);
} 

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

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

	long long divc = b / c - (a - 1) / c;
	long long divd = b / d - (a - 1) / d;
	long long divcd = b / lcm(c, d) - (a - 1) / lcm(c, d);

	cout << b - (a - 1) - (divc + divd - divcd) << endl;
	return 0;
}

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

bool isEnd( vector<int> vec ){
	int finish[30] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 4, 4, 4, 6, 6, 6, 5, 5, 5, 3, 3, 3, 3, 3, 3, 3, 3, 3};
	for( int i = 0; i < 30; i++ )
		if( vec[i] != finish[i] )
			return false;
	return true;
}
vector<int> rot( vector<int> vec, int type ){
	switch(type){
	case 0:
		swap(vec[0], vec[23]);
		swap(vec[3], vec[26]);
		swap(vec[6], vec[29]);
		swap(vec[15], vec[17]);
		swap(vec[9], vec[20]);
		break;
	case 1:
		swap(vec[2], vec[21]);
		swap(vec[5], vec[24]);
		swap(vec[8], vec[27]);
		swap(vec[12], vec[14]);
		swap(vec[11], vec[18]);
		break;
	case 2:
		swap(vec[6], vec[21]);
		swap(vec[7], vec[22]);
		swap(vec[8], vec[23]);
		swap(vec[9], vec[11]);
		swap(vec[12], vec[17]);
		break;
	case 3:
		swap(vec[0], vec[27]);
		swap(vec[1], vec[28]);
		swap(vec[2], vec[29]);
		swap(vec[18], vec[20]);
		swap(vec[14], vec[15]);
		break;
	}
	return vec;
}
void disp( vector<int> vec ){
	for( int i = 0; i < 30; i++ )
		cout << vec[i] << " ";
	cout << endl;
}

int dfs( vector<int> vec, int dep ){
	if( isEnd( vec ) )
		return dep;
	if( dep >= 7 )
		return 8;
		
	int ans = 514;
	for( int i = 0; i < 4; i++ ){
		vec = rot( vec, i );
		ans = min( ans, dfs(vec, dep + 1) );
		vec = rot( vec, i );
	}
	return ans;
}

int main()
{
	int n;
	cin >> n;
	for( int i = 0; i < n; i++ ){
		vector<int> vec;
		for( int j = 0; j < 30; j++ ){
			int t;
			cin >> t;
			vec.push_back(t);
		}
		cout << dfs(vec, 0) << endl;
	}
	return 0;
}

Measured memory_bytes: 1216
n=int(input())
ans=[]
for i in range(1,n//2+1):
    a=i
    b=n-i
    a=str(a)
    b=str(b)
    a=list(map(int,a))
    b=list(map(int,b))
    ans.append(sum(a)+sum(b))
print(min(ans))

Measured memory_bytes: 3700