akhauriyash/Code-Regression huggingface dataset:
/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*/
//vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  
  int n;
  cin >> n;
  vector<string>w(n);
  rep(i,n) cin >> w.at(i);
  int Aflag=0;
  int Bflag=0;
  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      if(w.at(i) == w.at(j)) Aflag=1;
    }
  }
  rep(i,n-1) if(w.at(i).at(w.at(i).size()-1) != w.at(i+1).at(0)) Bflag=1;
  if(Aflag==0 && Bflag==0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
// atcoder/abc129/B/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    vector<lli> v(n);
    cin >> v;
    lli mn = 1LL << 60;
    for (int t = 0; t <= 101; ++t) {
      lli a = 0;
      lli b = 0;
      for (int i = 0; i < v.size(); ++i) {
        if (i <= t) a += v[i];
        else b += v[i];
      }
      // cout << t << ' ' << a << ' ' << b << ' ' << abs(a - b) << endl;
      setmin(mn, abs(a - b));
    }
    cout << mn << endl;
  }

  return 0;
}


Measured memory_bytes: 256
# C
n = int(input())
s = str(input())
ans = [0] * n
ans[0] = s[1:].count('E')
for i in range(1, n):
    if s[i-1] == 'E':
        ans[i] = ans[i-1]
    else:
        ans[i] = ans[i-1] + 1
    if s[i] == 'E':
        ans[i] -= 1
print(min(ans))

Measured memory_bytes: 15436
n, k = [int(i) for i in input().split()]
r, s, p = [int(i) for i in input().split()]
t = [i for i in input()]

def takahashiKun(t_i, cnt):
    if cnt>=k and t[cnt-k]==t_i:
        t[cnt] = "X"
        return int(0)
    else:
        if   t_i=="p": return s
        elif t_i=="r": return p
        else         : return r

score = 0
for cnt, t_i in enumerate(t):
    score += takahashiKun(t_i, cnt)

print(score)


Measured memory_bytes: 4212
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
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;}

const ll MOD = (ll)1e9 + 7;
const ll HIGHINF = (ll)1e18;

vll d(100000, 0);
vll visited(100000, false);
vvll edges(100000, vll());

ll dfs(ll i) {
  if (visited.at(i)) return d.at(i);
  else {
    visited.at(i) = true;
    REP(toi, edges.at(i).size()) {
      ll to = edges.at(i).at(toi);
      d.at(i) = max(d.at(i), dfs(to) + 1);
    }
    return d.at(i);
  }
}

int main() {
  ll n, m; cin >> n >> m;
  REP(i, m) {
    ll x, y; cin >> x >> y;
    edges.at(x-1).push_back(y-1);
  }
  ll ans = 0;
  REP(i, n) {
    ans = max(ans, dfs(i));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 10752
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
 
K = min(K, 41)
 
# imos
for _ in range(K):
    B = [0 for _ in range(N)]
    for i in range(N):
        l = max(0, i-A[i])
        r = min(N-1, i+A[i])
        B[l] += 1
        if r+1 < N:
            B[r+1] -= 1
    for i in range(1, N):
        B[i] += B[i-1]
    A = B

print(*A)

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

using namespace std;

void output(vector<int> a)
{
  for(int i = 0;i < a.size() - 1;i++)
  {
    cout << a[i] << " ";
  }
  cout << a[a.size() - 1] << endl;
}

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0;i < n;i++)
  {
    cin >> a[i];
  }
  for(int i = 0;i < n;i++)
  {
    sort(a.begin(), a.begin() + i + 1);
    output(a);
  }
  return 0;
}



Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  ll n;
  cin >> n;
  ll i,j,ans=0;
  for(i=1;i*i<=n;i++){
    for(j=i;j<n;j++){
      if(n-i*j>0){
        ans+=2;
        if(i==j){
          ans--;
        }
      }
    }
  }
  cout << ans;
}
  

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int n, q;
long long f[200001];
vector <int> a[200001];
void dfs (int u, int par) {
  for (auto v : a[u]) {
    if (v != par) {
      f[v] += f[u];
      dfs (v, u);
    }
  }
}
int main () {
  if (fopen ("test.inp", "r")) {
    freopen ("test.inp", "r", stdin);
  }
  ios_base :: sync_with_stdio (0);
  cin.tie (nullptr);
  cout.tie (nullptr);
  cin >> n >> q;
  for (int i = 1; i < n; ++ i) {
    int u, v;
    cin >> u >> v;
    a[u].push_back (v);
    a[v].push_back (u);
  }
  while (q --) {
    int p, x;
    cin >> p >> x;
    f[p] += x;
  }
  dfs (1, 1);
  for  (int i = 1; i <= n; ++ i) cout << f[i] << " ";
}


Measured memory_bytes: 24320
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int n, W;
vi v, w;
ll memo[120][100200];

ll dp(int i, int j) {

	if (j <= 0)return 0;
	if (memo[i][j] != 0)return memo[i][j];
	if (i == 0)return -1;

	ll noi = dp(i - 1, j);
	ll usei = dp(i - 1, j - v[i - 1]);
	if (usei != -1)usei += w[i - 1];

	ll ret;
	if (noi == -1 && usei == -1)ret = -1;
	else if (noi == -1)ret = usei;
	else if (usei == -1)ret = noi;
	else ret = min(noi, usei);

	memo[i][j] = ret;
	return ret;

}

int main() {

	cin >> n >> W;
	v.resize(n);
	w.resize(n);
	rep(i, n)cin >> w[i] >> v[i];

	int l = 0, r = 100001;
	while (r - l > 1) {
		int c = (l + r) / 2;
		ll k = dp(n, c);
		if (k == -1 || k > W)r = c;
		else l = c;
	}

	cout << l << endl;

}

Measured memory_bytes: 79360
#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

const int P = 1000000007;
ll inv[100010], fac[100010], facInv[100010];

void initFact(int n){
  inv[1] = 1;
  for (int i = 2; i <= n; ++i){
    inv[i] = P - (P / i) * inv[P % i] % P;
  }

  fac[0] = facInv[0] = 1;
  for (int i = 1; i <= n; ++i) {
    fac[i] = (fac[i - 1] * i) % P;
    facInv[i] = (facInv[i - 1] * inv[i]) % P;
  }
}

ll choose(int n, int k) {
  if (k > n) return 0;
  return (((fac[n] * facInv[k]) % P) * facInv[n - k]) % P;
}

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

  vector<int> v(n + 1, -1);
  int x, outside;
  for(int i = 0; i < n + 1; i++){
    cin >> x;
    if(v[x] != -1){
      outside = n - i + v[x];
    }
    else{
      v[x] = i;
    }
  }

  initFact(n + 1);

  ll ans;
  for(int i = 1; i <= n + 1; i++){
    ans = (choose(n + 1, i) - choose(outside, i - 1) + P) % P;
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3968
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<climits>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reg(i,a,b) for(int i=(a);i<=(b);i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=(b);i>=(a);i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX


int main(void){
	while(1){
		int n;
		scanf("%d",&n);
		if(n==0)break;
		int s=0,ans=-1;
		rep(i,12){
			int a,b;
			scanf("%d%d",&a,&b);
			s+=(a-b);
			if(ans==-1 && s>=n)ans=i+1;
		}
		if(ans==-1)printf("NA\n");
		else printf("%d\n",ans);
	}
			
	return 0;
}

Measured memory_bytes: 1040
#include <bits/stdc++.h>
using namespace std;
static const int MOD = 1000000000+7;

struct Query {
  int a,b,c,d;
};

bool isEnd(vector<int> A, int m) {
  bool isLastSeq = true;
  for (int i=1; i<A.size(); i++) {
    if (A.at(i) != m) {
      isLastSeq = false;
      return isLastSeq;
    }
  }
  return isLastSeq;
}

void increment(vector<int> & A, int m)
{
  for (int i=A.size()-1; i>0; i--) {
    A.at(i)++;
    if (A.at(i) <= m) break;
    A.at(i) = 1;
  }

  A.at(0) = 0;
  for (int i=1; i<A.size(); i++) {
    A.at(i) = max(A.at(i-1), A.at(i));
  }
}

long long countScore(vector<int> const & A, vector<Query> const & Qu) {
  long long score=0;
  for (auto & e:Qu) {
    if ( A.at(e.b) - A.at(e.a) == e.c ) score += e.d;
  }
  return score;
}

int main() {
  int n,m,q;
  cin >> n >> m >> q;
  vector<Query> Qu(q);
  for (auto & e:Qu) {
    cin >> e.a >> e.b >> e.c >> e.d;
  }
  vector<int> A(n+1,1);
  A.back() = 0;

  long long ans=0;
  while (!isEnd(A,m)) {
    increment(A,m);
    ans = max( ans, countScore(A,Qu) );
    // cout << ans << endl;
  }

  cout << ans << endl;
}

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

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#pragma GCC optimize("Ofast")
//1.0 * clock() / CLOCKS_PER_SEC

#define fi first
#define se second
#define ll long long
#define dl double long

using namespace std;

const ll NN = 1e10 + 7;
const int N = 1e5 + 7;
const int M = 11;
const ll mod = 1e9 + 7;
const ll inf = 1e18 + 7;
const dl rf = 1e-14;

void solve1()
{
	char a, b, c;
	cin >> a >> b >> c;
	if(a == '7' || b == '7' || c == '7')
		cout << "Yes";
	else
		cout << "No";
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0); srand(time(0));
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    int cghf = 1;//cin >> cghf;
    while( cghf-- ){
        solve1();
    }
}


Measured memory_bytes: 3648
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=505;

int n,x[N],f[N],a[N*N+N];

bool cmp(int p,int q)
{
	return x[p]<x[q];
}

int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&x[i]),f[i]=i;
	sort(f+1,f+n+1,cmp);
	int now=1;
	for (int i=1;i<=n;i++)
	{
		int w=f[i];a[x[w]]=w;
		for (int j=1;j<w;j++)
		{
			while (a[now]) now++;
			a[now]=w;
		}
		if (now>x[w]) {puts("No");return 0;}
	}
	for (int i=1;i<=n;i++)
	{
		int w=f[i];
		for (int j=1;j<=n-w;j++)
		{
			while (a[now]) now++;
			if (now<x[w]) {puts("No");return 0;}
			a[now]=w;
		}
	}
	puts("Yes");
	for (int i=1;i<=n*n;i++) printf("%d ",a[i]);
	return 0;
}

Measured memory_bytes: 2176
#include<cstdio>
#include<map>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>

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

using namespace std;

int main(){
        string s;cin>>s;
        sort(s.begin(),s.end());
        int judge=0;
        REP(i,s.size()-1){
                if(s[i]==s[i+1]) judge++;
        }
        cout << (judge>0 ? "no":"yes") << endl;
        return 0;
}


Measured memory_bytes: 632
#include <bits/stdc++.h>
#define debug(x) cout << #x << " = " << x << endl;
using namespace std;

const int mod = 1e9 + 7;
const int MAX_N = 21;
bool match[MAX_N][MAX_N];
int dp[1 << MAX_N];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> match[i][j];
		}
	}
	dp[0] = 1;
	for (int mask = 0; mask < (1 << n) - 1; mask++) {
		int i = __builtin_popcount(mask);
		for (int j = 0; j < n; j++) {
			if (match[i][j] and !(mask & (1 << j))) {
				int mask2 = mask xor (1 << j);
				dp[mask2] = (dp[mask2] + dp[mask]) % mod;
			}
		}
	}
	cout << dp[(1 << n) - 1] << endl;;
	return 0;
}

Measured memory_bytes: 8448
fun main(arr: Array<String>) {
    val n = readLine()!!.toInt()
    val listA = readLine()!!.split(" ").map { it.toInt() }
    val total = Math.pow(3.toDouble(), n.toDouble()).toInt()
    val oddCount = Math.pow(2.toDouble(), listA.count { it % 2 == 0 }.toDouble()).toInt()
    println(total - oddCount)
}



Measured memory_bytes: 36428
#pragma GCC optimize ("O2")
#include<bits/stdc++.h>
#include <queue>
#include <cstring>

#define mp make_pair
#define pb push_back
#define p push

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ll long long

#define getI(a) scanf("%d",&a)
#define getII(a, b) scanf("%d%d",&a,&b)
#define getIII(a, b, c) scanf("%d%d%d",&a,&b,&c)
#define getL(a) scanf("%lld",&a)
#define getLL(a, b) scanf("%lld%lld",&a,&b)
#define getLLL(a, b, c) scanf("%lld%lld%lld",&a,&b,&c)
#define BEND(c) (c).begin(),(c).end()
#define BEND2(c) (c).rbegin(),(c).rend()
#define fi first
#define se second
#define pi 3.1415926535897932384626
#define getS(a) scanf("%s",a)
#define pfi(a) printf("%d",a);
#define pfii(a, b) printf("%d%d",a,b);
#define pfl(a) printf("%lld",a);
#define pfll(a, b) printf("%lld%lld",a,b);
#define pfd(a) printf("%lf",a);
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);
#define endl "\n"
#define sag (sol|1)
//#define sol (root<<1)
#define ort (bas+son)/2
#define SIZE  ( int)(1e9 + 7)
#define MAXN (ll) ((1e5+5))
#define K 25
#define  ALPHABET_SIZE  26
#define N (int)(1e5+10)
#define INF (ll )1e18
#define int ll
using namespace std;

typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<long long> vl;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<vi> graph ;



ll dp[20100];
signed main(){
    ll  h,n;
    cin>>h>>n;
    ll k = 1ll<<60;
    for (int i = 1; i <20001 ; ++i) {
        dp[i]=k;
    }

    for (int x,y,j = 0; j <n ; ++j) {
        cin >> x>>y;
        for (int i = 0; i <h ; ++i) {
            dp[i+x]=min(dp[i+x] , dp[i]+y);
        }
    }
    ll mn =k;
    for (int l = h; l <=20000 ; ++l) {
        mn=min(mn,dp[l]);
    }
    cout <<mn;
    return 0;
}

Measured memory_bytes: 384
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())


n = ni()

a = nl()

minn = min(a)
maxx = max(a)

lis = [0 for i in range(maxx - minn + 3)]
for aa in a:
    i = aa - minn
    lis[i - 1] += 1
    lis[i] += 1
    lis[i + 1] += 1
print(max(lis))


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

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

    int ans = 100;// MAX
    for(int i=0; i<26; i++){
        char letter = 'a' + i;
        if(s.find(letter) == s.npos) continue;

        string t = s;
        int test = 0;
        while(1){
            string u = "";
            bool flag = true;

            for(int j=0; j+1<t.length(); j++){
                if(t[j]   == letter 
                || t[j+1] == letter) u += letter;
                else{
                    u += t[j];
                    flag = false;
                }
            }

            if(flag == true) break;
            t = u;
            test += 1;
        }
        if(test != 0) test += 1;
        ans = min(ans, test);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3616
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

long N,A,B;
vector<int> X(100000);

int main(){
    cin >> N >> A >> B;
    for(int i=0;i<N;i++) cin >> X[i];
    long ans=0;
    for(int i=0;i<N-1;i++){
        long walk = A*(X[i+1]-X[i]);
        ans += min(walk,B);
    }
    cout << ans;
}

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

using namespace std;
#define MOD 1000000007
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define popb pop_back()
#define popf pop_front()
#define ff first
#define ss second
#define vl vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vll vector< pair<ll,ll> >
#define vii vector< pair<int,int> >
#define viii vector< tuple <int,int,int> >
#define vlll vector< tuple <ll,ll,ll> >
#define vvl vector<vector<ll>>
#define vv vector<vector<int>>
#define all(v) v.begin(),v.end()
#define sqrt sqrtl
#define cbrt cbrtl
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mapcl map<char,ll>
#define mapci map<char,int>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define seti set<int>
ifstream fin("input.txt");
ofstream fout("output.txt");

int gcd(int a,int b){while (a&&b)a>b?a%=b:b%=a;return a+b;}
ll pows(int a , int b){ll res=1;for(int i=0; i<b; ++i){res*=a;}return res;}
ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}

vi vis(100001,0);
vi adj[100001];

int main()
{	
    std::ios::sync_with_stdio(false);
    //cin.tie(NULL);
    //cout.tie(NULL);
    int n,d;
    cin>>n>>d;
    for(int i=0; i<n; ++i)
    {
    	for(int j=0; j<d; ++j)
    	{
    		int x;
    		cin>>x;
    		adj[i].pb(x);
    	}
    }
    ll cnt=0;
    for(int i=0; i<n; ++i)
    {
    	for(int j=i+1; j<n; ++j)
    	{
    		float sum=0;
    		for(int k=0; k<d; ++k)
    		{
    			sum+=pows(adj[i][k]-adj[j][k],2);
    		}
    		int tempx = sum;
    		sum = sqrt(tempx);
    		int meow = sum;
    		if(pows(meow,2)==tempx)
    			++cnt;
    		//cout<<tempx<<" "<<sum<<"\n";
    	}
    	
    }
    cout<<cnt<<"\n";
}

Measured memory_bytes: 2944
import java.util.*;

 class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        
        long[] a = new long[(int)N];
        long[] b = new long[(int)N];
        boolean[] Flg= new boolean[(int)N];
        for(int i=0;i<N;i++) {
            a[i] = sc.nextLong();
        }
        for(int i=0;i<N;i++) {
            b[i] = sc.nextLong();
        }
        int count=0;
        int ans1=0;
        int ans2=0;
        int k=1;
        for(int i=0;i<N;i++) {
    		count=0;
        	for(int j=0;j<a[i];j++) {
        		if(Flg[j]==false) {
        			count++;
        		}
        	}
    		Flg[(int) (a[i]-1)]=true;
    		k=1;
    		for(int l=1;l<N-i;l++) {
    			k=k*l;
    		}
//            System.out.println("i=" + i);
//            System.out.println("count=" + count);
    		ans1=(int) (ans1+k*(count-1));
        	
        }

        boolean[] Flg2= new boolean[(int)N];
        for(int i=0;i<N;i++) {
    		count=0;
    		k=1;
        	for(int j=0;j<b[i];j++) {
        		if(Flg2[j]==false) {
        			count++;
        		}
        	}
    		Flg2[(int) (b[i]-1)]=true;
    		k=1;
    		for(int l=1;l<N-i;l++) {
    			k=k*l;
    		}
    		ans2=(int) (ans2+k*(count-1));
        	
        }
//        System.out.println(Math.abs(ans1));
//        System.out.println(Math.abs(ans2));
        
        System.out.println(Math.abs(ans1-ans2));
    }

}

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

int main()
{
  int H, W;
  cin >> H >> W;

  vector<string> A;

  for (int i = 0; i < H; i++)
  {
    string s;
    cin >> s;
    A.push_back(s);
  }

  for (int i = 0; i < W + 2; i++)
  {
    cout << "#";
  }

  cout << "\n";

  for (int i = 0; i < H; i++)
  {
    cout << "#" << A[i] << "#\n";
  }

  for (int i = 0; i < W + 2; i++)
  {
    cout << "#";
  }

  cout << endl;
}


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

class Main{
    public static void main(String[] args){
	BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
	try {
	    String st;
	    while((st=sc.readLine())!=null){
		double b = Double.valueOf(st);
		String out;
		if(b<=48.0)
		    out = "light fly";
		else if(b<=51.0)
		    out = "fly";
		else if(b<=54.0)
		    out = "bantam";
		else if(b<=57.0)
		    out = "feather";
		else if(b<=60.0)
		    out = "light";
		else if(b<=64.0)
		    out = "light welter";
		else if(b<=69.0)
		    out = "welter";
		else if(b<=75.0)
		    out = "light middle";
		else if(b<=81.0)
		    out = "middle";
		else if(b<=91.0)
		    out = "light heavy";
		else
		    out = "heavy";
		System.out.println(out);
	    }
	}catch(Exception e){
	    System.out.println("Error");
	}
    }
}

Measured memory_bytes: 9740
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int main() {
  int N;
  cin >> N;
  std::vector<int> V(N);
  std::vector<int> C(N);
  int sum=0;
  REP(i,N) {
    cin >> V.at(i);
  }
  REP(i,N) {
    cin >> C.at(i);
  }
  REP(i,N){
    if(V.at(i)>C.at(i)){
      sum += V.at(i)-C.at(i);
    }
  }
  std::cout << sum << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) long long((x).size())
#define OUT(x) cout << (x) << endl
typedef long long ll;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
typedef pair<ll, ll> P;
typedef map<string, ll> M;
typedef unordered_map<ll, ll> HM;
typedef set<ll> S;
typedef multiset<ll> MS;
typedef queue<ll> Q;

int main(){
    int a; cin>>a;
    string s; cin>>s;
    if(a>=3200) OUT(s);
    else OUT("red");
}

Measured memory_bytes: 256
from collections import Counter

N = int(input())
S = []
for _ in range(N):
    s = list(input())
    s.sort()
    S.append(''.join(s))

c = Counter(S).most_common()

ans = 0
for i, j in c:
    ans += j * (j - 1) // 2

print(ans)


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

int main() {
  int c,c1,c2,c3;
  cin >> c;
  c1 = c/100;
  c2 = c/10 - c1*10;
  c3 = c - c1*100 - c2*10;
  cout << c1+c2+c3 << endl;
}

Measured memory_bytes: 256
n = int(input())
nlist = list(map(int, input().split()))

ans = nlist.copy

for i in range(n):
    v = nlist[i]
    j = i - 1
    while j >= 0 and nlist[j] > v:
        nlist[j+1] = nlist[j]
        j -= 1
    nlist[j+1] = v

    for j in range(n):
        if j == n-1:
            print(nlist[j])
        else:
            print(str(nlist[j]) + " ", end="")



Measured memory_bytes: 5984
s = input()
odd = ["R","U","D"]
even = ["L","U","D"]
flag1=True
flag2=True
for i in range(1,len(s)+1):
    if (i%2==1) and not(s[i-1] in odd):
        flag1 =False
    if (i%2==0) and not(s[i-1] in even):
        flag2 = False

if flag1 and flag2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1 << 30;

using namespace std;

using ll = long long;
using P = tuple<int, int>;
using iarr = valarray<int>;

int main()
{
    int N;
    cin >> N;
    ll pw = 1;
    for(int i = 1; i <= N; ++i){
        pw = (pw * i) % 1000000007;
    }
    cout << pw << endl;
    return 0;
}

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

int main() {
  int x=0,N;
  int ans =0;
  string S;

  cin >> N >> S;
  for(int i=0;i<N;++i){
    if(S.at(i) == 'I'){
      x += 1;
    }else{
      x -= 1;
    }

    if(ans < x) ans = x;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3580
import sys
from collections import defaultdict


def input():
    return sys.stdin.readline().rstrip()


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():
    N, M = map(int, input().split())

    uf = UnionFind(N)
    for i in range(M):
        x,y,z = map(int,input().split())
        uf.union(x-1,y-1)

    print(uf.group_count())



if __name__ == "__main__":
    main()


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

int val[10000];

int main()
{
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; i ++)
        cin >> val[i];
    sort(val, val + n);
    int sum = 0;
    for (int i = 0; i < k; i ++)
        sum += val[i];
    cout << sum << endl;

}

Measured memory_bytes: 3600
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>

//#include<bits/stdc++.h>

using namespace std;


int main() {
	int x;
	cin >> x;
	if (x >= 1200)cout << "ARC" << endl;
	else cout << "ABC" << endl;
	return 0;
	
}


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

class Program
{
    public static void Main()
    {
        string[] str = Console.ReadLine().Split(' ');
        int N = int.Parse(str[0]);
        int M = int.Parse(str[1]);
        List<Tuple<int, int, int>> Table = new List<Tuple<int ,int, int>>() { Capacity = M };
        for(int i = 0; i < M; i++)
        {
            str = Console.ReadLine().Split(' ');
            Tuple<int, int, int> t = new Tuple<int, int, int>(i, int.Parse(str[0]), int.Parse(str[1]));
            Table.Add(t);
        }
        Table.Sort((x,y)=>
        {
            if (x.Item2 - y.Item2 != 0)
                return x.Item2 - y.Item2;
            else
                return x.Item3 - y.Item3;
        });
        int pref = Table[0].Item2;
        int tid = 1;
        List<Tuple<int, string>> Table2 = new List<Tuple<int, string>>();
        for (int i = 0; i < M; i++)
        {
            if(pref == Table[i].Item2)
            {
                Table2.Add(new Tuple<int, string>(Table[i].Item1, pref.ToString().PadLeft(6, '0') + tid.ToString().PadLeft(6,'0')));
                tid++;
            }
            else
            {
                pref = Table[i].Item2;
                tid = 1;
                Table2.Add(new Tuple<int, string>(Table[i].Item1, pref.ToString().PadLeft(6, '0') + tid.ToString().PadLeft(6, '0')));
                tid++;
            }
        }
        Table2.Sort((x, y) => x.Item1 - y.Item1);
        foreach (var i in Table2)
            Console.WriteLine(i.Item2);
    }
}

Measured memory_bytes: 34280
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
  cin>>s;
  int l=s.length();
  for(int i=0,j=1;i<l||j<l;i++,j++)
  {if(s[i]=='L'||s[j]=='R')
  {cout<<"No";
  return 0;}i++;j++;}
  cout<<"Yes";
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long x = sc.nextLong();
    long a = 0;
    long b = 0;
    for (long i = -200; i <= 200; i++) {
      for (long j = -200; j <= 200; j++) {
        if ((i * i * i * i * i) - (j * j * j * j * j) == x) {
          a = i;
          b = j;
          break;
        }
      }
    }
    System.out.println(String.format("%d %d", a, b));
  }
}

Measured memory_bytes: 35736
#!/usr/bin/env ruby

n, cost = gets.strip.split(' ').map(&:to_i)

(0..n).each do |z|
  (0..(n - z)).each do |y|
    x =  n - z - y
    if 10000 * x + 5000 * y + 1000 * z == cost then
      puts "#{x} #{y} #{z}"
      exit
    end
  end
end
puts "-1 -1 -1"

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

#define REPI(x) for(int i=0;i<x;i++)
#define REPJ(x) for(int j=0;j<x;j++)

#define REPISE (s,e) for(int i=s,i<e;i++)
#define REPJSE (s,e) for(int j=s,j<e;j++)

typedef long long ll;

using namespace std;

bool cmp0 (const tuple<int,int,int> &p1, const tuple<int,int,int> &p2)
{
  return get<0>(p1) < get<0>(p2);
}

bool cmp1 (const tuple<int,int,int> &p1, const tuple<int,int,int> &p2)
{
  return get<1>(p1) < get<1>(p2);
}

bool cmp2 (const tuple<int,int,int> &p1, const tuple<int,int,int> &p2)
{
  return get<2>(p1) < get<2>(p2);
}


int main ()
{
  int N,M,P,Y,rank,cn;
  vector<tuple<int,int,int> > vt;

  cin >> N >> M;  

  vector<int> Prank(N+1);
  vector<string> id(M);
  ostringstream oss;

  REPI(N+1)
    Prank[i] = 1;

  REPI(M)
  {
    cin >> P >> Y;
    vt.emplace_back (i,P,Y);
  }

  sort(vt.begin (),vt.end (), cmp2);

  REPI(M)
  {
    oss.str("");
    oss.clear();
    P = get<1>(vt[i]);
    rank = Prank[P];
    Prank[P]++;
    cn = get<0>(vt[i]);
    oss << setfill('0') << right <<  setw(6) << P;
    oss << setfill('0') << right <<  setw(6) << rank;
    id[cn] = oss.str ();
  }

  sort(vt.begin (),vt.end (), cmp0);
  
  REPI(M)
    cout << id[i] << endl;
  return 0;
}

Measured memory_bytes: 8412
let n1 = readLine()!.split(separator: " ").map({$0})
    
    let n2 = readLine()!.split(separator: " ").map({$0})
    
    var r: Int = 0
    
    for i in 0 ..< n2.count {
      
      r += Int(n2[i])!
    }
    
    let sum = Int(n1[0])! - r
    
    if sum < 0 {
      print(-1)
    } else {
      print(sum)
    }

Measured memory_bytes: 8688
A = [list(map(int,input().split())) for i in range(3)]
N = int(input())
b = [int(input()) for i in range(N)]
cnt = [0]*8
ans = "No"
for i in range(3):
    for j in range(3):
        if A[i][j] in b:
            cnt[i] += 1
            cnt[j+3] += 1
            if i == j:
                cnt[-1] += 1
            if i+j == 2:
                cnt[-2] += 1
for k in range(8):
    if cnt[k] >= 3:
        ans = "Yes"
        break
print(ans)

Measured memory_bytes: 9224
#include <cstdio>

using namespace std;

int main() {
    int k, x;
    scanf("%d%d", &k, &x);
    for (int i = x - k + 1; i < x + k - 1; ++i) printf("%d ", i);
    printf("%d\n", x + k - 1);
    return 0;
}


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


void rectangle(int a, int b, int l[]){
	int area = a * b;
	int circumference = 2 * (a + b);
	l[0] = area;
	l[1] = circumference;
}

int main(){
	int t;
	cin >> t;
	int h, m, s;
	h = int(t / 3600);
	t = t % 3600;
	m = int(t / 60);
	t = t % 60;
	s = t;
	cout << h << ':' << m << ':' << s << endl;

	return 0;
}


Measured memory_bytes: 3124
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) ((a)<<(b))
#define Rshift(a,b) ((a)>>(b))
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define sz(a) int(a.size())
#define mset(x) memset(x, 0, sizeof(x))
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;


int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int x, n;
    cin >> x >> n;
    set<int> in;
    int i;
    rep(i, n) {
        int w;
        cin >> w;
        in.insert(w);
    }
    int diff(10000), didx(-1000);
    xrep(i, -200, 200) {
        if (!in.count(i)) {
            if (abs(i - x) < diff) {
                diff = abs(i - x);
                didx = i;
            }
        }
    }
    cout << didx << endl;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef __int128_t i128;
typedef long long i64;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#define FPEN2 freopen("out.txt", "w", stdout);
#else
#define FPEN
#define FPEN2
#endif
#define Sz(a) ((int)(a).size())
const int maxn = 200009;
const int MOD = 1e9 + 7;
int main(){
  FPEN;
  ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);
  i64 n;cin>>n;
  int ans=0;
  for(i64 i=2;i*i<=n;++i){
    if(n%i==0){
      int cnt=0;
      while(n%i==0){
        n/=i;cnt++;
      }
      int cur=0;
      for(int j=1;cur+j<=cnt;++j)ans++,cur+=j;
    }
  }
  if(n!=1)ans++;
  cout<<ans<<"\n";
  
  return 0;
}
//2020.05.31 20:15:08


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline void read(T &x){
	register short f=1;x=0;char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c))x=(x<<3)+(x<<1)+(c^48),c=getchar();
	x*=f;
}
template<typename T>inline void write(T x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
template<typename T>inline void writeln(T x){
	write(x),putchar('\n');
}
int main(){
	int m,n;
	read(m),read(n);
	writeln((m-1)*(n-1));
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
using System.Threading.Tasks;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }
    

    Scanner cin;
    
    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        Console.WriteLine(N / 3);
    }
}




class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}



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


int main(){
  long n;
  cin >> n;
  string ans = "";
  long t;
  if(n == 0){
      cout << "0" << endl;
      return 0;
  }
  while(n != 0){
      t = n % (2);
      n = n / (-2);
      if(t == -1){
          ans = "1" + ans;
          n += 1;
      }else if(t == 1){
          ans = "1" + ans;
      }else if(n != 0){
          ans = "0" + ans;
      }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
// 問題の URL を書いておく
// 

#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

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

int main(int, const char**)
{
    int a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
    return 0;
}


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

int main() {
  int D, G;
  cin >> D >> G;
  vector<int> P(D), C(D);
  for (int i = 0; i < D; i++) cin >> P.at(i) >> C.at(i);

  int ans = 1e9;

  for (int bit = 0; bit < 2 << D; bit++) {
    int sum = 0;
    int num = 0;
    for (int i = 0; i < D; i++) {
      if (bit >> i & 1) {
        sum += P.at(i) * (i + 1) * 100 + C.at(i);
        num += P.at(i);
      }
    }
    if (sum >= G) ans = min(ans, num);
    else {
      for (int i = D - 1; i >= 0; i--) {
        if (bit >> i & 1) continue;
        for (int j = 0; j < P.at(i); j++) {
          if (sum >= G) break;
          sum += (i + 1) * 100;
          num++;
        }
      }
      ans = min(ans, num);
    }
  }

  cout << ans << "\n";
}

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

using namespace std;

int N;

int main() {
	cin >> N;
	vector<int> B(N - 1);
	for (int i = 0; i < N - 1; i++) {
		cin >> B[i];
	}

	int ans = B[0] + B[N - 2];
	for (int i = 0; i < N - 2; i++) {
		if (B[i] < B[i + 1]) { ans += B[i]; }
		else { ans += B[i + 1]; }
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	var N int
	fmt.Scan(&N)
	Xs := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&Xs[i])
	}

	minX, maxX := MinMax(Xs...)

	ans := math.MaxInt32
	for p := minX; p <= maxX; p++ {
		sum := 0
		for _, x := range Xs {
			sum += (x - p) * (x - p)
		}
		ans = Min(ans, sum)
	}
	fmt.Println(ans)
}

func Min(xs ...int) int {
	min := xs[0]
	for _, x := range xs[1:] {
		if min > x {
			min = x
		}
	}
	return min
}

func MinMax(slice ...int) (int, int) {
	min, max := slice[0], slice[0]
	for _, v := range slice[1:] {
		if min > v {
			min = v
		} else if max < v {
			max = v
		}
	}
	return min, max
}


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

int main(void) {
    int x, y, a=0;
    scanf("%d%d", &x, &y);

    for (int i=0; i<=x; i++){
        for (int j=0; j<=x; j++){
            if (2*i+4*j==y && i+j==x){
                a = 1;
            }
        }
    }

    if (a==1){
        printf("%s", "Yes");
    }else{
        printf("%s", "No");
    }
    return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define EPS (1e-10)
#define rep(i,n) for(int i=0;i<(n);i++)
#define equals(a,b) (fabs((a) - (b)) < EPS)
#define ll long long
using namespace std;
typedef pair<int,int> P;
//const ll MOD = 1000000007;
//const ll INF = 100000000;

//const int max_n = 100000;
int k;
string s;
//vector<int> d(n);

//int ans = 0;

//stack<int> stack;
//queue<int> que;
//priority_queue<int> pque;
//set<int> s; set<int>::iterator ite;
//multiset<int> ms; multiset<int>::iterator ite;
//map<int, int> m; map<int, int>::iterator ite;
//multimap<int, int> mm; multimap<int, int>::iterator ite;

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

void solve() {
  if(s.length() <= k) cout << s << endl;
  else cout << s.substr(0, k) << "..." << endl;
  return;
}

int main(int argc, char const *argv[]) {

  cin >> k;
  cin >> s;

  /*rep(i,n) {
    int m;
    cin >> m;
    rep(j,m) {
      int a;
      cin >> a;
      d[a-1] = 1;
    }
  }*/

  solve();
  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h> 
using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define int ll

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

  int N,M;
  cin>>N>>M;
  vector<vector<int>>w(100000);
  for(int i=0;i<N;i++){
    int A,B;
    cin>>A>>B;
    w[A].push_back(B);
  }
  int ans=0;
  priority_queue<int>p;
  for(int i=1;i<=M;i++){
    for(auto it:w[i])p.push(it);
    if(p.size())ans+=p.top(),p.pop();
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 5632
#include<stdio.h>
int main(void)
{
	long long a,b,c,d,e,f,g;
	scanf("%lld %lld %lld",&a,&b,&c);
	if(a<0) a=-a;
	d=a/c;
	e=a%c;
	if(d<=b){
		f=d-b;
		if(f%2==0){
			printf("%lld\n",e);
		}
		else {
			printf("%lld\n",c-e);
		}
	}
	else {
		printf("%lld\n",a-(b*c));
	}
	return 0;
}

Measured memory_bytes: 1700
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N,K;
  cin>>N>>K;
  long long a,b;
  a=N%K;
  b=K-a;
  if(a>b){
  cout<<b<<endl;
  }

  else{
  cout<<a<<endl;
  }
  
}

Measured memory_bytes: 3640
n = int(input())
x = list(map(int,input().split()))

x_sorted = sorted(x)

med = (x_sorted[int(n/2)-1] + x_sorted[int(n/2)])/2

for i in range(n):
    if x[i]<med:
        print(x_sorted[int(n/2)])
    else:
        print(x_sorted[int(n/2)-1])



Measured memory_bytes: 93780
#include <iostream>
using namespace std;
int abs(int a,int b){
    if(a>b){
        return a-b;
    } return b-a;
}
int main()
{
    int n,sum=0;
    cin>>n;
    int A[n+1];
    A[0]=0;
    for(int i=1;i<n+1;i++){
        cin>>A[i];
        sum=sum+abs(A[i],A[i-1]);
    }
    sum=sum+abs(A[n],A[0]);
    for(int i=1;i<n+1;i++){
        int s;
        s=sum-(abs(A[i-1],A[i])+abs(A[(i+1)%(n+1)],A[i]))+abs(A[i-1],A[(i+1)%(n+1)]);
        cout<<s<<endl;
    }

    return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 
ll w[300010],e[300010];
int main() {
	ll n;
	cin>>n;
	string s;
	cin>>s;
	for(ll i=0;i<n;i++){
		char now=s[i];
		if(now=='W'){
			w[i]++;
		}
		else{
			e[i]++;
		}
	}
	for(ll i=1;i<n;i++){
		w[i]=w[i]+w[i-1];
	}
	for(ll i=n-2;i>=0;i--){
		e[i]=e[i]+e[i+1];
	}
	ll ans=INF;
	for(ll i=0;i<n;i++){
		ll sum=w[i]+e[i];
		ans=min(sum,ans);
	}
	cout << ans-1;
	// your code goes here
	return 0;
}

Measured memory_bytes: 5380
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<string>
#include<map>
#include<set>
#include<functional>
#include<list>
#include<bitset>
#include<numeric>
#include<utility>
#define INF (int)1e9
#define DINF (double)1e9
#define MOD 1000000007
#define MAX 210000
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> p;


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 main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m,l;
	cin >> n >> l;
	m = l;
	vector<int> x;
	for (int i = 2; i*i <= m; i++) {
		if (m%i == 0) {
			int a = 0;
			while (m%i == 0) {
				a++;
				m /= i;
			}
			x.push_back(a);
	//		cout << a << endl;
		}
//		cout << i << " xxxx
	}
	if (m != 1) {
		x.push_back(1);
	}
	COMinit();
//	makenCr();
	ull ans = 1;
	for (auto itr : x) {
//		cout << itr << " " << C(itr + n - 1, n - 1) << endl;
		ans *= COM(itr + n - 1, n - 1);
		ans %= MOD;
	}
	cout << ans;
	return 0;
}


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

int main() {

  int X, Y;
  cin >> X >> Y;
  
  if(X == Y) cout << -1 << endl;
  else {    
    for(long long i = 1; i <= Y; i++) {
      
      if((X*i) % Y != 0) {
        cout << X*i << endl;
        break;
      }
      
      if(i == Y) cout << -1 << endl;
      
    }
  }
  
}

Measured memory_bytes: 3632
a=int(input())
b=int(input())
c=int(input())
x=int(input())
ans=0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      sum = 500*i + 100*j + 50*k
      if sum==x:
        ans+=1
print(ans)

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

int main(){
    vector<int> dta(3);
    int ans=0, save=0;
    for (int i=0; i<3; i++) cin>>dta[i];

    for (int i=1; i<3; i++){
        if (dta[0]==dta[i]) save++;
        if (save == 2) save--;
    }
    if (dta[1]==dta[2]) save++;
    ans = 3 - save;
    cout<<ans<<endl;
}


Measured memory_bytes: 3576
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
#include <chrono>
#include <random>

using namespace std;

typedef long long ll;
//mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

void solve() {
	int n, m;
	cin >> n >> m;
	vector<vector<int>> g(n);
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	int ans = 0;
	vector<int> used(n);

	function<void(int)> dfs = [&](int v) {
		used[v] = 1;
		for (int to : g[v])
			if (!used[to])
				dfs(to);
	};

	for (int i = 0; i < n; i++) {
		if (!used[i]) {
			ans++;
			dfs(i);
		}
	}

	cout << ans - 1;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		//cout << endl;
	}
}

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

using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;

#define int long long
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

void accell() {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
}
vector<int>a;

int check(int cur) {
    int aa = a.size() - 1;
    int res = 0;
    for (int i = 0; i < a.size(); ++i) {
        while (aa >= 0 && a[i] + a[aa] >= cur) {
            --aa;
        }
        res += (int)a.size() - 1 - aa;
    }
    return res;
}



signed main() {
    accell();
    int n, k;
    cin >> n >> k;
    a.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int l = 0, r = 2e5 + 5;
    sort(all(a));
    while (r - l > 1) {
        int m = l + r >> 1;
        if (check(m) >= k)
            l = m;
        else
            r = m;
    }
    int p = check(l) - k;
    // cout << p << endl;
    int aa = n - 1;
    int res = -p * l;
    int s = 0;
    for (int i = 0; i < n; ++i) {
        while (aa >= 0 && a[i] + a[aa] >= l) {
            s += a[aa];
            --aa;
        }
        int cnt = n - 1 - aa;
        res += s + cnt * a[i];
        // cout << s << ' ' << a[i] << endl;
    }
    cout << res;
    return 0;
}


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

const int N = 1e5 + 5;

int n, a[N], b[N], c[N];
long long ans;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> a[i];
	for (int i = 1; i <= n; ++i) cin >> b[i];
	for (int i = 1; i <= n; ++i) cin >> c[i];
	sort(a + 1, a + n + 1);
	sort(b + 1, b + n + 1);
	sort(c + 1, c + n + 1);

	for (int i = 1; i <= n; ++i) {
		int pa = lower_bound(a + 1, a + n + 1, b[i]) - a - 1;
		int pc = upper_bound(c + 1, c + n + 1, b[i]) - c;
		ans += 1LL * pa * (n - pc + 1);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1408