akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
 
void MaxHeap(int *,int);

int main(int argc,char *argv[]) {
    int *hp, key, index, half, tmp;
    char cmd[20];
 
    hp = malloc(sizeof(int) * 2000001);
    hp[0] = 1;
    
    while (1) {
        scanf("%s %d ", cmd, &key);
        if (cmd[0] == 'i') {
            hp[0]++;
            index = hp[0];
            hp[index] = key;
 
            half = index / 2;
            while (index > 1 && hp[half] < hp[index]) {
                tmp = hp[index];
                hp[index] = hp[half];
                hp[half] = tmp;
                index /= 2;
                half = index / 2;
            }
        } else if (cmd[1] == 'x') {
            printf("%d\n", hp[1]);
            hp[1] = hp[hp[0]];
            hp[0]--;
            MaxHeap(hp, 1);
        } else {
	  
            return 0;
        }
    }
    
    return 0;
}
void MaxHeap(int *hp, int a) {
  int hsize, l, r, largest, tmp;
  
  hsize = hp[0];
  l = 2*a;
  r = 2*a + 1;
  if (l <= hsize && hp[l] > hp[a]) 
      largest = l;
  else 
      largest = a;
  if (r <= hsize && hp[r] > hp[largest]) 
      largest = r;
  if (largest != a) 
    {
      tmp = hp[a];
      hp[a] = hp[largest];
      hp[largest] = tmp;
      MaxHeap(hp, largest);
    }
}



Measured memory_bytes: 5588
#include <iostream>
#include <iomanip>
#include <complex>
using namespace std;

typedef complex<long double> P;

int n;

void dfs(const P& p1, const P& p2, int i)
{
    if(i == n){
        cout << p2.real() << ' ' << p2.imag() << endl;
        return;
    } else {
        P p3, p4, p5;
        p3 = (p2 - p1) / 3.0L + p1;
        p5 = 2.0L * (p2 - p1) / 3.0L + p1;
        //p4 = polar(abs(p5 - p3), arg(p5 - p3) + acos(-1.0L) / 3.0L) + p3;
        p4 = (p5 - p3) * polar(1.0L, acos(-1.0L) / 3.0L) + p3;
        dfs(p1, p3, i + 1);
        dfs(p3, p4, i + 1);
        dfs(p4, p5, i + 1);
        dfs(p5, p2, i + 1);
    }
}

int main()
{
    cin >> n;
    cout << setprecision(8) << fixed;
    cout << 0.0L << ' ' << 0.0L << endl;

    dfs(P(0,0), P(100,0), 0);
}

Measured memory_bytes: 1252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
using P = pair<int, int>;
const ll inf =1e9;

struct edge{
    int to;
    int cost;
};
using graph = vector<vector<edge>>;

int main(){
    int n, x; cin >> n >> x;
    if (n * 500 >= x){
        cout << "Yes" << endl;
        return 0;
    }else{
        cout << "No" << endl;
        return 0;
    }
}

Measured memory_bytes: 256
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let n: usize = s.trim().parse().unwrap();
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let a: Vec<usize> = s.trim().split_whitespace().map(|x| x.parse().unwrap()).collect();
    let mut b: Vec<usize> = vec![0; n];
    let z: usize = n/2 - (if n%2 == 0 {1} else {0});
    let mut i = 0;
    let mut j = 0;
    loop {
        b[z-j] = a[i];
        i += 1;
        if i >= n {break;}
        b[z+1+j] = a[i];
        i += 1;
        j += 1;
        if i >= n {break;}
    }
    if n%2 == 0 {b.reverse()}
    for i in 0..n {
        print!("{}{}", b[i], if i == n - 1 {"\n"} else {" "});
    }
}



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

int main() {
    int N ;
    int A[1000] ;
    cin >> N;
    for (int i = 0; i < N; ++i){
        cin >> A[i];
    }
    long double deno = 0;
    for (int i = 0; i < N; ++i ){
        deno += (double)1/A[i];
    }
    long double ans;
    ans = (double)1/deno;
    
    cout << setprecision(10) << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
#define ff first
#define ss second
#define pb push_back
#define N 505


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

	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	int ans = 0;
	vector<int> co;
	vector<int> co1;
	int i = 0, no;
	while(i < n)
	{
		no = 0;
		while(i < n && s[i] == '1') i++, no++;
		co1.pb(no);
		while(i < n && s[i] == '0') i++, no++;
		co.pb(no);
	}

	int nco = co.size();
	for(int i = 1; i < nco; ++i)
	{
		co[i] += co[i - 1];
	}
	
	co1.pb(0);
	co1.pb(0);
	co1.pb(0);
	co1.pb(0);
	co1.pb(0);
	if(nco <= k)
		ans = n;
	else
	{
		if(co[k - 1] + co1[k] > ans)
		ans = co[k - 1] + co1[k];
		i = k;
		while(i < nco)
		{
			if(co[i] - co[i - k] + co1[i + 1] > ans)
				ans = co[i] - co[i - k] + co1[i + 1];
			i++;
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>//ABC149C
using namespace std;
int main(void)
{
	int x,i,m=0;
	cin>>x;
	while(1){
		m=0;
		for(i=2;i<x;i++)
			if(x%i==0){
				m=1;
				break;
			}
			if(m==0){
				cout<<x;
				break;
			}
		x++;
	}
}

Measured memory_bytes: 256
T = list(input())

for index, i in enumerate(T):
    if i != "?":
        continue
    if 0 <= index - 1:
        if T[index - 1] == "P":
            T[index] = "D"
            continue
    if index + 1 < len(T):
        if T[index + 1] == "D":
            T[index] = "P"
            continue
    T[index] = "D"
print("".join(T))

Measured memory_bytes: 10900
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func pow(a, b int) int {
	ans := 1
	for i := b; i > 0; i-- {
		ans *= a
	}
	return ans
}

func main() {
	sc.Split(bufio.ScanWords)

	n, m := nextInt(), nextInt()
	ans := (n-m) * 100 * pow(2, m) + m * 1900 * pow(2, m)

	fmt.Println(ans)
}


Measured memory_bytes: 640
// 解説を見た　なるほど
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;

bool equals(double x, double y){
    return fabs(x-y) < 1e-6;
}

int main(){
    int n;
    cin >> n;
    if(n%2){
        cout << "NA" << endl;
        return 0;
    }
    double x[n], y[n];
    for(int i = 0; i < n; i++)  cin >> x[i] >> y[i];
    double px = (x[0]+x[n/2])/2.0, py = (y[0]+y[n/2])/2.0;
    bool ok = true;
    for(int i = 1; i < n/2; i++){
        ok &= equals(px-x[i], x[n/2+i]-px) && equals(py-y[i], y[n/2+i]-py);
    }
    if(ok)  cout << fixed << setprecision(12) << px << " " << py << endl;
    else    cout << "NA" << endl;
    return 0;
}


Measured memory_bytes: 3296
import java.util.Scanner;
//import java.util.Arrays;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int h = sc.nextInt();
		int w = sc.nextInt();
		String[] s = new String[h];
		for(int i=0; i<h; i++){
			s[i] = "#" + sc.next() + "#";
		}
		for(int i=0; i<w+2; i++){
			System.out.print("#");
		}
		System.out.println();
		for(int i=0; i<h; i++){
			System.out.println(s[i]);
		}
		for(int i=0; i<w+2; i++){
			System.out.print("#");
		}
	}
}


Measured memory_bytes: 39460
#include <bits/stdc++.h>
#define forn(x, n)              for (int x = 0; x < n; x++)
#define forr(x, n)              for (int x = n; x >= 0; x--)
#define fore(x, a, b, c)        for (int x = a; x <= b; x += c)
#define forre(x, a, b, c)       for (int x = a; x >= b; x -= c)
#define clr                     cin.ignore(numeric_limits<streamsize>::max(), '\n')
#define all(container)          (container).begin(), (container).end()
#define rall(container)         (container).rbegin(), (container).rend()
#define FILL(x, val)            memset(x, val, sizeof(x))
#define sz(container)           ((int) (container).size())
#define pb                      push_back
#define eb                      emplace_back
#define fi                      first
#define se                      second
#define mod                     (ll)1000000007
#define INF                     (int)0x3f3f3f3f

using namespace std;

#ifdef LOCAL_DEFINE
    #include "../../CLionProjects/Codeforces/library/DEBUG.hpp"
#endif

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }  

typedef long long ll; 
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<long long, long long>> vpll;

void solve() {
    ll a, b;
    cin >> a >> b;
    ll ans = __gcd(a, b);
    cout << ans << endl;
}

int main(void) {    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("in.txt", "r", stdin);
#endif
    int t = 1; 
//    cin >> t;
    while (t--)
        solve();
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << '\n';
#endif
    return 0;
}


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

int main(){
   string m;
   
   cin>>m;
   
   if(m.at(2) == m.at(3) && m.at(4) == m.at(5)){
        cout<<"Yes"<<endl;
   }
   else{
        cout<<"No"<<endl;
   }
}


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

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;
#pragma endregion

#pragma region const
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#pragma endregion

#pragma region util
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}
#pragma endregion

#pragma region init
struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

int main()
{
	i64 N;
	cin >> N;
	if (N == 1)
	{
		cout << "Hello World" << endl;
	}
	else
	{
		i64 A, B;
		cin >> A >> B;
		cout << A+B << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

#define MAX_VAL 100002

int main(void){

    int i,N,M,x[MAX_VAL],y[MAX_VAL],possibility[MAX_VAL],ball_num[MAX_VAL],ans = 0;
    
    scanf("%d %d",&N,&M);
    for(i = 1;i <= M;i++){
        scanf("%d %d",&x[i],&y[i]);
    }
    for(i = 1;i <= N;i++){
        possibility[i] = 0;
        ball_num[i] = 1;
    }
    possibility[1] = 1;

    for(i = 1;i <= M;i++){
        ball_num[x[i]]--;
        ball_num[y[i]]++;
        if(possibility[x[i]] == 1){
            possibility[y[i]] = 1;
        }
        if(ball_num[x[i]] == 0 && possibility[x[i]] == 1){
            possibility[x[i]] = 0;
        }
    }

    for(i = 1;i <= N;i++){
        //printf("possibility[%d]:%d\n",i,possibility[i]);
        ans += possibility[i];
    }

    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <tuple>
#include <cstdio>
#include <cassert>
#include <functional>
#define _LIBCPP_DEBUG 0
using namespace std;

int main(void){
    int n;
    cin >> n;
    
    vector<int> a(n);

    for (int i = 0; i < n; i++)
    {
        cin >> a.at(i);
    }

    sort(a.begin(),a.end());
    
    for (int i = 0; i < n-1; i++)
    {
        if (a.at(i)==a.at(i+1))
        {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}


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

int main()
{
  int n,x,t;
  cin>>n>>x>>t;
  int ans ;
  if(n%x==0)
    ans = (n/x)*t;
  else
    ans = (n/x)*t+t;
  
  cout<<ans;
  return 0;
}
    


Measured memory_bytes: 3572
#include<iostream>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include <utility>
#include <math.h>
#include<cmath>
#include<map>
#include <limits>
# include <iomanip>
#include<queue>
#include<stack>
#define INF 1000000009;
#define inl long long
using namespace std;
int gcd(int a, int b) {
	while (a % b != 0) {
		int c = 0;
		c = a % b;
		a = b;
		b = c;
	}
	return  b;
}
int kaizyo(int a) {
	long long ans = 1;
	for (int i = a; i > 0; i--) {
		ans *= i;
		ans = ans % 1000000007;
		//cout << ans << endl;
	}
	ans = ans % 1000000007;
	return ans;
}

int main() {
	int N = 0;
	vector<double>manji;
	cin >> N;
	double summ=1,sumw=0;
	for (int i = 0; i < N; i++) {
		double manjj;
		cin >> manjj;
		manji.push_back(manjj);
		summ *= manjj;
	}
	for (int i = 0; i < N; i++) {
		manji[i] = summ / manji[i];
		sumw += manji[i];
	}
	cout << std::setprecision(9) << summ / sumw << endl; 
	return 0;
}





Measured memory_bytes: 256
import sys
X,Y = map(int,input().split(" "))
#X = int(input())
#Y = int(input())

if X == Y:
    print(-1)
    sys.exit()

for i in range(2,100):
    if int((X*i)/Y) != (X*i)/Y:
        print(X*i)
        sys.exit()
print(-1)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
const long long M = 1e8 ;
int main()
{
    ll n,sum=0,b=1,a;
    cin>>n;
    for(int i=1;i<=3;i++){
        b=n*b;
        sum=sum+b;
    }
    cout<<sum<<endl;
    return 0;
}



Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,p,a[100001],f[100001][2];
signed main()
{
    cin>>n>>p;
    for(int i=1;i<=n;i++)cin>>a[i];
    f[0][0]=1;
    for(int i=1;i<=n;i++)
    {
        if(a[i]%2==0)
        f[i][0]=2*f[i-1][0],f[i][1]=2*f[i-1][1];
        else
        f[i][0]=f[i-1][1]+f[i-1][0],f[i][1]=f[i-1][0]+f[i-1][1];
    }
    cout<<f[n][p];
}

Measured memory_bytes: 3456
#include <stdio.h>

#define N 100

int main() {
	static int aa[N];
	int n, x, i, min, sum;

	scanf("%d%d", &n, &x);
	min = 1001;
	sum = 0;
	for (i = 0; i < n; i++) {
		scanf("%d", &aa[i]);
		sum += aa[i];
		if (min > aa[i])
			min = aa[i];
	}
	printf("%d\n", (x - sum) / min + n);
	return 0;
}


Measured memory_bytes: 128
#include <iostream> // cout, endl, cin
#include <iomanip>
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <numeric>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int64_t dfs(int64_t h)
{
    if(h == 1)
    {
        return 1;
    }
    return dfs(h/2)*2 + 1;
}

int main()
{
    int64_t H;
    cin >> H;
    cout << dfs(H) << endl;
    
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys
import os
import math

H, W = map(int, input().split())

def vertical_cut(H, W):
    if W < 3:
        return float('inf')

    if W % 3 == 0:
        min_w = W // 3
        max_w = W // 3
    else:
        min_w = W // 3
        max_w = W // 3 + 1

    S_max = max_w * H
    S_min = min_w * H

    return S_max - S_min

def horizontal_cut(H, W):
    return vertical_cut(W, H)

def vertical_and_horizontal_cut(H, W):
    min_score = float('inf')

    for cut_i in range(1, W // 2 + 1):
        left_S = cut_i * H
        right_W = W - cut_i

        right_H_top = H // 2
        right_H_bottom = H - right_H_top

        right_top_S = right_W * right_H_top
        right_bottom_S = right_W * right_H_bottom

        A = [left_S, right_top_S, right_bottom_S]
        score = max(A) - min(A)
        if score < min_score:
            min_score = score
    return min_score

def horizontal_and_vertical_cut(H, W):
    return vertical_and_horizontal_cut(W, H)

a = vertical_cut(H, W)
b = horizontal_cut(H, W)
c = vertical_and_horizontal_cut(H, W)
d = horizontal_and_vertical_cut(H, W)

print(min(a, b, c, d))


Measured memory_bytes: 3188
/* ex3-4
   Sagzar1993  */


#include <stdio.h>

int main(void) {
    int num;

    //入力を受け取る
    scanf("%d", &num);

    int i = 1;

    //numが各数字で割り切れ、かつその商が１から９の間であるとき、Yesを表示
    for(i; i < 10; i++){
        if(num % i == 0 && num / i <= 9){
            printf("Yes\n");
            break;
        }
    }

    if(i == 10){
        printf("No\n");
         //どれにも当てはまらなかった場合はNoを表示
    }
    
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n)  for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define deb(x) cerr << #x <<": " << x << '\n';
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
typedef long double ld;
typedef long long ll;

int main(){
    ios;
    int n; cin >> n;
    cout << pow(n,3);
    }



Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

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

		int n = Integer.parseInt(sc.nextLine());
		int[][] map = new int[2][n];
		for (int i = 0; i < 2; i++) {
			String[] inputs = sc.nextLine().split(" ");
			for (int j = 0; j < n; j++) {
				map[i][j] = Integer.parseInt(inputs[j]);
			}
		}
		int max = 0;
		for (int i = 0; i < n; i++) {
			int count = 0;
			for (int j = 0; j <= i; j++) {
				count += map[0][j];
			}
			for (int k = i; k < n; k++) {
				count += map[1][k];
			}
			max = Math.max(max, count);
		}

		System.out.println(max);

	}
}

Measured memory_bytes: 21844
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char* argv[])
{
    int N, T; cin >> N >> T;

    vector<int> path;
    for (int i = 0; i < N; i++) {
        int c, t; cin >> c >> t;
        if (t <= T) {
            path.push_back(c);
        }
    }

    sort(path.begin(), path.end());

    cout << ((path.size() == 0) ? "TLE" : to_string(path[0])) << endl;
    return 0;
}


Measured memory_bytes: 256
/*  
   |\_/|
   |* *|
   \_+_/
          */
#include<bits/stdc++.h>

#define endl '\n'

using namespace std;

int main(){

  cin.tie(0);     // cout と cin の同期を切る
  ios::sync_with_stdio(false);  /* cの stdioストリーム (printfとか)と*/


  long long N,K;

  cin>>N>>K;

  long long ans[100001]={ };

  int a,b;
  
  for(int i=0;i<N;i++){

    cin>>a>>b;


    ans[a]+=b;

  }

  long long cnt=0;
  
  for(int i=1;i<=100000;i++){

    cnt+=ans[i];
    
    if(cnt>=K){
      cout<<i<<endl;
      break;
    }

  }
  return 0;

}


Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int Mod=1e9+7;
int fac[4110000],ifac[4110000],f[2100][2100],n,k;

int pow(int x,int l){
	if(l==0)return 1;
	int t=pow(x,l/2);
	t=(ll)t*t%Mod;
	if(l&1)t=(ll)t*x%Mod;
	return t;
}

int C(int x,int y){
	return (ll)fac[x]*ifac[y]%Mod*ifac[x-y]%Mod;
}

int main(){
	scanf("%d %d",&n,&k);
	if(k==1){
		printf("%d\n",1);
		return 0;
	}
	fac[0]=1;for(int i=1;i<=4099999;i++)fac[i]=(ll)fac[i-1]*i%Mod;
	ifac[4099999]=pow(fac[4099999],Mod-2);for(int i=4099998;i>=0;i--)ifac[i]=(ll)ifac[i+1]*(i+1)%Mod;
	f[0][0]=1;
	for(int i=1;i<=n;i++)
		f[0][i]=(ll)f[0][i-1]*C(0+i*(k-1)-1,k-2)%Mod;
	for(int i=1;i<=n;i++){
		f[i][i]=f[i-1][i];
		for(int j=i+1;j<=n;j++){
			f[i][j]=(f[i-1][j]+(ll)f[i][j-1]*C(i+j*(k-1)-1,k-2))%Mod;
		}
	}
	printf("%d\n",(ll)f[n][n]*fac[n]%Mod);
	return 0;
}


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

int main()
{
	int N,ans=0;
	cin >> N;
	vector<int> V(N);
	for(int i=0;i<N;i++)
	{
		cin >> V[i];
	}
	vector<int> C(N);
	for(int i=0;i<N;i++)
	{
		cin >> C[i];
	}

	for(int i=0;i<N;i++)
	{
		if(V[i]>C[i])
		{	
			ans+=V[i]-C[i];
		}
	}
	cout << ans <<endl;
}

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

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	int n,l;
	string str[100];
	cin >> n >> l;
	REP(i,n) cin >> str[i];
	sort(str,str+n);
	string rst = "";
	REP(i,n) rst += str[i];
	cout << rst << endl;	
}

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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	for(int n;cin>>n&&n;){
		vi a(n);
		rep(i,n) cin>>a[i];
		set<int> s;
		s.insert(0);
		rep(i,n){
			set<int> t=s;
			for(int x:s)
				t.insert(x+a[i]);
			s=move(t);
		}
		int res=0;
		for(int x:s)
			if(x%10)
				res=max(res,x);
		cout<<res<<endl;
	}
}


Measured memory_bytes: 896
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,avx,avx2,mmx,abm")
//#pragma GCC optimize("O3,unroll-loops,inline")
#include <bits/stdc++.h>

using namespace std;

const int MOD = 998244353;

int add(int a, int b) {
	a += b;
	if (a >= MOD) a -= MOD;
	return a;
}

const int MAXN = 3010;
int n, s;
int a[MAXN];
int dp[MAXN];

signed main() {
	scanf("%d%d", &n, &s);
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	int ans = 0;
	for (int i = 0; i <= s; i++)
		dp[i] = 0;
	for (int i = 1; i <= n; i++) {
		for (int w = s - a[i]; w >= 1; w--) {
			int nxt = w + a[i];
			dp[nxt] = add(dp[nxt], dp[w]);
		}
		int nxt = a[i];
		if (nxt <= s) dp[nxt] = add(dp[nxt], i);
		ans = add(ans, dp[s]);
	}
	printf("%d\n", ans);
	return 0;
}

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

const int N=2e5+20;

int n,m,u,v,cnt,ans;
vector <int> adj[N];
set <pair <int,int>> s;
bool vis[N];

void dfs(int node)
{
	cnt++;
	vis[node]=true;
	for(auto child:adj[node])
		if(not vis[child]) dfs(child);
}

int main()
{
	scanf("%d%d",&n,&m);
	while(m--)
	{
		scanf("%d%d",&u,&v);

		if(u>v) swap(u,v);
		if(s.find({u,v})!=s.end()) continue;

		adj[u].push_back(v);
		adj[v].push_back(u);
		s.insert({u,v});
	}

	for(int i=1;i<=n;i++)
	{
		if(vis[i]) continue;
		cnt=0;
		dfs(i);
		ans=max(ans,cnt);
	}

	printf("%d",ans);
}

Measured memory_bytes: 30472
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<string,P> PP;
vector<PP> s;
int main(void){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        string a;
        int b;
        cin>>a>>b;
        s.push_back(PP{a,P{-b,i+1}});
    }
    sort(s.begin(),s.end());
    for(auto x:s){
        cout<<x.second.second<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "debug" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


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

    int N,K;
    string S;
    cin >> N >> K >> S;
    if(S[K-1] == 'A') S[K-1] = 'a';
    else if(S[K-1] == 'B') S[K-1] = 'b';
    else if(S[K-1] == 'C') S[K-1] = 'c';
    cout << S << endl;
}

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

int main()
{
    string s,t;
    cin >> s >> t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    reverse(t.begin(),t.end());
    if(s<t){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


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

using namespace std;

#define int long long
#define N 100005

vector < pair < int , int > > a[N];
int vis[N];
int pos[N];
int valid = 1;

void dfs(int n, int cur)
{
    vis[n] = 1;
    pos[n] = cur; 
    for(int i=0;i<a[n].size();i++)
    {
        if(vis[a[n][i].first]==0)
        {
            dfs(a[n][i].first, cur+a[n][i].second);
        }
        else
        {
            if( pos[n] + a[n][i].second != pos[a[n][i].first] )
                valid = 0;
        }
    }
}


int32_t main()
{
    int n, m;
    cin>>n>>m;
    for(int i=0; i<m; i++)
    {
        int u, v, w;
        cin>>u>>v>>w;

        a[u].push_back({v, w});
        a[v].push_back({u, -w});
    }

    for(int i=1;i<=n;i++)
        pos[i] = -1;

    int cur = 0;
    for(int i=1;i<=n;i++)
    {
        if(vis[i]==0)
        {
            dfs(i, cur);
            cur+=1e10;
        }
    }

    if(valid == 0)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;

    return 0;
}

Measured memory_bytes: 17280
N = int(input())
A = list(map(int,input().split()))
A.sort()

from bisect import bisect
i = bisect(A, A[-1]//2)
a = min(A[i], A[-1]-A[i])
b = min(A[i-1], A[-1]-A[i-1])
if a > b:
    print(A[-1], A[i])
else:
    print(A[-1], A[i-1])

Measured memory_bytes: 14420
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;

// 各ノードの座標と深さを保持するための構造体
struct Node{
    int y;
    int x;
    int depth;
};

int main() {
    // 標準入力
    int R, C;
    cin >> R >> C;
    vector<string> c(R);
    for (int i=0; i<R; i++) {
        cin >> c[i];
    }
    
    vector<int> y_vec = {0,0,-1,+1}; // 進む方向の簡便化
    vector<int> x_vec = {-1,+1,0,0}; // ループで回すことで上下左右に移動出来る。
    
    
    queue<Node> q;
    // 初期位置をキューに格納
    for (int i=0; i<R; i++) {
        for (int j=0; j<C; j++) {
            if (c[i][j]=='#') {
                Node start = {i, j, 0}; //初期位置の深さは0
                q.emplace(start);
            }
        }
    }
    
    
    int ans=0;
    
    // 幅優先探索
    while (!q.empty()) {
        Node now = q.front(); q.pop(); // キューの先頭を取り出し、nowとする
        
        // 上下左右４方向を探索。進むことができればキューに格納。
        for (int i=0; i<4; i++) {
            // 上下左右４方向に進む
            Node next = {now.y+y_vec[i], now.x+x_vec[i], now.depth+1};
            // 進む事ができれば（＝未探索Nodeかつ壁でなければ）キューに格納
            if (0<=next.y && next.y<R && 0<=next.x && next.x<C && //そこにNodeがあること
                c[next.y][next.x]=='.') { // 未探索でかつ壁マスでないこと
                c[next.y][next.x]='x'; // 探索済みの印を付ける
                q.push(next); // キューの後ろに追加する
                ans=next.depth;
            }
        }
    }
    
    // 解
    cout << ans << endl;
}


Measured memory_bytes: 13456
package main 

import (
        "fmt"
        "sort"
)

func main () {
        var n, k, l, an, a  int
        ka := []int{}
        fmt.Scan(&n,&k)
        for i :=0 ; i < n ; i++ {
                fmt.Scan(&l)
                ka = append(ka, l)
        }
        sort.Sort(sort.IntSlice(ka))
        a = n 
        for i := 0 ; i < k ; i++ {
                a -=1
                an = an + ka[a]
        }
        fmt.Println(an)
}


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

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

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

template <typename T>
class UnionFind {
    private:
        vector<int> parent;  // 親
        vector<int> rank;    // 木の深さ

        // 重み付きUnionFindでのみ利用
        vector<T> diffWeight; // 親ノードとの値の差
    public:
        UnionFind(int n);          // n要素で初期化
        int Find(int x);           // 木の根を返す
        void Unite(int x, int y);  // xとyの属する集合を併合
        bool Same(int x, int y);   // xとyが同じ集合に属するか否か

        // 重み付きUnionFindでのみ利用
        void Unite(int x, int y, T w);
        T Weight(int x);      // xの重みを返す
        T Diff(int x, int y); // xとyの差を返す
};

    template <typename T>
UnionFind<T>::UnionFind(int n) : parent(n), rank(n), diffWeight(n, 0)
{
    for (int i = 0; i < n; i++) {
        parent[i] = i;
        rank[i] = 0;
    }
}

template <typename T>
int UnionFind<T>::Find(int x) {
    if (parent[x] == x) {
        return x;
    } else {
        int r = Find(parent[x]);
        diffWeight[x] += diffWeight[parent[x]];
        return parent[x] = r;
    }
}

template <typename T>
void UnionFind<T>::Unite(int x, int y) {
    x = Find(x);
    y = Find(y);
    if (x == y) return;

    if (rank[x] < rank[y]) {
        parent[x] = y;
    } else {
        parent[y] = x;
        if (rank[x] == rank[y]) rank[x]++;
    }
}

template <typename T>
bool UnionFind<T>::Same(int x, int y) { return Find(x) == Find(y); }

template <typename T>
void UnionFind<T>::Unite(int x, int y, T w){
    w += Weight(x); w -= Weight(y);
    x = Find(x); y = Find(y);
    if(x == y) return;

    if(rank[x] < rank[y]) swap(x, y), w = -w;

    if(rank[x] == rank[y]) rank[x]++;
    parent[y] = x;

    diffWeight[y] = w;
}

template <typename T>
T UnionFind<T>::Weight(int x){
    Find(x);
    return diffWeight[x];
}

template <typename T>
T UnionFind<T>::Diff(int x, int y){
    return Weight(y) - Weight(x);
}

/*************** using variables **************/
int n, k, l;
vector<int> p, q, r, s;
map<P, int> mp;
/**********************************************/

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

    cin >> n >> k >> l;
    p.resize(k);
    q.resize(k);
    r.resize(l);
    s.resize(l);

    REP(i, k) cin >> p[i] >> q[i];
    REP(i, l) cin >> r[i] >> s[i];
    
    UnionFind<int> uf1(n), uf2(n);
    
    REP(i, k){
        p[i]--, q[i]--;
        uf1.Unite(p[i], q[i]);
    }

    REP(i, l){
        r[i]--, s[i]--;
        uf2.Unite(r[i], s[i]);
    }
    
    REP(i, n){
        mp[P(uf1.Find(i), uf2.Find(i))]++;
    }

    REP(i, n) cout << mp[P(uf1.Find(i), uf2.Find(i))] << (i != n-1 ? " " : "");
    cout << endl;
}


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

string s;
const ll N=10005;
const ll D=105;
const ll mod=1e9+7;
ll d;
ll dp[N][D][2];

ll recur(ll pos, ll rem, ll f)
{
	if(pos==(ll)s.size()) return (rem==0);
	ll &ans=dp[pos][rem][f];
	if(ans!=-1) return ans;
	ans=0;
	for(ll i=0; i<10; i++)
	{
		if(f) // already became smaller than s
		{
			ans=(ans + recur(pos+1, (rem + i)%d, 1))%mod;
		}
		else // write cases or use nf, new flag
		{
			if(i < s[pos]-'0')
			{
				ans=(ans + recur(pos+1, (rem + i)%d, 1))%mod;
			}
			else if(i == s[pos]-'0')
			{
				ans=(ans + recur(pos+1, (rem + i)%d, 0))%mod;
			}
			else { break; }
		}
	}
	return ans;
}
 
void solve()  
{
	cin>>s>>d;
	memset(dp, -1, sizeof dp);
	ll ans=recur(0, 0, 0);
	ans=(ans + mod - 1)%mod; // -1 for 0
	cout<<ans<<endl;
}
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);  
	ll T = 1;
	//cin>>T; 
	while(T--)
	    solve();
	return 0;
}


Measured memory_bytes: 17408
use proconio::*;
use std::cmp::max;
use std::collections::BinaryHeap;

#[fastout]
fn main() {
    input! {
        d: usize,
        c: [i64; 26],
        s: [[i64; 26]; d],
    };

    let mut lasts = [-1; 26];
    let mut t = vec![26; d];
    let depth = 23;
    for i in 0..d {
        let mut max_score = -10000000;
        for j in 0..26 {
            let tmp = search(i, j, &c, &s, &mut lasts, depth, d, 0, 6);
            if tmp > max_score {
                max_score = tmp;
                t[i] = j;
            }
        }
        lasts[t[i]] = i as i64;
    }

    for &a in &t {
        println!("{}", a + 1);
    }
}

fn calc_score(i: usize, j: usize, c: &Vec<i64>, s: &Vec<Vec<i64>>, lasts: &mut [i64; 26]) -> i64 {
    let mut res = s[i][j];
    let tmp = lasts[j];
    lasts[j] = i as i64;

    for j in 0..26 {
        let i = i as i64;
        let last = lasts[j];
        res -= c[j] * (i - last);
    }

    lasts[j] = tmp;
    res
}

fn search(
    i: usize,
    t: usize,
    c: &Vec<i64>,
    s: &Vec<Vec<i64>>,
    lasts: &mut [i64; 26],
    depth: usize,
    d: usize,
    cscore: i64,
    l: usize,
) -> i64 {
    if depth == 0 || i == d - 1 {
        return calc_score(i, t, &c, &s, lasts) + cscore;
    }

    let l = max(1, l - 1);
    let mut max_score = -1000000;
    let tmp_last = lasts[t];
    lasts[t] = i as i64;
    let tmp_score = calc_score(i, t, &c, &s, lasts);
    let mut cands = BinaryHeap::new();
    cands.reserve(26);
    for j in 0..26 {
        let tmp_score = calc_score(i + 1, j, &c, &s, lasts);
        cands.push((tmp_score, j));
    }
    let w = if l > 1 { 2 } else { 1 };
    for &(_, j) in cands.iter().take(w) {
        let tmp = search(i + 1, j, &c, &s, lasts, depth - 1, d, cscore + tmp_score, l);

        if tmp > max_score {
            max_score = tmp;
        }
    }

    lasts[t] = tmp_last;
    max_score + cscore
}


Measured memory_bytes: 2328
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
using namespace std;

int main() {
    int N,M;
    cin >> N;
    vector<string> sN(N);
    for(int i = 0; i<N; i++) cin >> sN.at(i);
    cin >> M;
    vector<string> sM(M);
    for(int i = 0; i<M; i++) cin >> sM.at(i);
    
    vector<int> ans(N,0);
    for(int i = 0; i<N; i++){
        for(int i2 = 0; i2 < N; i2++){
            if(sN.at(i) == sN.at(i2)) ans.at(i)++;
        }
        for(int i3 = 0; i3 < M; i3++){
            if(sN.at(i) == sM.at(i3)) ans.at(i)--;
        }
    }
    int max = ans.at(0);
    for(int i = 1; i<N; i++){
        if(ans.at(i) > max) max = ans.at(i);;
    }
    if(max < 0) cout << 0 << endl;
    else cout << max << endl;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

S = input()
N = len(S)

dp = [[0, 0] for _ in range(N+1)]
dp[1][0] = 1

for i in range(2, N+1):
	if S[i-1] != S[i-2]:
		dp[i][0] = dp[i-1][0] + 1

	dp[i][0] = max(dp[i][0], dp[i-1][1] + 1)
	dp[i][1] = dp[i-2][0] + 1

print(max(dp[-1]))

Measured memory_bytes: 40836
function Main(input) {
  input = input.split(' ')
  var A = parseInt(input[0])
  var B = parseInt(input[1])
  var C = parseInt(input[2])

  if (C > A - B) {
    C -= A - B
    console.log(C)
  } else {
    console.log(0)
  }
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'))


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

int main() {
  int YABAI, WAYO;
  string TKSS, EKSA, LAPLAND;
  cin >> YABAI >> EKSA >> WAYO;
  
  if(EKSA == "+"){
    YABAI += WAYO;
  }
  else{
    YABAI -= WAYO;
  }
  
  cout << YABAI << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
 
const int MAX = 11000000;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
int main() {
    // 前処理
    COMinit();
 
    lli x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
 
    lli sum = 0;
    for(lli r = y1;r<=y2;r++){
    	lli tmp = COM(x2+r+1,r+1)-COM(x1+r,r+1);
    	while(tmp<0)tmp += MOD;
    	tmp %= MOD;
    	sum += tmp;
    	sum %= MOD;
    }
    cout<<sum<<endl;
	
	return 0;
}

Measured memory_bytes: 258048
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    string s;
    ll q;
    cin >> s;
    cin >> q;
    string k;
    string h;
    ll flag = 0;
    for (ll i = 0; i < q; i++)
    {
        int p;
        cin >> p;
        if (p == 1)
        {              //このとき反転させられる。→どっち向きになったのかの情報を持っておく。
            flag += 1; //これが奇数の時には反転している。
        }
        else if (p == 2)
        {
            int y;
            cin >> y;
            char f;
            cin >> f;
            if ((y + flag) % 2 == 1)
            {
                k = f + k; //これは本来の文字列の向きの先頭につける者。
            }
            else
            {
                h = h + f;
            }
        }
    }
    if (flag % 2 == 1)
    {
        s=k+s+h;
        reverse(s.begin(), s.end());

        cout << s << endl;
        return 0;
    }
    cout << k + s + h << endl;
}

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

using namespace std;
typedef long long ll;

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

  for (int i = 1; i <= n; ++i) {
    if ((int) (i * 1.08) == n) {
      cout << i;

      return 0;
    }
  }

  cout << ":(";

  return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int q = sc.nextInt();
        int cnt = 1;
        char k = 0;
        char l = 0;
        int a2 = 0;
        int b2 = 0;
        List<Character> str = new ArrayList<>();
        for (int i = 0; i < s.length(); i++) {
            str.add(s.charAt(i));
        }
        while (cnt <= q) {
            String order = sc.next();
            int a = sc.nextInt();
            int b = sc.nextInt();
            a2 = a;
            b2 = b;
            switch (order) {
                case "print":
                    for (int i = 0; i <= b - a; i++) {
                        System.out.print(str.get(i + a));
                    }   System.out.println("");
                    break;
                case "reverse":
                    for (int i = 0; i < (b - a) / 2 + ((b - a) % 2); i++) {
                        k = str.get(a2);
                        l = str.get(b2);
                        str.set(a2, l);
                        str.set(b2, k);
                        a2++;
                        b2--;
                    }   break;
                default:
                    String p = sc.next();
                    for (int i = 0; i <= b - a; i++) {
                        str.set(a2, p.charAt(i));
                        a2++;
                    }   break;
            }
            cnt++;
        }
    }
}

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

int main()
{
  int n, ans = 0;
  string s;
  cin >> n >> s;
  for (int i = 1; i < n; i++) {
    int cnt = 0;
    for (char c = 'a'; c <= 'z'; c++) {
      int judge1 = 0, judge2 = 0;
      for (int j = 0; j < i; j++) {
        if (s[j] == c) {
          judge1 = 1;
          break;
        }
      }
      for (int j = i; j < n; j++) {
        if (s[j] == c) {
          judge2 = 1;
          break;
        }
      }
      if (judge1 == 1 && judge2 == 1) cnt++;
    }
    if (cnt >= ans) ans = cnt;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <queue>
#include <algorithm>
#include <vector>
#define INF 1000000000000000LL
using namespace std;
typedef long long ll;

ll labs(ll x){
	if(x<0)return -x;
	return x;
}

struct data{
	int x,y,id;
	data(){}
	data(int xx,int yy,int dd){
		x=xx;
		y=yy;
		id=dd;
	}
};

class data2{
public:
	int v,s;
	ll cost;
	data2(){}
	data2(int vv,int ss,ll cc){
		v=vv;
		s=ss;
		cost=cc;
	}
	bool operator<(const data2& d)const{
		return cost>d.cost;
	}
};

bool compx(const data &d1,const data &d2){
	if(d1.x==d2.x)return d1.y<d2.y;
	return d1.x<d2.x;
}

bool compy(const data &d1,const data &d2){
	if(d1.y==d2.y)return d1.x<d2.x;
	return d1.y<d2.y;
}
bool compid(const data &d1,const data &d2){
	return d1.id<d2.id;
}

int m,n,k;
data dat[200001];
vector<int> xid[100001];
vector<int> yid[100001];
vector<int> G[200001][2];
ll dp[200001][2];
ll dijk(){
	priority_queue<data2> que;
	for(int i=0;i<k;i++){
		dp[i][0]=dp[i][1]=INF;
	}
	if(yid[0].size()>0){
		que.push(data2(yid[0][0],1,dat[yid[0][0]].y));
		dp[yid[0][0]][1]=dat[yid[0][0]].y;
	}
	ll res=INF;
	while(que.size()){
		data2 d=que.top();
		que.pop();
		if(d.cost>dp[d.v][d.s] || d.cost>res)continue;
		if(d.s==1 && dat[d.v].x==m-1){
			res=min(res,d.cost+labs((ll)n-1-dat[d.v].y));
		}
		if(d.s==0 && dat[d.v].y==n-1){
			res=min(res,d.cost+labs((ll)m-1-dat[d.v].x));
		}
		if(dp[d.v][1-d.s]>(ll)d.cost+1){
			dp[d.v][1-d.s]=(ll)d.cost+1;
			que.push(data2(d.v,1-d.s,dp[d.v][1-d.s]));
		}
		for(int i=0;i<(int)G[d.v][d.s].size();i++){
			int t=(int)G[d.v][d.s][i];
			ll dist=labs((ll)dat[d.v].x-dat[t].x)+labs((ll)dat[d.v].y-dat[t].y);
			if(dp[t][d.s]>d.cost+dist){
				dp[t][d.s]=d.cost+dist;
				que.push(data2(t,d.s,dp[t][d.s]));
			}
		}
	}
	return res;
}

int main(void){
	scanf("%d%d%d",&m,&n,&k);
	for(int i=0;i<k;i++){
		scanf("%d%d",&dat[i].x,&dat[i].y);
		dat[i].x--;
		dat[i].y--;
		dat[i].id=i;
	}
	sort(dat,dat+k,compx);
	for(int i=0;i<k;i++){
		xid[dat[i].y].push_back(dat[i].id);
	}
	for(int i=0;i<n;i++){
		int si=xid[i].size();
		for(int j=0;j<si-1;j++){
			G[xid[i][j]][0].push_back(xid[i][j+1]);
			G[xid[i][j+1]][0].push_back(xid[i][j]);
		}
	}
	sort(dat,dat+k,compy);
	for(int i=0;i<k;i++){
		yid[dat[i].x].push_back(dat[i].id);
	}
	for(int i=0;i<m;i++){
		int si=yid[i].size();
		for(int j=0;j<si-1;j++){
			G[yid[i][j]][1].push_back(yid[i][j+1]);
			G[yid[i][j+1]][1].push_back(yid[i][j]);
		}
	}
	sort(dat,dat+k,compid);
	ll res=dijk();
	printf("%lld\n",res==INF?-1:res);
	return 0;
}

Measured memory_bytes: 39336
/******************************************
* AUTHOR : GURUTEJA *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define N 100005
#define MOD 1000000007
#define dd double
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second

void debug(){
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif 

}

  int main() {
    debug();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s,s1;	
    cin>>s;
    int x=1e9;
    for (int i = 0; i<s.length(); ++i)
    {
    	if(i<s.length()-2){
    		s1+=s[i],s1+=s[i+1],s1+=s[i+2];
    		x=min(x,abs(753-stoi(s1)));
    	}
    	s1.clear();
    }
    cout<<x<<endl;
    return 0;
  }

Measured memory_bytes: 3656
#include <iostream>
#include <cstring>
#include <set>
#include <stack>
#include <list>
#include <vector>
#include <map>
#include <math.h>
#include <algorithm>

typedef long long ll;
using namespace std;

int main() {
    int N;
    string S, T, ans = "";

    cin >> N >> S >> T;

    for(int i=0; i<N; i++){
        ans += S[i];
        ans += T[i];
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-indexed昇順

int main()
{
  int p;
  priority_queue<int, vector<int>, greater<int>> P;
  cin >> p;
  P.push(p);
  cin >> p;
  P.push(p);
  cin >> p;
  P.push(p);
  int a, b;
  a = P.top();
  P.pop();
  b = P.top();
  P.pop();
  cout << a + b << endl;
}

Measured memory_bytes: 256
from collections import deque


def bfs(S):  # 幅優先探索  # キュー
    que = deque([S])
    b, w = 0, 0
    while len(que) > 0:
        p, q = que.popleft()
        b += int(s[p][q] == '#')
        w += int(s[p][q] == '.')
        for i, j in near[p][q]:  # 移動先の候補
            if (i, j) in frag:  # 処理済みか否か
                continue
            if s[i][j] != s[p][q]:
                que.append((i, j)), frag.add((i, j))
    return b * w


h, w = map(int, input().split())
s = [input() for _ in range(h)]

near = [[set() for j in range(w)] for i in range(h)]
for i, si in enumerate(s):
    for j, sij in enumerate(si):
        for p, q in [(i - 1, j), (i, j - 1), (i + 1, j), (i, j + 1)]:
            if 0 <= p < h and 0 <= q < w and s[p][q] != sij:
                near[i][j].add((p, q))

ans, frag = 0,set()
for i in range(h):
    for j in range(w):
        if (i, j) not in frag:
            frag.add((i, j))
            ans += bfs((i, j))
print(ans)


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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  cout << s.substr(0, 4) << " " << s.substr(4, 8) << endl;
  return 0;
}


Measured memory_bytes: 256