akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _1_3_A_Stack_kai
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var s = new Stack<int>();

            for (int i = 0; i < input.Length; i++)
            {
                int a, b;
                int op;
                if (int.TryParse(input[i], out op))
                {
                    s.Push(op);
                }
                else
                {
                    a = s.Pop();
                    b = s.Pop();
                    if (input[i] == "+")
                    {
                        s.Push(b + a);
                    }
                    else if (input[i] == "-")
                    {
                        s.Push(b - a);
                    }
                    else
                    {
                        s.Push(b * a);
                    }
                }
            }
            Console.WriteLine(s.Peek());
        }
    }
}


Measured memory_bytes: 16400
import java.util.Scanner;
 
class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int g = sc.nextInt();
		int b = sc.nextInt();
		int n = r * 100 + g * 10 + b;
		if(n%4==0){
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 19796
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
ll n,m,ans;
int main(){
	scanf("%lld%lld",&n,&m);
	ll d=m/n;
	for(ll i=d;i>=1;i--){
		ll t=i*(n-1),ht=m-t;
		if(ht%i==0){
			printf("%lld",i);return 0;
		}
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  int N; cin >> N;
  int sum = 108;
  for(int i = 1; i < N; i++) {
    int a = i, b = N - i, x = 0, y = 0;
    for(; a > 0;) {
      x += a % 10;
      a /= 10;
    }
    for(; b > 0; ) {
      y += b % 10;
      b /= 10;
    }
    sum = min(sum, (x + y));
  }
  cout << sum << endl;
}

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

typedef long long ll;

using namespace std;

int main()
{
  ll n, m, v, p;
  cin >> n >> m >> v >> p;
  
  ll a[100000];
  for (ll i = 0; i < n; i++)
    cin >> a[i];
  
  sort(a, a+n, greater<int>());
  
  ll cnt = p, sum = a[p-1];
  for (ll i = p; i < n; i++) {
    if (a[p-1] > a[i] + m or sum + max(0LL,(v-p-n+i+1))*m > (a[i]+m)*(i-p+1)) break;
    cnt++;
    sum += a[i];
  }
  
  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 1024
import java.io.*;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner s  = new Scanner(System.in);
		String a = s.next();
		String b = s.next();
		String x  = b.substring(0,b.length()-1);
		if(x.equals(a) && a.length()+1==b.length()) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}

	}

}


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

int main()
{
    int n,k;
    cin>>n>>k;
    int r,s,p;
    cin>>r>>s>>p;
    string arr;
    cin>>arr;
    string frr;
    for(int i=0;i<arr.size();i++)
    {
        if(arr[i]=='r')frr+='p';
        else if(arr[i]=='p')frr+='s';
        else if(arr[i]=='s')frr+='r';
    }

    for(int i=0;i<frr.size();i++)
    {
        if(i-k>=0&&frr[i]==frr[i-k])
        {
            frr[i]='9';
        }
    }

    int a=0,b=0,c=0;

    for(int i=0;i<frr.size();i++)
    {
        if(frr[i]=='r')a++;
        if(frr[i]=='s')b++;
        if(frr[i]=='p')c++;
    }
    long long sum = a*r+b*s+c*p;
    cout<<sum<<endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<iomanip>

using namespace std;

int main(){
	int N;
	cin >> N;
	double sum;
	
	if(N%2==0){
		sum = N/2;
	} else {
		sum = N/2+1;
	}
	
	cout << fixed << setprecision(7) << sum/N;
	
	return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	_ = readInt()
	s := readBytes()

	end := 0
	for end == 0 {
		end = 1
		l, r := 0, 0
		// fmt.Println(string(s))
		for i := range s {
			if s[i] == '(' {
				l++
			} else {
				r++
			}
			if r > l {
				s = append([]byte{'('}, s...)
				end = 0
				break
			}
			if i == len(s)-1 && l > r {
				// fmt.Println(string(s), l, r)
				for j := 0; j < l-r; j++ {
					s = append(s, ')')
				}
				break
			}
		}
	}

	fmt.Println(string(s))
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

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
}

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

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


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

using namespace std;
typedef long long int lld;
#define INF 1000000000000000000
#define MOD 1000000007
lld DP[1000][1000];
int n,k;
lld arr[1000];
lld par[1001];

lld compute(int left,int right){
	if(DP[left][right]!=-1)return DP[left][right];
	DP[left][right]=INF;
	for(int i=left;i<right;i++){
		DP[left][right]=min(DP[left][right],compute(left,i)+compute(i+1,right)+par[right+1]-par[left]);
	}
	return DP[left][right];
}
int main(){
	cin>>n;
	par[0]=0;
	for(int i=0;i<n;i++){
		cin>>arr[i];
		par[i+1]=par[i]+arr[i];
	}
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++)DP[i][j]=-1;
	}
	for(int i=0;i<=n;i++)DP[i][i]=0;
	
	cout<<compute(0,n-1)<<endl;
	/*for(int i=0;i<n;i++){
		for(int j=i;j<n;j++)cout<<DP[i][j]<<" ";
		cout<<endl;
	}*/
	return 0;
}

Measured memory_bytes: 4224
class Button :
	def __init__(self):
		self.key_dict = {
					("","1"): ".", (".","1"):",", (",","1"):"!",
					("!","1"):"?", ("?","1"):" ", (" ","1"):".",
					("","2"): "a", ("a","2"):"b", ("b","2"):"c", ("c","2"):"a",
					("","3"): "d", ("d","3"): "e", ("e","3"): "f", ("f","3"): "d",
					("","4"): "g", ("g","4"): "h", ("h","4"): "i", ("i","4"): "g",
					("","5"): "j", ("j","5"): "k", ("k","5"): "l", ("l","5"): "j",
					("","6"): "m", ("m","6"): "n", ("n","6"): "o", ("o","6"): "m",	
					("","7"): "p", ("p","7"): "q", ("q","7"): "r", ("r","7"): "s", ("s","7"): "p",
					("","8"): "t", ("t","8"): "u", ("u","8"): "v", ("v","8"): "t",
					("","9"): "w", ("w","9"): "x", ("x","9"): "y", ("y","9"): "z", ("z","9"): "w"
						}
		self.s = ""
	def push(self, key):
		if key == "0":
			char = self.s
			self.s = ""
			return char
		else :
			self.s = self.key_dict[(self.s, key)]

n = int(raw_input())
button = Button()
for i in range(n):
	message = ""
	key_string = raw_input()
	for key in key_string:
		if key == "0":
			message += button.push(key)
		else :
			button.push(key)
	print message

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define repeat(i,a,b) for(int i=(a),_=(b);i<_;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,_=(a);i>=_;i--)
#define mst(a,x) memset(a,x,sizeof(a))
#define vector basic_string
#define fi first
#define se second
#ifndef qwq
int cansel_sync=(ios::sync_with_stdio(0),cin.tie(0),0);
#endif
//mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N=200010; const double err=1e-11; typedef long long ll; const int inf=~0u>>2; const ll INF=~0ull>>2; ll read(){ll x; if(scanf("%lld",&x)==-1)exit(0); return x;} typedef double lf; typedef long double llf; const lf pi=acos(-1.0); lf readf(){lf x; if(scanf("%lf",&x)==-1)exit(0); return x;} template<typename T> T sqr(const T &x){return x*x;} typedef pair<int,int> pii; template<typename A,typename B> ostream &operator<<(ostream &o,const pair<A,B> &x){return o<<'('<<x.fi<<','<<x.se<<')';}
const int mod=(1?1000000007:998244353); ll mul(ll a,ll b,ll m=mod){return a*b%m;} ll qpow(ll a,ll b,ll m=mod){ll ans=1; for(;b;a=mul(a,a,m),b>>=1)if(b&1)ans=mul(ans,a,m); return ans;} ll getinv(ll v,ll m=mod){return qpow(v,m-2,m);}
#define int ll
int ans,a,b,c;
signed main(){
	int k=read();
	repeat(a,1,k+1)
	repeat(b,1,k+1){
		int g=__gcd(a,b);
		if(g==1)ans+=k;
		else
		repeat(c,1,k+1)
			ans+=__gcd(g,c);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i < (int)(n); i++)
#define REP(i, m, n) for(int i = (m); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

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

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

template<class T> inline auto __lcm(T& a, T& b) 
{ return a * b / __gcd(a, b); }


int main() {
    ll N;  cin >> N;
    vector<ll> A(N);  rep(i, N) cin >> A[i];

    vector<ll> B(N);
    copy(all(A), B.begin());

    sort(all(B));
    ll mx1 = B[B.size()-1];
    ll mx2 = B[B.size()-2];
    rep(i, N) {
        if (A[i] == mx1) print(mx2);
        else print(mx1);
    }

    return 0;
}



Measured memory_bytes: 4736
#include <iostream>
using namespace std;
int main() {
	int N;
	long long a[10001];
	int b[10001];
	int ans = 0;

	cin >> N;

	for (int i = 1; i <= N; i++)
	{
		cin >> a[i];
	}

	for (int i = 1; i <= N; i++)
	{
		int cnt = 0;
		while (a[i]>0)
		{
			if (a[i] % 2 == 0) {
				a[i] /= 2;
				cnt++;
			}
			else {
				b[i] = cnt;
				break;
			}
		}
	}

	for (int i = 1; i <= N; i++)
	{
		ans += b[i];
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

ll a[51]; // レベル i のバーガーの層の総数
ll p[51]; // レベル i のバーガーに含まれるパティの総数

// レベル n のバーガー下から x 層に含まれるパティの個数
ll solve(ll n, ll x){
    if(n == 0){
        if(x <= 0) return 0;
        else return 1;
    }
    if(x == 1) return 0;
    if(x <= 1 + a[n-1]) return solve(n-1, x-1);
    if(x == 2 + a[n-1]) return p[n-1] + 1;
    if(x <= 2 + 2 * a[n-1]) return p[n-1] + 1 + solve(n-1, x-1-a[n-1]-1);
    if(x == 3 + 2 * a[n-1]) return 2 * p[n-1] + 1; 
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll n, x; cin >> n >> x;
    a[0] = 1;
    p[0] = 1;
    for(int i=1;i<=n;i++){
        a[i] = 2 * a[i-1] + 3;
        p[i] = 2 * p[i-1] + 1;
    }
    cout << solve(n, x) << endl;
}

Measured memory_bytes: 256
import sys
import bisect

# 10倍速いらしい
input = sys.stdin.readline

INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)

S = input().rstrip()
T = input().rstrip()

sn = len(S)
d = dict()
for i, s in enumerate(S):
    d[s] = d.get(s, [])
    d[s].append(i)

nowidx = -1
loop = 0
for t in T:
    l = d.get(t, [])
    if len(l) == 0:
        print(-1)
        sys.exit()
    j = bisect.bisect_right(l, nowidx)
    if len(l) <= j:
        nowidx = l[0]
        loop += 1
    else:
        nowidx = l[j]

# print(loop, nowidx)
print(loop * sn + nowidx + 1)


Measured memory_bytes: 7668
#include <bits/stdc++.h>
typedef long long ll;
#define MOD 1000000007
#define INF -99999999 
using namespace std;
 
int main(){
    int N,K; cin >> N >> K;
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        int x;
        cin >> x;
        ans += 2*min(x,K-x);
    }
    cout << ans << endl;
}


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

int diffcount(const string S1,const string S2);



int main(){
    string S,T;
    cin>>S;
    cin>>T;

    int letter=T.length();
    for(int i=0;i<S.length()-T.length()+1;i++){
        int count=diffcount(S.substr(i,T.length()),T);
        if(letter>count){
               letter=count;
        }
            
    }
    cout<<letter<<endl;
}

int diffcount(const string S1,const string S2){
    int count=0;
    for(int i=0;i<S2.length();++i){
        if(S1[i]!=S2[i]){
            ++count;
        }
    }
    return count;
}




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

int main() {
  string S, T;
  cin >> S >> T;

  int n = S.length();
  set<int> sets[30], sett[30];
  rep(i, n) {
    sets[S[i]-'a'].insert(T[i]-'a');
    sett[T[i]-'a'].insert(S[i]-'a');
  }
  bool f = true;
  rep(i, 30) {
    if (sets[i].size() > 1 || sett[i].size() > 1) f = false; 
  }
  cout << (f ? "Yes" : "No") << endl;
  return 0;
}

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

bool is_palin(const string &s) {
  int n = s.length();
  bool res = true;
  for (int i = 0; i < n / 2; i++) {
    if (s[i] != s[n - i - 1]) {
      res = false;
    }
  }
  return res;
}

int main() {
  string s;
  cin >> s;
  int n = s.length();
  cout << (is_palin(s) && is_palin(s.substr(0, (n - 1) / 2)) &&
                   is_palin(s.substr((n + 3) / 2 - 1))
               ? "Yes"
               : "No")
       << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
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; }



int main(int argc, char const *argv[]) {
int a,b,c;
cin >> a >> b >> c;
  if(a+b+c>=22) cout << "bust" << endl;
  else cout << "win" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
char t1[1510];
char t2[1510];
int main(){
	int n;
	int a=0,b=0;
	int i;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s %s",&t1,&t2);
		if(strcmp(t1,t2)==0) a++,b++;
		if(strcmp(t1,t2)>0) a+=3;
		if(strcmp(t1,t2)<0) b+=3;
	}
	printf("%d %d\n",a,b);
	return 0;
}



Measured memory_bytes: 2104
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using edge = struct {
  int to;
  int cost;
};
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define BITS(n, num) std::bitset<(n)>((num)).to_string()
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  vl A(N, 0), B(N, 0);
  vvl C = VVL(31, N, 0);
  REP(i, N) cin >> A[i];
  REP(i, N) cin >> B[i];
  REP(i, 31) {
    REP(j, N) { C[i][j] = B[j] % (1LL << (i + 1)); }
    sort(ALL(C[i]));
  }
  ll ans = 0;
  REP(i, 31) {
    ll yo = 0;
    // cout << i << endl;
    AUTO(a, A) {
      ll po = a % (1LL << (i + 1));
      auto t1 = lower_bound(ALL(C[i]), (1LL << i) - po);
      auto t2 = lower_bound(ALL(C[i]), 2LL * (1LL << i) - po);
      auto t3 = lower_bound(ALL(C[i]), 3LL * (1LL << i) - po);
      auto t4 = lower_bound(ALL(C[i]), 4LL * (1LL << i) - po);

      ll pos1 = distance(C[i].begin(), t1);
      ll pos2 = distance(C[i].begin(), t2) - 1;
      ll pos3 = distance(C[i].begin(), t3);
      ll pos4 = distance(C[i].begin(), t4) - 1;

      yo = (yo + (pos2 - pos1 + 1) + (pos4 - pos3 + 1)) % 2;
    }
    if (yo % 2 == 1)
      ans += 1LL << i;
  }
  cout << ans << endl;

  return 0;
}


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

int main(int argc,char** argv)
{

	int k;
	cin >> k;

	if(k%2 == 1){
		cout << (k/2) * (k/2+1) <<endl;
	}
	else{
		cout << (k/2) * (k/2) <<endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        String S = sc.nextLine();

        if(S.equals("ABC")){
            System.out.println("ARC");
        }else if(S.equals("ARC")){
            System.out.println("ABC");
        }

        sc.close();

    }
    
}

Measured memory_bytes: 35752
#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;
typedef long long ll;

int main() {
	
	int n;
	cin >> n;
	
	bool can_buy = false;
	for(int cake = 0; cake <= 100; cake += 4){
		for(int donut = 0; donut <= 100; donut += 7){
			if(n == cake + donut){
				can_buy = true;
				break;
			}
		}
		if(can_buy) break;
	}
	
	if(can_buy) puts("Yes");
	else puts("No");
	
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector <int> w(n);
    for (int tsumugi = 0; tsumugi < n; tsumugi++){
        cin >> w[tsumugi];
    }

    int left = 0;
    int right = accumulate(w.begin(), w.end(), 0);
    int ans = 1e5;
    int tmp;
    // int now = 0;
    for (int matsuri = 0; matsuri < n; matsuri++){
        // left += w[now];
        // right -= w[now];
        left += w[matsuri];
        right -= w[matsuri];
        tmp = abs(left - right);
        // cout << "tmp:" << tmp << endl;
        ans = min(ans, tmp);
        // now++;
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<string> s(N);
  for(int i = 0; i < N; i++) {
    cin >> s.at(i);
  }
  int M;
  cin >> M;
  vector<string> t(M);
  for(int i = 0; i < M; i++) {
    cin >> t.at(i);
  }

  int score = 0;
  for(int i = 0; i < N; i++) {
    int i_score = 0; //s.at(i)を言ったときのスコア
    for(int j = 0; j < N; j++) {
      if(s.at(i) == s.at(j)) {
        i_score++;
      }
    }
    for(int j = 0; j < M; j++) {
      if(s.at(i) == t.at(j)) {
        i_score--;
      } 
    }
    if(i_score > score) {
      score = i_score;
    }
  }
  
  cout << score << endl;
  
  return 0;
}

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

using namespace std;

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

    vector<int> b(n + 1);
    b[0] = 1e6;
    b[n] = 1e6;
    for (int i = 1; i < n; ++i) {
        cin >> b[i];
    }

    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        ans += min(b[i], b[i - 1]);
    }

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


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

lli n;

int main(void){
	cin >> n;
	vector<int> s(n);
	lli ans = 0;
	rep(i, n){
		cin >> s[i];
		ans += s[i];
	}
	sort(s.begin(), s.end());
	if(ans%10 != 0){
		cout << ans << endl;
		return 0;
	}
	bool f = true;
	rep(i, n){
		if(s[i] %10 != 0){
			f = false;
			ans -= s[i];
			break;
		}
	}
	if(f) cout << 0 << endl;
	else cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define xx first
#define yy second
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int inf=0x3f3f3f3f;
const LL INF=0x3f3f3f3f3f3f3f3f;
const int N=3e5+10;
const int M=1e6+10;

int main(){
	LL n,m;scanf("%lld%lld",&n,&m);
	cout<<n*(n-1)/2+m*(m-1)/2<<endl;
	return 0;
}

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

int main() {
  long long n;
  cin>>n;
  long long x=3*n;
  vector<long long>a(x);
  for(long long i=0;i<x;i++){
    cin>>a[i];
  }
  long long ans=0;
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  for(long long i=0;i<n;i++){
    ans+=a[1+2*i];
  }
  cout<<ans<< endl;
  return 0;
}

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

int main(){
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if((x-r)<0||(x+r)>W){
        printf("No\n");
    }else if((y-r)<0||(y+r)>H){
        printf("No\n");
    }else{
        printf("Yes\n");
    }
    return 0;
}


Measured memory_bytes: 3148
#include<bits/stdc++.h>
#define LL long long
using namespace std;
int main()
{
	LL x,s,x1;
	scanf("%lld",&x);
	s=0LL;
	if(x%11LL==0LL)s=(x/11LL)*2LL;
	else
	{
		x1=x%11LL;
		s=(x/11LL)*2LL;
		if(x1<=6LL)s++;
		else s+=2;
	}
	printf("%lld",s);
	return 0;
}

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

int main(void)
{
    long long N;
    cin >> N;
    vector<long long> A(N);
    for (long long i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    vector<long long> x;
    vector<long long> y;
    vector<long long> z;
    long long count0 = 0;
    for (long long i = 0; i < N; i++)
    {
        if (A[i]-1-i > 0)
        {
            x.push_back(A[i]-1-i);
        }
        else if (A[i]-1-i < 0)
        {
            y.push_back((-1) * (A[i]-1-i));
        }
        else
        {
            count0++;
        }
        z.push_back(A[i]-1-i);
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    long long b;
    if (x.size() >= y.size())
    {
        for (long long i = 0; i < count0; i++)
        {
            y.push_back(0);
        }
        if (x.size() > y.size())
        {
            b = (-1) * x[(x.size()-y.size()-1)/2];
        }
        else
        {
            b = 0;
        }
    }
    else
    {
        for (long long i = 0; i < count0; i++)
        {
            x.push_back(0);
        }
        if (y.size() > x.size())
        {
            b = y[(y.size()-x.size()-1)/2];
        }
        else
        {
            b = 0;
        }
    }
    
    long long ans = 0;
    for (long long i = 0; i < N; i++)
    {
        ans += abs(z[i]+b);
    }
    cout << ans << endl;
}

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

a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
c = [2]

if (x in a and y in a) or (x in b and y in b) or (x in c and y in c):
  print('Yes')
else:
  print('No')

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

int main(void)
{
    string str1, str2, str3;
    char turn = 'a';
    char winner;
    cin >> str1 >> str2 >> str3;
    while (1)
    {
        if (turn == 'a')
        {
            if (str1.empty())
            {
                winner = 'A';
                break;
            }
            else
            {
                turn = str1[0];
                str1.erase(str1.begin());
            }
        }
        else if (turn == 'b')
        {
            if (str2.empty())
            {
                winner = 'B';
                break;
            }
            else
            {
                turn = str2[0];
                str2.erase(str2.begin());
            }
        }
        else if (turn == 'c')
        {
            if (str3.empty())
            {
                winner = 'C';
                break;
            }
            else
            {
                turn = str3[0];
                str3.erase(str3.begin());
            }
        }
    }
    cout << winner << endl;
}

Measured memory_bytes: 256
fn run() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let a: f64 = it.next().unwrap().parse().unwrap();
    let b: f64 = it.next().unwrap().parse().unwrap();
    let x: f64 = it.next().unwrap().parse().unwrap();
    let s = x / a;
    let ans = if s > a * b / 2.0 {
        ((a * b - s) / (a * a / 2.0)).atan() / std::f64::consts::PI * 180.0
    } else {
        ((b * b / 2.0) / s).atan() / std::f64::consts::PI * 180.0
    };
    println!("{:.7}", ans);
}

fn main() {
    run();
}

Measured memory_bytes: 4352
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 0
//{
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
 
//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

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

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

//}
int a,b,c;
main(){
	cin>>a>>b>>c;
	dump(max({10*a+b+c,a+10*b+c,a+b+10*c}));
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n, y int
	fmt.Scan(&n)
	fmt.Scan(&y)
	for i := 0; i <= y/10000; i++ {
		for j := 0; j <= (y-10000*i)/5000; j++ {
			k := (y - 10000*i - 5000*j) / 1000
			if i+j+k == n {
				fmt.Printf("%d %d %d\n", i, j, k)
				return
			}
		}
	}
	fmt.Println("-1 -1 -1")
}


Measured memory_bytes: 512
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Here your code !
        Scanner scan = new Scanner(System.in);
        String a = scan.next();
        String b = scan.next();
        String c = scan.next();
        String str1 = a.substring(0,1);
        String str2 = b.substring(0,1);
        String str3 = c.substring(0,1);
        System.out.print(str1.toUpperCase());
        System.out.print(str2.toUpperCase());
        System.out.println(str3.toUpperCase());
    }
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
#define rep(i,n) for(ll i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main() {
  ll n, k, q;
  cin >> n >> k >> q;
  vector<ll> vec(q);
  rep(i, q) cin >> vec.at(i);
  vector<ll> ans(n, 0);
  rep(i,q) ans.at(vec.at(i)-1)++;
  rep(i,n) {
    if(ans.at(i) >= q-k+1) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 2176
N = int(input())
A = list(map(int,input().split(' ')))
num = 0
X = []
for i,j in enumerate(A):
  B = j-(i+1)
  X.append(B)
X.sort()
median = 0
if N % 2 == 0:
  median = (X[int(N/2)] + X[int(N/2-1)])/2
else:
  median = X[int((N-1)/2)] 

for x in X:
  num += abs(x-median)
print(int(num))    

Measured memory_bytes: 25196
dic = {}
n = int(input())
for i in range(n):
    s = str(input())
    dic.setdefault(s,0)
    dic[s] += 1
m = int(input())
for j in range(m):
    t = str(input())
    dic.setdefault(t,0)
    dic[t] -= 1
ans = max(dic.values())
if ans<0:
    ans = 0
print(ans)

Measured memory_bytes: 9116
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

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

    vector<int> upper(N);
    vector<int> lower(N);
    for (int i = 0; i < N; i++)
    {
        cin >> upper[i];
    }
    for (int i = 0; i < N; i++)
    {
        cin >> lower[i];
    }

    vector<int> rui_upper(N + 1, 0);
    vector<int> rui_lower(N + 1, 0);
    for (int i = 0; i < N; i++)
    {
        rui_upper[i + 1] = rui_upper[i] + upper[i];
        rui_lower[i + 1] = rui_lower[i] + lower[i];
    }

    // debug
    // for (int i = 1; i < N + 1; i++)
    // {
    //     cout << rui_lower[i] << " ";
    // }

    int sum = 0;
    int mx = -1;
    for (int i = 1; i < N + 1; i++)
    {
        sum = rui_upper[i] + rui_lower[N] - rui_lower[i - 1];
        // printf("%d %d\n", rui_upper[i], rui_lower[N] - rui_lower[i - 1]);
        mx = max(sum, mx);
    }
    cout << mx << endl;
}

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

#define reps(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   reps(i,0,n)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define PI (acos(-1))

int main(){
  int N,M;
  cin >> N >> M;
  int A[100010]={};
  rep(i,M){
    int l,r;
    cin >> l >> r;
    l--;r--;
    A[l]++;
    A[r+1]--;
  }
  int cnt=0;
  rep(i,N){
    A[i+1] += A[i]; 
  }
  rep(i,N){
    if(A[i] == M)cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define INF (int)1e9
#define INFL (ll)1e11
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	int H, W;
	cin >> H >> W;
	vector<vector<int>> a(H, vector<int>(W));
	REP(i, H)REP(j, W) {
		cin >> a[i][j];
	}
	vector<vector<int>> res;
	stack<P> st;
	st.push(P(0, 0));
	vector<vector<bool>> used(H, vector<bool>(W, false));
	while (!st.empty()) {
		int i = st.top().first;
		int j = st.top().second;
		used[i][j] = true;
		if (i + 1 < H && !used[i + 1][j]) {
			used[i + 1][j] = true;
			st.push(P(i + 1, j));
			if (a[i][j] % 2 == 1) {
				a[i + 1][j]++;
				vector<int> tmp = { i,j,i + 1,j };
				res.push_back(tmp);
			}
		}
		else if (i - 1 >= 0 && !used[i - 1][j]) {
			used[i - 1][j] = true;
			st.push(P(i - 1, j));
			if (a[i][j] % 2 == 1) {
				a[i - 1][j]++;
				vector<int> tmp = { i,j,i - 1,j };
				res.push_back(tmp);
			}
		}
		else if (j + 1 < W && !used[i][j + 1]) {
			used[i][j + 1] = true;
			st.push(P(i, j + 1));
			if (a[i][j] % 2 == 1) {
				a[i][j + 1]++;
				vector<int> tmp = { i,j,i,j + 1 };
				res.push_back(tmp);
			}
		}
		else if (j - 1 >= 0 && !used[i][j - 1]) {
			used[i][j - 1] = true;
			st.push(P(i, j - 1));
			if (a[i][j] % 2 == 1) {
				a[i][j - 1]++;
				vector<int> tmp = { i,j,i,j - 1 };
				res.push_back(tmp);
			}
		}
		else st.pop();
	}
	cout << res.size() << "\n";
	REP(i, res.size())REP(j, 4) {
		if (j < 3) cout << res[i][j] + 1 << " ";
		else cout << res[i][j] + 1 << "\n";
	}

	return 0;
}
		
		

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

int main() {

	using namespace std;

	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;

	if (x + r <= W && y + r <= H && x - r >= 0 && y - r >= 0) {
		cout << "Yes" << endl;
	}else {
		cout << "No" << endl;
	}

	return 0;

}


Measured memory_bytes: 3112
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <queue> 
#include <cctype> 
#include <climits> 
#include <stack> 
#include <map> 
#include <cstring> 

using namespace std; 

int main(){

    long long r,d,x;
    cin>>r>>d>>x;

    for(int i=0;i<10;i++){
        x=r*x-d;
        cout<<x<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
//https://qiita.com/tanakh
#[allow(unused_macros)]
macro_rules! input {
	(source = $s:expr, $($r:tt)*) => {
		let mut iter = $s.split_whitespace();
		let mut next = || { iter.next().unwrap() }; 
		input_inner!{next, $($r)*}
	};
	($($r:tt)*) => {

		let stdin = std::io::stdin();
		let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); 
		let mut next = move || -> String{
			bytes
				.by_ref()
				.map(|r|r.unwrap() as char) 
				.skip_while(|c|c.is_whitespace()) 
				.take_while(|c|!c.is_whitespace()) 
				.collect()
			};
	input_inner!{next, $($r)*} 
	};
}

#[allow(unused_macros)]
macro_rules! input_inner { 
	($next:expr) => {}; 
	($next:expr, ) => {};

	($next:expr, $var:ident : $t:tt $($r:tt)*) => { 
		let $var = read_value!($next, $t); 
		input_inner!{$next $($r)*}
	}; 
}
#[allow(unused_macros)]
macro_rules! read_value { 
	($next:expr, ( $($t:tt),* )) => {
		( $(read_value!($next, $t)),* ) 
	};
	
	($next:expr, [ $t:tt ; $len:expr ]) => {
		(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
	};

	($next:expr, chars) => {
		read_value!($next, String).chars().collect::<Vec<char>>()
	};
	
	($next:expr, bytes) => {
		read_value!($next, String).into_bytes()
	};
	
	($next:expr, usize1) => { 
		read_value!($next, usize) - 1
	};

	($next:expr, $t:ty) => {
		$next().parse::<$t>().expect("Parse error")
	};
}
fn main(){
	input!{
		n : usize,
		a : [(usize); n],
	}
	let mut Max : usize = a[0];
	let mut Min : usize = a[0];
	for i in 1..n {
		if Max < a[i] {
			Max = a[i];
		}
		if Min > a[i] {
			Min = a[i];
		}
		//println!("{} {}",Max,Min);
	}
	println!("{}",Max-Min);
}

Measured memory_bytes: 4352
//Author rahuliitkgp

/*A thing of beauty is a joy forever,
Its loveliness increases,
it will never pass into nothingness.*/
//Men at Work :)

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;

#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void cpp(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

int main(){
    cpp();
    char c;
    cin>>c;
    if(islower(c)){
        cout<<'a'<<endl;
    }
    else{
        cout<<"A"<<endl;
    }
    return 0;
}




Measured memory_bytes: 3636
distance=[]
for i in range(5):
    a=int(input())
    distance.append(a)
k=int(input())

flag=1
for i in range(5):
    for j in range(5):
        if abs(distance[i]-distance[j])>k:
            flag=0
if flag:
    print("Yay!")
else:
    print(":(")


Measured memory_bytes: 38384
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char[] s = sc.next().toCharArray();
        int x = 0;
        int max = 0;
        for (int i = 0 ; i < n ; i++) {
            if (s[i] == 'I') {
                x++;
            } else {
                x--;
            }
            max = Math.max(max, x);
        }
        System.out.println(max);
    }

}


Measured memory_bytes: 23764
#include<stdio.h>
#include<string.h>

int main(){
    int f[27]={0},len,i,j;
    char simizu[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
    char S[100000];

    scanf("%s",S);
    len=strlen(S);
    f[26]=1;
    for(i=0;i<len;i++){
        for(j=0;j<26;j++){
            if(S[i]==simizu[j]){
                f[j]=1;
            }
        }
    }
    for(i=0;i<=26;i++){
        if(f[i]==0){
            printf("%c",simizu[i]);
            goto end;
        }
    }
        printf("None");
   end: return 0;
}

Measured memory_bytes: 256
import bisect
from collections import Counter, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
import math

import sys

# import numpy as np

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


def main():
    n, k = list(map(int,ipti().split()))
    v = list(map(int,ipti().split()))

    #取り出せる宝石の数の最大
    pop_max = min(k,n)
    ans = 0

    for pop in range(pop_max + 1):
        push = k - pop
        for left in range(pop + 1):
            right = pop - left
            got_jewel = v[0:left]
            if right > 0:
                got_jewel.extend(v[-right:])

            got_jewel.sort()
            negative_count = bisect.bisect_left(got_jewel, 0)
            n_push = min(push, negative_count)
            value = sum(got_jewel[n_push:])
            ans = max(ans, value)

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 43372
use std::io::*;
use std::str::FromStr;

#[allow(unused_macros)]
macro_rules! scan {
  ($e:expr; $t:ty) => {
    $e.get::<$t>()
  };
  ($e:expr; $($t:ty), *) => {
    ($($e.get::<$t>(),)*)
  };
  ($e:expr => $i:expr; $t:ty) => {
    {
      let mut v = Vec::new();
      for _ in 0..$i {
        v.push($e.get::<$t>());
      }
      v
    }
  }
}

struct Scanner<R: Read> {
  reader: R
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
  fn new(reader: R) -> Scanner<R> {
    Scanner { reader: reader }
  }
  fn safe_get<T: FromStr>(&mut self) -> Option<T> {
    let token = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
      .skip_while(|c| c.is_whitespace())
      .take_while(|c| !c.is_whitespace())
      .collect::<String>();
    if token.is_empty() { None } else { token.parse().ok() }
  }
  fn get<T: FromStr>(&mut self) -> T {
    if let Some(v) = self.safe_get() { v } else {
      writeln!(stderr(), "Terminated with EOF").unwrap();
      std::process::exit(0);
    }
  }
}

fn binary_search(vec: &Vec<i64>, k: i64) -> i64 {
  let mut min = vec.clone().into_iter().max().unwrap();
  let mut max = vec.clone().iter().sum::<i64>();
  let mut ans = max;
  while min < max {
    let mid = (min + max) / 2;
    let mut cur_track = 1;
    let mut cur_carry = 0;
    for &w in vec.iter() {
      if cur_carry + w > mid {
        cur_track += 1;
        cur_carry = w;
      }
      else {
        cur_carry += w;
      }
    }
    if cur_track > k {
      min = mid + 1;
    }
    else {
      ans = if ans < mid { ans } else { mid };
      max = mid;
    }
  }
  ans
}

fn main() {
  let cin = stdin();
  let cin = cin.lock();
  let mut sc = Scanner::new(cin);
  let (n, k) = scan!(sc; i64, i64);
  let w = scan!(sc => n; i64);
  println!("{}", binary_search(&w, k));
}



Measured memory_bytes: 6980
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		List<int> input = IO.GetIntList();
		int h = input[0];
		int n = input[1];
		List<int> a = IO.GetIntList();
		
		Console.WriteLine((a.Sum() >= h)?"Yes":"No");
	}

}

static class IO
{
    static public string GetString() { return Console.ReadLine(); }
    static public int GetInt() { return int.Parse(Console.ReadLine()); }
    static public long GetLong() { return long.Parse(Console.ReadLine()); }
    static public List<string> GetStringList() { return Console.ReadLine().Split(' ').ToList(); }
    static public List<int> GetIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); }
    static public List<long> GetLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); }
    static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
    static public void WriteStrings<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
}

Measured memory_bytes: 17248
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int tax(int a, int x)
{
	return a * (100 + x) / 100;
}

int main(void)
{
	int x, y, s;

	while (cin >> x >> y >> s, s){
		int ret = -1;
		for (int i = 1; i < s; i++){
			for (int j = 1; j < s; j++){
				if (tax(i, x) + tax(j, x) == s){
					// ok
					int now = tax(i, y) + tax(j, y);
					ret = max(ret, now);
				}
			}
		}
		cout << ret << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
from collections import defaultdict
        

obj = defaultdict(lambda: 1)

N=int(input())
ANA=[]
L=set([])
for i in range(N):
    k="".join(sorted([x for x in input()]))
    if k in L:
        obj[k]+=1
    else:
        L.add(k)

result=0
for i in obj.values():
    if i and i-1:
        result+=i*(i-1)/2
    
print(int(result))


Measured memory_bytes: 57816
using System;

namespace Rectangle
{
	class Rectangle
	{
		private int height;
		private int weight;

		public Rectangle()
		{
			height = 0;
			weight = 0;
		}

		public void getHeightAndWeight()
		{
			string s = Console.ReadLine();
			string[] sArray = s.Split(' ');

			height = int.Parse(sArray[0]);
			weight = int.Parse(sArray[1]);
		}

		public int Height
		{
			set { height = value; }
			get { return height; }
		}

		public int Weight
		{
			set { weight = value; }
			get { return weight; }
		}

	}

	public class MainClass
	{
		private int area;
		private int periphery;

		private MainClass()
		{
			area = 0;
			periphery = 0;
		}

		private void calcAreaAndPeriphery(int h, int w)
		{
			area = h * w;
			periphery = h * 2 + w * 2;
		}

		private void putsAreaAndPeriphery()
		{
			Console.WriteLine("{0} {1}", area, periphery);
		}

		public static void Main(string[] args)
		{
			Rectangle rec = new Rectangle();
			MainClass main = new MainClass();

			rec.getHeightAndWeight();

			main.calcAreaAndPeriphery(rec.Height, rec.Weight);

			main.putsAreaAndPeriphery();
		}
	}
}

Measured memory_bytes: 9084
package main

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

var sc = bufio.NewScanner(os.Stdin)

func stringsFiledsToInts() []int {
	sc.Scan()
	r := []int{}
	ss := strings.Fields(sc.Text())
	for _, s := range ss {
		i, e := strconv.Atoi(s)
		if e != nil {
			panic(e)
		}
		r = append(r, i)
	}
	return r
}

func main() {
	inputs := stringsFiledsToInts()
	A := inputs[0]
	B := inputs[1]
	// C := inputs[2]
	K := inputs[3]

	// if K <= A {
	// 	fmt.Print(1 * A)
	// } else if K <= A+B {
	// 	fmt.Print(1 * A)
	// } else {
	// 	nokoriA := K - A
	// 	nokoriB := nokoriA - B
	// 	fmt.Print(1*A + -1*nokoriB)
	// }

	nokoriA := K - A
	if nokoriA < 0 {
		fmt.Print(1 * K)
	} else {
		nokoriB := nokoriA - B
		if nokoriB < 0 {
			fmt.Print(1 * A)
		} else {
			fmt.Print(1*A + -1*nokoriB)
		}
	}
}


Measured memory_bytes: 1752
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;


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

	int x=0;
	for (int i = 0; i < N; i++) {
		if(A[i]%2!=0) x=1;
	}

	if(x!=0) cout << "first" << endl;
	else cout << "second" << endl;

}
	


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

int main(){
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> p;
	int a, b;
	rep(i,m){
		cin >> a >> b;
		p.push_back(make_pair(b,a));
	}
	sort(p.begin(),p.end());
	vector<int> rmv;
	rep(i,m){
		if(rmv.size() == 0){
			rmv.push_back(p[i].first-2);
			continue;
		}
		if((p[i].second-1) <= rmv[rmv.size()-1]){
			continue;
		}else{
			rmv.push_back(p[i].first-2);
		}
	}
	cout << rmv.size() << endl;
	return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 (a>b) { a=b; return 1; } return 0; }

pair<ll, ll> p[3];
ll res;

void solve(vector<pair<ll, ll>> use) {
  if (use.size() == 0) return;
  sort(use.begin(), use.end(), greater<pair<ll, ll>>());
  if (use.size() == 1) {
    res += res / use[0].first * (use[0].second - use[0].first);
  }
  else if (use.size() == 2) {
    ll maxp = 0;
    rep(i, res / use[0].first + 1) {
      ll resp = i * (use[0].second - use[0].first) + (res - i * use[0].first) / use[1].first * (use[1].second - use[1].first);
      chmax(maxp, resp);
    }
    res += maxp;
  }
  else {
    ll maxp = 0;
    rep(i, res / use[0].first + 1) {
      rep(j, (res - i * use[0].first) / use[1].first + 1) {
        ll resp = i * (use[0].second - use[0].first) + j * (use[1].second - use[1].first) + (res - i * use[0].first - j * use[1].first) / use[2].first * (use[2].second - use[2].first);
        chmax(maxp, resp);
      }
    }
    res += maxp;
  }
}


int main() {
  cin >> res;
  rep(i, 3) cin >> p[i].first;
  rep(i, 3) cin >> p[i].second;

  vector<pair<ll, ll>> use;
  rep(i, 3) if (p[i].first < p[i].second) use.push_back(p[i]);
  solve(use);
  use.clear();
  rep(i, 3) swap(p[i].first, p[i].second);
  rep(i, 3) if (p[i].first < p[i].second) use.push_back(p[i]);
  solve(use);
  cout << res << endl;
  

  



  
  return 0;
}

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

long long sumvec(vector<long long> vec){
  long long ans;
  for(int i=0;i<vec.size();i++){
    ans += vec.at(i);
  }
  return ans;
}

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

  	vector<long long> H(N);
  	for(int i=0;i<N;i++){
      cin >> H.at(i);
    }
  	sort(H.begin(),H.end());
  
  	if(K > N){
      cout << 0 << endl;
      return 0;
    }
  	for(int i=0;i<K;i++){
      H.pop_back();
    }
  
	
  	long long attack = sumvec(H);

    cout << attack << endl;
}


Measured memory_bytes: 6188