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

using namespace std;

using ll = long long;

ll A[20];
ll X[20][20];
ll Y[20][20];

int counter(int x) {
    if (x == 0) return 0;
    return counter(x >> 1) + (x & 1);
}

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

    for (int i = 1; i <= N; i++) {
        cin >> A[i];
        for (int j = 1; j <= A[i]; j++) {
            cin >> X[i][j] >> Y[i][j];
        }
    }

    int ans = 0;
    for (unsigned int bits = 1; bits < (1 << N); bits++) {
        bool ok = true;
        for (int i = 1; i <= N; i++) {
            if (!(bits & (1 << (i - 1)))) continue;
            for (int j = 1; j <= A[i]; j++) {
                if (((bits >> (X[i][j]-1)) & 1) ^ Y[i][j]) ok = false;
            }
        }
        if (ok) ans = max(ans, counter(bits));
    }
    cout << ans << endl;

    return 0;
}


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

int main(){
	int H,W;
	cin>>H>>W;
	int sum = H*W;
	int h,w;
	cin>>h>>w;
	sum -= h*W;
	sum -= w*H;
	sum += h*w;
	cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    scanf("%d", &n);
    vector<int> s(n);
    int sm = 0;
    for(int i = 0; i < n; ++i){
        scanf("%d", &s[i]);
        sm += s[i];
    }
    if(sm % 10){
        printf("%d\n", sm);
    }
    else{
        sort(s.begin(), s.end());
        for(int i = 0; i < n; ++i){
            if(s[i] % 10){
                printf("%d\n", sm - s[i]);
                return 0;
            }
        }
        printf("0");
    }
    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
int main() {
    int a, b, c, d; cin >> a >> b >> c >> d;
    bool can = true;
    while(1){
        c -= b;
        a -= d;
        if(c <= 0){
            can = true;
            break;
        }
        if(a <= 0){
            can = false;
            break;
        }
    }

    if(can) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3672
#include <stdio.h>

int main(void)
{
	int w, n;
	int a, b, c;
	int amida[100];
	int kae;
	
	scanf("%d", &w);
	scanf("%d", &n);
	
	for (a = 0; a < w; a++) {
		amida[a] = a + 1;
	}
	for (a = 0; a < n; a++) {
		scanf("%d,%d", &b, &c);
		kae = amida[b-1];
		amida[b-1] = amida[c-1];
		amida[c-1] = kae;
	}
	for (a = 0; a < w; a++) {
		printf("%d\n", amida[a]);
	}
	
	return (0);
}	

Measured memory_bytes: 596
#include<cstdio>
inline int read()
{
	int x;char c;
	while((c=getchar())<'0'||c>'9');
	for(x=c-'0';(c=getchar())>='0'&&c<='9';)x=x*10+c-'0';
	return x;
}
#define MN 100000
int x[MN+5],z[MN+5],zn;long long p[MN+5],ans;
int main()
{
	int n=read(),s=read(),i,j=0,a,b;
	for(i=1;i<=n;++i)(x[i]=read())<s?j=i:0,p[i]=read();
	for(a=1,b=n;a<=j&&b>j;)
		if(p[b]>p[a])z[++zn]=a,p[b]+=p[a++];
		else z[++zn]=b,p[a]+=p[b--];
	while(a<=j)z[++zn]=a++;
	while(b>j)z[++zn]=b--;
	for(i=zn;i;--i)ans+=s<x[z[i]]?x[z[i]]-s:s-x[z[i]],s=x[z[i]];
	printf("%lld",ans);
}

Measured memory_bytes: 1664
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
 
   int a = sc.nextInt();
   int b = sc.nextInt();
   int c = sc.nextInt();
 
   if(a+b>=c) System.out.println("Yes");
   else System.out.println("No");
 }
}

Measured memory_bytes: 22996
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<set>
#include<map>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const int INF = 2000000000;

    ll N,M;
    ll A[101],X[101],C;
    std::string S,T;
    bool F=false;
    ll ans=0;
int main(){
    ios_base::sync_with_stdio(false);
    cin>>S;
    T="keyence";
    if(S==T||S.find(T)!=std::string::npos)F=true;
    REP(i,6){
        string x=T.substr(0,i+1),y=T.substr(i+1);
            if(S.substr(0,i+1)==x){
                for(int j=i+1;j<(signed)S.size();j++){
                    if(S.substr(j)==y){
                        F=true;
                    }
                }
            }
        }
    cout<<(F?"YES":"NO")<<endl;
    return 0;
}


Measured memory_bytes: 256
use std::collections::HashSet;
fn solve() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let m: usize = sc.read();
    let ps: Vec<(usize, String)> = (0..m)
        .map(|_| {
            let p: usize = sc.read();
            let s: String = sc.read();
            (p, s)
        })
        .collect();
    let mut ac = vec![0; n + 1];
    let mut wa = vec![0; n + 1];
    for ps in ps.iter() {
        if ps.1 == "AC" {
            ac[ps.0] = 1;
        } else if ps.1 == "WA" {
            if ac[ps.0] == 1 {
                continue;
            }
            wa[ps.0] += 1;
        }
    }
    let mut wa_cnt = 0;
    for i in 0..n + 1 {
        if ac[i] == 1 {
            wa_cnt += wa[i];
        }
    }
    println!("{} {}", ac.iter().fold(0, |sum, x| sum + x), wa_cnt);
}

fn main() {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024) // 64MB
        .spawn(|| solve())
        .unwrap()
        .join()
        .unwrap();
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 12668
#include<iostream>
#include<cstdio>
using namespace std;
int n;
int main()
{
   cin>>n;
   if(n%10==9)cout<<"Yes"<<endl;
   else if(n>=90&&n<=99)
   cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	var s []byte
	fmt.Scan(&s)
	var cnt int
	var p byte
	for i := range s {
		if s[i] != p {
			cnt++
		}
		p = s[i]
	}
	fmt.Println(cnt)
}

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

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

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


Measured memory_bytes: 2592
import sys
def input():
	return sys.stdin.readline().strip()

N, C = list(map(int, input().split()))
sushi = []
for i in range(N):
	sushi.append(tuple(map(int, input().split())))

sushi_sum = [0]
for i in range(N):
	sushi_sum.append(sushi_sum[-1] + sushi[i][1])


right_max = 0
right_list = []
left_max = 0
left_list = []
for i in range(N):
	if right_max < sushi_sum[i + 1] - sushi[i][0]:
		right_max = sushi_sum[i + 1] - sushi[i][0]
	right_list.append(sushi_sum[i + 1] - sushi[i][0])
	if left_max < sushi_sum[-1] - sushi_sum[i] - (C - sushi[i][0]):
		left_max = sushi_sum[-1] - sushi_sum[i] - (C - sushi[i][0])
	left_list.append(sushi_sum[-1] - sushi_sum[i] - (C - sushi[i][0]))

for i in range(1, N):
	right_list[i] = max(right_list[i - 1], right_list[i])
for i in range(N - 2, -1, -1):
	left_list[i] = max(left_list[i + 1], left_list[i])

right_left_max = 0
for i in range(N - 1):
	right_left_max = max(right_left_max, sushi_sum[i + 1] - 2*sushi[i][0] + left_list[i + 1])

left_right_max = 0
for i in range(1, N):
	left_right_max = max(left_right_max, sushi_sum[-1] - sushi_sum[i] - 2*(C - sushi[i][0]) + right_list[i - 1])

print(max(right_max, left_max, right_left_max, left_right_max))

Measured memory_bytes: 69852
{-# LANGUAGE DataKinds          #-}
{-# LANGUAGE ExplicitNamespaces #-}
{-# LANGUAGE KindSignatures     #-}
{-# LANGUAGE TypeOperators      #-}


import           Control.Exception (assert)
import           Data.List         (group, sort)
import           Data.Ratio        (denominator, numerator)
import           GHC.TypeLits      (type (+), KnownNat, Nat, type (^), natVal)

main :: IO ()
main = do
  n <- readLn
  s <- getLine
  assert (length s == n) $
    print $ solve s

type Modulus = 10 ^ 9 + 7

solve :: String -> Int
solve = subtract 1 . unModular' . product . map (fromIntegral . (+ 1) . length) . group . sort
  where
    unModular' :: Modular Int Modulus -> Int
    unModular' = unModular

newtype Modular a (modulus :: Nat) =
  Modular { unModular :: a }
  deriving (Eq)

instance Show a => Show (Modular a modulus) where
  show (Modular n) = show n

instance (Integral a, KnownNat modulus) => Num (Modular a modulus) where
  fromInteger           = toModular . fromInteger
  Modular n + Modular m = toModular $ n + m
  Modular n * Modular m = toModular $ n * m
  negate (Modular n)    = toModular $ negate n
  abs (Modular n)       = toModular $ abs n
  signum (Modular n)    = toModular $ signum n

instance (Integral a, KnownNat modulus) => Fractional (Modular a modulus) where
  recip m@(Modular n) = toModular $ modularReciprocal (fromInteger (natVal m)) n
  fromRational r = fromInteger (numerator r) / fromInteger (denominator r)

toModular :: (Integral a, KnownNat modulus) => a -> Modular a modulus
toModular n = let m = Modular $ n `mod` fromInteger (natVal m) in m

modularReciprocal :: Integral a => a -> a -> a
modularReciprocal modulus n = snd $ modularReciprocal' modulus n
  where
    -- modularReciprocal' n m = (x, y)
    -- n * x + m * y = 1
    modularReciprocal' _ 0 = notCoprimeError
    modularReciprocal' _ 1 = (0, 1)
    modularReciprocal' m l = (y, x - q * y)
      where
        (q, r) = m `divMod` l
        (x, y) = modularReciprocal' l r
    notCoprimeError =
      error $ unwords
        [ "divider"
        , parentheses $ showIntegral n
        , "must be coprime to modulus"
        , parentheses $ showIntegral modulus
        ]
    parentheses s = "(" ++ s ++ ")"
    showIntegral = show . toInteger


Measured memory_bytes: 12668
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<set>
#include<map>


using namespace std;

#define all(x) (x).begin(),(x).end()
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define y1 Emilia
#define forit(s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++)

#define N 400400
#define dracarys ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);

const ll mod = (ll)1e9 + 7;

int n;
string s;
int cnt[30];
int main(){
    dracarys
    cin >> n >> s;
    for(int i = 0; i < (int)s.size(); ++i)
        cnt[s[i] - 'a']++;
    ll ans = 1;
    for(int i = 0; i < 26; ++i){
        ans = (ans * (cnt[i] + 1)) % mod;
    }
    cout << ans - 1 << "\n";
    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in);) {
			String w = sc.next().toUpperCase();
			int sum = 0;
			while (true) {
				String t = sc.next();
				if (t.equals("END_OF_TEXT")) {
					break;
				}
				if (w.equals(t.toUpperCase())) {
					sum++;
				}
			}
			System.out.println(sum);
		}
	}
}



Measured memory_bytes: 26140
import java.util.*;
import java.util.Arrays;

public class Main{
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long m = x;
		long ans = 0;
		long money = 100;
		while(money<m){
			money=money+(long)(money*0.01);
			ans++;

			

		}
		System.out.println(ans);
		
		
	}
}











Measured memory_bytes: 27072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

/* 
 * g++ -std=c++17 A.cpp -o A
 */
int main() {
  ios_base::sync_with_stdio(false);
  int n, k;
  cin>>n>>k;
  cout << k * (int) pow(k-1, n-1) << endl;
}


Measured memory_bytes: 384
s = list(input())
count = 0

if s[2] == "1":
    if 0 <= int(s[3]) <= 2:
        count += 1
elif s [2] == "0":
    if  1 <= int(s[3]) <= 9:
        count += 1

if s[0] == "1":
    if 0 <= int(s[1]) <= 2:
        count += 2
elif s [0] == "0":
    if  1 <= int(s[1]) <= 9:
        count += 2

if count == 1:
    print("YYMM")
elif count == 2:
    print("MMYY")
elif count == 3:
    print("AMBIGUOUS")
else:
    print("NA")


Measured memory_bytes: 3064
import copy
def test(a_,n_):
    return abs(round(0.1/(n_-(a_+0.1))))

n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
a_max = max(a)
n_max = sum(x == a_max for x in a)
if n_max > 1:
    a_max_2 = a_max
    for _ in range(n):
        print(a_max)
else:
    #a_max_2=sorted(set(a))[-2]
    b = copy.copy(a)
    b.remove(a_max)
    a_max_2 = max(b)
    for i in a:
        x = test(i, a_max)
        print((1-x)*a_max + x*a_max_2)

Measured memory_bytes: 14556
function Main(input) {
  var maxM = parseInt(input.split(" ")[0]);
  var maxD = parseInt(input.split(" ")[1]);
  var output = 0;
  if(maxD < 22){
     console.log(output);
    return;
     }
  for(var i = 1; i <= maxM; i++){
    for(var j = 22; j <= maxD; j++){
      var tmp10 = parseInt(j.toString().split("")[0]);
      var tmp1 = parseInt(j.toString().split("")[1]);
      if(tmp1 <= 1){
         continue;
         }
      if(i == tmp10 * tmp1){
         output++;
         }
    }
  }
  console.log(output);
}

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


Measured memory_bytes: 21304
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <cassert>
#include <bitset>

using namespace std;

using int64 = long long;

/////////////////////
// Code starts here//
/////////////////////


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

    int N, M;
    cin >> N >> M;

    vector<pair<int, int>> req(M);
    for (int i = 0; i < M; i++) {
        cin >> req[i].first >> req[i].second;
        req[i].first--;
    }

    for (int i = 0; i < 1000; i++) {
        vector<int> digs;

        for (auto x = i; x; x /= 10) {
            digs.push_back(x % 10);
        }
        reverse(digs.begin(), digs.end());
    
        if (!i)
            digs.push_back(0);

        if (digs.size() != N)
            continue;

        bool ok = true;
        for (auto r: req) {
            if (digs[r.first] != r.second) {
                ok = false;
            }
        }
        if (ok) {
            cout << i << "\n";
            return 0;
        }
    }

    cout << -1 << "\n";

    return 0;
}


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

void solve(long long N, std::vector<long long> h)
{
    long long dp[N + 1] = {0}; /* 1-indexed */

    dp[2] = abs(h[2] - h[1]);
    for (long long i = 3; i <= N; i++)
    {
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
    }

    cout << dp[N] << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long N;
    scanf("%lld", &N);
    std::vector<long long> h(N + 1);
    for (int i = 1; i <= N; i++)
    {
        scanf("%lld", &h[i]);
    }
    solve(N, std::move(h));
    return 0;
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sorting_Three_Numbers
{
    class SortingThreeNumbers
    {
        static void Main()
        {
            string input = Console.ReadLine();
            string[] line = input.Split(' ');
            string answer = null;
            for (int i = 1; i < line.Length; i++)
            {
                for (int j = i; 0 < j; j--)
                {
                    if (int.Parse(line[j - 1]) > int.Parse(line[j]))
                    {
                        string a = line[j];
                        line[j] = line[j - 1];
                        line[j - 1] = a;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            for (int i = 0; i < line.Length; i++)
            {
                answer += line[i];
                if (i + 1 != line.Length)
                {
                    answer += " ";
                }
            }
            Console.WriteLine(answer);
        }
    }
}



Measured memory_bytes: 17920
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;
    set<int> st;
    int cnt=0;
    REP(i,N){
        int a; cin>>a;
        if(a<3200) st.insert(a/400);
        else cnt++;
    }
    int ans1=st.size();
    int ans2=st.size()+cnt;
    if(ans1==0) ans1=1;
    cout<<ans1<<' '<<ans2<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
//typedef long double ld;
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; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

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

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};
int main(){
  int N;  cin>>N;
  string s[N];
  rep(i,0,N) cin>>s[i];
  int a=0, b=0, c=0;
  ll ans = 0;
  rep(i,0,N){
    if(s[i][0]=='B' && s[i].back()=='A'){
      c++;
    }else if(s[i][0]=='B') b++;
    else if(s[i].back()=='A') a++;
    rep(j,0,s[i].size()-1){
      if(s[i][j]=='A' && s[i][j+1]=='B') ans++;
    }
  }
  if(a==0 && b==0) ans += max(c-1, 0);
  else{
    ans += c + min(a, b);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 768
#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <vector>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> II;
typedef pair<LL, II> III;
typedef priority_queue<III, vector<III>, greater<>> Queue;
static const LL INF = 1LL << 60;

LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
LL lcm(LL a, LL b) { return (a / gcd(a, b)) * b; }

#if 0
	auto possible = [&](LL t) {

		return false;
	};
	LL left = 1, right = 1000000000;
	while (right - left > 1) {
		LL mid = (left + right) / 2;
		if (possible(mid)) {
			left = mid;
		} else {
			right = mid;
		}
	}
#endif

static const long long MOD = 1000000007;
static const size_t MAX_N = 1000001;

struct modll {
	long long x;
	modll() { }
	modll(int _x) : x(_x) { }
	operator int() const { return (int)x; }
	modll operator+(int y) { return (x + y + MOD) % MOD; }
	modll operator+=(int y) { x = (x + y + MOD) % MOD; return *this; }
	modll operator-(int y) { return (x - y + MOD) % MOD; }
	modll operator-=(int y) { x = (x - y + MOD) % MOD; return *this; }
	modll operator*(int y) { return (x * y) % MOD; }
	modll operator*=(int y) { x = (x * y) % MOD; return *this; }
	modll operator/(int y) { return (x * modpow(y, MOD - 2)) % MOD; }
	modll operator/=(int y) { x = (x * modpow(y, MOD - 2)) % MOD; return *this; }
	static modll modinv(int a) { return modpow(a, MOD - 2); }
	static modll modpow(int a, int b) {
		modll x = a, r = 1;
		for (; b; b >>= 1, x *= x) if (b & 1) r *= x;
		return r;
	}
};

modll combination(LL n, LL r) {
	static modll fact[MAX_N + 1], inv[MAX_N + 1];
	if (!fact[0]) {
		fact[0] = 1;
		for (int i = 1; i <= MAX_N; ++i) {
			fact[i] = fact[i - 1] * i;
		}
		inv[MAX_N] = modll::modinv(fact[MAX_N]);
		for (int i = MAX_N; i >= 1; --i) {
			inv[i - 1] = inv[i] * i;
		}
	}
	if (r > n) {
		return 0;
	}
	return (fact[n] * inv[r]) * inv[n - r];
}

void solve(long long S) {
	vector<modll> dp(S + 1, 0);
	for (LL j = 3; j <= S; ++j) {
		dp[j] = 1;
	}
	LL loops = S / 3 + 2;
	modll ans = dp[S];
	for (LL i = 1; i < loops; ++i) {
		vector<modll> next(S + 1, 0);
		for (LL j = 3; j <= S - 3; ++j) {
			for (LL k = 3; j + k <= S; ++k) {
				next[j + k] += dp[k];
			}
		}
		dp = next;
		ans += next[S];
	}
	cout << ans << endl;
}

int main() {
    long long S;
	std::cin >> S;
	solve(S);
	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <unordered_map>

int main()
{
    int h, w, n;
    std::cin >> h >> w >> n;
    std::unordered_map<int64_t, int> map;
    for (int i = 0; i < n; ++i)
    {
        int a, b;
        std::cin >> a >> b;
        // 0-baseに変換
        --a;
        --b;

        for (int p_h = std::max(a - 2, 0); p_h <= std::min(a, h - 3); ++p_h)
        {
            for (int p_w = std::max(b - 2, 0); p_w <= std::min(b, w - 3); ++p_w)
            {
                ++map[static_cast<int64_t>(p_h) * w + p_w];
            }
        }
    }

    std::vector<int64_t> count(10);
    count[0] = static_cast<int64_t>(h - 2) * (w - 2);
    for (std::unordered_map<int64_t, int>::const_iterator it = map.begin(); it != map.end(); ++it)
    {
        --count[0];
        ++count[it->second];
    }

    for (int i = 0; i < 10; ++i)
    {
        std::cout << count[i] << std::endl;
    }
    return 0;
}


Measured memory_bytes: 36624
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define PB push_back
#define MP make_pair
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<29)
#define LLINF (1LL<<60)
#define MOD 1000000007
#define REP(i, n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;
typedef pair<int, int> P;

int main() {
    int n;
    cin >> n;
    cout << pow(n, 3) << endl;
    return 0;
}


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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }
template <class T1, class T2, class Pred = std::less<T2> >
struct sort_pair_second {
    bool operator()(const std::pair<T1,T2>&left, const std::pair<T1,T2>&right) {
        Pred p;
        return p(left.second, right.second);
    }
};

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

    string s; cin >> s;
    if ("ABC" == s) cout << "ARC" << endl;
    else cout << "ABC" << endl;
    return 0;
}

Measured memory_bytes: 3656
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
using namespace std;
using ll = int64_t;
using vi = vector<int>;
using vvi = vector<vi>;

vi color;

void dfs(int v, vector<vector<pair<int, int> > > &edge, int x) {
    if(color[v] != -1) {
        return;
    }
    color[v] = x%2;
    for(auto next:edge[v]){
        dfs(next.first, edge, x+next.second);
    }
    return;
}


int main() {
    int N, M;
    cin >> N;
    M = N-1;
    vector<vector<pair<int, int> > > edge(N,vector<pair<int, int> >());
    rep(i, M) {
        int u, v, w;
        cin >> u >> v >> w;
        edge[u-1].push_back(make_pair(v-1, w%2));
        edge[v-1].push_back(make_pair(u-1, w%2));
    }
    color.assign(N, -1);
    dfs(0, edge, 0);
    rep(i, N) {
        cout << color[i] << '\n';
    }
}

Measured memory_bytes: 8192
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;
vector<pair<ll,ll>> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}

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

#define MAX_N 110
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}

ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    
    return p;
}

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

int main(){
    ll a,b,count=0;
    cin >> a >> b;
    ll x=b-a;
    for (ll i=1;i<x;i++){
        count+=i;
    }
    cout << count-a << endl;
    return 0;
}



Measured memory_bytes: 256
def main():
    N, W = map(int, input().split())
    #dp[v] vとなる最小のＷ
    dp = [10**9+1 for _ in range(10**5+1)]
    for _ in range(N):
        w,v = map(int, input().split())
        for val in range(10**5, 1, -1):
            if val - v < 1:
                break
            dp[val] = min(dp[val], dp[val - v] + w)
        if dp[v] > w:
            dp[v] = w
    ans = 0
    for v, w in enumerate(dp):
        if w <= W:
            ans = max(ans, v)
    print(ans)
if __name__ == '__main__':
    main()

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

#define rep(i,x) for(int i=0;i<(int)(x);++i)

using Int = long long;
const int mo = 1e9+7;

Int N;

signed main()
{
    cin >> N;

    if (N % 2) {
        cout << 0 << endl;
        return 0;
    }

    N /= 2;

    long long ans = 0, b = 5;

    while (b <= N) {
        ans += N / b;
        b *= 5;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
n,x,y=map(int,input().split())

sets=[]
for i in range(n-1):
  sets.append([])

for i in range(n):
  for j in range(i+1,n):
    a=abs(x-(i+1))
    b=abs(y-(j+1))
    c=a+b+1
    if c>=(j-i):
      sets[j-i-1].append(1)
    else:
      sets[c-1].append(1)

for i in range(n-1):
  print(len(sets[i]))

Measured memory_bytes: 24948
#include <bits/stdc++.h>
using namespace std;
string s1,s2;
char c1,c2;
int main()
{
   cin>>c1>>c2;
   for(int i=1;i<=(int)c2-'0';i++)s1+=c1;
   for(int i=1;i<=(int)c1-'0';i++)s2+=c2;
   cout<<min(s1,s2)<<endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadLineInt();
            var hasuu = N % 1000;

            Console.WriteLine(hasuu == 0 ? 0 : 1000 - hasuu);
        }

        #region 使いまわし
        static string ReadLineStr() { return Console.ReadLine(); }

        static int ReadLineInt() { return Convert.ToInt32(Console.ReadLine()); }
        static (int, int) ReadLineInt2()
        {
            var temp = Console.ReadLine().Split(' ');
            return (Convert.ToInt32(temp[0]), Convert.ToInt32(temp[1]));
        }
        static (int, int, int) ReadLineInt3()
        {
            var temp = Console.ReadLine().Split(' ');
            return (Convert.ToInt32(temp[0]), Convert.ToInt32(temp[1]), Convert.ToInt32(temp[2]));
        }
        static List<int> ReadLineIntList()
        {
            var data = new List<int>();
            foreach (var temp in Console.ReadLine().Split(' '))
            {
                data.Add(Convert.ToInt32(temp));
            }

            return data;
        }

        static long ReadLineLong() { return Convert.ToInt64(Console.ReadLine()); }
        static (long, long, long) ReadLineLong3()
        {
            var temp = Console.ReadLine().Split(' ');
            return (Convert.ToInt64(temp[0]), Convert.ToInt64(temp[1]), Convert.ToInt64(temp[2]));
        }
        static List<long> ReadLineLongList()
        {
            var data = new List<long>();
            foreach (var temp in Console.ReadLine().Split(' '))
            {
                data.Add(Convert.ToInt64(temp));
            }

            return data;
        }
        #endregion
    }
}


Measured memory_bytes: 27496
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
 
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007;

bool visited[8][8];
string map[8] = {};

int main(){
    int n;cin >> n;
    int i = 1;
    int sum = 0;
    while(sum < n){
      sum += i;
      i++;
    }
    int not_choose = sum - n;
    for(int j = 1; j<i; j++){
      if(j != not_choose){
        cout << j << "\n";
      }
    }
}

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

#define ll long long

ll nc(ll x) {
  if (x == 0 || x == 1) {
    return 0;
  } else {
    return x * (x - 1) / 2;
  }
}

int main() {
  ll N;
  cin >> N;
  vector<ll> r(N+1);
  r[0] = 0;
  for (int i=0; i<N; i++) {
    ll A;
    cin >> A;
    r[i+1] = r[i] + A;
  }
  sort(r.begin(), r.end());

  ll cnt = 0, t = 1;
  for (int i=1; i<r.size(); i++) {
    if (r[i] == r[i-1]) {
      t++;
    } else {
      cnt += nc(t);
      t = 1;
    }
  }
  cnt += nc(t);

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 1792
import sys
from collections import Counter

def comb(n, r):
    if r > n:
        return 0
    r = min(r, n - r)
    if r == 0: return 1
    if r == 1: return n
    numerator = list(range(n-r+1, n+1))
    denominator = list(range(1, r+1))
    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
    return result

n, *a = map(int, sys.stdin.read().split())

def main():
    c = Counter(a)
    res = 0
    for v in c.values():
        res += comb(v, 2)

    for i in a:
        yield res - comb(c[i], 2) + comb(c[i]-1, 2)
        
if __name__ == "__main__":
    ans = main()
    print(*ans, sep='\n')

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;
#define NIL NULL

void inorder(Node);
void prerder(Node);
void insert(int);

Node root = NIL;

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while( x != NIL ){
    y = x;
    if( z->key < x->key ) x = x->left;
    else x = x->right;
  }

  z->parent = y;
  if( y == NIL ){
    root = z;
  }
  else if( z->key < y->key ){
    y->left = z;
  }
  else y->right = z;
}

void inorder(Node u){
  if( u->left != NIL ){
    inorder(u->left);
  }
  printf(" %d",u->key);
  if( u->right != NIL ){
    inorder(u->right);
  }
}

void preorder(Node u){
  printf(" %d",u->key);
  if( u->left != NIL ){
    preorder(u->left);
  }
  if( u->right != NIL ){
    preorder(u->right);
  }
}

int main(void){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

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

    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 11000
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N;
int A[200000];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  rep(i, N) cin >> A[i];
  if (A[0] != 0) {
    cout << -1 << "\n";
    return 0;
  }
  int cur = 0;
  long long sum = 0;
  for (int i=N-1; i>=0; i--) {
    cur = max(cur-1, 0);
    if (A[i] != cur) {
      if (cur > A[i]) {
        cout << -1 << "\n";
        return 0;
      }
      sum += A[i];
      cur = A[i];
    }
  }
  if (cur > 0) sum = -1;
  cout << sum << "\n";
  return 0;
}


Measured memory_bytes: 1152
#include <stdio.h>
#include <math.h>
int main(void){
	int a,b,c,i,j,cnt=0;
	scanf("%d",&a);
	for(i=0;i<a;i++){
		scanf("%d",&b);
		if(b==2){
			cnt++;
			goto start;
		}
		if(b<2 || b%2==0)
			goto start;
		c = sqrt(b);
		for(j=3;j<=c;j+=2){
			if(b%j==0)
				goto start;
		}
		cnt++;
		start:;
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<numeric>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<utility>
#include<sstream>
#include<complex>
#include<fstream>
#include<bitset>

using namespace std;

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

#define rep(i,N) for(int i=0;i<(N);i++)

int n, p;

int main() {
	while (cin >> n >> p&&n + p) {
		int cnt[100] = {};
		int now = 0;
		int k = p;
		while (1) {
			if (k > 0) {
				cnt[now]++;
				k--;
				if (k == 0 && cnt[now] == p) {
					cout << now << endl;
					break;
				}
			}
			else {
				k += cnt[now];
				cnt[now] = 0;
			}
			now = (now + 1) % n;
		}
	}
}

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

int main() {
	int h, a;
	cin >> h >> a;
	cout << (h + a - 1) / a << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
    
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		long a = sc.nextLong() - 1;
		long b = sc.nextLong();
		
		// 計算
		long result = 0L;
		long sumA = 0L;
		if(a%4 == 0) sumA = a;
		if(a%4 == 1) sumA = 1L;
		if(a%4 == 2) sumA = a + 1;
		if(a%4 == 3) sumA = 0L;
		long sumB = 0L;
		if(b%4 == 0) sumB = b;
		if(b%4 == 1) sumB = 1L;
		if(b%4 == 2) sumB = b + 1;
		if(b%4 == 3) sumB = 0L;
		result = sumA^sumB;
		
		// 出力
		System.out.println(result);
        
	}
}


Measured memory_bytes: 21972
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC112
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] nt = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[][] ct = new int[nt[0]][];
            int mincost = int.MaxValue;
            string ans = "";
            for (int i = 0; i < nt[0]; i++)
            {
                ct[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
                if (ct[i][1] <= nt[1] && ct[i][0] <= mincost) { mincost = ct[i][0]; }
            }
            if (mincost == int.MaxValue) { ans = "TLE"; }
            else { ans = mincost.ToString(); }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13396
x = list(map(int, input().split()))
a=[input() for i in range(x[1])]
count=[]

for i in range(0,x[0]+2):
    count=count+[[0,i]]

for i in a:
    i=list(map(int, i.split()))
    count[i[0]][0]+=1
    count[i[1]][0]+=1
   
  
for i in range (1,x[0]+1):
    print(count[i][0])


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

int main(){
    int n,T;
    cin>>n>>T;
    vector<int> t(n);
    for(int i=0;i<n;i++){
        cin>>t[i];
    }
    long long ans=0;
    for(int i=1;i<n;i++){
        ans+=min(T,t[i]-t[i-1]);
    }
    ans+=T;
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
def main():
  n, blue, red = input_list()
  d = n % (blue+red)
  if d == 0:
    print(blue * (n // (blue+red)))
  else:
    if d > blue:
      d = blue
    print(blue * (n // (blue+red))+d)
    
def input_list():
  return map(int, input().split())

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

import math
import fractions
from functools import reduce
main()

Measured memory_bytes: 5560
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e9+1
ll n,W;
struct item{
    ll Wt;
    ll val;
};
ll solve(vector<item> v){
    ll max_val=n*1000;
    ll dp[n+1][max_val+1];
    for(ll i=0;i<=max_val;i++){
        dp[1][i]=inf;
    }
    dp[1][0]=0;
    dp[1][v[1].val]=v[1].Wt;
    for(ll i=2;i<=n;i++){
        for(ll p=0;p<=max_val;p++){
            dp[i][p]=dp[i-1][p];
            if(p<v[i].val){continue;}
            dp[i][p]=min(dp[i][p],dp[i-1][p-v[i].val]+v[i].Wt);
        }
    }
    ll ans=0;
    for(ll i=0;i<=max_val;i++){
        if(dp[n][i]!=0 && dp[n][i]<=W){
            ans=i;
            
            //cout<<dp[n][i]<<" "<<ans<<endl;
        }
    }
    return ans;
}
int main(){
    
    cin>>n>>W;
    vector<item> v(n+1);
    for(ll i=1;i<=n;i++){
        cin>>v[i].Wt>>v[i].val;
    }
    
    cout<<solve(v);
    return 0;
}

Measured memory_bytes: 78336
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            String str = sc.next();
            if (str.equals("-")) {
                break;
            }
            int m = sc.nextInt();
            int[] h = new int[m];
            for (int i = 0; i < m; i++) {
                h[i] = sc.nextInt();
            }
            for (int j = 0; j < m; j++) {
                str = str.substring(h[j]) + str.substring(0, h[j]);
            }
            System.out.println(str);
        }
        sc.close();
    }
}


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

using namespace std;

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

  string s;
  uint64_t k;
  cin >> s >> k;
  for (size_t i = 0; i < s.size() && i < k; ++i) {
    if (s[i] != '1') {
      cout << s[i] << "\n";
      return 0;
    }
  }
  cout << "1\n";
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
typedef long long ll;
const int inf = 1000000001;
const ll INF = 1e18 * 4;
using namespace std;

int main(){
    int A, B;
    cin >> A >> B;
    A -= (B << 1);
    if(A<=0) cout << 0;
    else cout << A;
    cout << endl;
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>   // popen, pclose, fgets
#include <cstdlib> 
using namespace std;
#define rep0(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vvvi = vector<vvi>;
using ll = long long; //long longをllだけにした
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll =vector<vvll>;
const double PI=3.14159265358979323846;
//小数点以下を指定したい時　　→→→→  cout << fixed << setprecision();

int main() {
    int n,A[3][3],b[10];
    rep0(i,3){
        rep0(j,3){
            cin>>A[i][j];
        }
    }
    cin>>n;
    rep0(i,n){
        cin>>b[i];
    }
    bool mark[3][3];
    rep0(i,3){
        rep0(j,3){
            mark[i][j]=false;
            rep0(k,n){
                if(b[k]==A[i][j]){
                    mark[i][j]=true;
                }
            }
        }
    }
    string ans="No";
    rep0(i,3){
        if(mark[i][0] and mark[i][1] and mark [i][2]){
            ans="Yes";
        }
        if(mark[0][i] and mark[1][i] and mark [2][i]){
            ans="Yes";
        }
    }
    if(mark[0][0] and mark[1][1] and mark[2][2]){
        ans="Yes";
    }
     if(mark[0][2] and mark[1][1] and mark[2][0]){
        ans="Yes";
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3620
a = Array.new(1000000,true)

i=3
while i<1000
  if a[i] == true
    j = 3*i
    while j<1000000
      a[j] = false
      j = j + 2*i
    end
  end
  i = i+1
end

while n = gets
  n = n.chomp.to_i
  if n<2
    print 0, "\n"
  elsif n==2
    print 1, "\n"
  else
    c=1
    i=3
    while i<=n
      c += 1 if a[i]
      i += 2
    end
    print c, "\n"
  end
end

Measured memory_bytes: 13904
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i, MAT.size()){
    REP(j, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(void){
      return;
    };
    HOGE(CLASS1 key, CLASS2 value){
      this->key = key;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;

ll _753_vec[3] = {3, 5, 7};

ll calc_753(ll index, const ll digits){
  ll tmp = 0;
  vll tmp_vec(digits);
  REP(i, digits){
    tmp_vec[i] = index%3;
    index/=3;
  }
  REP(i, digits){
    tmp *= 10;
    tmp += _753_vec[tmp_vec[digits-i-1]];
  }
  return tmp;
};

bool is_753(ll num){
  vll tmp(10);
  while(num>0){
    if(num%10==3 || num%10==5 || num%10==7){
      tmp[num%10]++;
    }else{
      return false;
    }
    num/=10;
  }
  return (tmp[3]>0 && tmp[5]>0 && tmp[7]>0);
};

void add_cand(const ll digits, vll& cand){
  ll _max = 1;
  REP(i, digits) _max*=3;
  REP(i, _max){
    ll tmp = calc_753(i, digits);
    if(is_753(tmp)) cand.push_back(tmp);
  }
};

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N, N_tmp;
  cin >> N;
  N_tmp = N;
  ll digits=0;
  while(N_tmp>0){
    digits++;
    N_tmp/=10;
  }

  vll cand;
  FOR(i, 1, digits+1){
    add_cand(i, cand);
  }

  //search ten ~ N
  
  ll ans=0;
  FOR(i, 0, cand.size()){
    if(cand[i]<=N) ans++;
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 640