akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,x;
  cin >> a >> b >> x;
  if (a<=x && x<=(a+b))cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
import collections
N = int(input())
D = [int(i) for i in input().split()]
M = int(input())
T = [int(i) for i in input().split()]

count_D = collections.Counter(D)
count_T = collections.Counter(T)

ans = 'YES'
for k,v in count_T.items():
  if count_D[k] < v:
    ans = 'NO'
    break
print(ans)

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

#define double long double

const int INF=1001001001;
const int INFLL=1001001001001001001ll;
const int mod=1000000007;
inline void add(int &a,int b){
    a+=b;
    if(a>=mod)a-=mod;
}
int dy[4]={-1,0,1,0};
int dx[4]={0,-1,0,1};

int H,W;
char fld[555][555];
double E[555][555];
bool check(double e){
    queue<pint>que;
    fill_n(*E,555*555,1e14);
    rep(i,H)rep(j,W)if(fld[i][j]=='g'){
        E[i][j]=0;
        que.push({i,j});
    }
    bool flag=false;
    while(true){
        if(que.size()==0){
            if(flag)break;
            rep(i,H)rep(j,W)if(fld[i][j]=='*'){
                E[i][j]=e;
                que.push({i,j});
            }
            flag=true;
            continue;
        }
        int y,x;
        tie(y,x)=que.front();
        que.pop();

        if(E[y][x]+1>=e&&!flag){
            rep(i,H)rep(j,W)if(fld[i][j]=='*'){
                E[i][j]=e;
                que.push({i,j});
            }
            flag=true;
        }

        rep(d,4){
            int ny=y+dy[d],nx=x+dx[d];
            if(fld[ny][nx]=='#'||fld[ny][nx]=='*')continue;

            if(E[ny][nx]!=1e14)continue;
            E[ny][nx]=E[y][x]+1;
            que.push({ny,nx});
        }
    }

    double sum=0;
    int cnt=0;
    rep(i,H)rep(j,W){
        if(fld[i][j]=='#'||fld[i][j]=='*'||fld[i][j]=='g')continue;
        cnt++;sum+=E[i][j];
    }

    return sum<=e*cnt;
}


signed main(){
    cin>>W>>H;
    rep(i,H)cin>>fld[i];

    vector<vint>dist(H,vint(W,INT_MAX));
    queue<pint>que;
    rep(i,H)rep(j,W)if(fld[i][j]=='s'){
        dist[i][j]=0;
        que.push({i,j});
    }
    bool flag=false;
    while(que.size()){
        int y,x;
        tie(y,x)=que.front();
        que.pop();
        rep(d,4){
            int ny=y+dy[d],nx=x+dx[d];
            if(fld[ny][nx]=='#'||dist[ny][nx]!=INT_MAX)continue;
            if(fld[ny][nx]=='*')flag=true;
            dist[ny][nx]=dist[y][x]+1;
            que.push({ny,nx});
        }
    }

    if(!flag){
        rep(i,H)rep(j,W)if(fld[i][j]=='g'){
            printf("%.20Lf\n",(double)dist[i][j]);
            return 0;
        }
    }

    double lb=0,ub=1e12;
    rep(i,200){
        double mid=(ub+lb)/2;
        if(check(mid))ub=mid;
        else lb=mid;
    }

    rep(i,H)rep(j,W){
        if(fld[i][j]=='s'){
            printf("%.20Lf\n",E[i][j]);
        }
    }
    return 0;
}

Measured memory_bytes: 10332
#include <iostream>
#include <stack>
#include <vector>

using namespace std;

int solve(){
	stack<long> s;
	vector<pair<long, long> > v;
	char ch;
	long j, sub, sum = 0;

	for (long i = 0; cin >> ch; i++){
		if (ch == '\\') s.push(i);
		else if (ch == '/' && !s.empty()){
			j = s.top(); 
			s.pop();
			sub = i - j;
			sum += sub;
			while (!v.empty() && v.back().first > j){
				sub += v.back().second;
				v.pop_back();
			}
			v.push_back(make_pair(j, sub));
		}
	}
	cout << sum << endl << v.size();
	for (int i = 0; i < v.size(); i++) cout << " " << v[i].second;
	cout << endl;
}

signed main(){
	solve();
}

Measured memory_bytes: 3196
import java.util.*;
import static java.util.Comparator.*;
class Restaurant {
    private String city;
    private int score;
    private int index;
    public Restaurant(String city, int score, int index) {
        this.city = city;
        this.score = score;
        this.index = index;
    }
    public String getCity() {return this.city;}
    public int getScore() {return this.score;}
    public int getIndex() {return this.index;}
}
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner stdIn = new Scanner(System.in);
        int N = stdIn.nextInt();        
        List<Restaurant> rstList = new ArrayList<>();
        for(int i = 1; i <= N; i++) {
            rstList.add(new Restaurant(stdIn.next(), -stdIn.nextInt(), i));
        }
        rstList.stream()
            .sorted(comparing(Restaurant::getCity).thenComparing(Restaurant::getScore))
            .forEach(rst -> System.out.println(rst.getIndex()));
    }
}

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

#define int long long
#define forn(i,a,n) for (int i=a; i<n; i++)

int n,m;
char a[21][21];
int d[40001];
int dist[21][21];
int used[21][21];
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
int res=-2e18;

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

	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);

	cin>>n>>m;
	forn(i,0,n) forn(j,0,m) cin>>a[i][j];
	forn(i,0,n){
		forn(j,0,m){
			memset(dist,-1,sizeof(dist));
			memset(used,0,sizeof(used));
			if (a[i][j]=='#') continue;
			int qh=0,qt=0;
			d[qt++]=i;
			d[qt++]=j;
			used[i][j]=1;
			dist[i][j]=0;
			while (qh<qt){
				int x=d[qh++];
				int y=d[qh++];
				forn(k,0,4){
					int nx=x+dx[k];
					int ny=y+dy[k];
					if (nx<0 || nx>=n || ny<0 || ny>=m || a[nx][ny]=='#') continue;
					if (dist[nx][ny]==-1){
						d[qt++]=nx;
						d[qt++]=ny;
						dist[nx][ny]=dist[x][y]+1;
					}
				}
			}
			forn(r,0,n)
				forn(c,0,m)
					res=max(res,dist[r][c]);
		}
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 3580
import qualified Data.ByteString.Char8 as C
import Data.Maybe ( fromJust )
import Data.Char ( digitToInt )

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

main :: IO ()
main = do
  [n,a,b] <- readInts 
  print $ f n a b

f :: Int -> Int -> Int -> Int
f n a b = sum [ m | m <- [1..n]
                  , a   <= g m
                  , g m <= b ]
  where
--     g = sum . int2lst
    g = sum . map digitToInt . (show :: Int -> String )

int2lst
  :: Int -> [Int]
int2lst n
  | q == 0 = [r]
  | otherwise = r: int2lst q
  where
    (q,r) = divMod n 10

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

using namespace std;
using ll = long long;

void init();
void solve();

#define rep(i, a) for (int i = 0; i < (int) (a); i++)
#define reps(i, a, b) for (int i = (int) (a); i < (int) (b); i++)
#define rrep(i, a) for (int i = (int) a-1; i >= 0; i--)
#define rreps(i, a, b) for (int i = (int) (a)-1; i >= (int) (b); i--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
#define lcout(a) cout << a;
#define lcoutln(a) cout << a << endl;
#define lcerr(a) cerr << a;
#define lcerrln(a) cerr << a << endl;
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif
#define MOD 1000000007

string s;

signed main()
{
	init();
	solve();
}

ll N, M;
bool con[8][8];

void init()
{
	cin >> N >> M;
	rep(i, M) {
		CIN(int, a);
		CIN(int, b);
		a--;b--;
		con[a][b] = con[b][a] = true;
	}
}

bool hou[8];

int saiki(int pos = 0, int cnt = 1)
{
	if (hou[pos]) return 0;
	if (cnt == N) return 1;
	hou[pos] = true;
	int res = 0;
	rep(i, N) {
		if (con[pos][i]) res += saiki(i, cnt+1);
	}
	hou[pos] = false;
	return res;
}

void solve()
{
	cout << saiki() << endl;
}


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

using ll=long long;
const ll MOD=1e9+7;
int main(){
    int n,m;
    cin>>n>>m;
    vector<int> a(n);
    vector<int> b(m);
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<m;i++)cin>>b[i];

    vector<vector<int>> as(n*m+1);
    vector<vector<int>> bs(n*m+1);
    for(int i=0;i<n;i++) as[a[i]].push_back(i);
    for(int i=0;i<m;i++) bs[b[i]].push_back(i);
    int r=0;
    int c=0;
    ll res=1;
    int top=n*m;
    int st=0;
    for(int i=n*m;i>=0;i--){
        int ac=as[i].size();
        int bc=bs[i].size();
        if(ac+bc==0) continue;
        if(ac>=2 || bc>=2) res=0;
        else{
            int p=(ac+r)*(bc+c)-r*c;
            while(top!=i){
                if(st){
                    res*=st;
                    res%=MOD;
                    top--;
                    st--;
                }   
                else{
                    cout<<0<<endl;
                    return 0;
                }
            }
            if(ac+bc==2){
                st+=p-1;
                top--;
            }
            else if(ac+bc==1){
                st+=p-1;
                res*=p;
                top--;
            }
        }
        res%=MOD;
        r+=ac;
        c+=bc;
    }
    while(st){
        res*=st;
        res%=MOD;
        st--;
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 47232
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (int)(s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
constexpr long long INF = 1e18;
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a=b;return true;}return false;}

int gcd(int x,int y)
{
	if(x==0) return y;
	return gcd(y%x,x);
}
int lcm(int x, int y)
{
	return (x * y / gcd(x, y));
}

vector<pair<long long, long long> > prime_factorize(long long n) {
    //計算量は√N!!!
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

signed main(){
	int A,B;
	cin>>A>>B;
	int g = gcd(A,B);
	auto v = prime_factorize(g);
	cout<<v.size()+1<<endl;
}

Measured memory_bytes: 256
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val n = nextInt()
    val aa = listOfInt()
    val bb = listOfInt()
    val cc = listOfInt()

    var ans = 0
    var prevIndex = -2
    (1..n).forEach {
        var index = aa[it - 1] - 1
        ans += bb[index]
        if (prevIndex + 1 == index) ans += cc[index - 1]
        prevIndex = index
    }
    println(ans)
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 37644
import itertools

def solve(n,x):
  count = 0
  li = [x for x in range(1,n+1)]
  for team in itertools.combinations(li, 3):
      # print(team)
      if sum(team) == x:
        count += 1

  return print(count)

for i in range(100000000):
  n, x = map(int, input().split())
  if n == 0 and x == 0:
    break
  solve(n, x)



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

int main(void){
    int s;
    cin >> s;
    int fy = 1, fm = 1;
    int sf = s / 100, sb = s % 100;
    if(sb == 0 || sb > 12) fy = 0;
    if(sf == 0 || sf > 12) fm = 0;
    if(fy && !fm) cout << "YYMM" << endl;
    else if(!fy && fm) cout << "MMYY" << endl;
    else if(fy && fm) cout << "AMBIGUOUS" << endl;
    else cout << "NA" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

	while(sc.hasNext()){
	    String[] line = sc.next().split(",");
	    int[] dist = new int[10];
	    int sum = 0;
	    int i=0;
	    for(i=0; i<dist.length; i++){
		dist[i] = Integer.parseInt(line[i]);
		sum += dist[i];
	    }
	    double[] v = new double[2];
	    v[0] = Double.parseDouble(line[i]);
	    v[1] = Double.parseDouble(line[++i]);

	    double rate = v[0]/(v[0]+v[1]);
	    //System.out.println(rate);
	    double dist2 = (double)sum*rate;

	    int ans = 0;
	    sum = 0;
	    for(i=0; i<dist.length; i++){
		if(dist2>=sum && dist2<=sum+dist[i]){ans = i; break;}
		sum += dist[i];
	    }

	    System.out.println(ans+1);
	}
    }
}

Measured memory_bytes: 11000
#include<cstdio>
#include<algorithm>
#include<vector>

#define MAX_N 1000000

using namespace std;

long long A[MAX_N];
vector<int> G;
int cnt = 0;

void printNums(int n)
{
    for (int i = 0; i < n; i++) {
        printf("%lld\n", A[i]);
    }
}

void getG(int n)
{
    int k = 1;
    while(k <= n) {
        G.push_back(k);
        k = 3 * k + 1;
    }
}

void insertSort(int n, int interval)
{
    int i, j, pivot;
    for (i = interval; i < n; i++) {
        pivot = A[i];
        j = i - interval;
        while((j >= 0) && (A[j] > pivot)) {
            A[j + interval] = A[j];
            j -= interval;
            cnt++;
        }
        A[j + interval] = pivot;
    }
}

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

    getG(n);
    printf("%d\n", G.size());
    for (i = G.size() - 1; i > 0; i--) {
        printf("%d ", G[i]);
    }
    printf("%d\n", G[0]);

    for (i = G.size() - 1; i >= 0; i--) {
        insertSort(n, G[i]);
    }
    printf("%d\n", cnt);
    printNums(n);
}

Measured memory_bytes: 10616
#include<algorithm>
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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



vll A, B;

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

    int N;
    cin >> N;

    A.resize(N);
    B.resize(N);
    rep(i, N) cin >> A[i] >> B[i];

    sort(all(A));
    sort(all(B));

    //中央値の最大値と最小値の間の値は全て実現可能
    //各X_iは区間[A_i, B_i]を動くので、適宜+1、-1すればよい
    if (N % 2 == 0)
    {
        //真ん中の2項の平均・・・0.5単位
        ll minval = A[N / 2 - 1] + A[N / 2];
        ll maxval = B[N / 2 - 1] + B[N / 2];
        cout << maxval - minval + 1 << endl;
    }
    else
    {
        //真ん中は1個だけ
        ll minval = A[N / 2];
        ll maxval = B[N / 2];
        cout << maxval - minval + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 6356
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,i,q;
    set<int> s;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>q;
        s.insert(q);
    }
    cout<<s.size()<<'\n';
    return(0);
    }

Measured memory_bytes: 3644
m,k=map(int,input().split())
if 2**m<=k or m==1 and k!=0:
    print(-1)
elif m==1 and k==0:
    print(0,0,1,1)
else:
    ans=[k]
    for i in range(2**m):
        if i!=k:
            ans.append(i)
    ans.append(k)
    for i in range(2**m):
        i=2**m-1-i
        if i!=k:
            ans.append(i)
    print(*ans)

Measured memory_bytes: 19376
X,N = map(int,input().split())
if(N==0):
    print(X)
else:
    P = [int(i) for i in input().split()]
    A = []
    for i in range(-100,201):
        if not i in P:
            A.append([abs(X-i),i])

    A.sort()
    s = A[0][0]
    B = [[i,j] for i,j in A if i==s]
    B.sort(key = lambda x:x[1])
    print(B[0][1])

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

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

    ll ans = 1;
    ll tmp = X;
    while (1) {

        tmp *= 2;
        //cout << tmp << endl;

        if (tmp > Y) break;

        ans++;
    }

    cout << ans << endl;

}


Measured memory_bytes: 3592
import collections
import math
import operator as op
from functools import reduce
import numpy as np
import math
import bisect
import heapq


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


def get_inputs(cast_func=None):
    if cast_func is None:
        return input().split()
    else:
        return list(map(cast_func, input().split()))


def get_input(cast_func=None):
    if cast_func is None:
        return input()
    else:
        return cast_func(input())


def is_prime(n):
    if n == 1:
        return False
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


def main():
    A, B, K = get_inputs(int)
    if A >= K:
        print(A-K, B)
    elif A + B >= K:
        print(0, B - (K-A))
    else:
        print(0, 0)

if __name__ == '__main__':
    main()


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

int main() {
  
  int N,K;
  cin >> N >> K;
  int h;
  
  int s=0;
  for (int i=0; i<N; i++) {
    cin >> h;
    if (K<=h) s++;
  }
  
  cout << s << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cctype>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;

int comp(const void* a, const void* b){
	return *(int*)a - *(int*)b;
}

int main() {
	int r;
	cin >> r;
	if(r < 1200){
		cout << "ABC" << endl;
	}else if(1199 < r && r < 2800){
		cout << "ARC" << endl;
	}else{
		cout << "AGC" << endl;
	}
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

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

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

        int[][] B = new int[N][2];
        for (int i = 0; i < N; i++) {
            B[i][0] = i;
            B[i][1] = 1;
        }

        long[] inconv = new long[M+1];
        inconv[M] = (long) N * (N-1)/2;


        for (int i = M-1; i >= 0 ; i--) {
            int v1 = A[i][0];
            int v2 = A[i][1];

            int l1 = findRoot(B,B[v1][0]);
            int l2 = findRoot(B,B[v2][0]);

            inconv[i] = inconv[i+1];
            if( l1 != l2){
                int s1 = B[l1][1];
                int s2 = B[l2][1];
                inconv[i] -= s1 * s2;

                if(s1<s2) {
                    int temp = l1;
                        l1 = l2;
                        l2 = temp;
                }
                B[l1][1] += B[l2][1];
                B[l2][0]=l1;
                B[l2][1] =0;
            }
        }

        for (int i = 1; i < M+1; i++) {
            System.out.println(inconv[i]);
        }

    }

    static private int findRoot(int[][] leaders, int n){
        if(leaders[n][0]==n) return n;
        return findRoot(leaders,leaders[n][0]);
    }


}


Measured memory_bytes: 102972
#include <stdio.h>
 
int main(void) {
	int s[3000],n[3000];
	int a,b,c;
	a=0;
	b=0;
	while(1){
		scanf("%d %d",&s[a],&n[a]);
		if(s[a]==0 && n[a]==0){
			break;
		}
		a++;
	}
	for(b=0;b<a;b++){
		if(s[b]>n[b]){
			c=s[b];
			s[b]=n[b];
			n[b]=c;
		}
		printf("%d %d\n",s[b],n[b]);
	}
	return 0;
}


Measured memory_bytes: 2032
s=input()
t=input()

pos=[[] for _ in range(26)]

len_s=len(s)
len_t=len(t)


for i in range(len_s):
    idx=ord(s[i])-97
    pos[idx].append(i)

ans=[]
tmp=-1
cnt=0
for i in range(len_t):
    idx=ord(t[i])-97
    if len(pos[idx])==0:
        print(-1)
        exit()

    if tmp<pos[idx][-1]:
        l=-1
        r = len(pos[idx]) - 1
        while l + 1 < r:
            mid = (l + r) // 2
            if pos[idx][mid] <= tmp:
                l = mid
            else:
                r=mid
        ans.append(pos[idx][r])
        tmp=pos[idx][r]
    else:
        cnt+=1
        ans.append(pos[idx][0])
        tmp=pos[idx][0]


print(cnt*len_s+ans[-1]+1)




Measured memory_bytes: 14404
#include<iostream>
#include<string>
using namespace std;
int main(){
	int n,p,w,a[50];
	while(true){
	cin>>n>>p;
	if(n==0&&p==0)
		break;
	for(int i=0;i<n;i++)
		a[i]=0;
	w=p-1;
	a[0]=1;
	int i=1;
	while(true){
		if(w==0){
			w=a[i];
			a[i]=0;
		}
		else if(w!=0){
			a[i]++;
			w--;
		}
		if(a[i]==p)
			break;
		i++;
		i%=n;
	}
	cout<<i<<endl;
	}
    return 0;
}

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

typedef long long ll;
using namespace std;

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

	int l,a,b,c,d; cin >> l >> a >> b >> c >> d;

	cout << min(l-((a-1)/c+1),l-((b-1)/d+1)) << endl;;

	return 0;

}



Measured memory_bytes: 3104
if __name__ == '__main__':
    from sys import stdin
    # from collections import defaultdict
    # from collections import deque
    # from collections import Counter
    # import numpy as np
    # import math
    # import random
    input = stdin.readline

    t = input()[:-1]
    n = len(t)
    count_back_1 = [0]*n
    num_of_1 = 0
    cnt = 0
    for i in range(n-1, -1, -2):
        count_back_1[i] = cnt
        if t[i] == '1':
            cnt += 1
    num_of_1 += cnt
    cnt = 0
    for i in range(n-2, -1, -2):
        count_back_1[i] = cnt
        if t[i] == '1':
            cnt += 1
    num_of_1 += cnt
    # print(num_of_1)
    # print(count_back_1)

    ans = 0

    after_first_turn = [-1]*n
    after_first_turn_index = 0

    index = 0
    count_front_1 = 0
    while index < n:
        if t[index] == '1':
            after_first_turn[after_first_turn_index] = '1'
            if index == n-1:
                after_first_turn_index += 1
                break
            after_first_turn[after_first_turn_index+1] = t[index+1]
            index += 2
            count_front_1 += 1
            after_first_turn_index += 2
        else:
            ans += count_front_1
            ans += count_back_1[index]
            index += 1

        
    len_after_first_turn = after_first_turn_index    #  - 1
    # print(after_first_turn[:len_after_first_turn])
    # print(after_first_turn)
    if len_after_first_turn % 2 == 1:
        ans += (len_after_first_turn//2+1)
        len_after_first_turn -= 1
    half = len_after_first_turn//2
    ans += half*(half+1)
    print(ans)
    
    


Measured memory_bytes: 18600
#include <bits/stdc++.h>
#include <algorithm>  
#include <unordered_set>
#define ll long long

using namespace std;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll A;
	double B;

	cin >> A >> B;

	cout << (ll)((A * B * 100) / 100) << endl;

	return 0;
}

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

int main(){
    string s,t;
    cin >> s >> t;
    int res = 0;
    rep(i,3){
        if(s[i] == t[i])res++;
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        String s = sc.nextLine();
		String mozi = "";
		for(int i = 0; i < s.length(); i++){
			char tmp = s.charAt(i);
			if('A' <= tmp && tmp <= 'Z' )
				mozi += (char)(tmp - 'A' + 'a');
			else if('a' <= tmp && tmp <= 'z')
				mozi += (char)(tmp - 'a' + 'A');
			else
				mozi += tmp;
		}
		System.out.println(mozi);
    }
}


Measured memory_bytes: 31480
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
int n; 
double rd[3005],pre[3005],l;
double PI=acos(-1);
int main()
{
	scanf("%d%lf",&n,&l);
	double sum=0;
	for(int i=1;i<=n;i++)
	{
		double k;
		scanf("%lf",&k);
		rd[i]=k/l*2*PI;
	}
	double ansx=0,ansy=0;
	sort(rd+1,rd+n+1);
	int cnt=0;
	for(int i=1;i<n;i++)
		for(int j=i+1;j<=n;j++)
		{
			ansx+=cos((rd[i]+rd[j])/2)*(i-1+n-j);
			ansy+=sin((rd[i]+rd[j])/2)*(i-1+n-j);
			ansx+=cos((rd[i]+rd[j])/2+PI)*(j-i-1);
			ansy+=sin((rd[i]+rd[j])/2+PI)*(j-i-1);
		}
	printf("%.14lf %.14lf",ansx/(1.0*n*(n-1)*(n-2)/6),ansy/(1.0*n*(n-1)*(n-2)/6));
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<map>

#define REP(i,n) for(int i=0; i<(n); i++)
#define MAX (100000)

using namespace std;

int g[200][200];

int main(){
  int n;
  while(cin>>n, n){
    map<string,int> p;
    REP(i,200) REP(j,200) g[i][j] = MAX;
    int cnt = 0;

    REP(i,n){
      string str;
      string l,r;
      int ll,rr;
      cin>>str;

      int pos = str.find('-');
      l = str.substr(0,pos);
      r = str.substr(pos+1);
      
      if(p.count(l)) ll = p[l];
      else ll = p[l] = cnt++;
      if(p.count(r)) rr = p[r];
      else rr = p[r] = cnt++;

      //printf("%s => %d  %s => %d\n",l.c_str(),ll,r.c_str(),rr);
      g[ll][rr] = 1;
    }

    int num = p.size();
    REP(i,num) for(int j=i+1; j<num; j++){
      bool a = false;
      bool b = false;

      if(g[i][j] == 1 || g[j][i] == 1) continue;

      REP(k,num){
	if(k == i || k == j) continue;
	if((g[i][k] == 1 || g[k][i] == 1) &&
	   (g[j][k] == 1 || g[k][j] == 1))
	  a = true;

	if((g[i][k] == 1 && g[k][j] == 1) ||
	   (g[k][i] == 1 && g[j][k] == 1))
	  b = true;
      }

      if(a && !b) g[i][j] = g[j][i] = 0;
    }

    REP(k,num) REP(i,num) REP(j,num)
      g[i][j] = min(g[i][j], g[i][k] + g[k][j]);

    //REP(i,num) { REP(j,num) printf("%6d ",g[i][j]); puts(""); }

    int m; cin>>m;
    printf("%d\n",num);
    REP(i,m){
      string str;
      string l,r;
      int ll,rr;
      cin>>str;

      int pos = str.find('-');
      l = str.substr(0,pos);
      r = str.substr(pos+1);
      
      if(p.count(l)) ll = p[l];
      else goto bad;
      if(p.count(r)) rr = p[r];
      else goto bad;

      if(g[ll][rr] != MAX && g[ll][rr] % 2 == 1)
	puts("YES");
      else
	puts("NO");

      continue;
    bad:
      puts("NO");
    }
  }

  return 0;
}

Measured memory_bytes: 1116
#https://atcoder.jp/contests/abc121/tasks/abc121_c

import numpy as np

n,m=map(int,input().split())

ablist=np.array([list(map(int,input().split())) for i in range(n)])

#aの昇順にソート
newablist=ablist[ablist[:,0].argsort(),:]
x=newablist


costcount=0
i=0

while i<n and x[i][1]<= m:
	m -= x[i][1]
	costcount += x[i][0]*x[i][1]
	i += 1

if i < n:
	costcount += m*x[i][0]


print(costcount)









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

int main() {
  int a;
  int b;
  cin >> a >> b;

  if (a - b * 2 < 0) {
    cout << 0 << endl;
  } else {
    cout << a - b * 2;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <sstream>
#include <cmath>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;


int main(void){

string ws,wk;
	while(getline(cin,ws)){

		stack<double> stki;
		
		stringstream zz(ws);
		double z3=0;
		

		while(zz >> wk){
			if(wk == "+" || wk == "-" || wk == "*"  || wk == "/" ) {
				if(stki.empty()) break;
				double z1 = stki.top();
				stki.pop();
				double z2 = stki.top();
				stki.pop();
				z3=0;
				if(wk=="+") z3 = z2 + z1;
				if(wk=="-") z3 = z2 - z1;
				if(wk=="*") z3 = z2 * z1;
				if(wk=="/") z3 = z2 / z1;
//				printf("z2=%f,z1=%f, z3=%f ",z2,z1,z3);
				stki.push(z3);
				
			}else{
//				stringstream wqq(wk);
//				wqq >> z3;
//				stki.push(z3);
				stki.push(atof(wk.c_str()));
				
			}
		}
		if(cin.eof()) break;
//		printf("%.6lf\n",z3);
		printf("%.6lf\n",stki.top());
	}

	return 0;
	
}

Measured memory_bytes: 1276
S=list(raw_input())

#print S

if S[0] == 'A':
    if S[1] == 'B' or S[2] == 'B':
        print 'Yes'
    else:
        print 'No'
else:
    if S[1] == 'A' or S[2] == 'A':
        print 'Yes'
    else:
        print 'No'


Measured memory_bytes: 2568
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <string.h>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
#define INF 100000000

const int MOD = 1e9+7;
typedef long long ll;
using namespace std;
const ll M = 998244353;


int main(void) {
    int n, cnt=0, sum=0;
    double m;
    cin >> n >> m;
    double a[n];
    for(int i=0;i<n;i++) {
    	cin >> a[i];
    	sum += a[i];
    }
    for(int i=0;i<n;i++) {
    	if(a[i] >= sum/(4*m)) cnt++;
    }
    if((int)m <= cnt) cout << "Yes" << endl;
    else cout << "No" << endl;

}


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

using namespace std;

#define uint unsigned int
#define llong long long int
#define ullong unsigned long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(STL) STL.begin(), STL.end()
#define stl_rep(itr, STL) for (auto itr = STL.begin(); itr != STL.end(); ++itr)

const static long long int MOD = 1000000000 + 7;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

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

    string s;
    cin >> s;
    int n = s.size(), cnt_p_of_TopCodeer = 0;
    rep(i, n) {
        if (s[i] == 'p') ++cnt_p_of_TopCodeer;
    }

    cout << floor(n / 2) - cnt_p_of_TopCodeer << endl;
    
    return 0;
}

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

int main() {
  int H,W;
  while(cin>>H&&cin>>W&&(H!=0&&W!=0)){
    for(int i=0;i<H;i++){ 
      for(int j=0;j<W;j++){
        cout<<'#';
        if(j==W-1){cout<<endl;}}
       if(i==H-1){cout<<endl;}
                  }       
      }
  return 0;
}


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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)
vector<LL>v;
int main()
{
    LL n;
    cin>>n;
    LL a[n];
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
        v.pb(a[i]);
    }
    sort(all(v));
    reverse(all(v));
    for(int i=0; i<n; i++)
    {
        if(a[i]!=v[0])
            cout<<v[0]<<"\n";
        else
            cout<<v[1]<<"\n";
    }
}


Measured memory_bytes: 6596
#n,k = list(map(int,input().split()))
s = input()
a=int(s[:2])
b=int(s[2:])

if 1<=a<=12:
  if 1<=b<=12:
    print("AMBIGUOUS")
  else:
    print("MMYY")
else:
  if 1<=b<=12:
    print("YYMM")
  else:
    print("NA")


Measured memory_bytes: 2940
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;

public class Main {

	static PrintWriter out;
	static InputReader ir;

	static void solve() {
		int tot=ir.nextInt()+ir.nextInt();
		out.println(tot>=10?"error":tot);
	}

	public static void main(String[] args) throws Exception {
		ir = new InputReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.flush();
	}

	static class InputReader {

		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;

		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}

		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[curbuf++];
			else
				return -1;
		}

		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}

		public boolean hasNext() {
			skip();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (!isSpaceChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public char[][] nextCharMap(int n, int m) {
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++)
				map[i] = next().toCharArray();
			return map;
		}
	}
}


Measured memory_bytes: 21204
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		Map<Integer,List<int[]>> map = new HashMap<>();
		int[] uft = new int[n];
		for(int i=0;i<n;i++) {
			uft[i] = i;
		}
		for(int i=0;i<m;i++) {
			int l = in.nextInt()-1;
			int r = in.nextInt()-1;
			int d = in.nextInt();
			union(uft,l,r);
			int[] tmp1 = {r,d};
			int[] tmp2 = {l,-d};
			if(map.containsKey(l)) map.get(l).add(tmp1);
			else {
				List<int[]> list = new ArrayList<>();
				list.add(tmp1);
				map.put(l, list);
			}
			if(map.containsKey(r)) map.get(r).add(tmp2);
			else {
				List<int[]> list = new ArrayList<>();
				list.add(tmp2);
				map.put(r, list);
			}
 		}
		in.close();
		
		Set<Integer> startSet = new HashSet<>();
		for(int i:map.keySet()) {
			startSet.add(find(uft,i));
		}
		
		int[] x = new int[n];
		int INF = 1000000007;
		for(int i=0;i<n;i++) {
			x[i] = INF;
		}
		Queue<Integer> que = new ArrayDeque<>();
		
		boolean flag = true;
		
		for(int start:startSet) {
			que.add(start);
			x[start] = 0;
			while(!que.isEmpty()) {
				int from = que.poll();
				List<int[]> toList = map.get(from);
				for(int[] tmp:toList) {
					int to = tmp[0];
					int dist = tmp[1];
					if(x[to]==INF) {
						x[to] = x[from] + dist;
						que.add(to);
					}else {
						if(x[to]!=x[from]+dist) {
							flag = false;
							break;
						}
					}
				}
				if(!flag) break;
			}
			if(!flag) break;
		}
		
		System.out.println(flag?"Yes":"No");
		
		
	}
	
	public static int find(int[] uft,int idx) {
		if(idx==uft[idx]) return idx;
		else return uft[idx] = find(uft,uft[idx]);
	}
	
	public static void union(int[] uft,int a,int b) {
		uft[find(uft,a)] = find(uft,b);
	}
	
}


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

int main() {
  int A, B; 
  cin >> A >> B;
  int count = 0;  
  for (int i = A; i <= B; ++i) 
  {int s= i/10000, t = i/1000 % 10, 
   u = i/100 % 10, v = i/10 % 10, w = i % 10; 
  if(s == w && t == v)
    count++; 
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  string s;
  while(cin>>s){
    int joi=0,ioi=0;
    for(int i=0;i<(int)s.size()-2;i++){
      if(s.substr(i,3)=="JOI") joi++;
      if(s.substr(i,3)=="IOI") ioi++;
    }
    cout<<joi<<endl<<ioi<<endl;
  }
  return 0;
}

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

using namespace std;
typedef long long ll;
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; }
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;

int main(){

  string s;cin>>s;
  int num=0;
  if(s=="SUN")num=7;
  else if(s=="MON")num=6;
  else if(s=="TUE")num=5;
  else if(s=="WED")num=4;
  else if(s=="THU")num=3;
  else if(s=="FRI")num=2;
  else if(s=="SAT")num=1;

  out(num);

  return 0;
}


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

long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

long long binpowmod(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

int gcd(int a, int b) {
    if (!a || !b)
        return a | b;
    unsigned shift = __builtin_ctz(a | b);
    a >>= __builtin_ctz(a);
    do {
        b >>= __builtin_ctz(b);
        if (a > b)
            swap(a, b);
        b -= a;
    } while (b);
    return a << shift;
}

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

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	ll t;
	ll n,k,sum,extra;
	// cin>>t;
	// while(t--){
		
	// }
	string s;
	cin>>n>>s;
	if (s.size()>n)
	{
		for (int i = 0; i < n; ++i)
		{
			cout<<s[i];
		}
		cout<<"...";
	}
	else{
		cout<<s;
	}
}

Measured memory_bytes: 3652
#include<iostream>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<vector>
#include<climits>
#define ll long long int
using namespace std;
int main(void) {
  int x;
  cin>>x;
  if(x%2==0)
    cout<<x<<endl;
  else
    cout<<x*2<<endl;
  return 0;
}


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

const int maxn = 20;
LL a[maxn], power[maxn], n, m, ans;

LL dfs1(LL k, LL n, LL pre){
	if (2*k+1 == m){
		LL res; a[k] = n / (power[k] + power[k-1]) - pre;
		if (a[1] <= -10 || 10 <= a[1]) return 0;
		if ((pre + a[k]) * (power[k] + power[k-1]) != n) return 0;
		if (a[1] >= 0) res = 10 - abs(a[1]) - 1;
		else res = 10 - abs(a[1]);
		for (int i=2; i<=k; i++)
			if (a[i] <= -10 || 10 <= a[i]) return 0;
			else res *= 10 - abs(a[i]);
		return res * 10;
	}
	LL res = 0, d = power[k-1] + power[m-1-k], t;
	a[k] = ((n / power[k-1] - pre) % 10 + 10) % 10; t = a[k] + pre;
	res = dfs1(k+1, n-t*d, t);
	if (t){
		a[k] -= 10; t -= 10; 
		res += dfs1(k+1, n-t*d, t);
	}
	return res;
}

LL dfs2(LL k, LL n, LL pre){
	if (2*k == m){
		LL res; a[k] = n / power[k-1] - pre;
		if (a[1] <= -10 || 10 <= a[1]) return 0;
		if (a[1] >= 0) res = 10 - abs(a[1]) - 1;
		else res = 10 - abs(a[1]);
		for (int i=2; i<=k; i++)
			if (a[i] <= -10 || 10 <= a[i]) return 0;
			else res *= 10 - abs(a[i]);
		return res;
	}
	LL res = 0, d = power[k-1] + power[m-1-k], t;
	a[k] = ((n / power[k-1] - pre) % 10 + 10) % 10; t = a[k] + pre;
	res = dfs2(k+1, n-t*d, t);
	if (t){
		a[k] -= 10; t -= 10; 
		res += dfs2(k+1, n-t*d, t);
	}
	return res;
}

int main(){
	scanf("%lld", &n);
	if (n % 9) { puts("0"); return 0; }
	n /= 9; power[0] = 1;
	for (int i=1; i<=18; i++) power[i] = power[i-1] * 10;
	for (int i=2; i<=18; i++){
		if (i&1) { m = i; ans += dfs1(1, n, 0); }
		else { m = i; ans += dfs2(1, n, 0); }
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
# https://note.nkmk.me/python-format-zero-hex/
while 1:
    t,h,s = map(int, input().split())
    if t==h==s==-1:
        break
    rest_time = 7200-(t*3600+h*60+s)
    print('{:02d}:{:02d}:{:02d}'.format(rest_time//3600, (rest_time%3600)//60, rest_time%60))
    rest_time_3 = rest_time*3
    print('{:02d}:{:02d}:{:02d}'.format(rest_time_3//3600, (rest_time_3%3600)//60, rest_time_3%60))


Measured memory_bytes: 5604
//
// Created by 倉澤　一詩 on 2019-07-31.
//
#include <iostream>
#include <vector>


int main (){

    int n;
    int m;
    int sum_time;

    std::cin >> n;
    std::vector<int> t(n);

    for (auto& time : t) {
        std::cin >> time;
    }

    std::cin >> m;

    std::vector<int> p(m);
    std::vector<int> x(m);

    for (int i = 0; i < p.size(); i++) {
        std::cin >> p[i];
        std::cin >> x[i];
    }

    std::cout << std::endl;

    for (int i = 0; i < p.size(); i++) {

        sum_time = 0;

        for (int j = 0; j < t.size(); j++) {
            if((p[i]-1) != j) sum_time += t[j];
        }

        sum_time += x[i];

        std::cout << sum_time << std::endl;
    }

//デバッグ用
//    std::cout << n << std::endl;
//
//    for (int i = 0; i < n; ++i) {
//        std::cout << t[i] << " ";
//
//    }
//    std::cout << std::endl;
//
//    std::cout << m << std::endl;
//
//    for (int i = 0; i < p.size(); ++i) {
//        std::cout << p[i] << " " << x[i] << std::endl;
//    }
/////////

    return 0;
}

Measured memory_bytes: 256
while 1:
  s,t= map(int,input().split())
  if s+t == 0:break
  c=0
  for i in range(1,s+1):
    for j in range(i+1,s+1):
      for k in range(j+1,s+1):
        if i+j+k ==t:c+=1
  print(c)


Measured memory_bytes: 5592
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;
//int divr[maxn];
/*ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}
void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
















const int N=200005;
ll C;
ll n;
ll h[N];
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
deque<line> dq;
int main()
{
     cin>>n>>C;
     for(int i=0;i<n;i++)cin>>h[i];
     dq.push_back({-2LL*h[0],h[0]*h[0]});
     ll ans=0LL;
     for(int i=1;i<n;i++)
     {
          while(dq.size()>=2&&dq[0].eval(h[i])>=dq[1].eval(h[i]))dq.pop_front();
          ans=1LL*dq[0].eval(h[i])+h[i]*h[i]+C;
          line cur={-2LL*h[i],ans+h[i]*h[i]};
          while(dq.size()>=2&&dq.back().intersectX(cur)<=dq[dq.size()-2].intersectX(dq.back()))dq.pop_back();
          dq.push_back(cur);



     }
     cout<<ans;
}
























 

Measured memory_bytes: 3968