akhauriyash/Code-Regression huggingface dataset:
//Zory-2018
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<vector>
#include<algorithm>
#include<iostream>
using namespace std;

namespace mine
{
    typedef long long ll;
    const ll MOD=998244353;
	ll bin[4100];
	
	ll c[4100][4100];
	ll C(int n,int m) {return c[n][m];}
	
	ll C2(int n,int m) {return C(n-1+m,n-1);}
	ll solve(int i,int K,int n)
	{
		int tot=(i-1<=K)?(i-1):(2*K-i+1);
		tot=floor( (double)tot/2 );
		int oth=K-tot*2-((i%2)==0);
		
		ll ans=0;
		for(int k=0;k<=tot and k<=n;k++)
			if(oth+k>0)//debug
				ans+=C(tot,k)*C2(oth+k,n-k)%MOD*bin[k]%MOD,ans%=MOD;
		return (ans+MOD)%MOD;
	}
    void main()
    {
    	bin[0]=1;
		c[0][0]=1;
    	for(int i=1;i<4100;i++)
    	{
    		bin[i]=bin[i-1]*2%MOD;
			c[i][0]=1;
			for(int j=1;j<=i;j++) c[i][j]=(c[i-1][j-1]+c[i-1][j])%MOD;
		}
	
		int K,n;scanf("%d%d",&K,&n);
		for(int i=2;i<=2*K;i++)
			if(i%2==0) printf("%lld\n",(solve(i,K,n)+solve(i,K,n-1))%MOD);
			else printf("%lld\n",solve(i,K,n));
    }
};

int main()
{
    mine::main();
}

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

namespace ConsoleApp5
{
    class Program
    {

        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int res = 1000 - (N % 1000);
            if (res == 1000)
            {
                res = 0;
            }
            Console.WriteLine(res);
        }
    }
}

Measured memory_bytes: 27520
def main():
    from builtins import int, map, list, print, len
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = (lambda: (sys.stdin.readline()).rstrip())
    input_list = (lambda: input().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

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


if __name__ == '__main__':
    main()


Measured memory_bytes: 9276
N=int(input())
a=[0]*N
#b=[""]*N
#cnt=[0]*50
a=list(map(int,input().split()))
sum=0
for i in range(N):
    #b[i]=format(a[i],'b')
    sum=sum^a[i]

if(sum==0):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 14980
import java.util.*;
import java.math.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        final Map<String, Integer> cnt = new HashMap<>();
        {
            cnt.put("SUN", 7);
            cnt.put("MON", 6);
            cnt.put("TUE", 5);
            cnt.put("WED", 4);
            cnt.put("THU", 3);
            cnt.put("FRI", 2);
            cnt.put("SAT", 1);
        };


        int shift = in.nextInt();
        StringBuilder s = new StringBuilder(in.next());
        for (int i = 0; i < s.length(); ++i) {
            char newChar = (char)(s.charAt(i) + shift);
            if (newChar > 'Z') {
                newChar -= 'Z';
                newChar += ('A' - 1);
            }
            s.setCharAt(i, newChar);
        }
        out.println(s.toString());

        in.close();
        out.close();
    }
    static class Pair {
	  		public long first;
	  		public long second;

	  		public Pair() {
	  			this(0, 0);
	  		}

	  		public Pair(final long first, final long second) {
	  			this.first = first;
	  			this.second = second;
	  		}
	  	}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<< "\n"


int main(){
    int h,w;
    while(cin>>h>>w){
        if(h==0&&w==0) break;
        REP(i,h){
            REP(j,w){
                if((i+j)%2==0)cout<<'#';
                else cout<<'.';
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3092
import sys
input = sys.stdin.readline
H,W,K =list(map(int,input().split()))
s = [input().rstrip() for _ in range(H)]
cut = [[0]*W for _ in range(H)]
cnt =0
for ih in range(H):
    if s[ih].count('#')==0:
        continue
    else:
        for iw in range(W):
            if s[ih][iw] == '#':
                cnt +=1
                cut[ih][iw]= cnt

for ih in range(H):
    for iw in range(W-1):
        if cut[ih][iw+1] ==0:
            cut[ih][iw+1]= cut[ih][iw]
    for iw in range(W-1,0,-1):
        if cut[ih][iw-1] ==0:
            cut[ih][iw-1]= cut[ih][iw]
        
for ih in range(H-1):
    if cut[ih+1][0]==0:
        for iw in range(W):
            cut[ih+1][iw] = cut[ih][iw]
for ih in range(H-1,0,-1):
    if cut[ih-1][0]==0:
        for iw in range(W):
            cut[ih-1][iw] = cut[ih][iw]
for i in range(H):
    print(*cut[i])


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

#define ms(s, n) memset(s, n, sizeof(s))
#define f(i, a, b) for (int i = (a); i <=(b); i++)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<ll> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int MOD2 = MOD + 2; //1007681537;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) - 1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
int modulo(int a, int b) { return (a % b + b) % b; }
#define db(x) cerr << #x << " = " << (x) << " ";
#define endln cerr << "\n";

int main()
{
	IOS;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll n;
	cin >> n;
	vi a(n);
	f(i, 0, n - 1) {
		cin >> a[i];
	}
	ll curmax = 0, ans = 0;
	f(i, 0, n - 1) {
		curmax = max(curmax, a[i]);
		if (curmax > a[i]) {
			ans += curmax - a[i];
		}
	}
	cout << ans << endl;
	// read the stuff at the bottom
	return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* use int when constraints limits are tight
	* Time taken : global variable < pass by refernce < pass by value
	* It takes significant amt. of time in pass by value
*/





























Measured memory_bytes: 4792
const lines = require("fs")
  .readFileSync("/dev/stdin", "utf8")
  .trim()
  .split("\n");

const p = lines[1].split(" ").map(n => Number.parseInt(n));

const solver = () => {
  let count = 0;
  for (let i = 0; i < p.length; i++) {
    if (p[i] !== i + 1) {
      count++;
      if (count > 2) {
        return "NO";
      }
    }
  }
  return "YES";
};

console.log(solver());


Measured memory_bytes: 7372
import math
import copy
import sys

inputa = input().split()
# inputb = input().split()
# inputc = input().split()

a = int(inputa[0])
# b = int(inputa[1])
# c = int(inputa[2])

# x = int(inputb[0])
# y = int(inputb[1])

# inputaList = [int(n) for n in inputa]

# inputb = input().split()
# inputbList = [int(n) for n in inputb]
#
# inputList = []
# inputNumList = []
# for i in range(a):
#     inputNum = input()
#     inputNumList = list(inputNum)
#     inputList.append(inputNumList)

# inputList = [int(n) for n in inputList]

# b = [int(n) for n in inputb]
# c = [int(n) for n in inputc]

kaimen = int(a/7)+1

flg = False
for i in range(kaimen):
    if int(a - 7*i) % 4 == 0:
        flg = True
        break

if flg:
    print("Yes")
else:
    print("No")








Measured memory_bytes: 3444
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include<complex>
#include<functional>
#include<climits>
#include<cassert>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>

using namespace std;

int h;
int w;

int n;

vector<pair<int, int> > v;
int flag[200002];
set<pair<int, int> > s;
bool ok(int x) {
	if (x == h + 1)return true;
	memset(flag, -1, sizeof(flag));
	for (int i = 0; i < v.size(); i++) {
		if (v[i].first <= x) {
			flag[v[i].second] = max(flag[v[i].second], v[i].first);
		}
	}
	int pos_x = 1;
	int pos_y = 1;
	while (pos_y < x) {
		if (flag[pos_x] >= pos_y)return true;
		pos_y++;
		if (s.count(make_pair(pos_y, pos_x + 1)) == 0) {
			pos_x++;
		}
	}
	return false;
}
int main() {
	cin >> h >> w>>n;
	for (int i = 0; i < n; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		v.push_back(make_pair(x, y));
		s.insert(make_pair(x, y));
	}
	sort(v.begin(), v.end());
	int mint = 1;
	int maxt = h+1;
	while (mint + 1 < maxt) {
		int mid = (mint + maxt) / 2;
		if (ok(mid)) {
			maxt = mid;
		}
		else {
			mint = mid + 1;
		}
	}
	if (ok(mint)) {
		maxt = mint;
	}
	else {
		mint = maxt;
	}
	cout << mint-1 << endl;
	return 0;
}

Measured memory_bytes: 12016
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;

int main() {
  int n; cin >> n;
  vector<ll> res(n+1);

  priority_queue<int, vector<int>, greater<int>> lque;
  for (int i = 0; i < n; i++) {
    int a; cin >> a;
    res[0] += a;
    lque.push(a);
  }

  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    res[i+1] += res[i] + v[i];
    lque.push(v[i]);
    res[i+1] -= lque.top(); lque.pop();
  }

  ll sum = 0;
  priority_queue<int> rque;
  for (int i = 0; i < n; i++) {
    int a; cin >> a;
    sum += a;
    rque.push(a);
  }

  ll ans = res[n] - sum;
  for (int i = n-1; i >= 0; i--) {
    sum += v[i];
    rque.push(v[i]);
    sum -= rque.top(); rque.pop();
    ans = max(ans, res[i] - sum);
  }
  cout << ans << endl;
}

Measured memory_bytes: 2680
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pi acos(-1)
#define pb push_back
#define all(v) v.begin(),v.end()
using namespace std;
typedef pair<int,int> p;
typedef long long ll;

int main(){
	int n;
	cin>>n;
	ll a[n],b[n],c[n],tmp[n];
	rep(i,n)cin>>a[i];
	rep(i,n)cin>>b[i];
	rep(i,n)cin>>c[i];
	sort(a,a+n);
	sort(b,b+n);
	sort(c,c+n);
	ll res=0;
	rep(i,n){
		int cnt1=lower_bound(a,a+n,b[i])-a;
		int cnt2=upper_bound(c,c+n,b[i])-c;
		res+=(ll)cnt1*(n-cnt2);
	}
	cout<<res<<endl;
	return 0;
}

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

int main(void)
{
    int N;
    cin >> N;
    int M[3];
    
    for( int i = 0; i < 3; i++){
        M[i] = N % 10;
        N /= 10;
    }

    if( M[0] == M[2] ){
        cout << "Yes";
    }else{
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
ans = 0
max_L,min_R = map(int,input().split())
for i in range(M-1):
    L,R = map(int,input().split())
    if max_L < L:
        max_L = L
    if min_R > R:
        min_R = R
print(len([i for i in range(max_L,min_R+1)]))


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

struct UnionFind{
    int num;
    vector<int> par,rank;
    UnionFind(int n):num(n),par(n),rank(n,1){
        iota(par.begin(),par.end(),0);
    }
    int root(int x){
        return (par[x]==x?x:par[x]=root(par[x]));
    }
    bool merge(int x, int y){
        x=root(x),y=root(y);
        if (x==y) return false;
        // if (rank[x]<rank[y]) swap(x,y);
        par[y]=x;
        rank[x]+=rank[y];
        --num;
        return true;
    }
    bool same(int x, int y){return root(x)==root(y);}
    int size(int x){return rank[root(x)];}
    int count(){return num;}
};

const int MAX_N=1e5+10,MAX_Q=1e5+10;

int N,Q;
vector<int> G[MAX_N];
int p[MAX_N],V[MAX_N],Mark[MAX_N],par[MAX_N];
char c[MAX_Q];

void dfs(int v,int p,int D){
    par[v]=D;
    for (int u:G[v]){
        if (u==p) continue;
        dfs(u,v,(Mark[u]?u:D));
    }
}

void solve(){
    for (int i=0;i<N;++i) G[i].clear(),Mark[i]=0;
    for (int i=1;i<N;++i) G[p[i]].emplace_back(i);
    for (int i=0;i<Q;++i) if (c[i]=='M'){
        ++Mark[V[i]];
    }
    dfs(0,-1,0);
    UnionFind uf(N);
    for (int i=1;i<N;++i) uf.merge(par[i],i);
    long long ans=0;
    for (int i=Q-1;i>=0;--i){
        if (c[i]=='M'){
            if (--Mark[V[i]]==0) uf.merge(p[V[i]],V[i]);
        } else ans+=uf.root(V[i])+1;
    }
    cout << ans << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> N >> Q,N,Q){
        for (int i=1;i<N;++i) cin >> p[i],--p[i];
        for (int i=0;i<Q;++i) cin >> c[i] >> V[i],--V[i];
        solve();
    }
}


Measured memory_bytes: 15732
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

    int ans=INF;
    int n=s.size();
    for(int i=1;i<n;i++){
        if(s[i]==s[i-1]) continue;
        ans=min(max(i,n-i),ans);
    }
    if(ans==INF) ans=n;
    cout<<ans<<endl;
    return 0;
}


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

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

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

  int ans = A[0];
  for(int i=1; i<N; ++i)
    ans = gcd(ans, A[i]);

  cout << ans << endl;
}


Measured memory_bytes: 640
package main

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

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}

func printarray(a []int) {
	for i := 0; i < len(a); i++ {
		fmt.Printf("%d", a[i])
		if i != len(a)-1 {
			fmt.Printf(" ")
		}
	}
	fmt.Println()
}
func isort(a []int) {
	for i := 1; i < len(a); i++ {
		v := a[i]
		j := i - 1
		for j >= 0 && a[j] > v {
			a[j+1] = a[j]
			j--
		}
		a[j+1] = v
		printarray(a)
	}
}

func main() {
	var N int
	fmt.Scan(&N)
	a := make([]int, N)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := 0; i < N; i++ {
		a[i] = nextInt(sc)
	}
	printarray(a)
	isort(a)
}



Measured memory_bytes: 1244
package main

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

func main() {
	sc := NewScanner()

	mp := map[string]int{}
	n := sc.NextInt()
	random := 0
	for i := 0; i < n; i++ {
		tmp := sc.NextInt()
		if tmp < 400 {
			mp["gray"]++
		}
		if tmp >= 400 && tmp < 800 {
			mp["brown"]++
		}
		if tmp >= 800 && tmp < 1200 {
			mp["green"]++
		}
		if tmp >= 1200 && tmp < 1600 {
			mp["water"]++
		}
		if tmp >= 1600 && tmp < 2000 {
			mp["blue"]++
		}
		if tmp >= 2000 && tmp < 2400 {
			mp["yellow"]++
		}
		if tmp >= 2400 && tmp < 2800 {
			mp["orange"]++
		}
		if tmp >= 2800 && tmp < 3200 {
			mp["red"]++
		}
		if tmp >= 3200 {
			random++
		}
	}
	mx := len(mp) + random

	min := 0
	if len(mp) > 0 {
		min = len(mp)
	} else {
		min = 1
	}
	fmt.Printf("%d %d\n", min, mx)
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
import itertools

N,M,Q=list(map(int,input().split()))
s = [list(map(int,input().split())) for i in range(Q)]
int_list=[i for i in range(1,M+1)]
score_list=[]
for v in itertools.combinations_with_replacement(int_list, N):
  score=0
  for list_s in s:
    if v[list_s[1]-1]-v[list_s[0]-1]==list_s[2]:
      score+=list_s[3]
  score_list.append(score)

print(max(score_list))


Measured memory_bytes: 12704
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<ll,double> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl; 有効桁数指定
// *min_element(c + l, c + r) *max_element(c + l, c + r) 配列の中のmin-max
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// ~ は、-1の時だけfalse

int six(int k) {
    if(k==0) return 0;
    int num = 1;
    while(1) {
        if(k < num * 6) break;
        num*=6; 
    }
    int cnt = 0;
    while(1) {
        if(num > k) {
            num/=6;
            continue;
        }
        int ans = k/num;
        cnt += ans;
        k -= ans * num;
        num/=6;
        if(k==0) break;
    }
    return cnt;
}

int nine(int k) {
    if(k==0) return 0;
    int num = 1;
    while(1) {
        if(k < num * 9) break;
        num*=9; 
    }
    int cnt = 0;
    while(1) {
        if(num > k) {
            num/=9;
            continue;
        }
        int ans = k/num;
        cnt += ans;
        k -= ans * num;
        num/=9;
        if(k==0) break;
    }
    return cnt;
}

int main() {
    int n;cin>>n;
    ll ans = 100010;
    rep(i,n+1) {
        ans = min(ans,ll(six(i)+nine(n-i)));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3676
cat<<EOF>Source.c

int printf (const char *__restrict __format, ...);
int scanf (const char *__restrict __format, ...) ;

int max(int a,int b){
	return a>b?a:b;
}
int x[100000],y[100000],x_mod_k[100000],x_div_k[100000];
char s[100000][2];
int n,k;

void add(int*cnt,int x,int t){
	if((x_div_k[x]&1)==0){
		if(t==0){
			cnt[0]++;
			cnt[k-x_mod_k[x]]--;
		}
		else{
			cnt[k-x_mod_k[x]]++;
		}
	}
	else{
		if(t==0){
			cnt[k-x_mod_k[x]]++;
		}
		else{
			cnt[0]++;
			cnt[k-x_mod_k[x]]--;
		}
	}
}
int ans[2000];
int main(){
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%d%d%s",&x[i],&y[i],s[i]);
		x_mod_k[i]=y[i]%k;
		x_div_k[i]=y[i]/k;
	}
	int Max=0;
	#pragma omp parallel for num_threads(2)
	for(int i=0;i<k;i++){
		int d=max(n,k);
		int cnt[d];
		for(int j=0;j<d;j++)cnt[j]=0;
		for(int j=0;j<n;j++){
			if(s[j][0]=='B'){
				if(((x[j]+i)/k)%2==0){
					add(cnt,j,0);
				}
				else{
					add(cnt,j,1);
				}
			}
			else{
				if(((x[j]+i)/k)%2==0){
					add(cnt,j,1);
				}
				else{
					add(cnt,j,0);
				}
			}
		}
		for(int j=0;j<k;j++){
			if(j)cnt[j]+=cnt[j-1];
			ans[i]=max(ans[i],max(cnt[j],n-cnt[j]));
		}
	}
	for(int i=0;i<k;i++)Max=max(Max,ans[i]);
	printf("%d\n",Max);
}
EOF
gcc -Ofast Source.c -o Source -fopenmp -std=gnu11
./Source

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

int main() {
	int a, n, min, max;
	cin >> n;
	cin >> a;
	min = a;
	cin >> a;
	max = a - min;
	(min > a) && (min = a);
	for (int i = 0; i < n - 2; i++) {
		cin >> a;
	(max < (a - min)) && (max = (a - min));
	(min > a) && (min = a);
	}		
	cout << max << endl;
	return 0;
}

Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define PI 3.14159265359
int main(){
    int N=10000;
    vector<int> a(N,0);
    cin>>a[0];
    int mini=10000000;
    for(int i=1;i<N;i++){
        if(a[i-1]%2==0){
            a[i]=a[i-1]/2;
        }
        else{
            a[i]=3*a[i-1]+1;
        }
        for(int j=0;j<i;j++){
            if(a[i]==a[j]){
                mini=min(mini,i+1);
            }
        }
    }
    cout<<mini;
    return 0;
}

Measured memory_bytes: 256
/*
/ ￣￣￣＼　
|　ー　ー \　
|　 ◉　◉ |   / ￣￣￣ ＼
\ 　  ▱ 　 / ∠    114514
＼　　 イ    \
／　　　＼    \_________/
/　|　　 \ \　
|　|　　　 | |
*/
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string.h>
#include<queue>
#include<set>
#include<string>
#include<sstream>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

namespace FastIO{
    const int SIZE = 1 << 16;
    char buf[SIZE], obuf[SIZE], str[60];
    int bi = SIZE, bn = SIZE, opt;
    int read(char *s){
        while (bn){
            for (; bi < bn && buf[bi] <= ' '; bi++);
            if (bi < bn) break;
            bn = fread(buf, 1, SIZE, stdin);
            bi = 0;
        }
        int sn = 0;
        while (bn){
            for (; bi < bn && buf[bi] > ' '; bi++) s[sn++] = buf[bi];
            if (bi < bn) break;
            bn = fread(buf, 1, SIZE, stdin);
            bi = 0;
        }
        s[sn] = 0;
        return sn;
    }
    bool read(int& x){
        int n = read(str), bf;

        if (!n) return 0;
        int i = 0; if (str[i] == '-') bf = -1, i++; else bf = 1;
        for (x = 0; i < n; i++) x = x * 10 + str[i] - '0';
        if (bf < 0) x = -x;
        return 1;
    }
};

ll Pow_mod(ll a, ll b, ll c){
    ll ans = 1;
    a %= c;
    while (b){
        if (b & 1) ans = (ans * a) % c;
        a = (a * a) % c;
        b >>= 1;
    }
    return (ans % c);
}

ll mul(ll a, ll b, ll c){
    ll ans = 0;
    a %= c;
    while (b){
        if (b & 1) ans = (ans + a) % c;
        a = (a + a) % c;
        b >>= 1;
    }
    return (ans % c);
}

ll gcd(ll a, ll b){
    return b ? gcd(b, a % b) : a;
}

int a, b, c;

int main(){
    scanf("%d%d%d", &a, &b, &c);
    printf("%d\n", c >= (a - b) ? c - (a - b) : 0);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#define MOD 1000000007

typedef long long ll;
using namespace std;

int main(void) {
    //ll a=0,b=0,c=0;
    //ll i=0,j=0;
    int n=0,k=0;
    string s={},word;
    cin >> s;
    int mae,ushiro;
    mae=((int)s[0]-48)*10+(int)s[1]-48;
    ushiro=((int)s[2]-48)*10+(int)s[3]-48;
    if(mae>12 || mae == 0){
        if(ushiro>12 || ushiro==0){
            word="NA";
        }else{
            word="YYMM";
        }
    }else{
        if(ushiro>12 || ushiro==0){
            word="MMYY";
        }else{
            word="AMBIGUOUS";
        }
    }
    //cout << mae <<endl;
    //cout << ushiro << endl;
    cout << word << endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

const SPACE = '.'
const BLOCK = '#'
const NIL = -1

type Point struct {
	x int
	y int
	d int
}

type Queue []Point

func (q *Queue) push(x Point) {
	*q = append(*q, x)
}

func (q *Queue) pop() Point {
	x := (*q)[0]
	*q = (*q)[1:]
	return x
}

func (q *Queue) isEmpty() bool {
	return len(*q) == 0
}

var dx = []int{-1, 0, 1, 0}
var dy = []int{0, 1, 0, -1}
var sc = bufio.NewScanner(os.Stdin)

func main() {
	r := bufio.NewReader(os.Stdin)

	var h, w int
	fmt.Fscan(r, &h)
	fmt.Fscan(r, &w)

	grid := make([]string, h)

	spaceCnt := 0
	for i := 0; i < h; i++ {
		fmt.Fscan(r, &grid[i])
		for j := 0; j < w; j++ {
			if grid[i][j] == SPACE {
				spaceCnt++
			}
		}
	}
	spaceCnt-- // without start point

	cost := make([][]int, h)
	for i := 0; i < h; i++ {
		cost[i] = make([]int, w)
		for j := 0; j < w; j++ {
			cost[i][j] = NIL
		}
	}
	cost[0][0] = 0

	que := Queue{}
	que.push(Point{x: 0, y: 0})
	d := 0
	for !que.isEmpty() {
		p := que.pop()
		if p.x == w-1 && p.y == h-1 {
			d = p.d
			break
		}

		for i := 0; i < 4; i++ {
			nx := p.x + dx[i]
			ny := p.y + dy[i]
			if 0 <= nx && nx < w && 0 <= ny && ny < h && grid[ny][nx] != BLOCK && cost[ny][nx] == NIL {
				cost[ny][nx] = cost[p.y][p.x] + 1
				que.push(Point{x: nx, y: ny, d: p.d + 1})
			}
		}
	}
	if d > 0 {
		fmt.Println(spaceCnt - d)
	} else {
		fmt.Println(-1)
	}
}


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

using lli = long long int;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

template <class T>ostream &operator<<(ostream &o,const pair<T, T>&p)
{o<<"("<<p.first<<", "<<p.second<<")";return o;}

#define rep(i, n) for(lli i = 0; i < (lli)(n); i++)

const lli MOD = 1000000007LL;

lli modpow(lli a, lli n){
    lli res = 1;

    for(lli ai = a; n; n>>=1){
        if(1&n) res = (res*ai)%MOD;
        ai=(ai*ai)%MOD;
    }
    return res;
}

lli inv(lli n){
    return modpow(n, MOD-2);
}

lli modperm(lli n, lli k){
    lli res = 1;
    rep(i, k){
        res = (res*(n-i))%MOD;
    }
    return res;
}

lli modcomb(lli n, lli k){
    return (modperm(n, k)*inv(modperm(k, k)))%MOD;
}

lli posmod(lli n){
    lli res = n;
    res %= MOD;
    if(res < 0) res += MOD;
    return res;
}
string s;

int main(void){
    cin >> s;
    if(s == "ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
    return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>

void Do(int N){
  int i, M, m;
  int V[N], C[N];
  M = 0;
  for(i = 0;i < N;i++) scanf("%d", &V[i]);
  for(i = 0;i < N;i++) scanf("%d", &C[i]);
  for(i = 0;i < N;i++){
    m = V[i] - C[i];
    if(m > 0) M += m;
  }
  printf("%d\n", M);
}

int main(void){
  int N;
  scanf("%d", &N);
  Do(N);
  return 0;
}
  


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int n, k; cin >> n >> k;
    ll ans = 0;
    for(int b = 1; b <= n; b++){
        int p = n/b;
        int r = n%b;
        ans += max(b-k, 0) * p;
        ans += max(r+1-k, 0);
        if(k==0) ans--;
    }
    cout << ans << endl;
}

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

typedef long long ll;
typedef long long int lli;
const int MOD = 1000000007;
#define rep(i,n) for (int i = 0; i < (n); i++)

using namespace std;

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	double T, X; cin >> T >> X;
	cout << setprecision(10) << T / X << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
const ll INF = 1e18L + 1;

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  cout << c << " " << a << " " << b << endl;

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

typedef vector<int> vi;

#define PB push_back

const int inf = 1e9;

int dp[1000001], dp_odd[1000001];

int main()
{
	vi tet, tet_odd;

	for (int i = 1; ; ++i) {
		tet.PB(i * (i + 1) * (i + 2) / 6);
		if (tet.back() >= 1000000) break;
	}

	for (int i = 0; i < tet.size(); ++i) {
		if (tet[i] & 1) tet_odd.PB(tet[i]);
	}

	for (int i = 1; i <= 1000000; ++i) dp[i] = dp_odd[i] = inf;

	for (int i = 1; i <= 1000000; ++i) {
		for (int j = 0; j < tet.size(); ++j) {
			if (i >= tet[j]) {
				dp[i] = min(dp[i], dp[i - tet[j]] + 1);
			}
			if (i < tet[j]) break;
		}

		for (int j = 0; j < tet_odd.size(); ++j) {
			if (i >= tet_odd[j]) {
				dp_odd[i] = min(dp_odd[i], dp_odd[i - tet_odd[j]] + 1);
			}
			if (i < tet_odd[j]) break;
		}
	}

	int N;
	while (scanf("%d", &N), N) printf("%d %d\n", dp[N], dp_odd[N]);
}

Measured memory_bytes: 8864
#include<iostream>
using namespace std;
int main(){
    int n[101];
    int i,num;
    cin >> num ;
    for(i=0;i<num;i++) cin >> n[i] ;
    cout << n[num-1] ;
    for(i=1;i<num;i++){
        cout << " " << n[num-1-i] ;
    }
    cout << endl ;
    return 0 ;
}


Measured memory_bytes: 3084
package main

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

func main() {
	var a, b int
	var sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	if sc.Scan() {
		a, _ = strconv.Atoi(sc.Text())
	}
	if sc.Scan() {
		b, _ = strconv.Atoi(sc.Text())
	}
	fmt.Printf("%d %d %f\n", a/b, a%b, float64(a)/float64(b))
}


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

int check[300000];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	int N, M;
	cin >> N >> M;
	vector<int> v, ans;
	for(int i = 0; i < M; i++){
		int a;
		cin >> a;
		v.push_back(a);
	}
	reverse(v.begin(), v.end());
	for(auto a : v){
		if(!check[a]){
			ans.push_back(a);
		}
		check[a] = 1;
	}
	for(int i = 1; i <= N; i++){
		if(!check[i]) ans.push_back(i);
	}

	for(int i = 0; i < N; i++){
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
inline int add(int a,int b)
{a+=b;return a>=MOD?a-MOD:a;}
inline int mul(int a,int b)
{return 1LL*a*b%MOD;}
int inv[1<<20];
int main()
{
    int n,als=0;
    scanf("%d",&n);
    inv[1]=1;
    for(int i=2;i<=max(n,3);i++)
        inv[i]=mul(MOD-MOD/i,inv[MOD%i]);
    for(int i=1,pi=1;i<=n;i++)
        pi=mul(pi,inv[3]),als=add(als,mul(pi,inv[n-i+1]));
    printf("%d\n",mul(als,inv[n]));
    return 0;
}

Measured memory_bytes: 4352
#include<iostream>
#include<cmath>
#define M 1000000007
using namespace std;
int main()
{
    int n,m;
    while(cin>>n>>m)
    {
        if(n<m) swap(n,m);
        if(n-m>1)
            cout<<0<<endl;
        else if(n-m==1)
        {
            long long ans;
            long long a1=1;
            for(int i=2;i<=m;i++)
            {
                a1=(a1*i)%M;
            }
            ans=(((a1*a1)%M)*n)%M;
            cout<<ans<<endl;
        }
        else
        {
            long long a1=1;
            for(int i=2;i<=m;i++)
            {
                a1=(a1*i)%M;
            }
            cout<<(2*(a1*a1)%M)%M<<endl;
        }
    }
}


Measured memory_bytes: 256
from collections import defaultdict


n = int(input())
A = list(map(int, input().split()))

counts = defaultdict(int)

for a in A:
    counts[a] += 1

total = 0
for num, count in counts.items():
    pattern = count * (count - 1) // 2
    total += pattern

for a in A:
    count = counts[a]
    if count == 1:
        print(total)
        continue
    prev = count * (count - 1) // 2
    after = (count - 1) * (count - 2) // 2
    delta = prev - after
    print(total - delta)

Measured memory_bytes: 26780
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>

using namespace std;

int main(){
    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<int>> s(h, vector<int>(w, 0));
    for(int y=0; y<h; y++){
        string ss;
        cin >> ss;
        for(int x=0; x<w; x++) s[y][x] = ss[x] == '1' ? 1 : 0;
    }
    vector<vector<int>> sum(h+1, vector<int>(w,0));
    for(int y=1; y<=h; y++){
        for(int x=0; x<w; x++){
            sum[y][x] += sum[y-1][x] + s[y-1][x];
        }
    }
    int ans = 10 * 1000 + 1;
    bool flag = false;
    for(int i=0; i<1<<(h-1); i++){
        vector<int> line;
        int res = 0;
        line.push_back(0);
        for(int j=0; j<(h-1); j++){
            if(i>>j & 1){
                line.push_back(j+1);
                res++;
            }
        }
        line.push_back(h);
        for(int x=0; x<w; x++){
            for(int j=0; j<line.size()-1; j++){
                if(sum[line[j+1]][x] - sum[line[j]][x] > k){
                    flag = true;
                }
            }
        }
        if(flag){
            flag = false;
            continue;
        }
        vector<int> block(line.size()-1, 0);
        for(int x=0; x<w; x++){
            for(int j=0; j<line.size()-1; j++){
                block[j] += sum[line[j+1]][x] - sum[line[j]][x];
                if(block[j] > k){
                    res++;
                    for(int j=0; j<line.size()-1; j++){
                        block[j] = sum[line[j+1]][x] - sum[line[j]][x];
                    }
                    break;
                }
            }
        }
        ans = min(ans, res);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
INF = float('inf')


def main():
    N, *a = map(int, open(0).read().split())
    ans = INF
    tmp = 0
    total = sum(a)
    for i in range(N - 1):
        tmp += a[i]
        ans = min(ans, abs(2 * tmp - total))
    print(ans)
    return


main()


Measured memory_bytes: 24216
a[1111],b[1111],c[1111],d[1111],p[1111],i,j,x,y,z;main(){for(;scanf("%d%d%d",a,b,c)&&(*a+=*b+*c);i=0){for(scanf("%d",p);i++<*p;scanf("%d%d%d%d",a+i,b+i,c+i,d+i),p[i]=2);for(;--i;)for(j=0;j++<*p;d[j]?p[a[j]]=p[b[j]]=p[c[j]]=1:(x=p[a[j]]&1)&(y=p[b[j]]&1)?p[c[j]]=0:x&(z=p[c[j]])?p[b[j]]=0:y&z?p[a[j]]=0:0);for(;i<*a;printf("%d\n",p[++i]));}exit(0);}

Measured memory_bytes: 620
object Main {
  val sc = new java.util.Scanner(System.in)

  def sin(n: Int): Seq[Int] = Seq.fill(n)(sc.nextInt())

  def main(args: Array[String]): Unit = {
    val n = sc.nextInt()
    val p = sin(n)
    println(p.sum - p.max / 2)
  }
}

Measured memory_bytes: 27332
#include<iostream>
using namespace std;
int main()
{   
    int n,a[25],num=0,x=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
    	cin>>a[i];	
	    if(a[i]>=x) {num++;x=a[i];}
	}
	cout<<num;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define endl        "\n"
#define si(a)       scanf("%d",&a)
#define si2(a,b)    scanf("%d%d",&a,&b)
#define sl(a)       scanf("%lld",&a)
#define sl2(a,b)    scanf("%lld%lld",&a,&b)
#define pb          push_back
#define mk          make_pair
#define loop(n)     for(int i=0; i<n; i++)
#define FOR(a,b)    for(int i=a; i<=b; i++)
#define sz          size()
#define ff          first
#define ss          second
#define mem(a,val)  memset(a, val, sizeof(a))
#define md          1000000007
#define pi          acos(-1.0)

ll a[200010];
map<ll,ll>m;
vector<ll>v;
string s,q;

int main()
{
   ll t,n,i,j,k,l,r,mn=0, mx=0;
   sl(n);
       for(int i=0; i<n; i++)
       {
           sl(a[i]);
           m[a[i]]++;
           mx+=a[i];
       }
    sl(k);

    loop(k)
    {
        sl2(l,r);
        mx+=(r-l)*m[l];
        m[r]+=m[l];
        m[l]=0;
        printf("%lld\n", mx);
    }
}



Measured memory_bytes: 10512
while 1:

    T, D, L = map(int, input().split())
    # T秒間の間観測, 毎秒波が押し寄せてくる。T個のx
    # 海岸はD秒たつと乾く
    # 距離Lだけ離れた地点が少なくても何秒濡れていたか
    if T == 0:
        exit()
    XXX = [int(input()) for i in range(T)]

    limit_time = 0
    ans = 0
    swet_time = 0
    for i, x in enumerate(XXX):
        if limit_time > 0:
            swet_time += 1
            limit_time -= 1

        if x >= L:
            limit_time = D


        if limit_time == 0:
            ans += swet_time
            swet_time = 0
        elif i == len(XXX)-1:
            ans += swet_time

    print(ans)



Measured memory_bytes: 14184
#include <stdio.h>

int main(void)
{
	int c1, c5, c10, c50, c100, c500;
	
	scanf("%d %d %d %d %d %d",&c1, &c5, &c10, &c50, &c100, &c500);
	
	if (c1 + c5 * 5 + c10 * 10 + c50 * 50 + c100 * 100 + c500 * 500 >= 1000){
		printf("1\n");
	}
	else {
		printf("0\n");
	}
	
	return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
vector<ll> A, B;


signed main(){
	ll N, M, K;
	cin >> N >> M >> K;
	A = vector<ll>(N);
	B = vector<ll>(M);
	for(ll i = 0; i < N; i++){
		cin >> A.at(i);
	}
	for(ll i = 0; i < M; i++){
		cin >> B.at(i);
	}
	vector<ll> A_acm(N+1, 0), B_acm(M+1, 0);
	for(ll i = 1; i < N+1; i++){
		A_acm.at(i) += A_acm.at(i-1)+A.at(i-1);
	}
	for(ll i = 1; i < M+1; i++){
		B_acm.at(i) += B_acm.at(i-1)+B.at(i-1);
	}

	int max_book = 0;
	for(int a_i = 0, b_i = M; a_i < N+1; a_i++){
		if(K < A_acm.at(a_i)){
			break;
		}
		while(K-A_acm.at(a_i) < B_acm.at(b_i)){
			--b_i;
		}
		max_book = max(max_book, a_i+b_i);
	}
	cout << max_book << endl;
 
	return 0;
}

Measured memory_bytes: 9604
#include <bits/stdc++.h>
#define int long long 
using namespace std;
typedef pair<int,int> ii;

int fact[1000005];
int mod = 1000000007;
long long qexp(long long b, long long p){
    long long res = 1;
    while(p){
        if(p&1) res = (res * b) % mod;
        b = (b * b) % mod;
        p >>= 1;
    }
    return res;
}
int inv(long long b){ return qexp(b, mod-2); }
int choose(int N, int C){
	int res = fact[N];
	res *= inv(C);
	res %= mod;
	res *= inv(N-C);
	res %= mod;
	return res;
}

signed main(){
	//freopen("i.txt","r",stdin);
	ios_base::sync_with_stdio(false); cin.tie(0);
	
	fact[0] = 1;
	for(int i = 1;i <= 1000000;i++) fact[i] = (fact[i-1] * i) % mod;
	int a, b, c, d, e; cin >> a >> b >> c >> d >> e;
	
	int x = e * (b - d);
	
	if(x >= abs(a-c)) cout << "YES\n";
	else cout << "NO\n";
}



Measured memory_bytes: 11464
n,a,b=map(int,input().split())
s=input()
aa=0
bb=0
for i in range(n):
  if aa+bb<a+b:
    if s[i]=='a':
      print('Yes')
      aa+=1
    elif s[i]=='b' and bb<b:
      print('Yes')
      bb+=1
    else:
      print('No')
  else:
    print('No')

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

int main(){
    int n, x;
    int l[150];
    int sum = 0;
    int count = 0;
  	int j;
    cin >> n >> x;
    for(int i = 0;i < n;i++){
        cin >> l[i];
    }

    for(j = 0;j < n+2;j++){
        if(sum <= x){
            sum += l[j];
          	count++;
        }else break;
    }
  	cout << j << endl;
}	

Measured memory_bytes: 256
n = int(input())
word_list = []
flag = True
for i in range(n):
    word = input()
    if word_list == []:
        word_list.append(word)
    else:
        if (word_list[-1][-1] == word[0]) and (word not in word_list):
            word_list.append(word)
        else:
            flag = False
            break
            
if flag:
    print('Yes')
else:
    print('No')

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

vector<long long> sum;
map<long long, long long> d;

int main()
{
	int n;
	long long M;
	cin >> n >> M;
	sum.assign(n, 0);
	for (int i = 0; i < n; i++)
	{
		cin >> sum[i];
		if (i)
		{
			sum[i] += sum[i - 1];
		}
		//cout << sum[i] << " ";
		sum[i] %= M;
		d[sum[i]]++;
	}

	long long ans = 0;
	for (int i = 0; i < n; i++)
	{
		
		ans += d[sum[i]] - (sum[i] != 0);
		d[sum[i]]--;
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 4992
# -*- coding: utf-8 -*-
n = int(input())

if n<357:
    print(0)
    exit()

def inc(ary):
    ary[0] += 1
    for i in range(len(ary)-1):
        if ary[i]==0:
            ary[i] = 3
            break
        elif ary[i]==4:
            ary[i] = 5
            break
        elif ary[i]==6:
            ary[i] = 7
            break
        elif ary[i]==8:
            ary[i] = 3
            if ary[i+1]==0:
                ary[i+1] = 3
                break
            else:
                ary[i+1] += 1

cnt = 0
digit = [0 for _ in range(10)]
digit[0] = 3
while True:
    x = int("".join(map(str,reversed(digit))))
    if x>n:
        break
    if 3 in digit and 5 in digit and 7 in digit:
        cnt += 1

    inc(digit)
print(cnt)


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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

struct edge
{
    int to, cost;
};

const int max_N = 100010;

int N;
vector<edge> G[max_N];

ll d[max_N];

typedef pair<ll, int> P;

void dijkstra(int s)
{
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d, d + max_N, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty())
    {
        P p = que.top();
        que.pop();
        int v = p.second;

        if (d[v] < p.first)
            continue;

        rep(i, G[v].size())
        {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost)
            {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main()
{
    cin >> N;
    rep(i, N - 1)
    {
        int u, v, w;
        cin >> u >> v >> w;
        edge e;
        e.to = v;
        e.cost = w;
        G[u].push_back(e);

        edge re;
        re.to = u;
        re.cost = w;
        G[v].push_back(re);
    }

    dijkstra(1);

    rep(i, N)
    {
        if (d[i + 1] % 2 == 0)
        {
            cout << 0 << endl;
        }
        else
        {
            cout << 1 << endl;
        }
    }
}


Measured memory_bytes: 7296
#ifdef LOCAL_BUILD
#include "pch.h"
#define DLOG(msg) cout << "#" << __LINE__ << ":" << msg << endl;
#else
#include <bits/stdc++.h>
#define DLOG(msg)
#endif
using namespace std;

void printHead(vector<int>& heap) {
  for (size_t i = 0; i < heap.size(); ++i) {
    auto h_index = i + 1;
    cout << "node " << h_index << ": key = " << heap[h_index - 1] << ", ";
    if (i != 0) {
      cout << "parent key = " << heap[h_index / 2 - 1] << ", ";
    }
    if (h_index * 2 < heap.size() + 1) {
      cout << "left key = " << heap[h_index * 2 - 1] << ", ";
    }
    if (h_index * 2 + 1 < heap.size() + 1) {
      cout << "right key = " << heap[h_index * 2] << ", ";
    }
    cout << endl;
  }
}

int main() {
  int H;
  cin >> H;
  vector<int> heap;
  for (int t, i = 0; i < H; ++i) {
    cin >> t;
    heap.push_back(t);
  }
  printHead(heap);
}

Measured memory_bytes: 3164
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#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 range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

map<int,int> dp;
vi maho;

struct state{
	int p;
	int d;
	int t;
	bool operator <(state a)const{ return p < a.p; }
	bool operator >(state a)const{ return p > a.p; } 
};

vector<state> m;

int main(void){
	int l,n;
	cin >> l >> n;
	rep(i,n){
		state tmp;
		cin >> tmp.p >> tmp.d >> tmp.t;
		m.pb(tmp);
	}
	
	sort(m.begin(),m.end());
	rep(i,n){
		int p,d,t;
		p=m[i].p;
		d=m[i].d;
		t=m[i].t;
		if(dp.find(p)!=dp.end())
			dp[p]=min(dp[p],p);
		else
			dp[p]=p;
		rep(j,maho.size()){
			int rec=maho[j];
			if(rec<=p && dp.find(rec)!=dp.end())
				dp[p]=min(dp[p],dp[rec]+p-rec);
		}
		if(dp.find(p+d)!=dp.end())
			dp[p+d]=min(dp[p+d], min(dp[p]+t,p+d) );
		else
			dp[p+d]=min(dp[p]+t,p+d);
		maho.pb(p);
		maho.pb(p+d);
	//	cout << p << " "  << dp[p] << endl;
	//	cout << p+d << " "  << dp[p+d] << endl;
	}
	int ans=l;
	rep(i,maho.size()){
		int rec=maho[i];
		rec=l-rec+dp[rec];
		ans=min(rec,ans);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1336
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

//ABC129C
int main(void) {
  long long n, m, k, i,  tmp,  cou=1,mod=1e9+7, pre=0;
  scanf("%lld %lld", &n, &m);
  long long per[n+1],a[m+1];
  per[0]=1, per[1]=1,a[0]=-1;
  for(i=1;i<=m;i++)scanf("%lld",&a[i]);


  for(i=2; i <= n; i++){
    per[i]=(per[i - 1] + per[i - 2]) % mod;
    //printf("per[%lld]=%lld\n", i, per[i]);
  }
  i=1;

  while(i <= m){
    if(a[i] - a[i-1] == 1){
      printf("0");
      return 0;
    }
    cou=(cou * per[a[i] - a[i-1] - 2]) % mod;
    //printf("%4lld --- %10lld --- %10lld\n",a[i] - a[i-1] - 2,per[a[i] - a[i-1] - 2],cou);
    i++;
  }
  cou=(cou*per[n-a[m]-1])%mod;
  printf("%lld", cou);
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se seoncd
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
 
template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=200005;
int col[N],ans[N],n,u,v;
vi e[N],x,y,a,b,c;

void dfs(int u,int fa){
	if(col[u]) y.pb(u);
	else x.pb(u);
	for(auto v:e[u]){
		if(v==fa) continue;
		col[v]=col[u]^1;
		dfs(v,u);
	}
}

void doit(vi &x,vi &c){
	while(x.size()&&c.size()){
		ans[x.back()]=c.back();
		x.pop_back();
		c.pop_back();
	}
}

int main(){
	read(n);
	rep(i,1,n-1){
		read(u),read(v);
		e[u].pb(v),e[v].pb(u);
	}
	dfs(1,0);
	if(x.size()>y.size()) swap(x,y);
	rep(i,1,n){
		if(i%3==1) a.pb(i);
		else if(i%3==2) b.pb(i);
		else c.pb(i);
	}
	if(x.size()<=c.size()){
		doit(x,c);
		doit(y,c);
		doit(y,a);
		doit(y,b);
	}
	else{
		doit(x,a);
		doit(y,b);
		doit(x,c);
		doit(y,c);
	}
	rep(i,1,n) printf("%d ",ans[i]);
	return 0;
}

Measured memory_bytes: 20724