akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{

			int n = int.Parse(Console.ReadLine());

			string str = Console.ReadLine();
			char[] arr = str.ToCharArray();


			long sum = 0;

			for (int i = 1; i < n; i ++)
			{
				if (arr[i - 1] != arr[i]) sum++;
			}

			Console.WriteLine(sum + 1);

		}

	}

}


Measured memory_bytes: 13176
#include<bits/stdc++.h>
#define int long long int
#define rep(a,b,c) for(int a=b;a<c;a++)
#define repm(a,b,c) for(int a=(b-1);a>=c;a--)
#define pb push_back
#define str string
#define INF 1<<64
#define sf(a) scanf("%d",&a)
using namespace std;
int replac(str s){double ans=0;rep(i,0,s.length()){ans+=(s[i]-'0')*pow(10,s.length()-i-1);}return (int)ans;}
typedef pair<int,int> pii;
vector<pii> vii;
int n=0,cade[100005];

signed main(){
    fill(cade,cade+100005,0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    rep(i,0,n){
        cin >> cade[i];
    }
    int i=0,j=n-1,ans=0;
    while(1){
        if(cade[i]%2){
            if(cade[i+1]){
                ans++;
                cade[i+1]--;
                cade[i]--;
            }
            ans+=cade[i]/2;
                cade[i]=cade[i]%2;
        }else{
            ans+=cade[i]/2;
            cade[i]=0;
        }
        if(1){
            if(cade[j]%2){
                if(cade[j-1]){
                    ans++;
                    cade[j-1]--;
                    cade[j]--;
                }
                ans+=cade[j]/2;
                cade[j]=cade[j]%2;
            }else{
                ans+=cade[j]/2;
                cade[j]=0;
            }
        }
        i++;
        j--;
        if(i>j)break;
    }
    cout << ans << endl;
return 0;
}



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

using namespace std;


#define ff				first
#define ss				second
#define int				long long
#define pb				push_back
#define mp				make_pair
#define pii				pair<int,int>
#define vi				vector<int>
#define mii 			map<int,int>
#define	pqb				priority_queue<int>
#define pqs				priority_queue<int,vi,greater<int> >
#define setbits(x)		__builtin_popcountll(x)
#define zrobits(x)		__builtin_ctzll(x)
#define mod				1000000007
#define inf 			1e18
#define ps(x,y)			fixed<<setprecision(y)<<x
#define mk(arr,n,type)	type *arr = new type[n]
#define w(x)			int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)


void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

}


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

	}
	return true;
}

vector<int> Sieve(int n)
{
	bool prime[n + 1];
	memset(prime, true, sizeof(prime));
	for (int i = 2; i * i <= n; i++)
	{
		if (prime[i])
		{
			for (int j = i * i; j <= n; j += i)
			{
				prime[j] = false;
			}
		}
	}
	vi primes;
	for (int i = 2; i <= n; i++)
	{
		if (prime[i])
			primes.pb(i);
	}
	return primes;
}



set<int> primeFactors(int  n)
{
	set<int> factors;
	while (n % 2 == 0)
	{
		n /= 2;
		factors.insert(2);

	}
	for (int i = 3; i <= sqrt(n); i += 2)
	{
		while (n % i == 0)
		{
			factors.insert(i);
			n /= i;
		}
	}
	if (n > 2)
		factors.insert(n);
	return factors;
}


// int power(int x, unsigned int y, int p)
// {
// 	int res = 1;     // Initialize result

// 	x = x % p; // Update x if it is more than or
// 	// equal to p

// 	if (x == 0) return 0; // In case x is divisible by p;

// 	while (y > 0)
// 	{
// 		// If y is odd, multiply x with result
// 		if (y & 1)
// 			res = (res * x) % p;

// 		// y must be even now
// 		y = y >> 1; // y = y/2
// 		x = (x * x) % p;
// 	}
// 	return res;
// }
// Graph------------------------------------------------------------------------


int32_t main()
{
	FIO;
	// c_p_c();
// --------------------------------------------------

	int a, b;
	char c;
	cin >> a >> c >> b;
	if (c == '+')
	{
		cout << a + b << endl;
	}
	else
		cout << a - b << endl;
}





Measured memory_bytes: 256
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	k := iScan()
	td := make([][2]int, n)
	for i := 0; i < n; i++ {
		td[i][0], td[i][1] = iScan(), iScan()
	}
	sort.Slice(td, func(i, j int) bool { return td[i][1] > td[j][1] })
	h := &IntHeap{}
	heap.Init(h)
	d := make(map[int]struct{})
	s := 0
	for i := 0; i < k; i++ {
		s += td[i][1]
		if _, ok := d[td[i][0]]; ok {
			heap.Push(h, td[i][1])
		} else {
			d[td[i][0]] = struct{}{}
		}
	}
	ans := s + len(d)*len(d)
	for i := k; i < n; i++ {
		if h.Len() == 0 {
			break
		}
		if _, ok := d[td[i][0]]; !ok {
			d[td[i][0]] = struct{}{}
			s -= heap.Pop(h).(int)
			s += td[i][1]
			ans = larger(ans, s+len(d)*len(d))
		}
	}
	fmt.Println(ans)
}

type IntHeap []int

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] < h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *IntHeap) Push(x interface{}) {
	*h = append(*h, x.(int))
}
func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}


Measured memory_bytes: 7888
#include <iostream>
#include <queue>
bool is_prime(int num);

using namespace std;

int main(){
  int i;
  int j = 0;
  int primes[10000];
  for (i = 1; i <= 10000; ++i){
    if(is_prime(i)){primes[j] = i;j++;}
  }
  int input;
  int sum;
  int count;
  int vector_index = 0;
  while(cin>>input){
    if(input==0){break;}

    // initialization
    vector_index = 0;
    queue<int> sum_components;
    sum_components.push(primes[vector_index]);
    sum = primes[vector_index];
    vector_index++;
    count = 0;

    //???????????¨???
    while(sum_components.back() <= input){
      if(sum < input){
        sum_components.push(primes[vector_index]);
        sum += primes[vector_index];
        vector_index++;
      }else if(sum == input){
        count++;
        sum_components.push(primes[vector_index]);
        sum += primes[vector_index];
        vector_index++;
      }else{
        sum -= sum_components.front();
        sum_components.pop();
      }
    }
    cout << count << endl;
  }

}

bool is_prime(int num){
  if(num<2){return false;}
  if(num==2){return true;}
  for (int i = 2; i < num; ++i){
    if(num%i == 0){return false;}
  }
  return true;
}

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

int x,ans,minn;
int main()
{
	minn=9999999;
	for (int i=1; i<=5; i++)
	{
		cin>>x;
		ans+=(x/10);
		if (x%10!=0) ans++,minn=min(minn,x%10);
	}
	if (minn!=9999999) ans=(ans-1)*10+minn;
	else ans=ans*10;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
a=[[0 for x in range(14)] for y in range(4)]
for i in range(n):
    lis=input().split()
    if lis[0]=="S":
        a[0][int(lis[1])]=1
    elif lis[0]=="H":
        a[1][int(lis[1])]=1
    elif lis[0]=="C":
        a[2][int(lis[1])]=1
    else:
        a[3][int(lis[1])]=1

for i in range(4):
    for j in range(1,14):
        if a[i][j]==0:
            if i==0:
                print("S {}".format(j))
            elif i==1:
                print("H {}".format(j))
            elif i==2:
                print("C {}".format(j))
            elif i==3:
                print("D {}".format(j))        


Measured memory_bytes: 5612
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	final int _intMax = Integer.MAX_VALUE; // =2147483647>10^9
	final int _intMin = Integer.MIN_VALUE;
	final long _longMax = Long.MAX_VALUE; // =9223372036854775807L>10^18
	final long _longMin = Long.MIN_VALUE;
	static boolean bElapsed = false;

	void solve() {
		int[][] map = new int[3][3];
		for (int i = 0; i < 3; i++) {
			int[] ia = readNums();
			for (int j = 0; j < 3; j++) {
				map[i][j] = ia[j];
			}
		}
		int[][] delta = new int[4][3];
		for (int i = 0; i < 3; i++) {
			delta[0][i] = map[i][1] - map[i][0];
			delta[1][i] = map[i][2] - map[i][1];
			delta[2][i] = map[1][i] - map[0][i];
			delta[3][i] = map[2][i] - map[1][i];
		}
		for (int j = 0; j < 4; j++) {
			for (int i = 0; i < 2; i++) {
				if (delta[j][i] != delta[j][i + 1]) {
					pln("No");
					return;
				}
			}
		}
		pln("Yes");
	}

	int abs(int a) {
		return (a >= 0) ? a : -a;
	}

	int max(int a, int b) {
		return (a > b) ? a : b;
	}

	int min(int a, int b) {
		return (a < b) ? a : b;
	}

	int pint(String s) {
		return Integer.parseInt(s);
	}

	long plong(String s) {
		return Long.parseLong(s);
	}

	String readLine() {
		try {
			return _in.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	int readNum() {
		String line = readLine();
		return pint(line);
	}

	String[] readFlds() {
		String line = readLine();
		return line.split(" ");
	}

	int[] readNums() {
		String[] flds = readFlds();
		int[] nums = new int[flds.length];
		for (int i = 0; i < flds.length; i++) {
			nums[i] = pint(flds[i]);
		}
		return nums;
	}

	void p(char c) {
		_out.print(c);
	}

	void pln(char c) {
		_out.println(c);
	}

	void p(double d) {
		_out.print(d);
	}

	void pln(double d) {
		_out.println(d);
	}

	void p(long l) {
		_out.print(l);
	}

	void pln(long l) {
		_out.println(l);
	}

	void p(String s) {
		_out.print(s);
	}

	void pln(String s) {
		_out.println(s);
	}

	static BufferedReader _in;
	static PrintWriter _out;

	public static void main(String[] args) {
		long start = System.currentTimeMillis();
		_in = new BufferedReader(new InputStreamReader(System.in));
		_out = new PrintWriter(System.out);
		new Main().solve();
		_out.flush();
		long end = System.currentTimeMillis();
		if (bElapsed) {
			System.err.println((end - start) + "ms");
		}
	}
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
string s;
char x[2]={'C','F'};
bool gj=false;
int m=0;
int main()
{
	getline(cin,s);
	for(int i=0;i<s.size();++i)
	{
		if(s[i]==x[m])
		{
			if(m==1)
			{
				gj=true;
				break;
			}
			else
			{
				m++;
			}
		}
	}
	if(gj==true)
		cout<<"Yes"<<endl;
	else 
		cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let s: String = sc.next();
    let ans: u8 = match s.as_ref() {
        "SUN" => 7,
        "MON" => 6,
        "TUE" => 5,
        "WED" => 4,
        "THU" => 3,
        "FRI" => 2,
        "SAT" => 1,
        _ => panic!(),
    };

    println!("{}", ans);
}

/* ========== Scanner ========== */

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn read<T: FromStr>(&mut self) -> Option<T> {
        let token = self
            .reader
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn next<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.read() {
            s
        } else {
            writeln!(stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.next()).collect()
    }

    fn char(&mut self) -> char {
        self.next::<String>().chars().next().unwrap()
    }
}


Measured memory_bytes: 4352
import java.util.*;
public class Main{

	public static void main(String[] args) {
		int i1, i2, i3;
		Scanner sc = new Scanner(System.in);
		i1 = sc.nextInt();
		i2 = sc.nextInt();
		i3 = sc.nextInt();
		if(i1 < i2 && i2 < i3)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}

Measured memory_bytes: 17160
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
static const int INF (1<<30);

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

  if (N == 1) {
    cout << 0 << endl;
    return 0;
  } else if (N == 2) {
    cout << 1 << endl;
    return 0;
  }

  ll ans;

  if ((N-2)%2 == 0) {
    ans = ((N-2)/2) * (N+1) + 1;
    //ans = ((N-2)/2) * (N+1);
  } else {
    ans = ((N+1)/2) * (N-2) + 1;
  }

  cout << ans << endl; 

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#define nmax_def 110
using namespace std;
typedef long long ll;

int main() {
	int i, j;
	int N, X, L[nmax_def];
	int sum = 0;
	int ans = 0;
	cin >> N >> X;
	for (i = 0; i < N; i++)
	{
		cin >> L[i];
	}
	i = 0;
	while (1)
	{
		if (sum <= X)
			ans++;
		if (i < N)
			sum += L[i];
		else
			break;
		i++;
	}
	cout << ans << endl;
	return 0;
}

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

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

long long MOD = 1000000000 + 7;
long long MAX = 1000000000000000000;

int main(){
  cout << setprecision(10);
  int N,M;
  cin >> N >> M;

  map<int,string> order;
  map<string,string> ans;


  vector<vector<ll>> pref(N);

  for(int i = 0; i < M; i++){
    int tmp1;
    ll tmp2;
    cin >> tmp1 >> tmp2;

    pref[tmp1-1].push_back(tmp2);

    string key = to_string(tmp1) + "-" + to_string(tmp2);
    order[i] = key;
  }

  for(int i = 0; i < N; i++){
    if(pref.at(i).size() == 0) continue;

    sort(pref.at(i).begin(), pref.at(i).end());
    for(int j = 0; j < pref.at(i).size(); j++){
      int num = j + 1;
      string id = to_string(num);
      while(id.size() < 6){
        id = "0" + id;
      }
      id = to_string(i+1) + id;

      while(id.size() < 12){
        id = "0" + id;
      }

      string key = to_string(i+1) + "-" + to_string(pref.at(i).at(j));
      ans[key] = id;
    }
  }

  for(int i = 0; i < M; i++){
    cout << ans[order[i]] << endl;
  }
}



Measured memory_bytes: 36608
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<map>
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl
typedef long long ll;
const ll MOD = 1000000007;
 
using namespace std;

int main(){
    int N, tmp, ans;  cin >> N;
    vector<int> v(N);
    ans = 10000000;
    for(int i=0; i<N; i++)  cin >> v[i];
    for(int i=0; i<103; i++){
        tmp = 0;
        for(int j=0; j<N; j++)  tmp += (v[j] - i)*(v[j] - i);
        ans = min(ans,tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int n;
int a[200005];
int main()
{
    scanf("%d",&n);
    for(int i = 1;i <= n;i++) {scanf("%d",&a[i]);a[i] -= i;}
    sort(a+1,a+n+1);
    int b = a[n / 2 + n % 2];
    long long ans = 0;
    for(int i = 1;i <= n;i++){
        ans += (long long)abs(b - a[i]);
    }
    printf("%lld\n",ans);
    return 0;
}


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

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

#define eb emplace_back

using namespace std;

typedef long long ll;

const int INF = 1 << 29;

int main() {
    string s;
    cin >> s;
    vector<char> vc;

    rep (i, s.size()) {
        if (s[i] == 'B') {
            if (vc.size() != 0) {
                vc.pop_back();
            }
        } else {
            vc.push_back(s[i]);
        }
    }

    rep (i, vc.size()) {
        cout << vc[i];
    }
    cout << endl;
}


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

using namespace std;

int n, x[505][505], ans;
bool hv[505][505];
queue<pair<int, int>> q;

void go(int a, int b, int c) {
	if (x[a][b] <= c)
		return;
	x[a][b] = c;
	q.emplace(a, b);
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++) {
			x[i][j] = min(min(i, j), min(n + 1 - i, n + 1 - j));
			hv[i][j] = 1;
		}
	// for (int i = 0; i <= n + 1; i++) for (int j = 0; j <= n + 1; j++) printf("%d%c", x[i][j], " \n"[j == n + 1]);
	for (int i = 0; i < n * n; i++) {
		int tmp;
		scanf("%d", &tmp);
		tmp--;
		int ta = tmp / n + 1;
		int tb = tmp % n + 1;
		ans += x[ta][tb] - 1;
		hv[ta][tb] = 0;
		go(ta, tb, x[ta][tb + 1]);
		go(ta, tb, x[ta][tb - 1]);
		go(ta, tb, x[ta + 1][tb]);
		go(ta, tb, x[ta - 1][tb]);
		while (!q.empty()) {
			tie(ta, tb) = q.front();
			q.pop();
			go(ta + 1, tb, x[ta][tb] + hv[ta + 1][tb]);
			go(ta - 1, tb, x[ta][tb] + hv[ta - 1][tb]);
			go(ta, tb + 1, x[ta][tb] + hv[ta][tb + 1]);
			go(ta, tb - 1, x[ta][tb] + hv[ta][tb - 1]);
		}
		// printf("%d\n", ans);
		// for (int i = 0; i <= n + 1; i++) for (int j = 0; j <= n + 1; j++) printf("%d%c", x[i][j], " \n"[j == n + 1]);
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 5000
import java.util.Scanner;

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

        if(a<b) {
            if(b<c){
                System.out.println("Yes");
                System.exit(0);
            }
        }
        System.out.println("No");
    }
}



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

using i64 = long long;

vector<i64> a, b;
i64 sum;
int n;

int main() {
#ifdef HOME
	freopen("agc9a.in", "r", stdin);
	freopen("agc9a.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	cin >> n;
	a.reserve(n), b.reserve(n);
	for (int ta, tb, i = 0; i < n; ++i) {
		cin >> ta >> tb;
		a.push_back(ta), b.push_back(tb); }

	for (int i = n - 1; i >= 0; --i) {
		a[i]+= sum;
		if (a[i] % b[i] != 0)
			sum+= b[i] - a[i] % b[i]; }

	cout << sum << endl;

	return 0; }


Measured memory_bytes: 1792
#pragma GCC optimize("Ofast")
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int num[100005];
vector<int> g[100005];
int main(){
	int i,n,m,from,to;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)	
		scanf("%d",&num[i]);
	for(i=0;i<m;i++){
		scanf("%d%d",&from,&to);
		g[from].emplace_back(to);
		g[to].emplace_back(from);
	}
	int ans=0;
	for(i=1;i<=n;i++){
		bool right=1;
		for(auto x:g[i])
			if(num[x]>=num[i])
				right=0;
		ans+=right;
	}
	printf("%d\n",ans);
}


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

import sys
import copy

sys.setrecursionlimit(1000000)

# input = sys.stdin.readline

# ~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~~~~

K, S = map(int, input().split())
ans = 0

for x in range(K + 1):
    for y in range(K + 1):
        z = S - (x + y)
        if z >= 0 and z <= K:
            ans += 1



print(ans)


Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define int int64_t
#define pcnt __builtin_popcount
#define pb push_back
#define ALL(x) (x).begin(),(x).end()
#define vec vector<int>
#define mat vector<vector<int>> //mat データ名(縦,vec(横));
#define F first
#define S second
int INF = 1000000000000000001; //10^18+1
int MOD = 1000000007; //10^9+7
//cout << fixed << setprecision(15); (小数点以下表示)

signed main () {
  string S,T;
  cin >> S >> T;
  S.pb(T.at(T.size()-1));
  if(S==T){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3596
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cctype>
#define int long long
#define rg register
using namespace std;
inline int read(){
	rg int s=0,f=0;
	rg char ch=getchar();
	while(!isdigit(ch)) f|=(ch=='-'),ch=getchar();
	while(isdigit(ch)) s=(s<<1)+(s<<3)+(ch^48),ch=getchar();
	return f?-s:s;
}
int n;
signed main(){
	n=read();
	printf("%lld",n*(n-1)/2);
	return 0;
}

Measured memory_bytes: 256
from collections import Counter
import math

N = int(input())
c = Counter()

for i in range(2, math.ceil(math.sqrt(N)+1)+1):
    while N%i == 0:
        c.update([i])
        N = N // i
if N!=1: c.update([N])
            
def R(n):
    ret = 0
    for i in range(1, n+1):
        if n>=i:
            ret += 1
            n -= i
        else:
            break
    return ret
 
ans = 0
for n in c:
    ans += R(c[n])
print(ans)


Measured memory_bytes: 66596
#include <stdio.h>

int main() {
  int a,b,c,d;
  scanf("%d%d%d%d",&a,&b,&c,&d);

  int x;
  if(a>b)
    x=b;
  else 
    x=a;

  int y;
  if(c>d)
    y=d;
  else 
    y=c;
  
  int ans=x+y;
  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 2076
#１文字をインプット
a=int(input())

#下の２行で１の位をaに入れる
a=a%100
a=a%10
#確認用
#print(a)

if a == 0:
    print("pon")
elif a == 1:
    print("pon")
elif a == 2:
    print("hon")
elif a == 3:
    print("bon")
elif a == 4:
    print("hon")
elif a == 5:
    print("hon")
elif a == 6:
    print("pon")
elif a == 7:
    print("hon")
elif a == 8:
    print("pon")
else:
    print("hon")

Measured memory_bytes: 61816
import Control.Monad
main = do
    n <- readLn
    replicateM_ n (get2circle >>= \x -> print (judgeIntersection x))

judgeIntersection ((x1,y1,r1), (x2,y2,r2))
  | distance > r1+r2 = 0
  | distance + r1 < r2 = -2
  | distance + r2 < r1 = 2
  | otherwise        = 1
    where distance = sqrt $ (x1-x2)^2 + (y1-y2)^2

get2circle = do
    [x1,y1,r1,x2,y2,r2] <- fmap (map (read :: String -> Double).words) getLine
    return ((x1,y1,r1),(x2,y2,r2))

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

using namespace std;

void rwFile() {
    freopen("INP.inp", "r", stdin);
    freopen("OUT.out", "w", stdout);
}

void solveA() {
    int m, n; cin >> m >> n;
    if (m == n) cout << "Yes";
    else cout << "No";
}

void solveB() {
    int a, b; cin >> a >> b;
    if (a > b) swap(a, b);
    for (int i = 0; i < b; i++) cout << a;
}

void solveC() {
    int n; cin >> n;
    int minn = 1e9, res = 0;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] <= minn) res++;
        minn = min(a[i], minn);
    }
    cout << res;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
    //rwFile();
    solveC();
}


Measured memory_bytes: 1024
struct Read<R: std::io::BufRead> {
    stdin: R,
    v: Vec<String>,
    i: usize,
}
impl<R:std::io::BufRead> Read<R> {
    pub fn new(stdin: R) -> Self {
        Read{
            stdin: stdin,
            v: Vec::new(),
            i: 0,
        }
    }
    pub fn read_line(&mut self) {
        self.i = 0; self.v.clear();
        let mut buf = String::new();
        self.stdin.read_line(&mut buf).unwrap();
        let buf = buf.trim().to_owned();
        let mut ws = buf.split_whitespace();
        loop {
            let x = ws.next();
            if x.is_none() {break;}
            let x = x.unwrap().to_owned();
            self.v.push(x);
        }
    }
    #[allow(dead_code)]
    pub fn read_t<T: std::str::FromStr>(&mut self) -> T {
        if self.i == self.v.len() {self.read_line();}
        let elem = &self.v[self.i];
        self.i += 1;
        elem.parse().unwrap_or_else(|_| panic!())
    }
    
    #[allow(dead_code)]
    pub fn read_i32(&mut self) -> i32 {
        if self.i == self.v.len() {self.read_line();}
        let elem = self.v[self.i].parse().unwrap();
        self.i += 1;
        elem
    }
    #[allow(dead_code)]
    pub fn read_usize(&mut self) -> usize {
        if self.i == self.v.len() {self.read_line();}
        let elem = self.v[self.i].parse().unwrap();
        self.i += 1;
        elem
    }
    #[allow(dead_code)]
    pub fn read_u64(&mut self) -> u64 {
        if self.i == self.v.len() {self.read_line();}
        let elem = self.v[self.i].parse().unwrap();
        self.i += 1;
        elem
    }
    #[allow(dead_code)]
    pub fn read_string(&mut self) -> String {
        if self.i == self.v.len() {self.read_line();}
        let elem = &self.v[self.i];
        self.i += 1;
        elem.to_owned()
    }
}

fn main() {
    use std::io;
    let stdin = io::stdin();
    let stdin = io::BufReader::new(stdin.lock());
    let read = Read::new(stdin);
    solve(read);
}

fn solve<R: std::io::BufRead>(mut r: Read<R>) {
    let k = r.read_i32();
    let a = r.read_i32();
    let b = r.read_i32();

    for i in a..b+1 {
        if i % k == 0 {
            println!("OK");
            return;
        }
    }
    println!("NG");
}


Measured memory_bytes: 2072
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

typedef long long LL;
typedef pair <int, int> pii;

inline LL Read()
{
	LL x = 0; int f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

LL x, s, ans, cur = LLONG_MIN;
int n;

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	n = Read();
	for (int i = 1; i <= n; i ++)
		x = Read(), cur = max(cur, x - s), s += Read(), ans = max(ans, cur + s - x);
	return printf("%lld\n", ans), 0;
}


Measured memory_bytes: 256
import sys
import os
import math
import string

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    print(2*N*3.14)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10064
a,b,c = gets.split.map(&:to_i)
k = gets.to_i
flag = false
k.times do
  if a >= b
    b *= 2
  elsif b >= c
    c *= 2
  end
  if a < b && b < c
    flag = true
    break
  end
end
puts flag ? "Yes" : "No"

Measured memory_bytes: 14320
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);
	string s;
	cin>>s;
	int res = 0;
	for(int i=0;i<3;i++)
	{
		int c = 0;
		for(int j=i;j<3;j++)
		{
			if(s[j]=='R')
				c++;
			else
				break;
		}
		res = max(res, c);
	}
	cout<<res<<"\n";
	return 0;
}

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

int main(){ 
	ios::sync_with_stdio(false);
    	cin.tie(0); 
	string s; 
	cin>>s; 
	int K; 
	cin>>K; 
	int N=s.size();
	int top=min(K,N);  
	set<string> ss; 
	for(int i=0;i<K;i++){ 
		for(int p=0;p<N-i;p++){
			string sub="";
			for(int j=0;j<i+1;j++){ 
				sub=sub+s[p+j]; 
			}
			ss.insert(sub); 
		} 
	} 
	set<string>::iterator it=ss.begin();
	advance(it,K-1); 
	cout<<*it<<endl; 	
    
    return 0; 
}


Measured memory_bytes: 1664
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>
using namespace std;


const long long int mod=1000000007;
const long long int INF=99999999999999999;

long long int H,W,K,dp[105][10]={},fib[14]={1,1,2,3,5,8,13,21,34,55};

int main() {
	cout << fixed << setprecision(18);
    cin>>H>>W>>K;
    dp[0][1]=1;
    for(int i=1;i<=H;i++){
        dp[i][1]+=(dp[i-1][2])*fib[W-2];
        if(W!=1)dp[i][W]+=(dp[i-1][W-1])*fib[W-2];
        
        dp[i][1]+=(dp[i-1][1])*fib[W-1];
        if(W!=1)dp[i][W]+=(dp[i-1][W])*fib[W-1];
        for(int j=2;j<=W-1;j++){
            dp[i][j]+=dp[i-1][j-1]*fib[j-2]*fib[W-j];
            dp[i][j]+=dp[i-1][j]*fib[j-1]*fib[W-j];
            dp[i][j]+=dp[i-1][j+1]*fib[j-1]*fib[W-j-1];
        }
        for(int j=1;j<=W;j++){
            dp[i][j]%=mod;
        }
    }
    
    cout<<dp[H][K];
} 


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(int, n);
  vector<int> a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];
  sort(all(a));
  sort(all(b));
  if (n % 2) {
    cout << (b[n / 2] - a[n / 2] + 1) << endl;
  } else {
    int am = a[n / 2 - 1] + a[n / 2];
    int bm = b[n / 2 - 1] + b[n / 2];
    cout << (bm - am + 1) << endl;
  }
}


Measured memory_bytes: 4848
#include<iostream>
using namespace std;
class stack{
	int row[10];
	int top;
	public:
		stack(){top = 0;}
		void push(int x);
		int pop();
};
void stack::push(int x){
	row[top] = x;
	top++;
}
int stack::pop(){
	top--;
	return row[top];
}
int main(){
	stack cars;
	int k;
	while(cin >>k){
		if(k == 0){cout<<cars.pop()<<endl;}
		else{cars.push(k);}
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <cstring>
using namespace std;

int ar[11], ag[11], ab[11];
bool checked[59049];
int p3[11];
int change[9] = {0, 8, 4, 8, 4, 0, 4, 0, 8};

int conv(string s) {
    int ret = 0;
    for (int i=0; i<(int)s.size(); ++i) {
        ret *= 3;
        if (s[i] == 'g') ret += 1;
        if (s[i] == 'b') ret += 2;
    }
    return ret;
}

int rotate(int x, int n) {
    int ret = 0;
    for (int i=0; i<n; ++i) {
        ret = ret * 3 + (x % 3 + 1) % 3;
        x /= 3;
    }
    return ret;
}

int main() {
    p3[0] = 1;
    for (int i=1; i<=10; ++i) {
        p3[i] = p3[i-1] * 3;
    }
    ar[0] = ag[0] = ab[0] = 0;
    for (int i=1; i<=10; ++i) {
        ar[i] = ar[i-1];
        ag[i] = ag[i-1] * 3 + 1;
        ab[i] = ab[i-1] * 3 + 2;
    }
    string s;
    while (cin >> s, s != "0") {
        memset(checked, false, sizeof checked);
        int n = s.size();
        int first = conv(s);
        queue<pair<int,int> > q;
        q.push(make_pair(first, 0));
        checked[first] = true;
        int res = -1;
        while ( ! q.empty()) {
            int col = q.front().first;
            int t = q.front().second;
            q.pop();
            if (col == ar[n] || col == ag[n] || col == ab[n]) {
                res = t;
                break;
            }
            for (int i=0; i<n-1; ++i) {
                int replace = change[(col / p3[i]) % 9];
                int nx = (col / p3[i+2]) * p3[i+2] + replace * p3[i] + (col % p3[i]);
                if ( ! checked[nx]) {
                    q.push(make_pair(nx, t+1));
                    checked[nx] = true; nx = rotate(nx, n);
                    checked[nx] = true; nx = rotate(nx, n);
                    checked[nx] = true;
                }
            }
        }
        if (res < 0) {
            cout << "NA" << endl;
        } else {
            cout << res << endl;
        }
    }
    return 0;
}

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

int h,w;
int grid[500][500];
vector<string> m;

int main(){
	cin>>h>>w;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>grid[i][j];
		}
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w-1;j++){
			if(grid[i][j]%2==1){
				grid[i][j+1]+=1;
				m.push_back(to_string(i+1)+" "+to_string(j+1)+" "+to_string(i+1)+" "+to_string(j+2));
			}
		}
	}
	for(int i=0;i<h-1;i++){
		if(grid[i][w-1]%2==1){
			grid[i+1][w-1]++;
			m.push_back(to_string(i+1)+" "+to_string(w)+" "+to_string(i+2)+" "+to_string(w));
		}
	}
	cout<<m.size()<<endl;
	for(string i : m){
		cout<<i<<endl;
	}
}

Measured memory_bytes: 11892
#include <bits/stdc++.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 a;
    cin>>a;
    if(d%a==0) sum+=d/a;
    else sum+=d/a+1;
  }
  cout<<sum+x<<endl;
}

Measured memory_bytes: 3564
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define QUEUESIZE 100000
typedef struct{
  int num;
  char str[10]; 
}Prs;
typedef Prs ELEM;
ELEM queue[QUEUESIZE];
int head,tail;
int next(int);
void init();
void enqueue(ELEM);
ELEM dequeue();
int empty();

int main(){
  int i,n=0,q=0,rec=0;
  ELEM *data,j;
  init();
  scanf(" %d%d",&n,&q);
  data = (ELEM *)malloc(n * sizeof(ELEM));

  for(i=0;i<n;i++){
    scanf("%s %d",&data[i].str,&data[i].num);
	enqueue(data[i]);
  }
  i=0;
  while(empty()){
	  j = dequeue();
	  if(j.num > q){
		  j.num -= q;
		  rec += q;
		  enqueue(j);
	  }else{
		  rec += j.num;
		  data[i].num = rec;
		  strcpy(data[i].str,j.str);
		  i++;
	  }
  }
  i=0;
  while(i<n){
	  printf("%s %d\n",data[i].str,data[i].num);
	  i++;
  }

  return 0;
}

void init(){
	head = tail = 0;
}

int next(int a){
	return ((a+1)%QUEUESIZE);
}

int empty(){
	return head != tail;
}

void enqueue(ELEM a){
	queue[tail] = a;
	tail = next(tail);
}

ELEM dequeue(){
	ELEM a;
    a = queue[head];
	head = next(head);
	return a;
}


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

#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> veci;
typedef vector<long long> vecll;
typedef vector<unsigned long long> vecull;

string s;

int main(void) {
    cin >> s;

    int l = 0;
    int r = s.size() - 1;

    int ans = 0;
    while (r - l > 0) {
        if (s[r] != s[l]) {
            if(s[r] == 'x') {
                s = s.insert(l, "x");
                ans++;
                r++;
            }
            else if (s[l] == 'x') {
                s = s.insert(r + 1, "x");
                ans++;
                r++;
            }
            else {
                ans = -1;
                break;
            }
        }

        r--;
        l++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3756
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var t=(Arr[0].split(" "))[1]-0;
Arr.shift();
var T=0;
var i=0;
while(Arr.length!=0){
   var arr=Arr[0].split(" ");
   Arr.shift();
   var a=arr[0];
   var b=arr[1]-0;
   if(b-t<=0){
      console.log(a+" "+(T+b));
      T+=b;
   }else{
      Arr.push(a+" "+(b-t));
      T+=t;
   }
}

Measured memory_bytes: 29668
#include <iostream>
#include <cstdio>
#include <vector>

template <typename T> void in(T &_){
	char c=getchar(); _=0; int fl=1;
	while(c<'0'||c>'9') fl=c=='-'?-1:fl, c=getchar();
	while(c>='0'&&c<='9') _=_*10+c-'0', c=getchar(); _*=fl;
}
template <typename T, typename... A> void in(T &_, A &...a){in(_); in(a...);}

#define MOD 1000000007

int N, M, bit[1<<15], f[16][1<<15], g[16][1<<15], h[1<<15];
bool map[16][16];

int ksm(int x, int y){
	int z=1;
	for(; y; y>>=1, x=1LL*x*x%MOD) if(y&1) z=1LL*z*x%MOD;
	return z;
}

void print(int x){
	for(int i=0; i<N; i++)
		putchar('0'+((x>>i)&1)); 
}

int lowbit(int x){return (x&(-x));}

int main(){
	for(int i=0; i<15; i++) bit[1<<i]=i+1;
	in(N, M);
	for(int x, y, i=1; i<=M; i++){
		in(x); in(y);
		map[x][y]=true;
	}
	for(int i=1; i<=N; i++)
		for(int j=0; j<(1<<N); j++)
			f[i][j]=f[i][j-lowbit(j)]+map[i][bit[lowbit(j)]];
	for(int i=1; i<=N; i++)
		for(int j=0; j<(1<<N); j++)
			if(map[i][bit[lowbit(j)]]) g[i][j]=(g[i][j-lowbit(j)]<<1|1)%MOD;
			else g[i][j]=g[i][j-lowbit(j)];
	for(int i=0; i<(1<<N); i++){
		h[i]=1;
		for(int j=i&(i-1); j; j=i&(j-1))
			if(((j&1)^((j&2)>>1))==0 && (((i^j)&1)^(((i^j)&2)>>1))==0){
				int tmp=h[i^j];
				for(int k=j; k; k-=lowbit(k)) 
					tmp=1LL*tmp*ksm(2, f[bit[lowbit(k)]][i^j])%MOD;
				for(int k=i^j; k; k-=lowbit(k))
					tmp=1LL*tmp*g[bit[lowbit(k)]][j]%MOD;
				h[i]=(h[i]+tmp)%MOD;
			}
	}
	printf("%d\n", (ksm(2, M)-h[(1<<N)-1]+MOD)%MOD);
	return 0;
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define fre(i,t,n)  for(int i =(t);i<=(n);++i)
#define fer(i,n,t)  for(int i =(n);i>=(t);--i)
#define mp make_pair
#define pb push_back
typedef long long ll;
void smain();
int main(){
    ios::sync_with_stdio(false);
    smain();
    return 0;
}
string str;
const int maxn = 40;
bool col[maxn];
string r,b;
string rev;
ll dp[maxn][maxn];
int DP(int i,int j)
{
    if(dp[i][j]!=-1)    return dp[i][j];
    ll ans=(i==0&&j==0);
    if(i!=0)    ans=ans+(DP(i-1,j)*(rev[i+j-1]==r[i-1]));
    if(j!=0)    ans=ans+(DP(i,j-1)*(rev[i+j-1]==b[j-1]));
    return dp[i][j]=ans;
}
void smain(){
    int n;
    cin>>n;
    int N=2*n;
    cin>>str;
    rev=str.substr(n,n);
    reverse(rev.begin(),rev.end());
    ll ans=0;
    for(int i=0;i<(1<<n);++i)
    {
        b=r="";
        for(int j=0;j<n;++j)
            if(i&(1<<j))
                r+=str[j];
            else b+=str[j];
        //cout<<r<<" "<<b<<" "<<rev<<endl;
        memset(dp,-1,sizeof dp);
        ans=ans+DP(r.size(),b.size());
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
X,Y,A,B,C=map(int, input().split())
p=list(map(int, input().split()))
q=list(map(int, input().split()))
r=list(map(int, input().split()))

x=X-1
y=Y-1

p=sorted(p,reverse=True)
q=sorted(q,reverse=True)
r=sorted(r,reverse=True)

#print(p[:X],q[:Y])

if p[x]>=q[y]:
  a=q[y]
  f=1
else:
  a=p[x]
  f=2
while len(r)>=1 and a<r[0]:
#  print(a,r[0])
  if f==1 :
#    print('f=1')
    q[y]=r[0]
    y-=1
    r.pop(0)
  elif f==2 :
#    print('f=2')
    p[x]=r[0]
    x-=1
    r.pop(0)
  else:
#    print('break1')
    break
    
#  print(x,y,p[x],q[y])
    
  if (y==-1 and x>=0) or (x>=0 and p[x]<q[y]):
#    print('a=p[x]')
    a=p[x]
    f=2
  elif (x==-1 and y>=0) or (y>=0 and p[x]>=q[y]):
#    print('a=q[y]')
    a=q[y]
    f=1
  else:
#    print('break2')
    break

ans=0
#print(p[:X],q[:Y])
for i in p[:X]:
  ans+=i
for i in q[:Y]:
  ans+=i

print(ans)

Measured memory_bytes: 29028
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1001001001;
const ll LONGINF = 1001001001001001LL;
const ll MOD = 1000000007LL;

bool check(const vector<string> &vs, int K) {
    vector<string> conv;
    const string pat = "aiueo";
    
    for(const auto &s : vs) {
        string code = "";
        int N = s.size();
        for(int i=0; i<N; i++) {
            if(i == 0 or pat.find(s[i-1]) != string::npos) code += s[i];
        }
        if(code.size() >= K) code = code.substr(0, K);
        conv.emplace_back(code);
    }

    bool ok = true;
    int M = vs.size();
    for(int i=0; i<M; i++) {
        for(int j=i+1; j<M; j++) {
            if(conv[i] == conv[j]) ok = false;
        }
    }
    return ok;
}

int solve_testcase() {
    int N; cin >> N;
    if(N == 0) return 1;

    vector<string> vs(N);
    for(int i=0; i<N; i++) cin >> vs[i];

    const int MAX = 52;
    int ub = MAX, lb = -1;
    while(ub - lb > 1) {
        int mid = (ub + lb) / 2;
        if(check(vs, mid)) ub = mid;
        else lb = mid;
    }

    if(ub == MAX) cout << -1 << endl;
    else cout << ub << endl;
    return 0;
}

int main() {
    while(!solve_testcase());
    return 0;
}



Measured memory_bytes: 3168
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
int K;
string s;
void solve() {
	cin >> s;
	cin >> K;
	set<string> cut_s;
	for (int i = 0; i < s.length(); ++i) {
		for (int j = 1; j <= K; ++j) {
			cut_s.insert(s.substr(i, j));
		}
	}
	auto itr = cut_s.begin();
	for (int i = 1; i < K; ++i) {
		itr++;
	}
	cout << *itr << endl;
	return;
}
//逆元を求める関数
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(int args, char* argv[]) {
	solve();
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define D(x) cout << #x << "=" << x << " "
#define E puts("")
using namespace std;
typedef long long LL;
inline int getint() {
	int a = 0, f = 1; char c = getchar();
	while (c > '9' || c < '0') { if (c == '-') f = -1; c = getchar();}
	while (c <= '9' && c >= '0') { a = a * 10 + c - '0'; c = getchar();}
	return a * f;
}

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

int main(int argc, char const *argv[]) {
//	freopen("in", "r", stdin);
//	freopen("out", "w", stdout);
	LL n = getint(), m = getint();
	string str1, str2;
	cin >> str1 >> str2;
	LL lcm = n * m / gcd(n, m);
	LL p = lcm / n, q = lcm / m;
	LL LCM = p * q / gcd(p, q);
	bool flag = 0;
	if (str1[0] != str2[0]) {puts("-1"); return 0;}
	for (LL i = 1; str1[i * LCM / p] && str2[i * LCM / q]; i++) {
		if (str1[i * LCM / p] != str2[i * LCM / q]) {flag = 1; break;}
	}
	if (flag) puts("-1");
	else printf("%lld\n", lcm);
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int a[100001],b[100001];
int Pow(int p,int q){
    int s=1;
    for(;q;q>>=1,p=1LL*p*p%mod){
    	if(q&1){
    		s=1LL*s*p%mod;
		}
	}
    return s;
}
int main(){
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;++i){
    	cin>>a[i];
	}
    sort(a+1,a+n+1);
    for(int i=1;i<=n;++i){
    	b[i]=Pow(i,mod-2); 
	}
    long long p=1,ans=a[m];
    for(int i=m+1;i<=n;++i){
         p=p*(i-1)%mod;
         p=p*b[i-m]%mod;
         ans=(ans+a[i]*p%mod)%mod;
    }
    ans=ans-a[n-m+1];
    p=1;
    for(int i=m+1;i<=n;++i){
         p=p*(i-1)%mod;
         p=p*b[i-m]%mod;
         ans=(ans-a[n-i+1]*p%mod)%mod;
    }
    if(ans<0){
    	ans=ans+mod;
	}
    cout<<ans;
}

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

using namespace std;

void Main() {
    int N;
    cin >> N;
    set<char> colors;
    for (int i = 0; i < N; ++i) {
        char s;
        cin >> s;
        colors.insert(s);
    }

    cout << (colors.size() == 3 ? "Three" : "Four") << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3580
#include <iostream>


using namespace std;

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

	long long tmp = n;
	long long a = 1;
	long long b = 1;
	long long c = 1;
	while (tmp--)
	{
		a *= 10;
		a %= 1000000007;
		b *= 9;
		b %= 1000000007;
		c *= 8;
		c %= 1000000007;
	}
	
	int result = a;
	result -= b;
	result %= 1000000007;
	if (result < 0)
		result += 1000000007;
	result -= b;
	result %= 1000000007;
	if (result < 0)
		result += 1000000007;
	result += c;
	result %= 1000000007;
	if (result < 0)
		result += 1000000007;

	cout << result << endl;


	return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
long long n,arr[100009],dp[100009], k;
long long bt(int id)
{
    long long &ret=dp[id];
    if(ret!=-1) return ret;
    if(id+1 < n){
        ret = 1000000000000009ll;
        for(int i=1;i<=k;i++)
        {
            if(id+i < n) ret = min(ret,bt(id+i)+abs(arr[id]-arr[id+i]));
        }
        return ret;
    }
    return 0;
}
int main()
{
    memset(dp,-1,sizeof(dp));
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    cout<<bt(0);
}





/*


#include <bits/stdc++.h>
using namespace std;
int n,arr[100009];
int dp[100009];
int main(){
    cin>>n;
    for(int i=0;i<n;i++) cin>>arr[i];
    dp[n-2] = abs(arr[n-2]-arr[n-1]);
    for(int i=n-3;i>=0;i--){
        dp[i] = min(abs(arr[i]-arr[i+1])+dp[i+1],abs(arr[i]-arr[i+2])+dp[i+2]);
    }
    cout<<dp[0]<<endl;
}*/

Measured memory_bytes: 6528