akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
  public static void main(String...args) {
    final Scanner sc = new Scanner(System.in);
    final int a = sc.nextInt();
    final int b = sc.nextInt();
    System.out.println(a + b == 15 ? '+' : a * b == 15 ? '*' : 'x');
  }
}

Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  vector<int> c(n+1,0);
  rep(i,n) cin>>c[i+1];
  map<int,int> cnt;
  vector<int> dp(n+1,0);
  dp[0]=1;
  FOR(i,1,n+1){
    if(c[i-1]==c[i]){
      (dp[i]+=dp[i-1])%=mod;
    }else{
      (dp[i]+=dp[i-1]+cnt[c[i]])%=mod;
    }
    cnt[c[i]]=dp[i];
  }
  //cout_vec(dp);
  cout<<dp[n]<<endl;
}

Measured memory_bytes: 11264
import java.util.PriorityQueue

fun main(args: Array<String>) {
    var (N, M) = readInputLine().split(" ").map{it.toInt()}
    
    val works = PriorityQueue<Pair<Int, Int>>(N, {x, y -> if (x.first < y.first) -1 else if (x.first == y.first) {if (x.second > y.second) -1 else if (x.second == y.second) 0 else 1} else 1})
    
    for (i in 1..N) {
        val (A, B) = readInputLine().split(" ").map{it.toInt()}
        works.add(Pair(A, B))
    }

    val queue = PriorityQueue<Pair<Int, Int>>(N, {x, y -> if (x.second > y.second) -1 else if (x.second == y.second) 0 else 1})
    
    var ans = 0
    
    for (i in 1..M) {
        val work = works.peek() ?: Pair(Int.MAX_VALUE, 0)
        if (work.first > i) {
            ans += queue.poll()?.second ?: 0
        } else {
            val queueWork = queue.peek() ?: Pair(0, 0)
            if (work.second > queueWork.second) {
                ans += work.second
                works.poll()
            } else {
                ans += queue.poll()?.second ?: 0
            }
        }
        
        while (works.size != 0) {
            val work = works.poll()
            if (work.first > i) {
                works.add(work)
                break
            } else {
                queue.add(work)
            }
        }
    }
    
    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 60848
#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

//#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector<vector<int>> mat;
//typedef unsigned int uint;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int powi(int a, int b)
{
	int ans = 1;
	rep(i, 0, b)
	{
		ans *= a;
	}
	return ans;
}

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

	int D, N;

	cin >> D >> N;
	cout << powi(100, D)*(N != 100 ? N : N + 1) << endl;

	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"log"
	"sort"
)

func main() {
	log.SetFlags(log.Lshortfile)
	var N int
	fmt.Scan(&N)
	s := make([]int, N)
	for i := range s {
		fmt.Scan(&s[i])
	}
	sort.Ints(s)
	// log.Println(s)
	// log.Println(sum(s))
	sm := sum(s)
	i := 0
	for sm%10 == 0 {
		// log.Println(sm)
		if s[i]%10 != 0 {
			sm -= s[i]
			break
		}
		i++
		if i == len(s) {
			sm = 0
			break
		}
	}
	fmt.Println(sm)
}

func sum(a []int) int {
	r := 0
	for i := range a {
		r += a[i]
	}
	return r
}


Measured memory_bytes: 512
package main

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

func main() {
	N := nextInt()
	x := make([][]int, N)
	y := make([][]int, N)

	for i := 0; i < N; i++ {
		A := nextInt()
		x[i] = make([]int, A)
		y[i] = make([]int, A)

		for j := 0; j < A; j++ {
			x[i][j] = nextInt() - 1
			y[i][j] = nextInt()
		}
	}
	// 全部数える
	S := 1<<uint(N) - 1
	c := 0

loop:
	for s := 0; s <= S; s++ {
		for i := 0; i < N; i++ {
			for j := 0; j < len(x[i]); j++ {
				// 発言者が不親切なら無視
				if nthbit(s, i) == 0 {
					continue
				}
				// 発言者が正直者かつ不整合があれば次へ
				if nthbit(s, x[i][j]) != y[i][j] {
					continue loop
				}
			}
		}
		c1 := 0
		for i := 0; i < N; i++ {
			if nthbit(s, i) == 1 {
				c1++
			}
		}
		c = max(c, c1)
	}

	fmt.Println(c)
}

func nthbit(a int, n int) int { return int((a >> uint(n)) & 1) }

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

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}


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

using namespace std;

int main (){
string s;
cin>>s;
if(s[s.size()-1]=='s'){
    cout<<s+"es"<<endl;
    return 0;
}
cout<<s+'s'<<endl;
//system("pause");
return 0;
}


Measured memory_bytes: 3632
import java.io.*;
import java.util.*;

class Main {

    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        int N = sc.nextInt();
        int[] H = new int[N];
        for (int i=0; i<N; i++){
            H[i] = sc.nextInt();
        }
        int moveCnt = 0;
        int prevHeight = H[0];
        int ans = 0;

        for (int i=1; i<N; i++){
            if (H[i] <= prevHeight){
                moveCnt++;
            }else {
                ans = Math.max(ans, moveCnt);
                moveCnt = 0;
            }
            prevHeight = H[i];
        }
        ans = Math.max(ans, moveCnt);
        System.out.println(ans);
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;
    
        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }
    
        int nextInt() {
            return Integer.parseInt(next());
        }
    
        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 41032
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010


int main(){
  int n;
  int a[SIZE];
  int m = 0;
  
  scanf("%d",&n);
  for(int i=0;i<n;i++) scanf("%d",a+i);

  int absmaxpos = -1;
  int absmax = -1;

  printf("%d\n",(n-1)*2);
  
  for(int i=0;i<n;i++){
    if(absmax < abs(a[i])){
      absmaxpos = i;
      absmax = abs(a[i]);
    }
  }

  for(int i=0;i<n;i++){
    if(i != absmaxpos)
      printf("%d %d\n",absmaxpos+1, i+1);
  }

  if(a[absmaxpos] > 0){
    for(int i=0;i<n-1;i++) printf("%d %d\n",i+1, i+2);
  }else{
    for(int i=0;i<n-1;i++) printf("%d %d\n",n-i, n-i-1);
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <limits>

using namespace std;

typedef long long ll;

int main (int argc, char* argv[]) {
	int n;
	cin >> n;

	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i]--;
	}
	vector<int> b(n);
	for (int i = 0; i < n; i++) {
		cin >> b[i];
	}
	vector<int> c(n);
	for (int i = 0; i < n - 1; i++) {
		cin >> c[i];
	}
	int res = 0;
	int prev = -10;
	for (int i = 0; i < n; i++) {
		int j = a[i];
		res += b[j];
		if (j == prev + 1) {
			res += c[prev];
		}
		prev = j;
	}
	cout << res << endl;
}


Measured memory_bytes: 256
N = int(input())
A = list(sorted(map(int, input().split()), reverse=True))

from collections import Counter
cnt_a = Counter(A)

X = [0] * 3
for k, v in cnt_a.items():
    while v >= 3:
        v = (v // 3 + (v % 3))
    X[v] += 1

if X[2] % 2 == 0:
    print(X[1] + X[2])
else:
    print(X[1] - 1 + X[2])




Measured memory_bytes: 22012
#include <stdio.h>;
#include <string.h>

int main(void)
{
	int a[11][11];
	int i, j;
	int n;
	
	while (1){
		scanf("%d", &n);
		
		if (n == 0){
			break;
		}
		
		memset(a, 0, sizeof(a));
		
		for (i = 0; i < n; i++){
			for (j = 0; j < n; j++){
				scanf("%d", &a[i][j]);
			}
		}
		
		for (i = 0; i < n; i++){
			for (j = 0; j < n; j++){
				a[i][n] += a[i][j];
			}
		}
		
		for (i = 0; i <= n; i++){
			for (j = 0; j < n; j++){
				a[n][i] += a[j][i];
			}
		}
		
		for (i = 0; i <= n; i++){
			for (j = 0; j <= n; j++){
				printf("%5d", a[i][j]);
			}
			printf("\n");
		}
	}
	
	return (0);
}

Measured memory_bytes: 616
program test
implicit none
integer(8) :: n,i,j,k,ans=0,rgb(3,5000)=0,hoge=0,big=0,small=0
character(len=10000) :: s



read(*,*) n
read(*,*) s

do i=1,n
  if(s(i:i)=='R')then
    rgb(1,i:n) = rgb(1,i:n) + 1
  else if(s(i:i)=='G')then
    rgb(2,i:n) = rgb(2,i:n) + 1
  else if(s(i:i)=='B')then
    rgb(3,i:n) = rgb(3,i:n) + 1
  endif
enddo


if(n<=2)then
  ans = 0
else
  
  do j=2,n-1
    if(s(j:j) == 'R') then
      ans = ans + rgb(2,j-1)*(rgb(3,n)-rgb(3,j))
      ans = ans + rgb(3,j-1)*(rgb(2,n)-rgb(2,j))
      
      big = j+1
      small = j-1
      
      do while(big <= n .and. small >= 1)
        if((s(small:small)=='G' .and. s(big:big)=='B') .or. (s(small:small)=='B' .and. s(big:big)=='G')) then
         ans = ans - 1
        endif
        big = big + 1
        small = small - 1
      enddo
      
    endif

    if(s(j:j) == 'G') then
      ans = ans + rgb(1,j-1)*(rgb(3,n)-rgb(3,j))
      ans = ans + rgb(3,j-1)*(rgb(1,n)-rgb(1,j))

      big = j+1
      small = j-1
      
      do while(big <= n .and. small >= 1)
        if((s(small:small)=='R' .and. s(big:big)=='B') .or. (s(small:small)=='B' .and. s(big:big)=='R')) then
         ans = ans - 1
        endif
        big = big + 1
        small = small - 1
      enddo

    endif

    if(s(j:j) == 'B') then
      ans = ans + rgb(1,j-1)*(rgb(2,n)-rgb(2,j))
      ans = ans + rgb(2,j-1)*(rgb(1,n)-rgb(1,j))

      big = j+1
      small = j-1
      
      do while(big <= n .and. small >= 1)
        if((s(small:small)=='R' .and. s(big:big)=='G') .or. (s(small:small)=='G' .and. s(big:big)=='R')) then
         ans = ans - 1
        endif
        big = big + 1
        small = small - 1
      enddo

    endif
    
  enddo
  
endif

write(*,*) ans

end

Measured memory_bytes: 2976
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <stack>
#include <map>

using std::cin;
using std::cout;
using std::endl;
using std::terminate;
using std::vector;
using std::stack;
using std::map;
using std::make_pair;

typedef vector<vector<int> > Graph;
typedef int GraphId;

void dfs(Graph &G, GraphId &id, vector<GraphId> &visited, map<GraphId, int> &m, int v) {
    if (visited[v] != -1) {
        return ;
    }

    id++;

    stack<int> sta;

    visited[v] = id;
    sta.push(v);
    m.insert(make_pair(id, 1));

    while (sta.empty() == false) {
        int u = sta.top(); sta.pop();
        for (int x : G[u]) {
            if (visited[x] == -1) {
                visited[x] = id;
                sta.push(x);
                m[id]++;
            }
        }
    }

    return ;
}

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

    Graph Friend(N);
    vector<int> num(N, 0);
    for (int i = 0; i < M; ++i) {
        int a, b; cin >> a >> b; --a; --b;
        Friend[a].emplace_back(b);
        Friend[b].emplace_back(a);
        num[a]++;
        num[b]++;
    }

    Graph Block(N);
    for (int i = 0; i < K; ++i) {
        int c, d; cin >> c >> d; --c; --d;
        Block[c].emplace_back(d);
        Block[d].emplace_back(c);
    }

    vector<GraphId> visited; visited.assign(N, -1);
    GraphId id = 0;
    map<GraphId, int> m;
    for (int v = 0; v < N; ++v) {
        dfs(Friend, id, visited, m, v);

        GraphId gid = visited[v];
        int cnt = m[gid] - num[v] - 1;

        vector<int> blocks = Block[v];
        for (int x : blocks) {
            if (gid == visited[x]) {
                cnt--;
            }
        }

        if (v != N - 1) {
            cout << cnt << " ";
        } else {
            cout << cnt << endl;
        }
    }
}

int main() {

#ifdef DEV
    std::ifstream in("input");
    cin.rdbuf(in.rdbuf());

    int t; cin >> t;
    for (int x = 1; x <= t; ++x) {
        solve();
    }
#else
    solve();
#endif

    return 0;
}


Measured memory_bytes: 15852
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
void Main()
{
    int n;
    cin >> n;
    vector<string> S(n);
    rep(i, n) cin >> S[i];

    vector<int> Cnt('z' - 'a' + 1, 1e8);

    rep(i, n) {
        vector<int> c('z' - 'a' + 1);
        rep(j, S[i].size()) c[S[i][j] - 'a']++;

        rep(j, Cnt.size()) {
            Cnt[j] = min(Cnt[j], c[j]);
        }
    }

    rep(j, Cnt.size()) {
        rep(k, Cnt[j]) {
            cout << (char)('a' + j);
        }
    }

    cout << endl;
    
}
signed main(){ Main();return 0;}

Measured memory_bytes: 3632
#include <stdio.h>

#define N_MAX   100000
#define W_MAX   100000
#define H_MAX   100000

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

int width[W_MAX+1]    = {};
int height[H_MAX+1]   = {};

int main(void){
    int N,W,H,x,y,w;
    int i,j;
    int M;
    
    scanf("%d %d %d",&N,&W,&H);
    for( i=0; i<N; i++){
        scanf("%d %d %d",&x,&y,&w);
        /* wi-fiの届く範囲を記録 */
        width [MAX(0,  x-w)]++;
        width [MIN(H+1,x+w)]--;
        height[MAX(0,  y-w)]++;
        height[MIN(W+1,y+w)]--;
    }
    
    M=N;
    for( i=0; i<W; i++){
        if( M > width[i] ){
            /* 横方向でwi-fiが届く最小値を計算 */
            M = width[i];
        }
        /* シミュレート */
        width[i+1] += width[i];
    }
    
    /* 横方向でwi-fiが届かない地域がある場合、縦方向も計算 */
    if( M <= 0 ){
        M = N;
        for( i=0; i<H; i++){
            if( M > height[i] ){
                M = height[i];
            }
            height[i+1] += height[i];
        }
    }
    
    if( M <= 0 ){
        printf("No\n");
    }else{
        printf("Yes\n");
    }
}




Measured memory_bytes: 2504
import sys
sys.setrecursionlimit(1 << 25)
readline = sys.stdin.buffer.readline
read = sys.stdin.readline  # 文字列読み込む時はこっち

import numpy as np
from functools import partial
array = partial(np.array, dtype=np.int64)
zeros = partial(np.zeros, dtype=np.int64)
full = partial(np.full, dtype=np.int64)


def ints(): return np.fromstring(readline(), sep=' ', dtype=np.int64)


def read_matrix(H, W)->np.ndarray:
    '''return np.ndarray shape=(H,W) matrix'''
    lines = []
    for _ in range(H):
        lines.append(read())
    lines = ' '.join(lines)  # byte同士の結合ができないのでreadlineでなくreadで
    return np.fromstring(lines, sep=' ', dtype=np.int64).reshape(H, W)


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import

N, K = ints()
A = read_matrix(N, N)


# from numba import njit


# @njit('i8[:,:](i8[:,:],i8[:,:])', cache=True)
# def matmul_mod(X: np.ndarray, Y: np.ndarray)->np.ndarray:
#     MOD = 10**9 + 7
#     # return X @ Y
#     ret = np.empty((X.shape[0], Y.shape[1]), dtype=np.int64)
#     for i in range(X.shape[0]):  # Xの行
#         for j in range(Y.shape[1]):  # Yの列
#             tmp = (X[i, :] * Y[:, j]) % MOD
#             ret[i, j] = tmp.sum() % MOD
#     return ret


def matmul_mod(X: np.ndarray, Y: np.ndarray, MOD: int=10**9 + 7)->np.ndarray:
    # return X@Y %MOD
    ret = np.empty((X.shape[0], Y.shape[1]), dtype=np.int64)
    YT = Y.T
    for i in range(X.shape[0]):  # Xの行
        tmp = (YT * X[i, :]) % MOD
        ret[i, :] = tmp.sum(1) % MOD
    return ret


# def matmul_mod(X: np.ndarray, Y: np.ndarray, MOD: int=10**9 + 7)->np.ndarray:
#     # return X@Y %MOD
#     MOD = 10**9 + 7
#     X3d = X[:, :, np.newaxis].transpose(0, 2, 1)
#     Y3d = Y[:, :, np.newaxis].transpose(2, 1, 0)
#     return ((X3d * Y3d) % MOD).sum(2) % MOD


A_double = np.asanyarray(A, dtype=np.int64)
ans = np.eye(N, dtype=np.int64)
for j in range(int(K).bit_length()):
    if (K >> j) & 1:
        ans = matmul_mod(ans, A_double)
    A_double = matmul_mod(A_double, A_double)

print(ans.sum() % MOD)


Measured memory_bytes: 27428
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>
#include<queue>
#include <numeric>
using namespace std;
 
//conversion
//------------------------------------------
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();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 

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

LL lcm(LL a, LL b){
    LL g = gcd(a,b);
    return a/g *b;
}


int main(){
    int A,B;
    cin >> A >> B;
    if(A+B<24){
        cout << A+B;
    }
    else{
        cout << A+B-24;
    }
}

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

using namespace std;

int lineaSearch(int n, deque<int> s, int q, deque<int> t) {
    int result = 0;
    for (const int i : t) {
        if (find(s.begin(), s.end(), i) !=s.end()) {
            ++result;
        }
    }
    return result;
}

int main(int argc, char* argv[]) {
    deque<int> s;
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        s.push_back(x);
    }
    deque<int> t;
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int x;
        cin >> x;
        t.push_back(x);
    }
    cout << lineaSearch(n, s, q, t) << endl;

    return 0;
}



Measured memory_bytes: 3180
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    int s = 0;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        s += A[i];
    }

    int cnt = 0;
    for (int i = 0; i < N; i++) {
        if (A[i] * 4 * M >= s) {
            cnt++;
        }
    }
    if (cnt >= M) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forenska(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
#define randIn(L,R) (((LL)rand()*rand())%(R-L)+L)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.14159265358979323846264338327950288419716939937510582097;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read()
{
    int x=0;
    char ch=' ';
    bool flag=false;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')flag=true;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return flag?-x:x;
}

int main()
{
	int n,k;
	vec h;
	cin>>n>>k;
	h.resize(n);
	rep(i,0,n)cin>>h[i];
	sort(all(h));
	int ans=INT_MAX;
	rep(i,0,n-k+1)ans=min(ans,h[i+k-1]-h[i]);
	cout<<ans<<endl;
	return 0;
}



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

int main() {
	int n, m;
	while(cin >> n >> m, n || m) {
		set<int> s;
		int sum = 0, res = 0;

		s.insert(0);
		for(int i = 0; i < n; i++) {
			unsigned int a;
			set<int>::iterator it;
			cin >> a;
			sum = (sum + a) % m;
			it = s.upper_bound(sum);
			if(it == s.end())
				res = max(res, sum);
			else
				res = max(res, (sum - *it + m) % m);
			s.insert(sum);
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 2408
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define PI 		    acos(-1)
#define pb          push_back
#define ins         insert
#define INF        	1000000000000000007 //1e18+7
#define mk          make_pair
#define lb(v,x)     lower_bound(all(v),x)
#define ub(v,x)     upper_bound(all(v),x)
#define ff          first
#define ss          second
#define rev         reverse
#define endl        "\n"
#define max3(x,y,z)  max(x,max(y,z))
#define min3(x,y,z)  min(x,min(y,z))
#define sz(a)       (ll)a.size()
#define ld     		long double
#define minpq       priority_queue <ll,vector<ll>,greater<ll> > 
#define fill(x,y)   memset(x,y,sizeof(x))
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define mod         1000000007		//1e9+7
#define bp(n)       __builtin_popcountll(n)
#define mxt(a)      *(max_element(a.begin(),a.end()))
#define mnt(a)      *(min_element(a.begin(),a.end())
#define unique_sort(c) (sort(all(c)), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define rep(i, a, mp) for(ll i = (a); i<=(mp); ++i)
#define trav(a, x) 	  for(auto &a : x)
#define re(i,n)       for(ll i = 0; i < n; ++i) 
const int N = 5e5 + 7;
const ld eps=1e-7;
typedef pair<ll,ll>   pii;
typedef vector<pii>   vpii;
typedef vector<ll>    vll;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int dx[8]={+1, +1, +1, 0, 0, -1, -1, -1};
int dy[8]={+1, 0, -1, +1, -1, +1, 0, -1};
ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=(res*x);y=y>>1;x=(x*x);}return res;}
template <typename T> T gcd(T a,T mp){ if(a==0) return mp; return gcd(mp%a,a); }
template <typename T> T powm(T a,T mp, ll m){T cnt=1; while(mp>0){ if(mp%2==1) cnt=(cnt*a)%m; mp/=2; a=(a*a)%m; }return cnt%m;}
ll ncr(ll n,ll r){ll res=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){res*=(n-i);res/=(i+1);}return res;}
ll sqr(ll x) { return x * x;} 
void prec(){

}
ll dp[405][405],a[405],pre[405];
void run(){
	int n,i;cin>>n;	
	for(i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1; i<=n ;++i) pre[i]=pre[i-1]+a[i];
	for(i=1;i<=n;i++)
		dp[i][i]=a[i];
	for(int l=2;l<=n;l++)
	{
		for(i=1;i<=n-l+1;i++)
		{
			int j=i+l-1;
			dp[i][j]=1e14;
			for(int x=i;x<j;x++)
				dp[i][j]=min(dp[i][j],dp[i][x]+dp[x+1][j]+pre[j]-pre[i-1]);
		}
	}
	cout<<dp[1][n]-pre[n];
}
int main()
{
    cin.sync_with_stdio(0);cin.tie(0);
	cin.exceptions(cin.failbit);
    int tc=1;
    //cin>>tc;
    prec();
    re(i,tc)
    	run();
    return 0; 
}


Measured memory_bytes: 1536
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <stack>
#include <functional>
#include <sstream>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
#define N 1000000007
#define M 998244353

using namespace std;

int main(){
    lli n,m,h,a,b;
    vector<lli> hight,ans;
    lli i,j;
    cin>>n>>m;
    lli cnt=0;
    rep(i,0,n){
        cin>>h;
        hight.push_back(h);
        ans.push_back(1);
    }
    rep(i,0,m){
        cin>>a>>b;
        if(hight[a-1]>hight[b-1]){
            ans[b-1]=0;
        }
        else if(hight[a-1]<hight[b-1]){
            ans[a-1]=0;
        }
        else{
            ans[a-1]=0;
            ans[b-1]=0;
        }
    }
    rep(i,0,n){
//        cout<<ans[i]<<" ";
        if(ans[i]==1){
            cnt++;
        }
    }
//    cout<<endl;
    cout<<cnt<<endl;
}


Measured memory_bytes: 5092
using System.Linq;
using System.Text;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Diagnostics;
using System.Reflection.Metadata;
using System.Threading;
using System.Runtime.CompilerServices;

namespace AtCoder
{
    class Program
    {

        struct Point
        {
            public int x;
            public int y;

            public Point(int x, int y)
            {

                this.x = x;
                this.y = y;

            }

        }


        const int BiggestMod = 1000000007;

        public static void Main()
        {

            var t = Console.ReadLine().Select(x => x == 'S').ToArray();
            var res = new bool[]{ t[0] == t[1], t[1] == t[2], t[1] == false};
            var ans = 0;

            if (res[2])
            {
                if (res[0] && res[1]) ans = 3;
                else if (res[0] || res[1]) ans = 2;
                else ans = 1;
            }
            else if (t.Any(x => x == false)) ans = 1;
            Console.WriteLine(ans);

        }

    }

}

Measured memory_bytes: 26672
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]


MAX = 100000
N = int(input())

block = [1]
cnt = 6
while cnt <= MAX:
    block.append(cnt)
    cnt *= 6

cnt = 9
while cnt <= MAX:
    block.append(cnt)
    cnt *= 9

dp = [int(1e18)]*(MAX+1)
dp[0] = 0
for i in range(MAX):
    for e in block:
        if i + e <= MAX:
            dp[i+e] = min(dp[i+e], dp[i] + 1)

print(dp[N])



Measured memory_bytes: 41836
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define INF 999999999
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define Vecpr vector<pair<lli,lli>>
int main() {
  lli A,B,C,D;
  string a,b,c;
  cin >>A>>B>>C;
  D=A-B;
  C=A-C;
  if(D<0)D*=-1;
  if(C<0)C*=-1;
  if(D>C)Out('B');
  else Out("A");
}
  


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    void solve() {
        Int N, K;
        cin >> N >> K;
        vector<Int> A(N);
        for (int i = 0; i < N; ++i) {
            cin >> A[i];
        }
        Int max_s = 0;
        Int s = 0;
        for (int i = 0; i < N; ++i) {
            s += A[i];
            if (i - K >= 0) {
                s -= A[i - K];
            }
            chmax(max_s, s);
        }

        double ans = 0.5 * (max_s + K);
        cout << ans << endl;
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;

public class AtCoderB
{
    static void Main()
    {
        int k;
        int x;
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            k = int.Parse(words[0]);
            x = int.Parse(words[1]);
        }

        int min = Math.Max(-1000000, x - k + 1);
        int max = Math.Min(1000000, x + k - 1);

        string answer = "";
        for (int i = min; i <= max; i++)
        {
            answer += " " + i;
        }

        Console.WriteLine(answer.Trim());
    }
}

Measured memory_bytes: 13140
#include <stdio.h>
int main(void)
{
  int ab,bc,ca;
  int ans;
  //辺の長さ入力
  scanf("%d %d %d",&ab,&bc,&ca);
  if((ab*ab+bc*bc)==ca*ca){
    ans = ab*bc/2;
    printf("%d",ans);
  }
  return 0;
}


Measured memory_bytes: 128
//#define _XCODE_DEBUG

#include <iostream>
#include <vector>

#ifdef _XCODE_DEBUG
    #include <fstream>
#endif

int main() {
    #ifdef _XCODE_DEBUG
        std::ifstream in("input.txt");
        std::cin.rdbuf(in.rdbuf());
    #endif
    int N, M;
    std::cin >> N >> M;
    int m1, m2;
    std::vector<std::pair<int, int>> pair_vec;
    for (int i=0; i<M; ++i) {
        std::cin >> m1 >> m2;
        pair_vec.push_back(std::make_pair(m1-1, m2-1));
    }
    std::sort(pair_vec.begin(), pair_vec.end(), [](auto &l, auto &r) {
        return r.second > l.second;
    });
    
    // remove bridges
    int ans = 1, ind = pair_vec[0].second-1;
    for (int i=1; i<M; ++i) {
        if (pair_vec[i].first > ind){
            ind = pair_vec[i].second - 1;
            ++ans;
        }
    }
    std::cout << ans << "\n";
    return 0;
}

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

int main() {

  int N = 0, M = 0;
  cin >> N >> M;
  
  vector<int> A(M);
  int A_sum = 0;
  for(int i = 0; i < M; i++){
    cin >> A.at(i);
    A_sum += A.at(i);
  }
  
  if(N - A_sum >= 0){
    cout << N - A_sum << endl;
  }
  else{
    cout << -1 << endl;
  }
}


Measured memory_bytes: 3668
#include<stdio.h>



int count(int n, int s, int a)
{
	int i,result = 0;
	if (n == 1)
	{
		if (s >= a && s <= 9)
		{
			return 1;
		}
		else
		{
			return 0;
		}
	}

	for (i = a; i <= 9; i++)
	{
		result += count(n - 1, s - i, i + 1);
	}

	return result;
}




int main()
{
	int  n,s;

	while (1)
	{
		scanf("%d %d", &n,&s);
		if (n == 0 && s == 0)
		{
			break;
		}
		printf("%d\n",count(n,s,0));
	}
	
	return 0;
}


Measured memory_bytes: 600
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    int k;
    string s;
    cin >> k >> s;

    if (s.size() <= k) {
        cout << s << endl;
    } else {
        cout << s.substr(0, k) << "..." << endl;
    }

    return 0;
}

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

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i,n){
        cin >> p[i];
    }

    sort(p.begin(), p.end());
    int sum = 0;
    rep(i, k)
    {
        sum += p[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 3624
#include<iostream>

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;

    if((a-(b*2)) <= 0)
    {
        cout << "0" << endl;
    }
    else
    {
        cout << (a-(b*2)) << endl;
    }

    return 0;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <tuple>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

signed main() {
	int h;
	cin >> h;
	
	int i;
	for (i = 0; (1LL << i) <= h; i++);
	cout << (1LL << i) - 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
char s[N];
int main()
{
    int n,a,b,c,d,m,i,j,k,x=1,y,z,l=0,r=0;long long ans=0;
    scanf("%s",s+1);n=strlen(s+1);
    if(n<=2){printf("0\n");return 0;}
    for(i=1;i<=n-2;i++)
    {
        if(s[i]!='A')l=r=i;
        else if(x==1)r++;
        x=1;
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
        {

            swap(s[i],s[i+1]),swap(s[i+1],s[i+2]);
            ans+=r-l;
            r=i+2,l+=2;i+=1;x=0;continue;
        }

    }
    cout<<ans<<endl;
}


Measured memory_bytes: 384
import re

def makelist(n, m):
    return [[0 for i in range(m)] for j in range(n)]

N = int(input())

acgt = ["A", "C", "G", "T"]
changed = [".*AGC", ".*GAC", ".*ACG", ".*A.GC", ".*AG.C"]


# initialize
dp = {}
for a in acgt:
    for b in acgt:
        for c in acgt:
            now = a+b+c
            
            if any(map(lambda ch: re.match(ch, now), changed)):
                dp[now] = 0
            else:
                dp[now] = 1

N -= 3

MOD = int(1e9) + 7
# main
while N > 0:
    dpNow = {}
    for a in acgt:
        for b in acgt:
            for c in acgt:
                abc = (a + b + c)[:min(N, 3)]
                dpNow[abc] = 0
                for key, value in dp.items():
                    now = key + abc

                    if not any(map(lambda ch: re.match(ch, now), changed)):
                        dpNow[abc] += value
                        dpNow[abc] %= MOD
                        
    dp = dpNow
    N -= 3

ans = 0
for v in dp.values():
    ans += v
    ans %= MOD

print(ans)


Measured memory_bytes: 53980
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
using namespace std;
const ll N=500010;

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

	ll n,p;
	cin>>n>>p;
	string s;
	cin>>s;
	if(p==2)
    {
        ll ans=0;
        for(ll i=n-1;i>=0;--i)
        {
            int d=s[i]-'0';
            if(d%2==0)
            {
                ans+=(i+1);
            }
        }
        cout<<ans;
        return 0;
    }
    if(p==5)
    {
        ll ans=0;
        for(ll i=n-1;i>=0;--i)
        {
            int d=s[i]-'0';
            if(d==0||d==5)
            {
                ans+=(i+1);
            }
        }
        cout<<ans;
        return 0;
    }
	reverse(s.begin(),s.end());

	vector<ll> m(p+1,0);
	m[0]=1;
	ll ans=0;

	ll sum=0;
	ll a=1;
	for(ll i=0;i<n;++i)
    {
        int d=s[i]-'0';
        sum=(sum+ (a*d)%p )%p;
        //cout<<"!!"<<d<<" "<<sum<<endl;
        ans+=m[sum];
        m[sum]+=1;
        a=(a*10)%p;
    }
    cout<<ans;

	return(0);
}


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

using namespace std;

typedef long long ll;

int main() {
  int N;
  cin >> N;
  vector<ll> V(N);
  for (auto &x : V) cin >> x;
  vector<ll> W = V;
  sort(W.begin(), W.end());
  int B = W[N / 2];
  int C = W[N / 2 - 1];
  for (int i = 0; i < N; i++) {
    if (V[i] <= C) {
      cout << B << endl;
    } else {
      cout << C << endl;
    }
  }
}

Measured memory_bytes: 5376
#import math
#import itertools
#import numpy as np
#from collections import deque
# sys.setrecursionlimit(10 ** 6)
#MOD = 10 ** 9 + 7
#INF = 10 ** 9
#PI = 3.14159265358979323846

INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))

def do():
    s=STR()
    if s[-1]=='s':
        print(s+'es')
    else:
        print(s+'s')
if __name__=='__main__':
    do()

Measured memory_bytes: 9116
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<ctime>
#include<stack>
#include<queue>
#include<map>
#define size 300010
#define ll long long
#define db double
#define il inline
#define rint register int
#define gc getchar()
#define rep(i,s,n) for (register int i=s;i<=n;i++)
#define sro_zyb_orz int main()

using namespace std;

il ll r()
{
	char c; ll x,f=1;
	for (c=gc;!isdigit(c);c=gc) if (c=='-') f=-1; x=c-'0';
	for (c=gc;isdigit(c);c=gc) x=x*10+c-'0'; return x*f;
}

int n,a,s1,s2;
priority_queue<int> q;

sro_zyb_orz
{
	n=r(); rep(i,1,n) a=r(),q.push(a);
	while (!q.empty())
	{
		s1+=q.top(); q.pop(); 
		if (q.empty()) break;
		s2+=q.top(); q.pop(); 
 	}
	cout<<s1-s2<<endl;
 	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
typedef long long ll;
const int maxn=50;
const ll inf=1000000000000LL;
vector<int> g[maxn+5];
ll w[maxn+5],v[maxn+5];
int n,x,d,len;
ll dp[50*50*50+5];
vector<pair<ll,ll> > a;
void dfs(int k)
{
    v[k]=1;
    for(auto u:g[k])
    {
        dfs(u);
        v[k]+=v[u];
        w[k]+=w[u];
    }
}
struct wjmzbmr
{
    ll w,v,num;
}b[maxn+5];
bool cmp(const wjmzbmr x,const wjmzbmr y)
{
return 1.0*x.v/x.w>=1.0*y.v/y.w;
}
ll work()
{
    ll ans=0;
    for(int i=0;i<=125000;++i)
        if(dp[i]<=x)
        {
            ll res=i;
            ll now=x-dp[i];
            for(int j=1;j<=len;++j)
                if(b[j].num==inf||1.0*b[j].num*b[j].w>1.0*now)
                {
                    res+=now/b[j].w*b[j].v;
                    break;
                }
                else res+=b[j].num*b[j].v,now-=b[j].num*b[j].w;
            ans=max(ans,res);
        }
    return ans;
}
int main()
{
 
    scanf("%d%d%d",&n,&x,&d);
    scanf("%lld",&w[1]);
    for(int i=2;i<=n;++i)
    {
        int x;
        scanf("%lld%d",&w[i],&x);
        g[x].push_back(i);
    }
    dfs(1);
    for(int i=1;i<=n;++i)
    {
        int num=min(d,50);
        if(i==1) num=50;
        int pw=1;
        while(num>=pw)
        {
            a.push_back(mp(w[i]*pw,v[i]*pw));
            num-=pw;
            pw<<=1;
        }
        if(num) a.push_back(mp(w[i]*num,v[i]*num));
        if(i==1||d>50) b[++len]={w[i],v[i],d-50LL};
        if(i==1) b[len].num=inf;
    }
    //for(auto x:a) printf("%lld %lld\n",x.first,x.second);
    sort(b+1,b+len+1,cmp);
    //for(int i=1;i<=len;++i) printf("%lld %lld %lld\n",b[i].w,b[i].v,b[i].num);
    for(int i=0;i<=125000;++i) dp[i]=inf;
    dp[0]=0;
    for(auto x:a)
        for(int j=125000;j>=x.second;--j)
            dp[j]=min(dp[j],dp[j-x.second]+x.first);
    //for(int i=0;i<=50;++i) printf("%d : %lld\n",i,dp[i]);
    //printf("x : %d\n",x);
    printf("%lld\n",work());
    return 0;
}

Measured memory_bytes: 1280
def swap(x, y):
    t = x
    x = y
    y = t
    return x, y

l = list(map(int, input().split()))
l[0], l[1] = swap(l[0], l[1])
# Swap the contents of the boxes A and B
l[0], l[2] = swap(l[0], l[2])
# Swap the contents of the boxes A and C
print(*l)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
const ll mod = 1e9 + 7;

int main()
{
    int n, k;
    string s;
    cin >> n >> k >> s;
    int count = 0;
    rep(i, n - 1)
    {
        if (s[i] == s[i + 1])
            count++;
    }
    cout << min(n - 1, count + 2 * k) << endl;
    return 0;
}


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

#define f(i,n) for(int i=0;i<n;i++)

signed main(){
	int n,m;
	cin>>n>>m;
	int a[n];
	int total=0;
	f(i,n){ 
		cin>>a[i];
		total+=a[i];
	}
	int selectable=0;
	double criterai = total/(4.0*m);
	// cout<<criterai<<endl;
	f(i,n){
		if(a[i]>=criterai)
			selectable++;
		if(selectable>=m){
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;

}

Measured memory_bytes: 256
def main():
    from collections import namedtuple
    import sys
    input = sys.stdin.readline

    Sushi = namedtuple('Sushi', 'x cal')

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

    a = []
    for _ in range(n):
        x, v = map(int, input().split())
        a.append(Sushi(x=x, cal=v))
    # x昇順ソート済

    clock = [0] * (n + 1)  # 注目する寿司以前で離脱する最大摂取カロリー
    clock_to_0 = [0] * (n + 1)  # 時計回り->初期位置
    ma = 0  # 注目する寿司以前で離脱する最大摂取カロリー
    curr = 0  # 現在のカロリー(移動によるカロリー消費を無視)
    for i, s in enumerate(a, start=1):
        curr += s.cal
        ma = max(ma, curr - s.x)
        clock[i] = ma
        clock_to_0[i] = curr - s.x * 2

    anti = [0] * (n + 1)  # 注目する寿司以前で離脱する最大摂取カロリー
    anti_to_0 = [0] * (n + 1)  # 反時計回り->初期位置
    ma = 0  # 注目する寿司以前で離脱する最大摂取カロリー
    curr = 0  # 現在のカロリー(移動によるカロリー消費を無視)
    for i, s in zip(range(n, -1, -1), reversed(a)):
        curr += s.cal
        ma = max(ma, curr - (c - s.x))
        anti[i] = ma
        anti_to_0[i] = curr - (c - s.x) * 2

    ans = 0
    for exit_pos in range(1, n + 1):
        ans = max(
            ans,
            clock_to_0[exit_pos - 1] + anti[exit_pos],
            anti_to_0[(exit_pos + 1) % (n + 1)] + clock[exit_pos]
        )

    print(ans)


if __name__ == '__main__':
    main()


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

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

    auto pi = vector<int>(N);
    for (auto& x : pi)
    {
        cin >> x;
        x--;
    }

    auto inverse = vector<int>(N);
    for (auto i = 0; i < N; i++)
        inverse[pi[i]] = i;

    for (auto i = 0; i < N; i++)
        cout << i*N + 1 << " " ;
    cout << endl;

    for (auto i = 0; i < N; i++)
        cout << (N-i)*N + inverse[i] + 1 << " ";
    cout << endl;
}


Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  string s;
  cin >> s;
  int a=s[0]-'0';
  int b=s[1]-'0';
  int c=s[2]-'0';
  int d=s[3]-'0';
  rep(bit,1<<3){
    auto f=[&](int i){return bit>>i&1; };
    int x=a;
    x += f(0)?b:-b;
    x += f(1)?c:-c;
    x += f(2)?d:-d;
    if(x==7){
      s.insert(1,f(0)?"+":"-");
      s.insert(3,f(1)?"+":"-");
      s.insert(5,f(2)?"+":"-");
      s+="=7";
      break;
    }
  }
  cout << s << endl;
}


Measured memory_bytes: 256
(defun solve (n monsters warriors)
  (let ((all-monsters (reduce #'+ monsters)))
    (dotimes (i n)
      (let ((delta (min (aref warriors i) (aref monsters i))))
        (decf (aref monsters i) delta)
        (setf (aref monsters (1+ i))
              (max 0 (- (aref monsters (1+ i)) (- (aref warriors i) delta))))))
    (- all-monsters (reduce #'+ monsters))))

#-swank
(let* ((n (read))
       (monsters (make-array (1+ n) :element-type 'fixnum))
       (warriors (make-array n :element-type 'fixnum)))
  (loop for i from 0 to n
        do (setf (aref monsters i) (read)))
  (loop for i from 0 below n
        do (setf (aref warriors i) (read)))
  (format t "~A~%" (solve n monsters warriors)))


Measured memory_bytes: 59876
#include <vector>
#include <utility>
#include <queue>
#include <cmath>
#include <algorithm>
#include <iostream>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

const string YES = "Yes";
const string NO = "No";

//void solve(long long N, long long K, long long Q, std::vector<long long> A){
  //std::vector<bool> passed(N, true);

  //priority_queue< pair<ll, ll> > que; // (-正解数, 番号) のペア

  //for(ll i=0; i<N; i++){
    //que.push(make_pair(-0ll, i));
  //}

  //for(ll round=0; round<Q; round++){
    //ll a = A[round];


    //// round 回目までには、 (round - K)/2 回以上正解しないと生き残れない。
    //while((que.size() > 0) && (-2*que.top().first))
    
  //}
//}
//

void solve(long long N, long long K, long long Q, std::vector<long long> A){
  vector<ll> X(N, K-Q);

  for(ll i=0; i<Q; i++){
    X[A[i]-1] ++;
  }

  for(ll n=0; n<N; n++){
    //cerr << X[n] << endl;
    if(X[n] > 0){
      cout << YES << endl;
    } else {
      cout << NO << endl;
    }
  }
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    long long Q;
    scanf("%lld",&Q);
    std::vector<long long> A(Q);
    for(int i = 0 ; i < Q ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, K, Q, std::move(A));
    return 0;
}


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

using namespace std;

//typedef pair<int,int> P;
typedef long long ll; 

#define int ll


main(){
	int n,k;
	cin >> n >> k;
	
	int a[n];
	for(int i=0;i<n;i++){
		cin >> a[i];
		a[i]--;
	}

	int cnt[n]={0};
	int p = 0;
	int l = 0;
	int r = 0;
	for(int i=0;i<k;i++){
		cnt[p]++;
		if(cnt[p]==2 && l==0){
			l = i;
		}
		if(cnt[p]==3){
			l = i - l;
			r = (k-i) % l;
			break;
		}
		p = a[p];
	}
	for(int i=0;i<r;i++){
		p = a[p];
	}
	
	cout << p+1 << endl;
	return 0;
}

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

int main() {
  int A, B, C, five = 0, seven = 0;
  cin >> A >> B >> C;

  if (A == 5) five++;
  if (A == 7) seven++;
  if (B == 5) five++;
  if (B == 7) seven++;
  if (C == 5) five++;
  if (C == 7) seven++;

  if (five == 2 & seven == 1) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256