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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, K, s[100] = {};
    cin >> N >> K;
    REP(i, K) {
        int d;
        cin >> d;
        REP(j, d) {
            int A;
            cin >> A;
            s[A - 1]++; 
        }
    } 

    int ans = 0;
    REP(i, N) if (s[i] == 0) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
import std.stdio;
import std.ascii;
import std.conv;
import std.string;
import std.algorithm;
import std.range;
import std.functional;
import std.math;
import core.bitop;

void main()
{
    auto dg = readln.chomp.split.map!(to!long);
    long d = dg[0], g = dg[1];
    long[] p = new long[](d), c = new long[](d);
    foreach (i; 0 .. d)
    {
        auto pc = readln.chomp.split.map!(to!long);
        p[i] = pc[0];
        c[i] = pc[1];
    }

    g /= 100;
    c[] /= 100;
    long[] tmp = new long[](0);
    solve(p, c, tmp.dup, tmp.dup, iota(0, cast(long) p.length).array, g).writeln;
}

long solve(long[] p, long[] c, long[] use, long[] notuse, long[] a, long g)
{
    if (a.empty)
    {
        long score, cnt;

        foreach (long i; use)
        {
            score += (i + 1) * p[i] + c[i];
            cnt += p[i];
        }
        if (g <= score)
        {
            return cnt;
        }
        else if (!notuse.empty)
        {
            if ((g - score) / (notuse.reduce!max() + 1) <= p[notuse.reduce!max()])
            {
                return max(cnt + ((g - score) / (notuse.reduce!max() + 1)), 1);
            }
            else
            {
                return long.max;
            }
        }
        else
        {
            return long.max;
        }
    }
    else
    {
        long y = solve(p, c, use ~ a[0], notuse, a[1 .. $], g);
        long n = solve(p, c, use, notuse ~ a[0], a[1 .. $], g);
        return min(y, n);
    }
}


Measured memory_bytes: 380
#include <iostream>
#include <string>


using namespace std;
int main() {
    string w;
    int a;
    int b;
    while(1){
    cin >> w;
    if(w=="-") break;
    cin >> a;
    for (int i=0; i<a; i++) {
        cin >>b;
        w += w.substr(0,b);
        w.erase(0,b);
    }
        cout << w << endl;
    }
    }


Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    double r;
    cin >> r;
    cout << fixed << setprecision(10);
    cout << acos(-1) * 2.0 * r << '\n';
    return 0;
}

Measured memory_bytes: 3804
#include <iostream>
#include <vector>
#include <cmath>

int main() {
    int N,D;
    std::cin >> D >> N;
    std::cin.ignore();
    std::vector<std::vector<int64_t>> data;
    int d = D;
    while(d-->0) {
        int n = N;
        std::vector<int64_t> vec;
        vec.reserve(N);
        while(n-->0) {
            int val;
            std::cin >> val;
            vec.push_back(val);
        }
        std::cin.ignore();
        data.push_back(vec);
    }
    int ans = 0;
    for(int d = 0; d<D-1;++d) {
        for(int dn = d + 1; dn <D; ++dn) {
            int64_t RR = 0;
            for(int n =0; n <N;++n) {
                RR += (data[d][n] - data[dn][n])*(data[d][n] - data[dn][n]);
            }
            double R = sqrt(RR);
            double intR;
            if(modf(R,&intR) == 0.0) ++ans;
            
        }
    }
    std::cout << ans <<std::flush;
}

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

int main() {
  vector<int> x(3);
  int k, y;
  for(int i=0;i<3;i++) cin >> x.at(i);
  cin >> k;
  sort(x.begin(), x.end());
  y = x.at(2);
  for(int i=0;i<k;i++) y = 2*y;
  cout << x.at(0) + x.at(1) + y << endl;
}


Measured memory_bytes: 256
import sys


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))
    ans = sum(b)
    for i in range(n - 1):
        if a[i + 1] - a[i] == 1:
            ans += c[a[i] - 1]
    print(ans)


if __name__ == "__main__":
    main()


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

public class Program
{
    #region Standard I/O
    readonly TextReader input;
    readonly TextWriter output;

    X[] ReadLine<X>(Func<string, X> func)
    {
        return input.ReadLine().Split(' ').Select(func).ToArray();
    }

    void WriteLineOne(object obj)
    {
        output.WriteLine("{0}", obj);
    }

    void WriteLineMany(params object[] objects)
    {
        output.WriteLine(string.Join(" ", objects.Select(obj => obj.ToString())));
    }
    #endregion

    int n;
    long[] xs;

    void Read()
    {
        n = ReadLine(int.Parse)[0];
        xs = ReadLine(long.Parse);
    }

    long Solve(long[] xs)
    {
        var count = 0L;
        var s = xs[0];

        for (var i = 1; i < xs.Length; i++)
        {
            var t = s + xs[i];

            if (Math.Sign(t) == 0)
            {
                var d = s > 0 ? 1 : -1;
                t -= d;
                count += 1;
            }
            else if (Math.Sign(s) == Math.Sign(t))
            {
                var d = t + (t > 0 ? 1 : -1);
                t -= d;
                count += Math.Abs(d);
            }

            s = t;
        }

        return count;
    }

    long Calc()
    {
        if (xs[0] == 0)
        {
            var ys = xs.ToArray();
            xs[0] = 1;
            ys[0] = -1;
            return Math.Min(Solve(xs), Solve(ys)) + 1;
        }
        else
        {
            var ys = xs.ToArray();
            var d = ys[0] + (ys[0] > 0 ? 1 : -1);
            ys[0] -= d;

            return Math.Min(Solve(xs), Solve(ys) + Math.Abs(d));
        }
    }

    public void Run()
    {
        Read();
        WriteLineOne(Calc());
    }

    public Program(TextReader input, TextWriter output)
    {
        this.input = input;
        this.output = output;
    }

    public static void Main(string[] args)
    {
        new Program(Console.In, Console.Out).Run();
    }
}


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

int main() {
  int a, b;
  cin >> a >> b;
  vector<int> x(100);

  
  if (a <= b){
    for (int i = 0; i < b; i++){
      x.at(i) = a;
      cout << x.at(i);
    }
  }else if (a > b){
    for (int i = 0; i < a; i++){
      x.at(i) = b;
      cout << x.at(i);
    }
  }


}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int N= scan.nextInt();
		int[][] darr = new int[N][2];
		int zorome = 0;
		for (int i = 0; i < N; i++) {
			darr[i][0] = Integer.parseInt(scan.next());
			darr[i][1] = Integer.parseInt(scan.next());
			if (darr[i][0]==darr[i][1]) {
				zorome++;
				if (zorome ==3) {
					System.out.println("Yes");
					return;
				}
			} else {
				zorome = 0;
			}
		}
		System.out.println("No");
		return;
	}

}


Measured memory_bytes: 35860
#include<bits/stdc++.h>
long N,M,x,y;
std::priority_queue<int>q;
main(){
for(std::cin>>N>>M;N--;q.push(x))std::cin>>x;
for(;M--;q.pop())q.push(q.top()/2);
for(;q.size();q.pop())y+=q.top();
 std::cout<<y;
}


Measured memory_bytes: 892
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(),v.rend() //reverse
#define vl vector<long long>v(n);
#define mii unordered_map<ll,ll>
double pi = 2*acos(0.0);
//ll power(ll a,ll b){ ll res=1;while(b){if(b&1)res=res*a;b=b/2; a=(a*a); }return res;}
 
 
    
      
 int main()
 {
       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
       ll tst;
       tst=1;
       //cin>>tst;
    
       while(tst--)
       {
         int n,k;
         cin>>n>>k;
         vl(n);
         for(int i=0;i<n;i++)
         {
               cin>>v[i];
         }
         sort(all(v));ll sum=0;
         for(int i=0;i<k;i++)
         {
               sum=sum+v[i];
         }
         cout<<sum<<endl;
       }
       
 }

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int main()
{

    int n,r;
    cin>>n;
    while(n>0)
    {
        r = n%10;
        if(r==7)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
        n = n/10;
    }
    cout<<"No"<<endl;

    return 0;
}


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

int main() {
    string odd,even;
    cin >> odd >> even;
    //string ans;
    string ans(odd.size()+even.size(), 'a');
    int odds = 0;
    int evens = 0;

    for(int i = 0;i < odd.size()+even.size();i++){
        if(i%2==0){
            ans.at(i) = odd.at(odds);
            odds++;
        }
        else{
            ans.at(i) = even.at(evens);
            evens++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	char c[4];
	int i;

	for (i = 0; i < 4; i++)
		scanf("%c", c + i);

	for (i = 0; i < 3; i++) {
		if (c[i] == c[i + 1]) {
			printf("Bad\n");
			return 0;
		}
	}

	printf("Good\n");
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using UL = unsigned long;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

    void Solve() {
        string C; cin >> C;
        for (char& c : C) if ('A' <= c && c <= 'Z') c = c - 'A' + 'a';
        UL ans = 0;
        while (true) {
            string S; cin >> S;
            if (S == "END_OF_TEXT") break;
            for (char& c : S) if ('A' <= c && c <= 'Z') c = c - 'A' + 'a';
            if (C == S) ans++;
        }
        cout << ans << endl;
    }
};
int main() {
    unique_ptr<Problem> p(new Problem());
    cout << fixed << setprecision(10);
    p->Solve();
    return 0;
}



Measured memory_bytes: 3136
package main
import . "fmt"
func main() {
  var n,m,c,a,s,x int
  var b []int
  Scan(&n,&m,&c)
  b = make([]int,m)
  for i:=0;i<m;i++ { Scanf("%d",&b[i]) }
  x = 0
  for k:=0;k<n;k++ {
    s = 0
    for i:=0;i<m;i++ {
      Scanf("%d",&a)
      s += b[i]*a
    }
    if s+c > 0 { x++ }
  }
  Println(x)
}

Measured memory_bytes: 512
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use itertools_num::ItertoolsNum;
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::iter;
#[allow(unused_imports)]
use superslice::*;

fn run() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let s = sc.read_chars();
    let mut k: usize = sc.read();

    let n = s.len();
    let mut ans = vec![];
    for i in 0..n {
        let d = s[i] as usize - 'a' as usize;
        let update = 26 - d;
        if d == 0 {
            ans.push(s[i]);
        } else if 26 <= k + d {
            ans.push('a');
            k -= update;
        } else {
            ans.push(s[i]);
        }
    }
    if k > 0 {
        // let n = ans.len();
        // let s_n = ans[n - 1];
        // let d = s_n as usize - 'a' as usize;
        // ans[n - 1] = (((d + k) % 26) as u8 + 'a' as u8) as char;
        ans[n - 1] = ('a' as u8 + ((ans[n - 1] as u8 - 'a' as u8) + (k % 26) as u8) % 26) as char;
    }
    println!("{}", ans.iter().collect::<String>());
}

fn main() {
    std::thread::Builder::new()
        .name("run".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(run)
        .unwrap()
        .join()
        .unwrap();
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn read_pairs<T: std::str::FromStr>(&mut self, n: usize) -> Vec<(T, T)> {
        (0..n).map(|_| (self.read(), self.read())).collect()
    }
    pub fn read_pairs_1_indexed(&mut self, n: usize) -> Vec<(usize, usize)> {
        (0..n)
            .map(|_| (self.read::<usize>() - 1, self.read::<usize>() - 1))
            .collect()
    }
    pub fn read_chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    pub fn read_char_grid(&mut self, n: usize) -> Vec<Vec<char>> {
        (0..n).map(|_| self.read_chars()).collect()
    }
    pub fn read_matrix<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n)
            .map(|_| (0..m).map(|_| self.read()).collect())
            .collect()
    }
}


Measured memory_bytes: 2436
#include <stdio.h>

int main(void){
	int d;
	scanf("%d",&d);
	if(d==25){
		printf("Christmas");
	}else if(d==24){
		printf("Christmas Eve");
	}else if(d==23){
		printf("Christmas Eve Eve");
	}else if(d==22){
		printf("Christmas Eve Eve Eve");
	}                                   
	return 0;
}

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

int main()
{
    string c1,c2;

    cin >> c1 >> c2;

    reverse(c1.begin(), c1.end());

    if (c1 == c2){
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }

    return 0;
}



Measured memory_bytes: 256
n,m=map(int,input().split())
s=[]
g=[]
for i in range(m):
  x,y=map(int,input().split())
  if x==1:
    s.append(y)
  elif y==n:
    g.append(x)
s=set(s)
g=set(g)
z=s.intersection(g)
print('POSSIBLE' if len(z)>0 else 'IMPOSSIBLE')

Measured memory_bytes: 21056
s = input()

first = s[:int((len(s)-1)/2)]
last  = s[int((len(s)+2)/2):]

isOK = True

for i in range(int(len(first)/2)):
    if first[i] != first[len(first)-i-1]:
        isOK = False
    
    if last[i] != last[len(last)-i-1]:
        isOK = False

    if first != last:
        isOK = False

if isOK:
    print('Yes')
else:
    print('No')

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

int main(void){
  while(1){
    int stone[50];
    for(int k = 0 ; k < 50 ; k++){stone[k] = 0;}

    int bowl;
    int n, p;  // n???????£?????????°???p????°????????????°
    cin >> n;
    cin >> p;

    if(n == 0 && p == 0){return 0;}

    bowl = p;

    bool flg = true;
    int ans;

    for(int i = 0 ; flg ; i = (i+1) % n){

      if(bowl == 0){
        bowl = bowl + stone[i];
        stone[i] = 0;
      }else{
        stone[i]++;
        bowl--;
        if(bowl == 0 && stone[i] == p){ans = i; flg = false;}
      }
    }

    cout << ans << endl;
  }
}

Measured memory_bytes: 2992
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; ++i)
#define rep1(i,n) for(ll i=1; i<=n; ++i)
#define revrep(i,n) for(ll i=n-1; n>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;
#define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false);
#define endl '\n'
template <class T> bool updmax(T& a, T b) { if (b > a) { a = b; return true;} return false;}
template <class T> bool updmin(T& a, T b) { if (b < a) { a = b; return true;} return false;}

int main() {
    fastio;
    ll ans=0;
    ll N;
    cin >> N;
    if (N % 2) {
        ans = 0;
    } else {
        ll d = 10;
        while (d <= N) {
            ans += N/d;
            d *= 5;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int c[500001];

int main(){
  int n;
  cin>>n;
  int len=0,mx=0;
  while(n--){
    int x;
    cin>>x;
    mx=max(mx,x);
    x=min(x,500000);
    if(!c[0]&&(len<x||(len==x&&mx<=x))){
      while(++c[x]==2)c[x--]=0;
      int llen=max(len,1);
      while(c[llen])llen++;
      len=llen-1;
      cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
  }
  return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  int a[m], b[m];
  for (int i = 0; i < m; i++) cin >> a[i] >> b[i];
  for (int i = 0; i < m; i++) {
    a[i]--; b[i]--;
  }
  bool e[n][n];
  memset(e, false, sizeof(e));
  for (int i = 0; i < m; i++) {
    e[a[i]][b[i]] = e[b[i]][a[i]] = true;
  }
  int res = 0;
  int v[n];
  for (int i = 0; i < n; i++) v[i] = i;
  do {
    bool t = true;
    for (int i = 0; i < n - 1; i++) {
      if (!e[v[i]][v[i + 1]]) {
        t = false;
        break;
      }
    }
    res += t; 
  } while (next_permutation(v + 1, v + n));
  cout << res << "\n";
  return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define INF INT_MAX/3

int main(){
    cin.sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    cout << (n - 1) * (m - 1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s; cin >> s;
    vector<int> v(26);
    rep(i,s.size()) {
        v[s[i]-'a']++;
    }
    int zindex;
    rep(i,26) {
        if(!v[i]) {
            cout << s + (char)('a'+i) << endl;
            return 0;
        }
    }
    set<int> se;
    se.insert((int)s[s.size()-1]);
    for(int i = s.size()-2; i>=0; i--) {
        for(auto val : se) {
            if((int)s[i]<val) {
                s = s.substr(0,i);
                cout << s + (char)val << endl;
                return 0;
            }
            se.insert(s[i]);
        }
    }
    cout << -1 << endl;

    return 0;
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

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

const int mod = 998244353;
const int N = 3e3+23;

int a, b, c, d;
long long dp[N][N];

long long rek(int i, int j) {
  if (i < a || j < b) return 0;
  if (i == a && j == b) return 1;
  long long &ret = dp[i][j];
  if (ret != -1) return ret;
  ret = rek(i-1, j)*j%mod;
  ret = (ret + rek(i, j-1)*i%mod)%mod;
  ret = (ret - rek(i-1, j-1)*(i-1)*(j-1)%mod + mod) % mod;
  return ret;
}

void solve() {
  memset(dp, -1, sizeof(dp));
  scanf("%d%d%d%d", &a, &b, &c, &d);
  printf("%lld", rek(c, d));
}

int main() {
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	llong N, K;
	vector<llong> A, rui, prui;

	cin >> N >> K;
	A.resize(N+1);
	rui.resize(N+1,0);
	prui.resize(N+1,0);
	for(int i = 1; i <= N; i++){
		cin >> A[i];
		rui[i] = rui[i-1] + A[i];
		prui[i] = prui[i-1] + (A[i] > 0 ? A[i] : 0);
	}

	llong ans = 0;
	for(int i = 1; i <= N-K+1; i++){
		llong res = prui[i-1] - prui[0] + prui[N] - prui[i+K-1];
		ans = max({ans,res, res + rui[i+K-1] - rui[i-1]});
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

using namespace std;
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}


typedef long long ll;

ll sum(ll n){
    ll s=0;
    while(n) {
        s+=n%10;
        n/=10;
    }
    return s;
}
int main() {
    std::ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    #ifndef ONLINE_JUDGE
   // freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif
    
    ll ans=1e9,b,sm;
    cin>>sm;
    for (ll i = sm-1; i >=1; --i) {
        b=sm-i;
       // cout<<sum(i)<<" "<<sum(b)<<"\n";
        ans=min(ans,sum(i)+sum(b));
    }
    cout<<ans<<"\n";
    
    

    return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<vector<long int>> path(n), score(n);
  for(int i = 0; i < n-1; i++){
    int a,b,w;
    cin >> a >> b >> w;
    a--;
    b--;
    path.at(a).push_back(b);
    path.at(b).push_back(a);
    score.at(a).push_back(w);
    score.at(b).push_back(w);
  }
  vector<int> out(n, -1);
  out.at(0) = 0;
  queue<int> q;
  q.push(0);
  while(!q.empty()){
    int u = q.front();
    q.pop();
    for(int i = 0; i < path.at(u).size(); i++){
      int v = path.at(u).at(i);
      if(out.at(v) != -1) continue;
      out.at(v) = (out.at(u) + score.at(u).at(i)) % 2;
      q.push(v);
    }
  }
  for(int i = 0; i < n; i++){
    cout << out.at(i) << endl;
  }
}

Measured memory_bytes: 12800
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<bits/stdc++.h>
using namespace std;
char ma[102][102];
int main(void)
{
    int a,b;
    cin>>a>>b;
    printf("100 100\n");
    for(int i = 0;i < 50;i++)
    {
        for(int j = 0;j < 100;j++)
        {
            ma[i][j] = '#';
            ma[i+50][j] = '.';
        }
    }
    a--;
    b--;
    int s = 0,j = 0;
    while(a)
    {
        a--;
        ma[s][j] = '.';
        j+=2;
        if(j == 100)
        {
            j = 0;
            s += 2;
        }
    }
    s = 99,j = 0;
    while(b)
    {
        b--;
        ma[s][j] = '#';
        j+=2;
        if(j == 100)
        {
            j = 0;
            s -= 2;
        }
    }
    for(int i = 0;i < 100;i++)
    {
        for(int j = 0;j < 100;j++)
        {
            printf("%c",ma[i][j]);
        }
        printf("\n");
    }
    return 0;
}


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

using namespace std;

int main()
{
   long n;
   cin>>n;
  long long count=0;

  count += (n/500)*1000;
  n=n%500;
   count += (n/5)*5;

   cout<<count;
   
}
//ā 

/*100
82 51 81 14 37 17 78 92 64 15 8 86 89 8 87 77 66 10 15 12 100 25 92 47 21 78 20 63 13 49 41 36 41 79 16 87 87 69 3 76 80 60 100 49 70 59 72 8 38 71 45 97 71 14 76 54 81 4 59 46 39 29 92 3 49 22 53 99 59 52 74 31 92 43 42 23 44 9 82 47 7 40 12 9 3 55 37 85 46 22 84 52 98 41 21 77 63 17 62 91
*/

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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

using V = complex<double>;

void dft(vector<V>& f, int64_t dir = 1) {
    int64_t n = f.size();

    if (n == 1) {
        return;
    }

    assert(n % 2 == 0);

    array<vector<V>, 2> ff;
    ff[0].resize(n / 2);
    ff[1].resize(n / 2);

    for (auto i : irange(0L, n)) {
        ff[i % 2][i / 2] = f[i];
    }

    dft(ff[0], dir);
    dft(ff[1], dir);

    double pi = acos(-1);
    V z = polar(1.0, 2 * pi * dir / n);
    V p = 1;
    for (auto i : irange(0L, n)) {
        f[i] = ff[0][i % (n / 2)] + p * ff[1][i % (n / 2)];
        p *= z;
    }
}

void inv_dft(vector<V>& f) {
    int64_t n = f.size();

    dft(f, -1);
    for (auto&& x : f) {
        x /= V(n);
    }
}

int main() {
    int64_t n, m;
    cin >> n >> m;

    vector<V> p(1L << 18);
    for (auto i : irange(0L, n)) {
        int64_t a;
        cin >> a;
        p[a] += 1;
    }

    dft(p);

    vector<V> q(p.size());
    for (auto i : irange(0uL, p.size())) {
        q[i] = p[i] * p[i];
    }

    inv_dft(q);

    int64_t ans = 0, num = 0;
    for (auto i : irange(0uL, q.size()) | reversed) {
        int64_t qq = q[i].real() + 0.5;

        if (num + qq > m) {
            ans += (m - num) * i;
            break;
        }

        ans += qq * i;
        num += qq;
    }

    cout << ans << endl;
}

Measured memory_bytes: 16924
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map{ it.toLong() }

    val minus = a.count { it<0L }
    val absScore = a.map{ Math.abs(it) }.sum()
    val absMin = a.map { Math.abs(it) }.min()!!
    println( if(minus%2==1) (absScore - absMin * 2) else absScore )

}

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

int main(){
    vector<int> v(4);
    vector<int> z(4);
    for (size_t i = 0; i < 5; i++) {
       v[i] = i+1;
    }

    for (size_t i = 0; i < 5; i++) {
        cin >> z[i];
    }

    for (size_t i = 0; i < 5; i++) {
        if(z[i] == 0) cout << v[i] <<endl;
    }
}


Measured memory_bytes: 3624
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <functional>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define	BitSetV(Val,Bit)		((Val) |= (Bit))			
#define	BitTstV(Val,Bit)		((Val) & (Bit))				
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define MAX_DWORD				(0xFFFFFFFF)
#define	MAX_SDWORD				((SDWORD)0x7FFFFFFF)
#define	MIN_SDWORD				((SDWORD)0x80000000)
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define	MIN_QWORD				((QWORD)0x0000000000000000)
#define	MAX_SQWORD				((SQWORD)0x7FFFFFFFFFFFFFFF)
#define	MIN_SQWORD				((SQWORD)0x8000000000000000)
#define M_PI					3.14159265358979323846

typedef long					SDWORD;
typedef long long				SQWORD;
typedef unsigned long			DWORD;
typedef unsigned long long int	QWORD;
typedef long long ll;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	int N;
	cin >> N;
	int x[8], y[8];
	REP(i, N) cin >> x[i] >> y[i];

	double ans = 0;
	for(int i = 0; i < N - 1; i++) {
		for(int j = i + 1; j < N; j++) {
			double pow = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
			ans += sqrt(pow);
		}
	}
	ans = ans * 2 / N;
	printf("%lf\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include<map>
#include<cstring>
#include<iomanip>
#include <string>
#include <vector>	
#include<unordered_map>
#include<unordered_set>
using namespace std;


typedef long long unsigned llu;
typedef long double ld;
#define ll long long
#define PI 3.14159265358979323846
#define For(i, a, b) for (int i = a, sz = (int)b; i < sz; i++)
#define rFor(i, a, b, c) for (int i = (a); i >= (b); i -= (c))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fill(a, b) memset(a, b, sizeof(a))
#define IO ios_base::sync_with_stdio(false), cin.tie(0),cout.tie(0)
const int mod = 1000000007;
const ll inf = 1000000000009;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) { return a*b/gcd(a,b);}

//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdoutn

int main()
{
	IO;
	int n{},a{},b{},x{1};
	cin>>n;
	vector<int>v(n);
	For(i,0,n)cin>>v[i];
	sort(all(v));
	for(int i=n-1;i>=0;i--)
	{
		if((x%2))a+=v[i],x++;
		else b+=v[i],x++;
	}
	cout<<a-b<<'\n';
//	system("pause");
	return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const ll mod=1e9+7;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    vector<ll>v1,v2;
    for(int i=0;i<n;i++){
        ll a;
        cin>>a;
        v1.push_back(a);
    }
    for(int i=0;i<n;i++){
        v2.push_back(v1[n-1-i]);
    }
    for(int i=0;i<n;i++){
        if(i==0){
            if(v2[i]>=v2[i+1]-1){v2[i]++;continue;}
            else{cout<<"No"<<endl;return 0;}
        }
        else if(i==n-1){
            if(v2[i]<=v2[i-1])continue;
            else{cout<<"No"<<endl;return 0;}
        }
        if(v2[i]>=v2[i+1]){
            if(v2[i]+1<=v2[i-1])v2[i]++;
            continue;
        }
        else{
            if(v2[i]+1<v2[i+1]){cout<<"No"<<endl;return 0;}
            else if(v2[i]+1>v2[i-1]){cout<<"No"<<endl;return 0;}
            else{v2[i]++;continue;}
        }
    }
    cout<<"Yes"<<endl;
    return 0;
    }


Measured memory_bytes: 2548
program main
  integer::n,i,j,k,ans,le
  !integer,allocatable::
  character(10000)::s
read(*,*)n

read(*,*)s
le=len(s)
!write(*,*) le
do i=1,n
  do j=1,le
    select case(s(j:j))
    case('A')
      s(j:j)='B'
    case('B')
      s(j:j)='C'
    case('C')
      s(j:j)='D'
    case('D')
      s(j:j)='E'
    case('E')
      s(j:j)='F'
    case('F')
      s(j:j)='G'
    case('G')
      s(j:j)='H'
    case('H')
      s(j:j)='I'
    case('I')
      s(j:j)='J'
    case('J')
      s(j:j)='K'
    case('K')
      s(j:j)='L'
    case('L')
      s(j:j)='M'
    case('M')
      s(j:j)='N'
    case('N')
      s(j:j)='O'
    case('O')
      s(j:j)='P'
    case('P')
      s(j:j)='Q'
    case('Q')
      s(j:j)='R'
    case('R')
      s(j:j)='S'
    case('S')
      s(j:j)='T'
    case('T')
      s(j:j)='U'
    case('U')
      s(j:j)='V'
    case('V')
      s(j:j)='W'
    case('W')
      s(j:j)='X'
    case('X')
      s(j:j)='Y'
    case('Y')
      s(j:j)='Z'
    case('Z')
      s(j:j)='A'
    end select
  end do
end do
s=trim(s(1:le))
write(*,'(a)') s
stop
end program


Measured memory_bytes: 768
#include "bits/stdc++.h"
using namespace std;
typedef long long lint;
int main() {
	lint n; cin >> n;
	string s;
	while (n) {
		if (n % 2)s = '1' + s;
		else s = '0' + s;
		n = ceil((double)n / (double)-2);
	}
	if (s == "")s = "0";
	cout << s << endl;
}

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

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;

const ll INF = 2e18;
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 5;

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	ll n, a, b;
	cin >> n >> a >> b;
	if(a > b) swap(a, b);
	if((b-a)%2) cout << min(a + (b-a-1)/2, n-b+1 + (n-(a+n-b+1))/2);
	else cout << (b-a)/2;
}


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

using namespace std;

#define int long long

void solve() {
    double kek;
    cin >> kek;
    cout.precision(12);
    cout << (kek / 3.0) * (kek / 3.0) * (kek / 3.0);
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


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

int main(){
    using namespace std;
    unsigned long T;
    cin >> T;
    for(unsigned long iter{0}, N; iter < T; ++iter){
        cin >> N;
        vector<pair<unsigned long, unsigned long>> f, b;
        f.reserve(N);
        unsigned long ans{0};
        for(unsigned long i{0}, k, l, r; i < N; ++i){
            cin >> k >> l >> r;
            if(l > r){
                ans += r;
                f.emplace_back(k, l - r);
            }else{
                ans += l;
                if(k < N)b.emplace_back(N - k, r - l);
            }
        }
        sort(begin(f), end(f));
        sort(begin(b), end(b));
        priority_queue<unsigned long, vector<unsigned long>, greater<>> pq;
        for(const auto& [k, c] : f){
            pq.emplace(c);
            while(pq.size() > k)pq.pop();
        }
        while(!pq.empty()){
            ans += pq.top();
            pq.pop();
        }
        for(const auto& [k, c] : b){
            pq.emplace(c);
            while(pq.size() > k)pq.pop();
        }
        while(!pq.empty()){
            ans += pq.top();
            pq.pop();
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 8208
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;

inline void up(int &x,const int &y){if(x<y)x=y;}
inline void down(int &x,const int &y){if(x>y)x=y;}
const int maxn = 110000;

int n;
char str[maxn];

int main()
{
	scanf("%s",str); n=strlen(str);
	int re=n-1;
	for(int k=0;k<26;k++)
	{
		int now=0;
		int las=-1;
		for(int i=0;i<n;i++) if(str[i]-'a'==k)
			up(now,i-(las+1)),las=i;
		up(now,(n-1)-las);
		down(re,now);
	}
	printf("%d\n",re);
	
	return 0;
}


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

Measured memory_bytes: 1712
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		long x = sc.nextLong();
		long a = 0l, b = 0l;
		boolean c = false;
		for(int i = -118; i < 120; i++) {
			if(c)break;
			a = i;
			for(int j = -118; j < 120; j++) {
				b = j;
				if(Math.pow(a, 5)-Math.pow(b, 5) == x) {
					c = true;
					break;
				}
			}
		}
		System.out.println(a + " " + b);
	}
	
	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}


Measured memory_bytes: 36896
#include <iostream>
#include <set>
using namespace std;
int main(){
    int N;
    int d[110];
    cin >> N;
    for(int i = 0;i < N; ++i) cin >> d[i];

    set<int> values;
    for(int i = 0; i < N; ++i) values.insert(d[i]);

    cout << values.size() << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <bitset>
#include <cmath>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define FI first
#define SE second
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<int>
#define VP vector<PA>
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define MOD 1000000007
#define INF 1000000007
#define PI 3.141592653589793238462643383279
using namespace std;
//
const int N=4000004;
bitset<N> A;
int main(){
  int N,S=0;
  A.set(0);
  cin>>N;
  FOR(i,0,N){
    int X;
    cin>>X;
    S+=X;
    A|=A<<X;
  }
  S=(S+1)/2;
  while(1){
    if(A[S]){
      cout<<S<<endl;
      return 0;
    }
    S++;
  }
}


Measured memory_bytes: 1664
X,Y = map(int, input().split())

if Y % 2 == 1:
    print("No") 

else:
    result_list = []    
    
    for a in range(X+1):
        result_list.append(2 * a + 4 * (X - a) == Y)
    
    if any(result_list):
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 9184
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define P pair<int, int>
typedef long long ll;
const ll mod = 1e9+7;

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//ngcd n個の最大公約数
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(ll i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
//nlcm n個の最小公倍数
ll nlcm(vector<ll> a) {
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size(); i++) {
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
ll digsum(ll x){
  ll res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}


int main(){
  string s;
  cin >> s;
  if(s[0] == s[1] && s[1] == s[2]){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
} 






Measured memory_bytes: 256
#include<iostream>
#define INF (1<<24)
using namespace std;

int compute(int a,int b,string str){
 
  int i=a,sum=0,tmp=INF,tmp2=INF,cnt=0;
  while(1){ //cout<<a<<' '<<b<<endl;
     
    sum=0;
    if(str[i]=='('){
      sum=compute(i+1,0,str);
      //cout<<sum<<endl;
      cnt=0;
      for(i=i;i<(int)str.size();i++){
    if(str[i]==')')cnt--;
    if(str[i]=='(')cnt++;
    if(cnt==0)break;
      }
      i++;
       
    }else{
      while(1){
    if('0'<=str[i]&&str[i]<='9'){
      sum*=10;
      sum+=(str[i]-'0');
      i++;
    }else{
      break;
    }
      }
    }
 
    if(b==1){
      sum*=-1;
      b=0;
    }
    if(tmp!=INF){
      sum*=tmp;
      tmp=INF;
    }
    if(tmp2!=INF){
      sum=tmp2/sum;
      tmp2=INF;
    }
    //if(a==8)cout<<sum<<endl;   
    if(str[i]=='\0'||str[i]==')'||str[i]=='='||i==(int)str.size())return sum;
    if(str[i]=='+')return sum + compute(i+1,0,str);
    if(str[i]=='-')return sum + compute(i+1,1,str);
    if(str[i]=='*'){
      i++;
      tmp=sum;
    }else if(str[i]=='/'){
      i++;
      tmp2=sum;
    }
  }
       
}
int check(string str){
  int x=0,y=0;
  string t[3];
  for(int i=0;i<(int)str.size();i++){
    if(str[i]=='+'||str[i]=='='){
      t[y++]=str.substr(x,i-x);
      x=i+1;
    }
  }
  t[y]=str.substr(x);
  /*
  for(int i=0;i<3;i++){
    cout<<t[i]<<endl;
  }
  */
  if(t[0][0]=='X'&&t[0][1]!='\0')return 1;
  if(t[1][0]=='X'&&t[0][1]!='\0')return 1;
  if(t[1][0]=='X'&&t[0][1]!='\0')return 1;
  return 0;
  
}

int main(){
  int x,A,B,i,f;
  string str,tmp;
  
  while(cin>>str){
    
    tmp=str;
    for(i=check(tmp);i<=9;i++){

      str=tmp;f=0;
      for(int j=0;j<(int)str.size();j++){
	if(str[j]=='X'){
	  str[j]='0'+i;
	}
	if(str[j]=='=')x=j;
      }//j
      if(f)continue;
      //cout<< str.substr(0,x)<<' '<<str.substr(x+1) <<endl;
      A=compute(0,0,str.substr(0,x));
      B=compute(0,0,str.substr(x+1));
      //cout<<A<<' '<<B<<endl;
      if(A==B){
	cout<<i<<endl;
	break;
      }
    }//i
    if(i==10)cout<<"NA"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1192
#include <cstdio>
#include <cstring>

const int mxn = 100005;

int n, t[mxn], q[mxn], d[mxn];

signed main() {
	scanf("%d", &n);

	for (int i = 1; i <= n; ++i)
		scanf("%d", t + i);

	memset(d, 0x3f, sizeof d);

	int l = 0, r = 0;

	d[q[r++] = 1] = 0;

	while (l != r) {
		int u = q[l++], v = t[u];

		if (d[v] > d[u] + 1)
			d[v] = d[u] + 1, q[r++] = v;
	}

	if (d[2] < d[0])
		printf("%d\n", d[2]);
	else
		puts("-1");
}

Measured memory_bytes: 1408
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define answer cout << ans << endl;
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
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> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;

//auto mod int
using ll = long long;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}

  mint comb(int r){//O(r)で間に合うようなrのみ使用可能
    mint x=1,y=1;
    for(int i=0;i<=r-1;i++){
      y*=*this-i;
      x*=i+1;
    }
    return y/x;
  }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

signed _main(){
  int n,a,b; cin >> n >> a >> b;
  cout << mint(2).pow(n)-1-mint(n).comb(a)-mint(n).comb(b) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
using namespace std;
using ui = unsigned int;
using ul = unsigned long;
#pragma GCC optimize("Ofast")
#define loop(i, n) for (ui i = 0; i < n; i++)
struct BIT
{
private:
    vector<ul> bit;
    ui n;
    inline ul sum(ui x)
    {
        ul ret = 0;
        while (x > 0)
        {
            ret += bit[x];
            x -= x & -x;
        }
        return ret;
    }

public:
    BIT(ui n0, vector<ul> &A) : bit(n0 + 1, 0), n(n0)
    {
        for (ui i = 1; i <= n; i++)
            bit[i] = A[i - 1];
        for (ui i = 1; i < n; i++)
            bit[i + (i & -i)] += bit[i];
    }
    inline ul sum(ui l, ui r)
    {
        return sum(r + 1) - sum(l);
    }
    inline void add(ui i, ul x)
    {
        i++;
        while (i <= n)
        {
            bit[i] += x;
            i += i & -i;
        }
    }
};
#define scan(x) scanf("%ld", &x)
#define putout(a) printf("%ld\n", a)
int main()
{
    ui N, Q;
    scan(N), scan(Q);
    vector<ul> A(N);
    loop(i, N) scan(A[i]);
    BIT data(N, A);
    loop(i, Q)
    {
        ui a;
        ul b, c;
        scan(a);
        scan(b);
        scan(c);
        if (a == 0)
            data.add(b, c);
        else
            putout(data.sum(b, c - 1));
    }
    return 0;
}


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

using namespace std;

const int D = 80 * 160 + 10;
const int D2 = D * 2;

int h, w;
int a[100][100];
bitset<D2> dp[90][90];

int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int x;
      cin >> x;
      a[i][j] = x;
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int x;
      cin >> x;
      a[i][j] = abs(a[i][j] - x);
    }
  }

  dp[0][0][D - a[0][0]] = 1;
  dp[0][0][D + a[0][0]] = 1;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (i) {
        dp[i][j] |= dp[i - 1][j] << a[i][j];
        dp[i][j] |= dp[i - 1][j] >> a[i][j];
      }
      if (j) {
        dp[i][j] |= dp[i][j - 1] << a[i][j];
        dp[i][j] |= dp[i][j - 1] >> a[i][j];
      }
    }
  }

  int ans = D2;
  for (int i = 0; i < D2; i++) {
    if (dp[h - 1][w - 1][i]) {
      ans = min(ans, abs(i - D));
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 24832
def binary_search(arr, max, k)
  left = 0
  right = max
  while left < right do
    mid = (left + right) / 2
    if can_load?(arr.dup, k, mid)
      right = mid
    else
      left = mid + 1
    end
  end
  return left
end

def can_load?(arr,k, p)
  k.times do
    k_load = 0
    while true
      if arr.length == 0
        break
      end

      if k_load + arr[0] <= p
        k_load += arr.shift
      else
        break
      end
    end
  end
  arr.length == 0
end

n, k = gets.split.map(&:to_i)
arr = []
n.times do
  arr << gets.to_i
end
max = 100000 * 10000
ans = binary_search(arr, max, k)
puts ans


Measured memory_bytes: 8956