akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stack>
#include<vector>
#define reep(a,s,d) for(int a=d;a<s;a++)
#define rep(a,s) reep(a,s,0)
using namespace std;
stack<int> S[2];
int main(){
    int n;
    while(cin>>n,n){
        int s[2]={};
        reep(i,n+1,1){
            bool c;
            cin>>c;
            if(i%2){
                if(s[c]>0)s[c]++;
                else{
                    S[c^1].push(s[c^1]);
                    s[c^1]=0;
                    s[c]++;
                }
            }else{
                if(s[c]>0)s[c]++;
                else{
                    s[c]=s[c^1]+1;
                    if(!S[c].empty()){
                        s[c]+=S[c].top();
                        S[c].pop();
                    }
                    s[c^1]=0;
                }
            }
        }
        while(!S[0].empty()){
            s[0]+=S[0].top();S[0].pop();
        }
        while(!S[1].empty())S[1].pop();
        cout<<s[0]<<endl;
    }
}

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


int main() {
	int m, count,x;
	int h[1000];
	string str, str2, str3;

	for (int c = 0; c < 10;c++) {

		cin >> str;

		if (str == "-") {

			break;

		}

		cin >> m;

		x = str.size();

		for (int a = 0; a < m; a++) {

			cin >> h[a];

			count = x - h[a];

			str2 = str.substr(0,h[a]);
			
			str3 = str.erase(0,h[a]);
			
			str = str3 + str2;
			
		}

		cout << str << endl;


	}
	
	return 0;
}


Measured memory_bytes: 3220
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

const ll INF = 1e12;
signed main(){
    string s; cin >> s;
    ll k; cin >> k;
    rep(i,s.size()){
        if(s[i]!='1'){
            cout << s[i] << endl;
            return 0;
        }
        if(i+1==k){
            cout<<1<<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <algorithm>
using namespace std;
int main()
{
  int q;
  cin >> q;
  for(int i=0; i<q; i++){
    int n;
    cin >> n;
    int count=0;
    set<int> memo;
    memo.insert(n);
    bool bloop = false;
    while(n > 9){
      int next = 0;
      for(int j=10; j<n; j*=10){
        int a = n/j;
        int b = n%j;
        next = max(next,a*b);
      }
      if(!memo.insert(next).second){
        bloop = true;
        break;
      }
      n = next;
      count++;
    }
    if(bloop) cout << -1 << endl;
    else cout << count << endl;
  }
  return 0;
}

Measured memory_bytes: 1196
# -*- coding: utf-8 -*-
# ITP1_10_C

import statistics

while 1:
    n = int(input())
    if n == 0 :
        break
    data = map(int, input().split())
    """
    statistics.m = mean(data)
    statistics.median = median(data)
    statistics.variance = variance(data)
    """
    std = float(statistics.pstdev(data))
    
    print(std)
    


Measured memory_bytes: 7072
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
ans = sum(A)

from collections import Counter
A = Counter(A)

for i in range(Q):
  B, C = map(int, input().split())
  try:
    var = A[B]
    ans += var*(C-B)
    A.pop(B)
    try:
      A[C] += var
    except:
      A[C] = var
    print(ans)
  except:
    print(ans)

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

int main(void) {
  int N;
  cin >> N;
  map<int64_t, int> mp;
  vector<int64_t> vec;
  rep(i, N) {
    int A;
    cin >> A;
    mp[A]++;
    if ((mp[A] % 2) == 0)
      vec.push_back(A);
  }
  // for (const auto& [key, value] : mp) {
  //    cout << key << " => " << value << endl;
  //  }

  if (vec.size() < 2) {
    cout << "0" << endl;
  } else {
    sort(vec.begin(), vec.end(), greater<int64_t>());
    cout << vec[0] * vec[1] << endl;
  }
  return 0;
}

Measured memory_bytes: 6528
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n, i := scanInt(), scanInt()
	fmt.Fprintln(wr, n+1-i)
}


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

int n, m, sum=0;

int main(){
	cin >> n >> m;
	for (int i=0;i<m;i++){
		int a;
		cin >> a;
		sum+=a;
	}
	cout << (n-sum<0 ? -1 : n-sum) << "\n";
}

Measured memory_bytes: 3632
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
using namespace std;

long double p(int i, int n,int k)
{
	long double c;
	long double N = 1.0 / n;
	for (int j = 0;; j++)
	{

		if ((i + 1) * pow(2,j) >= k)
		{

			c = N*(pow (0.5,  j));
			return c;
		}

	}

}
int main() {
	int n;
	int k;
	long double A[100000] = { 0 };
	long double  total = 0;
	cin >> n;
	cin >> k;
	for (int i = 0; i < n; i++)
	{
		A[i]=p(i,  n, k);
	}
		
	for (int i = 0; i < n; i++)
	{
		total = total + A[i];
	}

	cout << setprecision(11) << total ;
}

Measured memory_bytes: 1792
import sys
import math
input = sys.stdin.readline


def eratosthenes(limit):
    A = [i for i in range(2, limit + 1)]
    P = []

    for i in range(65):
        prime = min(A)

        if prime > math.sqrt(limit):
            break

        P.append(prime)
        for j in range(limit):
            if j >= len(A):
                break
            if A[j] % prime == 0:
                A.pop(j)
                continue

    for a in A:
        P.append(a)

    return P


def binary_search(list, item):
    low = 0
    high = len(list) - 1

    while low <= high:
        mid = (low + high) // 2
        guess = list[mid]
        if guess == item:
            return True
        if guess > item:
            high = mid - 1
        else:
            low = mid + 1
    # 見つからなかったとき
    return None


MAX = 10 ** 5
prime_list = eratosthenes(MAX)
cumsum = [0] * ((MAX + 1) // 2)
cnt = 0

for i in range(1, MAX, 2):
    if binary_search(prime_list, i) and binary_search(prime_list, (i + 1) / 2):
        cnt += 1
    cumsum[(i - 1) // 2] = cnt

q = int(input())
for i in range(q):
    l, r = map(int, input().split())
    if l == 1:
        ans = cumsum[(r - 1) // 2]
    else:
        ans = cumsum[(r - 1) // 2] - cumsum[(l - 3) // 2]
    print(ans)

Measured memory_bytes: 7524
#include <iostream>
#include <string>
#include <vector>
#include <map>

using namespace std;

int main(){
    int m, n, cans, pena;
    cans = 0;
    pena = 0;
    cin >> n >> m;
    map<int, int> mp;
    for(int i=0; i<m; i++){
        string str;
        int p;
        cin >> p >> str;
        if(mp[p] == -1)
          continue;
        else{
            if(str == "WA"){
               mp[p]++;
            }else{
               pena += mp[p];
               cans++;
               mp[p] = -1;
            }
        }
    }

    cout << cans << " " << pena << endl;
    return 0;
}


Measured memory_bytes: 4992
#include <stdio.h>
#include <math.h>
int main() {
	int A[10],C[10],i,j;
	for(i=1;i<=9;i++){
		scanf("%d", &A[i]);
		C[i]=0;
	}
	int N;
	scanf("%d", &N);
	int b[N];
	for(i=1;i<=N;i++){
		scanf("%d", &b[i]);
	}
	for(i=1;i<=N;i++){
		for(j=1;j<=9;j++){
			if(b[i]==A[j]){
				C[j]=1;
			}
		}
	}
	if(C[1]==1 && C[4]==1 && C[7]==1){
		printf("Yes\n");
		return 0;
	}
	if(C[2]==1 && C[5]==1 && C[8]==1){
		printf("Yes\n");
		return 0;
	}
	if(C[3]==1 && C[6]==1 && C[9]==1){
		printf("Yes\n");
		return 0;
	}
	if(C[1]==1 && C[2]==1 && C[3]==1){
		printf("Yes\n");
		return 0;
	}
	if(C[4]==1 && C[5]==1 && C[6]==1){
		printf("Yes\n");
		return 0;
	}
	if(C[7]==1 && C[8]==1 && C[9]==1){
		printf("Yes\n");
		return 0;
	}
	if(C[1]==1 && C[5]==1 && C[9]==1){
		printf("Yes\n");
		return 0;
	}
	if(C[3]==1 && C[5]==1 && C[7]==1){
		printf("Yes\n");
		return 0;
	}
	printf("No\n");
	return 0;
}


Measured memory_bytes: 128
N = int(input())
a = [list(map(int, input().split())) for _ in range(N)]
a.insert(0, [0, 0, 0])
dp = [[0, 0, 0] for _ in range(N+1)]
for i in range(1, N + 1):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i][j] = max(dp[i][j], a[i][j] + dp[i - 1][k])
print(max(dp[-1]))

Measured memory_bytes: 105168
#include <vector>
#include <string>
#include <set>
#include <iterator>
#include <unordered_map>
#include <iomanip>
#include <cmath>
#include <limits>
#include <cstdlib>
#include <numeric>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <unordered_set>
#include <fstream>

using namespace std;

#define Fill(a, b) memset(a, b, sizeof(a))
typedef long long LL;
const LL inf = 1LL << 61;
const LL mod = 1000000007;

#ifndef DEBUG
#define DEBUG
#endif

#ifdef DEBUG
#define Debug(x) cout << #x << "=" << (x) << endl;
#else
#define Debug(x) ;
#endif



int main() {
    
    std::ios::sync_with_stdio(false);
    
    string s;
    cin >> s;
    
    string res = s.substr(0, s.length()-8);
    
    cout << res << endl;
    
    return 0;
}


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

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;

const int MAX_N = (2e5) * 2 + (1e5) + 100;

int nN, M;
vector<pi> Ed[MAX_N];
map<int, vector<int>> G[MAX_N];
map<int, int> Vc[MAX_N]; int Vix[MAX_N];
int N;

int main() {
	cin >> nN >> M;
	for(int i=0; i<M; i++) {
		int x, y, c; scanf("%d%d%d", &x, &y, &c);
		G[x][c].push_back(y);
		G[y][c].push_back(x);
	}
	for(int i=1; i<=nN; i++) {Vix[i] = N++; for(auto &val : G[i]) Vc[i][val.one] = N++;}

	int St = Vix[1], En = Vix[nN];
	for(int i=1; i<=nN; i++) {
		for(auto &val : Vc[i]) {
			int c, v; tie(c, v) = val;
			for(int &x : G[i][c]) {
				int w = Vc[x][c];
				Ed[v].emplace_back(w, 0);
			}
			Ed[v].emplace_back(Vix[i], 0);
			Ed[Vix[i]].emplace_back(v, 1);
		}
		//printf("[%d -> %d]\n", i, Vix[i]);
	}
	
	vector<int> dis(N, INF);
	vector<bool> vis(N, 0);
	deque<int> Q; Q.push_front(St); dis[St] = 0;
	while(!Q.empty()) {
		int v = Q.front(); Q.pop_front();
		if(vis[v]) continue; vis[v] = true;
		//printf("%d -> %d\n", v, dis[v]);
		for(auto &val : Ed[v]) {
			int w, d; tie(w, d) = val;
			if(!vis[w] && dis[w] > dis[v] + d) (d==0 ? Q.push_front(w) : Q.push_back(w)), dis[w] = dis[v] + d;
		}
	}
	printf("%d\n", dis[En]==INF ? -1 : dis[En]);
	return 0;
}


Measured memory_bytes: 142336
import sys
sys.setrecursionlimit(10**7)

N,M = map(int,input().split())
es = [tuple(map(lambda x:int(x)-1,input().split())) for i in range(M)]
gr = [[0 for j in range(N)] for i in range(N)]
for a,b in es:
    gr[a][b] = gr[b][a] = 1
compgr = [[] for i in range(N)]
for i in range(N-1):
    for j in range(i+1,N):
        if gr[i][j]: continue
        compgr[i].append(j)
        compgr[j].append(i)

colors = [0] * N
def dfs(v,color):
    colors[v] = color
    b,w = (1,0) if color==1 else (0,1)
    for to in compgr[v]:
        if colors[to] == color:
            print(-1)
            exit()
        elif colors[to] == 0:
            db,dw = dfs(to, -color)
            b += db
            w += dw
    return [b,w]

dp = set([0])
for i in range(N):
    if colors[i] != 0: continue
    b,w = dfs(i,1)
    dp2 = set()
    for n in dp:
        dp2.add(n+b)
        dp2.add(n+w)
    dp = dp2

ans = N*N
for a in dp:
    b = N-a
    tmp = a*(a-1)//2 + b*(b-1)//2
    ans = min(ans, tmp)
print(ans)

Measured memory_bytes: 34688
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
int main() {
  int H,W;
  cin>>H>>W;
  char a;
  vector<string>vec(H+2);
  string str="#";
  rep(i,W+1){
    str+="#";
  }
  rep(i,H+2){
    vec.at(i)=str;
  }
  rep(i,H){
    rep(j,W){
      cin>>a;
      vec.at(i+1).at(j+1)=a;
    }
  }
  rep(i,H+2){
    cout<<vec.at(i)<<endl;
  }
  
  
}


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

answer = ''
for i in range(len(S)-len(T)+1):
    if any([S[i+j] != '?' and S[i+j] != T[j] for j in range(len(T))]):
        continue
    tmp = (S[:i] + T + S[i+len(T):]).replace('?', 'a')
    if answer == '' or tmp < answer:
        answer = tmp

print('UNRESTORABLE' if answer == '' else answer)

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

const int N = 110;

char s[N];

int main(){
    scanf("%s", s);
    if (!strcmp(s, "keyence")){
        puts("YES");
        return 0;
    }
    int n = strlen(s);
    for (int i = 0; i < n; ++ i){
        for (int j = i; j < n; ++ j){
            if (n - (j - i + 1) != 7) continue;
            std::string str;
            for (int k = 0; k < n; ++ k){
                if (k < i || k > j){
                    str = str + s[k];
                }
            }
            if (str == "keyence"){
                puts("YES");
                return 0;
            }
        }
    }
    puts("NO");
    return 0;
}

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

//---------- 最大公約数 ----------
int64_t gcd(int64_t a, int64_t b){
    if (b > a) return gcd(b, a);

    if(a % b == 0) return b;
    else return gcd(b, a % b);
}

map<int64_t, int> prime_factor(int64_t n) {
  map<int64_t, int> res;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if(n != 1) res[n] = 1;
  return res;
}

int main(){
  int64_t A, B;
  cin >> A >> B;

  int64_t g = gcd(A,B);
  
  map<int64_t, int> prime = prime_factor(g);

  cout << prime.size()+1 << endl;
  
} 

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    
    public void solve(){
        Scanner sc = new Scanner(System.in);
        int syu,mai,b,uri;
        for(int t=0; t<4; t++){
            syu = sc.nextInt();
            if(syu==1){
                b=6000;
                }else if(syu==2){
                    b=4000;
                }else if(syu==3){
                    b=3000;
                }else{
                    b=2000;
            }
            mai = sc.nextInt();
            uri = b*mai;
            System.out.println(uri);
        }
    }
    public static void main(String[] args){
        Main obj = new Main();
        obj.solve();
    }
}

Measured memory_bytes: 17320
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var abc = ReadSplitInt();
            var set = new HashSet<int>();
            foreach (var a in abc)
                set.Add(a);

            Println(set.Count);
        }

        static List<long> ReadLines(long n)
        {
            var l = new List<long>();
            for (long i = 0; i < n; i++)
            {
                l.Add(ReadLong());
            }
            return l;
        }

        static void YESOrNO(bool e) => Println(e ? "YES" : "NO");

        static void YesOrNo(bool e) => Println(e ? "Yes" : "No");

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int SumDigits(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b);
        static long Lcm(long a, long b) => a / Gcd(a, b) * b;

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());
        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}



Measured memory_bytes: 13404
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vll vector<ll>
#define vpll vector<pll>
#define vpii vector<pii>
#define pb push_back
#define eb emplace_back
#define mt make_tuple
#define MP make_pair
#define fs first
#define sc second
#define F first
#define S second
#define nl "\n"
#define asche cerr<<"Ekhane asche\n";
#define pf printf
#define sf scanf
#define mem(a,x) memset(a,x,sizeof(a))
#define SZ(v) (int)v.size()
#define all(v) v.begin(),v.end()
#define one(x) __builtin_popcount(x)
#define fout(x) fixed<<setprecision(x)
#define BeatMeScanf ios_base::sync_with_stdio(false)
//int dx[]={1,0,-1,0,1,-1,-1,1};
//int dy[]={0,1,0,-1,1,1,-1,-1};
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); deb(_it, args); }
void deb(istream_iterator<string> it) {}
template<typename T, typename... Args>
void deb(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    deb(++it, args...);
}
template <typename T> using o_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
namespace IO
{
    #define in() ( { int a ; scanf("%d",&a); a; } )
    #define LL() ( { ll a ; scanf("%lld",&a); a; } )
       #define ULL() ( { ull a ; scanf("%llu",&a); a; } )
    #define DD() ({ double a; scanf("%lf", &a); a;})
    #define CC() ( { char a ; scanf("%c",&a); a; } )
    #define pf1(a) printf("%d\n",a)
    #define pf1ll(a) printf("%lld\n",a)
}
using namespace IO;

const int mod=1e9+7;
const int N=3e5+9;
const double eps=1e-9;
const double PI=acos(-1.0);
ll qpow(ll n,ll k) {ll ans=1;assert(k>=0);n%=mod;while(k>0){if(k&1) ans=(ans*n)%mod;n=(n*n)%mod;k>>=1;}return ans%mod;}

int a[N];
int32_t main()
{
    int n=in(),k=in();
    for(int i=1;i<=n;i++){
        a[i]=in();
        a[i]++;
    }
    o_set<int>se;
    ll inv=0;
    for(int i=1;i<=k;i++){
        inv+=i-1-se.order_of_key(a[i]);
        se.insert(a[i]);
    }
    int ans=0,ok=0;
    if(inv) ans++;
    else ok=1;
    //debug(inv);
    for(int i=k+1;i<=n;i++){
        ll last=inv;
        inv-=se.order_of_key(a[i-k]);
        se.erase(a[i-k]);
        inv+=k-1-se.order_of_key(a[i]);
        if(inv==0) ok=1;
        else if(last!=inv) ans++;
        else if(*(--se.end())>a[i]) ans++;
        se.insert(a[i]);
        //debug(inv);
    }
    ans+=ok;
    pf1(ans);
    return 0;
}
///Before submit=>
///    *check for integer overflow,array bounds
///    *check for n=1



Measured memory_bytes: 10368
#include "bits/stdc++.h"
using namespace std;
using ll = long long;



class SegmentTree {
public:
	SegmentTree() {}
	SegmentTree(ll size) {
		n = 1;
		while (n < size)n *= 2;
		dat.resize(2 * n, 0);
	}
	void update(ll k, ll a) {
		k += n - 1;
		dat[k] = a;
		while (k > 0) {
			k = (k - 1) / 2;
			dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
		}
	}
	ll query(ll a, ll b) {
		return query_impl(a, b, 0, 0, n);
	}
private:
	ll n;
	vector<ll> dat;

	ll query_impl(ll a, ll b, ll k, ll l, ll r) {
		if (r <= a || b <= l)return 0;
		if (a <= l && r <= b)return dat[k];

		ll vl = query_impl(a, b, k * 2 + 1, l, (l + r) / 2);
		ll vr = query_impl(a, b, k * 2 + 2, (l + r) / 2, r);
		return max(vl, vr);
	}
};


ll N, M, C;
SegmentTree stl, str;

bool judge(ll d) {
	vector<ll> res(N);
	for (ll i = 0; i < N; i++) {
		ll a = stl.query(max(0ll, i - d), i + 1) - C * i;
		ll b = str.query(i, min(N - 1, i + d) + 1) - C * (N - 1 - i);
		res[i] = max(a, b);
	}
	return accumulate(res.begin(), res.end(), 0ll) >= M;
}

int main() {
	cin >> N >> M >> C;
	stl = SegmentTree(N);
	str = SegmentTree(N);
	for (int i = 0; i < N; i++) {
		ll ai;
		cin >> ai;
		stl.update(i, ai + C * i);
		str.update(i, ai + C * (N - 1 - i));
	}

	int l = 0, r = N;
	while (r - l > 1) {
		int mid = (l + r) / 2;
		if (judge(mid))r = mid;
		else l = mid;
	}
	if (r == N && !judge(r)) {
		cout << -1 << endl;
	}
	else {
		if (judge(l))cout << l << endl;
		else cout << r << endl;
	}
	return  0;
}


Measured memory_bytes: 7880
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	int i=0;
	char x[27]={"ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
	char y[27]={"DEFGHIJKLMNOPQRSTUVWXYZABC"};
	string str;
	cin>>str;
	while(str[i]){
		//cout<<"OK!"<<endl;
		for(int j=0;j<26;j++){
			if(str[i]==y[j]){
			//cout<<"OK"<<endl;
			str[i]=x[j];
			break;
			}
		}
		i++;
	}
	cout<<str<<endl;
return 0;
}

Measured memory_bytes: 1180
#include <iostream>
#include <string.h>

using namespace std;

int main()
{
    string s1,s2;
    cin>>s1;
    cin>>s2;
    
    int num=0;
    for(int i=0;i<s1.length();i++){
        if(s1[i]!=s2[i]){
            num++;
        }
    }
    cout<<num<<endl;

    return 0;
}


Measured memory_bytes: 3468
#include <iostream>
#include <string>    
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll n, m;

int main() {
	ll magic = 100000;
	ll t[magic+1][2] = {};//prime. 2017like
	t[1][0] = -1;
	for(ll i = 2; i*i <= magic; i++){
		if(t[i][0] == 0){
			for(ll j = 2; j*i <= magic; j++){
				t[j*i][0] = -1;
			}
		}
	}
	
	for(ll i = 1; i <= magic/2; i++){
		if(t[2*i-1][0] == 0 && t[i][0] == 0){
			t[2*i-1][1] = 1;
		}
	}
	
	for(ll i = 1; i <= magic; i++){
		t[i][1] += t[i-1][1];
	}
	
	//for(ll i = 0; i <= 100; i++){cout << i << " " << t[i][1] << endl;}
	
	ll q, l, r;
	cin >> q;
	for(ll i = 0; i < q; i++){
		cin >> l >> r;
		cout << t[r][1]-t[l-1][1] << endl;
	}
	return 0;
}

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

int main(){
  string s;
  cin >> s;
  int count = 0;
  for(int i = 0; i < s.size() / 2; i++){
    if(s[i] != s[s.size() - i - 1]) count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 3628
N,K = map(int,input().split())
K += 1

AB = []

for i in range(N):

    a,b = map(int,input().split())
    AB.append([a,b,format(a,'b')])

kb = format(K,'b')
#print (kb)
ans = 0

for i in range(len(kb)):

    now = 0
    if kb[-1-i] == "1":

        for j in range(N):

            flag = True
            at = AB[j][2]

            if len(kb) < len(at):
                continue

            for m in range(len(at)):

                

                if m == i and at[-1-m] == "1":
                    flag = False
                    break

                elif m > i and kb[-1-m] == "0" and at[-1-m] == "1":
                    flag = False
                    break

            if flag:
                now += AB[j][1]

        #print (i,now)
        ans = max(ans,now)
        
print (ans)


Measured memory_bytes: 88792
lst_1 = input().split()

N = int(lst_1[0])
M = int(lst_1[1])
X = (lst_1[2])
Y = (lst_1[3])

lst_X = input().split()
lst_Y = input().split()

lst_X.append(X)
lst_Y.append(Y)

for i in range(N+1):
    lst_X[i] = int(lst_X[i])
for i in range(M+1):
    lst_Y[i] = int(lst_Y[i])

X_max = max(lst_X)
Y_min = min(lst_Y)

if X_max < Y_min:
    ans = "No War"

else:
    ans = "War"

print(ans)

Measured memory_bytes: 3064
a,b,c = (input() for _ in range(3))
na,nb,nc = len(a),len(b),len(c)
now = 'a'
while(na*nb*nc>=0):
    if(now=='a'):
        na-=1
        if(na<0):
            print('A')
            break
        now=a[0]
        a=a[1:]
    elif(now=='b'):
        nb-=1
        if(nb<0):
            print('B')
            break
        now=b[0]
        b=b[1:]
    else:
        nc-=1
        if(nc<0):
            print('C')
            break
        now=c[0]
        c=c[1:]

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

using namespace __gnu_pbds;
using namespace std;

using ll = long long;
using ld = long double;

#define mp make_pair

typedef tree<
        pair<int, int>,
        null_type,
        less<pair<int, int>>,
        rb_tree_tag,
        tree_order_statistics_node_update>
        ordered_set;


const int p = 1000000007;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

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

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}


mt19937 rnd(time(0));

/*
const int N = 1200000;

vector<int> facs(N), invfacs(N);

void init()
{
    facs[0] = 1;
    for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i);
    invfacs[N-1] = inv(facs[N-1]);
    for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}

int C(int n, int k)
{
    if (n<k) return 0;
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}
*/

const int ALPHABET_SIZE = 26;

ll cnt = 0;

// trie node
struct TrieNode
{
    struct TrieNode *children[ALPHABET_SIZE];
    int endHere = 0;
};

// Returns new trie node (initialized to NULLs)
struct TrieNode *getNode(void)
{
    struct TrieNode *pNode =  new TrieNode;

    pNode->endHere = 0;

    for (int i = 0; i < ALPHABET_SIZE; i++)
        pNode->children[i] = NULL;

    return pNode;
}

// If not present, inserts key into trie
// If the key is prefix of trie node, just
// marks leaf node
void insert(struct TrieNode *root, string key)
{
    struct TrieNode *pCrawl = root;

    vector<int> let(26);
    for (auto c: key) let[c-'a']++;

    for (int i = 0; i < key.length(); i++)
    {
        int index = key[i] - 'a';
        for (int index1 = 0; index1<26; index1++) if (let[index1] && index1!=index && pCrawl->children[index1]) cnt+=pCrawl->children[index1]->endHere;

        let[index]--;

        if (!pCrawl->children[index])
            pCrawl->children[index] = getNode();

        pCrawl = pCrawl->children[index];
        cnt+=pCrawl->endHere;
    }

    // mark last node as leaf
    pCrawl->endHere++;
}


const int N = 1e6;



int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);

    int n; cin>>n;
    vector<vector<string>> lol(N+1);
    for (int i = 0; i<n; i++)
    {
        string s; cin>>s; reverse(s.begin(), s.end()); lol[s.size()].push_back(s);
    }

    struct TrieNode *root = getNode();

    for (int i = 1; i<=N; i++) for (auto s: lol[i]) insert(root, s);
    cout<<cnt;

}


Measured memory_bytes: 246128
n = int(input())
a = [0] * n
for i in range(n):
  a[i] = int(input())

a.sort()

c0 = [0] * n
for i in range(n-1):
  if i%2:
    c0[i] += 1
    c0[i+1] += -1
  else:
    c0[i+1] += 1
    c0[i] += -1
    
c0.sort()

s0 = sum(i*j for i, j in zip(a, c0))
s1 = sum(-i*j for i, j in zip(a, c0[::-1]))

print(max(s0, s1))
      

Measured memory_bytes: 8744
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		String s = sc.next();
		if (s.matches("[0-9]{"+a+"}-[0-9]{"+b+"}")) System.out.println("Yes");
		else System.out.println("No");
        sc.close();
	}
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    double ave = 0;
    rep(i, n) ave += a[i];
    ave /= n;

    double sa = INF;
    int ans = 0;

    for (int i = n - 1; i >= 0; --i) {
        if (sa >= abs(ave - a[i])) {
            ans = i;
            sa = abs(ave - a[i]);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;
 
int main(){

    long A,B,K;
    cin>>A>>B>>K;

    if(A>=K){
        A-=K;
        K=0;
    }else{
        K-=A;
        A=0;
    }
    if(B>=K){
        B-=K;
    }else{
        B=0;
    }
    
    cout <<A<<" "<<B<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
template<C T>void pr(T a){cout<<a;ln;}
template<C T,C T2>void pr(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n;
  R n;
  int a[n];
  rep(i,n) {
    R a[i];
    a[i]--;
  }
  int ans=0;
  rep(i,n) {
    if(a[a[i]]==i) ans++;
  }
  pr(ans/2);
}

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  Main();return 0;
}


Measured memory_bytes: 640
class UnionFind():
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x

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


n, k, l = map(int, input().split())

uf1 = UnionFind(n)
for _ in range(k):
    p, q = map(int, input().split())
    uf1.union(p - 1, q - 1)

uf2 = UnionFind(n)
for _ in range(l):
    r, s = map(int, input().split())
    uf2.union(r - 1, s - 1)

d = dict()
for i in range(n):
    f1 = uf1.find(i)
    f2 = uf2.find(i)
    t = (f1, f2)
    d[t] = d.get(t, 0) + 1

ans = []
for i in range(n):
    f1 = uf1.find(i)
    f2 = uf2.find(i)
    t = (f1, f2)
    ans.append(d[t])

print(*ans)

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

int main(){
    string s;
    long long k;

    cin >> s >> k;

    bool one_kind = true;
    for(long long i = 0; i < s.size()-1; i++){
        if(s[i] != s[i+1]){
            one_kind = false;
            break;
        }
    }

    if(one_kind == true){
        cout << s.size()*k/2 << endl;
        return 0;
    }

    if(s[0] != s[s.size()-1]){
        long long i = 0;
        long long count = 0;
        while(i < s.size()){
            if(s[i] == s[i+1]){
                long long length = 1;
                while(i < s.size() and s[i] == s[i+1]){
                    i++;
                    length++;
                }
                count += length/2;
           
            }
     
            i++;   
        }

        cout << count*k << endl;
        return 0;
    }
    else{
        long long i = 0;
        long long first_length = 1;

        while(i < s.size()){
            if(s[0] == s[1]){
                long long length = 1;
                while(i < s.size() and s[i] == s[i+1]){
                    i++;
                    length++;
                }
                first_length = length;
            }
            break;  
        }

        i = s.size()-1;
        long long last_length = 1;

        while(i >= 0){
            if(s[s.size()-1] == s[s.size()-2]){
                long long length = 1;
                while(i < s.size() and s[i] == s[i-1]){
                    i--;
                    length++;
                }
                last_length = length;
            }
            break;  
        }

        i = 0;
        long long count = 0;

        while(i < s.size()){
            if(s[i] == s[i+1]){
                long long length = 1;
                while(i < s.size() and s[i] == s[i+1]){
                    i++;
                    length++;
                }
                count += length/2;
            }
            i++;   
        }
        //cout << "count " << count << endl;

        //cout << "first length" << first_length << "last_length" << last_length << endl;

        cout << count*k + (k-1)*((first_length+last_length)/2 - first_length/2 - last_length/2) << endl;

        return 0;
    }

  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define llINF 1000000000000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[200010];
struct edge{int to,cost;};
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
void init_fact(int n){
	kaijo[0]=1;
	for(int i=1;i<=n;i++){
		kaijo[i]=kaijo[i-1]*i;
		kaijo[i]%=MOD;
	}
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	int memo=modpow(a,b/2);
	return memo*memo%MOD;
}
int comb(int a,int b){
	return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
//int g(int x){
//	x=modpow(x,MOD-2);
//	return x;
//}
int n,m,l,d[334][334],D[334][334];
signed main(){
	cin>>n>>m>>l;
	rep(i,n){
		rep(j,n){
			if(i==j)d[i][j]=0;
			else d[i][j]=llINF;
		}
	}
	rep(i,m){
		int a,b,c;
		cin>>a>>b>>c;
		a--,b--;
		d[a][b]=d[b][a]=c;
	}
	rep(k,n){
		rep(i,n){
			rep(j,n){
				d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
			}
		}
	}
	rep(i,n){
		rep(j,n){
			if(i==j)D[i][j]=0;
			else D[i][j]=llINF;
		}
	}
	rep(i,n){
		rep(j,n){
			if(i!=j){
				if(d[i][j]<=l)D[i][j]=1;
			}
		}
	}
	rep(k,n){
		rep(i,n){
			rep(j,n){
				D[i][j]=min(D[i][j],D[i][k]+D[k][j]);
			}
		}
	}
	int Q;
	cin>>Q;
	while(Q--){
		int S,T;
		cin>>S>>T;
		S--,T--;
		if(D[S][T]==llINF)puts("-1");
		else cout<<D[S][T]-1<<endl;
	}
	return 0;
}


Measured memory_bytes: 2048
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tp3 = tuple<int, int, int>;
using Mat = vector<vector<ll>>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}
// ============ template finished ============

int main()
{
    int L, R, d;
    cin >> L >> R >> d;
    int vl = (L - 1) / d;
    int vr = R / d;
    cout << vr - vl << endl;
    return 0;
}


Measured memory_bytes: 3596
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.StringTokenizer;

public class Main {
	
	public static boolean dfs(int node, int parent, ArrayList<HashSet<Integer>> adj, boolean[] visited, boolean[] looped) {
		if(looped[node]) { 
			return looped[node];
		}else if(visited[node]) {
			return looped[node] = true;
		}
		
		visited[node] = true;
		for(final int next : adj.get(node)) {
			if(next == parent) { continue; }
			
			if(dfs(next, node, adj, visited, looped)) {
				looped[node] = true;
			}
		}
		
		return looped[node];
	}
	
	public static void main(String[] args) throws IOException {
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			final int M = sc.nextInt();
			
			ArrayList<HashSet<Integer>> adj = new ArrayList<HashSet<Integer>>();
			for(int i = 0; i < N; i++) { adj.add(new HashSet<Integer>()); }
			
			for(int i = 0; i < M; i++) {
				final int x = sc.nextInt() - 1;
				final int y = sc.nextInt() - 1;
				final int w = sc.nextInt();
				
				adj.get(x).add(y);
				adj.get(y).add(x);
			}
			
			boolean[] visited = new boolean[N];
			boolean[] looped = new boolean[N];
			
			
			int count = 0;
			for(int i = 0; i < N; i++) {
				if(visited[i]) { continue; }
				//System.out.println(i);
				
				if(dfs(i, -1, adj, visited, looped)) {
					//count += 1;
				}
				count += 1;
			}
			
			System.out.println(count);
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

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

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 91208
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define mkp make_pair
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repre(i,a,b)for(int i=a;i<=b;i++)
#define clr1(arr) memset(arr,-1,sizeof(arr));
#define clr0(arr) memset(arr,0,sizeof(arr));
#define pi pair<int,int>
#define pii pair<int,pi>
#define aint(v) v.begin(),v.end()
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> orderedSet;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> orderedMSet;
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define ump gp_hash_table<int,int,custom_hash>
//*p.find_by_order(index) return value at index
//p.order_of_key(key) return index
/*int **dp,in main function,int row,col;dp=new int*[n];rep(i,n)dp[i]=new int[m]*/
//**** Maths Section*******/
int power(int x,int y);
bool isPrime(int n);
int modInv(int a,int b);
int gcdExtended(int a,int b,int *x,int* y);
int mpower(int a,int b,int p);
/***************************/
int32_t main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  fastio
  int n;
  cin>>n;
  string a,b;
  cin>>a>>b;
  string ans="";
  rep(i,n)
  {
    ans+=a[i];
    ans+=b[i];
  }
  cout<<ans<<endl;
  return 0;
}

int modInv(int a, int m)
{
int x, y;
int g = gcdExtended(a, m, &x, &y);
int res = (x%m + m) % m;
return res;
}

int gcdExtended(int a, int b, int *x, int *y)
{
if (a == 0){
    *x = 0, *y = 1;
    return b;
  }
  int x1, y1;
  int gcd = gcdExtended(b%a, a, &x1, &y1);
  *x = y1 - (b/a) * x1;
  *y = x1;
  return gcd;
}

int mpower(int x, int y, int p)
{
int res = 1;
x = x % p;
while(y > 0){
    if(y & 1) res = (res*x) % p;
      y = y>>1;
      x = (x*x) % p;
    }
    return res;
}
int power(int x, int y)
{
int res = 1;
while (y > 0){
    if (y & 1) res = res*x;
      y = y>>1;
      x = x*x;
    }
    return res;
}

bool isPrime(int n)
{
if (n <= 1)  return false;
  if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
      int p=sqrt(n);
      for(int i=5;i<=p;i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
          return false;
      return true;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
    int N, D, X;
    cin >> N >> D >> X;
    int sum = 0;
    for (int i=0; i< N; i++) {
        int choco = 1;
        int A;
        cin >> A;
        int day = A + 1;
        int count = 1;
        while (day <= D) {
            choco += 1;
            count += 1;
            day = (count * A) + 1;
        }

        sum += choco;
    }

    cout << sum + X << endl;
    return 0;
}

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

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = 2000 + 10;
const int MOD = 1000000007;
const int LOG = 20;
const int INF = 1000000010;
const int delta = 11353;

int DP[N][N], PS[N][N], n, k, tav;

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	tav = 1;
	cin >> n >> k;
	if (n == 1) return cout << 1, 0;
	for (int i = 1; i <= n - k - 1; i++) tav = tav * 2ll % MOD;
	DP[1][0] = 1;
	PS[1][0] = PS[1][1] = 1;
	for (int i = 2; i <= n - 1; i++){
		for (int j = 0; j <= i - 1; j++){
			DP[i][j] = DP[i - 1][j];
			if (j != 0) DP[i][j] = (DP[i][j] + PS[i - 1][j - 1]) % MOD;
		}
		for (int j = 0; j <= i; j++) PS[i][j] = (j == 0?DP[i][j]:(DP[i][j] + PS[i][j - 1]) % MOD);
	}
	cout << PS[n - 1][k - 1] * 1ll * tav % MOD << '\n';
	//cout << (n - 1) * 1ll * tav % MOD;
	return 0;
}


Measured memory_bytes: 31192
const MAX_N: usize = 310;
const INF: u64 = 1_u64 << 60;
fn solve() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let k: usize = sc.read();
    let mut tmp_h: Vec<usize> = sc.vec(n);
    let mut h = vec![0];
    h.append(&mut tmp_h);
    h.push(0);
    let mut dp = vec![vec![INF; MAX_N]; MAX_N];
    dp[0][0] = 0;
    for i in 0..n + 2 {
        for j in 0..k + 1 {
            if dp[i][j] == INF {
                continue;
            }
            for x in i + 1..n + 2 {
                let cost = x - i - 1;
                let diff = if h[x] > h[i] { h[x] - h[i] } else { 0 };
                if cost + j <= k {
                    dp[x][cost + j] = std::cmp::min(dp[x][cost + j], dp[i][j] + diff as u64);
                }
            }
        }
    }
    let result = dp[n + 1].iter().min().unwrap();
    println!("{}", result);
}

fn main() {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024) // 64MB
        .spawn(|| solve())
        .unwrap()
        .join()
        .unwrap();
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 8572
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
using namespace std;
#define ll long long
#define rep(i, s, n) for(int i = s; i < n; i++)

int main() {
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++) {
        cout << "x";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256