akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();

			Map<Integer, Integer[]> cakes = new HashMap<Integer, Integer[]>();
			int fw = sc.nextInt();
			int fd = sc.nextInt();
			if (n == 0 && fw == 0) {
				sc.close();
				break;
			}
			Integer[] first = { fw, fd };
			cakes.put(1, first);
			for (int i = 0; i < n; i++) {
				int p = sc.nextInt();
				int s = sc.nextInt();

				int w = cakes.get(p)[0];
				int d = cakes.get(p)[1];

				// 識別番号を付け直す
				for (int id = p + 1; id <= i + 1; id++) {
					// i回目のカット前には識別番号i+1までケーキがある
					// 1個ずつ下にずれる
					cakes.get(id - 1)[0] = cakes.get(id)[0];
					cakes.get(id - 1)[1] = cakes.get(id)[1];
				}

				s %= (w + d);

				int wa = w, da = d;
				int wb = w, db = d;
				if (s < w) {
					wa = s;
					wb = w - wa;
				} else {
					da = s - w;
					db = d - da;
				}

				cakes.get(i + 1)[0] = Math.min(wa, wb);
				cakes.get(i + 1)[1] = Math.min(da, db);

				// i回目のカットでは識別番号i+2のケーキが生まれる
				Integer[] newcake = { Math.max(wa, wb), Math.max(da, db) };
				cakes.put(i + 2, newcake);
			}

			ArrayList<Integer> list = new ArrayList<Integer>();
			for (int i = 1; i <= n + 1; i++) {
				int w = cakes.get(i)[0];
				int d = cakes.get(i)[1];
				list.add(w * d);
			}

			Collections.sort(list);
			for (int i = 0; i < list.size(); i++) {
				System.out.print(list.get(i));
				if (i != list.size() - 1) {
					System.out.print(" ");
				}
			}
			System.out.println();

		}
	}
}

Measured memory_bytes: 57972
#include<iostream>

void func_A(int N, int A, int B) {
	std::cout << (A*N > B ? B : A * N) << std::endl;
}

int main() {
	int N, A, B;
	std::cin >> N >> A >> B;
	func_A(N, A, B);
	return 0;
}

Measured memory_bytes: 256
// https://qiita.com/port-development/items/eea3a0a225be47db0fd4
#include<iostream>
#include<cmath>
using namespace std;

#define PI 2*acos(0.0)
#define DEGtoRAD(X) (X*PI)/180.0

int main(){
    double a, b, c, d;
    while(cin >> a >> b >> c >> d){
        if(a+b+c+d == -4)   break;
        a = DEGtoRAD(a);
        b = DEGtoRAD(b);
        c = DEGtoRAD(c);
        d = DEGtoRAD(d);
        double x = acos(sin(a)*sin(c) + cos(a)*cos(c)*cos(b-d));
        int ans = round(6378.1 * x);
        cout << ans << endl;
    }
    return 0;
}



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

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;

  ll remain = k;
  ll sum = 0;
  if (a >= remain) {
    cout << k << endl;
    return 0;
  } else {
    sum += a;
    remain -= a;
  }

  if (b >= remain) {
    cout << sum << endl;
    return 0;
  } else {
    remain -= b;
  }

  cout << sum - remain << endl;
}


Measured memory_bytes: 3500
import bisect
s = list(input())
t = list(input())

if len(set(t)-set(s)) > 0:
  print(-1)
  exit()

c = set(s)
dic = {}
for char in c:
  dic[char] = []

for i in range(len(s)):
  dic[s[i]] += [i]

last = -1
r = 0
for char in t:
  tmp = last
  idx = bisect.bisect_right(dic[char], last)
  if idx < len(dic[char]):
    last = dic[char][idx]

  if tmp == last:
    r += 1
    last = dic[char][0]

print(len(s)*r + last + 1)


Measured memory_bytes: 87984
#include <iostream>
#include <complex>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
const double EPS = 1e-5;
const double INF = 1e12;
const double PI = acos(-1);
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define X real()
#define Y imag()
typedef complex<double> P;
typedef vector<P> VP;

namespace std{
    bool operator < (const P& a, const P& b){
        return !EQ(a.X,b.X) ? a.X<b.X : a.Y+EPS<b.Y;
    }
    bool operator == (const P& a, const P& b){
        return abs(a-b) < EPS;
    }
}

double dot(P a, P b){
    return (conj(a)*b).X;
}
double cross(P a, P b){
    return (conj(a)*b).Y;
}

double getangle(P a, P b){
    return abs(arg(a/b));
}
double getarea(const VP &poly){
    double ret = 0;
    for (int i=0; i<(int)poly.size(); i++){ 
        ret += cross(poly[i], poly[(i+1)%poly.size()]);
    }
    return ret*0.5;
}

int main(){
    int n;
    while(cin >> n){
        VP p(n);
        for(int i=0; i<n; i++){
            double x,y;
            cin >> x >> y;
            p[i] = P(x, y);
        }
        if(p[0] == p.back()){
            p.pop_back();
            n--;
        }

        bool ng = false;
        double len = abs(p[1] -p[0]);
        for(int i=0; i<n; i++){
            double a = getangle(p[i] -p[(i+1)%n], p[(i+2)%n] -p[(i+1)%n]);
            a *= 5/PI;
            double l = abs(p[(i+1)%n] -p[i]);
            if(!EQ(len, l)) len = -1;
            if(!EQ(a, round(a)) || !EQ(l, round(l))){
                ng = true;
                break;
            }
        }
        if(len != -1 && n == 5) ng = true;
        if(ng){
            cout << -1 << " " << -1 << endl;
            continue;
        }

        double area = getarea(p);
        double thin = sin(PI/5);
        double thick = sin(2*PI/5);
        int a=-1, b=-1;
        for(int i=0; thin*i < area +EPS; i++){
            double rem = area -thin*i;
            double j = rem/thick;
            if(EQ(j, round(j))){
                a = i;
                b = round(j) +EPS;
                break;
            }
        }
        cout << a << " " << b << endl;
    }
    return 0;
}


Measured memory_bytes: 3408
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		if (s.length() == 2) {
			System.out.println(s);
			return;
		} else {
			for (int i = 2; i >= 0; i--) {
				System.out.print(s.charAt(i));
			}
			System.out.println("");
		}
	}
}


Measured memory_bytes: 21844
#include <stdio.h>

int main(void) {
	int n, x, i, j, k, cnt;
	
	while(1) {
	    scanf("%d%d", &n, &x);
	    
	    //どちらも0だったら処理を終了する
	    if((n == 0) && (x == 0)) {
	        break;
	    }
	    
	    cnt = 0;
	    for(i = 1; i <= n; i++){
	     for(j = i + 1; j <= n; j++) {
	         for(k = j + 1; k <= n; k++) {
	             if(i + j + k == x) {
	             		if((i != j) && (i != k) && (j != k)) {
	             //			printf("%d+%d+%d=%d\n", i, j, k, x);
	                 		cnt++;
	             		}
	                }
	             }
	         }
	    }
	    printf("%d\n", cnt);
	}
	return 0;
}


Measured memory_bytes: 2052
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
    S = readline().strip()
    ans = 0
    d = 0; cur = 0
    for c in S:
        if c == "R":
            if d == cur:
                cur += 1
            d = (d + 1) % 4
            if d == 0 and cur == 4:
                ans += 1
                cur = 0
        else:
            d = (d - 1) % 4
            if d == 0:
                cur = 0
    write("%d\n" % ans)
solve()


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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

map<PLL, vector<PLL>> nexts; // edges[v]: {u1, u2, ..}
map<PLL, ll> prevs;
vector<ll> a[2000];

PLL ver(ll i, ll j) {
  if (i > j)
    swap(i, j);
  return PLL(i, j);
}

signed main() {
  ll N;
  cin >> N;
  rep(i,N) {
    rep(j,N-1) {
      ll x;
      cin >> x;
      x--;
      a[i].push_back(x);
    }
  }
  rep(i,N) {
    rep(j,N-2) {
      auto cur = ver(i, a[i][j]);
      auto nex = ver(i, a[i][j+1]);
      nexts[cur].push_back(nex);
      prevs[nex]++;
      // printf("cur: (%d, %d) nex: (%d, %d)\n", cur.first, cur.second, nex.first, nex.second);
    }
  }

  // deleted candinates
  vector<PLL> can;
  rep(i,N) rep(j,i) {
    auto v = ver(i,j);
    if (prevs[v] == 0){
      can.push_back(v);
    }
  }
  //for (auto e : can) {
  //  printf("(%d, %d)\n", e.first, e.second);
  //}

  ll ans = 0;
  ll done = 0;
  while (done < N*(N-1)/2) {
    if (can.size() == 0) {
      cout << -1 << endl;
      return 0;
    }
    vector<PLL> t;
    for (auto v : can) {
      done++;
      for (auto u: nexts[v]) {
        prevs[u]--;
        if (prevs[u] == 0) {
          t.push_back(u);
        }
      }
    }
    can = t;
    ans++;
  }

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


Measured memory_bytes: 111744
#include<stdio.h>
char p[200];
int main(void){
    int i,cnt;
    char x;
    for(i=0;i<200;i++){
        p[i]=0;
    }
    cnt=0;
    i=0;
    while(1){
        scanf("%c",&x);
        if(x=='\n'){
            break;
        }
        cnt++;
        p[i]=x;
        i+=2;
    }
    i=1;
    while(1){
        scanf("%c",&x);
        if(x=='\n'){
            break;
        }
        cnt++;
        p[i]=x;
        i+=2;
    }
    for(i=0;i<cnt;i++){
        printf("%c",p[i]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 128
import math

n = int(input())
a = [int(input()) for i in range(n)]
n = 0
for x in a:
    if x == 2:
        n += 1
        continue
    if x < 2 or x % 2 == 0:
        continue
    i = 3
    while i <= math.sqrt(x):
        if x % i == 0:
            n -= 1
            break
        i = i + 2
    n += 1
print(n)


Measured memory_bytes: 6004
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <cassert>
using namespace std;
#define MOD 1000000007

long long dp[111111][13];

void add(long long &x, long long y){
    x = (x + y) % MOD;
}

int main(){
    string S;
    cin >> S;
    int N = S.size();
    S = ' ' + S;

    long long pow10[111111];
    pow10[0] = 1;
    for(int i=1; i<111111; i++)
        pow10[i] = (pow10[i-1]*10) % 13;

    dp[0][0] = 1;

    for(int i=1; i<=N; i++){
        int dig = N - i;
        if(S[i] == '?'){
            for(int j=0; j<13; j++){
                for(int k=0; k<10; k++){
                    int r = (j + k*pow10[dig]) % 13;
                    add(dp[i][r], dp[i-1][j]);
                }
            }
        }else{
            int num = S[i] - '0';
            for(int j=0; j<13; j++){
                int r = (j + num*pow10[dig]) % 13;
                add(dp[i][r], dp[i-1][j]);
            }
        }
    }
    cout << dp[N][5] << endl;
    return 0;
}

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

using namespace std;

typedef struct Node {
    int value;
    Node *prev;
    Node *next;
} Node;

Node *nil;

void list_initialize() {
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void list_insert(int x) {
    Node *node = (Node *)malloc(sizeof(Node));

    node->value = x;

    node->next = nil->next;
    nil->next->prev = node;
    nil->next = node;
    node->prev = nil;
}

void list_delete_node(Node *node) {
    node->prev->next = node->next;
    node->next->prev = node->prev;
    free(node);
}

void list_delete(int x) {
    for (Node *node = nil->next; node != nil; node = node->next) {
	if (node->value == x) {
            list_delete_node(node);
            return;
	}
    }
}

void list_delete_first() {
    if (nil->next == nil) {
	return;
    }

    Node *node = nil->next;
    list_delete_node(node);
}

void list_delete_last() {
    if (nil->prev == nil) {
        return;
    }

    Node *node = nil->prev;
    list_delete_node(node);
}

void list_print() {
    for (Node *node = nil->next; node != nil; node = node->next) {
        if (node != nil->next) {
            cout << " ";
        }
	cout << node->value;
    }
    cout << endl;
}

int main() {
    int n;

    cin.tie(0);
    ios::sync_with_stdio(false);

    list_initialize();

    cin >> n;
    for (int i = 0; i < n; i++) {
        string com;
        int key;

        cin >> com;
        if (com == "insert") {
            cin >> key;
            list_insert(key);
        } else if (com == "delete") {
            cin >> key;
            list_delete(key);
	} else if (com == "deleteFirst") {
            list_delete_first();
        } else { // deleteLast                                                  
	    list_delete_last();
        }
    }
    list_print();
    return 0;
}




Measured memory_bytes: 34388
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func solve(s string) int {
	if s == "SSS" {
		return 0
	}
	if s == "RSS" {
		return 1
	}
	if s == "SRS" {
		return 1
	}
	if s == "RRS" {
		return 2
	}
	if s == "SSR" {
		return 1
	}
	if s == "RSR" {
		return 1
	}
	if s == "SRR" {
		return 2
	}
	if s == "RRR" {
		return 3
	}
	return 0
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	s := getString()
	out(solve(s))
	// for i := 0; i < 8; i++ {
	// 	s := ""
	// 	for j := 0; j < 3; j++ {
	// 		if i&(1<<j) != 0 {
	// 			s = s + "R"
	// 		} else {
	// 			s = s + "S"
	// 		}
	// 	}
	// 	out(s, solve(s))
	// }
}


Measured memory_bytes: 1772
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        int N = Integer.valueOf(line);
		String line2 = sc.nextLine();
      	char target = 'B';
        int B1 = line2.length() - line2.replace(target + "", "").length();
        
      	target = 'R';
        int R1 = line2.length() - line2.replace(target + "", "").length();
      
        if(B1<R1){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 23508
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <numeric>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
#define fi first
#define se second
const int INF = 1e15;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int x; cin >> x;
    rng(i,-200,200){
        rng(j,-200,200){
            if(j*j*j*j*j==i*i*i*i*i+x){
                cout << j << " " << i << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main()
{
   int N; scanf("%lld",&N);
   vector<int> a(N),b(N);
   for(int i=0;i<N;i++) scanf("%lld",&a[i]);
   for(int i=0;i<N;i++) scanf("%lld",&b[i]);

   int ans=0;
   for(int i=28;i>=0;i--){
      const int mod=1<<(i+1);
      for(int j=0;j<N;j++){
         a[j]%=mod;
         b[j]%=mod;
      }
      sort(b.begin(),b.end());

      int cnt=0;
      for(int j=0;j<N;j++){
         for(int k=0;k<2;k++){
            cnt+=lower_bound(b.begin(),b.end(),mod+k*mod-a[j])
                -lower_bound(b.begin(),b.end(),mod/2+k*mod-a[j]);
         }
      }
      if(cnt&1) ans|=1<<i;
   }
   printf("%lld\n",ans);
}


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

int main() {
	int x;
	cin >> x;
	for (int i = x; 1; i++) {
		bool f = true;
		for (int j = 2; j*j <= i; j++) {
			if (i%j==0) {
				f = false;
				break;
			}
		}
		if (f) {
			cout << i << endl;
			return 0;
		}
	}
}

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

using namespace std;

using ll = long long;
using ld = long double;
using li = __int128;
using uli = unsigned __int128;

#define fi first
#define se second

template <typename T> void s_min(T& a, T b) {
	if (a > b) a = b;
}

template <typename T> void s_max(T& a, T b) {
	if (a < b) a = b;
}

const int MAXN = 3005;
int N;
double p[MAXN], dp[MAXN][MAXN];
bool vis[MAXN][MAXN];

double rec(int n, int h) {
	if (n == N) {
		if (h >= (N + 1) / 2) return 1;
		return 0;
	}
	if (vis[n][h]) return dp[n][h];
	vis[n][h] = true;
	return dp[n][h] = p[n] * rec(n + 1, h + 1) + (1 - p[n]) * rec(n + 1, h);
}

int main() {
	ios_base::sync_with_stdio(0);

	cin >> N;
	for (int i = 0; i < N; i++) cin >> p[i];
	memset(vis, false, sizeof(vis));
	double ans = rec(0, 0);
	cout << fixed << setprecision(12) << ans;

	return 0;
}

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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    ll N, T;
    vector<ll> t;
    ll count = 0;
    cin >> N >> T;
    t.resize(N);
    for(ll i = 0;i < N;i++) cin >> t[i];
    for(ll i = 0;i < N;i++) {
        ll p = i == 0 ? 0 : t[i - 1];
        count += min(t[i] - p, T);
    }
    count += T;
    cout << count << endl;
    return 0;
}


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

int main(){
  int N,L;
  cin >> N >> L;
  int mini = 10000000000;
  int ans = 0;
  for(int i = 1; i <N + 1; i++){
    mini = min(abs(L+i-1),abs(mini));
    if(L+i-1 < 0) mini = 0 - mini;
    ans += L+i-1;
  }
  cout << ans-mini << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
import sys
import itertools
import collections

INF = 1145141919


def solve(S: int):
    l = list(reversed(str(S)))
    a = [int(l[c]) * pow(10, c, 2019) for c in range(len(l))]

    def list_cumsum(l):
        return list(itertools.accumulate(l))
    s = [n % 2019 for n in list_cumsum([0]+a)]

    return sum([int(v * (v-1) / 2) for v in collections.Counter(s).values()])


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = int(next(tokens))  # type: int
    print(solve(S))


if __name__ == '__main__':
    main()


Measured memory_bytes: 111576
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------
ll dp[410][410]; // i番までにj個与える

ll modpow(ll a, ll n=MOD-2, ll mod=MOD){ // a^n % MOD の計算
    ll res = 1;
    while (n > 0){
        if(n & 1) res = res * a % mod;
        a = a * a  % mod;
        n >>= 1;
    }
    return res;
}

ll powawa[410][410];
//--MAIN-----------------------------------
void Main(){
    ll N,C; cin>>N>>C;
    vector<ll> A(N);
    vector<ll> B(N);
    rep(i,N) cin>>A[i];
    rep(i,N) cin>>B[i];

    dp[0][0]=1;

    rep(i,401){
        powawa[i][0]=1;
        reps(j,1,401){
            powawa[i][j]=(powawa[i][j-1]*i)%MOD;
        }
    }

    // sumj=0->i( j^x )
    ll sum[410][410];
    rep(i,405){
        rep(j,405){
            sum[i][j]=powawa[i][j];
        }
    }
    rep(i,405){
        rep(j,405){
            (sum[i+1][j]+=sum[i][j])%=MOD;
        }
    }



    rep(i,N){
        //reps(j,A[i],B[i]+1){ // A->Bのとき
            rep(k,C+1){ // iまででk個
                rep(l,C-k+1){ // C個になるまで配る l個
                    ll kakeru=((sum[B[i]][l]-sum[A[i]-1][l])+MOD)%MOD;
                    (dp[i+1][k+l]+=dp[i][k]*kakeru)%=MOD;
                }
            }   
        //}
    }
    cout<< dp[N][C] <<"\n";
}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


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

int main() {
    string s;
    cin >> s;
    int n = s.size();
    s += '*';

    vector<int> ans(n);
    for (int i = 0; i < n;) {
        int pi = i;
        if (s[i] == 'R') {
            while (s[i] == 'R') i++;
            ans[i-1] += (i - pi + 1) / 2;
            ans[i] += (i - pi) / 2;
        } else {
            while (s[i] == 'L') i++;
            ans[pi-1] += (i - pi) / 2;
            ans[pi] += (i - pi + 1) / 2;
        }
    }
    for (auto& e : ans) cout << e << " ";
}


Measured memory_bytes: 1024
//file_name:ABC83_A.cpp
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // int scan
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // matrix scan
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // string scan
    /*
    string s;
    cin >> s;
    */


int main() {
    int n;
    scanf("%d",&n);
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);
    if(n+x==y+z){
        puts("Balanced");
    }else if(n+x>y+z){
        puts("Left");
    }else{
        puts("Right");
    }


    return 0;
}



Measured memory_bytes: 256
// Problem : E - Colorful Blocks
// Contest : AtCoder - AtCoder Beginner Contest 167
// URL : https://atcoder.jp/contests/abc167/tasks/abc167_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define int long long
#define fastio                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0);
#define sz(a) (int)((a).size())
#define pb push_back
#define mp make_pair
#define db1(x) cout << #x << "=" << x << endl
#define db2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z)                                                       \
  cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
       << endl
#define dbp(x) \
  cout << #x << "= {" << (x.first) << ", " << (x.second) << "}" << endl;
#define dbv(v)                         \
  {                                    \
    cout << #v << " : ";               \
    for (auto x : v) cout << x << ' '; \
    cout << endl;                      \
  }
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rep2(i, a, b) for (int i = a; i >= b; i--)
#define die(x) return cout << x << '\n', 0;
const int MOD = 998244353;

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
const int MAX = 2e5;
ll modulo(ll a, ll b, ll n) {
  ll x = 1, y = a;
  while (b > 0) {
    if (b % 2 == 1) {
      x = (x * y) % n;  // multiplying with base
    }
    y = (y * y) % n;  // squaring the base
    b /= 2;
  }
  return x % n;
}
vi fact(MAX + 1), factinv(MAX + 1);

void pre() {
  fact[0] = 1;
  factinv[0] = 1;
  for (int i = 1; i <= MAX; ++i) {
    fact[i] = (fact[i - 1] * i) % MOD;
    factinv[i] = (factinv[i - 1] * modulo(i, MOD - 2, MOD)) % MOD;
  }
}

int mult(int a, int b) { return (a * b) % MOD; }
int nCr(int n, int r) {
  return mult(fact[n], mult(factinv[r], factinv[n - r]));
}

int32_t main() {
  fastio;
  //  freopen("input.txt", "r", stdin);
  //  freopen("output.txt", "w", stdout);
  int testcases;
  testcases = 1;
  // cin>>testcases;
  pre();
  while (testcases--) {
    int n, m, k;
    cin >> n >> m >> k;
    int ans = 0;
    rep(i, 0, k) {
      int temp = nCr(n - 1, i);
      temp = mult(temp, m);
      temp = mult(temp, modulo(m - 1, n - 1 - i, MOD));
      ans = (ans + temp) % MOD;
    }
    cout << ans << '\n';
  }

  return 0;
}


Measured memory_bytes: 6260
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint N; cin >> N;
    set<string> distinct_S;
    range(i, 0, N) {
        string S; cin >> S;
        distinct_S.emplace(S);
    }
    cout << distinct_S.size() << "\n";
}

Measured memory_bytes: 19248
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,m,n) for (int i = m; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
inline int popcount(const int x) { return __builtin_popcount(x);}
template<class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b;}
template<class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b;}
template<class T> void drop(const T &x) { std::cout<<x<<endl; exit(0);}
void debug_out() { std::cout << "\n";}
template<class T, class... Args> void debug_out(const T &x, const Args &... args) { std::cout<<x<< " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

struct InitIO{
  InitIO() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
  }
}init_io;

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  int now = 0;
  rep2(i, k, n) {
    if (a[now] < a[i]) cout << "Yes\n";
    else cout << "No\n";
    now++;
  }
  return 0;
}

Measured memory_bytes: 4780
import sys

def input(): return sys.stdin.readline().rstrip()

from collections import deque

def main():

    n,m=map(int,input().split())

    graph=[[] for _ in range(n)]

    for i in range(m):

        a,b=map(int,input().split())

        graph[a-1].append(b-1)

        graph[b-1].append(a-1)

    queue=deque([0])

    visited=[False]*n

    visited[0]=True

    ans=[0]*n

    while queue:

        node=queue.popleft()

        for xnode in graph[node]:

            if visited[xnode]:continue

            ans[xnode]=node+1

            visited[xnode]=True

            queue.append(xnode)

    print("Yes")

    for a in ans[1:]:

        print(a)





if __name__=='__main__':

    main()

Measured memory_bytes: 38780
import sys

N, C, K = map(int, sys.stdin.readline().strip().split())
T = []
for _ in range(N):
    T.append(int(sys.stdin.readline().strip()))

T.sort()
ans = 0
n = 0
left_min = float("inf")
for t_i in T:
    left_min = min(t_i, left_min)
    if left_min + K < t_i:
        ans += 1
        left_min = t_i
        n = 1
        continue

    n += 1
    if n == C:
        ans += 1
        n = 0
        left_min = float("inf")

if n > 0:
    ans += 1

print(ans)

Measured memory_bytes: 46284
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
int main() {
  int X;
  cin >> X;
  if (30 <= X) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
const long long mod=1000000007ll;
int main()
{
  int n;
  scanf("%d",&n);
  static int x[100000];
  for(int i=0;i<n;i++){
    scanf("%d",x+i);
  }
  long long ans=1ll;
  int K=1;
  for(int i=1;i<n;i++){
    if(2*K==x[i]){
      ans*=K+1;
      ans%=mod;
    }
    else{
      K++;
    }
  }
  for(int t=1;t<=K;t++){
    ans*=t;
    ans%=mod;
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    string A;
    string B;
    cin>>A>>B;
    //cout<<B;
    if(A=="0"||B=="0"||B=="0.0"||B=="0.00"){
        cout<<0<<endl;
        return 0;
    }
    int ans[1000]={0};
    for(int i=0;i<A.size();i++){
        ans[i]+=(A[A.size()-1-i]-'0')*(B[3]-'0');
        ans[i+1]+=(A[A.size()-1-i]-'0')*(B[2]-'0');
        ans[i+2]+=(A[A.size()-1-i]-'0')*(B[0]-'0');
    }

    for(int i=0;i<100;i++){
        ans[i+1]+=ans[i]/10;
        ans[i]=ans[i]%10;
    }

    for(int i=0;i<10;i++){
        //printf("[%d]",ans[i]);
    }

    int flg=0;
    for(int i=100;2<=i;i--){
        if(flg||ans[i]!=0){
            cout<<ans[i];
            flg=1;
        }
    }
    if(flg==0)cout<<0;
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <map>

using namespace std;

int main(void) {
    int64_t N, K;
    cin >> N >> K;
    vector<int> A(N);
    for(int i=0; i<N; i++) {
        cin >> A[i];
        --A[i];
    }

    vector<int> visited(N);
    vector<int> v = {0};
    int now = 0;
    visited[0] = 1;

    while(visited[A[now]] == 0) {
        v.emplace_back(A[now]);
        now = A[now];
        visited[now] = 1;
    }

    int64_t d = distance(v.begin(), find(v.begin(), v.end(), A[now]));
    if(K < v.size()) {
        cout << v[K] + 1 << endl;
    } else {
        K -= d;
        K %= (int64_t)v.size() - d;

        cout << v[d + K] + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 5888
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <climits>
#include <utility>
#include <deque>
#include <list>
#include <stdexcept>
using namespace std;

#define ll long long
#define VEC2(type, name, dim0, dim1, init_val) vector<vector<type>> name(dim0, vector<type>(dim1, init_val))
#define IN(type, name) type name; cin >> name
#define IN_V(type, name, size) vector<type> name(size); for(auto& x: name) cin >> x
#define IN_VPair(type1, type2, name, size) vector<pair<type1, type2>> name(size); for(auto& x: name) cin >> x.first >> x.second
#define IN_VW(type, name, size) vector<type> name(size); for(auto& x: name)

#define REP(name, start, end) for(ll name = (start); (name) < (end); ++(name))
#define REPR(name, end, start) for(ll name = (start - 1); (name) >= (end); --(name))
#define ALL(iterable) (iterable).begin(), (iterable).end()

template<typename _T> void OutIter(_T beg, _T end, string separator = " ", bool eol = true) {
	cout << *beg;
	for (auto it = beg + 1; it != end; ++it) {
		cout << separator << *it;
	}
	if(eol)cout << endl;
}

int main()
{
	cout << fixed << setprecision(6);
	IN(ll, n);

	cout << (int)pow(n, 3) << endl;
	return 0;
}

Measured memory_bytes: 384
import sys

sys.setrecursionlimit(10 ** 6)

N, M = map(int, input().split())
A = []
ANS = []
for i in range(N + 10):
    ANS.append(None)

for _ in range(M):
    a = int(input())
    A.append(a)
    ANS[a] = 0


def f(x):
    if ANS[x] is not None:
        return ANS[x]

    if x > N:
        return 0
    if x == N:
        return 1

    if ANS[x + 1] is None:
        x1 = f(x + 1)
        ANS[x + 1] = x1
    else:
        x1 = ANS[x + 1]

    if ANS[x + 2] is None:
        x2 = f(x + 2)
        ANS[x + 2] = x1
    else:
        x2 = ANS[x + 2]

    ans = x1 + x2
    # ans = f(x + 1) + f(x + 2)
    ANS[x] = ans
    return ans


print(f(0) % 1000000007)


Measured memory_bytes: 494308
s = list(input())
k = int(input())
S = s.copy()
S_3 =s.copy()
cnt = 0
cnt_2 = 0
cnt_3 = 0


for i in range(1, len(s)):
    if s[i-1] == s[i]:
        cnt += 1
        s[i] = "A"

# --------------------------

for i in range(len(s)):
    S.append(S[i])

for i in range(1, len(S)):
    if S[i-1] == S[i]:
        cnt_2 += 1
        S[i] = "A"

# if k == 1:
#     print(cnt)
# else:
#     print(cnt + (cnt_2 - cnt) * (k-1))

# ---------------------------------------

for i in range(len(S)):
    S_3.append(S_3[i])

for i in range(1, len(S_3)):
    if S_3[i-1] == S_3[i]:
        cnt_3 += 1
        S_3[i] = "A"

# --------------------------------------

if k == 1:
    print(cnt)
elif k == 2:
    print(cnt_2)
elif k == 3:
    print(cnt_3)
elif cnt_2 - cnt == cnt_3 - cnt_2:
    print(cnt + (cnt_2 - cnt) * (k-1))
else:
    if k % 2 == 0:
        print(int(cnt + (cnt_2 - cnt) * (k / 2) + (cnt_3 - cnt_2) * (k / 2 - 1)))
    else:
        print(int(cnt + (cnt_2 - cnt) * ((k - 1) / 2) + (cnt_3 - cnt_2) * ((k - 1) / 2)))



Measured memory_bytes: 3064
a,b,c,x = 4.times.map{gets.to_i}
count = 0

(0..a).each do |o|
  (0..b).each do |p|
    (0..c).each do |q|
      count += 1 if o * 500 + p * 100 + q * 50 == x
    end
  end
end
puts count

Measured memory_bytes: 1788
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, L = nl()

min_aji = 1000
min_aji_real = 1000
total = 0
for i in range(N):
    total += L + i
    if abs(L + i) < min_aji:
        min_aji = abs(L + i)
        min_aji_real = L + i

print(total - min_aji_real)


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

using namespace std;

int main()
{
   int n;
   cin>>n;
   priority_queue<float,vector<float>,greater<float>>qu;


   for(int i = 0 ; i < n ; i++)
   {
    float val;
    cin>>val;
    qu.push(val);
   }

  while(qu.size() > 1)
  {
    float top1 = qu.top();
    qu.pop();
    float top2 = qu.top();
    qu.pop();

    qu.push((top1+top2)/2.0);
  }

  cout<<qu.top()<<endl;
   return 0;
}

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

int main() {
  
  int s1s2s3, s1, s2, s3;
  
  cin >> s1s2s3;
  
  s1 = s1s2s3 / 100;
  s2 = (s1s2s3 - s1 * 100) / 10;
  s3 = s1s2s3 - s1 * 100 - s2 * 10;
  
  cout << s1 + s2 + s3 <<endl;
}

Measured memory_bytes: 256
import numpy as np
from collections import Counter
import collections
a = list(map(int,input().split()))
b = list(map(int,input().split()))
#値を大きさ順に並べる
b = sorted(b)
l = Counter(b)
Num = 0
for k,v in l.items():
  if v-k>=0 :
  	Num += v-k
  else:
    Num += v 
print(Num)

Measured memory_bytes: 26852
//
//AtCoder Beginner Contest 174
//C
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>
#include <bitset>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;

const double PI = 3.14159265358979323846;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

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

    ll now = 0;
    ll ans = -1;

    FOR(i, 1, 1000001){
        now = now*10 + 7;
        now %= k;
        if (now==0){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


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


int main(){
  
  int n, x;
  while(cin >> n >> x, n|x){
  int ans = 0;
    for(int i=1; i<=n-2; i++){
      for(int j=i+1; j<=n-1; j++){
        for(int k=j+1; k<=n; k++){
          if(i+j+k == x) ans++;
        }
      }
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3084
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

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; }

using ll = long long;

ll N;
ll A[200010];
ll dp[200010][2][3];

int main()
{
  std::cin >> N;

  rep( i, N )
    std::cin >> A[i];

  rep( i, N+1 ) rep( j, 2 ) rep( k, 3 )
    dp[i][j][k] = -(1ll<<60);

  dp[0][1][0] = 0;

  rep( i, N )
  {
    rep( j, 2 ) rep( k, 3 )
    {
      if( j+k < 3 )
        chmax( dp[i+1][1][j+k], dp[i][j][k] );
      
      if( j == 1 )
        chmax( dp[i+1][0][k], dp[i][j][k]+A[i] );
    }
  }

  if( N%2 == 0 )
  {
    std::cout << std::max( dp[N][0][1], dp[N][1][0] ) << std::endl;
  }
  else
  {
    std::cout << std::max( dp[N][0][2], dp[N][1][1] ) << std::endl;
  }

  return 0;
}

Measured memory_bytes: 14092
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <list>
using namespace std;

int main(){
  int n, k, m;
  while(cin >> n >> k >> m){
    if(n == 0 && k == 0 && m == 0) break;
    vector<int> v;
    for(int i = 1 ; i <= n ; i++){
      v.push_back(i);
    }
    for(int i = m-1 ; v.size() != 1 ; i = (k+i-1) % v.size()){
      v.erase(i+v.begin());
    }
    cout << *v.begin() << endl;
  }   
  return 0;
}

Measured memory_bytes: 1324
#include <iostream>

using namespace std;
int main() {
    int M, N;
    cin >> N >> M;
    int oddmax = (M % 2 == 0) ? (M-1) : M;
    int oddsize = (M+1) / 2;
    for (int i=0; i<oddsize; i++) {
        cout << i+1 << " " << oddmax - i + 1 << endl;
    }
    int offset = oddmax + 2;
    int evenmax = (M%2 == 0) ? M : (M-1);
    int evensize = M / 2;
    for (int i=0; i<evensize; i++) {
        cout << offset + i <<  " " << offset + evenmax - i << endl;
    }
    return 0;
}



Measured memory_bytes: 3596
import java.io.*;

class Main{
    public static void main(String[] args){
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {
                int a, b, c, d;

                String line = reader.readLine();
                String[] strAry = line.split(" ");

                a = Integer.parseInt(strAry[0]);
                b = Integer.parseInt(strAry[1]);
                c = Integer.parseInt(strAry[2]);

                while(2 >= 1){
                    if(a > b){
                        d = a;
                        a = b;
                        b = d;
                    }else if(b > c){
                        d = b;
                        b = c;
                        c = d;
                    }

                    if(a <= b && b <= c){
                        break;
                    }
                }

                System.out.println(a + " " + b + " " + c);
                
        } catch (IOException e) {
            //TODO: handle exception
            System.out.println(e);
        }
    }
}

Measured memory_bytes: 24276
function main(input) {
  const inputList = input.split(/\s/).map(inp => formatNum(inp));
  const N = inputList[0];
  const A = inputList[1];
  const B = inputList[2];
  var result = 0;
  if (N * A > B) {
    result = B;
  } else {
    result = N * A;
  }
  console.log(result);
};

// 文字列を数値に変換
function formatNum(str) {
  return Number(str);
};

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21064
// header file
#include <iostream>
#include <cstdio>
#include <vector>  //vector<T> vec; ランダムアクセスが速い、挿入は線形時間
#include <list>  //list<T> ls; 挿入・消去速い、アクセスは線形時間
#include <algorithm>
#include <functional> // greater<int>()を使える
#include <utility>
#include <string>
#include <map>
// macro
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define R_REP(i, n) for(int i = ((int)(n - 1)); i >= 0; i--)  // Reverse n-1 ~ 0
#define R_REPN(i, n) for(int i= ((int)(n));i > 0;i--)  // Reverse n ~ 1
#define FOR(i, m, n) for(int i = m;i < n;i++)  // 指定範囲loop m ~ n-1
#define pb(vec) push_back(vec)  // 配列の一番うしろに追加
// typedef
typedef long long ll;  // int64

using namespace std;

int main(void) {
    char c;
    cin >> c;
    string str = "aeiou";

    int i = 0;
    while (i <= str.size() - 1){
        if (c == str.at(i)) {
            std::cout << "vowel" << std::endl;
            break;
        }
        // 最後の母音の確認
        if (i == str.size() - 1) {
            if (c == str.at(i)) {
                std::cout << "vowel" << std::endl;
                break;
            } else {
                std::cout << "consonant" << std::endl;
                break;
            }
        }
        i++;
    }
    return 0;
}


Measured memory_bytes: 256
import sys

def intinput(): return map(int,sys.stdin.readline().split())

n=int(sys.stdin.readline())
l = []
for i in range(n):
    a,b = sys.stdin.readline().split()
    l.append([a,-int(b),i+1])
l.sort()
for (x,y,z) in l:
    print(z)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);


int main() {
    cin>>N;
    vec c(26), last(26, 0);
    mat s(N, vec(26));
    rep(i,26) cin>>c[i];
    rep(i,N) rep(j, 26) cin>>s[i][j];
    rep(day, N){
        vec temp(26, 0);
        rep(i, 26) {
            temp[i] += s[day][i];
            if(day != N - 1) temp[i] -= s[day + 1][i] - c[i];
        }
        rep(i, 26) {
            temp[i] += c[i] * (day + 1 - last[i]);
        }
        auto ite = max_element(ALL(temp));
        cout<<(ite - temp.begin()) + 1<<endl;
        last[ite - temp.begin()] = day + 1;
    }
}


Measured memory_bytes: 3720
#include <stdio.h>
int main(void) {
int a, b, c, n=0;
scanf("%d", &a);
scanf("%d", &b);
scanf("%d", &c);
for( int i = a; i <= b; ++i ) {
if( c%i == 0 ) {
++n;
}
}
printf("%d\n", n);
return 0;
}

Measured memory_bytes: 1024
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
ret = 0
for i in range(k):
    last = 'x'
    for c in t[i::k]:
        if last != c:
            ret += p if c == 'r' else r if c == 's' else s
            last = c
        else:
            last = 'x'
print(ret)



Measured memory_bytes: 73180
#include <iostream>

using namespace std;

int main()
{
	int n, k;

	cin >> n >> k;

	if ((n%2 == 0 && ((n / 2) >= k)) || (n%2 !=0 && ((n / 2) + 1) >= k))
		cout << "YES\n";
	else
		cout << "NO\n";


	return 0;
}

Measured memory_bytes: 256