akhauriyash/Code-Regression huggingface dataset:
import javax.swing.ComboBoxEditor

fun main(args:Array<String>):Unit {
    val combinations = listOf(1, -1).flatMap{look ->
        listOf(1, -1).flatMap{taste ->
            listOf(1, -1).map{pop ->
                Combination(look.toLong(), taste.toLong(), pop.toLong())
            }
        }
    }
    val (n, m) = readLine()!!.trim().split(' ').map(String::toInt)
    val cakes = Array(n){
        val (x, y, z) = readLine()!!.trim().split(' ').map(String::toLong)
        Cake(x, y, z)
    }
    val max = combinations.mapNotNull{combinator ->
        val memo:Array<Combination?> = Array(m + 1){null}
        memo[0] = combinator
        for (cake in cakes) for (i in (m downTo 1)){
            if (memo[i - 1] != null) {
                if (memo[i] == null) {
                    memo[i] = memo[i - 1]!!.add(cake)
                }else if (memo[i - 1]!!.add(cake) > memo[i]!!) {
                        memo[i] = memo[i - 1]!!.add(cake)
                    }
                }
            }
        memo[m]?.sum()
        }.max()!!

    println(max)
}
data class Cake(val look:Long, val taste:Long, val popular:Long) {
    operator fun plus(other:Cake):Cake = Cake(look + other.look, taste + other.taste, popular + other.popular)
}
open class Combination private constructor (private val mLook:Long, private val mTaste:Long, private val mPopular:Long, private var mCake:Cake):Comparable<Combination>{
    override fun compareTo(other: Combination): Int {
        return sum().compareTo(other.sum())
    }
    open fun sum():Long = mLook * mCake.look + mTaste * mCake.taste + mPopular * mCake.popular
    fun add(cake: Cake):Combination {
        return Combination(mLook, mTaste, mPopular, cake + mCake)
    }

    constructor(look:Long, taste:Long, pop:Long):this(look, taste, pop, Cake(0, 0, 0))
}

object Dummy:Combination(0, 0, 0){
    override fun sum():Long = -1000000000000
}

Measured memory_bytes: 111460
/*
 * Problem Description: Stack
 * Category:
 * Author: Khan
 * Date: 11th October, 2017
 */

#include <iostream>
#include <cstdlib>
#include <stack>

using namespace std;

int main(int argc, char const *argv[])
{
    //freopen("sample.txt", "r", stdin);
    stack<int> S;
    int a, b, x;
    char s[100];
    while(cin >> s)
    {
        switch(s[0])
        {
        case '+':
            a = S.top(); S.pop();
            b = S.top(); S.pop();
            S.push(a + b);
            break;
        case '-':
            b = S.top(); S.pop();
            a = S.top(); S.pop();
            S.push(a - b);
            break;
        case '*':
            a = S.top(); S.pop();
            b = S.top(); S.pop();
            S.push(a * b);
            break;
        default:
            S.push(atoi(s));
            break;
        }
    }
    cout << S.top() << endl;
    return 0;
}

Measured memory_bytes: 3080
#include "bits/stdc++.h"
using namespace std;
int main()
{
    int n, a, b, c, d = 0;
    scanf("%d %d %d", &n, &a, &b);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &c);
        if (a > c || c >= b)
        {
            d++;
        }
    }
    printf("%d\n", d);
}


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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

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

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

ll n, a, b, h[100000];

// x回爆発を起こすとするとまず魔物全員の体力がb*x減り、更に任意の魔物の体力をa-bだけ減らすって操作をx回できる
// だからそれぞれの要素の必要な最小操作回数(h[i]-b*x)/(a-b) (切り上げ)の合計を求めて、それがx以下ならOK
bool ok(ll x) {
	ll cnt = 0;
	rep(i,n) {
		ll hp = h[i] - b*x;
		if (hp>0) cnt += (hp + a-b-1)/(a-b);
	}
	return cnt <= x;
}

int main() {
	cin >> n >> a >> b;
	rep(i,n) cin >> h[i];
	
	ll low = 0, high = 1000000000;
	while (high-low>1) {
		ll mid = (high+low)/2;
		if (ok(mid)) high = mid;
		else low = mid;
	}
	cout << high << ln;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

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++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  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;
  }
};

int main()
{
  int n, m;
  cin >> n >> m;
  priority_queue<ll> pq;
  rep(i, n) {
    ll a; cin >> a;
    pq.push(a);
  }

  rep(i, m) {
    ll a = pq.top(); pq.pop();
    a /= 2;
    pq.push(a);
  }

  ll ans = 0;
  rep(i, n) {
    ans += pq.top(); pq.pop();
  }
  cout << ans << endl;
}

Measured memory_bytes: 4188
# sys.stdin.readline
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N = int(input())
        txy = [list(map(int, input().split())) for _ in range(N)]

        t, x, y = 0, 0, 0

        for next in txy:
            time = next[0] - t
            x_d = abs(next[1] - x)
            y_d = abs(next[2] - y)
            if x_d + y_d > time or (x_d + y_d) % 2 != time % 2:
                print('No')
                exit()
            t, x, y = next

        print('Yes')


# Run main
if __name__ == '__main__':
    AtCoder().main()

Measured memory_bytes: 56396
#include <stdio.h>
#define INF 100000000
int A[20000000];
int n;

int count(){//????´??????°?????°??????
  int i;
  for(i=1;A[i]!=0;i++){
  }
  return i;
}

void maxHeapify( int i )
{
  int l,r,large,tmp,k;
  l=2*i;
  r=2*i+1;
  if(l<= n && A[l] > A[i]) large=l;

  else large=i;

  if(r<= n && A[r] > A[large]) large=r;

  if(large!=i){
    tmp=A[i];
    A[i]=A[large];
    A[large]=tmp;
    maxHeapify(large);
  }
  
}
void increaseKey(int n,int k){
  int tmp;
  A[n]=k;
  while(n>1 && A[n/2] < A[n]){
    tmp=A[n];
    A[n]=A[n/2];
    A[n/2]=tmp;
    n=n/2;
  }
}

void insert(int k){
  int i;
  //i=count();
 n++;
  A[n]=-INF;
  //n++;
  increaseKey(n,k);

}

int extractMax(){
  int i,max;

   maxHeapify(1);




  //n=count();
  
  max=A[1];
 
  A[1]=A[n];
  //printf("A[n]=%d\n",A[n]);
  n--;

  maxHeapify(1);
  
  return max;
}




int main(){
  int i, x;
  char com[20];

  for ( i = 1; i <= 2000000; i++ ){
    scanf("%s", com);
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    

    } 
     else if ( com[1] == 'x' ){
       printf("%d\n",extractMax());
    } 
     else if ( com[1] == 'n' ) break;
  }

 
  return 0;
}

Measured memory_bytes: 4692
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    ll n,m;
    std::cin >> n>>m;
    ll count[100010];
    Fill(count,0);
    for (int i = 0; i < m; i++) {
        ll t1,t2;
        std::cin >> t1>>t2;
        count[t1-1]++;
        count[t2-1]++;
    }
    for (int i = 0; i < n; i++) {
        if(count[i] %2==0){
            continue;
        }else{
            std::cout << "NO" << std::endl;
            return 0;
        }
    }
    std::cout << "YES" << std::endl;
}


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

using ll = long long int;

const ll MAX = (ll)(1e9 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(1e5 + 5);

/////////////////////////////////////////////////////////////
class BinaryIndexedTree {
 public:
  static const int MAX_N = (int)(2e5 + 100);

  ll bit_arr[MAX_N];
  int n;

  BinaryIndexedTree(int n) {
    this->n = n;
    init();
  }

  void init() {
    for (int i = 0; i < n; ++i) bit_arr[i] = 0LL;
  }

  ll sum(int i) {
    ll s = 0LL;
    while (i > 0) {
      s += bit_arr[i];
      i -= i & -i;
    }
    return s;
  }

  void add(int i, ll x) {
    while (i <= n) {
      bit_arr[i] += x;
      i += i & -i;
    }
  }
};
/////////////////////////////////////////////////////////////

int n;
ll a[MAX_N];
ll b[MAX_N];

int s[MAX_N];

BinaryIndexedTree bit(MAX_N * 2);

bool check(ll x) {
  ll num = 0;

  for (int i = 1; i <= n; ++i) s[i] = (a[i] >= x) ? 1 : -1;
  for (int i = 1; i <= n; ++i) s[i] += s[i - 1];

  bit.init();

  for (int i = 0; i <= n; ++i) {
    num += bit.sum(s[i] + MAX_N);
    bit.add(s[i] + MAX_N, 1);
  }

  ll whole = (1LL * (n + 1) * n) / 2;
  ll target =  (whole - 1) / 2 + 1;

  return (num >= target);
}

int main(void) {
  // Here your code !
  scanf("%d", &n);

  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &(a[i]));
    b[i] = a[i];
  }

  sort(b + 1, b + n + 1);

  b[n + 1] = b[n] + 1; // guard

  int ok = 1;
  int ng = n + 1;

  while (abs(ok - ng) > 1) {
    int next = (ok + ng) / 2;

    if (check(b[next])) {
      ok = next;
    }
    else {
      ng = next;
    }
  }

  printf("%lld\n", b[ok]);

  return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fr first
#define sc second
#define N 200009
#define pi pair<ll,ll>
#define pb push_back
using namespace std;
typedef long long ll;
int main()
{
    //FAST;
    ll n,a;
    cin>>n;
     ll ans=0;
    for(ll i=1;i<=n;i++) {
        cin>>a;
        if(i%2!=0 && a%2!=0) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3628
import java.util.*;

public class Main {

	static void cal(int n, int[] R){
	
		int max = R[1] - R[0];
		int x;
		int minr = R[0];
		
		for(int i = 1; i < n; i++){
			x = R[i] - minr;
			if(max < x) max = x;
			if(minr > R[i]) minr = R[i];
		}
		System.out.println(max);
	}

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
		
        int n = sc.nextInt();
		int[] R = new int[n];
		
		for(int i = 0; i < n; i++) R[i] = sc.nextInt();
		
		cal(n, R);
	}
}


Measured memory_bytes: 100792
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

struct DisjointSet {
	vector<int> par;

	DisjointSet(int N) : par(N, -1) {}

	bool isSame(int a, int b) {
		return root(a) == root(b);
	}

	int root(int a) {
		if (par[a] < 0) return a;
		par[a] = root(par[a]);
		return par[a];
	}

	int size(int a) {
		return -par[root(a)];
	}

	void unite(int a, int b) {
		if (!isSame(a, b)) {
			a = root(a);
			b = root(b);
			if (size(a) < size(b)) swap(a, b);
			par[a] += par[b];
			par[b] = a;
		}
	}
};

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> a(M), b(M);
	for (size_t i = 0; i < M; ++i) {
		cin >> a[i] >> b[i];
		--a[i];
		--b[i];
	}
	int ans = 0;
	for (size_t i = 0; i < M; ++i) {
		DisjointSet ds(N);
		for (size_t j = 0; j < M; ++j) {
			if (i != j) ds.unite(a[j], b[j]);
		}
		size_t j;
		for (j = 0; j < N; ++j) {
			if (ds.size(j) != N) break;
		}
		if (j != N) ++ans;
	}
	cout << ans;
}

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()

A,B = map(int, input().split())

def calc(a):

    cnt = (a+1) // 2
    ans = cnt % 2

    if a % 2 == 0:
        ans ^= a

    return ans

print(calc(A-1)^calc(B))

Measured memory_bytes: 38256
K = int(input())
N = 50

ans = list(range(N))

for i in range(len(ans)):
    ans[i] += K//N

for i in range(K % N):
    for j in range(len(ans)):
        if j == i:
            ans[j] += N
        else:
            ans[j] -= 1
    
print(N)
print(*ans)

Measured memory_bytes: 3064
min, mid, max = sorted([int(i) for i in input().split()])

ope1 = max - mid    # この回数「midとminに1を足す」を行うと、maxとmidが同じ数になる

diff = (max - (ope1 + min))  # その上で、minをそろえるためにあといくつ増やさなければならないか
ope2 = diff // 2             # minに2を足す回数

if diff % 2 != 0:
    ope1 = ope1 + 1          # minを増やす数が奇数の場合、ope1を一度増やして差を偶数にする。
    ope2 = ope2 + 1          # 差が2になったので、ope2をもう一度

print(ope1 + ope2)


Measured memory_bytes: 2940
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define max(a, b)	(((a) > (b)) ? (a) : (b))		/* ２個の値の最大値 */
#define min(a, b)	(((a) < (b)) ? (a) : (b))		/* ２個の値の最小値 */
#define ENTER		printf("\n")					/* 改行プリント */
int DBG = 1;										/* デバッグプリント 提出時は0 */
/* main *************************************************************/
int main()
{
	int		a,b,c,i,j,k,n,m,x,y,ans = 0;
	char	s[256],t[256];
	
	scanf("%d", &n);
	scanf("%s", s);
	scanf("%s", t);
	
	for(i=0;i<n;i++) {
		printf("%c%c",s[i],t[i]);
	}
	ENTER;
		



	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,k;
	bool flag=0;
	cin>>k>>a>>b;
	for(int i=a;i<=b;i++){
		if(i%k==0){
			flag=1;
			break;
		}
	}
	if(flag){
		cout<<"OK";
	}
	else{
		cout<<"NG";
	}
}

Measured memory_bytes: 3636
def scoring(d, t):
    arr = [l for l in last]
    arr[t] = d
    return S[d][t] - sum((d - l) * c for l, c in zip(arr, C))

D = int(input())
C = list(map(int, input().split()))
S = []
for _ in range(D):
    s = list(map(int, input().split()))
    S.append(s)
last = [-1] * 26
ans = []
for i in range(D):
    res = -10 ** 6
    idx = -1
    for j in range(26):
        tmp = scoring(i, j)
        if tmp > res:
            res = tmp
            idx = j
    last[idx] = i
    ans.append(idx+1)
print(*ans, sep='\n')

Measured memory_bytes: 9356
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
A = list(map(int,input().split()))
now_max = -1
for i in range(n):
  if now_max > A[i]:
    count += now_max - A[i]
  else:
    now_max = A[i]
print(count)


Measured memory_bytes: 103856
#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()

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

    // start
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a * b >= c * d)
        cout << a * b << endl;
    else
        cout << c * d << endl;
    // end

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

template <class T, class Comp>
struct AdditionChain {
  int k;
  vector<T> prepare;
  T t, unit;
  Comp comp;

  AdditionChain(const T& t, const Comp& comp, int k, const T& unit = 1) : comp(comp), t(t), unit(unit), k(k), prepare(1U << k) {
    prepare[0] = unit;
    for (int i = 1; i < 1 << k; ++i)
      prepare[i] = comp(prepare[i - 1], t);
  }

  static AdditionChain fourRussians(const T &t, const Comp &comp, int lgn, const T &unit = 1) {
    lgn = max(lgn, 1);
    int k = 1, lglgn = 1;
    while (2 << lglgn <= lgn)
      ++lglgn;
    int w = lglgn / lgn;
    while (1 << k < w)
      ++k;
    return AdditionChain(t, comp, k, unit);
  }

  T pow(ll n) const {
    if (n < 1 << k)
      return prepare[n];
    ll r = n & ((1 << k) - 1);
    T step = pow(n >> k);
    for (int rep = 0; rep < k; ++rep)
      step = comp(step, step);
    return comp(step, prepare[r]);
  }
};

const int N = 50, P = 1000000007;

int n;

struct Mat {
  int g[N][N];

  Mat() { memset(g, 0, sizeof(g)); }

  Mat(const Mat& rhs) { memcpy(g, rhs.g, sizeof(g)); }

  Mat operator*(const Mat& rhs) const {
    Mat ret = Mat();
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < n; ++j)
        for (int k = 0; k < n; ++k)
          ret.g[i][j] = (ret.g[i][j] + g[i][k] * (ll)rhs.g[k][j]) % P;
    return ret;
  }
};

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif

  ll k;
  scanf("%d%lld", &n, &k);
  Mat g = Mat();
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
      scanf("%d", &g.g[i][j]);
  Mat id = Mat();
  for (int i = 0; i < n; ++i)
    id.g[i][i] = 1;
  Mat res = AdditionChain<Mat, multiplies<Mat>>::fourRussians(g, multiplies<Mat>(), (int)log2(k), id).pow(k);
  printf("%d\n", accumulate(*res.g, *res.g + N * N, 0LL) % P);

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 768
n = int(input())
*A, = map(int, input().split())
for i in range(n):
    v = A[i]
    j = i - 1
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v
    print(*A)



Measured memory_bytes: 5976
#include<bits/stdc++.h>
#define int long long int
#define double long double
#define endl "\n"
#define sz(x) (int)x.size()
using namespace std;

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int n;
  cin>>n;

  string s;
  cin>>s;

  string ans=s.substr(0, n);

  if(n>=(int)s.size()) {
    cout<<s;
  } else {
    cout<<ans<<"...";
  }

}


Measured memory_bytes: 3660
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_set>
#include <utility>
#include <cmath>
#include <stdlib.h> 
#include <stdio.h>
#include <iterator>
#include <chrono>
#include <iomanip>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <deque>
#include <stack>
#include <queue>
#include <fstream>
#include <limits>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <sstream>
#include <random>
#include <cassert>

using namespace std;
#define ffor(n) for(int i = 0; i < n; i++)
#define fffor(n) for(int j = 0; j < n; j++)
int INF = 1e9 + 7;

int main(void) {
	cin.tie(0); ios::sync_with_stdio(0);
	
	int n;
	cin >> n;
	string s;
	ffor(n) s += "ACL";
	cout << s;
}
	




/*
C:\Users\User\Desktop\comp_programming\final_straw_after_this_im_switching_to_vs_code\final_straw_after_this_im_switching_to_vs_code.cpp
*/

Measured memory_bytes: 3604
fun main(args: Array<String>) {
    val mod = 1000000007L
    val fib = arrayOf<Long>(1, 2, 3, 5, 8, 13, 21, 34, 55)
    val (h, w, k) = readLine()!!.split(' ').map(String::toInt)
    val dp = Array(h + 1) { Array(w) { 0L } }
    dp[0][0] = 1
    for (i in 0 until h) {
        for (j in 0 until w) {
            if (j > 0) {
                dp[i + 1][j - 1] += dp[i][j] * fib[Math.max(0, j - 2)] * fib[Math.max(0, w - j - 2)]
                dp[i + 1][j - 1] %= mod
            }
            dp[i + 1][j] += dp[i][j] * fib[Math.max(0, j - 1)] * fib[Math.max(0, w - j - 2)]
            dp[i + 1][j] %= mod
            if (j < w - 1) {
                dp[i + 1][j + 1] += dp[i][j] * fib[Math.max(0, j - 1)] * fib[Math.max(0, w - j - 3)]
                dp[i + 1][j + 1] %= mod
            }
        }
    }
    println(dp[h][k - 1])
}


Measured memory_bytes: 36388
N, Q = map(int, input().split())

S = input()
items = []
for i in range(Q):
    items.append(input().split())

left_ok = -1
left_ng = N


def check_left(mid):
    flag = False
    tmp = mid
    for t, d in items:
        if t == S[tmp]:
            if d == "L":
                if tmp - 1 == -1:
                    flag = True
                    break
                tmp -= 1
            else:
                if tmp + 1 >= N:
                    break
                tmp += 1
    return flag


def check_right(mid):
    flag = False
    tmp = mid
    for t, d in items:
        if t == S[tmp]:
            if d == "R":
                if tmp + 1 == N:
                    flag = True
                    break
                tmp += 1
            else:
                if tmp - 1 == -1:
                    break
                tmp -= 1

    return flag


while abs(left_ng - left_ok) > 1:
    mid = (left_ok + left_ng) // 2
    if check_left(mid):
        left_ok = mid
    else:
        left_ng = mid

right_ok = N
right_ng = -1

while abs(right_ok - right_ng) > 1:
    mid = (right_ok + right_ng) // 2

    if check_right(mid):
        right_ok = mid
    else:
        right_ng = mid

ans = N
if left_ok != -1:
    ans -= left_ok + 1

if right_ok != N:
    ans -= N - right_ok

if left_ok >= right_ok:
    ans = 0

print(ans)


Measured memory_bytes: 93644
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

int main() {
	int n;
	cin >> n;
	vector<vector<int>> v(2, vector<int>(n));
	for (int j = 0; j < 2; j++) {
		for (int i = 0; i < n; i++) {
			cin >> v[j][i];
		}
	}

	vector<ll> pr(n);
	vector<ll> suf(n);
	pr[0] = v[0][0];
	for (int i = 1; i < n; i++) {
		pr[i] = pr[i - 1] + v[0][i];
	}
	suf[n - 1] = v[1][n - 1];
	for (int i = n - 2; i > -1; i--) {
		suf[i] = suf[i + 1] + v[1][i];
	}
	ll best = 0;
	for (int i = 0; i < n; i++) {
		best = max(best, pr[i] + suf[i]);
	}
	cout << best;
}


Measured memory_bytes: 256
# import sys
# input = sys.stdin.readline

def mp(): return map(int, input().split())
def lmp(): return list(map(int, input().split()))

x = int(input())
if 400 <= x <= 599:
    print(8)
if 600 <= x <= 799:
    print(7)
if 800 <= x <= 999:
    print(6)
if 1000 <= x <= 1199:
    print(5)
if 1200 <= x <= 1399:
    print(4)
if 1400 <= x <= 1599:
    print(3)
if 1600 <= x <= 1799:
    print(2)
if 1800 <= x <= 1999:
    print(1)






Measured memory_bytes: 61784
import sys
#sys.exit()
#sorted( ,reverse=True)
#N = int(input())
#S,T = map(int, input().split())
#A = list(map(int, input().split()))
#A = [int(input()) for _ in range(N)]

#cnt = 0
#cnt += 1



#print(N)
#print(S,T)
#print(A)
#print('Yes')
#print('No')
#print(cnt)

N = str(input())

if N[-1] == "2" or  N[-1] =="4" or  N[-1] =="5" or  N[-1] =="7" or  N[-1] =="9":
    print("hon")
elif N[-1] == "0" or N[-1] == "1" or  N[-1] =="6" or  N[-1] =="8":
    print("pon")
else:
    print("bon")

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

int main(){
  ll a, b, k;
  cin >> a >> b >> k;
  if(k<=a){
    a -= k;
    cout << a << " " << b << "\n";
  }
  else if(a<k&&k<=a+b){
    cout << 0 << " " << a + b - k << "\n";
  }
  else{
    cout << 0 << " " << 0 << "\n";
  }
}


Measured memory_bytes: 256
def gcd(a, b):
    if (b == 0):
        return a
    return gcd(b, a % b)

n, x = map(int,input().split())
arr = list(map(int,input().split()))
diff = []
arr.sort()
g = abs(arr[0] - x)
for i in range(1,n):
    g = gcd(g, abs(arr[i] - x))
print(g)

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

int main()
{
  int N, tem;
  int aaa = 1;
  int ans = 1;
  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> tem;
    if(tem % 2 == 0)
      aaa *= 2;
    ans *= 3;
  }
  
  cout << ans - aaa << endl;
  
  return 0;
}

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

int n;
int num[210];
int main(){
	cin >> n;
	for (int i = 0; i < n; ++i)cin >> num[i];
	int res=0;
	while (true)
	{
		bool odd_exist= false;
		for (int i = 0; i < n; ++i) {
			if (num[i] % 2 != 0) odd_exist = true;
		}
		if (odd_exist) break;
		for (int i = 0; i < n; ++i) {
			num[i] /= 2;
		}
		++res;
	}
	cout << res << endl;
}


Measured memory_bytes: 3172
using System;
using System.Linq;

namespace abc100_c
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            long ret = 0;
            for (int i = 0; i < n; i++)
            {
                while (x[i] % 2 == 0)
                {
                    ret++;
                    x[i] /= 2;
                }
            }
            Console.WriteLine(ret);
        }
    }
}

Measured memory_bytes: 14176
#include<bits/stdc++.h>
#include<vector>
#include<iostream>
#include<sstream>
#include<fstream>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<ctime>
#include<iomanip>
using namespace std;
/*freopen{"input.txt","r",stdin};
freopen{"output.txt","w",stdout};*/
#define mp make_pair
#define pb push_back
const int INF=1000*1000*1000;
const int maxn=2e5; 
typedef long long ll;
typedef long double ld;
typedef pair<int,int>PII;
//priority_queue <int,vector<int>,greater<int> > q1;  //从小到大 
//priority_queue <int,vector<int>,less<int> >q2;  //从大到小 

//set multiset vector queue priority_queue map multimap pair string structure 

//枚举 思维 贪心 搜索 模拟 预处理 二分 排序 
map<int,int>m;
int main(){
	//ios_base::sync_with_stdio(0);
    //cin.tie(0);
    //cout.tie(0);
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		m[x]++;
	}
	for(auto it=m.begin();it!=m.end();it++){
		if(it->second>1){
			cout<<"NO";
			return 0;
		}
	}
	cout<<"YES";
	
	
	
	
	
	
	return 0;
}



Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define int long long 
const int mod=1e9+7;
int power(int a,int b)
{
    if(a==1 || b==0)
        return 1;
    if(b==1)
        return a;
    int x=power(a,b/2);
    if(b%2==0)
        return ((x%mod)*(x%mod))%mod;
    return (((x%mod)*(x%mod))%mod * a)%mod;
}
void solve()
{
    int n, k, sum = 0;
    cin >> n >> k;
    vector<int> dp(k + 1, 0);
    for (int i = k; i >= 1; i--)
    {
        dp[i] = power(k / i, n);
        for (int j = i + i; j <= k; j+=i)
        {
            dp[i] = dp[i] - dp[j] + mod;
            while (dp[i] >= mod)
                dp[i] -= mod;
        }
        sum += dp[i]*i;
        while (sum >= mod)
            sum -= mod;
    }
    cout<<sum;
}

int32_t main()
{
    solve();
    return 0;
}


Measured memory_bytes: 4036
///cREATED bY BERNARB.01
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef priority_queue<int,vector<int>,greater<int>> pqil;
typedef priority_queue<int> pqig;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef priority_queue<pii> pqiig;
typedef vector<pii> vii;
typedef vector<piii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef map<int, int> mii;
#define mid ((l+r)/2)
#define PB push_back
#define PP pop_back
#define PF push_front
#define DF pop_front
#define F first
#define S second
#define MP make_pair
#define C continue
#define B break
#define R return
#define sz(v) (int)(v).size()
#define len(s) (int)(s).length()
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define clr(arr, x) memset((arr), (x), sizeof (arr))
#define loop(n) for(ll i=0; i<(n); i++)
#define jloop(n) for(ll j=0; j<(n); j++)
#define rloop(n) for(ll i=(n)-1; i>=0; i--)
#define sgm(y) (((y)*((y)+1))/2)
const ll INF = 2e17+423;
const ll mod = 1e9+7; //998244353;
const ld pi = acos(-1.0);
const ld cmpf = 1e-9;
//__int128_t
//      -ASCII-
//a -> z | A -> Z | 0 -> 9
//97 122 | 65  90 | 48  57
#define endl '\n'
ll po(ll,ll);



















int main() {
  /*#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  #endif // ONLINE_JUDGE*/
  ios::sync_with_stdio(0);
  cin.tie(0);
  int h, a;
  cin >> h >> a;
  cout << (h/a)+(h%a!=0) << endl;
  R 0;
}
/*

*/




























































ll po(ll x, ll n){
  if(n==0) R 1;
  ll y = po(x, n/2);
  y = ((y)*(y));
  if(n%2) y = (y*(x));
  R y;
}


Measured memory_bytes: 256
//標準関数をすべてインクルードする。
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;

const int_least64_t INF = 10000000;

int main(){
    //cin coutを高速化
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout.tie(0);

    int n;
    cin >> n;
    vector<int> p(n, 0);
    rep(i, n) cin >> p[i];
    int rem = 0;
    for(int i = 1; i < n - 1; i++){
        if(p[i - 1] < p[i] && p[i] < p[i + 1]) rem++;
        if(p[i - 1] > p[i] && p[i] > p[i + 1]) rem++;
    }
    
    cout << rem << endl;

    return 0;
}



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

using namespace std;

#define db(x) cout << (x) << '\n';
#define all(x) x.begin(),x.end()
#define UNIQUE(x) sort(all(x)),x.resize(unique(all(x))-x.begin())
#define LB(v,x) lower_bound(all(v),x)
#define UB(v,x) upper_bound(all(v),x)
#define endl "\n"
#define F first
#define S second
#define PB push_back
#define PF push_front
#define int long long
#define double long double
#define trick int m = (l+r)>>1,lc=n<<1,rc=lc|1

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

int dy[]={0,1,1,1,0,-1,-1,-1};
int dx[]={-1,-1,0,1,1,1,0,-1};
const int maxn = 1e5;
const int OO = 1e18;
const int mod = 1e9 + 7;
const double PI = acos(-1);

void maxself(int &a,int b)
{a=max(a,b);}
void minself(int &a,int b)
{a=min(a,b);}

vector<vi> g(maxn);


int32_t main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

//	freopen("name.in","r",stdin);
//	freopen("name.out","w",stdout);
	
	int r;
	cin >> r;
	cout << r*r;

	return 0;
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
typedef pair<int,int> ipair;
#define pb push_back
#define MP make_pair
#define ff first
#define ss second
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define ABS(x) ((x)<0?-(x):(x))
 
ll mod = 1000000007;


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

	int cnt=0;
	int prev;
	string pe,tp;

	if(s.length()<2){return s.length();}

	cnt = 1;
	pe = s.substr(0,1);
	prev = 1;

	for(int i=1;i<s.length();i++){
		tp = s.substr(prev,i-prev+1);
		if(tp!=pe){
			cnt++;
			prev = i+1;
			pe = tp;
		}
	}
	cout<<cnt<<endl;
}
 
//-------------------------//

Measured memory_bytes: 720
N = int(input())
E = [ [] for i in range(N)]
D = [0] * N
for i in range(N-1):
    a,b = map(int,input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)
c = list(map(int,input().split()))
x = max(c)
print(sum(c)-max(c))
start = 0
for i in range(N):
    if (len(E[i]) >= 2):
        start = i
        break
already = [0]*N
already[start] = 1
path = [start]
while(path):
    start = path[0]
    try:
        next = E[start][0]
    except:
        d = min(c)
        D[start] = d
        c.remove(d)
        path.remove(start)
        continue
    if already[next] == 1:
        E[start].remove(next)
        continue
    path.insert(0,next)
    already[next] = 1
for d in D:
    print(d,end = " ")


Measured memory_bytes: 6004
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef struct pair<int,int> P;
typedef struct pair<int,P> P2;

int n;

int dp[31][1000001]={};
int d[31][1000001]={};

const ll INF=100000000001;
int main() {
	string s,t;
	cin>>s>>t;
	int ls=s.length();
	int lt=t.length();
	string ns1,ns2;
	bool flg=false;
	int num=0;
	for(int i=0;i<ls-lt+1;++i){
		flg=true;
		for(int j=0;j<lt;++j){
			if(!(s[i+j]=='?'||s[i+j]==t[j]))flg=false;
		}
		if(flg){
			ns2=s;
			for(int j=0;j<i;++j){
				if(s[j]=='?')ns2[j]='a';
			}
			for(int j=0;j<lt;++j){
				if(s[i+j]=='?')ns2[i+j]=t[j];
			}
			for(int j=i+lt;j<ls;++j){
				if(s[j]=='?')ns2[j]='a';
			}
			if(num==0)ns1=ns2;
			ns1=min(ns1,ns2);
			num++;
		}
	}
	if(num==0){
		cout<<"UNRESTORABLE"<<endl;
	}else{
		cout<<ns1<<endl;
	}
	return 0;
}


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

#define IO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define m(a,b) memset(a,b,sizeof(a))
#define rep(i,n) for(int i=1;i<=n;i++)
typedef long long ll;
typedef pair<string,int> p;
const int MAXN=1e5+10;
int a[105];
int main(){
	IO;
	int a,b,c,x,y;
	cin>>a>>b>>c>>x>>y;
	if (x==y) cout<<min(x*(a+b),2*x*c)<<endl;
	else{
		int ans=0;
		if (x>y){
			ans+=(x-y)*a;
			ans+=min(y*(a+b),2*y*c);
		}
		else{
			ans+=(y-x)*b;
			ans+=min(x*(a+b),2*x*c);
		}
		if (max(x,y)*2*c<ans) ans=y*2*c;
		cout<<ans<<endl;
	}
	return 0;
}

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

int c0, c1, c2, c3, n;
string s;

int main() {
    c0 = c1 = c2 = c3 = 0;
    for(cin>>n; n > 0; n--) {
        cin>>s;
        if(s == "AC")
            c0++;
        else if(s == "WA")
            c1++;
        else if(s == "TLE")
            c2++;
        else c3++;
    }
    cout<<"AC x "<<c0<<"\nWA x "<<c1<<"\nTLE x "<<c2<<"\nRE x "<<c3;
    return 0;
}


Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        private const int MODULO = 1000000007;
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        class Path
        {
            public readonly int a;
            public readonly int b;
            public readonly long c;
            public Path(long[] v)
            {
                a = (int)(v[0] - 1);
                b = (int)(v[1] - 1);
                c = v[2];
            }
        }
        static long? Solve(int N, int M, Path[] paths)
        {
            var d = Enumerable.Repeat(long.MinValue / 2, N).ToArray();
            d[0] = 0;
            for (int i = 0; i < N; ++i)
            {
                foreach (Path p in paths)
                {
                    d[p.b] = Math.Max(d[p.a] + p.c, d[p.b]);
                }
            }
            for (int i = 0; i < N; ++i)
            {
                foreach (Path p in paths)
                {
                    if (p.b == N - 1 && d[p.a] + p.c > d[p.b]) { return null; }
                    d[p.b] = Math.Max(d[p.a] + p.c, d[p.b]);
                }
            }
            return d[N - 1];
        }
        static void Main(string[] args)
        {
            int[] v = ReadInts();
            int N = v[0];
            int M = v[1];
            var paths = new Path[M];
            for (int i = 0; i < M; ++i) { paths[i] = new Path(ReadLongs()); }
            var ans = Solve(N, M, paths);
            Console.WriteLine((ans != null) ? ans.ToString() : "inf");
        }
    }
}


Measured memory_bytes: 13360
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

using ll = long long;
using P = pair<int, int>;

const long long MOD = 1e9+7;

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

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

    const int INF = 1000;
    vector<vector<int>> dp(1 << n, vector<int>(n + 1, INF));
    dp[0][n] = 0;
    rep(bit, 1 << n) {
        int cnt = 0;
        rep(i, n) cnt += bit >> i & 1;
        
        rep(i, n + 1) rep(j, n) {
            if (bit >> j & 1) continue;

            int last_num = 0;
            if (i < n) last_num = x[abs(cnt - 1 - i) % 2][i];
            int new_num = x[abs(cnt - j) % 2][j];
            if (last_num <= new_num) {
                int rev = 0;
                repr(k, j, n) if (bit >> k & 1) rev++;
                chmin(dp[bit | (1 << j)][j], dp[bit][i] + rev);
            }
        }
    }

    int ans = INF;
    rep(i, n) chmin(ans, dp[(1 << n) - 1][i]);
    if (ans == INF) cout << -1 << endl;
    else cout << ans << endl;
}

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

long long dp[100006][3],n,k,r,s,p;
string str;

long long solve(long long idx,long long sta)
{


    if(idx>n)return 0;
    else if(dp[idx][sta]!=-1)return dp[idx][sta];
    else
    {

        if(idx<=k)
        {

            long long rr,ss,pp,fr,sc,tr,rs;

            if(str[idx-1]=='r'){  rr=0; ss=0; pp=p;   }
            else if(str[idx-1]=='s'){  rr=r; ss=0; pp=0;     }
            else{  rr=0; ss=s; pp=0; }

            fr=rr+solve(idx+k,0);   sc=ss+solve(idx+k,1);  tr=pp+solve(idx+k,2);
            rs=max(fr,sc);  rs=max(rs,tr);  dp[idx][sta]=rs;  return dp[idx][sta];


        }
        else
        {
             long long rr,ss,pp,fr,sc,tr,rs;

             if(sta==0)
             {
                 if(str[idx-1]=='r'){   ss=0; pp=p;   }
                 else if(str[idx-1]=='s'){   ss=0; pp=0;     }
                 else{   ss=s; pp=0; }

                sc=ss+solve(idx+k,1);  tr=pp+solve(idx+k,2);
                rs=max(sc,tr);   dp[idx][sta]=rs;  return dp[idx][sta];


             }
             else if(sta==1)
             {
                 if(str[idx-1]=='r'){  rr=0; pp=p;   }
                 else if(str[idx-1]=='s'){  rr=r; pp=0;     }
                 else{  rr=0; pp=0; }

                fr=rr+solve(idx+k,0);    tr=pp+solve(idx+k,2);
                rs=max(fr,tr);   dp[idx][sta]=rs;  return dp[idx][sta];



             }
             else
             {
                 if(str[idx-1]=='r'){  rr=0; ss=0;   }
                 else if(str[idx-1]=='s'){  rr=r; ss=0;  }
                 else{  rr=0; ss=s;  }

                 fr=rr+solve(idx+k,0);   sc=ss+solve(idx+k,1);
                 rs=max(fr,sc);  dp[idx][sta]=rs;  return dp[idx][sta];

             }


        }



    }



}

int main()
{


    long long res=0,ans,i,j,a,b;
    scanf("%lld %lld",&n,&k);
    scanf("%lld %lld %lld",&r,&s,&p);

    cin>>str;


    memset(dp,-1,sizeof dp);

    for(i=1;i<=k;i++)
    {
        ans=solve(i,0);  res=res+ans;
    }


    printf("%lld\n",res);

    return 0;
}





Measured memory_bytes: 10868
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<int> vec(n, 0);
	for(int i = 0; i < n; ++i){
		cin>>vec[i];
	}
	int res = 0;
	for(int i = 1; i < n - 1; ++i){
		int a = vec[i - 1];
		int b = vec[i];
		int c = vec[i + 1];
		if(b > a && b < c){
			res++;
		}
		else if(b > c && b < a){
			res++;
		}
			   
	}
	cout<<res<<endl;	
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"strconv"
)

type key struct {
	Head rune
	Tail rune
}

func perm(n, k int) int {
	ans := 1
	if k > 0 && k <= n {
		for i := 0; i < k; i++ {
			ans *= n - i
		}
	} else if k > n {
		ans = 0
	}
	return ans
}

func main() {
	var n int
	fmt.Scan(&n)

	mh := make(map[key][]int)
	mt := make(map[key][]int)
	ms := make(map[key][]int)
	for i := 1; i <= n; i++ {
		s := strconv.Itoa(i)
		head := rune(s[0]) - '0'
		tail := rune(s[len(s)-1]) - '0'
		if head == 0 || tail == 0 {
			continue
		}
		if head < tail {
			k := key{head, tail}
			mh[k] = append(mh[k], i)
		} else if head > tail {
			k := key{tail, head}
			mt[k] = append(mt[k], i)
		} else {
			k := key{head, tail}
			ms[k] = append(ms[k], i)
		}
	}

	ans := 0
	for _, v := range ms {
		ans += perm(len(v), 1)
		ans += perm(len(v), 2)
	}
	for k := range mh {
		if _, ok := mt[k]; ok {
			ans += len(mh[k]) * len(mt[k]) * 2
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

const int NOUSE = 1001001001;

struct UnionFind{
	vector<int> d;
	UnionFind(int n) : d(n, -1){}
	int find(int x){
		if(d.at(x) < 0) return x;
		return d.at(x) = find(d.at(x));
	}
	bool unite(int x, int y){
		x = find(x); y = find(y);
		if(x == y) return false;
		if(d.at(x) > d.at(y)) swap(x, y);
		d.at(x) += d.at(y);
		d.at(y)= x;
		return true;
	}
	bool same(int x, int y) { return find(x) == find(y); }
	int size(int x) { return -d.at(find(x)); }
};

int main(){
	int n, m;
	cin >> n >> m;
	UnionFind uf(n);
	vector<vector<pair<int, int>>> gr(n, vector<pair<int, int>>());
	rep(i, m){
		int l, r, d;
		cin >> l >> r >> d;
		l--; r--;
		gr.at(l).push_back(make_pair(r, d));
		gr.at(r).push_back(make_pair(l, -d));
		uf.unite(l, r);
	}

	vector<int> d(n, NOUSE);
	rep(i, n){
		if(uf.d.at(i) < 0){
			queue<pair<int, int>> q;
			d.at(i) = 0;
			q.push(make_pair(i, 0));
			while(!q.empty()){
				auto frq = q.front(); q.pop();
				int now = frq.first, cost = frq.second;
				for(auto p : gr.at(now)){
					if(d.at(p.first) == NOUSE){
						d.at(p.first) = cost + p.second;
						q.push(make_pair(p.first, cost + p.second));
					}else{
						if(d.at(p.first) != cost + p.second){
							cout << "No" << endl;
							return 0;
						}
					}
				}
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 9972
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    int n;
    cin >> n;
    long long int a, b;
    long long int res = 0;
    vector<long long int> v;
    int c = 0;
    for (int i = 0; i < n; i++) {
        cin >> a >> b;
        res += a + b;
        if (a < b) {
        } else {
            c++;
            if (a > b) v.push_back(b);
        }
    }
    sort(v.begin(), v.end());
    if (c == n) {
        cout << 0 << endl;
    } else {
        cout << res / 2 - v[0] << endl;
    }
}









Measured memory_bytes: 3716
N  = int(input())
count = [0] * 100001
a = list(map(int, input().split()))

for i in range(N):
    if a[i] == 0:
        count[a[i]] += 1
        count[a[i]+1] += 1
    else:
        count[a[i]-1] += 1
        count[a[i]] += 1
        count[a[i]+1] += 1

ans = max(count)
print(ans)

Measured memory_bytes: 14732
#include<cstdio>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;

typedef long long ll;

ll digitsofnum(ll n){
    int digits=0;
    while(n){
        n/=10;
        digits++;
    }
    return digits;
}

int main(){
    ll n;
    scanf("%lld",&n);
    ll a=sqrt(n);
    ll ans=1e11;
    for(ll i=1;i<=a;i++){
        if(n%i==0){
            ll tmp=n/i;
            ll f=max(digitsofnum(tmp),digitsofnum(i));
            ans=min(ans,f);
        }
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 128
/*3.3 hightierra*/
#include <stdio.h>
#include <math.h>
 
int main(void){
    int N,K; //変数の定義
    scanf("%d %d",&N,&K); //入力
 
    int exp = 1; //指数を定義
 
    /*K^(exp-1)<=N<K^expのとき、NはK進法でexp桁*/
    while(pow((double)K,(double)exp)<=N){
      	exp++;
    }
    printf("%d\n",exp);
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
  	int n;
  	cin>>n;
  	vint a(n);
	rep(i,n){
      	cin>>a[i];
    }
  	sort(all(a));
  	rep(i,n){
      cout<<a[i];
      if(i!=n-1){
        cout<<' ';
      }
      else{
        cout<<'\n';
      }
    }
    return(0);
}


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

int main(){
    int n;
    scanf("%d", &n);
    
    vector<int> a(n), b(n);
    for(int i = 0; i < n; i++){
        scanf("%d", &a[i]);
        b[i] = a[i];
    }

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

    int cnt = 0;
    for(int i = 0; i < n; i++)  cnt += (a[i] != b[i]);

    int q;
    scanf("%d", &q);

    int x[q], y[q];
    for(int i = 0; i < q; i++){
        scanf("%d %d", x+i, y+i);
        x[i]--, y[i]--;
    }

    int ans;
    for(ans = 0; cnt != 0 && ans < q; ans++){
        if(a[x[ans]] == a[y[ans]])  continue;

        if(a[x[ans]] == b[x[ans]])  cnt++;
        else if(a[y[ans]] == b[x[ans]]) cnt--;

        if(a[y[ans]] == b[y[ans]])  cnt++;
        else if(a[x[ans]] == b[y[ans]]) cnt--;
        
        swap(a[x[ans]], a[y[ans]]);
    }

    if(cnt) cout << -1 << endl;
    else    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 7648