akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;


int main(){
   int H;
   cin >> H;
   int N;
   cin >> N;
   vector<int> A(N,0);
   for(int i=0;i<N;i++){
      cin>>A[i]
   ;}
   int sum=0; 
   for(int i=0;i<N;i++){
     sum+=A[i]
   ;}
   if(sum>=H)cout<<"Yes"<<endl;
   else cout<<"No"<<endl;

   return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
  int num[2][2];
  //
  //  A B
  //  C D
  scanf("%d%d%d%d", &num[0][0], &num[1][0], &num[0][1], &num[1][1]);
  int ans[2];

  if (num[0][0] > num[0][1])
  {
    ans[0] = num[0][0];
  }
  else
  {
    ans[0] = num[0][1];
  }

  if (num[1][0] < num[1][1])
  {
    ans[1] = num[1][0];
  }
  else
  {
    ans[1] = num[1][1];
  }

  if ((ans[1] - ans[0]) >= 0)
  {
    printf("%d\n", ans[1] - ans[0]);
  }
  else
  {
    printf("0\n");
  }

  return 0;
}

Measured memory_bytes: 128
package main

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

func lib_CopyInt64(values []int64) []int64 {
	dst := make([]int64, len(values))
	copy(dst, values)
	return dst
}
func lib_MinInt64(values ...int64) (min int64, err error) {
	if len(values) == 0 {
		return 0, errors.New("empty slice is given")
	}
	min = values[0]
	for _, value := range values {
		if min > value {
			min = value
		}
	}
	return
}
func lib_MustMinInt64(values ...int64) (min int64) {
	min, err := lib_MinInt64(values...)
	if err != nil {
		panic(err)
	}
	return min
}
func lib_New2DimInt64SliceWithInitialValue(row, col int, initialValue int64) [][]int64 {
	ret := make([][]int64, row)
	values := lib_NewInt64SliceWithInitialValue(col, initialValue)
	for r := 0; r < row; r++ {
		ret[r] = lib_CopyInt64(values)
	}
	return ret
}
func lib_NewInt64SliceWithInitialValue(length int, initialValue int64) []int64 {
	ret := make([]int64, length)
	for i := 0; i < length; i++ {
		ret[i] = initialValue
	}
	return ret
}
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	const initialBufSize = 4096
	const maxBufSize = 1000000
	scanner.Buffer(make([]byte, initialBufSize), maxBufSize)
	scanner.Split(bufio.ScanWords)
	var N int64
	scanner.Scan()
	N, _ = strconv.ParseInt(scanner.Text(), 10, 64)
	var W int64
	scanner.Scan()
	W, _ = strconv.ParseInt(scanner.Text(), 10, 64)
	w := make([]int64, N)
	v := make([]int64, N)
	for i := int64(0); i < N; i++ {
		scanner.Scan()
		w[i], _ = strconv.ParseInt(scanner.Text(), 10, 64)
		scanner.Scan()
		v[i], _ = strconv.ParseInt(scanner.Text(), 10, 64)
	}
	fmt.Println(solve(N, W, w, v))
}
func solve(N int64, W int64, w []int64, v []int64) int64 {
	maxV := N * int64(1000)
	dp := lib_New2DimInt64SliceWithInitialValue(int(N)+1, int(maxV+1), math.MaxInt64/2)
	dp[0][0] = 0
	for i := 0; i < int(N); i++ {
		for j := int64(0); j <= maxV; j++ {
			if newV := j + v[i]; newV <= maxV {
				newW := dp[i][j] + w[i]
				dp[i+1][newV] = lib_MustMinInt64(dp[i+1][newV], newW)
			}
			dp[i+1][j] = lib_MustMinInt64(dp[i+1][j], dp[i][j])
		}
	}
	resV := int64(1)
	for i := int64(1); i <= maxV; i++ {
		if dp[N][i] <= W && resV < i {
			resV = i
		}
	}
	return resV
}


Measured memory_bytes: 83200
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;

int main(){
	int a,b,c,d;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	if(a+b==c+d) printf("Balanced\n");
	if(a+b<c+d) printf("Right\n");
	if(a+b>c+d) printf("Left\n");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    int a,b;
    string s;
    cin >> a >> b >> s;

    bool ans=true;
    for(int i=0;i<s.size();i++){
        if(i==a){
            if(s[i]!='-'){
                ans = false;
                break;
            }
        }else{
            if(s[i]-'0'<0 || s[i]-'0'>9){
                ans = false;
                break;
            }
        }
    }

    if(ans)cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3612
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>
#include<string.h>

typedef int32_t i32;
typedef int64_t i64;

#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))

const i32 mod = 1000000007;

void matmul (i32 *c, i32 *a, i32 *b, i32 n) {
  static i32 *tmp = NULL;
  if (tmp == NULL) tmp = ALLOC (n * n, i32);
  memset (tmp, 0, sizeof (i32) * n * n);
  for (i32 i = 0; i < n; ++i) {
    for (i32 k = 0; k < n; ++k) {
      for (i32 j = 0; j < n; ++j) {
        tmp[i * n + j] = (tmp[i * n + j] + (i64) a[i * n + k] * b[k * n + j]) % mod;
      }
    }
  }
  memcpy (c, tmp, sizeof (i32) * n * n);
}

void run (void) {
  i32 n;
  i64 k;
  scanf ("%" SCNi32 "%" SCNi64, &n, &k);
  i32 *s = ALLOC (n * n, i32);
  for (i32 i = 0; i < n * n; ++i) {
    scanf ("%" SCNi32, s + i);
  }
  i32 *t = ALLOC (n * n, i32);
  for (i32 i = 0; i < n; ++i) {
    t[i * n + i] = 1;
  }
  while (k > 0) {
    if (k & 1) matmul (t, s, t, n);
    matmul (s, s, s, n);
    k >>= 1;
  }
  i64 ans = 0;
  for (i32 i = 0; i < n * n; ++i) {
    ans += t[i];
  }
  ans %= mod;
  printf ("%" PRIi64 "\n", ans);
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1e09+7;



#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vi vector<int>

int main(){

  int n,m;
  cin>>n>>m;
  
  vi correct(n+1,0);
  vi wrong(n+1,0);
  
  rep(i,m){
    int p;
    string s;
    cin>>p>>s;
    if (s=="AC"){
      correct.at(p)=1;
    }
    else if (correct.at(p)==0){
      wrong.at(p)++;
    }
  }
  
  int correctcount=0;
  
  for (int i=1;i<=n;i++){
    correctcount+=correct.at(i);
  }
  
  int penaltycount=0;
  
  for (int i=1;i<=n;i++){
    if (correct.at(i)==1){
      penaltycount+=wrong.at(i);
    }
  }
  
  
  cout<<correctcount<<" "<<penaltycount<<endl;
  

  
  
  
}



Measured memory_bytes: 1024
import collection.mutable.ArrayBuffer

trait graph {
   import scala.reflect.ClassTag
   case class Edge[T](from : Int, to : Int, cost : T)
   type Edges[T] = ArrayBuffer[Edge[T]]
   def Edges[T](xs : Edge[T]*) = ArrayBuffer(xs : _*)
   type WeightedGraph[T] = ArrayBuffer[Edges[T]]
   def WeightedGraph[T](size : Int) = ArrayBuffer.fill(size)(Edges[T]())
   type UnWeightedGraph = ArrayBuffer[Edges[Int]]
   type Matrix[T] = Array[Array[T]]
   def Matrix[T:Numeric:ClassTag](row : Int, col : Int) : Matrix[T] = {
       val zero: T = implicitly[Numeric[T]].zero
       Array.fill(row, col)(zero)
   }
   def Matrix[T:Numeric:ClassTag](row : Int, col : Int, init : T) : Matrix[T] = {
       Array.fill(row, col)(init)
   }
   def Matrix[T:Numeric:ClassTag](size : Int) : Matrix[T] = Matrix(size, size)
   def Matrix[T:Numeric:ClassTag](size : Int, init : T) : Matrix[T] = Matrix(size, size, init)
}

object WarshallFloyd extends graph {
    def warshallFloyd(g : Matrix[Int], V : Int) = {
        val dist = g.clone
        for (i <- 0 until V) dist(i)(i) = 0
        for (k <- 0 until V) {
            for (i <- 0 until V) {
                for (j <- 0 until V 
                    if dist(i)(k) != Int.MaxValue 
                    && dist(k)(j) != Int.MaxValue) {
                    dist(i)(j) = dist(i)(j) min dist(i)(k) + dist(k)(j)
                }
            }
        }
        dist
    }
}


import WarshallFloyd._

object Main {
    def main(args: Array[String]) = {
        val sc = new java.util.Scanner(System.in)
        val V, E = sc.nextInt
        val mat = Matrix[Int](V, init = Int.MaxValue)
        for (_ <- 1 to E) {
            val s, t, c = sc.nextInt
            mat(s)(t) = c
        }
        val res = warshallFloyd(mat, V)
        var flag = true
        for (i <- 0 until res.size if flag) {
            if (res(i)(i) < 0) {
                flag = false
            }
        }
        if (!flag) {
            println("NEGATIVE CYCLE")
        } else {
            for (r <- res) {
                for (i <- 0 until r.size) {
                    if (i > 0) print(" ")
                    if (r(i) == Int.MaxValue) print("INF")
                    else print(s"${r(i)}")
                }
                println("")
            }
        }
    }
}


Measured memory_bytes: 86044
#include <iostream>
#include <math.h>
using namespace std;

int main(){
	int N;
	cin>>N;
	int kosu=0;
	for(int k=1;k<=N;k++){
		double	k_double = (double)k;
		double root = sqrt(k_double);
		int root_int=(int)root;
		if(pow(root_int, 2)==N){ //Nが平方根
			continue;
		}
		int number=0;
		for(int l=1;l<=root_int;l++){
			if(k%l==0){
				number+=2;	
			}
		}
		if(number==8 && k%2==1){
			kosu+=1;
		}
	}
	cout<<kosu;
	return 0;
}	


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;


int main(){

    int n, q;
    cin>>n>>q;
    string s;
    cin>>s;

    vector<int> sum(n+1, 0);
    rep(i,n){
        if(i+1<n && s[i]=='A' && s[i+1]=='C') sum[i+1]=sum[i]+1;
        else sum[i+1]=sum[i];
    }

    rep(i,q){
        int l, r;
        cin>>l>>r;
        l--;r--;
        cout<<sum[r]-sum[l]<<endl;
    }
   
    return 0;
}


Measured memory_bytes: 3848
#include <bits/stdc++.h>
#define maxn 200009
using namespace std;
vector<int>G[maxn];
int solve(int x,int y){
    int cnt=0;
    int n=G[x].size();
    int cur=0;
    while(cur<n){
        int L=cur;
        while(cur+1<n&&G[x][cur]==G[x][cur+1])
            cur++;
        int R=cur;
        cnt+=(R-L+1)/2;
        cur++;
    }
    return min(y/2,cnt);
}
int main(){
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        G[x%m].push_back(x);
    }
    for(int i=0;i<m;i++)
        sort(G[i].begin(),G[i].end());


    
    int ans=0;
    for(int i=0;i<=m/2;i++){
        int x=i;
        int y=(m-i)%m;
        int sz1=G[x].size();
        int sz2=G[y].size();
        if(x==y){
            ans+=sz1/2;
        }
        else if(y>x){
            if(sz1>sz2){
                ans+=solve(x,sz1-sz2);
            }
            else if(sz2>sz1){
                ans+=solve(y,sz2-sz1);
            }
            ans+=min(sz1,sz2);
        }
    }
    cout<<ans<<endl;
    //system("pause");
    return 0;
}

Measured memory_bytes: 8064
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		if(a > b){
			System.out.println("a > b");
		}
		else if(a < b){
			System.out.println("a < b");
		}
		else if(a == b){
			System.out.println("a == b");
		}
	}
}

Measured memory_bytes: 26096
import java.util.*;

public class Main {

    private static final long MOD = 1_000_000_007L;

    private static long fact[];

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        fact = new long[N+1];
        fact[0] = 1;
        for (int i = 1; i <= N; i++) {
            fact[i] = (fact[i-1]*i)%MOD;
        }

        long all = pow(10,N);
        long no09 = pow(8,N);

        long only0 = 0;
        for (int i = 1; i <= N; i++) {
            long tmp = comb(N,i)*pow(8,N-i);
            tmp %= MOD;
            only0 += tmp;
            only0 %= MOD;
        }

        long only9 = only0;

        long sub = no09+only0;
        sub %= MOD;
        sub += only9;
        sub %= MOD;

        long ans = all - sub;
        if (ans < 0) ans += MOD;
        ans %= MOD;
 
        System.out.println(ans);
    }

    private static long pow(long a, long n) {
        if (n == 0) return 1;
        if (n == 1) return a;

        if (n%2 == 1) {
            return (pow(a, n-1)*a)%MOD;
        } else {
            long half = pow(a, n/2);
            return (half*half)%MOD;
        }
    }

    private static long comb(int a, int b) {
        long lower = (fact[a-b]*fact[b])%MOD;
        return (fact[a]*pow(lower,MOD-2))%MOD;
    }
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#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 all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;

struct edge { int to, cost; };

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
//const ll INF = 1e18;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);

int dp[3010][3010];

int main()
{
	string s,t;
	cin >> s >> t;
	for(int i = 1; i <= s.size(); i++){
		for(int j = 1; j <= t.size(); j++){
			if(s[i-1] == t[j-1]) dp[i][j] = dp[i-1][j-1] + 1; 
			else dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
			//cout << dp[i][j];
		}
		//cout << s[i-1] <<  endl;
	}
	string ans;
	int i = s.size(),j = t.size();
	while(i > 0 && j > 0){
		if(dp[i-1][j] == dp[i][j]){
			i--;
		}else if(dp[i][j-1] == dp[i][j]){
			j--;
		}else{
			i--,j--;
			ans = s[i] + ans;
		}
	}
	cout << ans << endl;
	return 0;	
}

Measured memory_bytes: 35584
#include <bits/stdc++.h>
#include <ext/pb_ds/priority_queue.hpp>
#define priority_queue __gnu_pbds::priority_queue
typedef long long LL;
typedef long double LD;
typedef unsigned long long ul;
#define ri register int
#define pb push_back
#define fi first
#define se second
#define mid ((l + r) >> 1)
#define ls (i << 1)
#define rs (i << 1 | 1)
#define enum(i, j, k) for(int i = j; i <= k; i ++)
#define FO(x) { freopen(#x".in", "r", stdin); freopen(#x".out", "w", stdout); }
using namespace std;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
typedef vector<int> vi;
#define ae(x) for(node *p = h[x]; p; p = p->nxt)
#define G \
	struct node { int v; node *nxt; } e[maxm], *h[maxn]; int z;\
	void adde(int u, int v) { e[++z].v = v; e[z].nxt = h[u]; h[u] = &e[z]; }\
	void addrev(int u, int v) { adde(u, v); adde(v, u); }
#define W \
	struct node { int v, w; node *nxt; } e[maxm], *h[maxn]; int z;\
	void adde(int u, int v, int w) { e[++z].v = v; e[z].w = w; e[z].nxt = h[u]; h[u] = &e[z]; }\
	void addrev(int u, int v, int w) { adde(u, v, w); adde(v, u, w); }
inline int _() // ret >= 0
{
	int ret = 0; char ch = getchar();
	while(ch < '0' || ch > '9') ch = getchar();
	do { ret = ret * 10 + ch - '0'; ch = getchar(); } while('0' <= ch && ch <= '9');
	return ret;
}
inline void _(int x) // x >= 0
{
	if(x < 10) { putchar(x + '0'); return ; }
	_(x / 10); putchar(x % 10 + '0');
}
void What_are_you_doing_at_the_end_of_the_world_Are_you_busy_Can_you_save_us()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cout << fixed << setprecision(16);
}
/* Default Code Ends Here. */

LL gcd(LL x, LL y)
{
	return x == 0 ? y : gcd(y % x, x);
}

int main()
{
	What_are_you_doing_at_the_end_of_the_world_Are_you_busy_Can_you_save_us();
	
	LL n, t;
	cin >> n >> t;
	cout << 3 * (n / gcd(n, t) - 1) * gcd(n, t) << endl;
	return 0;
}


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

using namespace std;

int main(){
  int a[3], ans[6];

  cin >> a[0] >> a[1] >> a[2];

  ans[0] = abs(a[1] - a[0]) + abs(a[2] - a[1]);
  ans[1] = abs(a[2] - a[0]) + abs(a[1] - a[2]);
  ans[2] = abs(a[0] - a[1]) + abs(a[2] - a[0]);
  ans[3] = abs(a[2] - a[1]) + abs(a[0] - a[2]);
  ans[4] = abs(a[0] - a[2]) + abs(a[1] - a[0]);
  ans[5] = abs(a[1] - a[2]) + abs(a[0] - a[1]);
  
  sort(ans, ans+6);

  cout << ans[0] << endl;

  return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc062/tasks/arc074_a

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")

const int H_MAX = 1e5;
const int W_MAX = 1e5;
const ll INF = 1e12;

ll H, W;

void split(ll w, ll h, ll &s1, ll &s2) {
  ll s = w * h;
  if (s % 2 == 0) {
    s1 = s2 = s / 2;
  } else {
    s1 = (s + min(w, h)) / 2;
    s2 = s - s1;
  }
}

ll sd(ll s1, ll s2, ll s3) {
  ll ret = abs(s1 - s2);
  ret = max(ret, abs(s2 - s3));
  ret = max(ret, abs(s3 - s1));
  return ret;
}

void solve() {
  ll ans = INF;
  ll s1, s2, s3;
  FOR(w1, 1, W - 1) {
    s1 = w1 * H;
    split(W - w1, H, s2, s3);
    ans = min(ans, sd(s1, s2, s3));
  }
  FOR(h1, 1, H - 1) {
    ll s1 = W * h1;
    split(W, H - h1, s2, s3);
    ans = min(ans, sd(s1, s2, s3));
  }
  printf("%lld\n", ans);
}

void input() {
  scanf("%lld%lld", &H, &W);
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int mod=1000000007;
int main()
{
	ll x,s[1001];
	ll i,j;
	cin>>x;
	for(i=0;i<1001;i++)
		s[i]=i*i*i*i*i;
//		for(i=0;i<101;i++) cout<<s[i]<<" ";
	for(i=0;i<1001;i++)
	{
		for(j=0;j<1001;j++)
		{
			if(s[i]+s[j]==x)
			{
				cout<<i<<" "<<-1*j;
				break;
			}
			else if(s[i]-s[j]==x)
			{
				cout<<i<<" "<<j;
				break;
			}
		}
		if(j!=1001) break;
	}
	
	return 0;
}

Measured memory_bytes: 3632
a,b,c,x = [int(input()) for i in range(4)]
ans=0
for a0 in range(a+1):
  for b0 in range(b+1):
    for c0 in range(c+1):
      if (a0*500)+(b0*100)+(c0*50) == x:
        ans+=1
print(ans)

Measured memory_bytes: 2940
let n, m = Scanf.scanf " %d %d" @@ fun a b -> a, b
let a_ss = Array.(init n @@ fun _ -> Scanf.(scanf " %d" @@ fun k -> init k @@ fun _ -> scanf " %d" pred))
let cs = Array.make m 0
let _ = Array.(iter (fun a_s -> iter (fun a -> cs.(a) <- cs.(a) + 1) a_s) a_ss; fold_left (fun a c -> a + if c = n then 1 else 0) 0 cs) |> Printf.printf "%d\n"

Measured memory_bytes: 640
package main

import "fmt"

func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)

	ans := f(b, c, d) - f(a-1, c, d)
	fmt.Println(ans)
}

func f(x, c, d int) int {
	res := x
	res -= x / c
	res -= x / d
	res += x / lcm(c, d)
	return res
}

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

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
vector<vector<int>>v;
vector<int> ans;
void solve(int idx, int one)
{
    if(idx >= 10)
    {
        if(one)
            v.push_back(ans);
        return;
    }

    ans.push_back(1);
    solve(idx + 1, one + 1);
    ans.pop_back();

    ans.push_back(0);
    solve(idx + 1, one);
    ans.pop_back();

    return;
}
int main()
{
    Hello
    solve(0, 0);
    int n;
    ll ans = -1e10;
    cin >> n;
    int arr[n + 5][15], shop[n + 5][15];
    for(int i = 0; i < n; i++)
        for(int j = 0; j < 10; j++)
            cin >> arr[i][j];
    for(int i = 0; i < n; i++)
        for(int j = 0; j < 11; j++)
            cin >> shop[i][j];
    for(int i = 0; i < v.size(); i++)
    {
        ll cur = 0;
        for(int k = 0; k < n; k++)
        {
            int common = 0;
            for(int j = 0; j < 10; j++)
                if(arr[k][j] == v[i][j] && arr[k][j])
                    common++;
            cur += shop[k][common];
        }
        ans = max(ans, cur);
    }
    cout << ans;
    return 0;
}


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

using namespace std;
constexpr int64_t MOD = 1'000'000'007;

constexpr int     MAX =       500'005;

int64_t fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
int64_t COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(void) {
    COMinit();
    int64_t N, M;
    cin >> N >> M;

    int64_t tmp = fac[M] * finv[M-N] % MOD;

    vector<int64_t> v(N+1, 1);
    for(int i=1; i<=N; i++) {
        v[i] = v[i-1] * (M-N+i) % MOD;
    }

    int64_t ans = tmp;
    for(int k=1; k<=N; k++) {
        if(k%2) {
            ans -= COM(N, k) * v[N-k];
            ans %= MOD;
        } else {
            ans += COM(N, k) * v[N-k];
            ans %= MOD;
        }
    }

    ans *= tmp;
    ans %= MOD;
    if(ans < 0) ans += MOD;

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


Measured memory_bytes: 18584
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll x;
  cin >> x;
  ll ans = x / 11 * 2;
  x %= 11;
  if(x == 0) {
  } else if(x <= 6)
    ans++;
  else
    ans += 2;
  cout << ans << endl;
}

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

int main(){
	while(1){
		int x, y;
		cin >> x >> y;
		if(x==0 && y==0) break;
		
		if(x>y){
			int tmp = x;
			x = y;
			y = tmp;
		}
		cout << x << " " << y <<endl;
	}
}


Measured memory_bytes: 2992
#include <iostream>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define inf 1e+9
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define msg(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define pri(a) cout << a << endl;

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

  ll n,ans=0;
  cin >> n;
  //ll n,k,ans=0;
  //cin >> n >> k;
  // stirng s;
  // cin >> s;
  ll d[n];
  rep(i,n){
    cin >> d[i];
  }

  rep(i,n){
    for(int j=i+1;j<n;j++){
      ans += d[i]*d[j];
    }
  }



  cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MX = 300000;
int row[MX], col[MX];
map<pair<int, int>, bool> mp;
int main() {
  int h, w, m, maxrow = 0, maxcol = 0;
  cin >> h >> w >> m;

  for (int i = 0; i < m; i++) {
    int r, c;
    cin >> r >> c;
    r--;
    c--;
    mp[{r, c}] = 1;
    row[r]++;
    col[c]++;
    maxrow = max(maxrow, row[r]);
    maxcol = max(maxcol, col[c]);
  }
  vector<int> max_rows, max_cols;
  for (int i = 0; i < h; i++) if (row[i] == maxrow) max_rows.push_back(i);
  for (int j = 0; j < w; j++) if (col[j] == maxcol) max_cols.push_back(j);
  int ans = maxrow + maxcol;
  for (int i = 0; i < max_rows.size(); i++) for (int j = 0; j < max_cols.size(); j++) {
    if (!mp[{max_rows[i], max_cols[j]}]) {
      cout << ans << endl;
      return 0;
    }
  }
  cout << --ans << endl;
  return 0;
}

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

int main(){
  
  //入力
  int N;
  cin>>N;
  int a[N];
  int b[N];
  int c[N];   
  for(int i=0;i<N;i++){
    cin>>a[i]>>b[i]>>c[i];
  }
  
  //dpテーブルを0で初期化
  int dp[N][3];
  for(int i=0;i<N;i++){
    for(int j=0;j<3;j++){
      dp[i][j]=0;
    }
  }
  
  //dp
  
  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]=dp[i-1][1]+a[i];
    dp[i][0]=max(dp[i][0],dp[i-1][2]+a[i]);
    dp[i][1]=dp[i-1][0]+b[i];
    dp[i][1]=max(dp[i][1],dp[i-1][2]+b[i]);    
    dp[i][2]=dp[i-1][0]+c[i];
    dp[i][2]=max(dp[i][2],dp[i-1][1]+c[i]); 
  }
  cout<<max(max(dp[N-1][0],dp[N-1][1]),dp[N-1][2])<<endl;
  return 0;
}



Measured memory_bytes: 5904
import java.util.*;

public class Main {
	static public void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		String c = s.next();
		if (n%2 == 1) {
			System.out.println("No");
		} else {
			boolean yes = true;
			for (int i=0; i<n/2 && yes; i++) {
				if (c.charAt(i) != c.charAt(i+n/2))
					yes = false;
			}
			if (yes) System.out.println("Yes");
			else System.out.println("No");
		}
	}
}

Measured memory_bytes: 21844
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        MyScanner scn = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        // Solution Start
        int t = scn.nextInt();
        if (t >= 1800) out.println("1");
        else if (t >= 1600) out.println("2");
        else if (t >= 1400) out.println("3");
        else if (t >= 1200) out.println("4");
        else if (t >= 1000) out.println("5");
        else if (t >= 800) out.println("6");
        else if (t >= 600) out.println("7");
        else out.println("8");
        //Solution end
        out.close();
    }


    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;

    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
    //--------------------------------------------------------
}


Measured memory_bytes: 32932
#include <bits/stdc++.h>
using namespace std;
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; }
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int n,q;
string s;
vector<int> l,r;

void input(){
    cin >> n >> q >> s;
    l.resize(q);
    r.resize(q);
    for(int i=0;i<q;i++) cin >> l[i] >> r[i];    
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    int cnt[n]; //先に"AC"の個数をカウントしておく
    cnt[0] = 0;
    for(int i=1;i<n;i++){
        if(s[i] == 'C' && s[i-1] == 'A'){
            cnt[i] = cnt[i-1] + 1;
        }
        else{
            cnt[i] = cnt[i-1];
        }
    }
    for(int i=0;i<q;i++){
        cout << cnt[r[i]-1] - cnt[l[i]-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 2256
#include<bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(register int i=a;i<=b;++i)
typedef long long ll;
signed main() {
	int n,m,a;
	scanf("%d%d",&n,&m);
	f(i,1,m) {
		scanf("%d",&a);
		n-=a;
		if(n<0) {
			printf("-1");
			return 0;
		}
	} printf("%d",n);
}

Measured memory_bytes: 3760
def main():
    n = int(input())
    s = list(input())
    w = 0
    e = 0
    r = [0]*n
    r[0] = s[1:].count('E')
    for i in range(n-1):
        r[i+1] = r[i]
        if s[i] == 'W':
            r[i+1] += 1
        if s[i+1] == 'E':
            r[i+1] -= 1
    print(min(r))
main()


Measured memory_bytes: 17616
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
S,T = [S() for _ in range(2)]
num = 0
for i in range(len(S)-len(T)+1):
    str = S[i:i+len(T)]
    count = 0
    for j in range(len(T)):
        if str[j]==T[j]:
            count += 1
        num = max(num,count)
print(len(T)-num)


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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> cnt(N, 0);
  for (int i = 0; i < N; i++) {
    int num;
    cin >> num;
    cnt[num - 1]++;
  }
  sort(cnt.begin(), cnt.end());
  int s = 0;
  for (int i = N - K - 1; i >= 0; i--) s += cnt[i];
  cout << s << endl;
}


Measured memory_bytes: 1152
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		char[] c = s.toCharArray();
		int n = s.length() - 1;
		String ans = null;
		for (int i = 0; i < (1 << n); i++) {
			long sum = c[0] - '0';
			StringBuilder formula = new StringBuilder();
			formula.append(sum);
			for (int j = 0; j < n; j++) {
				if ((i & (1 << j)) != 0) {
					sum += c[j + 1] - '0';
					formula.append("+" + c[j + 1]);
				} else {
					sum -= c[j + 1] - '0';
					formula.append("-" + c[j + 1]);
				}
			}
			if (sum == 7) {
				formula.append("=7");
				ans = formula.toString();
				break;
			}
		}
		System.out.println(ans);
		sc.close();
	}
}

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

int main(void) {
	long long k,n;
	vector<vector<long long>>ab;
	cin >> n >> k;
	ab.resize(n);
	for (long long i = 0; i < n; i++) {
		ab[i].resize(2);
	}
	for (long long i = 0; i < n; i++) {
		cin >> ab[i][0] >> ab[i][1];
	}

	sort(ab.begin(),ab.end());

	for (long long i = 0; i < n; i++) {
		k -= ab[i][1];
		if (k <= 0) {
			cout << ab[i][0] << endl;
			break;
		}
	}
}

Measured memory_bytes: 5760
/*******************************\
   Name:    REAJUL HAQUE REAYZ  |
   School:  COMILLA UNIVERSITY  |
            CSE (5TH BATCH)     |
********************************/
#include<bits/stdc++.h>
#define endl "\n"
#define inf 1<<30
#define pi acos(-1.0)
#define pb push_back
#define mp make_pair
#define ss stringstream
#define all(v) v.begin(), v.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define bit_cnt(mask) __builtin_popcount(mask)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MOD = 1000000007; /// 1e9+7
const int MAX = 100005;     /// 1e5+5
ll bigmod(ll n, ll r)
{
    if(r==0) return 1;
    if(r==1) return n;
    if(r%2==0)
    {
        ll ret = bigmod(n, r/2);
        return ((ret%MOD) * (ret%MOD)) % MOD;
    }
    else return ((n%MOD) * (bigmod(n,r-1)%MOD)) % MOD;
}
ll modinverse(ll a){return bigmod(a,MOD-2)%MOD;}
ll lcm(ll a, ll b) {a=abs(a); b=abs(b); return (a/__gcd(a,b))*b;}
ll gcd(ll a, ll b) {a=abs(a); b=abs(b); if(!b) return a; return __gcd(b,a%b);}

vector<string>s;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, l; cin>>n>>l;
    for(int i=0; i<n; i++) {
        string t; cin>>t;
        s.pb(t);
    }
    sort(all(s));
    for(int i=0; i<n; i++) cout<<s[i];
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
const ll INF = 1LL << 60;

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	set<int> st;
	st.insert(a);
	st.insert(b);
	st.insert(c);
	cout << st.size();
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var x int
	fmt.Scan(&x)

	if x <= 2 {
		fmt.Println("2")
		return
	}

	sosu := []int{2}

	for i := 3; ; i++ {
		isSosu := true
		for _, v := range sosu {
			if i%v == 0 {
				isSosu = false
				break
			}
		}
		if isSosu {
			sosu = append(sosu, i)
			if i >= x {
				break
			}
		}
	}
	fmt.Println(sosu[len(sosu)-1])
}


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

int main()
{
  string s;
  cin >> s;
  int n = s.size();
  if(s[0] == s[n - 1]){
    if(n % 2) cout << "Second" << endl;
    else cout << "First" << endl;
  }
  else{
    if(n % 2) cout << "First" << endl;
    else cout << "Second" << endl;
  }
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main()
{
    int a,b;
    cin>>a>>b;
    if (a==b)
        cout<<"Draw";
    else
    {
        if (a==1)
            cout<<"Alice";
        else
        {
            if (b==1)
                cout<<"Bob";
            else
            {
                if (a>b)
                    cout<<"Alice";
                else
                    cout<<"Bob";
            }
        }
    }


}


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


void solve(long long n, std::vector<long long> p){
    int res = 0;
    for (int i = 1; i + 1 < p.size(); i++) {
        if (p[i] > min(p[i-1], p[i+1]) && p[i] < max(p[i-1], p[i+1]))
            res++;
    }
    cout << res << endl;
}

int main(){
    long long n;
    scanf("%lld",&n);
    std::vector<long long> p(n);
    for(int i = 0 ; i < n ; i++){
        scanf("%lld",&p[i]);
    }
    solve(n, std::move(p));
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
char map[20][20];
void dfs(int i, int j) {
	map[i][j] = '0';
	if (map[i - 1][j] == '1')dfs(i - 1, j);
	if (map[i + 1][j] == '1')dfs(i + 1, j);
	if (map[i][j - 1] == '1')dfs(i, j - 1);
	if (map[i][j + 1] == '1')dfs(i, j + 1);
	return;
}
int main() {
	for (int i = 0; i <= 13; i++) {
		for (int j = 0; j <= 13; j++) {
			map[i][j] = '0';
		}
	}
	while (cin >> map[1][1]) {
		int ans = 0;
		for (int i = 1; i <= 12; i++) {
			for (int j = 1; j <= 12; j++) {
				if (i == 1 && j == 1)continue;
				cin >> map[i][j];
			}
		}
		for (int i = 1; i <= 12; i++) {
			for (int j = 1; j <= 12; j++) {
				if (map[i][j] == '1') {
					dfs(i, j);
					ans++;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

int dir[8][2] = { {-1,-1},{0,-1},{1,-1},{-1,0},{1,0},{-1,1},{0,1},{1,1} };
int h, w;
bool check(int i, int j)
{
	return i >= 0 && i < h&&j >= 0 && j < w;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	std::cout.tie(nullptr);
	cin >> h >> w;
	vector<string>ori(h);
	
	for(int i=0;i<h;i++)
		cin >> ori[i];
	vector<string> v(ori);
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)
		{
			if (ori[i][j] == '.')
			{
				int count = 0;
				for (int k = 0; k < 8; k++)
				{
					int x = i + dir[k][0], y = j + dir[k][1];
					if (check(x, y))
					{
						if (ori[x][y] == '#')
							count++;
					}
				}
				v[i][j] = count + 48;
			}
		}
	for(int i=0;i<h;i++)
	{
		cout << v[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 256
from collections import Counter
import bisect 

N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0

for i in range(N):
  for j in range(i+1, N):
    idx = bisect.bisect_right(L, L[i]+L[j]-1)
    ans += (idx-(j+1))

print(ans)

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	// your code goes here
	int n,arr[10000];
	long sum=0;
	cin>>n;
	for(int i=0;i<n;++i)cin>>arr[i];
	for(int i=0;i<n;++i){
	    for(int j=i+1;j<n;++j)sum+=(arr[i]*arr[j]);
	}
	cout<<sum;
}

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

string S;
char ans = 0;

int main() {
    cin >> S;
    
    bool app[26];
    for (int i = 0; i < 26; i++) app[i] = false;
    for (int i = 0; S[i] != '\0'; i++) app[S[i] - 'a'] = true;
    for (int i = 0; i < 26; i++) {
        if (!app[i]) {
            cout << (char) ('a' + i) << endl;
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}


Measured memory_bytes: 512
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;

typedef long long ll;

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

const int inf=2147483647;

ll read()
{
	ll x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}

void print(ll x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
//agc020_a
int n,a,b;

int main(){
	n=read(),a=read(),b=read();
	
	while(1){
		if(a<b-1) a++;
		else{
			puts("Borys");
			return 0;
		}
		if(b>a+1) b--;
		else{
			puts("Alice");
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
K = int(input())

a=[7 % K]
for i in range(1, K):
  a.append((10*a[i-1] + 7) % K)

flag = False
for i in range(len(a)):
  if a[i] == 0:
    print(i+1)
    flag = True
    break
if not flag:
  print(-1)


Measured memory_bytes: 48492
#include<bits/stdc++.h>
using namespace std;
int n,state;
long long num[100010];
long long totalsum=0,ans=LLONG_MAX,cou;

int main()
{
	int i,j;
	
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%lld",&num[i]);
	}
		//first is +
		state = 1;
		if(num[0] <= 0)
		{
			totalsum = 1;
			cou = -num[0]+1;
		}
		else
		{
			totalsum = num[0];
			cou = 0;
		}
		for(i=1;i<n;i++)
		{
			totalsum += num[i];
			state *= -1;
			
			if(state == 1)
			{
				if(totalsum <= 0)
				{
					cou += -totalsum+1;
					totalsum = 1;
				}
			}
			else if(state == -1)
			{
				if(totalsum >= 0)
				{
					cou += (totalsum)+1;
					totalsum = -1;
				}
			}
		}
		if(cou < ans) ans = cou;
		
		//first is -
		state = -1;
		if(num[0] >= 0)
		{
			totalsum = -1;
			cou = num[0]+1;
		}
		else
		{
			totalsum = num[0];
			cou = 0;
		}
		for(i=1;i<n;i++)
		{
			totalsum += num[i];
			state *= -1;
			
			if(state == 1)
			{
				if(totalsum <= 0)
				{
					cou += -totalsum+1;
					totalsum = 1;
				}
			}
			else if(state == -1)
			{
				if(totalsum >= 0)
				{
					cou += (totalsum)+1;
					totalsum = -1;
				}
			}
		}
		if(cou < ans) ans = cou;

	printf("%lld\n",ans);
}

Measured memory_bytes: 4580
import sys
from math import floor
def main():
    h = int(input())
    r = 0
    n = 1
    while True:
        if h == 1:
            r += n
            print(r)
            sys.exit()
        else:
            h = floor(h/2)
            r += n
            n *= 2

if __name__ == '__main__':
    main()

Measured memory_bytes: 9040
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>

using namespace std;
long long x_1, y_1, x_2, y_2, sw;
long long N;
long long X[200000], Y[200000];
long long n;
vector<pair<long long, long long> > fountains;
long long a[200000], dp[200000], len;
long long p_min, p_max, p;

int main() {

	scanf("%lld %lld %lld %lld", &x_1, &y_1, &x_2, &y_2);
	scanf("%lld", &N);
	for (int i = 0; i < N; i++) {
		scanf("%lld %lld",&X[i], &Y[i]);
	}

	if (x_1 > x_2) { 
		sw = x_1; x_1 = x_2; x_2 = sw; 
		sw = y_1; y_1 = y_2; y_2 = sw;
	}
	if (y_1 > y_2) {
		y_1 = -y_1;
		y_2 = -y_2;
		for (int i = 0; i < N; i++) {
			Y[i] = -Y[i];
		}
	}

	/*一直線だった時の処理をここら辺に書く*/

	if (x_1 == x_2) {
		/*間に噴水があるか調べる*/
		for (int i = 0; i < N; i++) {
			if (X[i] == x_1 && y_1 < Y[i] && Y[i] < y_2) {
				/*間に噴水がある*/
				printf("%.15Lf\n", (y_2 - y_1) * 100 - 20 + 40 * atan((long double)1));
				return 0;
			}
		}
		/*噴水はない*/
		printf("%lld\n", (y_2 - y_1) * 100);
		return 0;
	}

	if (y_1 == y_2) {
		/*間に噴水があるか調べる*/
		for (int i = 0; i < N; i++) {
			if (Y[i] == y_1 && x_1 < X[i] && X[i] < x_2) {
				/*間に噴水がある*/
				printf("%.15Lf\n",(x_2 - x_1) * 100 - 20 + 40 * atan((long double)1));
				return 0;
			}
		}
		/*噴水はない*/
		printf("%lld\n", (x_2-x_1)*100);
		return 0;
	}

	/*一直線じゃなかった場合*/

	for (int i = 0; i < N; i++) {
		if (x_1 <= X[i] && X[i] <= x_2 && y_1 <= Y[i] && Y[i] <= y_2) {
			fountains.push_back(make_pair(X[i], Y[i]));
		}
	}
	sort(fountains.begin(), fountains.end());
	/*最長増加部分列*/
	len = 0;
	n = fountains.size();
	if (n > 0) {
		for (int i = 0; i < n; i++) {
			a[i] = fountains[i].second;
		}

		len = 1;
		dp[0] = a[0];
		for (int i = 1; i < n; i++) {
			p_min = 0;
			p_max = len;
			while (p_min < p_max) {
				p = (p_min + p_max) / 2;
				if (dp[p] > a[i]) { p_max = p; }
				else { p_min = p + 1; }
			}
			if (p_min == len) { len++; }
			dp[p_min] = a[i];
			for (int j = 0; j < len; j++) {
			}
		}
	}
	/*(x_2-x_1) + (y_2-y_1)個の道を通って、その間にlen個の噴水を通る。
	100 * ((x_2-x_1) + (y_2-y_1))+(- 20 + 5pi) * len
	*/
	if (len <= x_2 - x_1 && len <= y_2 - y_1) {
		printf("%.15Lf\n", 100 * ((x_2 - x_1) + (y_2 - y_1)) + (-20 + 20 * atan((long double)1)) * len);
	}
	else {
		/*この場合を忘れていたっぽい…このときは、len-1個の噴水でショートカットし、1個の噴水で遠回りをする。
		100 * ((x_2-x_1) + (y_2-y_1))+(- 20 + 5pi) * (len-1) - 20 + 10pi
		*/
		printf("%.15Lf\n", 100 * ((x_2 - x_1) + (y_2 - y_1)) + (-20 + 20 * atan((long double)1)) * (len - 1) - 20 + 40 * atan((long double)1));
	}
	
}

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

int main()
{
    long long N, K;
    cin >> N >> K;
    vector<long long> A(N), F(N);
    rep(i, N)
    {
        cin >> A[i];
    }
    rep(i, N)
    {
        cin >> F[i];
    }
    sort(A.begin(), A.end());
    sort(F.rbegin(), F.rend());

    long long l = -1;
    long long r = A.back() * F.front();
    while (r - l != 1)
    {
        long long c = (l + r) / 2;
        long long trainingCount = 0;
        rep(i, N)
        {
            long long digestCost = c / F[i];
            trainingCount += max(A[i] - digestCost, (long long)0);
        }
        if (trainingCount <= K)
            r = c;
        else
            l = c;
    }

    long long ans = r;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3328
def puta ary
  
  size = ary.size
  
  ary.each_with_index do |s,i|
    print s
    print i == size - 1 ? "\n" : " "
  end
end
  

H, W = gets.split.map(&:to_i)
N = gets.to_i
a = gets.split.map(&:to_i)

k = 0

row = Array.new(W)

H.times do |i|
  
  W.times do |j|
    if a[k] == 0
      k += 1
    end
    
    row[j] = k + 1
    a[k] -= 1
  end
  
  row.reverse! if i.odd?
  puta row
end
  

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

class Solution
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        long k = 0;
        while(a.Any(v => v >= n))
        {
            for(int i = 0; i < n;i++ )
            {
                if (a[i] >= n)
                {
                    var t = a[i] / n;
                    a[i] %= n;
                    for (int j = 0; j < n; j++)
                    {
                        if (i != j)
                        {
                            a[j] += t;
                        }
                    }
                    k += t;
                }
            }
        }

        Console.WriteLine(k);
        return;
    }
}

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

const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n"
#define rep(i,n) for(int i=0; i<(n); ++i)

typedef pair<int, int> P;
typedef pair<string, int> Psi;


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

	int n,m;cin>>n>>m;

	if(n>=m){
		writeln(0);
		return 0;
	}

	vector<int> X(m);


	rep(i,m){
		cin>>X[i];
	}

	sort(X.begin(),X.end(),greater<int>());

	int ans =0;

	vector<int> x;

	for(int i=1; i<m; i++){
		ans +=(X[i-1]-X[i]);
		x.push_back(X[i-1]-X[i]);
	}

	sort(x.begin(),x.end(),greater<int>());

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




}



Measured memory_bytes: 1276
// by adiforluls
#pragma GCC optimize ("-O2")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define FAST            ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll              long long
#define ld              long double
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define mii             map<int,int>
#define vi              vector<int>
#define vll             vector<long long>
#define all(a)          (a).begin(),(a).end()
#define clz(a)          __builtin_clz(a) // count leading zeroes
#define ctz(a)          __builtin_ctz(a) // count trailing zeroes
#define popc(a)         __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define lul             1000000007
#define rep(i,a,b)      for(int i=a;i<b;i++)
#define rfor(i,a,b)     for(int i=a; i>=b; i--)
#define debug(x)        cerr << #x << " = " << x << endl;
#define F               first
#define S               second
#define mod             998244353 
#define pll             pair<ll,ll>
#define endl            '\n'
#define deci(n)         cout<<fixed<<setprecision(n)
#define ordered_set     tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key(k)
// find_by_order(k)
const ld PI = acos(-1.0);
const int INF = 0x3f3f3f3f;

int bsearch(vi &a, int val, int l, int r)
{
    int idx = -1;
    while(l<=r)
    {
        int mid = l + (r-l)/2;
        if(a[mid]>=val)
        {
            idx = mid;
            r = mid-1;
        }
        else l = mid+1;
    }
    return idx;
}
void solve()
{
    ll n; cin>>n;
    vi l(n);
    rep(i,0,n) cin>>l[i];
    sort(all(l));
    ll ans = (n*(n-1)*(n-2))/6;
    rep(i,0,n)
    {
        rep(j,i+1,n)
        {
            int idx = bsearch(l,l[i]+l[j],j+1,n-1);
            if(idx!=-1) ans-=(n-idx);
        }
    }
    cout<<ans;
}
int main()
{   
    FAST;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; t=1; //cin>>t;
    while(t--){
       solve();
    }
    return 0;
}

Measured memory_bytes: 384
n,m = map(int, input().split())

# マス目の上下左右の端が全て表になるので、マス目の総数から引けばOK ※角が重複するので-4をする
if n*m == 1: print(1)
elif n == 1 or m == 1: print(n*m - 2)
else: print(n*m - (2*n+2*m-4))

Measured memory_bytes: 9156