akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}


fn main()
{
    input! {
        n: usize,
        q: usize,
        s: chars,
        p: [(usize, usize); q],
    }

    let mut acc_arr = vec![0; n];

    for i in 1..n {
        let t = if s[i] == 'C' && s[i-1] == 'A' { 1 } else { 0 };
        acc_arr[i] = acc_arr[i-1] + t;
    }

    for i in 0..q {
        println!("{}", acc_arr[p[i].1-1]- acc_arr[p[i].0-1]);
    }
}

Measured memory_bytes: 6908
fun main(args:Array<String>){
    val numOfpole = readLine()!!.toInt()
    val poleLength = readLine()!!.split(" ").map(String::toInt)
    var ans = 0
    var counter = 1
    var counter2 = 2
    for(i in 0..numOfpole-3){
        for(j in counter..numOfpole-2){
            for(k in j+1..numOfpole-1){
                if(poleLength[i] + poleLength[j] > poleLength[k] &&
                   poleLength[j] + poleLength[k] > poleLength[i] &&
                   poleLength[k] + poleLength[i] > poleLength[j] &&
                   poleLength[i] != poleLength[j] &&
                   poleLength[i] != poleLength[k] && 
                   poleLength[j] != poleLength[k]) {
                    ans++
                }
            }
            counter2++
        }
        counter++
    }
    println(ans)
}

Measured memory_bytes: 38952
/*
 * 0を区切りに1以上が続く区間をスタックで管理しようとしたが、よく分からなくなり断念。
 * 方針を以下に変更
 * ①0が出てくるまで、目標の高さを先頭からマイナス1する
 * ②0が出てきた場合、先頭に戻る。
 *   ただし、1以上の区間に遭遇していない(先頭から連続する0の区間の場合) 例:[0,0,0,0,2,2,3]とか
 *   場合は先頭に戻らない
 * ③終了条件を満たすまで①、②を繰り返す。
 *   ⇒目標の高さが全て0になったら終了
 */

import java.util.Scanner;
class Main{
  public static void main(String[] args) {
    Main mmcgmCompany = new Main();
    mmcgmCompany.run();
  }
  private void run() {

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] ary = new int[n];
    int cnt = 0;
    for(int i=0; i<n; i++) {
      ary[i] = sc.nextInt();
    }

    boolean br = true;
    while(br){
      //out(ary);

      // 終了条件
      br = false;
      for(int i=0; i<n; i++) {
        if(ary[i] > 0 ) {
          br = true;
          break;
        }
      }
      boolean zeroSecEnd = true;
      for(int i=0; i<n; i++) {

        // 先頭の0を読み飛ばす
        if(ary[i] <= 0 && zeroSecEnd) {
          continue;
        }

        // 1以上の区間をマイナス1する。1以上の区間が終わったらブレイク。
        if(ary[i] <= 0) break;
        ary[i]--;
        zeroSecEnd = false;
      }
      // カウントアップ
      if (!zeroSecEnd) cnt++;

    }
    System.out.println(cnt);
  }
//  private void out(int[] pary) {
//	  for(int i : pary)
//		  System.out.print(i + " ");
//	  System.out.println();
//  }
}


Measured memory_bytes: 23124
<?php
  fscanf(STDIN,"%d %d",$N,$M);
  fscanf(STDIN,"%d %d",$min,$max);
  for($i=1;$i<$M;$i++){
  	fscanf(STDIN,"%d %d",$nl,$nr);
    $min = max($min,$nl);
    $max = min($max,$nr);
  }
  
if($max - $min < 0){
    echo 0;
    return;
}
 
  echo $max - $min+1;

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

int main() {
    int a,b,c,d,e,f;
    cin>>a>>b>>c>>d>>e>>f;
    double percent=0.0;
    int sum,sugar=0,water=0;
    for (int i=0; i<=30; i++) {
        for (int j=0; j<=30; j++) {
            for (int k=0; k<=100; k++) {
                for (int l=0; l<=100; l++) {
                    int water_weight=a*i+b*j;
                    int sugar_weight=c*k+d*l;
                    sum=100*water_weight+sugar_weight;
                    if (sum<=f&&sugar_weight<=water_weight*e) {
                        if (percent<(double)sugar_weight/(double)sum) {
                            percent=(double)sugar_weight/(double)sum;
                            water=water_weight*100;
                            sugar=sugar_weight;
                        }
                    }
                }
            }
        }
    }
    if (percent==0) water=100*a;
    cout<<water+sugar<<" "<<sugar<<endl;
}


Measured memory_bytes: 256
import { readFileSync } from 'fs'
import { reverse } from 'dns'
import { start } from 'repl'
 
let lines: string[] = [];
const reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});
 
reader.on('line', function (line: string) {
    lines.push(line);
});
reader.on('close', function () {
    let n = parseInt(lines[0])
    /* let a = lines[1].split(' ').map( _ => parseInt(_)) */
    
    if(n == 0) {
        console.log(1);
    } else {
        console.log(0);
    }

});

Measured memory_bytes: 30088
import java.util.Scanner;

public class Main {

	static int prime[];
	
	public static int solve(int c[]) {
		int count = 0;
		int c2[];
		c2 = new int[4];
		int n = c.length;
		int d[] = {3, 5, 15, 25};
		
		
		for(int i = 0; i < n; ++i) {
			if(c[i] >= 75)++count;
			for(int j = 0; j < 4; ++j) {
				if(c[i] >= d[j]) c2[j]++;
			}
		}
		
		count += (c2[0] - 1) * c2[3];
		count += (c2[1] - 1) * c2[2];
		count += c2[1] * (c2[1] - 1) * (c2[0] - 2) / 2;
		
		return count;
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		prime = new int[100];
		
		prime[0] = prime[1] = -1;
		prime[2] = 1;
		
		for(int i = 2; i < 100; ++i) {
			if(prime[i] != -1) {
				prime[i] = 1;
				for(int j = 2; i * j < 100; ++j) {
					prime[j * i] = -1;
				}
			}
		}
		
		int n;
		
		n = sc.nextInt();
		
		sc.close();
		
		int ans = 0;
		int count[];
		count = new int[n];
		
		for(int i = 2; i < n; ++i) {
			if(prime[i] == 1) {
				long tmp = i;
				int d = 1;
				while(tmp <= n) {
					count[i] += (n / tmp);
					++d;
					tmp = (long)Math.pow(i, d);
				}
				count[i]++;
			}
		}
		
		ans = solve(count);
		System.out.println(ans);
	}

}


Measured memory_bytes: 22868
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		long N = long.Parse(Console.ReadLine());
		long mod = 1000000007;
		long[,]D = new long[60,3];
		D[59,2] = 1;
		long Na = 0;
		if(N>=(long)Math.Pow(2,59)){
			D[59,1] = 1;
			Na += (long)Math.Pow(2,59);
		}
		for(var i=58;i>=0;i--){
          	if(N >= Na + (long)Math.Pow(2,i)){
				D[i,0] = D[i+1,0]*3+D[i+1,1]*2;
				D[i,1] = D[i+1,1]*1+D[i+1,2];
				D[i,2] = D[i+1,2];
              	Na += (long)Math.Pow(2,i);
			} else {
				if(N >= (long)Math.Pow(2,i)*2){
                 	D[i,0] = D[i+1,0]*3+D[i+1,1];
					D[i,1] = D[i+1,1];
					D[i,2] = D[i+1,1]+D[i+1,2];
				} else if(N >= (long)Math.Pow(2,i)){
                 	D[i,0] = D[i+1,0];
					D[i,1] = D[i+1,1]+D[i+1,2];
					D[i,2] = D[i+1,2];
                  	Na += (long)Math.Pow(2,i);
				} else {
					D[i,0] = D[i+1,0];
 	                D[i,1] = D[i+1,1];
    	            D[i,2] = D[i+1,2];
                }
			}
			D[i,0] %= mod;
			D[i,1] %= mod;
			D[i,2] %= mod;
		}
		Console.WriteLine((D[0,0]+D[0,1]+D[0,2])%mod);
	}
}

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

int main(){
  int A[5];
  for(int i=0; i<5; i++){
    cin >> A[i];
  }
  int mi=9;
  int idx=0;
  for(int i=0; i<5; i++){
    if(A[i]%10!=0 && A[i]%10<=mi){
      mi = A[i]%10;
      idx = i;
    }
  }
  int sum=0;
  for(int i=0; i<5; i++){
    if(i!=idx){
      if(A[i]%10==0) sum+= A[i];
      else sum+= A[i]+(10-A[i]%10);
    }
  }
  sum+=A[idx];
  cout << sum << 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)
#define REP(i,a,b) for(int i=a; i<b; ++i)
#define all(v) (v).begin() , (v).end()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvc = vector<vector<char>>;
using pii = pair<int , int>;
using pll = pair<long long , long long>;

//プロトタイプ宣言
void faster(void);
template <class T>
T gcd(T , T);
template <class T>
T get_digent(T);
template <class T>
T POW(T , T);


int main(){
  faster();
  int a,b;
  cin >> a >> b;
  string s,t;
  rep(i,b) s += to_string(a);
  rep(i,a) t += to_string(b);
  if(s<=t) cout << s;
  else cout << t;
}



























//同期解除
void faster(void){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

//ユークリッドの互除法
template <class T>
T gcd(T a, T b) {
  return (b ? gcd(b, a%b) : a);
} 

//桁数取得
template <class T>
T get_digent(auto x){
  string s;
  s = to_string(x);
  ll digent = s.size();
  return digent;
} 

//べき乗計算
template <class T>
T POW(T x, T y){
  if(y==0) return 1;
  if(y%2 == 1){
    ll temp = POW(x,y-1);
    return (temp*x);
  }
  else{
    ll temp = POW(x,y/2);
    return temp*temp;
  }
} 



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define fs first
#define sc second
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main(){
  ll n,k,q;
  cin>>n>>k>>q;
  vector<ll>a(q);
  vector<ll>b(n,k-q);
  rep(i,q){
    cin>>a[i];
  }
  rep(i,q){
    b[a[i]-1]++;
  }
    rep(i,n){
      if(b[i]>0)cout<<"Yes"<<endl;
      else cout<<"No"<<endl;
    }
}

Measured memory_bytes: 2176
n = input()
l = list(map(int, str(n)))

dp = [[0] * 2 for _ in range(len(l)+1)]
dp[0][1] = 1

for i, v in enumerate(l):
    dp[i+1][0] = min(dp[i][0] + v, dp[i][1] + (10 - v))
    dp[i+1][1] = min(dp[i][0] + v + 1, dp[i][1] + (10 - v) - 1)

print(dp[-1][0])

Measured memory_bytes: 154360
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  vector<int> ans;
  int n, flag;
  while(cin >> n){
    ans.clear();
    flag=0;
    if(n > 1023) return 0;
    for(int i=512; i >= 1; i /= 2){
      if(n - i >= 0){
	n -= i;
	ans.push_back(i);
      }
    }
    sort(ans.begin(), ans.end());
    vector<int>::iterator it = ans.begin();
    while( it != ans.end() ){
      if(flag == 0) {
	cout << *it;
	flag = 1;
      }
      else
	cout << " " << *it;
      ++it;
    }
    cout << endl;
    
  }
  return 0;
}

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

int main(){
	string s;
	cin >> s;
	int x,y;
	cin >> x >> y;

	int sx = 0;
	int sid = 0;
	for(int i = 0;i < s.size();i++){
		if(s[i] == 'T')break;
		sx++;
		sid = i;
	}

	vector<int> lr;
	vector<int> ud;
	int sum_lr = sx;
	int sum_ud = 0;
	bool now_x = true;
	for(int i = sx != 0 ? sid + 1 : 0;i < s.size();i++){
		int count_T = 0;
		int j = i;
		while(j < s.size() && s[j] == 'T'){
			j++;
			count_T++;
		}

		int count_F = 0;
		int k = j;
		while(k < s.size() && s[k] == 'F'){
			count_F++;
			k++;
		}

		//
		if(count_T % 2 == 1)now_x = !now_x;

		if(now_x){
			lr.push_back(count_F);
			sum_lr += count_F;
		}
		else{
			ud.push_back(count_F);
			sum_ud += count_F;
		} 
		i = k - 1;
	}


	vector<vector<bool>> dp_lr(lr.size()+1,vector<bool>(sum_lr * 2 + 1,false));
	dp_lr[0][sum_lr + sx] = true;
	for(int i = 0;i < lr.size();i++){
		for(int j = 0;j <= sum_lr * 2;j++){
			if(dp_lr[i][j]){
				dp_lr[i+1][j+lr[i]] = true;
				dp_lr[i+1][j-lr[i]] = true;
			}
		}
	}
	vector<vector<bool>> dp_ud(ud.size()+1,vector<bool>(sum_ud * 2 + 1,false));
	dp_ud[0][sum_ud] = true;
	for(int i = 0;i < ud.size();i++){
		for(int j = 0;j <= sum_ud * 2;j++){
			if(dp_ud[i][j]){
				dp_ud[i+1][j+ud[i]] = true;
				dp_ud[i+1][j-ud[i]] = true;
			}
		}
	}


	if(sum_lr + x > sum_lr * 2 || sum_ud + y > sum_ud * 2 || sum_lr + x < 0 || sum_ud + y < 0){
		cout << "No" << endl;
		return 0;
	}

	if(dp_lr[lr.size()][sum_lr+x] && dp_ud[ud.size()][sum_ud+y])cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 5816
N, X = map(int, input().split())
x = list(map(int, input().split()))

xx = [abs(xxx - X) for xxx in x]

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

l = xx[0]
if len(xx) > 1:
    for i in xx[1:]:
        l = gcd(l, i)


print(l)

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

std::vector<std::string> vecArray[12][12];
std::vector<std::string> ansVec;

char alphabets[] = {'0', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'};

int main(int argc, char *argv[])
{
    int n;
    std::cin >> n;
    vecArray[1][1].push_back("a");
    for(int i = 1; i < n; i++){
        for(int j = 1; j <= i; j++){
            for(std::string item : vecArray[i][j]){
                if(i == n-1){
                    ansVec.push_back(item+alphabets[j+1]);
                }else{
                    vecArray[i+1][j+1].push_back(item+alphabets[j+1]);
                }
                for(int k = 1; k <= j; k++){
                    if(i == n-1){
                        ansVec.push_back(item+alphabets[k]);
                    }else{
                        vecArray[i+1][j].push_back(item+alphabets[k]);
                    }
                }
            }
        }
    }
    if(n==1){std::cout << "a" << std::endl; return 0;}
    std::sort(ansVec.begin(), ansVec.end());
    for(std::string s : ansVec){
        std::cout << s << std::endl;
    }

    return 0;
}


Measured memory_bytes: 9592
// #include "bits/stdc++.h"
#include <vector>
#include <algorithm>
#include <iostream>
#include <math.h>

using namespace std;


class Timer {
#ifdef LOCAL
	std::chrono::high_resolution_clock::time_point m_start;
public:
	Timer() 
	: m_start(std::chrono::high_resolution_clock::now()) {}

	~Timer() {
		auto end = std::chrono::high_resolution_clock::now();
  		auto duration_s = std::chrono::duration<double>(end - m_start).count();
  		cerr << "Completed in " << duration_s << endl;
  	}
#else
#endif
};

template < class c > struct rge { c b, e; };
template < class c > rge<c> range(c i, c j) { return rge<c>{i, j}; }
template < class c > auto dud(c* x) -> decltype(cerr << *x, 0);
template < class c > char dud(...);
struct debug {
#ifdef LOCAL
	~debug() { cerr << endl; }
	template < class c > typename enable_if<sizeof dud<c>(0) != 1, debug&>::type operator<<(c i) { cerr << boolalpha << i; return *this; }
	template < class c > typename enable_if<sizeof dud<c>(0) == 1, debug&>::type operator<<(c i) { return *this << range(begin(i), end(i)); }
	template < class c, class b > debug & operator <<(pair < b, c > d) {
	  return * this << "(" << d.first << ", " << d.second << ")";
	}
	template < class c > debug & operator <<(rge<c> d) {
	  *this << "[";
	  for (auto it = d.b; it != d.e; ++it)
	    *this << ", " + 2 * (it == d.b) << *it;
	  return * this << "]";
	}
#else
	template < class c > debug & operator <<(const c&) { return * this; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

#define fori(i,n) for(int i=0; i<n; ++i)
#define forir(i,n) for(int i=n-1; i>=0; i--)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
const int INF = 1e9 + 5;

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

#include <iostream>

void solve() {
	ll modulo = 1e9 + 7;
	int h, w;
	cin >> h >> w;

	vector<vector<bool>> grid(h, vector<bool>(w, false)); // 0 - empty, 1 - wall
	vector<vector<ll>> dp(h, vector<ll>(w, 0)); // dp[i][j] - how many variants to get to grid[i][j]
	dp[0][0] = 1;

	char temp;	
	fori(i, h) {
		fori(j, w) {
			cin >> temp;
			if (temp == '#') {
				grid[i][j] = true;
			}

			if (i > 0 && !grid[i-1][j]) {
				dp[i][j] += dp[i-1][j];
				dp[i][j] %= modulo;
			}
			if (j > 0 && !grid[i][j-1]) {
				dp[i][j] += dp[i][j-1];
				dp[i][j] %= modulo;
			}
		}
	}

	cout << dp[h-1][w-1] << endl;
}

int main() {
	FAST
	int t = 1;
	// cin >> t;

	for (int i = 0; i < t; ++i) {
		solve();
	}
}

Measured memory_bytes: 8320
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			int m = scanner.nextInt();
			if ((n | m) == 0)
				break;
			int[] num = new int[n + 1];
			for (int i = 1; i <= n; i++)
				num[i] = scanner.nextInt();
			List<Integer> list = new ArrayList<Integer>();
			for (int i = 0; i <= n; i++)
				for (int j = i; j <= n; j++)
					if (num[i] + num[j] <= m)
						list.add(num[i] + num[j]);
			Collections.sort(list);
			int ans = list.get(0) + list.get(list.size() - 1);
			int i = 0;
			int j = list.size() - 1;

			boolean flag = true;
			while (i < j) {
				int l = i;
				int r = j;
				while (l < r) {
					int mid = (l + r) / 2;
					int ret = list.get(flag ? j : i) + list.get(mid);
					if (ret <= m) {
						ans = Math.max(ans, ret);
						l = mid + 1;
					} else {
						r = mid;
					}
				}

				if (flag)
					i = l + 1;
				else
					j = r;
				flag = !flag;

			}
			System.out.println(ans);

		}
	}
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);  
	
	int n, k;
	cin >> n >> k;
	vector<long long> a(n + 1);
	for(int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		a[i] = a[i - 1] + x;
	}
	vector<long long> s;
	for(int i = 0; i <= n; i++) {
		for(int j = i + 1; j <= n; j++) {
			s.push_back(a[j] - a[i]);
		}
	}
	sort(s.begin(), s.end(), greater<long long>());
	int siz = s.size();
	int max_bit = ceil(log(s[0]) / log(2));
	long long ans = 0;
	for(int i = max_bit; i >= 0; i--) {
		int cnt = 0;
		for(int j = 0; j < siz; j++) {
			if((s[j] >> i) & 1) cnt++;
		}
		if(cnt >= k) {
			for(int j = 0; j < siz; j++) {
				if(((s[j] >> i) & 1) == 0) s[j] = 0;
			}
			ans += pow(2, i);
		}
	}
	cout << ans << endl;
	return 0;	
}

Measured memory_bytes: 6256
#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#define debug(x) cout << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
typedef long long ll;
const int maxn=2e5+7,inf=0x3f3f3f3f,mod=1e9+7;

ll dp[70][2][2];
int a[70];

ll dfs(int pos,bool lim=1,bool add=0)  //add表示当前位需不需要产生进位
{
    if(pos<0) return add==0;
    if(dp[pos][lim][add]!=-1) return dp[pos][lim][add];
    ll res=0;
    int up=lim?a[pos]:1;
    if(up==1)  //当前1
    {
        if(add) res=(res+dfs(pos-1,lim,1))%mod;  //1 1
        else
        {
            res=(res+dfs(pos-1,lim,0))%mod;
            res=(res+dfs(pos-1,lim,1))%mod;
        }
    }
    //0
    if(add)
    {
        res=(res+dfs(pos-1,lim&&up==0,1))%mod;  //1 0
        res=(res+dfs(pos-1,lim&&up==0,0))%mod;  //1 1
    }
    else res=(res+dfs(pos-1,lim&&up==0,0))%mod;  //0 0
    return dp[pos][lim][add]=res;
}
ll solve(ll x)
{
    memset(dp,-1,sizeof(dp));
    int pos=0;
    while(x)
    {
        a[pos++]=x&1;
        x/=2;
    }
    return dfs(pos-1);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin>>n;
    cout<<solve(n)<<'\n';
    return 0;
}


Measured memory_bytes: 3584
#include<stdio.h>
int main()
{
    int n, a[101], i, sum=0, p;
    scanf("%d" , &n);
    for(i=1; i<=n; i++)
    {
        scanf("%d", &a[i]);
        sum += a[i];
    }
    int max = -1;
    for(i=1; i<=n; i++)
    {
        if(a[i] > max)
            max = a[i];
    }
    p = sum - max;
    if(p > max)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}

Measured memory_bytes: 1660
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int l = Integer.parseInt(sc.next());
		int sum = 0;
		for (int i = 1; i <= n; i++) {
			sum += l + i - 1;
		}
		int ans = 0;
		for (int i = 1; i <= n; i++) {
			if (Math.abs(sum - ans) > Math.abs(l + i - 1)) {
				ans = sum - (l + i - 1);
			}
		}
		System.out.println(ans);
		sc.close();
	}
}

Measured memory_bytes: 21844
num,money = map(int,input().split())

for x in range(num +1):
  for  y in range(num-x +1):
    summary = 9000*x + 4000*y + 1000*num
    if summary == money:
      print(x,y,num-x-y)
      exit()
print("-1 -1 -1")


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n; cin >> n;
	vector<vi> v(n, vi(n)), tate(n, vi(n + 1));
	rep(i, n) rep(j, n){
		cin >> v[i][j];
		tate[j][i + 1] = tate[j][i] + v[i][j];
	}
	
	int ans = -inf;
	rep(y, n) for(int Y = y; Y < n; Y++){
		int s = -inf;
		rep(x, n){
			int tmp = tate[x][Y + 1] - tate[x][y];
			int tmp2 = y == Y ? v[y][x] : v[Y][x] + v[y][x];
			ans = max(ans, max(0, s) + tmp);
			s = max(s + tmp2, tmp);
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
	string S;
	cin >> S;
	int alp[26] = {0};
	rep(i,S.size()){
		int j = S[i] - 'a';
		alp[j] ++;
	}

	rep(i,26){
		if (alp[i] == 0) {
			printf("%c\n", 'a'+i);
			return 0;
		}
	}
	cout << "None" << endl;
	
	return 0;
}


Measured memory_bytes: 3812
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
typedef long long ll;

template<typename T>
struct BIT {
  vector<T> data;
  BIT() {}
  BIT(int n) : data(n+1, 0) {}
  void init(int n) { data.assign(n+1, 0); }
  T sum(int ed) const {
    // cerr << ">> " << ed << endl;
    for(T res(0); ; ed &= ed-1) if(ed) res += data[ed]; else return res;
  }
  void add(int i, const T& x) {
    // cerr << ">>> " << i << endl;
    for(++i; i < (int)data.size(); i += i&-i) data[i] += x;
  }
};

int n;
ll k;
ll vs[200000+10];
ll ss[200000+10];
ll ts[200000+10];

int main(void) {
  scanf("%d%lld", &n, &k);
  REP(i, n) {
    scanf("%lld", &vs[i]);
    ts[i+1] = ss[i+1] = ss[i] + vs[i] - k;
  }

  sort(ts, ts + n+1);
  ll res = 0;
  BIT<ll> bit(n+1);
  {
    int idx = lower_bound(ts, ts+n+1, ss[n]) - ts;
    // cerr << " add to " << idx << endl;
    bit.add(idx, 1);
  }
  for(int i = n-1; i >= 0; --i) {
    // cerr << "i=" << i << ", ss[i]=" << ss[i] << endl; 
    int idx = lower_bound(ts, ts+n+1, ss[i]) - ts;
    // cerr << " + " << bit.sum(n) - bit.sum(idx) << " @ i=" << i << ", idx=" << idx << endl;
    res += bit.sum(n+1) - bit.sum(idx);
    bit.add(idx, 1);
  }
  printf("%lld\n", res);
  
  return 0;
}


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

int main()
{
    int n, i;
    double m, sum=0, cnt=0;
    double mini;

    cin >> n >> m;
    int a[n];

    for(i=0; i<n; i++)
    {
        cin >> a[i];
    }

    for(i=0; i<n; i++)
    {
        sum=sum+a[i];
    }

    mini=sum/(4*m);

    for(i=0; i<n; i++)
    {
        if(a[i]>=mini) cnt++;
    }

    if(cnt>=m) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


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

int main() {
    int n;
    cin >> n;
    int a[2][n];
    rep(i, n) cin >> a[0][i];
    rep(i, n) cin >> a[1][i];

    int ans = 0;
    rep(i, n) {
        int now = 0;
        rep(j, n) {
            if (i == j)
                now += a[0][j] + a[1][j];
            else if (i > j)
                now += a[0][j];
            else
                now += a[1][j];
        }
        ans = max(ans, now);
    }

    cout << ans << 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++)
const int INF = 1 << 29;
const int MOD = 1000000007;

int main() {
    long long n;
    cin >> n;
    string ans = "";
    /*
    while (n > 0) {
        // nを26で割ったあまりを求める
        int res = n % 26;
        // あまりが0なら26に変える(zに相当)
        if (res == 0) {
            res = 26;
        }
        // 余りは文字を付け足す
        ans += (char)('a' + res - 1);
        // 余りを引いて26で割る(小数点切り捨て)
        n = (n - res) / 26;
    }
    */
    while (n) {
        n--;
        ans += (char)('a' + (n % 26));
        n /= 26;
    }

    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef long long ll;
const int inf   = 1<<29;
const ll  mod = 1e9+7;

int main(){
  string s;
  cin>>s;
  ll n=s.size();
  vector<ll> v(26);
  rep(i,n){
    int x=s[i]-'a';
    v[x]++;
    }
  ll ans=n*(n-1)/2+1;
  rep(i,26)
    ans-=v[i]*(v[i]-1)/2;
  cout<<ans<<endl;
  return 0;
  }

Measured memory_bytes: 640
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    long n = lread();
    auto w = aryread();
    long diff = w.sum();
    foreach (i; 0 .. n - 1)
    {
        long beforesum;
        long aftersum;
        foreach (j, e; w)
        {
            if(j <= i)
                beforesum += e;

            if(j > i)
                aftersum += e;
        }
        diff = min(abs(aftersum - beforesum), diff);
    }
    diff.writeln();
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <utility>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main()
{
  int n;
  cin >> n;
  cout << n * 800 - 200 * (n/15) << endl;

  return 0;
}


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

pair<int,int> G[20][(1<<20)];
int A[(1<<20)];

int main(){
  int N; cin>>N;
  int NN=(1<<N);
  rep(i,NN){
    cin>>A[i];
    G[0][i].first=A[i];
  }
  for(int i=1;i<=N;i++){
    int nn=1<<(i-1);
    rep(j,NN){
      int ne=nn|j;
      int a=G[i-1][j].first;
      int b=G[i-1][j].second;
      int c=G[i][j].first;
      int d=G[i][j].second;
      int x[4]={a,b,c,d};
      sort(x,x+4);
      G[i][j]={x[3],x[2]};
      if(ne!=j){
        int e=G[i][j+ne].first;
        int f=G[i][j+ne].second;
        int y[4]={a,b,e,f};
        sort(y,y+4);
        G[i][ne]={y[3],y[2]};
      }
    }
  }
  ll ans=0;
  for(int i=1;i<NN;i++){
    ll sum=1LL*G[N][i].first+1LL*G[N][i].second;
    ans=max(ans,sum);
    cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 81920
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 110
typedef long long ll;
 
int N,M;
ll dp[MAX][1<<16],L[MAX];
int bit[MAX];

ll solve(int n,int S){
    if(n == N) return 0LL;
    if(dp[n][S] != -1){
	return dp[n][S];
    }
    ll res = 0LL;
    res = max(res,solve(n+1,S));
    bool ok = true;
    for(int i = 0 ; i < 16 ; i++){
	if((S >> i) & (bit[n] >> i)){
	    ok = false;
	    break;
	}
    }
    if(ok){
	res = max(res,solve(n+1,S|bit[n])+L[n]);
    }
    return dp[n][S] = res;
}
 
int main(){
    int S,E;
    while(cin >> N, N){
	memset(dp,-1,sizeof(dp));
	for(int i = 0 ; i < N ; i++){
	    cin >> M >> L[i]; bit[i] = 0;
	    for(int j = 0 ; j < M ; j++){
		cin >> S >> E;
		S -= 6; E -= 6;
		for(int k = S ; k < E ; k++){
		    bit[i] |= (1<<k);
		}
	    }
	}
	cout << solve(0,0) << endl;
    }
    return 0;
}

Measured memory_bytes: 59296
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;


int main() {
	int n;
	vector<int> p;
	cin >> n;
	p.resize(n);

	rep(i, n) cin >> p[i];
	
	int x = INF;
	int cnt = 0;
	
	rep(i, n) {
		if (p[i] < x) {
			x = p[i];
			cnt++;
		}
	}

	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll= long long;
using ld= long double;
using P =pair<ll,ll>;


//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<=(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define sort(a) sort(ALL(a))//sortの省略
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 10000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define in(T, x) T x;cin >> x;//Tは型,xが入力値
#define vec(T,a,n,x) vector<T> a(n,x);
#define vec2(T,a,n,m) vector<vector<T>> a(n,vector<T>(m));
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define out(x) cout << x << endl//出力
#define bout(b) if(b){out("Yes");}else{out("No");}//真偽問題に対する出力
#define ain(T, a, n) vector<T> a(n);REP(i, n){cin >> a[i];}//配列の宣言と入力
#define a2in(T1, a, T2, b, n) vector<T1> a(n);vector<T2> b(n);REP(i, n){cin >> a[i] >> b[i];}//2つの配列を同時宣言、入力

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }//dp表とかで最大値更新するやつ
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }//最小値更新


signed main(){
  in(ll,N);
  in(ll,Y);
  ll y=Y/1000;
  ll a=-1,b=-1,c=-1;
  REP(i,N){
    REP(j,N-i){
      ll k=N-i-j;
      if(10*i+5*j+k==y){
        a=i,b=j,c=k;
      }
    }
  }
  
  
  out(a<<" "<<b<<" "<<c);

}


Measured memory_bytes: 384
import java.util.*;

public class Main {    
    
  public static void main(String[] args) {              
     Scanner sc = new Scanner(System.in);
     
     int N = sc.nextInt();
     
     int sum = 0;
     int min = Integer.MAX_VALUE;
     
     int count = 0;
     for(int i = 0;i < N;i++){
         int a = sc.nextInt();
         if(a%10 == 0){
               count++;
         }
         sum += a;
         if(a%10 != 0){
           min = Math.min(min,a);
         }
     }
     
     if(count == N){
         System.out.println(0);
         return;
     }     
                           
     if(sum%10 != 0){
         System.out.println(sum);
         return;
     }else{
         System.out.println(sum - min);
         return;
     }
      
  }          
}

Measured memory_bytes: 23892
#include<stdio.h>
#include<stdlib.h>
int main(void){
    int n,t,a;
    scanf("%d%d%d",&n,&t,&a);
    int tmp[n],i,min=1919810,ans=0;
    for(i=0;i<n;i++){
        scanf("%d",&tmp[i]);
        tmp[i]=abs(a*1000-(t*1000-(tmp[i]*6)));
        if(min>tmp[i]){min=tmp[i];ans=i;}
    }
    printf("%d\n",ans+1);
    return 0;    
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#define INF (long)1e9
const int MOD = 1e9 + 7;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
using namespace std;
typedef long long ll;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, x, cnt = 0;
	cin >> n;
	ll min_ans = 0, max_ans = 0;
	vector<ll> vec(8, 0);
	for(ll i = 0; i < n; i++)
	{
		cin >> x;
		ll tmp = x / 400;
		if(tmp <= 7)
			vec[tmp]++;
		else
			cnt++;
	}
	bool flag = true;
	for(ll i = 0; i < vec.size(); i++)
	{
		if(vec[i] > 0) min_ans++;
	}
	if(min_ans == 0) min_ans = 1;
	for(int i = 0; i < vec.size(); i++)
	{
		if(cnt > 0)
		{
			if(vec[i] == 0)
			{
				vec[i]++;
				cnt--;
			}
		}
	}
	for(ll i = 0; i < vec.size(); i++)
	{
		if(vec[i] > 0) max_ans++;
	}
	cout << min_ans << " " << max_ans + cnt << endl;
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
    int n;
    cin >> n;
    int anscnt = 0;
    for (int i = 105; i <= n; i += 2) {
        int cnt = 1; //i % 1 == 0
        for (int j = 2; j <= i; ++j) {
            if (i % j == 0) {
                cnt++;
            }
        }
        if (cnt == 8) {
            anscnt++;
        }
    }
    cout << anscnt << 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, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    double a, b, x;
    cin >> a >> b >> x;
    double s = x / a;
    double rad;
    if (s >= a*b/2){
        double h = 2.0 * (a*b - s) / a;
        rad = atan2(h, a);
    }else{
        double w = 2.0 * s / b;
        rad = atan2(b, w);
    }
    double deg = rad * (180.0 / acos(-1));
    printf("%.7f\n", deg);
}

Measured memory_bytes: 384
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll N, h[101], i, i2, min=200, ans=0, judge=1;

    cin >> N;

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

    while(judge==1){
        for(i=1; i<=N; i++){
            if(h[i]>0){
                while(h[i]>0){
                    h[i]--;
                    i++;
                }
                ans++;
            }
        }

        judge = 0;
        for(i=1; i<=N; i++){
            if(h[i]>0){
                judge = 1;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();

		// 計算
		int cnt = 0;
		for(int i = 2; i <= 55555; i++){
		    if(i%5 != 1) continue;
		    boolean flg = true;
		    for(int j = 2; j <= sqrt(i); j++){
		        //System.out.println("i:" + i + " j:" + j);
		        if(i%j == 0){
		            flg = false;
		            break;
		        }
		    }
		    if(flg){
		        System.out.print(i + " ");
		        cnt++;
		        if(cnt == n) break;
		    }
		}

		// 出力
		//System.out.println("cnt:" + cnt);
	}
}


Measured memory_bytes: 22996
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

void OutputError(std::string s) {
  cerr << "\033[93m" << s << "\033[m" << endl;
  return;
}

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::string x;
  int64_t result = 0;
  cin >> x;
  std::stack<char> stk;
  // OutputError("hogee");
  for (auto c : x) {
    // OutputError("hogee");
    if (c == 'S') {
      // OutputError("push s");
      stk.push('S');
    } else {
      if (stk.size() > 0 && stk.top() == 'S') {
        // OutputError("Pop");
        stk.pop();
      } else {
        // OutputError("push T");
        stk.push('T');
      }
    }
  }
  cout << stk.size() << endl;

  return 0;
}


Measured memory_bytes: 832
## coding: UTF-8


H,W,K = map(int,input().split())
x1, y1, x2, y2 = map(int,input().split())
x1-=1
y1-=1
x2-=1
y2-=1
#1-index to 0-index


c = []
for i in range(H):
    c.append(input())

fresh = [True] * (H*W)
count = [-1] * (H*W)

queue = [x1*W+y1] #now <- start
count[x1*W+y1] = 0 #start -> step = 0
fresh[x1*W+y1] = False
n = [] #next
for i in range(H):
    for j in range(W):
        if(c[i][j] == '@'):
            fresh[i*W+j] = False

#print(fresh)
#print(count)
#print(queue)

step = 1
status = True
while status:
    if(len(queue) > 0):
        pivot = queue.pop()
        #右へ移動
        #if(pivot%W != W-1):#and fresh[pivot+1]):
        for g in range(1, K+1):
            if((pivot+g)%W != 0 and fresh[pivot+g]):
                n.append(pivot+g)
                count[pivot+g] = step
                #fresh[pivot+g] = False false後回し
            else:
                break
        #左へ移動
        #if(pivot%W != 0): #and fresh[pivot-1]):
        for g in range(1, K+1):
            if((pivot-g)%W != W-1 and fresh[pivot-g]):
                n.append(pivot-g)
                count[pivot-g] = step
                #fresh[pivot-g] = False false後回し 
            else:
                break   
        #下へ移動
        #if( int(pivot/W)<(H-1) and fresh[pivot+W]):
        for g in range(1, K+1):
            if( (pivot+g*W)//W < H and fresh[pivot+g*W]):
                n.append(pivot+g*W)
                count[pivot+g*W] = step
                #fresh[pivot+g * W] = False false後回し
            else:
                break    
        #上へ移動
        #if( int(pivot/W)>0 and fresh[pivot-W] ):
        for g in range(1, K+1):
            if( (pivot-g*W)>= 0 and fresh[pivot-g*W] ):
                n.append(pivot-g*W)
                count[pivot-g*W] = step
                #fresh[pivot-g*W] = False
            else:
                break
    elif(len(n)>0): 
        n = sorted(n)
        last = -1
        l = []
        for i in range(len(n)):
            if last != n[i]:
                l.append(n[i])
                last = n[i]
        for e in l:
            fresh[e] = False
        queue = l
        n = []
        #print('step{}end, queue:{}, n:{}, fresh:{}, count:{}'.format(step, queue, n, fresh, count))
        step += 1
    else:
        status = False            


print(count[x2*W+y2])

Measured memory_bytes: 39220
<?php
  $n = trim(fgets(STDIN)); 
  $i = trim(fgets(STDIN)); 
 
	$i = explode(" ", $i);
	rsort($i);

	$bob = 0;
	$alice = 0;
	foreach($i as $b => $a){
      $a . "/n";
      if($b % 2) {
      	$bob = $bob + $a;
      } else {
        $alice = $alice + $a;
	  }
    }
	echo $alice - $bob;


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a.at(i);
    }
    
    reverse(a.begin(),a.end());
    for (int i = 0; i < n; i++)
    {
        cout << a.at(i);
        if(i == n-1) cout << endl;
        else cout << " ";
    }
    
}


Measured memory_bytes: 3092
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  long n; readV(n);

  auto m = int.max;
  foreach (i; 1..n.nsqrt+1)
    if (n%i == 0) {
      auto f = max(i.to!string.length, (n/i).to!string.length).to!int;
      m = min(m, f);
    }

  writeln(m);
}

pure T nsqrt(T)(T n)
{
  import std.algorithm, std.conv, std.range, core.bitop;
  if (n <= 1) return n;
  T m = T(1) << (n.bsr/2+1);
  return iota(1, m).map!"a * a".assumeSorted!"a <= b".lowerBound(n).length.to!T;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

template<typename T>
class BIT{
public:
    vector<T> bit;
    int size;
    BIT(int size):
        bit(vector<T>(size+1,0)),size(size){}
    
    T sum(int i){
        if(!i) return 0;
        return bit[i]+sum(i-(i&(-i)));
    }

    void add(int i,T x){
        if(i>size)return;
        bit[i]+=x;
        add(i+(i&(-i)),x); 
    }   
};

ll inversion(const vector<ll> &v){
    int N = v.size();
    vector<ll> w(N);
    REP(i,N) w[i]=v[i];
    sort(all(w));
    w.erase(unique(all(w)),w.end());
    vector<ll> v2(N);
    REP(i,N) {
        v2[i] = lower_bound(all(w),v[i]) - w.begin();
    }
    BIT<ll> bit(w.size()+1);
    ll res = 0;
    REP(i,N) {
        res += bit.sum(v2[i]+1);
        bit.add(v2[i]+1,1);
    }
    return res;
}

bool check(ll K, const vector<ll> &v){
    ll N = v.size();
    vector<ll> w(N+1,0);
    REP(i,N) w[i+1] = (v[i]>=K ? 1:-1);
    REP(i,N) w[i+1] += w[i];
    return 2*inversion(w) >= N*(N+1)/2;
}

int main(){
    int N; cin >> N;
    vector<ll> a(N);
    REP(i,N) cin >> a[i];  
    //cout << inversion(a) << endl;
    ll ub = 1000000001;
    ll lb = 1;
    ll mid;
    while(ub-lb>1){
        mid = (ub+lb)/2;
        if(check(mid,a)) lb = mid;
        else ub = mid;
    }
    cout << lb << endl;
    return 0;
}

Measured memory_bytes: 4208
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    string s;
    cin>>s;
    bool bad=false;
    if(s[0]==s[1]||s[1]==s[2]||s[2]==s[3])bad=true;
    if(bad)cout<<"Bad"<<endl;
    else cout<<"Good"<<endl;
}


Measured memory_bytes: 256
/*--------------------------"SABUJ-JANA"------"JADAVPUR UNIVERSITY"--------*/
/*-------------------------------@greenindia-----------------------------------*/
//
//		  _____       _           _        _
//		 / ____|     | |         (_)      | |
//		| (___   __ _| |__  _   _ _       | | __ _ _ __   __ _
//		 \___ \ / _` | '_ \| | | | |  _   | |/ _` | '_ \ / _` |
//		 ____) | (_| | |_) | |_| | | | |__| | (_| | | | | (_| |
//		|_____/ \__,_|_.__/ \__,_| |  \____/ \__,_|_| |_|\__,_|
//		                        _/ |
//		                       |__/
/*---------------------- Magic. Do not touch.-----------------------------*/
/*------------------------------God is Great/\---------------------------------*/
#include <bits/stdc++.h>
using namespace std;
#define crap ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
//cout<<fixed<<showpoint<<setprecision(12)<<ans<<endl;
#define int long long int
#define double long double
#define PI acos(-1)

void print1d(const vector<int>& vec) {for (auto val : vec) {cout << val << " ";} cout << endl;}

void print2d(const vector<vector<int>>& vec) {for (auto row : vec) {for (auto val : row) {cout << val << " ";} cout << endl;}}

int power(int a, int b, int MOD) {
	a = a % MOD;
	int res = 1;
	while (b) {
		if (b & 1)
			res = (res * a) % MOD;
		a = (a * a) % MOD;
		b /= 2;
	}

	return res;
}

signed main() {
 

	int n, p;
	cin >> n >> p;

	string str;
	cin >> str;

	int ans = 0;
	if (p == 2 or p == 5) {
		for (int i = 0; i < n; i++) {
			if ((str[i] - '0') % p == 0) {
				ans += (i + 1);
			}
		}

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

	map<int,int> mp;
	mp[0] = 1;

	int cur = 0;
	for(int i = 0; i < n; i++){
		cur = cur* 10 + (str[i] - '0');
		cur = cur % p;

		int val = (power(10, n-1-i, p));
		val = val * cur;
		val = val % p;

		mp[val]++;
	}

	for(int i = 0; i < p; i++){
		ans += (mp[i] * (mp[i] - 1))/ 2;
	}

	cout << ans << endl;



	return 0;
}






Measured memory_bytes: 1028
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        for (;;) {
            int ｆｙ = sc.nextInt(), ｆｍ = sc.nextInt(), ｆｄ = sc.nextInt();
            int ｔｙ = sc.nextInt(), ｔｍ = sc.nextInt(), ｔｏ = sc.nextInt();
            if (ｆｙ == -1)
                break;
            System.out.println(Duration.between(LocalDateTime.of(ｆｙ, ｆｍ, ｆｄ,0,0), LocalDateTime.of(ｔｙ, ｔｍ, ｔｏ,0,0)).toDays());
        }
    }
}



Measured memory_bytes: 32528