akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;

const ll M = 1e9+7;

vector<ll> fac(301); //n!(mod M)
vector<ll> ifac(301); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}

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

    //大した量ではないので，先にfax[i]とifax[i]を全て計算しておく
    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<300; i++){
        fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }

    ll ans=0;
    if(n > 1) ans += comb(n, 2);
    if(m > 1) ans += comb(m, 2);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

X, K, D = list(map(int, input().split()))

n = abs(X) // D

if K <= n:
    if X < 0:
        print(abs(X + D*K))
        sys.exit()
    else:
        print(abs(X - D*K))
        sys.exit()
else:
    if (K-n) % 2 == 0:
        if X < 0:
            print(abs(X + n * D))
            sys.exit()
        else:
            print(abs(X - n * D))
            sys.exit()
    else:
        if X < 0:
            print(abs(X + (n+1) * D))
            sys.exit()
        else:
            print(abs(X - (n+1) * D))
            sys.exit()



Measured memory_bytes: 73012
import fractions
 
def gcd_1(a):
    p = fractions.gcd(a[0],a[1])
    if len(a) > 2:
        for i in range(2,len(a)):
            p = gcd_1([p,a[i]])
    else:
        p = fractions.gcd(a[0],a[1])
 
    return p
 
n = int(input())
a = [int(i) for i in input().split()]
 
print(gcd_1(a))


Measured memory_bytes: 16276
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{int p,i,j,k,flag=0,count=2;

scanf("%d",&p);
i=p;
while(1)
{count=2;
    for(j=2;j<=i;j++)
    {
        k=i%j;
        if(k==0)
        break;
    
        count++;
    }

    if(count==i)
   { break;}

    i++;
}
printf("%d\n",i);

}

Measured memory_bytes: 128
#ifndef TEMPLATE_HPP
#define TEMPLATE_HPP
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())
using namespace std;
using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void amax(T &x, T y) { x = max(x, y); }
template <typename T> void amin(T &x, T y) { x = min(x, y); }
template <typename T> T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename U> vector<U> make_vector(T&& n, U&& val) { return vector<U>(forward<T>(n), forward<U>(val)); }
template <typename T, typename... Args> decltype(auto) make_vector(T&& n, Args&&... args) { return vector<decltype(make_vector(forward<Args>(args)...))>(forward<T>(n), make_vector(forward<Args>(args)...)); }
const int INF = 1001001001;
const i64 LINF = 1001001001001001001ll;
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
#endif

void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  rep(i, n) {
    if (s[i] == 'W') s[i] = 1; else s[i] = 0;
  }
  {
    int zero = 0;
    rep(i, n) zero += s[i] == 0;
    if (zero == n || zero == 0) {
      cout << 0 << endl;
      return;
    }
  }
  int ans = 0;
  int l = 0, r = n - 1;
  while (true) {
    while (s[l] == 0) l += 1;
    while (s[r] == 1) r -= 1;
    if (l > r) break;
    ans += 1;
    swap(s[l], s[r]);
  }
  cout << ans << endl;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(16);
  cerr << fixed << setprecision(16);
  solve();
  return 0;
}

Measured memory_bytes: 3720
#[int(x) for x in input().split()]
#map(int,input().split())
#for _ in range(int(input())):
x=input()
l=list(x)
c=0
for i in range(len(l)):
	if l[i]=='?':
		if i-1<0:
			if i+1<len(l):
				if l[i+1]=='D':
					l[i]='P'
				elif l[i+1]=='?':
					l[i]='P'
				else:
					l[i]='D'
			else:
				l[i]='D'
		elif l[i-1]=='P':
			l[i]='D'
		elif i+1<len(l):
			if l[i+1]=='D':
				l[i]='P'
			elif l[i+1]=='?':
				l[i]='P'
			else:
				l[i]='D'
		else:
			l[i]='D'
print(''.join(l))




Measured memory_bytes: 73816
#include <iostream>
#include <cassert>

int main()
{
  int A, B, C;
  std::cin >> A >> B >> C;
  assert(1 <= A and A <= 100);
  assert(1 <= B and B <= 100);
  assert(1 <= C and C <= 100);

  if (A == B and B == C)
    std::cout << "Yes" << std::endl;
  else
    std::cout << "No" << std::endl;

  return 0;
}


Measured memory_bytes: 256
import math
def div(s):
    i=1
    while(i<=math.sqrt(s)):
        if(s%i==0):
            if(s//i==i):
                if(i!=1):
                    if(i in d):
                        return False
                    else:
                        d[i]=1
            else:
                if(i!=1):
                    if(i in d):
                        return False
                    else:
                        d[i]=1
                if(s//i!=1):
                    if(s//i in d):
                        return False
                    else:
                        d[s//i]=1
        i+=1
    #print(d,s)
    return True
                

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

d=dict()

setwise=False
pairWise=True
pairWise&=div(l[0])
pairWise&=div(l[1])
val=math.gcd(l[0],l[1])

for i in range(2,n):
    pairWise&=div(l[i])
    val=math.gcd(val,l[i])
if(pairWise):
    print('pairwise coprime')
elif(val==1):
    print('setwise coprime')
else:
    print('not coprime')


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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

vector<int> to[200005];

mint dfs(int v) {
  mint res = 1;
  for (int u : to[v]) {
    res *= dfs(u);
  }
  return res + 1;
}

int main() {
  int n;
  cin >> n;
  vector<P> p(n);
  rep(i,n) cin >> p[i].first >> p[i].second;
  sort(p.begin(), p.end());
  set<P> s;
  for (int i = n-1; i >= 0; --i) {
    int x = p[i].first, d = p[i].second;
    while (s.size() && s.begin()->first < x+d) {
      to[i].push_back(s.begin()->second);
      s.erase(s.begin());
    }
    s.emplace(x, i);
  }

  mint ans = 1;
  for (auto x : s) {
    int v = x.second;
    ans *= dfs(v);
  }
  cout << ans.x << endl;
  return 0;
}



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

int digitsum(int a) {
  int ret=0;
  while(a!=0) {
    ret+=a%10;
    a/=10;
  }
  return ret;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  int n;
  cin>>n;
  int ans=100000000;
  repeat(a,1,n) {
    int b = n-a;
    ans=min(ans,digitsum(a)+digitsum(b));
  }
  cout << ans << endl;
  return 0;
}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;

int main() {
    long double a; cin >> a;
    long double b; cin >> b;
    ll ans = floor(a * b);

    cout << ans << endl;
}


Measured memory_bytes: 3732
dice = list(map(str, input().split()))
direction = input()
for i in range(len(direction)):
	if direction[i] == "N":
		dice[0],dice[1],dice[4],dice[5] = dice[1],dice[5],dice[0],dice[4]
	elif direction[i] == "S":
		dice[0],dice[1],dice[4],dice[5] = dice[4],dice[0],dice[5],dice[1]
	elif direction[i] == "W":
		dice[0],dice[2],dice[3],dice[5] = dice[2],dice[5],dice[0],dice[3]
	else :
		dice[0],dice[2],dice[3],dice[5] = dice[3],dice[0],dice[5],dice[2]
print(dice[0])


Measured memory_bytes: 5576
#include<bits/stdc++.h>
using namespace std;
int main (){
  int n;
  int k;
  int ans=0;
  int count;
  cin >> k ;
  for(n=1;n<=k;n++){
    count=0;
    for(int i=1;i<=n;i++){
      if(n%2==1 && n%i==0){
        count++;
      }
    }
    if(count==8){
      ans++;
    }
  }
  cout << ans << endl;
  /*if(n<105){
    cout << 0 << endl;
  }else if(105<= n < 165){
    cout << 1 << endl;
  }else{
    cout << 2 << endl;
  }*/
  return 0;
}


Measured memory_bytes: 256
# 公舎の入居者数

# input
N = int(input())

# initialization
room_info = [[[0]*10 for i in range(3)] for j in range(4)]

# insert
for i in range(N):
    b, f, r, v = map(int, input().split())
    room_info[b-1][f-1][r-1] += v

# output
for b in range(4):
    for f in range(3):
        print(" ", end="")
        rooms = room_info[b][f]
        rooms = list(map(str, rooms))
        print(" ".join(rooms))
    if not b==3:
        print("####################")



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

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

const int inf = 1'000'000'000;

int main() {
  int k,n;
  cin >> k >> n;
  std::vector<int> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  vec.push_back(vec.at(0) + k);
  int maxLength = 0;
  int total = 0;
  for (int i = 0; i<n; i++) {
    total += abs(vec.at(i) - vec.at(i+1));
    maxLength = max(maxLength, abs(vec.at(i) - vec.at(i+1)));
  }
  cout << total - maxLength << endl;
}


Measured memory_bytes: 4816
from collections import Counter,defaultdict
import sys,bisect,math,itertools,string,queue
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

n = inp()
ss = []
for i in range(n):
    s,p = input().split()
    ss.append([i+1,s,int(p)])

ss.sort(key = lambda x:x[2], reverse = True)
ss.sort(key = lambda x:x[1])
for i in ss:
    print(i[0])


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

using namespace std;

int main() {

	string str1, str2;
	cin >> str1 >>  str2;

	queue<char> s;
	queue<char> t;
	for (int i = 0; i < str1.size(); i++) {
		s.push(str1[i]);
		t.push(str2[i]);
	}

	char tmp;
	for (int i = 0; i < str1.size(); i++) {
		if (s == t) { cout << "Yes" << endl; return 0; }
		else {
			tmp = s.front();
			s.pop();
			s.push(tmp);
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
import sys

N, K = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().strip().split()))

A.sort()
if K == 0:
    print(A[-1])
else:
    ans = 10**9
    l = 0
    r = 10**9
    while l < r:
        # t以下の長さにするのに必要な切る回数
        t = (l + r) // 2
        if t == 0:
            break
        # print(t)
        n = K
        for a in A:
            n -= (a - 1) // t
            if n < 0:
                break
        if n >= 0:
            ans = min(ans, t)
        if n >= 0:
            r = t
        else:
            l = t + 1

    print(ans)

Measured memory_bytes: 93864
n = gets.to_i
a = gets.split.map(&:to_i)

def merge(a, left, mid, right)
    n1 = mid - left
    n2 = right - mid
    _L = a[left..mid-1]
    _R = a[mid..right-1]
    _L[n1] = 1.0/0.0
    _R[n2] = 1.0/0/0
    i = j = 0
    cnt = 0
    left.upto(right-1){|k|
        if _L[i] <= _R[j] then
            a[k] = _L[i]
            i += 1
        else
            a[k] = _R[j]
            j += 1
            cnt += n1 - i
        end
    }
    return cnt
end

def mergeSort(a, left, right)
    count = 0 
    if left + 1 < right then
        mid = (left + right) / 2
        count += mergeSort(a, left, mid)
        count += mergeSort(a, mid, right)
        count += merge(a, left, mid, right)
    end
    return count
end

count = mergeSort(a, 0, n)
puts count


Measured memory_bytes: 32896
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")
from collections import deque


def main():
    S = input()
    dS = deque(list(S))
    front = 0
    Q = int(input())
    for q in range(Q):
        query = input()
        if query[0] == "1":
            front = 1-front
        else:
            _, f, c = query.split()
            f = int(f)
            if f == 1:
                if front == 0:
                    dS.appendleft(c)
                else:
                    dS.append(c)
            else:
                if front == 0:
                    dS.append(c)
                else:
                    dS.appendleft(c)
    if front == 0:
        print("".join(dS))
    else:
        print("".join(reversed(dS)))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 8804
import java.lang.reflect.Method;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			if (n == 0)
				break;
			Dice d = new Dice();
			int ans = 1;
			for (int i = 0; i < n; i++) {
				Method m = d.getClass().getMethod(sc.next());
				d = (Dice) m.invoke(d);
				ans += d.top;
			}
			System.out.println(ans);
		}
	}
}

class Dice {
	public int top;
	public int bottom;
	public int east;
	public int west;
	public int south;
	public int north;

	Dice() {
		top = 1;
		south = 2;
		east = 3;
		bottom = 7 - top;
		west = 7 - east;
		north = 7 - south;
	}

	Dice(int t, int s, int e) {
		top = t;
		south = s;
		east = e;
		bottom = 7 - top;
		west = 7 - east;
		north = 7 - south;
	}

	public Dice North() {
		int tmp = south;
		south = bottom;
		top = tmp;
		return new Dice(top, south, east);
	}

	public Dice East() {
		int tmp = west;
		east = top;
		top = tmp;
		return new Dice(top, south, east);
	}

	public Dice West() {
		int tmp = east;
		east = bottom;
		top = tmp;
		return new Dice(top, south, east);
	}

	public Dice South() {
		int tmp = north;
		south = top;
		top = tmp;
		return new Dice(top, south, east);
	}

	public Dice Right() {
		int tmp = east;
		east = north;
		south = tmp;
		return new Dice(top, south, east);
	}

	public Dice Left() {
		int tmp = south;
		south = west;
		east = tmp;
		return new Dice(top, south, east);
	}

	public String toString() {
		return "east:" + east + "west:" + west + "top:" + top + "bottom:"
				+ bottom + "north:" + north + "south:" + south;
	}
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;

int main() {
  ll n,m,d;
  cin >> n >> m >> d;
  if (d == 0) {
    if (n == 1) {
      cout << m-1 << endl;
      return 0;
    }
    long double a = (long double)m / (long double)n;
    cout << setprecision(120) << a << endl;
    return 0;
   }
  ll suit = (max(n-(2LL*d),0LL) * 2LL) + (min(2LL*d,n) * 1LL);
  long double K = (((long double)suit / ((long double)n * (long double)n))) * (m-1);
  cout << setprecision(120) << K << endl;
  return 0;
}

Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int N = 100 + 5;
int a[N];
 
int main() {
	int n;
    cin >> n;
    double sum = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        sum += a[i];
    }
    int p = round(sum / n);
    int ans = 0;
    for(int i = 0; i < n; i++)
        ans += pow((a[i] - p), 2);
    cout << ans << endl;
	return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M; cin >> N >> M;
  vector<int> A(M, 0);
  int sumM = 0;
  REP(i, M){
    cin >> A[i];
    sumM += A[i];
  }
  cout << max(N-sumM, -1) << endl;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
int64_t dp[MAXN]; // 最大の高さがiの時の最大値

int main()
{
  int N;
  cin >> N;
  int base = 1;
  while (base <= N)
  {
    base *= 2;
  }
  vector<int64_t> Tree(2 * base);

  vector<int64_t> H(N), A(N);
  for (int i = 0; i < N; i++)
  {
    cin >> H[i];
  }
  for (int i = 0; i < N; i++)
  {
    cin >> A[i];
  }
  for (int i = 0; i < N; i++)
  {
    int x = H[i] + base;
    int64_t best = 0;
    while (x > 1)
    {
      if (x % 2 == 1)
      {
        best = max(best, Tree[x - 1]);
      }
      x /= 2;
    }
    dp[H[i]] = best + A.at(i);
    for (int j = base + H[i]; j >= 1; j /= 2)
    {
      Tree[j] = max(Tree[j], dp[H[i]]);
    }
  }
  int64_t ans = 0;
  for (int i = 0; i <= N; i++)
  {
    ans = max(ans, dp[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 11952
n, q = map(int, input().split())
s = input()
lst = [0] * n
for i in range(1, n):
  lst[i] = lst[i-1]
  if s[i-1:i+1] == 'AC':
    lst[i] += 1

for i in range(q):
  l, r = map(int, input().split())
  print(lst[r-1] - lst[l-1])


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

int cnt[101];

int main() {
	int i;
	for (i = 0; i < 12; i++) {
		int len;
		cin >> len;
		cnt[len]++;
	}
	for (i = 0; i < 101; i++) {
		if (cnt[i] % 4) {
			cout << "no" << endl;
			return 0;
		}
	}
	
	cout << "yes" << endl;
	return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
using Int = long long;
using namespace std;
#define PUTS(x) cout << (x) << endl;
int main() {
    int n, r;
    cin >> n >> r;
    if (n >= 10) {
        PUTS(r);
    } else {
        PUTS(r + 100 * (10 - n));
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define xx first
#define yy second
using namespace std;
const int N = 200000 + 5;
int h[N], suf[N], info[N], n;
int stk[N], top;
ll k;
bool vis[N];

int main () {
	#ifdef wll
	freopen ("testdata.in", "r", stdin);
	#endif
	scanf ("%d%lld", &n, &k);
	for (int i = 1; i <= n; ++i) {scanf ("%d", &info[i]);}
	for (int i = 1; i <= n; ++i) {if (h[info[i]]) {suf[h[info[i]]] = i;}h[info[i]] = i;}
	for (int i = n; i >= 1; --i) {h[info[i]] = i;}
	for (int i = 1; i <= n; ++i) {if (!suf[i]) {suf[i] = h[info[i]];}}
	int cir = 1, now = 1;
	while (1) {
		bool flag = false;
		if (suf[now] <= now) {cir++;flag = true;}
		now = suf[now] % n + 1;
		if (vis[now]) {if (flag)--cir;break;}
		vis[now] = 1;
	}
	k %= cir;
	now = 1;
	int cnt = 1;
	while (1) {
//		printf ("%d %d\n", now, cnt);
		if (now > n) {now -= n;cnt++;}
		if (now > n || cnt > k) {break;}
		int nxt = suf[now];
		if (nxt <= now) {
			if (1LL * cnt >= k) {stk[++top] = info[now++];continue;}
			else {cnt++; now = suf[now] + 1;}
		}
		else {
			now = suf[now] + 1;
		}
	}
	for (int i = 1; i <= top; ++i) {
		printf ("%d ", stk[i]);
	}
	return 0;
}











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

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define lfs <<fixed<<setprecision(10)<<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
template<typename T>
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll n,k;cin>>n>>k;
  vector<ll>a(n);
  rep(i,0,n)cin>>a[i];
  vector<bool>dp(k+1,false);//falseで負け手番
  rep(i,0,k+1){
    bool judge=false;
    rep(j,0,n){
      if(i>=a[j]&&!dp[i-a[j]])judge=true;
    }
    dp[i]=judge;
  }
  ans(dp[k],"First","Second");
  return 0;
}

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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    string s;
    cin >> s;
    if (s.size() != 26) {
        bool used[26] = {0};
        REP(i, 0, s.size()) {
            used[s[i] - 'a'] = true;
        }
        cout << s;
        REP(i, 0, 26) {
            if (!used[i]) {
                cout << char('a' + i) << endl;
                break;
            }
        }
    } else {
        bool used[26] = {0};
        for (int i = s.size() - 1; i >= 0; i--) {
            used[s[i] - 'a'] = true;
            for (int j = s[i] - 'a' + 1; j < 26; j++) {
                if (used[j]) {
                    cout << s.substr(0, i) << char(j + 'a') << endl;
                    return 0;
                }
            }
        }
        cout << -1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
/*in the name of Allah the most beneficent the most merciful.*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define MAX 1e18
#define MIN -1e18
#define MOD 1000000007
//#define mod2 20071027
//#define MOD 998244353
// #define base 100001
//#define mod 1000074259
#define base2 31
#define memz(a) memset(a, 0, sizeof(a))
#define memn(a) memset(a, -1, sizeof(a))
#define in1(a) scanf("%lld", &a)
#define in2(a, b) scanf("%lld%lld", &a, &b)
#define TC(c) printf("Case %lld:\n", ++c)
#define out(x) cout << #x << " -> " << x << endl;
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FILE   freopen("input.txt", "r", stdin);  freopen("out.txt", "w", stdout);
using namespace std;
const int N = 300010;
ll n, m,res=1,par[N],sz[N];
ll fp(ll a){
	if(par[a]==a) return a;
	return par[a]=fp(par[a]);
}
int solve() {
	in2(n,m);
	for(int i=1;i<=n;i++) {
		sz[i]=1;
		par[i]=i;
	}
	for(int i=0;i<m;i++)
	{
		ll u, v;
		in2(u,v);
		ll pu = fp(u);
		ll pv = fp(v);
		if(pu!=pv){
			par[pv]=pu;
			sz[pu]+=sz[pv];
			res=max(res, sz[pu]);
			sz[pv]=0;
		}
	}
	printf("%lld\n", res);
	return 0;
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	return solve();
}

Measured memory_bytes: 6968
#include <iostream>

using namespace std;

int main()
{
    int n, k; cin >> n >> k;
    // int initMinPoint = 0;
    int cnt = 0;

    int a[100010] = {0};

    cnt = ((n - 1) + (k - 1) - 1) / (k - 1); 

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        // if (a[i] == 1) initMinPoint = i;
    }

    // // initMinPointよりも前の部分の探索
    // int bp = initMinPoint;
    // while(bp > 1) {
    //     for (int i = 1; i <= (k - 1); i++) {
    //         if (bp - i >= 1) a[bp - i] = 1;
    //     }
    //     cnt++;
    //     bp -= k - 1;
    // }

    // // initMinPointよりも後ろの部分の探索
    // int ap = initMinPoint;
    // while(ap < n) {
    //     for (int i = 1; i <= (k - 1); i++) {
    //         if (ap + i <= n) a[ap + i] = 1;
    //     }
    //     cnt++;
    //     ap += k - 1;
    // }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

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

  vector<vector<char>> G(100, vector<char>(100));
  repp(i, 0, 49) {
    rep(j, 100) {
      G[i][j] = '#';
    }
  }
  repp(i, 50, 99) {
    rep(j, 100) {
      G[i][j] = '.';
    }
  }

  A--;
  B--;
  int ai = A / 50;
  int aj = A % 50;
  for (int i = 0; i < ai * 2; i += 2) {
    for (int j = 0; j < 50 * 2; j += 2) {
      G[i][j] = '.';
    }
  }
  for (int j = 0; j < aj * 2; j += 2) {
    G[ai * 2][j] = '.';
  }

  A--;
  int bi = B / 50;
  int bj = B % 50;
  for (int i = 0; i < bi * 2; i += 2) {
    for (int j = 0; j < 50 * 2; j += 2) {
      G[99 - i][99 - j] = '#';
    }
  }
  for (int j = 0; j < bj * 2; j += 2) {
    G[99 - bi * 2][99 - j] = '#';
  }

  cout << 100 << ' ' << 100 << endl;
  rep(i, 100) {
    rep(j, 100) {
      cout << G[i][j];
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int a,b,c;cin>>a>>b>>c;
    cout<<(b-a == c-b ? "YES":"NO")<<endl;
}

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

int main()
{
	int n, m;
	int x[100];

	cin >> n;

	for (int i = 0; i < n; i++)
		cin >> x[i];

	cin >> m;

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

		if ((a == n || x[a] != x[a - 1] + 1) && x[a - 1] < 2019)
			x[a - 1]++;
	}

	for (int i = 0; i < n; i++)
		cout << x[i] << endl;

	return 0;
}


Measured memory_bytes: 3108
//2回2分探索をしても良いことを、証明したいね。意味としてはなんとなく分かるけど。
//2回2分探索できそうでできない例：AOJ542
//ちょっと気まぐれだが、O(N^2logN)の枝刈りで通してみたくなったからそれで通す。→無理でした。
#include<stdio.h>
#include<iostream>
using namespace std;

#define GOMAE (long long)50000
#define EPS (long long)4000
#define TO_OUTSIDE (long long)1500
#define IS_NOT_EVEN_HOBBY (long long)573
int N;
long long input;
long long A[300010];
long long ans;

//A[medi]-A[st] >= A[ed]-A[medi]となる最小のmediを返す。
int seach1( int st, int ed ){
	int medi,s = st,e = ed;
	
	while( s <= e ){
		medi = (s+e)>>1;
		if( A[medi]-A[st] == A[ed]-A[medi] )
			break;
		if( A[medi]-A[st] > A[ed]-A[medi] ){
			if( A[medi-1]-A[st] < A[ed]-A[medi-1] )
				break;
			e = medi-1;
		}
		else{
			s = medi+1;
		}
	}
	return medi;
}
//A[medi]-A[st] >= Xとなる最小のmediを返す。
int seach2( int st, int ed, long long X ){
	int s=st,e=ed,medi;
	while( s<=e ){
		medi= (s+e)>>1;
		if( A[medi]-A[st] < X )
			s=medi+1;
		if( A[medi]-A[st] >= X ){
			if( A[medi-1]-A[st] < X )
				break;
			e=medi-1;
		}
	}
	return medi;
}

int solve( long long X ){
	int i,j,k;
	
	if( X >= (A[N]>>1) )
		return 0;
	for( i = 0; i < N; i++ ){
		//大きさがX以上になるように切る
		j = seach2(i,N+i,X);
		//できるだけ真ん中で切る
		k = seach1(j,N+i);
		if( min( A[j]-A[i], min( A[k]-A[j], A[i+N]-A[k] ) ) >= X )
			break;
		k--;
		if( min( A[j]-A[i], min( A[k]-A[j], A[i+N]-A[k] ) ) >= X )
			break;
	}
	if( i < N )
		return 1;
	return 0;
}
				
int main(){
	int i,j,k;
	long long s = 0, e = GOMAE * EPS * TO_OUTSIDE * IS_NOT_EVEN_HOBBY * EPS;
	scanf("%d",&N);
	if( N > 100000 )
		return 0;
		
	for( i = 1; i < N+1; i++ ){
		scanf("%d",&input);
		A[i] = A[i-1]+input;
	}
	for( i = N+1; i < 3*N+1; i++ ){
		A[i] = A[i-N] + A[N];
	}
	
	//printf("%lld %lld\n",s,e);
	while( s <= e ){
		ans = (s+e)>>1;
		if( solve(ans) ){
			if( solve(ans+1) )
				s = ans+1;
			else
				break;
		}
		else{
			e = ans-1;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3532
import sys
import itertools

input = sys.stdin.readline

def func(l, r):
    mod_min = float('inf')

    for i in range(l, r):
        for j in range(i+1, r+1):
            mod = (i*j % 2019)

            if mod == 0:
                print(mod)
                exit()     

            elif mod < mod_min:
                mod_min = mod

    print(mod_min)

def main():
    l, r = [int(i) for i in input().split()] 
    func(l, r)
    
# main関数呼び出し
if __name__ == "__main__":
    main() 

Measured memory_bytes: 3064
import java.util.Scanner;
import java.util.Arrays;

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

Measured memory_bytes: 22100
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main()
{
  ll n;
  cin>>n;
  string s;
  cin>>s;
  vecll dp(n, 0);
  constexpr ll MOD = 1000000007;
  dp[0] = 1;
  for(auto&& i:irange(0l,n-1)) {
    ll l = i+1;
    vecll tmp(n, 0);
    if(s[i] == '>') {
      ll sum = 0;
      for(int j=l-1; j>=0; --j) {
        sum += dp[j];
        sum %= MOD;
        tmp[j] = sum;
      }
    } else {
      ll sum = 0;
      for(auto&& j:irange(0l,l+1)) {
        tmp[j] = sum;
        sum += dp[j];
        sum %= MOD;
      }
    }
    swap(dp, tmp);
  }
  ll ans = 0;
  for(auto&& e:dp) {
    ans += e;
    ans %= MOD;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())

A = [int(i) for i in input().split()]

X = []

for i in range(0, M):
    B, C = map(int, input().split())
    X.append([C, B])

X.sort(reverse=True)

A.sort()

index = 0
l = 0
a = 0
k = X[a][0]

while index < N and a < M and A[index] < k:
    A[index] = k;
    index += 1;
    l += 1;
    if(l == X[a][1]):
        a += 1
        if a >= M:
            break
        k = X[a][0]
        l = 0

print(sum(A))


Measured memory_bytes: 23996
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;


int main(void){
    int n,w,h,s,t;
    while(true){
        cin>>n;
        if(n==0)break;
        cin>>w>>h;
        vector<int>x(n),y(n);
        for(int i=0;i<n;i++){
            cin>>y[i]>>x[i];
            x[i]--;
            y[i]--;
        }
        cin>>s>>t;
        int ans =0;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                int height = i+t;
                int width = j+s;
                int num = 0;
                if((height>h)||(width>w))break;
                for(int k=i;k<height;k++){
                    for(int l=j;l<width;l++){
                        for(int m=0;m<n;m++){
                            if(x[m]==k && y[m]==l)num++;
                        }
                    }
                }
                ans = max(ans,num);
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#include <iomanip>
#define rep(i,N) for(int i=0;i<(int)N;++i)
//cout << fixed << setprecision(20) << *** << endl;
typedef long long ll;
using namespace std;
ll gcd(ll a,ll b){
	ll t;
	if(a<b){
		t=a;
		a=b;
		b=t;
	}
	if(a%b==0)return b;
	return gcd(b,a%b);
}
int main()
{
	double L;
	cin>>L;
	cout << fixed << setprecision(20) << (L/3.0)*(L/3.0)*(L/3.0) << endl;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define YN(y, n, b) (b? y : n)
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

void Main() {
    i32 N;
    cin >> N;
    i32 sum = 0;
    for (i32 i = 1; i <= N; i++) {
        if (to_string(i).size() % 2 == 1) sum++;
    }
    cout << sum << endl;

}


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


int main() {
    vector<int> v(10);

    for (int i = 0; i < 10; i++) {
        cin >> v[i];
    }

    sort(v.begin(), v.end(), [](int a, int b){return a > b;});

    for (int i = 0; i < 3; i++) {
        cout << v[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 1204
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
  ll N;cin>>N;
  vector<ll> H(N);
  rep(i,N) cin>>H[i];
  ll i;

  bool a = true;

  rep(i,N-1){
    if(H[i] - H[i+1] > 1){
      a = false;
    }
    if(!a){
      cout<<"No"<<endl;
      return 0;
    }
  }
  bool b= false;
  ll tmp=0;
  rep(i,N){
    tmp = max(tmp,H[i]);
  }
  ll tmp1;
  rep(i,N){
    if(tmp==H[i]){
      tmp1 =i ;
      b= true;
    }
    if(b) break;
  }
  for(i=tmp1;i<N;i++){
    if(H[i] < tmp-1){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
char a[99999];
int main(){
	int n,s=0,x=1,i;
	for(scanf("%d",&n);s<n;x++)s+=x;
	memset(a,')',--x);
	memset(a+x,'(',x);
	i=a[x],a[x]=a[x-s+n],a[x-s+n]=i;
	puts(a);
}

Measured memory_bytes: 2756
#include <stdio.h>
#define LEN 200000

int main(void){
    char str[LEN+1];
    char buf1;
    int i;
    int sublen = 1;
    int len;
    int buflen;
    int j,flag;
    long long int count = 0;
    scanf("%s", str);
    
    i = 0;
    while(str[i++] != '\0');
    len = i-1;
    
    buf1 = str[0];
    i = 1;
    count++;
    while(i < len){
        if(buf1 != str[i]){
            count++;
            buf1 = str[i];
            i++;
        }else if(i+3 < len){
            count += 2;
            buf1 = str[i+2];
            i += 3;
        }else if(i+2 < len){
            count += 2;
            break;
        }else if(i+1 < len){
            count++;
            break;
        }else{
            break;
        }
    }
    
    printf("%lld\n", count);
    
    return 0;
}

Measured memory_bytes: 384
N = int(input())
S = {}
c = 0
for _ in range(N):
	s = input()
	if s not in S:
		S[s] = 1
	else:
		S[s] += 1
	c = max(c, S[s])
ans = []
for k, v in S.items():
	if v == c:
		ans.append(k)
ans.sort()
for a in ans:
	print(a)


Measured memory_bytes: 35308
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#include <bits/stdc++.h>
using namespace std;

int main() {
  ll n;
  cin>>n;
  
  ll A[3*n];
  rep(i,3*n) cin>>A[i];

  sort(A,A+3*n);
  
  ll sum=0;
  for(int i=3*n-2;i>n-1;i-=2){
    sum+=A[i];
  }
  
  cout<< sum <<endl;
  
  return 0;
}

Measured memory_bytes: 2560
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <stack>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;

const int H = 2437;
string s[H];

struct Rectangle{ ll height;  int pos; };

// http://algorithms.blog55.fc2.com/blog-entry-132.html
int solve(const VI &histo) {
  int n = histo.size();
  stack<Rectangle> S;
  VL buffer(n + 1);
  ll maxv = 0;
  buffer[n] = 0;
  REP(i, 0, n) {
    buffer[i] = histo[i];
  }
     
     for ( int i = 0; i <= n; i++ ){
         Rectangle rect;
         rect.height = buffer[i];
         rect.pos = i;
         if ( S.empty() ){
             S.push( rect );
         } else {
             if ( S.top().height < rect.height ){
                 S.push( rect );
             } else if ( S.top().height > rect.height ) {
                 int target = i;
                 while ( !S.empty() && S.top().height >= rect.height){
                     Rectangle pre = S.top(); S.pop();
                     ll area = pre.height * (i - pre.pos + 1);
                     maxv = max( maxv, area);
                     target = pre.pos;
                 }
                 rect.pos = target;
                 S.push(rect);
             }
         }
     }
     
     return maxv;
}


int main(void) {
  int h, w;
  cin >> h >> w;
  REP(i, 0, h) {
    cin >> s[i];
  }
  vector<VI> diff(h - 1, VI(w - 1, 0));
  REP(i, 1, h) {
    REP(j, 1, w) {
      diff[i - 1][j - 1] =
	s[i][j] ^ s[i - 1][j] ^ s[i][j - 1] ^ s[i - 1][j - 1] ? 1 : 0;
    }
  }
  int ma = max(h, w);
  vector<VI> histo(h - 1, VI(w - 1, 0));
  REP(j, 0, w - 1) {
    int cur = 1;
    REP(i, 0, h - 1) {
      if (diff[i][j] == 1) {
	cur = 1;
      } else {
	cur += 1;
      }
      histo[i][j] = cur;
    }
  }
  REP(i, 0, h - 1) {
    if (0) {
      cerr << "histo[" << i <<"]:";
      REP(j, 0, w - 1) {
	cerr << " " << histo[i][j];
      }
      cerr << endl;
    }
    ma = max(ma, solve(histo[i]));
  }
  if (0) {
    REP(i, 0, h - 1) {
      REP(j, 0, w - 1) {
	cerr << diff[i][j] << " ";
      }
      cerr << endl;
    }
  }
  cout << ma << endl;
}


Measured memory_bytes: 35712
#include <iostream>
#include <complex>

#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b)) < EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real) && EQ((a).imag(), (b).imag) )

using namespace std;

typedef complex<double> P;

double dot(P a, P b) {
  return (a.real() * b.real() + a.imag() * b.imag());
}

int is_orthogonal(P a1, P a2, P b1, P b2) {
  return EQ( dot(a1-a2, b1-b2), 0.0);
}

int main() {
  P a1, a2, b1, b2;
  
  while (true) {
    cin >> a1.real() >> a1.imag() >> a2.real() >> a2.imag() >> b1.real() >> b1.imag() >> b2.real() >> b2.imag();
    if (EQ(a1.real(), 1000)) break;
    cout << (is_orthogonal(a1, a2, b1, b2) ? "YES" : "NO") << "\n";
    //cout << a1.real() << a1.imag() << a2.real() << a2.imag() << b1.real() << b1.imag() << b2.real() << b2.imag() << "\n";

    a1.real() = 1000;
  }
  return 0;
}

Measured memory_bytes: 0
s = input()
t = input()
ls = len(s)
lt = len(t)
dp = [[0 for _ in range(lt + 1)] for _ in range(ls + 1)]
ans = 0
for i in range(ls):
    for j in range(lt):
        if s[i] == t[j]:
            dp[i][j] = dp[i - 1][j - 1] + 1
            if dp[i][j] > ans:
                ans = dp[i][j]
        else:
            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])
            
l = dp[i][j]
ans = ""
while l > 0:
    if s[i] == t[j]:
        ans += s[i]
        i -= 1
        j -= 1
        l -= 1
    elif dp[i][j] == dp[i - 1][j]:
        i -= 1
    else:
        j -= 1
print(ans[::-1])
        

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

#define ll long long int
#define IO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


using namespace std;

const int INF = 1e9 + 7;

int main() {	
	IO;
	
	int n; cin >> n;
	vector<int> a(n);
	vector<int> b(n);
	vector<int> c(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i] >> b[i] >> c[i];
	}
	
	vector<vector<int>> dp(n, vector<int>(3));
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];
	
	for (int i = 1; i < n; ++i) {
		dp[i][0] = a[i] + max(dp[i-1][1], dp[i-1][2]);
		dp[i][1] = b[i] + max(dp[i-1][0], dp[i-1][2]);
		dp[i][2] = c[i] + max(dp[i-1][1], dp[i-1][0]);
	}
	
	cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]});
	
}


Measured memory_bytes: 9756
#include<cstdio>
int a,b,c,d,ans;
void swap(int &a,int &b){int t=a;a=b;b=t;}
int min(int a,int b){return a<b?a:b;}
int main(){
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if(a>c||(a==c&&b>d)) swap(a,c),swap(b,d);
	ans=min(b,d)-c;
	printf("%d",ans>=0?ans:0);
}

Measured memory_bytes: 128
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define fo(i,n) for(int i=0;i<(n);i++)
#define inp(a) int a;cin>>a;
#define inpa(a,n)vector<int> a(n);fo(i,n)cin>>a[i];
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
using namespace std;
#define int ll
// #define MAX 20
#define INF (int)1e18

template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.F<<','<< P.S<<')';}


signed main()
{
	fio
	inp(a) inp(b) inp(c) inp(d)
	int t=0;
	while(1)
	{
		if(t%2)
		{
			a-=d;
			if(a<=0)
			{
				cout<<"No\n";
				return 0;
			}
		}
		else
		{
			c-=b;
			if(c<=0)
			{
				cout<<"Yes\n";
				return 0;
			}
		}
		t++;
	}
	printclock;
}

Measured memory_bytes: 3648