akhauriyash/Code-Regression huggingface dataset:
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	aStr, _ := reader.ReadString('\n')
	bStr, _ := reader.ReadString('\n')
	cStr, _ := reader.ReadString('\n')
	dStr, _ := reader.ReadString('\n')
	eStr, _ := reader.ReadString('\n')
	aStr = strings.Trim(aStr, "\n")
	bStr = strings.Trim(bStr, "\n")
	cStr = strings.Trim(cStr, "\n")
	dStr = strings.Trim(dStr, "\n")
	eStr = strings.Trim(eStr, "\n")

	a, err := strconv.Atoi(aStr)
	if err != nil {
		log.Fatalln(err)
	}
	b, err := strconv.Atoi(bStr)
	if err != nil {
		log.Fatalln(err)
	}
	c, err := strconv.Atoi(cStr)
	if err != nil {
		log.Fatalln(err)
	}
	d, err := strconv.Atoi(dStr)
	if err != nil {
		log.Fatalln(err)
	}
	e, err := strconv.Atoi(eStr)
	if err != nil {
		log.Fatalln(err)
	}

	sum := roundUp(a) + roundUp(b) + roundUp(c) + roundUp(d) + roundUp(e)
	lastC := lastC([]int{a, b, c, d, e})
	if lastC != 0 {
		sum -= 10 - lastC
	}

	fmt.Println(sum)
}

func roundUp(n int) int {
	c := n % 10
	if c == 0 {
		return n
	} else {
		return n + 10 - c
	}
}

func lastC(nums []int) int {
	var lastC int
	for _, num := range nums {
		c := num % 10
		if c != 0 && (lastC == 0 || c < lastC) {
			lastC = c
		}
	}
	return lastC
}


Measured memory_bytes: 640
# coding: utf-8
# Your code here!

A, B, C = map(int, input().split())

d = 0
cnt = 0
while True:
   d += 1
   if d % 7 == 0:
      cnt += (A + B)
   else:
      cnt += A
   if cnt >= C:
      print(d)
      break


Measured memory_bytes: 5600
n = gets.chomp.to_i
a = [0]
v = [false] * n
n.times do
  a << gets.chomp.to_i
end

i = 1
c = 0
loop do
  v[i] = true
  i = a[i]
  c += 1

  if i == 2
    puts c
    break
  end
  if v[i]
    puts '-1'
    break
  end
end


Measured memory_bytes: 3452
import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);for(int n;(n=s.nextInt())>0;){char[]c=s.next().toCharArray();int[][]a=new int[n][];for(int i=0;i<n;++i)a[i]=new int[]{s.nextInt()-1,s.nextInt()-1};for(;n-->0;){int u=a[n][0],v=a[n][1],x=(v-u)%26,t=c[u]+x,p=c[v]+x;c[u]=(char)(p-(p>122?26:0));c[v]=(char)(t-(t>122?26:0));}System.out.println(new String(c));}}}

Measured memory_bytes: 12000
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N; cin >> N;
    vector<int> A(N), B(N - 1);
    cin >> B[0];
    A[0] = B[0], A[1] = B[0];
    ll sum = (ll) A[0];
    for (int i = 1; i < N-1; i++) {
        cin >> B.at(i);
        if (A[i] > B[i]) A[i] = B[i];
        sum += (ll) A[i];
        A[i+1] = B[i];
    }
    cout << sum + (ll) A[N-1] << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# C

import sys
from decimal import Decimal
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

a, b = input().split()

print(int(Decimal(a) * Decimal(b)))




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


void solve(long long a, std::string s){
    if(a<3200){
        cout<<"red"<<endl;
    }
    else{
        cout<<s<<endl;
    }
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long a;
    scanf("%lld",&a);
    std::string s;
    std::cin >> s;
    solve(a, s);
    return 0;
}


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

constexpr int MAX_N = 1e5;

string s[MAX_N];
bool used[MAX_N];

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

  for (int i{}; i < N; ++i) {
    cin >> s[i];
    sort(s[i].begin(), s[i].end());
  }
  sort(s, s+N);

  long ans{};
  string prev = s[0];
  long sum{};
  for (int i{1}; i < N; ++i) {
    if (prev != s[i]) {
      ans += (sum + 1) * sum / 2;
      sum = 0;
      prev = s[i];
    } else {
      ++sum;
    }
  }
  ans += (sum + 1) * sum / 2;

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


Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  string ans = "No";
  int X = 0;
  int tN = N;
  while (tN>0){
    X += tN%10;
    tN /= 10;
  }
  if (N%X == 0) ans = "Yes";
  
  cout << ans << endl; 
  
} 


Measured memory_bytes: 3604
#include <iostream>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

void solve(std::string s){
    REP(i, s.size())
        if (i % 2 == 0) cout << s[i];
    cout << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::string s;
    std::cin >> s;
    solve(s);
    return 0;
}


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

using namespace std;

int main() {
  int n;
  string s;
  cin >> n;
  cin >> s;
  int count_w[n], count_e[n];
  count_w[0] = 0;
  count_e[n - 1] = 0;
  if (s[0] == 'W') count_w[0]++;
  if (s[n - 1] == 'E') count_e[n - 1]++;
  for (int i = 1; i < n; i++) {
    count_w[i] = count_w[i - 1];
    if (s[i] == 'W') count_w[i]++;
  }

  for (int i = n - 2; i >= 0; i--) {
    count_e[i] = count_e[i + 1];
    if (s[i] == 'E') count_e[i]++;
  }

  int ans = min(count_e[1], count_w[n - 2]);
  for (int i = 1; i < n - 1; i++) {
    ans = min(ans, count_w[i - 1] + count_e[i + 1]); 
  }

  cout << ans;

}


Measured memory_bytes: 2948
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

const int Cin()
{
    int n;
    cin >> n;
    return n;
}

int main()
{
    int N = Cin(), M = Cin();
    multimap<int, int> dayToPayoffMap;
    for (int i = 0; i < N; ++i)
    {
        int Ai = Cin(), Bi = Cin();
        dayToPayoffMap.insert({ Ai, Bi });
    }
    // (M-1)日後から逆順にその時選べる報酬最大のアルバイトを選んでいく
    multiset<int> availablePayoffSet;
    LLONG ans = 0;
    for (int day = 1; day <= M; ++day)
    {
        auto range = dayToPayoffMap.equal_range(day);   // O(logN)
        for (auto itr = range.first; itr != range.second; ++itr)
        {
            availablePayoffSet.insert(itr->second); // O(<logN)
        }
        if (!availablePayoffSet.empty())
        {
            auto maxPayoffItr = --availablePayoffSet.end();
            ans += *maxPayoffItr;
            availablePayoffSet.erase(maxPayoffItr);
        }
    }
    cout << ans << endl;
}


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

int main()
{
    int n,x;
    int cnt=0,point=0;
    cin>>n>>x;
    vector<int>L(n);
    for(int i=0; i<n; i++){
        cin>>L[i];
    }
    for(int i=0; i<n+1; i++){
        if(i==0){point = 0;}
        else { point = point+L[i-1];}
        
        if(point<=x){
            cnt++;
            //cout << point <<endl;
        }
        else { break; }
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>

#define INF 1 << 28

using namespace std;

int building[2][101];
int dp[2][101];
int n;

void solve(int b, int level){
	int nb = 1 - b;
	for(int i=0;i<3;i++){
		int nl = level+i;
		if(nl >= n) continue;
		while(building[nb][nl] == 1 && building[nb][nl+1] == 1){
			nl++;
		}
		while(building[nb][nl] == 2) nl--;
		if(dp[nb][nl] > dp[b][level] + 1){
			dp[nb][nl] = dp[b][level]+1;
			solve(nb, nl);
		}
	}
}

int main(){
	while(cin >> n && n){
		int tmp=0;
		fill((int *)dp, (int *)dp+2*101, INF);
		
		for(int i=0;i<2;i++){
			for(int j=0;j<n;j++){
				cin >> building[i][j];
			}
		}
		//ツ氾板閉コ
		building[0][n] = 0;
		building[1][n] = 0;
		
		tmp = 0;
		while(building[0][tmp] == 1 && building[0][tmp+1] == 1){
			tmp++;
		}
		dp[0][tmp] = 0;
		solve(0,tmp);
		tmp = 0;
		while(building[1][tmp] == 1 && building[1][tmp+1] == 1){
			tmp++;
		}
		dp[1][tmp] = 0;
		solve(1,tmp);
		if(dp[0][n-1] == INF && dp[1][n-1] == INF){
			cout << "NA" << endl;
		}else{
			cout << min(dp[0][n-1], dp[1][n-1]) << endl;
		}
	}
}

Measured memory_bytes: 0
import Control.Applicative ((<$>), (<*>))
import Data.List (tails, inits)
import Data.Bool (bool)

main :: IO ()
main = solve <$> getLine <*> getLine >>= putStrLn

solve :: String -> String -> String
solve s t = bool "No" "Yes" . elem t . (zipWith (++) <$> tails <*> inits) $ s


Measured memory_bytes: 508
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

using ll = long long;

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main(){
	ll n;

	cin >> n;

	vector<pair< ll ,ll > > ab;
	
	for (size_t i = 0; i < n; ++i) {
		ll a_tmp;
		ll b_tmp;
		cin >> a_tmp;
		cin >> b_tmp;

		ab.push_back(make_pair(a_tmp, b_tmp));
	}

	// sort by limit time
	sort(begin(ab), end(ab), compare_by_b);
	
	string ret = "Yes";

	ll sum_time = 0;
	for (size_t i = 0; i < n; ++i) {
		sum_time += ab.at(i).first;
		if (sum_time > ab.at(i).second) {
			ret = "No";
			break;
		}
	}

	cout << ret << endl;
	
	return 0;
}

Measured memory_bytes: 6128
#include<stdio.h>
int main(void) {
	int A, B;
	int num_plug, num_A;
	scanf("%d", &A);
	scanf("%d", &B);
	num_A = 0;
	num_plug = 1;
	while (1) {
		if (num_plug >= B)break;
		num_plug = num_plug + A - 1;
		num_A += 1;
	}
	printf("%d",num_A);
	return 0;
}

Measured memory_bytes: 128
# /usr/bin/env python3


def compute(a, b):
    max_v = b * 200
    for v in range(1, max_v):
        if int(v * 0.08) == a and int(v * 0.1) == b:
            return v
    else:
        return None


def main():
    a, b = (int(x) for x in input().split())
    res = compute(a, b)
    print(-1 if res is None else res)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define NIL -1

int d[1003][1003];
char e[1002];
char f[1002];

int max(int,int);
int seq(int,int);

int main()
{
    int a;
    scanf("%d",&a);
    int i;
    for(i=1;i<=a;i++)
    {
        int j,k;
        for(j=0;j<=1000;j++)
        {
            for(k=0;k<=1000;k++)
            {
                d[j][k]=NIL;
            }
        }
    
        scanf("%s %s",e,f);
        printf("%d\n",seq (strlen(e)-1,strlen(f)-1)); 
    }
    return 0;
}

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

int seq(int x,int y)
{
    if(x==-1||y==-1) return 0;
    if(d[x][y]==NIL)
    {
        if(e[x]==f[y])d[x][y]=seq(x-1,y-1)+1;
        else d[x][y]=max(seq(x-1,y),seq(x,y-1));
        
    }
    return d[x][y];
}


Measured memory_bytes: 5772
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin>>n;
  vector<ll>l(n+1),r(n+1),a(n);
  rep(i,n){
    cin>>a[i];
  }
  rep(i,n){
    l[i+1]=max(l[i],a[i]);
  }
  rrep(i,n){
    r[i]=max(r[i+1],a[i]);
  }
  rep(i,n){
    cout<<max(l[i],r[i+1])<<endl;
  }
  return 0;

}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

typedef pair<int,int> P;

int nextInt() { int x; scanf("%d", &x); return x;}

struct BIT {
  int n;
  vector<ll> tree;
  BIT(int n):n(n),tree(n+1) {}
  void fill(ll val) {
    REP(i, n+1) tree[i] = (i&-i) * val;
  }
  void add(int idx, ll val) {
    for (int x=idx+1; x<=n; x+=x&-x) tree[x] += val;
  }
  // sum[0, idx]
  ll range(int idx) {
    ll sum=0;
    for (int x=idx+1; x>0; x-=x&-x) sum += tree[x];
    return sum;
  }
  // sum[a, b]
  ll range(int a, int b) {
    return range(b) - range(a - 1);
  }
};

const int MAX_N = 312345;
const int MAX_M = 112345;
P ps[MAX_N];
int ans[MAX_M];

int len(P p) {
  return p.second - p.first + 1;
}

int main2() {
  int N = nextInt();
  int M = nextInt();
  REP(i, N) {
    int a = nextInt();
    int b = nextInt();
    ps[i] = {a, b};
  }
  sort(ps, ps + N, [](const P &a, const P& b){
    return len(a) < len(b);
  });

  BIT bit(M+10);

  int pi = 0;
  for (int d = 1; d <= M; d++) {
    while (pi < N && len(ps[pi]) < d) {
      bit.add(ps[pi].first,      +1);
      bit.add(ps[pi].second + 1, -1);
      pi++;
    }
    int res = N - pi;
    for (int k = 0; k <= M; k += d) {
      res += bit.range(k);
    }
    ans[d] = res;
  }

  for (int d = 1; d <= M; d++) {
    printf("%d\n", ans[d]);
  }
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


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

const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 5;

ll modpow(ll a, ll b) {
  ll res = 1;
  while (b) {
    if (b&1)
      res = (res * a) % MOD;
    a = (a * a) % MOD;
    b >>= 1;
  }
  return res;
}

ll f[MAXN];
ll invf[MAXN];

ll ncr(ll n, ll r) {
  if (r == 0 || n == r) return 1;
  return (((f[n] * invf[n-r]) % MOD) * invf[r]) % MOD;
}

int main() {
  int h, w, a, b;
  cin >> h >> w >> a >> b;
  f[0] = 1;
  for (int i = 1; i < MAXN; i++) {
    f[i] = (f[i-1] * i) % MOD;
    invf[i] = modpow(f[i], MOD-2);
  }
  ll res = 0;
  for (int i = b; i < w; i++) {
    int y1 = h - a - 1, x1 = i;
    int y2 = a - 1, x2 = w - i - 1;
    ll p = (ncr(x1 + y1, x1) * ncr(x2 + y2, x2)) % MOD;
    res = (res + p) % MOD;
  }
  cout << res << '\n';
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define show(x) cout << #x << " = " << (x) << endl;
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl;
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

int main () {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;

  string ans;
  const int dx = tx - sx, dy = ty - sy;
  ans += string(dy,'U');
  ans += string(dx,'R');
  ans += string(dy,'D');
  ans += string(dx,'L');

  ans += string(1,'L');
  ans += string(dy+1,'U');
  ans += string(dx+1,'R');
  ans += string(1,'D');
  ans += string(1,'R');
  ans += string(dy+1,'D');
  ans += string(dx+1,'L');
  ans += string(1,'U');

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

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

using namespace std;

double arr[3006];
double dp[3006][3006];

int main(){
	int n;
	cin>>n;
	double ans = 0; 
	for(int x=1;x<=n;x++) cin>>arr[x];
	dp[0][0] = 1;
	for(int x=0;x<=n;x++){
		for(int i=0;i<=n;i++){
			if(x + i == 0) continue;
			dp[x][i] = 0;
			if(x+i <= n){
				if(x-1 >=0) dp[x][i] += dp[x-1][i]*(1 - arr[x+i]);
				if(i-1 >=0) dp[x][i] += dp[x][i-1]*(arr[x+i]);
			}
			if(x+i == n && i>x) ans+= dp[x][i];
		}
	}
	cout<<fixed<<setprecision(16)<<ans;
	return 0;
}

Measured memory_bytes: 70784
#include<bits/stdc++.h>
#define int long long
#define x first
#define y second
#define pb push_back

#define speed ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;

set<int> st;
signed main()
{
    int n,m;cin>>n>>m;
    std::vector<pair<int,int>> inp(n);
    for(int i=m;i>0;--i)
    {
        st.insert(i);
    }
    for(int i=0;i<n;++i)
    {
        cin>>inp[i].y>>inp[i].x;
    }
    sort(inp.begin(),inp.end());
    int ans=0;
    for(int i=n-1;i>=0;--i)
    {
        int days=inp[i].y;
        auto it=st.lower_bound(days);
        if(it!=st.end())
        {
            st.erase(it);
            ans+=inp[i].x;
        }
        if(st.empty()){break;}
    }
    cout<<ans;

}

Measured memory_bytes: 6528
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using pii = pair<int, int>;
const int MOD = (int)1e9 + 7, INF = (1 << 27); const ll INFLL = (1LL << 55);
#define FOR(i,a,b) for(int (i)=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
template<typename T, typename U> static void chmin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void chmax(T &x, U y) { if (x < y) x = y; }


ll f(ll b, ll n) {
    if (b > n) return n;
    else return f(b, n / b) + n%b;
}

vector<ll> divisors(ll n) {
    vector<long long> res;
    for (ll i = 1; i * i <= n; i++) if (n % i == 0) {
        res.push_back(i);
        if (i != n / i) res.push_back(n / i);
    }
    sort(res.begin(), res.end());
    return res;
}

int main() {
    ll n, s; cin >> n >> s;
    if (n == s) {
        cout << s + 1 << endl; return 0;
    }
    if (n - s < 0) {
        cout << -1 << endl; return 0;
    }
    FOR(b, 2, 1e6) if (f(b, n) == s) {
        cout << b << endl; return 0;
    }

    auto divs = divisors(n - s);
    ll mb = INFLL;
    for (ll d : divs) {
        ll b = (n - s) / d + 1;
        if (b >= 2 && f(b, n) == s) chmin(mb, b);
    }
    cout << (mb == INFLL ? -1 : mb) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int T , ca;
const int N = 200005;
const int Q = 1e9 + 7;
int n , d[N] , p[N] , f[N] , nxt[N][26];
char str[N];
bool v[26];
void work() {
    int i , j ;
    scanf("%s" , str +1);
    n = strlen(str + 1);
    for(j = 0 ; j < 26 ; ++ j)
        nxt[n + 1][j]= n + 1;
    for(i = n ; i > 0 ; -- i) {
        for(j = 0 ; j < 26 ; ++ j)
            nxt[i][j] = nxt[i + 1][j];
        nxt[i][str[i] - 'a'] = i;
    }
    for(j = 0 ;j < 26 ; ++ j)
        nxt[0][j] = nxt[1][j];
    for(i = n ; i >= 0 ; -- i) {
        d[i] = 1 << 30 , f[i] = 0;
        for(j = 0 ; j < 26 ; ++ j) {
            int x = nxt[i + 1][j];
            if(x <= n) {
                if(d[x] < d[i]) {
                    d[i] = d[x];
                    p[i] = x;
                    f[i] = j;
                }
            } else {
                d[i] = -1;
                f[i] = j;
                break;
            }
        }
        ++ d[i];
        //printf("%d : %d %d %d\n" , i , d[i] , p[i] , f[i]);
    }
    int T = d[0] + 1, x = 0;
    while (T --) {
        putchar(f[x] + 'a');
        x = p[x];
    }
    puts("");
}

int main() {
    work();
    return 0;
}


Measured memory_bytes: 23040
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int n;
  cin>> n;
  vector<int> p(n);
  rep(i,n){
    cin>>p[i];
  }
 int k=0;
  rep(i,n){
    if(p[i]!=i+1){
      k++;
    }
  }
    if(k==0||k==2){
      cout<<"YES"<<endl;
    }
    else {
      cout<<"NO"<<endl;
    }
    return 0;
  }

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int b1, b2, b3;
  cin >> b1 >> b2 >> b3;
  if(b1 == b2 && b2 != b3)
    cout << "Open\n";
  else
    cout << "Close\n";
  return 0;
}

Measured memory_bytes: 1124
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

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

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func main() {
	sc.Split(bufio.ScanWords)
	fmt.Println(strings.Replace(next(), ",", " ", -1))
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k , n , temp, temp1, max, first;
    vector <int> v;
    cin >> k;
    cin >> n;
    cin >> temp;
    first=temp;
    for(int i=0; i<n-1; i++){
        cin >> temp1;
        v.push_back(temp1-temp);
        temp=temp1;
    }
    v.push_back(k+first-temp1);
    max=v[0];
    for(int i=1; i<n; i++){
        if(max<v[i]){
            max=v[i];
        }
    }
    cout << k-max;
    return 0;
}

Measured memory_bytes: 1400
import java.util.Scanner;

public class Main {
    //http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_3_A
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int S = in.nextInt();//target
        int a[] = new int[n+1];
        for(int i = 0; i<n ;i++){
            a[i] = in.nextInt();
        }
        //use two pointer
        int p1 = 0, p2 = 0;
        int min = n+1;//smallest size
        int prevSum = 0;
        for(p1  =0; p1<n ;p1++){
            //p2 = p1;
            int sum = prevSum;
            while(sum<S){
                if(p2==n) break;
                sum+= a[p2];
                p2++;
            }
            if(sum>=S){
                if(min>(p2-p1)) min  = p2-p1;

            }
            prevSum = sum-a[p1];

        }
        if(min == n+1) System.out.println(0);
        else System.out.println(min);

    }

}



Measured memory_bytes: 70536
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;//998244353;

template<class _T> static void get(_T& a) {
	std::cin >> a;
}
template<class _T> static void get(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void get(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}
template<class _T> static void getint(_T& a) {
	if (sizeof(_T) > sizeof(int)) {
		scanf("%lld", &a);
	}
	else {
		scanf("%d", &a);
	}
}

static void exec();

int main()
{
	exec();
	fflush(stdout);
	return 0;
}

static void exec()
{
	LLONG N;
	get(N);

	int ans = MOD_NUM;
	LLONG limit = (LLONG)sqrt(N) + 1;
	for (int i = 1; i <= limit; i++) {
		if (N % i == 0) {
			LLONG A = N / i;

			int da = 0;
			while (A) {
				da++;
				A /= 10;
			}
			LLONG B = i;
			int db = 0;
			while (B) {
				db++;
				B /= 10;
			}
			ans = std::min(std::max(da, db), ans);
		}
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 3684
def main():

    S = list(input())
    S= S[0:-2] if len(S)%2==0 else S[0:-1]
    while(True):

        half = len(S)//2
        if S[0:half]==S[half:]:
            print(len(S))
            exit()
        else:
            S = S[:-2]






if __name__ == "__main__":
    main()



Measured memory_bytes: 2940
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
		
		StringTokenizer st = new StringTokenizer(br.readLine());
		int N = Integer.parseInt(st.nextToken());
		int K = Integer.parseInt(st.nextToken());
		
		int[] prices = new int[N];
		
		st = new StringTokenizer(br.readLine());
		
		for(int i=0;i <prices.length; i++)
			prices[i] = Integer.parseInt(st.nextToken());
		
		Arrays.sort(prices);
		
		int sum = 0;
		for(int i=0; i<K; i++)
			sum += prices[i];
		
		bw.write(sum + "\n");
		bw.flush();
	}

}


Measured memory_bytes: 36524
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;
const double PI=acos(-1);

int main(){
	ll r, c, m; cin >> r >> c >> m;
	vector<vector<ll>> v(r, vector<ll>(c, 0));
	for(ll i = 0; i < m; i++){
		ll a, b, c; cin >> a >> b >> c;
		a--; b--;
		v[a][b] = c;
	} 

	vector<vector<vector<ll>>> dp(r + 1, vector<vector<ll>>(c + 1, vector<ll>(4, 0)));

	for(ll i = 0; i < r; i++){
		for(ll j = 0; j < c; j++){
			// ひろうか？
			for(ll k = 2; k >= 0; k--){
				dp[i][j][k + 1] = max(dp[i][j][k + 1], dp[i][j][k] + v[i][j]);
			}
			// 下がるか？
			for(ll k = 0; k < 4; k++){
				dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][k]);
				dp[i][j + 1][k] = max(dp[i][j + 1][k], dp[i][j][k]);
			}
		}
	}

	ll ans = 0;
	for(ll i = 0; i < 4; i++){
		ans = max(ans, dp[r - 1][c - 1][i]);
	}

	cout << ans << endl;
}


Measured memory_bytes: 707176
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    string s;
    cin >> s;
    long long ans = 0;
    long long a = 0;
    long long ab = 0;
    long long d = 1;
    rep(i,s.size()){
        if(s[i] == 'A'){
            a+=d;
        }
        else if(s[i] == 'B'){
            ab += a;
        }
        else if(s[i] == 'C'){
            ans += ab;
        }
        else{
            ans = 3*ans + ab;
            ab = 3*ab + a;
            a = 3*a + d;
            d = 3*d;
        }
        ans%=MOD;
        ab%=MOD;
        a%=MOD;
        d%=MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

N,A,B  =  inputIL()

print(min(N*A,B))

Measured memory_bytes: 63980
module Main where
import qualified Control.Monad as C
import qualified Data.Char as C
import qualified Data.List as L
import qualified Data.Map as M
import qualified Data.Array as A

int = read :: String -> Int
getWord :: IO String
getWord = do
  c <- getChar
  if C.isSpace c
  then
    return []
  else do
    ws <- getWord
    return (c:ws)
getInt = fmap int getWord
replace pred a = map (\x -> if pred x then a else x)

main = interact $ printer . solver . parser
parser = map int . words
printer = unlines . map show

solver (n:as) =
  if oddn > evnn then (oddn:length oddorder:oddorder)
                 else (evnn:length evnorder:evnorder)
  where
    (oddn, oddorder) = deleting as id
    (evnn, evnorder) = deleting (tail as) (1:)


deleting :: [Int] -> ([Int]->[Int]) -> (Int, [Int])
deleting (a1:[]) order = (a1, (order []))
deleting (a1:a2:[]) order = deleting [a1] (order . (2:))
deleting (a1:a2:a3:[]) order
  | a1 < 0 && a1 < a3 = deleting [a3] (order . (1:) . (1:))
  | a3 < 0 && a3 < a1 = deleting [a1] (order . (3:) . (2:))
  | True              = deleting [a1+a3] (order . (2:))
deleting (a1:a2:a3:a4:as) order
  | a1 < 0 && a1 <= a3 = deleting (a3:a4:as) (order . (1:) . (1:))
  | a3 < 0 && a3 < a1 = deleting (a1:(a2+a4):as) (order . (3:))
  | True              = deleting ((a1+a3):a4:as) (order . (2:))



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

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

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

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


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

/* Binary Indexed Tree(0-index) */

struct BIT{
  typedef int Type;
  int bit_size;
  vector<Type> data;
  
  BIT(int n){
    bit_size = n;
    data.assign(n+1,0);
  }
  
  //add x to kth value
  void add(int k,Type x){
    k += 1;
    
    while(k<=bit_size){
      data[k]+=x;
      k+= k&(-k); }
  }
  
  //sum of [1,k]
  Type query(int k){
    k += 1;
    
    Type rec=0;
    while(k>0){
      rec+=data[k];
      k-= k&(-k);
    }
    
    return rec;
  }
};

int dp[SIZE][SIZE];

int main(){
  int n;
  int p[2][SIZE];

  scanf("%d", &n);

  for(int i=0;i<n*2;i++){
    char c; int a;
    scanf(" %c %d", &c, &a);
    a--;
    if(c == 'B') p[0][a] = i;
    else p[1][a] = i;
  }


  for(int i=0;i<=n;i++){
    for(int j=0;j<=n;j++){
      dp[i][j] = INF;
    }
  }

  dp[0][0] = 0;
  
  for(int i=0;i<=n;i++){
    BIT bit((n+1) * 2);
    
    for(int j=i;j<n;j++) bit.add(p[0][j], 1);
    for(int j=0;j<n;j++) bit.add(p[1][j], 1);
    
    for(int j=0;j<=n;j++){
      if(i < n) dp[i+1][j] = min(dp[i+1][j], dp[i][j] + bit.query(p[0][i]-1));
      if(j < n) dp[i][j+1] = min(dp[i][j+1], dp[i][j] + bit.query(p[1][j]-1));
      if(j < n) bit.add(p[1][j], -1);
    }
  }

  printf("%d\n", dp[n][n]);
  
  return 0;
}



Measured memory_bytes: 16000
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
vector<int> G[100000];
ll dp[100000][2];
ll solve(int v, int color, int p) { //color=1:黒
	if (dp[v][color] != -1) return dp[v][color];
	ll t = 1;
	for (int c : G[v]) {
		if (c == p) continue;
		if (color == 1) {
			(t *= solve(c, 0, v)) %= MOD;
		}
		else {
			ll x = solve(c, 0, v);
			(x += solve(c, 1, v)) %= MOD;
			(t *= x) %= MOD;
		}
	}
	return dp[v][color] = t;
}
int main() {
	int N;
	cin >> N;
	for (int i = 0; i + 1 < N; i++) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	memset(dp, -1, sizeof(dp));
	ll ans = solve(0, 0, -1);
	(ans += solve(0, 1, -1)) %= MOD;
	cout << ans << endl;
}

Measured memory_bytes: 15616
N, A, B = map(int, input().split())
S = input()

cnt_a = 0
cnt_b = 0
for s in S:
    if s == 'c':
        print('No')
    elif s == 'b':
        if (cnt_b < B) and ((cnt_a + cnt_b) < (A + B)):
            print('Yes')
            cnt_b += 1
        else:
            print('No')
    elif s == 'a':
        if (cnt_a + cnt_b) < (A + B):
            cnt_a += 1
            print('Yes')
        else:
            print('No')


Measured memory_bytes: 9304
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <math.h>
#include <vector>

using namespace std;

int main() {

	string S, T;

	cin >> S >> T;

	if (equal(S.begin(), S.end(), T.begin()) == true)
	{
		cout << "Yes";
	}
	else
	{
		cout << "No";
	}

	return 0;

}

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

int main (){
  string S,T;
  cin>>S>>T;
  int a=1;
  for(int i=0;i<S.size();i++){
  	if(S.at(i)!=T.at(i)) a=0;
  }
  
  if(a)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
  return 0;
}

Measured memory_bytes: 3580
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))


def retminvalue(syou):
    mini = 0
    mini += syou // (K-1)
    if(syou % (K-1) != 0):
        mini += 1
    return mini

for i in range(N):
    if A[i] == 1:
        p = i+1

if p == 0 or p==(N):
    print(retminvalue(N))
else:
    minlist = [99999 for i in range(K+3)]
    for i in range(K-1):
        minlist[i] =  retminvalue(N-p+i) + retminvalue(p-1-i)
    print(min(minlist))

Measured memory_bytes: 13812
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		
		if (a > b)
			System.out.println("a > b");
		else if (a < b)
			System.out.println("a < b");
		else
			System.out.println("a == b");
		scanner.close();
	}
}

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

int main(){
  int64_t N, M, K;
  cin>>N>>M>>K;
  vector<int64_t> A(N+1);
  vector<int64_t> B(M+1);
  
  A[0]=0, B[0]=0;
  for(int i=1;i<N+1;i++){
    int64_t a;
    cin>>a;
    A[i] = A[i-1]+a;
  }
  for(int i=1;i<M+1;i++){
    int64_t b;
    cin>>b;
    B[i] = B[i-1]+b;
  }
  
  int j=M;
  int read_max=0;
  for(int i=0;i<N+1;i++){
    if(A[i]>K) break;
    while(B[j]>K-A[i]){
      j--;
    }
    //cout<<i<<' '<<j<<endl;
    if(read_max<(i+j)){
      read_max=i+j;
    }
  }
  cout<<read_max<<endl;
}

Measured memory_bytes: 6404
/*

結果:
*/
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>  
#include <stdbool.h>   
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define PI 3.14159265358979323846;
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
/*
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r)
*/
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r)
#define TYPE long long
#define ll long long
#define MEMSET(a) memset(a,0,sizeof(a))
#define MEMSET_U(a) memset(a,-1,sizeof(a))
const int mod = (int)1e09 + 7;

//#define DEBUG1
//#define DEBUG2
//#define DEBUGF
#define DUMMY

int in(void) { int i; scanf("%d", &i); return i; }
long long llin(void) { long long i; scanf("%lld", &i); return i; }
double din(void) { double i; scanf("%lf", &i); return i; }
void chin(char s[]) { scanf("%s", s); }

void print(int a) { printf("%d\n", a); }
void llprint(long long a) { printf("%lld\n", a); }
void dprint(double a) { printf("%.10f\n", a); }
void print2(int a, int b) { printf("%d %d\n", a, b); }
int Max(int a, int b) { if (a > b) { return a; }return b; }
int Min(int a, int b) { if (a < b) { return a; }return b; }
long long llmax(long long a, long long b) { return a > b ? a : b; }
long long llmin(long long a, long long b) { return a < b ? a : b; }
double dmax(double a, double b) { return a > b ? a : b; }
double dmin(double a, double b) { return a < b ? a : b; }
//long long llmax(long long a, long long b) { return a > b ? a : b; }
//long long llmin(long long a, long long b) { return a < b ? a : b; }
//double dmax(double a, double b) { return a > b ? a : b; }
int cmp(const void *a, const void *b) { return *(TYPE *)a - *(TYPE *)b; }
int cmp_r(const void *a, const void *b) { return *(TYPE *)b - *(TYPE *)a; }
int char_cmp(const void *a, const void *b) { return strcmp((char *)a, (char *)b); }
int char_cmp_r(const void *a, const void *b) { return strcmp((char *)b, (char *)a); }
void swap(int *a, int *b) { int t = *a; *a = *b; *b = t; }

//A
//int main() {
//	char N[4];
//	char ans[4];
//	scanf("%s", &N);
//	for (int i = 0; i < 4; i++) {
//		if (N[i] == '1') {
//			printf("%c",'9');
//		}
//		else if(N[i] == '9'){
//			printf("%c", '1');
//		}
//	}
//	printf("\n");
//
//#ifdef DEBUGF
//	getch();
//#endif
//return 0;
//}

//B
int main() {
	int N;
	scanf("%d", &N);
	for (int i = 1; i <= 9; i++) {
		if (111*i >= N) {
			printf("%d",111*i);
			break;
		}
	}
	printf("\n");

#ifdef DEBUGF
	getch();
#endif
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>


using namespace std;


constexpr auto BASE = 1000000007;

int N,K;

vector<long long> A;


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

	A = vector<long long>(N);

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

	sort(A.begin(), A.end(), [](auto const& lhs, auto const& rhs) {
		return abs(lhs) > abs(rhs);
	});

	{
		int mc = 0;
		for (int i = 0; i < K; i++) {
			if (A[i] < 0)mc++;
		}

		if (mc % 2 == 0) {
			long long ans = 1;
			for (int i = 0; i < K; i++) {
				ans = (ans * A[i]) % BASE;
			}

			cout << ans << endl;

			return 0;
		}
	}

	int ml=-1;
	int pl = -1;
	int mr = N;
	int pr = N;
	for (int i = K - 1; i > 0; i--) {
		if (A[i]<0) {
			ml = i;
			break;
		}
	}
	for (int i = K - 1; i > 0; i--) {
		if (A[i]>=0) {
			pl = i;
			break;
		}
	}
	for (int i = K; i < N; i++) {
		if (A[i]<0) {
			mr = i;
			break;
		}
	}
	for (int i = K; i < N; i++) {
		if (A[i]>=0) {
			pr = i;
			break;
		}
	}


	long long  pc = -1;
	long long mc = -1;


	if (pr < N && ml >= 0) {
		if (pl < 0) {
			pc = 1;
		}
		else {
			pc = A[pr] * A[pl];
		}
	}
	if (mr < N && pl >= 0) {
		if (ml < 0) {
			mc = 1;
		}
		else {

			mc = A[mr] * A[ml];
		}
	}

	if (pc < 0 && mc < 0) {
		long long ans = 1;
		for (int i = 0; i < K; i++) {
			ans = (ans * A[N-1-i]) % BASE;
		}

		while (ans < 0) {
			ans += BASE;
		}

		cout << ans << endl;

		return 0;
	}


	if (pc > mc) {
		long long ans = 1;
		for (int i = 0; i < K; i++) {
			if (i == ml) { continue; }

			ans = (ans * A[i]) % BASE;
		}

		ans = (ans * A[pr]) % BASE;

		cout << ans << endl;

		return 0;
	}
	else {
		long long ans = 1;
		for (int i = 0; i < K; i++) {
			if (i == pl) { continue; }

			ans = (ans * A[i]) % BASE;
		}

		ans = (ans * A[mr]) % BASE;

		cout << ans << endl;

		return 0;
	}



	

	return 0;
}



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

int main(){
    int n,m; cin >> n >> m;
    ll a;
    priority_queue<ll> q;
    rep(i,n){
        cin >> a;
        q.push(a);
    }
    ll tmp;
    for(int i = 0; i < m; i++){
        tmp = q.top();
        q.pop();
        tmp /= 2;
        q.push(tmp);
    }
    ll ans = 0;
    for(int i = 0; i < n; i++){
        if(!q.empty()){
            ans += q.top();
            q.pop();
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1400
lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

D = lines[0][0]
Inf = 10 ** 10

last_date = []
for i in 1..26 do
  last_date.push(0)
end

def try(lines,last_date,bias,final)
  satis = 0
  for i in 1..D do
    max_satis = - Inf
    best_contest = 0
    for k in 1..26 do
      now_satis = 0
      now_satis += lines[i+1][k-1]
      now_satis += lines[1][k-1] * (i - last_date[k-1]) * bias
      if now_satis > max_satis then
        max_satis = now_satis
        best_contest = k
      end
    end
    satis += max_satis
    last_date[best_contest-1] = i
    if final then
      if i < D then
        puts best_contest
      else
        print best_contest
      end
    end
  end
  return satis
end

# Normal Case: bias = 1
bias = 0.0
best_bias = 0.0
best_satis = - Inf
200.times do |num|
  current_satis = try(lines,last_date,bias,false)
  if current_satis < best_satis then
    best_satis = current_satis
    best_bias = bias
  end
  bias += 0.01
end
try(lines,last_date,best_bias,true)

Measured memory_bytes: 14312
def mul(x, y)
  if x == '2' && y == '2' then '2'
  elsif x == '0' || y == '0' then '0'
  else '1'
  end
end

def plus(x, y)
  if x == '0' && y == '0' then '0'
  elsif x == '2' || y == '2' then '2'
  else '1'
  end
end

def to_num(s)
  ['0', '1', '2'].repeated_permutation(3).map { |p, q, r|
    s.gsub(/P|Q|R/, 'P' => p, 'Q' => q, 'R' => r)
  }
end

def calc(expr)
  while expr.size > 1
    expr.gsub!(/-(\d)/) {
      (2 - $1.to_i).to_s
    }
    expr.gsub!(/\((\d)\+(\d)\)/) {
      plus($1, $2)
    }
    expr.gsub!(/\((\d)\*(\d)\)/) {
      mul($1, $2)
    }
  end
  if expr == '2' then return true
  else return false
  end
end

while s = gets.chomp
  break if s == "."
  puts to_num(s).count{ |expr| calc(expr) }
end

Measured memory_bytes: 9764
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define INF 1e9
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

ll N, sum[2] = {};
string S, odd = "" ,even = "";

void solve(){
    N = S.size();

    if(N==1) cout << 0 << endl;
    else{
        rep(i,N){
            if(i%2==0)
                even.push_back(S[i]-'0');
            else
                odd.push_back(S[i]-'0');
        }

        rep(i, even.size()) sum[0] += even[i];
        rep(i, odd.size()) sum[1] += odd[i];

        // printf("sum[0]: %lld, sum[1]: %lld\n",sum[0],sum[1]);

        cout << min(sum[0]+odd.size()-sum[1], sum[1]+even.size()-sum[0]) << endl;
    }
}

int main(){
    cin >> S;

    solve();
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int w,h;
  int vx[8]={1,0,-1,0,1,1,-1,-1};
  int vy[8]={0,1,0,-1,1,-1,1,-1};
  while(cin>>w>>h,w+h){
    ll ans=0;
    int Map[h][w]={};
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)
	cin>>Map[i][j];
    bool Map2[h][w]={};
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(Map2[i][j])continue;
	if(Map[i][j]==0)Map2[i][j]=true;
	else{
	  Map2[i][j]=true;
	  queue<pair<int,int> >que;
	  que.push(mp(i,j));
	  while(!que.empty()){
	    pair<int,int>now=que.front();
	    que.pop();
	    for(int i=0;i<8;i++){
	      int a=now.F+vx[i],b=now.S+vy[i];
	      if(!(a>=0&&a<h&&b>=0&&b<w))continue;
	      if((Map[a][b]==1)&&(!Map2[a][b])){
		Map2[a][b]=true;
		que.push(mp(a,b));
	      }else{
		Map2[a][b]=true;
	      }
	    }
	  }
	  ans++;
	}
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

using namespace std;

#define INF 2000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;


int main()
{
	int n;
	cin >> n;
	if (n %10 ==0) {
		cout << 10 << "\n";
		return 0;
	}
	string s = to_string(n);
	int ans = 0;
	for (int i = 0; i < s.size(); ++i) {
		int tmp = s[i]-'0';
		ans += tmp;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<stack>
using namespace std;






int main() {
	int n; cin >> n;
	int m; cin >> m;
	queue<string>a,a1;
	queue<int>b,b1;
	int i = 0;
	while (i<n) {
		string s;
		cin >> s;
		int t;
		cin>> t;
		a.push(s);
		b.push(t);
		i++;
	}
	int time = 0;
	while (!a.empty()) {
		//cout << a.front() << " "<<b.front() << endl;
		if (b.front() > m) {
			a.push(a.front());
			b.push(b.front() - m);
			b.pop(); a.pop();
			time += m;

		}
		else {
			time += b.front();
			a1.push(a.front());
			b1.push(time);
			//cout <<a1.back()<<" "<< b1.back();
			b.pop(); a.pop();
		}
		//cout <<" "<< time << endl;
	}
	while (!a1.empty()) {
		cout << a1.front() << " " << b1.front() << endl;
		a1.pop(); b1.pop();
	}
}







Measured memory_bytes: 5616
N = int(input().strip())
A = list(map(int, input().strip().split()))

neg = 0
for i in range(N):
    if A[i] < 0:
        neg += 1
        A[i] *= -1
A.sort()
ans = 0
if neg % 2 == 1:
    A[0] *= -1
for i in A:
    ans += i
print(ans)

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

typedef long long ll;
typedef double db;

#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const ll LINF = LLONG_MAX, MOD = 1e9 + 7, N = 1e5 + 5, LG = 20;
const int INF = INT_MAX;
const db PI = acos(-1), EPS = 1 / db(1e6);

void test() {
    int n, k; cin >> n >> k;
    int a[n];
    for (auto &x : a) cin >> x;
    sort(a, a + n);
    int sum = 0;
    for (int i = 0; i < k; ++i) sum += a[i];
    cout << sum;
}

int main() {
      fast_io();
      #ifdef HOME
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
      #endif
      cout << fixed << setprecision(15);
      int t = 1;
      // cin >> t;
      for (int i = 1; i <= t; ++i) {
          test();
      }
      #ifdef HOME
          cout << "Time: " << (int)(clock() * 1000. / CLOCKS_PER_SEC) << "ms";
      #endif
      return 0;
}


Measured memory_bytes: 3660