akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int n;
	cin>>n;
	int ans = 0;
	rep(i,n){
		int a;
		cin>>a;
		while(a%2 == 0){
			ans++;
			a /= 2;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

typedef pair<int, int> P;
typedef pair<P, int> PP;

int main() {
    int N, M;
    cin >> N >> M;
    vector<PP> C(M);
    for (int i = 0; i < M; i++) {
        int p, y;
        cin >> p >> y;
        C[i] = PP(P(p, y), i);
    }
    sort(C.begin(), C.end());

    vector<P> res(M);
    int pre = 0, cnt = 0;
    for (int i = 0; i < M; i++) {
        int p = C[i].first.first;
        if (p == pre) {
            cnt++;
        } else {
            cnt = 1;
        }
        pre = p;
        res[C[i].second] = P(p, cnt);
    }

    for (int i = 0; i < M; i++) {
        printf("%.6d%.6d\n", res[i].first, res[i].second);
    }
    return 0;
}

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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;
const ll INF = 1e9+5;

int n;
double memo[305][305][305];

double dp(int a, int b, int c) {
	if (a == 0 and b == 0 and c == 0) return 0;
	if (memo[a][b][c] != -1) return memo[a][b][c];
	double pa = double(a)/n;
	double pb = double(b)/n;
	double pc = double(c)/n;
	double x = 1;
	if (a) x+=pa*dp(a-1, b, c);
	if (b) x+=pb*dp(a+1, b-1, c);
	if (c) x+=pc*dp(a, b+1, c-1);
	double f = 1.0 - pa - pb - pc;
//	cout <<a<<", "<<b<<", "<<c<<"   x = "<<x<<"    f = "<<f<<endl;
	return memo[a][b][c] = x/(1.0-f);
}

int main() {
	for (int i=0 ; i<=300 ; i++) {
		for (int j=0 ; j<=300 ; j++) {
			for (int k=0 ; k<=300 ; k++) {
				memo[i][j][k] = -1;
			}
		}
	}
	scanf("%d", &n);
	int a = 0;
	int b = 0;
	int c = 0;
	for (int i=0 ; i<n ; i++) {
		int x;
		scanf("%d", &x);
		if (x == 1) a++;
		if (x == 2) b++;
		if (x == 3) c++;
	}
	printf("%.10lf\n", dp(a, b, c));
	return 0;
}

Measured memory_bytes: 220948
#include<iostream>
#include<string>
using namespace std;
int n;
int main(){
  cin >> n;
  double ret = 0;
  for(int i=0; i<n; i++){
    double d; cin >> d;
    string s; cin >> s;
    if(s[0] == 'J') ret += d;
    else ret += d * 380000;
    }
  cout << ret << endl;
  return 0;
  }


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

int main(){
    int N,K;
    cin >> N >> K;
    vector<int> vec(N);
    rep(i,N){
        cin >> vec[i];
    }
    sort(all(vec));
    vec.push_back(0);
    vector<pair<int,int> > sequence(0);
    int count = 1;
    rep(i,N){
        if (vec[i] == vec[i + 1]){
            count++;
        }
        else{
            sequence.push_back(pair<int,int>(count,vec[i]));
            count = 1;
        }
    }
    sort(all(sequence));
    int len_seq = sequence.size();
    int answer = 0;
    if (len_seq <= K ){
        answer = N;
    }
    else{
        rep(i,K){
            answer += sequence[len_seq - i - 1].first;
        }
    }
    cout << N - answer << endl;
}


Measured memory_bytes: 4080
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int N,M;
    cin>>N>>M;
    int a[M],b[M];
    Graph G(N);
    rep(i,M){
        cin>>a[i]>>b[i];
        a[i]--;
        b[i]--;
        G[a[i]].push_back(b[i]);
        G[b[i]].push_back(a[i]);
    }

    int ans=0;
    rep(i,M){
        vector<int> dist(N,-1);
        queue<int> q;
        q.push(0);
        dist[0]=0;
        while(!q.empty()){
            int v=q.front();
            q.pop();
            for(auto nv:G[v]){
                if(a[i]==v&&b[i]==nv)continue;
                if(a[i]==nv&&b[i]==v)continue;
                if(dist[nv]!=-1)continue;
                dist[nv]=0;
                q.push(nv);
                

            }
        }
        rep(j,N){
            if(dist[j]==-1){
                ans++;
                break;
            }
        }
    }
    cout << ans << endl;


    



}


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

int main()
{
    int n,i;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    for(i = 0;i < n;++i){
        cin >> a.at(i);
    }
     for(i = 0;i < n;++i){
        cin >> b.at(i);
    }
    long long need = 0;
    int neednum = 0,ans = 0;
    vector<long long> koe;
    for(i = 0;i < n;++i){
        if(a.at(i) > b.at(i)){
            koe.push_back(a.at(i)-b.at(i));
        }else if(a.at(i) < b.at(i)){
            need += b.at(i)-a.at(i);
            ++neednum;
        }
    }
    if(need == 0){
        cout << 0 << endl;
        return 0;
    }
    sort(koe.begin(),koe.end());
    for(i = koe.size()-1;i >= 0;--i){
        need -= koe.at(i);
        ++ans;
        if(need <= 0){
            break;
        }
    }
    if(i == -1){
        cout << -1 << endl;
    }else{
        cout << ans+neednum << endl;
    }
    return 0;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using namespace std;
using namespace boost::multiprecision; // for use cpp_int
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    cpp_dec_float_100 a;
    cpp_dec_float_100 b;
    cin >> a >> b;
    a *= b;
    string s = a.str();
    string ans = "";
    rep(i, len(s)) {
        if (s[i] == '.') {
            break;
        }
        ans += s[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3760
import sys

while True:
    try:
        a = map(int, raw_input().strip().split())
        b = map(int, raw_input().strip().split())

        hit = 0
        blow = 0

        for i in xrange(len(b)):
            if b[i] in a:
                blow += 1
            if b[i] == a[i]:
                hit += 1

        blow -= hit

        print "%d %d" % (hit, blow)

    except EOFError:
        break

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

void counting_sort(vector<int> &a, int k) {
    vector<int> c(k+1);
    rep(i, a.size()) {
        c[a[i]]++;
    }
    rep(i, k) {
        c[i+1] += c[i];
    }
    vector<int> b(a.size());
    for (int i = a.size()-1; i >= 0; i--) {
        c[a[i]]--;
        b[c[a[i]]] = a[i];
    }
    rep(i, a.size()) {
        a[i] = b[i];
    }
}

int main() {
    int n;
    scanf("%d", &n);
    vector<int> a(n);
    // vector<int> c(10001);
    rep(i, n) {
        scanf("%d", &a[i]);
        // c[a[i]]++;
    }
    // rep(i, 10000) {
    //     c[i+1] += c[i];
    // }
    // vector<int> b(n);
    // for (int i = n-1; i >= 0; i--) {
    //     c[a[i]]--;
    //     b[c[a[i]]] = a[i];
    // }
    // rep(i, n) {
    //     printf("%d", b[i]);
    //     if (i != n-1) printf(" ");
    //     else printf("\n");
    // }
    counting_sort(a, 10000);
    rep(i, n) {
        printf("%d", a[i]);
        if (i != n-1) printf(" ");
        else printf("\n");
    }
}


Measured memory_bytes: 18352
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)

const lint MOD = pow(10, 9) + 7;

lint gcd(lint a, lint b) {
	//aとbの最大公約数を返す
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(a % b, b);
}

lint lcm(lint a, lint b) {
	//aとbの最小公倍数を返す
	return a / gcd(a, b) * b;
}

lint sgm(lint n) {
	//0からの総和を返す
	return n * (n + 1) / 2;
}

lint fact(lint n) {
	//n!を返す
	if (n == 0) return 1;
	else return n * fact(n - 1);
}

lint power(lint x, lint n, lint m) {
	//(x^n)%mを返す
	lint res = 1;
	x %= m;
	while (n > 0) {
		if (n % 2 == 1) {
			res = res * x % m;
		}
		x = x * x % m;
		n /= 2;
	}
	return res;
}

/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/


int main() {
	string S;
	cin >> S;
	int Z = S.size();
	int n = 0, w = 0, s = 0, e = 0;
	rep(i, Z) {
		if (S[i] == 'N')n++;
		if (S[i] == 'W')w++;
		if (S[i] == 'S')s++;
		if (S[i] == 'E')e++;
	}
	if ((n == 0 && s == 0) || (n != 0 && s != 0)) {
		if ((w == 0 && e == 0) || (w != 0 && e != 0)) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n), dp(n, INT_MAX);
  rep(i, n) cin >> h[i];
  dp[0] = 0;
  for (int i = 1; i < n; i++) {
    for (int j = 1; j <= k; j++) {
      if (i >= j) dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
    }
  }
  cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main() {
    int n; cin >> n;
    int a[n];
    cin >> a[0];
    int min, max;
    min = max = a[0];
    for (int i = 1; i < n; ++i) {
        cin >> a[i];
        min = min < a[i] ? min : a[i];
        max = max < a[i] ? a[i] : max;
    }
    int mmin = (100 - (-100)) * (100 - (-100)) * 100;
    for (int i = min; i <= max; ++i) {
        int sum = 0;
        for (int j = 0; j < n; ++j) {
            sum += (a[j] - i) * (a[j] - i);
        }
        mmin = mmin < sum ? mmin : sum;
    }
    cout << mmin << endl;
    return 0;
}


Measured memory_bytes: 256
import math
n,d = map(int,input().split())
counter = 0
x = []
tmp = 0
for i in range(n):
    tmp = list(map(int,input().split()))
    x.append(tmp)
for i in range(n-1):
    for j in range(i+1,n):
        if tmp != 0:
            tmp = 0
        for k in range(d):
            tmp +=(abs(x[i][k] - x[j][k]))**2
        if float.is_integer(math.sqrt(tmp)):
            counter +=1
print(counter)

Measured memory_bytes: 3064
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
        
n, m = map(int, input().split())
UF = UnionFind(n)
for _ in range(m):
    a, b = map(int, input().split())
    UF.union(a - 1, b - 1)
ans = 0
for i in range(n):
    ans = max(ans, UF.size(i))
print(ans)

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

int main() {
  int n = 0;
  string a = "Yes";
  string s;
  cin >> s;
  n = s.size();
  for(int i = 0; i < n/2; i++){
  	if(s.at(i) != s.at(n-1-i)){
    	a = "No";
      break;
    }
  //  cout << a << endl;
  }
  for(int i =0; i < (n-1)/2/2; i++){
    if(s.at(i) != s.at((n-1)/2-i-1)){
    	a = "No";
      break;
    }
 // cout << a << endl;
  }
  for(int i =0; i < (n-(n+3)/2+1)/2; i++){
    if(s.at((n+3)/2+i-1) != s.at(n-1-i)){
    	a = "No";
      break;
    }
   // cout << a << endl;
  }
       cout << a << endl;
}

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

int main (){

  int a,b,c;

  cin >>  a >> b >> c;
  
  if (a<b && b<c)  cout << "Yes" <<'\n';
  else if (!(a<b && b<c))  cout << "No"   <<'\n';
 
  return 0;

}

Measured memory_bytes: 1124
t = input()
p = input()
 
anslist = []
for i in range(len(t) - len(p) + 1):
    if t[i] == p[0]:
        k = 0
        for j in range(i, i + len(p)):
            if t[j] != p[k]:
                break
            k += 1
        else:
            anslist.append(i)
 
for ans in anslist:
    print(ans)


Measured memory_bytes: 5572
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}

func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	k := iScan()
	x := iScan()
	ans := make([]int, 0)
	for i := x - k + 1; i < k+x; i++ {
		ans = append(ans, i)
	}
	fmt.Println(strings.Trim(fmt.Sprint(ans), "[]"))
}


Measured memory_bytes: 1800
n = gets.to_i
f11 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
f12 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
f13 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
f21 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
f22 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
f23 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
f31 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
f32 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
f33 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
f41 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
f42 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
f43 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
b1 = [f11,f12,f13]
b2 = [f21,f22,f23]
b3 = [f31,f32,f33]
b4 = [f41,f42,f43]
bf = [b1,b2,b3,b4]

n.times do
    x = gets()
    x = x.split

    b = x[0].to_i - 1
    f = x[1].to_i - 1
    r = x[2].to_i - 1
    v = x[3].to_i 
    if 0 <= b && b <= 4 && 0 <= f && f <= 3 && 0 <= r && r <=10 && 0 <= bf[b][f][r] + v && bf[b][f][r] <= 9
    bf[b][f][r] = bf[b][f][r] + v
    end
end

puts " " + f11.join(" ")
puts " " + f12.join(" ")
puts " " + f13.join(" ")
puts "#" * 20
puts " " + f21.join(" ")
puts " " + f22.join(" ")
puts " " + f23.join(" ")
puts "#" * 20
puts " " + f31.join(" ")
puts " " + f32.join(" ")
puts " " + f33.join(" ")
puts "#" * 20
puts " " + f41.join(" ")
puts " " + f42.join(" ")
puts " " + f43.join(" ")



Measured memory_bytes: 6892
package main

import "fmt"

var k, s int

func main() {
	fmt.Scan(&k, &s)
	cnt := 0
	for x := 0; x <= k; x++ {
		for y := 0; y <= k; y++ {
			z := s - x - y
			if 0 <= z && z <= k {
				cnt++
			}
		}
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <algorithm>

int n;
int a[100000];
int b[100000];
int c[100000];
int dp[100000][3];

int main(){
  scanf("%d", &n);
  for(int i = 0; i < n; i++)
    scanf("%d%d%d", a+i, b+i, c+i);

  dp[0][0] = a[0];
  dp[0][1] = b[0];
  dp[0][2] = c[0];
  for(int i = 1; i < n; i++){
    dp[i][0] = std::max(dp[i-1][1], dp[i-1][2]) + a[i];
    dp[i][1] = std::max(dp[i-1][2], dp[i-1][0]) + b[i];
    dp[i][2] = std::max(dp[i-1][0], dp[i-1][1]) + c[i];
  }

  printf("%d\n", std::max({dp[n-1][0], dp[n-1][1], dp[n-1][2]}));

  return 0;
}


Measured memory_bytes: 2560
#	!/usr/bin/env python3
#	encoding: UTF-8
#	Modified: <19/May/2019 05:33:27 PM>


#	✪ H4WK3yE乡
#	Mohd. Farhan Tahir
#	Indian Institute Of Information Technology (IIIT), Gwalior


import sys


def get_array(): return list(map(int, sys.stdin.readline().split()))


def get_ints(): return map(int, sys.stdin.readline().split())


def input(): return sys.stdin.readline().strip()


def main():
    n, k = get_ints()
    s = list(input())
    s[k - 1] = s[k - 1].lower()
    print(*s, sep='')


if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC085B
{
    class Program
    {
        static void Main(string[] args)
        {
            var count = int.Parse(Console.ReadLine());
            var d = new List<int>();
            for(int i = 0; i < count; i++)
            {
                d.Add(int.Parse(Console.ReadLine()));
            }
            var sorted = d.OrderBy(v => v).ToArray();

            var result = new List<int>();
            for(int i = 1; i < sorted.Count(); i++)
            {
                if(sorted[i] == sorted[i - 1])
                {
                    continue;
                }

                result.Add(sorted[i]);
            }

            if (!result.Contains(sorted[0]))
            {
                result.Add(sorted[0]);
            }

            Console.WriteLine($"{result.Count()}");
        }
    }
}


Measured memory_bytes: 13396
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int m, n;
	int[] a;

	void run(){
		for(;;){
			m=sc.nextInt();
			n=sc.nextInt();
			if((m|n)==0){
				break;
			}
			a=new int[n];
			for(int i=0; i<n; i++){
				a[i]=sc.nextInt();
			}
			solve();
		}
	}

	void solve(){
		int left=0, right=1500000;
		for(int i=0; i<100; i++){
			int mid=(left+right)/2;
			if(check(mid)){
				right=mid;
			}else{
				left=mid;
			}
		}
		println(""+right);
	}

	boolean check(int b){
		int d=1;
		int sum=0;
		for(int i=0; i<n; i++){
			if(a[i]>b){
				return false;
			}
			sum+=a[i];
			if(sum>b){
				sum=a[i];
				d++;
			}
		}
		return d<=m;
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

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

using namespace std;

#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template<class T>
void print(vector<T>& V, bool spaced = true) {
    string space;
    spaced ? space = " " : space = "";
    for(int i = 0; i < V.size(); i++) {
        cout<< V[i] << space;
    }cout<< '\n';
}

template<class T>
void printendl(vector<T>& V) {
    for(int i = 0; i < V.size(); i++) {
        cout<< V[i] << '\n';
    }
}

template<class T>
T gcd(T a, T b) {
    T r;
    while (b != 0) {
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}

template <class T>
T lcm (T a, T b) {
    return a / gcd(a, b) * b;
}

template<class T>
T Max(T a, T b) {
    return (a < b) ? b : a;
}

template<class T>
T Min(T a, T b) {
    return (a < b) ? a : b;
}

//str

bool isPalindrome(string str){
    
    int length = str.length();
 
    for (int i = 0; i < (length / 2); i++)
        if (str[i] != str[length - 1 - i])
            return false;
 
    return true;    
}

void reverseStr(string& str) 
{ 
    int n = str.length(); 
    for (int i = 0; i < n / 2; i++) 
        swap(str[i], str[n - i - 1]); 
}
 

//Read through the messages at the end when you're done

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);


    string s; cin>> s;
    if(s[2] == s[3] && s[4] == s[5]) {cout << "Yes" << '\n';}
    else { cout << "No"<< '\n';}

    
    

    return 0;
}

    //Use long long da5eel rabbak!
    //Dont use endl;
    //DONT SUBMIT IZA UR NOT SURE WALLAHI BTENDAM
    //Dear Amine, just because it worked for the test cases doesnt necessarily mean it is correct.
    //Dear Amine, try it on ur own test cases iza ur not SURE
    //In case u didnt use long long, CHECK FOR POTENTIAL OVERFLOWS
    //DONT FORGET TO MOD EVERYTHING IZA U NEED TO MOD



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int    
#define mod 1000000007
void solve()
{
    ll n;
    cin>>n;
    string s;
    while(n>0)
    {
        int rem=n%26;
        if(rem==0)
        {
            s+='z';
            n=n/26 - 1;
        }
        else
        {
            s+='a'+(rem-1);
            n=n/26;
        }
    }
    reverse(s.begin(),s.end());
    cout<<s<<endl;

}
int main()
{
    solve();
}

Measured memory_bytes: 3600
#include <iostream>
#include <fstream>
#include <cstdio>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <cassert>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <list>
#include <forward_list>
#include <array>
#include <cstring>
#include <cmath>
#include <tuple>
#include <complex>
#include <bitset>
#include <climits>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using LD = long double;
using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pld = pair<LD, LD>;
const int MAX_N = 1e2;


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

    int N, K;
    cin >> N >> K;

    bitset<MAX_N + 1> has_snacc;
    while (K--)
    {
        int d;
        cin >> d;

        int snecc;
        while (d--)
        {
            cin >> snecc;
            has_snacc[snecc] = true;
        }
    }

    cout << N - has_snacc.count();
}


Measured memory_bytes: 3604
from collections import deque
h,w=map(int,input().split())
num=[list(input()) for _ in range(h)]
seen=[[False]*w for _ in range(h)]
queue=deque()
queue.append([0,0])
ans=[[0]*w for _ in range(h)]
seen[0][0]=True
for i in range(h*w*100):
    if len(queue)==0:
        break
    cnt=queue.popleft()
    if num[max(0,cnt[0]-1)][cnt[1]]=="." and seen[max(0,cnt[0]-1)][cnt[1]]==False:
        queue.append([cnt[0]-1,cnt[1]])
        seen[max(0,cnt[0]-1)][cnt[1]]=True
        ans[max(0,cnt[0]-1)][cnt[1]]=ans[cnt[0]][cnt[1]]+1
    if num[min(h-1,cnt[0]+1)][cnt[1]]=="." and seen[min(h-1,cnt[0]+1)][cnt[1]]==False:
        queue.append([cnt[0]+1,cnt[1]])
        seen[min(h-1,cnt[0]+1)][cnt[1]]=True
        ans[min(h-1,cnt[0]+1)][cnt[1]]=ans[cnt[0]][cnt[1]]+1
    if num[cnt[0]][max(cnt[1]-1,0)]=="." and seen[cnt[0]][max(cnt[1]-1,0)]==False:
        queue.append([cnt[0],cnt[1]-1])
        seen[cnt[0]][max(cnt[1]-1,0)]=True
        ans[cnt[0]][max(cnt[1]-1,0)]=ans[cnt[0]][cnt[1]]+1
    if num[cnt[0]][min(w-1,cnt[1]+1)]=="." and seen[cnt[0]][min(w-1,cnt[1]+1)]==False:
        queue.append([cnt[0],cnt[1]+1])
        seen[cnt[0]][min(w-1,cnt[1]+1)]=True
        ans[cnt[0]][min(w-1,cnt[1]+1)]=ans[cnt[0]][cnt[1]]+1
if seen[-1][-1]==False:
    print(-1)
else:
    cnt3=0
    for i in range(h):
        cnt3+=num[i].count(".")
    print(cnt3-ans[-1][-1]-1)


Measured memory_bytes: 9404
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include <iomanip>
#include <math.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60
const double PI = 3.14159265358979323846;

bool pro[100009];
int wanum[100009];

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

	int N, M; cin >> N >> M;
	int ans = 0;
	int wa = 0;
	for (int i = 0; i < M; i++) {
		int p; string S; cin >> p >> S;
		if (!pro[p]) {
			if (S == "AC") {
				ans++;
				pro[p] = true;
			}
			else {
				wanum[p]++;
			}
		}
	}

	for (int i = 1; i <= N; i++) if (pro[i]) wa += wanum[i];

	cout << ans << " " << wa << endl;

	return 0;
}

Measured memory_bytes: 768
//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu) FUNC(printe) FUNC(printe0);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

// #define NDEBUG
#include "atcoder/all"
using namespace atcoder;

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    dsu uf(n);
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        uf.merge(a, b);
    }
    cout << uf.groups().size() - 1 << '\n';
}


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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
    int goukei;
   for (int i = 0; i < N; i++) {
    goukei += vec.at(i);}
  
  int SA, SB, s;
   for (int i = 0; i < N; i++) {
     SA += vec.at(i);
     SB = goukei - SA;
     if(SA > SB){
       int p = SA - SB;
        if(p < s)
          s = p;
       else
         break;
     }
     else
       s = SB - SA;
   }
  cout << s << endl;
}


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

int n;
long long sol = 0, x, maxim;

int main() {
    cin >> n;
    cin >> maxim;
    for(int i = 2; i <= n; i++) {
        cin >> x;
        if(x < maxim) {
            sol += maxim - x;
        }
        maxim = max(maxim, x);
    }
    cout << sol;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod_) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod_;
		}
		x = x * x % mod_;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}
/*--------Library Zone!--------*/

int n, m, a[114514];
P p[114514];
signed main() {
	cin >> n >> m;
	rep(i, n)cin >> a[i];
	sort(a, a + n);
	rep(i, m)cin >> p[i].second >> p[i].first;
	sort(p, p + m, greater<>());
	int now = 0;
	rep(i, m) {
		rep(j, p[i].second) {
			if (now >= n)break;
			if (a[now] <= p[i].first) {
				a[now] = p[i].first;
				now++;
			}
			else {
				break;
			}
		}
	}
	int ans = 0;
	rep(i, n) {
		ans += a[i];
	}
	cout << ans << endl;
}


Measured memory_bytes: 2688
//template code, C343, 2019
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Iterator;

class GraphR {
	private int totalVertex;
	private LinkedList<LinkedList<Integer>> adjList;

	// adjacency list of edges
	public GraphR() {
		totalVertex = 0;
	}

	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjList = new LinkedList<LinkedList<Integer>>();
		for (int i = 0; i < totalVertex; i++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			int idx1 = in.nextInt();
			int degree = in.nextInt();
			// System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
			for (int j = 0; j < degree; j++) {
				int idx2 = in.nextInt();
				int weight = in.nextInt();
				tmp.add(idx2);
				tmp.add(weight);
			}
			adjList.add(tmp);
		}
		in.close();
	}

	public void runDijkstra() {
		Pair[] paths = new Pair[totalVertex];
		paths[0] = new Pair(0);

		for (int i = 1; i < totalVertex; i++) {
			paths[i] = new Pair(Integer.MAX_VALUE);
		}

		int min = 0;

		while (min != -1) {
			Pair minPair = paths[min];
			minPair.setDone(true);
			LinkedList<Integer> neighbors = adjList.get(min);
			Iterator<Integer> it = neighbors.iterator();

			while (it.hasNext()) {
				int n = it.next();
				int w = it.next();
				Pair neighbor = paths[n];
				neighbor.setDistFromStart(Math.min(neighbor.getDistFromStart(), minPair.getDistFromStart() + w));
			}

			min = findMinVertex(paths);
		}

		for (int i = 0; i < totalVertex; i++) {
			System.out.println(i + " " + paths[i].getDistFromStart());
		}
	}

	private int findMinVertex(Pair[] paths) {
		int min = -1;
		int minDist = Integer.MAX_VALUE;

		for (int i = 0; i < totalVertex; i++) {
			Pair p = paths[i];
			if (p.getDistFromStart() < minDist && !p.isDone()) {
				minDist = p.getDistFromStart();
				min = i;
			}
		}

		return min;
	}
}

class Pair implements Comparable<Pair> {
	private int distFromStart;
	private boolean isDone;

	public Pair(int distFromStart) {
		this.distFromStart = distFromStart;
		this.isDone = false;
	}

	public boolean isDone() {
		return isDone;
	}

	public void setDone(boolean isDone) {
		this.isDone = isDone;
	}

	public int getDistFromStart() {
		return distFromStart;
	}

	public void setDistFromStart(int distFromStart) {
		this.distFromStart = distFromStart;
	}

	public int compareTo(Pair other) {
		return this.distFromStart - other.distFromStart;
	}
}

//change class name GraphRepresentation to Main() for submission to AIZU
public class Main {
	public static void main(String argv[]) {
		GraphR g = new GraphR();
		g.loadAdjList();
		// g.updateTimes();
		// g.printTimeStamps();
		// g.printAdjMatrix();
		// g.printShortestPaths();
		g.runDijkstra();
	}
}


Measured memory_bytes: 40016
import java.util.*;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        String input = sc.next().trim();
        int s = 0;
        int w = 0;
        int n = 0;
        int e = 0;
        for(int i = 0; i < input.length(); i++) {
            switch (input.charAt(i)) {
                case 'S':
                    s = 1;
                    break;
                case 'N':
                    n = 1;
                    break;
                case 'W':
                    w = 1;
                    break;
                case 'E':
                    e = 1;
                    break;
            }
        }
        String ans = (((s^n)|(e^w)) == 1) ? "No" : "Yes";
        System.out.println(ans);
    }
}


Measured memory_bytes: 9684
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    double w, h, x, y; cin >> w >> h >> x >> y;
    double ans = (w * h) / 2.00000;
    cout << fixed << setprecision(9) << ans << " "; 
    cout << (x * 2 == w and y * 2 == h ? 1 : 0) << endl;

}

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

int main(){
    string s, spart;
    cin >> s;
    int min = 999;
    int tmp = 0;
    for(int i = 0; i < s.length()-2; i++){
        spart = s.substr(i, 3);
        tmp = stoi(spart);
        if(min > abs(tmp - 753)) min = abs(tmp - 753);
    }
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vp;
typedef map<ll, ll> mll;
typedef map<string, ll> mstrll;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fir first
#define sec second
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
#define out(x) cout << (x)
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
ll gcd(ll a, ll b){return b != 0 ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}
const ll INF = 1e16;
const ll MOD = 1e9 + 7;
ll a, b, c, n, m, x, y, z, w, h, ans, cnt, mx, mn;
string s, t;
vll dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
//vll dx = {-1, 0, 1, -1, 1, -1, 0, 1}, dy = {-1, -1, -1, 0, 0, 1, 1, 1};

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> n >> a >> b){
        if((b - a) <= 2 || a >= b){
            print(n + 1);
        }else{
            ll turn = n - a + 1;
            print(turn / 2 * (b - a) + (n - (a - 1)) % 2 + a);
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#define rep(i,n) for(int i = 0; i < n; i++)
using ll = long long;
using namespace std;
int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  cout << max(abs(min(a,c)-max(b,d)) - abs(c-a) - abs(d-b),0) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    LL a, b;
    int c, d;
    cin >> a >> b >> c >> d;
    --a;
    LL p = b / (LL)c - a / (LL)c;
    LL q = b / (LL)d - a / (LL)d;
    LL tmp = (LL)c / __gcd( c, d ) * d;
    LL r = b / tmp - a / tmp;
    cout << ( b - a ) - ( p + q - r ) << endl;
    return 0;
}



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

int main() {
  int a,b,c,k;
  cin >> a >> b >> c >> k;

  bool flag = false;
  bool a_b = false;
  bool b_c = false;

  while(true) {
    if(a < b) {
      a_b = true;
    }
    if(a_b && b < c) {
      b_c = true;
    }
    if(a_b && b_c) {
      flag = true;
      break;
    }

    if(k == 0) {
      break;
    }

    if(!a_b) {
      b *= 2;
    }
    if(a_b && !b_c) {
      c *= 2;
    }
    k--;
  }

  if(flag) cout << "Yes" << '\n';
  else cout << "No" << '\n';

  return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii  pair<int,int>
#define vpii vector<pii>
#define vll  vector<ll>
#define vi  vector<int>
#define pb push_back
#define f  first
#define s  second

int main() {

  int x,a,b;
    cin>>x>>a>>b;
    
      if(abs(x-a)>abs(x-b))
          cout<<"B";
     else
         cout<<"A";
    
    
    
    

	return 0;
}

Measured memory_bytes: 256
using System;

namespace _0031
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string now = Console.ReadLine();
                if (now == null)
                {
                    break;
                }
                int x = int.Parse(now);
                string two = Convert.ToString((x), 2);
                int j = 1;
                int k = 0;
                for (int i = two.Length - 1; i >= 0; i--)
                {
                    if(two[i]=='1')
                    {
                        if(k==0)
                        {
                            Console.Write(j);
                        }
                        else
                        {
                            Console.Write(" " + j);
                        }
                        k++;
                    }
                    j = j * 2;
                }
                Console.WriteLine();
            }
        }
    }
}

Measured memory_bytes: 9152
s=gets.chomp
n=s.size-1
ans=0
patterns=[]
(2**n).times do |i|
  patterns << i.to_s(2).rjust(n, "0")
end

patterns.each do |pattern|
  new_s=s.dup
  diff=0
  pattern.size.times do |i|
    if pattern[i]=="1"
      new_s=new_s.insert(i+1+diff, " ")
      diff+=1
    end
  end
  ans+=new_s.split.map(&:to_i).inject(:+)
end
puts ans


Measured memory_bytes: 1788
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {
        int h = sc.nextInt();
        int w = sc.nextInt();
        int n = sc.nextInt();
        int[] arr = new int[n];
        for (int i=0; i<n; i++) arr[i] = sc.nextInt();

        int[][] ans = new int[h][w];

        List<Integer> list = new ArrayList<>();

        for (int i=0; i<n; i++) {
            for (int j=0; j<arr[i]; j++) {
                list.add(i+1);
            }
        }

//        System.out.println(list);

        List<List<Integer>> sub = new ArrayList<>();

        for (int i=0; i<h; i++) {
            sub.add(list.subList(i*w, i*w+w));
        }

//        System.out.println(sub);

        for (int i=0; i<h; i++) {
            if (i%2==0) {
                for (int j=0; j<w-1; j++) {
                    System.out.print(sub.get(i).get(j)+" ");
                }
                System.out.println(sub.get(i).get(w-1));
            } else {
                for (int j=w-1; j>=1; j--) {
                    System.out.print(sub.get(i).get(j)+" ");
                }
                System.out.println(sub.get(i).get(0));

            }
        }




    }

}

Measured memory_bytes: 34636
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int A, B, C, K;
	cin >> A >> B >> C >> K;
	if(A >= K){
		cout << K << endl;
	}
	else if(A+B >= K){
		cout << A << endl;
	}
	else{
		cout << A-(K-A-B) << endl;
	}
}

Measured memory_bytes: 3648
# base-2 number
from math import ceil, floor
n = int(input())


low = 0
high = 1
digit = 1

while True:
    if low <= n <= high:
        break

    if digit & 1:
        low += (-2) ** digit
    else:
        high += (-2) ** digit
    digit += 1

ans = ""
for i in range(digit, 0, -1):
    mid = (low + high) / 2
    if low <= n < mid:
        if i % 2 == 0:
            ans += "1"
        else:
            ans += "0"
        high = floor(mid) if mid > 0 else ceil(mid)
    else:
        if i % 2 == 0:
            ans += "0"
        else:
            ans += "1"
        low = ceil(mid) if mid > 0 else floor(mid)

print(ans)


Measured memory_bytes: 3064
import Data.List
import Data.Array
import Data.Array.IO
import Data.Maybe
import Data.Bits
import Control.Monad
import Control.Applicative

modifyArray arr i f = readArray arr i >>= \x -> writeArray arr i (f x)

listToTuple2 (a:b:_) = (a,b)
listToTuple3 (a:b:c:_) = (a,b,c)
listToTuple4 (a:b:c:d:_) = (a,b,c,d)

main :: IO ()
main = do
  n <- readLn :: IO Int

  putStrLn $ foldl1 (++) . map show $ reverse $ minusbinary n

  where
    minusbinary 0 = [0]
    minusbinary 1 = [1]
    minusbinary n = s : (minusbinary (div (n-s) (-2)))
      where s = if odd n then 1 else 0


Measured memory_bytes: 508
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(){
  int x, key=0,a,b;
  int stack[101];
  char s[100];

  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
		a = stack[key];
                b = stack[key-1];
                stack[key-1] = b + a;
                key--;

    } else if ( s[0] == '-' ){
                a = stack[key];
                b = stack[key-1];
                stack[key-1] = b - a;
                key--;

    } else if ( s[0] == '*' ){
		a = stack[key];
                b = stack[key-1];
                stack[key-1] = b * a;
                key--;

    } else {
      x = atoi(s);
      key++;
      stack[key] = x;
    }
  }
  printf("%d\n",stack[key]);

  return 0;
}

Measured memory_bytes: 548
#include<bits/stdc++.h>
using namespace std;
const int N=2e8+5;
char s[N],t[N];
int n,m,xx,yy,nex[N];
void kmp_init()
{
    int i=1,k=0;
    while(i<=xx*m)
        if(k==0||t[i]==t[k]) nex[++i]=++k;
    else k=nex[k];
}
int main()
{
    scanf("%s%s",s+1,t+1);
    n=strlen(s+1);m=strlen(t+1);
    xx=50000000/m;
    for(int j=1;j<xx;j++)
    for(int i=1;i<=m;i++)
        t[i+m*j]=t[i];
    kmp_init();
    int ans=0,p=m*xx/n;
    int now=0,pos=0;
    m*=xx;
    for(int l=1;l<=p;l++)
    {
        for(int i=1;i<=n;i++)
        {
            pos++;
            while(pos&&t[pos]!=s[i])
                pos=nex[pos];
            ans=max(ans,pos);
        }
    }
    m/=xx;
    if(ans==n*p||ans>=n*(p-1)) printf("-1\n");
    else printf("%d\n",ans/m);
}


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

int main() {
  int N;
  cin >> N;
  vector<double> vec(N);
  for(int i=0;i<N;i++){
    cin >> vec.at(i);
  }
  
  double bunbo = 0;
  for(int i=0;i<N;i++) bunbo += 1/vec.at(i);
  //cout << "bonbo:" << bunbo << endl;
  cout << 1/bunbo << endl;
  /*
  // 分子
  double q = 1;
  for(int i=0;i<N;i++){
    q *= vec.at(i);
  }
  
  // cout << "q:" << q << endl;
  
  vector<int> vec2(N);
  for(int i=0;i<N;i++){
    vec2.at(i) = 1;
    for(int j=0;j<N;j++){
      if(j!=i){
        vec2.at(i) *= vec.at(j);
      }
    }
  }
  
  //for(int i=0;i<N;i++) cout << vec2.at(i) << endl;
  
  int p = 0;
  for(int i=0;i<N;i++){
    p += vec2.at(i);
  }
  
  //cout << "p:" << p << endl;
  //cout << "q:" << q << endl;
  
  double ans = q/p;
  cout << ans << endl;
  */
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Maxn 200007
using namespace std;
int n;
int lx[Maxn],rx[Maxn];
long long ans=0;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		scanf("%d%d",&lx[i],&rx[i]);
	sort(lx,lx+n+1);
	sort(rx,rx+n+1);
	for (int i=0;i<=n;i++)
		if (lx[n-i]>rx[i]) ans+=lx[n-i]-rx[i];
	printf("%lld\n",2*ans);
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <time.h>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) (min(a,b) <= (x) && (x) <= max(a,b)) //hei
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007LL
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pll Dir[4] = {
	{ -1 ,0 },{ 0 , 1 },{ 1 ,0 },{ 0 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL
#define chmax(a,b) a = max(a,b)
#define chmin(a,b) a = min(a,b)

struct Edge {
	int from, to;
	ll w;
	bool operator<(const Edge& rhs) const {
		return MP(w, MP(from, to)) < MP(rhs.w, MP(rhs.from, rhs.to));
	}

};

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

signed main(void) {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int cou = 0;
	char bef = 'A';
	REP(i, n) {
		if (s[i] != bef) {
			cou++;
			bef = s[i];
		}
	}
	cout << cou << endl;
	return 0;
}


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

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

  string S;
  cin >> S;

  int ans = 0;
  for (int i = 0; i < N - 2; i++) {
    if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C') ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636