akhauriyash/Code-Regression huggingface dataset:
//
// Created by chuta on 2020/09/19.
//

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main() {
    //CFS;
    ll n;
    int q;
    cin >> n >> q;
    n -= 2;
    ll mi1 = n, mi2 = n;
    vl v1(n + 1, IINF), v2(n + 1, IINF);
    vl g1(n, false), g2(n, false);
    v1[n] = n, v2[n] = n;
    rep(i, q) {
        int c, x;
        cin >> c >> x;
        x -= 2;
        if (c == 1) {
            if (x < mi1) {
                v1[x] = mi2;
                mi1 = x;
            }
            g1[x] = true;
        } else {
            if (x < mi2) {
                v2[x] = mi1;
                mi2 = x;
            }
            g2[x] = true;
        }
    }
    ll ans = n * n;
    ll pre1, pre2;
    rep(i, n) {
        if (v1[i] != IINF) pre1 = v1[i];
        if (v2[i] != IINF) pre2 = v2[i];
        if (g1[i]) ans -= pre1;
        if (g2[i]) ans -= pre2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9588
#include<bits/stdc++.h>
using namespace std;
int n;
void dfs(int i, string s, char c){
    if(i == n) {
        cout << s << endl;
    }
    else{
        for (char j = 'a'; j <= c + 1; j++)
        {
            string t = s + j;
            dfs(i+1,t,max(c,char(j)));
        }
        
    }
}


int main(){
    cin >> n;
    dfs(1,"a",'a');
}

Measured memory_bytes: 3592
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }

char S[333];
int K;
int memo[333][333][333];

int solve(int a, int b, int u) {
  if (memo[a][b][u] >= 0) {
    return memo[a][b][u];
  }
  int& r = memo[a][b][u];
  if (a > b) {
    return r = 0;
  }
  if (a == b) {
    return r = 1;
  }

  if (S[a] == S[b]) {
    return r = solve(a + 1, b - 1, u) + 2;
  }
  r = 0;
  chmax(r, solve(a + 1, b, u));
  chmax(r, solve(a, b - 1, u));
  if (u > 0) {
    chmax(r, solve(a + 1, b - 1, u - 1) + 2);
  }
  return r;
}

int main() {
  scanf("%s", S);
  K = in();
  const int L = strlen(S);
  for (int i = 0; i <= L; ++i) {
    for (int j = 0; j <= L; ++j) {
      fill(memo[i][j], memo[i][j] + L + 1, -1);
    }
  }

  printf("%d\n", solve(0, strlen(S) - 1, K));

  return 0;
}


Measured memory_bytes: 131200
import java.util.*;
public class Main {
	
	static int N;
	static int[] ans;
	static Map<Integer, HashSet<edge>> m = new HashMap<>();
	
	static class edge{
		int st, end, id;
		edge(int st, int end, int id){
			this.st = st;
			this.end = end;
			this.id = id;
		}
	}
	
	static void dfs(int now, int prev) {
		int color = 1;
		if(!m.containsKey(now))
			return;
		for(edge e : m.get(now)) {
			if(color == prev)
				color++;
			dfs(e.end, color);
			ans[e.id] = color;
			color++;
		}
		
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		ans = new int[N];
		for(int i = 0; i < N-1; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			if(!m.containsKey(a))
				m.put(a, new HashSet<>());
			m.get(a).add(new edge(a, b, i));
		}
		dfs(1, -1);
		int max = 0;
		StringBuilder a = new StringBuilder();
		for(int i = 0; i < N-1; i++) {
			a.append(ans[i] + "\n");
			max = Math.max(max, ans[i]);
		}
		System.out.println(max);
		System.out.print(a);

	}

}

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

struct Directions
{
	int E[6] = { 2, 1, 5, 0, 4, 3 };
	int W[6] = { 3, 1, 0, 5, 4, 2 };
	int N[6] = { 4, 0, 2, 3, 5, 1 };
	int S[6] = { 1, 5, 2, 3, 0, 4 };
	int Rotate[6] = { 0, 2, 4, 1, 3, 5 };
};

class Dice
{
public:
	int num[6];
	void swap(int*);
	Directions dir_array;
	Dice();
	void roll(char);
	void show_num(int);
};

Dice::Dice()
{
	Directions direction;
	for (int i = 0; i < 6; i++)
		cin >> this->num[i];
}

void Dice::roll(char c)
{
	switch (c)
	{
	case 'E':
		this->swap(dir_array.E);
		break;
	case 'W':
		this->swap(dir_array.W);
		break;
	case 'N':
		this->swap(dir_array.N);
		break;
	case 'S':
		this->swap(dir_array.S);
		break;
	case 'R':
		this->swap(dir_array.Rotate);
		break;
	}
	return;
}

void Dice::swap(int *dir)
{
	int tmp[6];
	for (int i = 0; i < 6; i++)
		tmp[dir[i]] = num[i];
	for (int i = 0; i < 6; i++)
		num[i] = tmp[i];
	return;
}

void Dice::show_num(int i)
{
	cout << this->num[i] << endl;
	return;
}

int check(Dice* dice)
{
	int tmpf, flag = 0;
	for (int i = 0; i < 4; i++) {
		tmpf = 1;
		for (int j = 0; j < 6; j++)
			if (dice[0].num[j] != dice[1].num[j])
			{
				tmpf = 0;
				break;
			}
		if (tmpf)
			flag = 1;
		dice[1].roll('R');
	}
	return flag;
}

int main()
{
	int flag = 0;
	Dice dice[2];

	for (int i = 0; i < 4; i++)
	{
		flag += check(dice);
		dice[1].roll('E');
	}
	dice[1].roll('N');
	flag += check(dice);
	dice[1].roll('N');
	dice[1].roll('N');
	flag += check(dice);
	if (flag)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 3132
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)


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

    ll a;
    multiset<ll, greater<ll> > A;
    rep(i, N){
        cin >> a;
        A.insert(a);
    }

    rep(i, M){
        a = *A.begin();
        A.erase(A.begin());
        a /= 2;
        A.insert(a);
    }

    ll ans = 0;
    for(multiset<ll, greater<ll> >::const_iterator it = A.begin(); it != A.end(); it++){
        ans += *it;
    }
    cout << ans << endl;

    return 0;
}




Measured memory_bytes: 8196
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // 標準入力から値を取得してinput_lineに入れる
        int input_line = sc.nextInt()*2;

        // 取得した値を標準出力するために"XXXXXX"をどう書き換える？
        System.out.println(input_line * 3.14159);
    }
}

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

immutable long MOD = 10^^9 + 7;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto K = s[1];
    auto A = readln.split.map!(to!int).array;

    auto dp = new long[][](N+1, K+10);
    dp[0][K] = 1;

    foreach (i; 0..N) {
        foreach (j; 0..K+1) {
            (dp[i+1][max(0, j-A[i])] += dp[i][j]) %= MOD;
            (dp[i+1][j+1] -= dp[i][j]) %= MOD;
        }
        foreach (j; 0..K+1) {
            (dp[i+1][j+1] += dp[i+1][j]) %= MOD;
        }
    }

    long ans = (dp[N][0] + MOD) % MOD;
    ans.writeln;
}


Measured memory_bytes: 80380
package main

import "math"
import "fmt"

func main(){
    var num int
    var t, a int
    var h []int

    fmt.Scanf("%d", &num)
    var tmp = scanNums(2)
    t, a = tmp[0], tmp[1]
    h = scanNums(num)

    a_float64 := float64(a)

    diff := math.MaxFloat64
    
    target_i := -1
    for i:=0; i<num; i++{
        temp := float64(t) - float64(h[i])*0.006
        if math.Abs(temp-a_float64) < diff {
            target_i = i
            diff = math.Abs(temp - a_float64)
        }
    }
    fmt.Printf("%d\n", target_i+1)
}

/**
 * １行に空白区切りで数字を読み込み
 */
func scanNums(len int) (nums []int) {
	nums = make([]int, len)
	for i := 0; i < len; i++ {
		fmt.Scan(&nums[i])
	}
	return
}

func absint(x int) int{
    if x < 0{
        return -x
    }
    return x
}


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

using namespace std;

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(a + b > c + d){
        cout << "Left";
    }else if(a + b < c + d){
        cout << "Right";
    }else{
        cout << "Balanced";
    }
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
using namespace std;
typedef long long ll;

int main(){
    int n, ans = 0;
    cin >> n;
    string s;
    cin >> s;
    for(int i = 0; i < n-2; ++i){
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C'){
            ++ans;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
N = int(input())
W = [input() for _ in range(N)]
d = set()
last = ""
for i in range(N):
    if W[i] in d:
        print("No")
        sys.exit()
    if last != "" and last != W[i][0]:
        print("No")
        sys.exit()
    last = W[i][-1]
    d.add(W[i])

print("Yes")

Measured memory_bytes: 3064
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

const ll mod = 1e9 + 7;
const ll inf = 1e18;

struct Operation{
    int i0;
    int j0;
    int i1;
    int j1;
    
    Operation(int a, int b, int c, int d){
        i0 = a;
        j0 = b;
        i1 = c;
        j1 = d;
    }
};

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

    // input
    ll H, W;
    cin >> H >> W;

    vector<vector<ll> > A(H);
    FOR(i, 0, H){
        FOR(j, 0, W){
            ll a;
            cin >> a;
            A[i].push_back(a);
        }
    }

    vector<Operation> OP;

    FOR(i, 0, H){
        FOR(j, 0, W-1){
            if(A[i][j]%2==1){
                A[i][j]--;
                A[i][j+1]++;
                OP.push_back(Operation(i, j, i, j+1));
            }
        }
    }
    FOR(i, 0, H-1){
        if(A[i][W-1]%2==1){
            A[i][W-1]--;
            A[i+1][W-1]++;
            OP.push_back(Operation(i, W-1, i+1, W-1));
        }
    }

    p(OP.size());
    for(auto op : OP){
        cout << op.i0+1 << " " << op.j0+1 << " " << op.i1+1 << " " << op.j1+1 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 6264
import java.util.*;

class Main {
        public static void main(String args[]) {
                try (Scanner sc = new Scanner(System.in)) {
                        int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt();
                        int ans = 0;
                        for (int i = a; i <= b; i++) {
                                if (c % i == 0) {
                                        ans++;
                                }
                        }
                        System.out.println(ans);
                }
        }
}

Measured memory_bytes: 26260
#include <iostream>
#include <map>
#include <algorithm>

using namespace std;

int main()
{
    int n, q;

    while (cin >> n >> q, n || q) {
        map<int, int> look;
        int m, d;
        
        for (int i = 0; i < n; i++) {
            cin >> m;
            for (int j = 0; j < m; j++) {
                cin >> d;
                if (look.count(d) == 0) 
                    look[d] = 1;
                else
                    look[d]++;
            }
        }

        map<int, int>::iterator it = look.begin();
        int num = 0;
        int day = 0;
        while (it != look.end()) {
            if ((*it).second >= q && (*it).second > num) {
                day = (*it).first;
                num = (*it).second;
            }
            it++;
        }
        if (num >= q)
            cout << day << endl;
        else
            cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 1200
#include<iostream>
#include<cstring>
#include<algorithm>
#include<math.h>
using namespace std;
int main()
{
    long long int i,n,j=0,k,t,c,d,b,a[60];
    cin>>n;
    for(i=0;i<n;i++)
{
    cin>>a[i];
    if(a[i]!=i+1)
    j++;
}
if(j==2 ||j==0)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}


Measured memory_bytes: 3056
N, K = map(int, input().split())

A = [list(map(int,input().split())) for _ in range(2*K)]

Pocession = [False for _ in range(N)]
for i, poc in enumerate(A):
    if i %2 == 1:
        for po in poc:
            Pocession[po-1] = True

print(Pocession.count(False))

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

 
int main() {
    ll a,b,c;
    cin >> a >> b >> c;
    if(b > c || (a==1&&c!=b)){
        cout << 0 << endl;
    } else {
        cout << (c*(a-1)+b) - (b*(a-1)+c) + 1 << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
int year,month,date;

while(cin>>year>>month>>date){
if(year<1868||year==1868&&month<9||year==1868&&month==9&&date<8)cout<<"pre-meiji"<<endl;
else if(year<1912||year==1912&&month<7||year==1912&&month==7&&date<30)cout<<"meiji "<<year-1867<<" "<<month<<" "<<date<<endl;
else if(year<1926||year==1926&&month<12||year==1926&&month==12&&date<25)cout<<"taisho "<<year-1911<<" "<<month<<" "<<date<<endl;
else if(year<1989||year==1989&&month==1&&date<8)cout<<"showa "<<year-1925<<" "<<month<<" "<<date<<endl;
else cout<<"heisei "<<year-1988<<" "<<month<<" "<<date<<endl;
}
}

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

int main() {

  int n, m;
  cin >> n >> m;

  int l_max = 0, r_min = n;
  for(int j = 0; j < m; j++) {
    int l, r;
    cin >> l >> r;
    if(l > l_max) l_max = l;
    if(r < r_min) r_min = r;
  }

if(l_max > r_min) cout << 0 << endl;
else cout << r_min - l_max + 1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	int a[102];
	cin>>n;
	for(int i=0;i<=n-1;i++)
		cin>>a[i];
	sort(a,a+n);
	int alice=0,bob=0;
	if(n%2==0){
		for(int i=0;i<=n-1;i++){
			if((i+2)%2==0)
				alice+=a[i];
			else
				bob+=a[i];
		}
		cout<<bob-alice<<endl;
		return 0;
	}else{
		for(int i=0;i<=n-1;i++){
			if((i+2)%2==1)
				alice+=a[i];
			else
				bob+=a[i];
		}
		cout<<bob-alice<<endl;
		return 0;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll T1, T2, A1, A2, B1, B2;
  cin>>T1>>T2>>A1>>A2>>B1>>B2;
  if((A1-B1)*T1==-(A2-B2)*T2) {
    cout<<"infinity"<<endl;
    return 0;
  }
  if((A1>B1 && A2>B2>0) || (A1<B1 && A2<B2)) {
    cout<<0<<endl;
    return 0;
  }
  if(abs(A1-B1)*T1>abs(A2-B2)*T2) {
    cout<<0<<endl;
    return 0;
  }
  ll s = abs(abs(A2-B2)*T2-abs(A1-B1)*T1);
  if(abs(A1-B1)*T1%s==0) {
    cout<<abs(A1-B1)*T1/s*2<<endl;
  }
  else {
    cout<<abs(A1-B1)*T1/s*2+1<<endl;
  }
}



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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descsort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

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

    cout<<s.substr(0,s.rfind("FESTIVAL"))<<endl;
    return 0;
}

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

int A,B,C,K;
int main() {
    //cout<<"here we go\n";
    cin>>A>>B>>C>>K;
    int a[3], mutiplier[3];
    
    a[0] = A;
    a[1] = B;
    a[2] = C;
    
    mutiplier[0]=1;
    mutiplier[1]=0;
    mutiplier[2]=-1;

    int ans = 0;
    int cnt = 0;
    while(K>0 && cnt<3){
        if(a[cnt]>K){
            ans += mutiplier[cnt]*K;
            break;
        }else{
            ans += mutiplier[cnt]*a[cnt];
            K -= a[cnt];
        }
        cnt++;
    }
    
    cout<<ans;
    
    return 0;
}


Measured memory_bytes: 3172
n = int(input())
dp = [0 for i in range(n+1)]
dp[0] = 1
mod = 1000000007
for i in range(3,n+1):
  for j in range(i-3,-1,-1):
    dp[i]+= dp[j]
    dp[i]%=mod
print(dp[-1])

Measured memory_bytes: 9108
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
	int n, k;
	scanf("%d %d", &n, &k);
	double a[n], s = 0;
	for (int i = 0; i < n; i++){
		scanf("%lf", &a[i]);
		a[i] = 1 + (a[i] - 1) / 2.0;
	}
	for (int i = 0; i < k; i++) s += a[i];
	double ans = s;
	for (int i = k; i < n; i++){
		s += a[i];
		s -= a[i - k];
		ans = max(ans, s);
	}
	printf("%.6lf\n", ans);
}

Measured memory_bytes: 1664
h,w=map(int,input().split())
s=['#'*(w+2)]
s+=['#'+input()+'#' for _ in range(h)]
s.append('#'*(w+2))
h+=2
w+=2
p=[[1,0],[0,1],[-1,0],[0,-1]]
st=[]
cnt=0
for i in range(h):
    for j in range(w):
        if s[i][j]=='.':
            st.append((i,j))
            cnt+=1
ans=0
for i in range(cnt):
    n=[st[i]]
    route={n[0]:0}
    c=1
    count=1
    while c<cnt:
        n2=[]
        for i in n:
            for j in p:
                np=(i[0]+j[0],i[1]+j[1])
                if s[np[0]][np[1]]=='.' and route.get(np,-1)==-1:
                    n2.append(np)
                    route[np]=count
                    c+=1
        n=n2
        count+=1
    ans=max(ans,count-1)
print(ans)

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

int main()
{
    int n;
    string s;
    cin>>n;
    fflush(stdin);
    cin>>s;
    int l=s.length();
    if(n<l){
        for(int i=0;i<n;i++)
        {
            cout<<s[i];
        }
        cout<<"...";
    }
    else{
        for(int i=0;i<l;i++)
        {
            cout<<s[i];
        }
    }


}


Measured memory_bytes: 3596
#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

struct Node {
    int key;
    Node *prev, *next;
};

// ??????????????????????????????
// *??????????????£?¨?????????¨????????????????§????????????°?????????
// ????????????????????????????????¢?????¬??????????????????????????????????????°??????????????????????????§?????????
// nil = ?§????????????°?????¢?????¬???
Node *nil;

void init() {
    nil = (Node *)malloc(sizeof(Node));
    // ?????????????????°????????????????????¢???????????????
    nil -> next = nil;
    nil -> prev = nil;
}

void insert(int key) {
    Node *x = (Node *)malloc(sizeof(Node));
    x -> key = key;

    // ???????????´??????????´??????????
    x -> next = nil -> next;//x's next = nil's next
    nil -> next -> prev = x;//nil's next's prev = x
    nil -> next = x;//nil's next = x
    x -> prev = nil;//x's prev = nil
}

Node* listSearch(int key) {
    Node *cur = nil -> next;//??????????¬????????´????????????????

    while (cur != nil && cur -> key != key) {
        cur = cur->next;
    }
    return cur;
}

void deleteNode(Node *t) {
    if (t == nil) return;//t??????????????¨?????????????????????
    t -> prev -> next = t -> next;
    t -> next -> prev = t -> prev;
    free(t);
}

void deleteFirst() {
    deleteNode(nil -> next);
}

void deleteLast() {
    deleteNode(nil -> prev);
}

void deleteKey(int key) {
    // ????´¢????????????????????????
    deleteNode(listSearch(key));
}

void printList() {
    Node *cur = nil->next;
    int isf = 0;

    while(1) {
        if (cur == nil) break;
        if (isf++ > 0) printf(" ");
        printf("%d", cur->key);
        cur = cur -> next;
    }
    printf("\n");
}

int main(){
    int n, m;
    string order;
    init();
    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> order;

        if (order == "insert") {
            cin >> m;
            insert(m);
        } else if (order == "delete") {
            cin >> m;
            deleteKey(m);
        } else if (order == "deleteFirst") {
            deleteFirst();
        } else if (order == "deleteLast") {
            deleteLast();
        } else {
            cout << "error" << endl;
        }
    }

    printList();

    return 0;
}

Measured memory_bytes: 34432
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
// #define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
const int mod = 1000000007;
ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }



void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}

// https://qiita.com/nomikura/items/4167cb3a7a889988e3b3
// https://kyopro-friends.hatenablog.com/entry/2019/01/12/231106

void solve() {
  int n;
  cin >> n;
  ll a[n][n];
  rep(i, n) rep(j, n) cin >> a[i][j];
  vector<ll> dp(1 << n); // 集合 S に属するウサギのグループ分けの最高得点

  vector<ll> score(1 << n);
  rep(i, 1 << n) {
    rep(j, n) rep(k, j) {
      if ((i & (1 << j)) and (i & (1 << k))) {
        score[i] += a[j][k];
      }
    }
  }

  rep(i, 1 << n) {
    int unused = i ^ ((1 << n) - 1);
    for (int j = unused; j > 0; j = (j - 1) & unused) { // unused の部分集合
      chmax(dp[j | i], dp[i] + score[j]);
    }
  }

  cout << dp[(1 << n) - 1] << endl;
  // rep(i, 1 << n) cout << bitset<16>(i) << " " << dp[i] << endl;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define R(n)for(L i=0;i<n;i++)
#define M make_pair
typedef long L;using namespace std;int main(){L n,k,s,t,a[50];cin>>n>>k>>s>>t;R(n)cin>>a[i];map<pair<L,L>,L> p[50];R(n){for(L j=k-1;j;j--)for(auto&l:p[j-1])p[j][M(l.first.first&a[i],l.first.second|a[i])]+=l.second;p[0][M(a[i],a[i])]=1;}n=0;R(k)n+=p[i][M(s,t)];cout<<n;}

Measured memory_bytes: 153904
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 50;
int A[MAXN], gf[MAXN], gb[MAXN];

main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int N; cin >> N;
    for (int i=1; i<=N; i++) cin >> A[i];
    for (int i=1; i<=N; i++) gf[i] = __gcd(gf[i-1], A[i]);
    for (int i=N; i>=1; i--) gb[i] = __gcd(gb[i+1], A[i]);
    int ans = 0;
    for (int i=1; i<=N; i++){
        ans = max(ans, __gcd(gf[i-1], gb[i+1]));
    }
    cout << ans;
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;

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

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    CIN(string, S);

    int count = 0;
    for (int i = 1; i < S.size(); i++) {
        if ( S[i] != S[i-1] ) count++;
    }

    cout << count << "\n";
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
const double pi = 3.14159265358979;

int k, a, b;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> k >> a >> b;
	for(int i = a; i <= b; i++)
		if(i % k == 0){
			cout << "OK\n";
			return 0;
		}
	cout << "NG\n";
	return 0;
}

Measured memory_bytes: 3676
import java.util.Scanner;

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

        for (int a = 0; a <= n; a++) {
            for (int b = 0; b <= n; b++) {
                if (n - a - b < 0) {
                    continue;
                }

                if (10000 * a + 5000 * b + 1000 * (n - a - b) == y) {
                    System.out.println(
                            String.format("%d %d %d", a, b, (n - a - b))
                    );
                    return;
                }
            }
        }
        System.out.println("-1 -1 -1");
    }
}



Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int A,B;
int d[11][11];
const int T = 100;

int c[T+1][T+1];

int main(){
	cin>>A>>B;
	rep1(x,A) rep1(y,B) cin>>d[x][y];
	rep(i,T+1) rep(j,T+1){
		int cij = 0;
		rep1(x,A) rep1(y,B) chmax(cij,d[x][y]-x*i-y*j);
		c[i][j] = cij;
	}

	rep1(x,A) rep1(y,B){
		int dxy = 1e9;
		rep(i,T+1) rep(j,T+1) chmin(dxy,x*i+y*j+c[i][j]);
		if(dxy != d[x][y]){
			puts("Impossible");
			return 0;
		}
	}
	puts("Possible");
	int N = (T+1)*2, M = T*2 + (T+1)*(T+1);
	cout<<N<<" "<<M<<endl;
	rep(t,T){
		cout<<1+t<<" "<<2+t<<" X"<<endl;
	}
	rep(t,T){
		cout<<T+3+t<<" "<<T+2+t<<" Y"<<endl;
	}
	rep(i,T+1) rep(j,T+1){
		cout<<1+i<<" "<<T+2+j<<" "<<c[i][j]<<endl;
	}
	cout<<1<<" "<<T+2<<endl;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  string o, e;
  cin >> o >> e;
  for (int i = 0; i < e.length(); ++i) cout << o[i] << e[i];
  if(o.length() > e.length()) cout << o[o.length() - 1];

  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;
public class Main {
    static String[] map;
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        while(stdIn.hasNext()) {
            map = new String[8];
            for(int i = 0; i < 8; i++) {
                map[i] = stdIn.next();
            }
            int ans = solv();
            System.out.println(B[ans]);
        }
    }
     
    public static int solv() {
        for(int i = 0; i < 8; i++) {
            for(int j = 0; j < 8; j++) {
                CON:for(int k = 0; k < A.length; k++) {
                    if(i + A[k].length > 8) {
                        continue CON;
                    }
                    for(int l = 0; l < A[k].length; l++) {
                        if(j + A[k][0].length() > 8) {
                            continue CON;
                        }
                        if(!map[i+l].substring(j, j+A[k][0].length()).equals(A[k][l])) {
                            continue CON;
                        }
                    }
                    return k;
                }
            }
        }
        return -1;
    }
    static String[][] A = new String[][]{{"11","11"},{"1","1","1","1"},{"1111"},{"01","11","10"},{"110","011"},{"10","11","01"},{"011","110"}};
    static String[] B = new String[]{"A","B","C","D","E","F","G"};
     
     
 
     
}


Measured memory_bytes: 27836
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
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; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

void  base_num(ll data,ll base){
    if(data==0) return;
    ll next=abs(data)%abs(base);
    if(data<0) next=(abs(base)-next)%abs(base);
    base_num((data-next)/base,base);
    cout << next;
}


int main(){
    string s,t;
    cin >> s >> t;
    if (s.size()!=t.size()-1){
        cout << "No" << endl;
        return 0;
    }
    for (ll i=0;i<s.size();i++){
        if (s[i]!=t[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}
 
 


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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;

#define TT template<typename T>
#define ET(T) typename T::value_type
TT inline T sq(T x){return x*x;}
TT inline T In(){T x;cin>>x;return x;}
TT inline int ubnd(T&v,ET(T) x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT inline int lbnd(T&v,ET(T) x){return lower_bound(begin(v),end(v),x)-begin(v);}
TT inline void sort(T&v){sort(begin(v),end(v));}
TT inline void revs(T&v){reverse(begin(v),end(v));}
TT inline void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT inline void inpt(T&v,int n,function<ET(T)()>f=In<ET(T)>){for(v.reserve(n);n--;v.emplace_back(f()));}
TT inline void show(T&v,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),cout<<x;cout<<e;}
#undef TT
#undef ET

inline void fast_io(){ios::sync_with_stdio(0); cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline string instr(){string x;cin>>x;return x;}
inline ll pow_mod(ll a, ll k, ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a, ll p){return pow_mod(a,p-2,p);}

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

int main()
{
  fast_io();

  vector<int> c, q;
  int N, Q;
  cin >> N >> Q;
  inpt(c, N);
  inpt(q, Q);
  sort(c);
  revs(c);
  int mbucket[300001] = {};
  for (const auto& ci : c){
    for (int x = ci + 1; x <= 300000; x++){
      if (mbucket[x]) break;
      mbucket[x] = ci;
    }
  }
  for (const auto& qi : q){
    int maxi = 0;
    for (int x = qi; x <= 300000; x += qi){
      maxi = max(maxi, mbucket[x] % qi);
    }
    cout << maxi << "\n";
  }
  return (0);
}

// priority_queue queue deque front top push pop map set stringstream max_element min_element insert count find get tie make_tuple

Measured memory_bytes: 3900
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sca = new Scanner(System.in);
		int n = sca.nextInt();
		long sum = 0L;
		for(int i = 1; i <= n; i++) {
			if(i % 3 == 0 && i % 5 == 0) {
				// FizzBuzz
			}
			else if(i % 3 == 0 || i % 5 == 0) {
				// Fizz, Buzz
			}
			else {
				sum += i;
			}
		}
		System.out.println(sum);

		// 後始末
		sca.close();
	}
}

Measured memory_bytes: 35720
#include<bits/stdc++.h>
#define ll  long long
#define pp pair<int,int>
#define ppn pair<pp,int>
#define F first
#define S second
#define N 1000005
#define mod 1000000007
#define pi 3.14159265358979323846

using namespace std;




int main()
{


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

    int n;
    cin>>n;
    for(int i=0; i<n; i++)cout<<"ACL";
    cout<<endl;
}


Measured memory_bytes: 3568
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int H,W;
    
    while(true){
        cin >> H >> W;
        if(H == 0 && W == 0)break;
        
        for(int i = 0; i < H; i++){
            for(int n = 0; n < W; n++){
                if((i + n) % 2){
                    cout << ".";
                }else{
                    cout << "#";
                }
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 3076
import java.util.Scanner;

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

        String S = scanner.next();

        String First = S.substring(0, 2);
        String Second = S.substring(2, 4);

        int first = Integer.parseInt(First);
        int second = Integer.parseInt(Second);

        boolean yymm = false;
        boolean mmyy = false;

        if(0 <= first && first <= 99 && 1 <= second && second <= 12){
            yymm = true;
        }

        if(0 <= second && second <= 99 && 1 <= first && first <= 12){
            mmyy = true;
        }

        if(yymm && !mmyy){
            System.out.println("YYMM");
        }else if(!yymm && mmyy){
            System.out.println("MMYY");
        }else if(!yymm && !mmyy){
            System.out.println("NA");
        }else{
            System.out.println("AMBIGUOUS");
        }

    }
}


Measured memory_bytes: 21972
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

ll mod = 998244353;
int dp[200010][3][3][2];

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	string s;
	cin >> s;
	int n = s.size();
	int ans = 0;
	bool allsame = true;
	bool notsame = true;
	rep(i, n - 1) {
		if (s[i] == s[i + 1]) notsame = false;
		else allsame = false;
	}
	if (allsame) {
		cout << 1 << endl;
		return 0;
	}
	if (n == 2) {
		cout << 2 << endl;
		return 0;
	}
	if (n == 3) {
		if (notsame) {
			if (s[0] != s[2]) cout << 3 << endl;
			else cout << 7 << endl;
		}
		else {
			cout << 6 << endl;
		}
		return 0;
	}
	if (n >= 4) {
		if (notsame) ans++;
		dp[0][0][0][0] = 1;
		dp[0][1][1][0] = 1;
		dp[0][2][2][0] = 1;
		for (int i = 1; i < n; i++) {
			for (int j = 0; j < 3; j++) {
				for (int k = 0; k < 3; k++) {
					for (int l = 0; l < 3; l++) {
						if (k == l) {
							dp[i][(j + l) % 3][l][1] += dp[i - 1][j][k][0] + dp[i - 1][j][k][1];
							dp[i][(j + l) % 3][l][1] %= mod;
						}
						else {
							for (int m = 0; m < 2; m++) {
								dp[i][(j + l) % 3][l][m] += dp[i - 1][j][k][m];
								dp[i][(j + l) % 3][l][m] %= mod;
							}
						}
					}
				}
			}
		}
		int p = 0;
		rep(i, n) {
			int pl = s[i] - 'a';
			p += pl; p %= 3;
		}
		for (int k = 0; k < 3; k++) {
			ans += dp[n - 1][p][k][1];
			ans %= mod;
		}
		cout << ans << endl;
	}
}

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

using namespace std;

int main() {

  int k, s;
  cin >> k >> s;

  int count = 0;

  for (int x = 0; x <= k; x++) {
    for (int y = 0; y <= k; y++) {
      if (0 <= s - x - y && s - x - y <= k)
        count++;
    }
  }

  cout << count << "\n";

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool visited[1000001];
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int s; int tmp = 0; vector<int> v(1000001, 0);
	cin >> s;
	memset(visited, false, sizeof(visited));
	while(true){
		tmp++;
		v[tmp-1] = s;
		//cerr << v[tmp-1] << "\n";
		if(s%2 == 0) s /= 2;
		else s = 3*s + 1;
		if(tmp == 1000000) break; 
	}
	//cout << v[0] << "\n";
	for(int i=0;i<100000;i++){
		//cerr << v[i] << "\n";
		if(!visited[v[i]]) visited[v[i]] = true;
		else{
			cout << i+1 << "\n";
			return 0;
		} 
	}
	return 0;
}

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

using namespace std;

typedef long long ll;

const int MAX_N = 2e5 + 5;

int n;
int a[MAX_N];
map<int, ll> dp[MAX_N];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	dp[0][0] = 0;
	dp[1][1] = a[1];
	for (int i = 1; i <= n; ++i) {
		for (int k = max(0, i / 2 - 5); k <= min(n / 2, i / 2 + 5); ++k) {
			if (dp[i - 1].count(k)) {
				dp[i][k] = dp[i - 1][k];
			}
			for (int p = max(0, i - 4); p < i - 1; ++p) {
				if (dp[p].count(k - 1)) {
					if (dp[i].count(k)) {
						dp[i][k] = max(dp[i][k], dp[p][k - 1] + a[i]);
					} else {
						dp[i][k] = dp[p][k - 1] + a[i];
					}
				}
			}
		}
	}
	cout << dp[n][n / 2] << "\n";
	return 0;
}

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

int main()
{
  int k;
  cin>>k;
  string s;
  cin>>s;
  
  if(s.size() <= k)
    cout<<s<<endl;
  else
  {
 	string ans = "";
    for(int i = 0; i<k; i++)
      ans += s[i];
    ans += "...";
    cout<<ans<<endl;
  }
 
  return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
using ll = long long; // ll は long long　と同じとする。(int64_t)
int main() {
    int n;
	string s;
	cin >> n >> s;
 
	long long r, g, b;
	r = count(s.begin(),s.end(),'R');
	g = count(s.begin(),s.end(),'G');
	b = count(s.begin(),s.end(),'B');
 
	long long ans = r * g * b;
	for(int i = 0; i < n - 2; i++){
		for(int j = i + 1; j < n - 1; j++){
			int k =2 * j - i;
			if(k >= n){
                break;
            }
			if(s[i] != s[j] && s[i] != s[k] && s[j] != s[k]){
                ans--;
            }
		}
	}
 
	cout << ans << endl;
}


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

using namespace std;

int main() {
  string s;
  cin >> s;
  int left = 0, right = s.size() - 1;
  int ans = 0;
  while (1) {
    if (s[left] == s[right] && s[left] == 'x') {
      left++;
      right--;
    } else if (s[left] == 'x' && s[left] != s[right]) {
      left++;
      ans++;
    } else if (s[right] == 'x' && s[left] != s[right]) {
      right--;
      ans++;
    } else if (s[left] == s[right] && s[left] != 'x') {
      left++;
      right--;
    } else {
      cout << -1 << endl;
      return 0;
    }

    if (right <= left)
      break;
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int a, b;
    cin >> a >> b;
    vector<int> v;
    v.push_back(a+b);
    v.push_back(a-b);
    v.push_back(a*b);
    OUT(*max_element(ALL(v)))

    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
 
public class Main {
	private static FastScanner sc = new FastScanner();
	
	public static void main(String[] args) {
		int N = sc.nextInt();
		int[] A1 = new int[N];
		for(int i=0; i<N; i++) {
			A1[i] = sc.nextInt();
		}
		int[] A2 = new int[N];
		for(int i=0; i<N; i++) {
			A2[i] = sc.nextInt();
		}
		int max = 0;
		for(int i=0; i<N; i++) {
			int sum = 0;
			for(int j=0; j<N; j++) {
				if(j < i) {
					sum += A1[j];
				} else if(j > i) {
					sum += A2[j];
				} else {
					sum += A1[j];
					sum += A2[j];
				}
			}
			if(sum > max) max = sum;
		}
		System.out.println(max);
	}
	
	static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if(ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch(IOException e) {
                    e.printStackTrace();
                }
                if(buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public int nextInt(){
            return Integer.parseInt(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}


Measured memory_bytes: 21332
import java.util.*;
public class Main {
 public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int N=sc.nextInt();
    int[] v=new int[N];
   	for(int i=0;i<N;i++)v[i]=sc.nextInt();
   	Arrays.sort(v);
    double r=v[0];
   	for(int i=1;i<N;i++)r=(r+v[i])/2;
	System.out.println(r);
 }
}


Measured memory_bytes: 22732
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//pair sort
bool compare_by_b(pair<LL, LL> a, pair<LL, LL> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}


void solve(long long X, long long A, long long B){
    LL date=B-A;
    debug(date)
    if(date<1)cout<<"delicious"<<endl;
    else if(date<=X)cout<<"safe"<<endl;
    else cout<<"dangerous"<<endl;
}

int main(){
    long long X;
    scanf("%lld",&X);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(X, A, B);
    return 0;
}


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

namespace ITP1_8_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var result = new List<int>();
            string input;
            while ((input = Console.ReadLine()) != "0")
            {
                int sum = 0;
                foreach (var i in input) sum += int.Parse(i.ToString());                 
                result.Add(sum);
            }
            foreach (var r in result) Console.WriteLine(r);               
        }
    }
}

Measured memory_bytes: 9216