akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_imports)]
use itertools::Itertools;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }
    if a.iter().all(|a| a % 2 == 0) {
        println!("second");
    } else {
        println!("first");
    }
}


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

using namespace std;

int main() {
  long h;
  cin >> h;

  long sum = 0;
  long cnt = 1;
  while (h > 1) {
    h /= 2;
    sum += cnt;
    cnt *= 2;
  }
  sum += cnt;
  cout << sum << endl;
}



Measured memory_bytes: 256
n, a, b = map(int, input().split())

s = 0
ans = 0

for x in range(1, n+1):
    num = str(x)
    length = len(num)
    for y in range(0, length):
        s += int(num[y])
    if a <= s and s <= b:
        ans += x
    s = 0

print(ans)


Measured memory_bytes: 3060
#include<stdio.h>

void trace(int A[], int N) {
  int i;
  for (i=0; i<N; i++) {
    if (i>0) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

void insertionSort(int A[], int N) {
  int j, i, v;
  for (i=1; i<N; i++) {
    v = A[i];
    j = i - 1;
    while (j>=0 && A[j]>v) {
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    trace(A, N);
  }
}

int main() {
  int N, i, j;
  int A[100];

  scanf("%d", &N);
  for (i=0; i<N; i++) scanf("%d", &A[i]);

  trace(A, N);
  insertionSort(A, N);

  return 0;
}



Measured memory_bytes: 2100
#include<stdio.h>
int main() {
	int n;
	scanf("%d", &n);
	int a[100];
	int i, j, k;
	j = 0;
	k = 0;
	for (i = 0;i < n;i++) {
		scanf("%d", &a[i]);
	}
	for (i = 0;i < n;i++) {
		if (a[i] % 2 == 0) {
			j = j + 1;
			if (a[i] % 3 == 0||a[i]%5 == 0) {
				k = k + 1;
			}
		}
	}
	if (j == k) {
		printf("APPROVED");
	}
	else {
		printf("DENIED");
	}
	return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
int N;
int A[200000];
long long dp[3][200000+1];
int main(){
  int i, k;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  for(k=(0);k<(3);k++){
    int i;
    for(i=(0);i<(N+1);i++){
      dp[k][i] = -4611686016279904256LL;
    }
  }
  for(i=(0);i<(N);i++){
    for(k=(1);k<(3);k++){
      chmax(dp[k][i+1], dp[k-1][i]);
    }
    for(k=(0);k<(3);k++){
      if(i>0){
        chmax(dp[k][i+1], dp[k][i-1]+ A[i]);
      }
      else{
        chmax(dp[k][i+1], -4611686016279904256LL+ A[i]);
      }
    }
    if(i<3){
      chmax(dp[i][i+1], A[i]);
    }
  }
  if(N%2==0){
    wt_L(dp[1][N]);
    wt_L('\n');
  }
  else{
    wt_L(dp[2][N]);
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20200412-1

// --- original code ---
// int N, A[2d5];
// 
// ll dp[3][2d5+1];
// {
//   rd(N,A(N));
//   rep(k,3) rep(i,N+1) dp[k][i] = -ll_inf;
//   rep(i,N){
//     rep(k,1,3) dp[k][i+1] >?= dp[k-1][i];
//     rep(k,3) dp[k][i+1] >?= if[i>0, dp[k][i-1], -ll_inf] + A[i];
//     if(i<3) dp[i][i+1] >?= A[i];
//   }
//   wt(if[N%2==0, dp[1][N], dp[2][N]]);
// }


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

#pragma GCC optimize("O3")

using namespace std;

#define all(x) (x).begin(), (x).end()

typedef long long ll;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;

int main() {
    int n;
    int k;
    cin >> n >> k;
	int ans = 0;
	while(n > 0) {
		n /= k;
		++ans;
	}
	cout << ans;
    return 0;
}


Measured memory_bytes: 3576
/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
using namespace std;
#define ll       long long
#define ull       unsigned long long
#define  si(x)   scanf("%d", &x)
#define  sll(x)   scanf("%lld", &x)
#define  sd(x)   scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)
#define MAX       100000
#define maxn 	  200002
#define pb 		  push_back
#define mk 		  make_pair
#define endl	  "\n"
#define INF 	  1000000000
#define MOD		  1000000007



int main ()
{
		ios::sync_with_stdio(0);
		cin.tie(0);
		//CODE TONOY
	    string s;
	    cin >> s;
	    int ans = 753;
	    for (int i=0 ; i<(int)s.length()-2 ; i++)
	    {
			string t = s.substr(i,3);
			int x = 0;
			for (int j=0 ; j<3 ; j++)
			{
				x*=10;
				x+=t.at(j)-'0';
			}
			ans = min(ans,abs(753-x));
		}
		cout << ans << endl;
		return 0;
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e8;
const ll INF = 1e16;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    ll x;
    cin >> x;
    ll ans = 0;
    ans += 1000*(x/500);
    x %= 500;
    ans += 5*(x/5);
    cout << ans << endl;
}

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

int main() {
  for (int i = 0; ; i ++) {
    int a, b;
    char op;
    cin >> a >> op >> b;
    if (op == '?') return 0;
    else if (op == '+') cout << a + b << endl;
    else if (op == '-') cout << a - b << endl;
    else if (op == '*') cout << a * b << endl;
    else cout << a / b << endl;
  }
}



Measured memory_bytes: 3024
class F:
    def __init__(self, x):
        self.bit = x
        for i in range(len(x)):
            j = i | (i + 1)
            if j < len(x):
                x[j] += x[i]
    def update(self, idx, x):
        while idx < len(self.bit):
            self.bit[idx] += x
            idx |= idx + 1
    def query(self, end):
        x = 0
        while end:
            x += self.bit[end - 1]
            end &= end - 1
        return x
    def findkth(self, k):
        idx = -1
        for d in reversed(range(len(self.bit).bit_length())):
            right_idx = idx + (1 << d)
            if right_idx < len(self.bit) and k >= self.bit[right_idx]:
                idx = right_idx
                k -= self.bit[idx]
        return idx + 1
import sys
z=sys.stdin.readline
y=lambda:map(int,z().split())
n,q=y()
v=F([0]*(n-2))
h=F([0]*(n-2))
w=j=n-2
s=0
for _ in range(q):
    a,b=y()
    if a<2:
        if b-2<w:h.update(n-2-j,w-b+2);w=b-2
        s+=n-2-v.query(n-b)
    else:
        if b-2<j:v.update(n-2-w,j-b+2);j=b-2
        s+=n-2-h.query(n-b)
print((n-2)*(n-2)-s)

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

int main(){
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  int x[N], y[M];
  bool can = true;
  int xmax = X;
  for(int i = 0; i < N; i++){
    cin >> x[i];
    xmax = max(xmax, x[i]);
  }
  int ymin = Y;
  for(int i = 0; i < M; i++){
    cin >> y[i];
    ymin = min(ymin, y[i]);
  }
  if(xmax >= ymin) can = false;
  cout << (can? "No War" : "War") << endl;
  return 0;
}


Measured memory_bytes: 256
S,N,A,K,i,T,U;
main()
{
	scanf("%d",&N);
	for(i=0;i<N;i++)
	{
		scanf("%d%d",&A,&K);
		while(A>K)
		{
			T=A/K+1;
			U=A%K%T;
			if(U==0)break;
			A=A/K*K-T+U;
		}
		S^=A/K;
	}
	puts(S?"Takahashi":"Aoki");
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <bitset>
#include <stack>
#include <deque>

using namespace std;

int main(){
    int A, B;
    int result;
    cin >> A >> B;
    result = B - A;
    if(B % A == 0){
        result = A + B;
    }
    cout << result << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
int a,b,c,d,e,f;
scanf("%d %d %d",&a,&b,&c);
if(a<b){
d=a;
e=b;
}
else{
d=b;
e=a;
}
if(e<c)
f=c;
else{
f=e;
e=c;
}
if(d>e){
a=d;
d=e;
e=a;
}
printf("%d %d %d\n",d,e,f);
return 0;
}

Measured memory_bytes: 596
#!/usr/bin/env python3

import sys
# import math
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
from fractions import gcd                    # for Python 3.4


def main():
    mod = 1000000007                  # 10^9+7
    inf = float('inf')
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    a, b, c, d = mi()
    m = c * d // gcd(c, d)
    one_to_a_minus_1 = (a-1) - ((a-1)//c + (a-1)//d - (a-1)//m)
    one_to_b = b - (b//c + b//d - b//m)
    print(one_to_b - one_to_a_minus_1)


if __name__ == "__main__":
    main()

Measured memory_bytes: 5424
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

void out(int n){
    cout << n << endl;
}

int in(){
    string s;
    cin >> s;
    int res = -1;
    if(s == "Male") res = 0;
    if(s == "Female") res = 1;
    if(s == "Vacant") res = 2;
    return res;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    out(0);
    int t = in();
    if(t == 2){
        return 0;
    }
    int l = 0, r = n;
    rep(i, 0, 18){
        int mid = (l + r) / 2;
        if(mid % 2) mid++;
        out(mid);
        int tmp = in();
        if(tmp == 2){
            return 0;
        }
        if(tmp != t){
            r = mid;
        }else{
            l = mid;
        }
    }
    out(l + 1);
    in();
}

Measured memory_bytes: 852
#include <stdio.h>
int a, b;
int main()
{
    scanf("%d %d", &a, &b);
    while (!(a == 0 && b == 0))
    {
        if (a > b)
        {
            printf("%d %d\n", b, a);
        }
        else
        {
            printf("%d %d\n", a, b);
        }
        scanf("%d %d", &a, &b);
    }
}



Measured memory_bytes: 2028
import math
A, B, H, M = map(int, input().split())
p = 0
o = 0
for i in range(1, H+1):
    p += 30
for q in range(1, M+1):
    o += 6
y = M * 0.5
p = p + y
H = abs(o - p)
total = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(math.radians(H)))
print(total)


Measured memory_bytes: 9492
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
	
		Scanner scan = new Scanner(System.in);
		int i , j , n , m;
		n = scan.nextInt();
		m = scan.nextInt();
		long value = 1;
		for (i = 0;i < m;i ++) {
			value *= 2;
		}
		value *= ((long) (n - m) * 100 + (long) m * 1900);
		System.out.println(value);
		
	}
		
}










Measured memory_bytes: 21844
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define int long long int
constexpr int INF = std::numeric_limits<int>::max();
constexpr int NINF = std::numeric_limits<int>::min();
using namespace std;

vector<int> tasks[100000 + 1];

void solve() {
  int N, M;
  cin >> N >> M;

  while (N--) {
    int a, b;
    cin >> a >> b;
    tasks[a].push_back(b);
  }

  priority_queue<int> q;
  int ans = 0;
  for (int i = 1; i <= M; i++) {
    for (int b : tasks[i]) {
      q.push(b);
    }

    if (!q.empty()) {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
}

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


Measured memory_bytes: 5760
import sys
import  math
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

S=list(ns())
T=list(ns())
ans=0
for i in range(len(S)):
    if(S[i]!=T[i]):
        ans+=1

print(ans)

    


Measured memory_bytes: 13420
# ランレングス圧縮
def getRunLengthEncoding(Ss):
    anss = []
    Ss += '$'
    SPrev = Ss[0]
    num = 1
    for S in Ss[1:]:
        if S == SPrev:
            num += 1
        else:
            anss.append((SPrev, num))
            SPrev = S
            num = 1
    return anss

N, K = map(int, input().split())
R, S, P = map(int, input().split())
Ts = input()

ans = 0
for i in range(K):
    As = Ts[i::K]
    RLE = getRunLengthEncoding(As)
    for c, num in RLE:
        m = (num+1)//2
        if c == 'r':
            ans += P*m
        elif c == 's':
            ans += R*m
        else:
            ans += S*m

print(ans)


Measured memory_bytes: 10544
#include <string>
#include <vector>
#include <iostream>
using namespace std;
const int mod = 1000000007;
int n, a, b; string s[1009]; vector<int> G[1009];
int solve(int pos, int pre) {
	vector<int> res;
	for (int i : G[pos]) {
		if (i == pre) continue;
		res.push_back(solve(i, pos));
	}
	int ret = 0;
	if (s[pos][0] == 'A') for (int i : res) ret = (ret + i) % mod;
	else if(s[pos][0] == 'R') {
		ret = 1;
		for (int i : res) ret = 1LL * ret * (i + 1) % mod;
		ret = (ret + mod - 1) % mod;
	}
	else {
		ret = 1;
		for (int i : res) ret = 1LL * ret * i % mod;
	}
	if (s[pos].size() == 2) ret++;
	return ret;
}
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) cin >> s[i];
	for (int i = 0; i < n - 1; i++) {
		cin >> a >> b; a--, b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	int ret = solve(0, -1);
	cout << ret << endl;
	return 0;
}

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

N,M = map(int, input().split())
abM = [list(map(int, input().split())) for i in range(M)]

abM.sort(key = lambda x: (x[0], x[1]))

tmp_e = abM[0][1]
cnt = 1

for i in range(1,M):
    if tmp_e > abM[i][0]:
        tmp_e = min(abM[i][1], tmp_e)
    else:
        cnt += 1
        tmp_e = abM[i][1]
print(cnt)

Measured memory_bytes: 35580
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')

sys.setrecursionlimit(10 ** 5)


def main():
    x = int(readline())

    if x >= 30:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 61660
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int[] h = new int[N];
		for (int i = 0; i < N; i++) {
			h[i] = in.nextInt();
		}
		int ans = 0;
		while (true) {
			int left = -1;
			for (int i = 0; i < N; i++) {
				if (h[i] != 0) {
					left = i;
					break;
				}
			}
			if (left == -1) {
				break;
			}
			int i = left;
			while (i < N) {
				if (h[i] == 0)
					++i;
				else {
					++ans;
					while (i < N && h[i] > 0) {
						--h[i];
						++i;
					}
				}
			}
		}
		System.out.println(ans);
		in.close();
	}
}

Measured memory_bytes: 22996
import sys
import bisect
n, k = [int(i) for i in sys.stdin.readline().split()]
x_ls = [int(i) for i in sys.stdin.readline().split()]
zero_pos = bisect.bisect_left(x_ls, 0)
x_ls = x_ls[:zero_pos] + [0] + x_ls[zero_pos:]
len_x = len(x_ls)
INF = 10**18
best = INF
for left in range(1+min(k, zero_pos)):
    right = k - left
    if zero_pos + right >= len_x:
        continue
    _min = x_ls[zero_pos - left]
    _max = x_ls[zero_pos + right]
    res = abs(_min) + abs(_max) + min(abs(_min), abs(_max))
    best = min(res, best)
print(best)

Measured memory_bytes: 58736
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
const ll MOD=1000000007,INF=1e18;

#define int long long

int h,w,x,y,amari=0,cnt4=0,cnt2=0;
int a[100];
char c;
bool can;

signed main(){
   cin>>h>>w;
   int hw=h*w;
   rep(i,0,hw){
       cin>>c;
       a[c-'a']++;
       if(a[c-'a']==4){
           a[c-'a']-=4;
           cnt4++;
       }
   }
   rep(i,0,27){
       if(a[i]>=2){
           a[i]-=2;
           cnt2++;
       }
   }
   x=(h/2)*(w/2);
   y=hw-x*4;
   can=true;
   if(x>cnt4)can=false;
   else if((y/2)>(cnt2+max((cnt4-x)*2,0ll)))can=false;
   can?puts("Yes"):puts("No");
   
   
   
   
   return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;
typedef tuple<ll, ll, ll> tuplll;

const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;
const int MOD = 1000000007;

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 (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }



int n;
ll V, w;
const ll inf = 1LL << 60;
const ll maxV = 1000;
vll vw, vv;
vvll dp;

void init()
{
	cin >> n >> w;
	vw.resize(n); vv.resize(n);
	V = n * maxV;

	REP(i, n) cin >> vw[i] >> vv[i];

	dp.resize(n + 1, vll(V + 1, inf));
	dp[0][0] = 0;
}

void print(const vvll& v)
{
	REP(i, SZ(v))
	{
		REP(j, SZ(v[i]))
			cout << v[i][j] << " ";
		cout << endl;
	}
}

int main()
{
	init();

	REP(i, n)
		REPC(j, V)
	{
		chmin(dp[i + 1][j], dp[i][j]);
		if (j + vv[i] <= V)
			chmin(dp[i + 1][j + vv[i]], dp[i][j] + vw[i]);
	}

	int ans = 0;
	REPC(j, V)
		if (dp[n][j] <= w)
			ans = j;

	cout << ans << endl;

}


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

#define vi vector<int>
#define pb push_back

bool start[200010] = {}, goal[200010] = {};
int main()
{
    string s;
    cin >> s;
    cout << s[0] << s.size() - 2 << s[s.size() - 1] << endl;
    return 0;
}

Measured memory_bytes: 256
a, b, c, x = [int(input()) for _ in range(4)]
cnt = 0
for i in range(a + 1):
    for j in range(b + 1):
        left = x - 500 * i - 100 * j
        if left % 50 == 0 and 0 <= left // 50 <= c:
            cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include<stdio.h>

#define MAX 101

int size[MAX],p[MAX],roll[MAX][MAX];
void GVE(int c,int v);

int main(){
  int i,j,n,m;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    p[i]=10000;
    for(j=1;j<=n;j++){
      roll[i][j]=0;
    }
  }
  for(i=1;i<=n;i++){
    scanf("%d",&m);
    scanf("%d",&size[m]);
    for(j=1;j<=size[m];j++){
      scanf("%d",&roll[m][j]);
    }
  }
  GVE(1,0);
  for(i=1;i<=n;i++){
    if(p[i]==10000){
      p[i]=-1;
    }
    printf("%d %d\n",i,p[i]);
  }
  return 0;
}

void GVE(int c,int v){
  int i;
  p[c]=v;
  for (i=1;i<=size[c];i++){
    if (p[roll[c][i]]>v){
      GVE(roll[c][i],v+1);
    }
  }
}




Measured memory_bytes: 2096
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
  int K, A, B;

  scanf("%d", &K);
  scanf("%d %d", &A, &B);

  for (int i = A; i <= B; i++)
  {
    if (i % K == 0)
    {
      printf("OK");
      return 0;
    }
  }

  printf("NG");
  return 0;
}

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

using namespace std;

typedef long long ll;
struct dat{
	string s;
	int p, id;
};

bool comp(dat lhs, dat rhs){
	if(lhs.s != rhs.s){
		return lhs.s < rhs.s;
	}

	return lhs.p >= rhs.p;
}

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

	int n;
	cin >> n;

	vector<dat> v(n);
	rep(i, n){
		string s;
		int p;
		cin >> s >> p;

		v[i].s = s;
		v[i].p = p;
		v[i].id = i + 1;
	}

	sort(v.begin(), v.end(), comp);
	rep(i, n){
		cout << v[i].id << endl;
	}

}


Measured memory_bytes: 256
n = int(input())

adj = [[] for i in range(n)]
ans = [0 for i in range(n)]
anum = 0
depth = [0 for i in range(n)]

for i in range(n-1):
    aa,ba = map(int,input().split())
    adj[aa-1].append(ba-1)
    adj[ba-1].append(aa-1)

c = list(map(int,input().split()))
c = sorted(c)

sh = []

def delete(edges):
    sh.append(edges)

    for i in range(len(edges)):
        la = adj[edges[i]][0]
        adj[la].remove(edges[i])
        if len(adj[la]) == 0:
            sh.append([la])
        adj[edges[i]] = []
    return

def search(adj):
    k = []
    for i in range(len(adj)):
        if len(adj[i]) == 1:
            k.append(i)
    return k

ed = search(adj)

while len(ed):
    delete(ed)
    ed = search(adj)
    if len(ed) == 1:
        sh.append(ed)
        break
    if len(ed) == 2:
        if adj[ed[0]] and adj[ed[0]][0] == ed[1]:
            sh.append(ed)
            break

sug = []
for i in range(len(sh)):
    for m in sh[i]:
        sug.append(m)


for i in range(len(sug)):
    ans[sug[i]] = c[i]



for i in range(n-1):
    anum += c[i]
print(anum)

las = ""
for num in ans:
    las += str(num)+ " "
print(las)


Measured memory_bytes: 144004
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define deb(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;

typedef long long int ll;
typedef string str;

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

void fast(){
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main ()
{
	ll t,n,m,k,i,a,b,j;
	str s;
	cin >> n >> k >> m;
	if(n<0)
		n*=(-1);
	i=n/m;
	b=n%m;
	if(i>=k)
		a=n-k*m;
	else
	{
		k-=i;
		if(k%2)
			a=m-b;
		else
			a=b;
	}
	cout << a << "\n";
}

Measured memory_bytes: 3624
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const ll MOD = 1000000007;
// const int INF = 2000000000;

int N, M;
// vector<int> L, R;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M;
  vector<int> sum(N + 1, 0);
  for (int i = 0; i < M; i++) {
    int li, ri;
    cin >> li >> ri;
    li--;
    ri--;
    sum[li]++;
    sum[ri + 1]--;
  }

  vector<int> cum(N + 1, 0);
  cum[0] = sum[0];
  for (int i = 1; i <= N; i++) {
    cum[i] = cum[i - 1] + sum[i];
  }

  int ans = 0;
  for (int i = 0; i <= N; i++) {
    if (cum[i] == M) {
      ans++;
    }
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <algorithm>
#include <ctime>
#include <vector>
#include <set>
#include <queue>
using namespace std;
typedef long long ll;

#define PI 3.14159265358979323846264338327950L

string res;

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

    string s,t;
    cin >> s >> t;
    res = "No";
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());

    if(s<t){
        res = "Yes";
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3592
import java.util.*;
class Main
{
    public static void main(String arg[])
    {
        int count=0,s,n1;
        Scanner sc = new Scanner(System.in);
        try {
            int n = sc.nextInt();
            int b= sc.nextInt();
            if(b>0&&b<=10)
            {
                while(n>0)
                {
                    s=n%b;
                    n=n/b;
                    count++;
                }
            }
        } catch(Exception e) {
        } 
        System.out.println(count);
    }
}

Measured memory_bytes: 21972
import java.util.*;
public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int m = sc.nextInt();
                m = sc.nextInt();
                int x = sc.nextInt();
                int[] a = new int[m];
                for(int i = 0 ; i < m ; i++){
                        a[i] = sc.nextInt();
                }
                sc.close();
                int yono = 0;
                int pct = 0;
                for(int i = 0 ; i < m ; i++){
                        if(a[i] < x){
                                yono++;
                        }else{
                                pct++;
                        }
                }
                System.out.println(Math.min(yono , pct));
        }
}
//鶏になれ


Measured memory_bytes: 35688
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;
typedef long long ll;

int main(){
	ll a, b, c, d;
	scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
	ll r1= a * c, r2= a * d, r3 = b * c, r4 = b * d;
	ll res = max(max(max(r1, r2), r3), r4);
	printf("%lld\n", res);
	return 0;
} 

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

const int N = 1100;

char pat[N][N];

int main() {
	
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	int n, m, d; cin >> n >> m >> d;
	if (d & 1) {
		for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) {
			if ((i + j) & 1) pat[i][j] = 'R';
			else pat[i][j] = 'G';
		}
	} else {
		assert(d % 2 == 0);
		
		for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) {
			if (i % (d + d) < d) {
				if (i % d < d / 2) {
					if (d / 2 - 1 - i % (d / 2) < j % d && j % d <= d / 2 + i % (d / 2)) {
						if (j % (d + d) < d) pat[i][j] = 'R';
						else pat[i][j] = 'B';
					}
					else {
						if (j % (d + d) < d / 2 || j % (d + d) >= d + d / 2) pat[i][j] = 'G';
						else pat[i][j] = 'Y';
					}
				} else {
					if ((i % d - d / 2) < j % d && j % d <= d - 1 - (i % d - d / 2)) {
						if (j % (d + d) < d) pat[i][j] = 'R';
						else pat[i][j] = 'B';
					}
					else {
						if (j % (d + d) < d / 2 || j % (d + d) >= d + d / 2) pat[i][j] = 'Y';
						else pat[i][j] = 'G';
					}
				}
			} else {
				if (i % d < d / 2) {
					if (d / 2 - 1 - i % (d / 2) < j % d && j % d <= d / 2 + i % (d / 2)) {
						if (j % (d + d) < d) pat[i][j] = 'B';
						else pat[i][j] = 'R';
					}
					else {
						if (j % (d + d) < d / 2 || j % (d + d) >= d + d / 2) pat[i][j] = 'Y';
						else pat[i][j] = 'G';
					}
				} else {
					if ((i % d - d / 2) < j % d && j % d <= d - 1 - (i % d - d / 2)) {
						if (j % (d + d) < d) pat[i][j] = 'B';
						else pat[i][j] = 'R';
					}
					else {
						if (j % (d + d) < d / 2 || j % (d + d) >= d + d / 2) pat[i][j] = 'G';
						else pat[i][j] = 'Y';
					}
				}
			}
		}
	}
	
	auto check = [&]() {
		for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) {
			for (int ii = 0; ii < n; ii++) for (int jj = 0; jj < m; jj++) {
				if (abs(i - ii) + abs(j - jj) == d) {
					assert(pat[i][j] != pat[ii][jj]);
				}
			}
		}
	};
	
//	check();
	
	for (int i = 0; i < n; i++, cout << "\n") for (int j = 0; j < m; j++) cout << pat[i][j];
	
	return 0;
}


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

int main() {
  
  string S;
  cin >> S;
  
  int n=0;
  
  for (int i = 0; i < 4; i++) {
    if (S.at(i) == '+') {
      n++;
    }
    else {
      n--;
    }
  }
  
  cout << n << endl;

return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define ld long double
#define vi vector<vector<ll> >
using namespace std;
const int MOD=1000000007;
const int MOD2=15000007;
const ll MAX=9187201950435737471;
const int N=100005;
const int INF=1e17;
const long double PI=acos(-1);



void solve(int T){
    ll m,n;
    cin>>m>>n;
    ll sum=0;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        sum+=x;
    }
    if(sum>=m){
        cout<<"Yes\n";
    }
    else {
        cout<<"No\n";
    }
}

int main() {
    fastio
    int T=1;
    //cin>>T;
    for(int i=1;i<=T;i++){
        solve(i);
        //if(i<T)cout<<"\n";
    }
    return 0;
}




Measured memory_bytes: 3648
function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0].split(" ")[0]);
  var M = parseInt(input[0].split(" ")[1]);
  var A=input[1].split(" ").map(i => [1,parseInt(i)]);
  input.shift();
  input.shift();
  var BC=input.map(i => i.split(" ").map(i => parseInt(i)));
  BC.pop();
  A.push(...BC);
  A.sort(function(a,b){
    if (a[1] < b[1]) return 1;
    if (a[1] > b[1]) return -1;
    return 0;
  })
  var ans=0;
  var cnt=0;
  for(var i=0;i<N;i++){
    if(cnt+A[i][0]<=N){
      ans+=A[i][1]*A[i][0];
      cnt+=A[i][0];
    }else if(cnt+1<=N){
      ans+=A[i][1]*(N-cnt);
      cnt=N;
    }else{
      break;
    }
  }


  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 69760
k, a, b = map(int, input().split())

cookie = 0

if a + 2 >= b or k + 1 < a:
    cookie = k + 1
else:
    action = int((k-(a-1))/2)
    cookie = a
    if action >= 1:
        cookie += action*(b-a)
    if (k-(a-1))/2 - action > 0:
        cookie += 1

print('{}'.format(cookie))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
const ll mod = 1000000007;
const ll INF = 9223372036854775807;
#define Sort(a) sort(a.begin(), a.end())
#define Bsort(a) sort(a.begin(), a.end(), greater<ll>())
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  ll n;
  cin >> n;
  ld ave = 0;
  vector<ll> a(n);
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    ave += a[i];
  }
  ave /= n;
  ll t = llround(ave);
  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    ans += (a[i]-t)*(a[i]-t);
  }
  cout << ans << '\n';
}

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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define chmax(s, t) s=max(s,t);
#define chmin(s, t) s=min(s,t); 

#define deg2rad(deg) (((deg)/360)*2*M_PI)
#define rad2deg(rad) (((rad)/2/M_PI)*360)

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

/*素数判定*/
bool is_prime(ll n){
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}

/*約数列挙*/
vll enum_divisors(ll n){
    vll l;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            l.push_back(i);
            if(n/i != i) l.push_back(n/i);
        }
    }
   sort(all(l));
   return l;
}

/*素因数分解*/
vector<P> prime_factorize(ll n){
    vector<P> l;
    for(ll i=2;i*i<=n;i++){
        if(n%i!=0) continue;
        ll e = 0;
        while(n%i==0){
            e++;
            n /= i;
        }
        l.push_back({i, e});
    }
    if(n!=1) l.push_back({n, 1});
    return l;
}

/*最小公倍数*/
ll lcm(ll a, ll b){
    return a*b/__gcd(a,b);
}

/*最大公約数*/
ll gcd(ll a, ll b){
    return __gcd(a,b);
}

/*組み合わせ(Combination)*/
const ll CMAX = 1010000;
const ll CMOD = 1e9+7;
ll fac[CMAX], finv[CMAX], inv[CMAX];
// テーブルを作る前処理
void combinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < CMAX; i++) {
		fac[i] = fac[i - 1] * i % CMOD;
		inv[i] = CMOD - inv[CMOD%i] * (CMOD / i) % CMOD;
		finv[i] = finv[i - 1] * inv[i] % CMOD;
	}
}
// 二項係数計算
ll comb(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % CMOD) % CMOD;
}

/*階乗*/
ll factorial(ll n){
    const ll FMOD = 1e9+7;
    ll ret = n;
    for(ll i=n-1;i>0;i--){
        ret*=i;
        ret%=FMOD;
    }
    return (ret?ret:1);
}


int main(){

    ll n; cin >> n;

    cout << (n>=30?"Yes":"No") << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;
int N;
string s;

void print_animal(vector<bool> is_sheep)
{
  rep(i, N)
  {
    if (is_sheep[i])
      cout << 'S';
    else
      cout << 'W';
  }
  cout << endl;
}

bool is_ok(vector<bool> is_sheep)
{
  rep(i, N - 1)
  {
    if (s[i + 1] == 'o' && is_sheep[i + 1])
      is_sheep.push_back(is_sheep[i]);
    else if (s[i + 1] == 'x' && is_sheep[i + 1])
      is_sheep.push_back(!is_sheep[i]);
    if (s[i + 1] == 'o' && !is_sheep[i + 1])
      is_sheep.push_back(!is_sheep[i]);
    if (s[i + 1] == 'x' && !is_sheep[i + 1])
      is_sheep.push_back(is_sheep[i]);
  }

  bool ok = true;
  rep(i, N)
  {
    int i_pre = (i + N - 1) % N;
    int i_next = (i + 1) % N;

    if ((is_sheep[i_pre] && is_sheep[i_next]) || (!is_sheep[i_pre] && !is_sheep[i_next]))
    {
      if (s[i] == 'o' && is_sheep[i])
        continue;
      else if (s[i] == 'x' && !is_sheep[i])
        continue;
    }
    else if ((!is_sheep[i_pre] && is_sheep[i_next]) || (is_sheep[i_pre] && !is_sheep[i_next]))
    {
      if (s[i] == 'o' && !is_sheep[i])
        continue;
      else if (s[i] == 'x' && is_sheep[i])
        continue;
    }

    ok = false;
    break;
  }

  if (ok)
    print_animal(is_sheep);

  return ok;
}

int main()
{
  cin >> N >> s;
  if (!is_ok({true, true}) && !is_ok({true, false}) && !is_ok({false, true}) && !is_ok({false, false}))
    cout << -1 << endl;

  return 0;
}

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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+9;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL my_pow(int x, int y){
	LL a=1;
	REP(i,y){
		a *= x;
		a %= MOD;
	}
	return a % MOD;
}
void Main()
{
	int x,y;
	cin >> x >> y;
	cout << 6-x-y << endl;

	return;
}

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

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

n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = list(input())

safe = [False] * n

result = [True] * n

for i in range(n-k):
    if t[i] == t[i+k] and (not safe[i]):
        result[i] = False
        safe[i+k] = True


points = {"r":p, "s":r, "p":s}

score = 0

for i in range(n):
    if result[i]:
        score += points[t[i]]

print(score)


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

using namespace std;

typedef long long ll;

#define PB push_back
#define MP make_pair
#define MOD 1e9+7
#define newline cout<<"\n"


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

    ll a,b,c,k;
    cin>>a>>b>>c>>k;

    int ans;

    if(k>a+b){
        int x = k-(a+b);
        ans = a-x;
    }
    else{
        if(k<=a){
            ans = k;
        }
        else{
            ans = a;
        }
    }

    cout<<ans<<endl;


    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define F first
#define S second
#define sq(x) (x)*(x)
using namespace std;
typedef long long LL;
typedef pair<LL, LL> pii;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;
const LL MOD = 1e9 + 7;
struct B {
    int w, s; LL v;
    bool operator < (const B &rhs) const {
        return w + s < rhs.w + rhs.s;
    }
};
void marmot0814() {
    int n; cin >> n;
    vector<B> arr(n);
    for (auto &p : arr)
        cin >> p.w >> p.s >> p.v;
    sort(arr.begin(), arr.end());
    vector<LL> dp(2e4 + 5, 0); dp[0] = 0;
    for (int i = 0 ; i < n ; i++)
        for (int w = arr[i].s ; w >= 0 ; w--)
            dp[w + arr[i].w] = max(dp[w + arr[i].w], dp[w] + arr[i].v);
    cout << *max_element(dp.begin(), dp.end()) << '\n';
}
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int t = 1, kase = 0; // cin >> t;
    while (t--) {
        // cout << "Case #" << ++kase << ":";
        marmot0814();
    }
}

Measured memory_bytes: 3676
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1

//{
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
#define hi cerr<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1
#define sysp system("pause")
#define PI acos(-1)
#define ins insert
#define aer(v) (v).erase((v).begin(),(v).end()) 
#define fh(x,v) for(auto x:v)

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

//}

int n,a[5];

main(){
	cin>>n;rep(i,5)cin>>a[i];
	int l=INT_MAX;rep(i,5)if(l>a[i])l=a[i];
	int ans=4+(n+(l-1))/l;
	dans;
}






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

int main()
{
  long x, k, d;
  cin >> x >> k >> d;
  if(k % 2 == 1){
    if(x > 0) x -= d;
    else x += d;
  }
  d *= 2;
  k /= 2;
  long l = abs(x) / d;
  long m=0;
  if(l > k){
    if(x < 0) m = abs(x + d * k);
    else m = abs(x - d * k);
  }else{
    if(x < 0) {
      if(abs(x + d * l) < abs(x + d * (l+1))) m = abs(x + d * l);
      else m = abs(x + d * (l+1));
    }else{
      if(abs(x - d * l) < abs(x - d * (l+1))) m = abs(x - d * l);
      else m = abs(x - d * (l+1));
    }
  }
  cout << m << endl;
}


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

class MainClass
{

    public static void Main(string[] args)
    {
        var L = (double)LnInt();
        var edge = L / 3;
        print(Pow(edge, 3));
    }


    
    public static void print(object obj) { Console.WriteLine(obj); }
    public static long Gcd(long a, long b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } }
    public static int Gcd(int a, int b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } }
    public static int[] LnInts() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new int[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = int.Parse(vs[i]); return ins; }
    public static int LnInt() { var vs = Console.ReadLine().Trim(); return int.Parse(vs); }
    public static long[] LnLngs() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new long[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = long.Parse(vs[i]); return ins; }
    public static long LnLng() { var vs = Console.ReadLine().Trim(); return long.Parse(vs); }
    public static string[] LnStrs() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); return vs; }
    public static string LnStr() { var vs = Console.ReadLine().Trim(); return vs; }
}



Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int w, a, b;
    cin >> w >> a >> b;
    put(max(0, max(b - a - w, a - b- w)))
    return 0;
}

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

#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define MP make_pair
#define PB push_back
#define PI 3.1415926535897932384626433832795
typedef long long ll;
#define MOD 998244353
ll gcd(ll a,ll b){if (b == 0)return a;return gcd(b, a % b);} 
vector< pair<int,int> >v;
#define cases int t;cin>>t;while(t--)

int main()
{
int x,y,z;cin>>x>>y>>z;
swap(x,y);
swap(x,z);
cout<<x<<" "<<y<<" "<<z<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fir first
#define sec second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 5;
const int M = 2e5 + 5;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = 1e-8;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
inline ull qpow(ull a, ull b, ull c)
{
    ull ans = 1;
    while (b)
    {
        if (b & 1)
            ans = ans * a % c;
        a = a * a % c;
        b >>= 1;
    }
    return ans;
}
bool cmp(pii a, pii b)
{
    return a.fir > b.fir;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x, y, a, b, c;
    ull ans = 0;
    cin >> x >> y >> a >> b >> c;
    vector<pii> app(a + b + c);
    for (int i = 0; i < a; i++)
    {
        cin >> app[i].fir;
        app[i].sec = 1;
    }
    for (int i = a; i < a + b; i++)
    {
        cin >> app[i].fir;
        app[i].sec = 2;
    }
    for (int i = a + b; i < a + b + c; i++)
    {
        cin >> app[i].fir;
        app[i].sec = 0;
    }
    sort(app.begin(), app.end(), cmp);
    int cnt_0 = 0, cnt_1 = 0, cnt_2 = 0;
    for (int i = 0; i < a + b + c; i++)
    {
        if (cnt_0 + cnt_1 + cnt_2 == x + y)
            break;
        if (cnt_1 == x && app[i].sec == 1)
            continue;
        if (cnt_2 == y && app[i].sec == 2)
            continue;
        ans += app[i].fir;
        if (app[i].sec == 1)
            cnt_1++;
        else if (app[i].sec == 2)
            cnt_2++;
        else
            cnt_0++;
    }
    cout << ans;
}

Measured memory_bytes: 2560