akhauriyash/Code-Regression huggingface dataset:
/* binary_indexed_tree.cpp
    BIT を用いて、区間和の更新や計算を高速に行う。

    応用: 転倒数の計算( i<j において a_i > a_j となる数を数える)
        j(0~n-1)について以下を繰り返す
            1. j-sum(j)を答えに加える
            2. add(a[j],1)
        sum(j)は i<j における a_i<= a_j となる数なので、 j-sum(j) で j を固定したときの転倒数が求まる

    参考：http://hos.ac/slides/20140319_bit.pdf
    verified: AOJ DSL_2_B
        http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_B&lang=jp
*/

#include <bits/stdc++.h>
using namespace std;

/* BIT: 区間和の更新や計算を行う構造体
    初期値は a_1 = a_2 = ... = a_n = 0
    ・add(i,a): a_i += a とする
    ・sum(i): a_1 + a_2 + ... + a_i を計算する
    ・query(l,r): [l,r) の区間の和を求める
    計算量は全て O(logn)
*/
template <typename T>
struct BIT {
    int n;          // 要素数
    vector<T> bit;  // データの格納先
    BIT(int n_) : n(n_ + 1), bit(n, 0) {}

    void add(int i, T x) {
        if (i == 0) {
            return;
        } else {
            for (int idx = i; idx <= n; idx += (idx & -idx)) {
                bit[idx] += x;
            }
        }
    }

    T sum(int i) {
        T s(0);
        for (int idx = i; idx > 0; idx -= (idx & -idx)) {
            s += bit[idx];
        }
        return s;
    }

    // [l,r)
    T query(int l, int r) { return sum(r - 1) - sum(l - 1); }
};

int main() {
    int n, q;
    cin >> n >> q;
    BIT<int> bit(2e5);
    vector<int> c(q), x(q), y(q);
    for (int i = 0; i < q; i++) {
        cin >> c.at(i) >> x.at(i) >> y.at(i);
    }

    for (int i = 0; i < q; i++) {
        if (c[i] == 0) {
            bit.add(x[i], y[i]);
        } else if (c[i] == 1) {
            cout << bit.query(x[i], y[i] + 1) << endl;
        }
    }

    return 0;
}



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

#define ll long long

string s;

void solve(){
    cin>>s;
    if(s=="SUN")cout<<7<<endl;
    if(s=="MON")cout<<6<<endl;
    if(s=="TUE")cout<<5<<endl;
    if(s=="WED")cout<<4<<endl;
    if(s=="THU")cout<<3<<endl;
    if(s=="FRI")cout<<2<<endl;
    if(s=="SAT")cout<<1<<endl;
}

signed main(){
    //while(1)
    solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<ll,pll> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n,m,q;
vi a;

int main(){
	cin>>n>>m>>q;
	a=vi(n);
	for(int i=0;i<q;i++){
		int x;
		cin>>x;
		a[x-1]++;
	}
	for(int i=0;i<n;i++) cout<<(a[i]>q-m?"Yes":"No")<<endl;
}

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

bool all_same(vector<int> v){
    int t = v[0];
    for(int i = 1; i < v.size(); i++){
        if(v[i]-t) return false;
    }
    return true;
}

int main(){
    int n;
    while(cin>>n,n){
        vector<int> v(n);
        for(int i = 0; i < n; i++){
            cin >> v[i];
        }
        int count = 0;
        while( true ){
            vector<int> freq(n, 0);
            for(int i = 0; i < v.size();i++){
                if( freq[i] ) continue;
                int f = 0;
                vector<int> ot;
                for(int j = 0; j < v.size(); j++){
                    if( v[i]==v[j] ){
                        f++;
                        ot.push_back(j);
                    }
                }
                for(int j = 0; j < ot.size(); j++){
                    freq[ ot[j] ] = f;
                }
            }
            if(v == freq) break;
            count++;
            v = freq;
        }
        cout << count << endl;
        cout << v[0];
        for(int i = 1; i < v.size(); i++){
            cout << ' ' << v[i];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1220
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
    if (v.empty())return out;
    constexpr bool is_vector_v = is_vector<T>::value;
    if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
    else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
    return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

int main() {
    IOS;
    ll h,w,s,t;
    cin >> h >> w >> s >> t;
    ll c = h/s,d = w/t;
    ll k = (h-s*c)*w+(w-t*d)*h-(h-s*c)*(w-t*d);
    if(k==0){
        put("No");
        return 0;
    }
    put("Yes");
    ll p,m;
    p = c*d/k+1;
    m = p*(s*t-1)+1;
    ll res = 0;
    REP(i,h){
        REP(j,w){
            if((i+1)%s==0&&(j+1)%t==0){
                cout << -m << " ";
                res += -m;
            }else{
                cout << p << " ";
                res += p;
            }
        }
        put("");
    }
    return 0;
}



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

using namespace std;

int main() {

    int a, b;
    cin >> a >> b;

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

    return 0;

}

Measured memory_bytes: 256
import sys
from math import sqrt, pi
from collections import Counter, defaultdict, deque

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


def I():
    return int(input())


def MI():
    return map(int, input().split())


def LI():
    return list(MI())


def LIN(n: int):
    return [I() for _ in range(n)]


inf = float("inf")
mod = 10 ** 9 + 7


def main():
    r = I()
    print(2 * r * pi)
    pass


if __name__ == "__main__":
    main()


Measured memory_bytes: 65244
#include <stdio.h>
#define Max 10000
#define Min 500

int LinerSearch(int );

int n,S[Max],T[Min];

int main()
{
  int i,q,a,sum=0;

  scanf("%d",&n);

  for(i=0;i<n;i++)
    {
      scanf("%d",&S[i]);
    }

  scanf("%d",&q);

  for(i=0;i<q;i++)
    {
      scanf("%d",&T[i]);
    }

  for(i=0;i<q;i++)
    {
      a = LinerSearch(T[i]);

      if(a == T[i]) sum++;
    }

  printf("%d\n",sum);

  return 0;
}

int LinerSearch(int k)
{
  int i;

  for(i=0;i<n;i++)
    {
      if(S[i] == k) return S[i];
    }

  return S[i];
}
       

Measured memory_bytes: 636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		StringBuilder sb = new StringBuilder();
		for(int i = 0;i < s.length();i++) {
			sb.append("x");
		}
		System.out.println(sb);
	}
}

Measured memory_bytes: 23764
n,k,c = map(int,input().split())
s = [i == "o" for i in list(input())]
i = 0
cnt = 0
l = [0]*n
r = [0]*n
while i < n:
    if s[i]:
        cnt += 1
        for j in range(i,c+i+1):
            if j < n:
                l[j] = cnt
        i += c+1
    else:
        l[i] = cnt
        i += 1
i = n-1
cnt = 0
while i >= 0:
    if s[i]:
        cnt += 1
        for j in range(i,i-1-c,-1):
            if j >= 0:
                r[j] = cnt
        i -= c+1
    else:
        r[i] = cnt
        i -= 1
#print(l,r)
r.append(0)
if r[1] < k:
    print(1)
for i in range(1,n-1):
    if not s[i]:
        continue
    if l[i-1] + r[i+1] < k:
        print(i+1)
if l[n-2] < k:
    print(n)

Measured memory_bytes: 28028
def main():
  n = int(input())
  a = list(map(int, input().split()))
  ans = 'APPROVED'
  for i in a:
    if i%2==0:
      if i%3==0 or i%5==0:
        pass
      else:
        ans = 'DENIED'
    else:
      pass
  print(ans)
if __name__ == '__main__':
  main()

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

int main() {
  int N;
  cin >> N;
  map<int,int> mp;
  for(int i=0;i<N;i++){
    int a;
    cin >> a;
    mp[a]++;
  }
  int sum=0;
  for(auto p:mp){
    int x=p.first;
    int n=p.second;
    if(n<x)sum+=n;
    else sum+=n-x;
  }
  cout << sum;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)
#define rrep(i,j,n) for(ll i = (ll)(j); i < (ll)(n); i++)
#define mrep(i,n) for (ll i = (ll)(n-1); i >= 0; i--)
#define be(v) (v).begin(), (v).end()
#define dcout cout << fixed << setprecision(20) 
ll INF = 1LL << 60;
ll mod = 1e9 + 7;

int main(){
	int a,b,x; cin >> a >> b >> x;
	if(a<=x&&x<=a+b) cout << "YES" << endl;
	else cout << "NO" << endl;
}

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


int main(){
  int n;
  int a[100000][3];
  cin>>n;
  rep(i,n) cin>>a[i][0]>>a[i][1]>>a[i][2];
  int x=0,y=0,dis,prev=0;
  rep(i,n){
    dis=abs(x-a[i][1])+abs(y-a[i][2]);
    //cout<<prev<<" "<<dis<<endl;
    if(a[i][0]-prev < dis){cout<<"No"<<endl;return 0;}
    if((a[i][0]-prev-dis)%2 == 1){cout<<"No"<<endl;return 0;}
    x=a[i][1];y=a[i][2];prev=a[i][0];
  }
  cout<<"Yes"<<endl;
  return 0;
}



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


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		char[] s = sc.next().toCharArray();
		int n = s.length;
		char[] t = sc.next().toCharArray();
		int m = t.length;

		Arrays.sort(s);
		Arrays.sort(t);

		for (int i = 0; i < Math.min(n, m); i++) {
			if (s[i] < t[m - 1 - i]) {
				pr.println("Yes");
				return;
			} else if (s[i] > t[m - 1 - i]) {
				pr.println("No");
				return;
			}
		}

		if (n >= m) {
			pr.println("No");
		} else {
			pr.println("Yes");
		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 23252
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <math.h>
#include <assert.h>

using namespace std;

#define x first
#define y second
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define all(x) x.begin(),x.end()
#define SZ(x) int(x.size())
#define rep(i, a, b) for(int i = a; i < b; i++)
#define per(i, a, b) for(int i = b-1; i >= a; i--)
#define DBG(x) cerr << (#x) << "=" << x << "\n";
#define ll long long
#define inf 1000000007
#define mod 1000000007
#define N 200005

template<typename U, typename V> void Min(U &a, const V & b){if(a > b)a = b;}
template<typename U, typename V> void Max(U &a, const V & b){if(a < b)a = b;}
template<typename U, typename V> void add(U &a, const V & b){a = (a + b) % mod;}
template<typename U> U gcd(U a, U b){
    if(a == 0)return b;
    if(b == 0)return a;
    if(a >= b)return gcd(a % b, b);
    else return gcd(a, b % a);
}
int pow(int a, int b){
    int ans = 1;
    while(b){
        if(b & 1)ans = 1LL * ans * a % mod;
        a = 1LL * a * a % mod;
        b >>= 1;
    }
    return ans;
}
int pow(int a, int b, int c){
    int ans = 1;
    while(b){
        if(b & 1)ans = 1LL * ans * a % c;
        a = 1LL * a * a % c;
        b >>= 1;
    }
    return ans;
}

pii w[10][10];
pair<int, ll> go(int k, ll n){
    if(n == 1){
        return {k, 0};
    }
    auto res = go(k, n/2);
    int K = res.x;
    ll ans = res.y * 2 + w[K][K].y;
    K = w[K][K].x;
    if(n & 1){
        ans += w[K][k].y; 
        K = w[K][k].x;
    }
    return {K, ans};
}
pii cal(int x, int y){
    x += y;
    if(x < 10)return {x, 1};
    auto ans = cal(x%10, x/10);
    ans.y++;
    return ans;
}
int main(){
    int T, i, j, k, ca = 0, K, n, m;
    rep(i, 0, 10)rep(j, 0, 10)w[i][j] = cal(i, j);
    scanf("%d", &n);
    ll x, ans = 0;
    int last = 0;
    rep(i, 0, n){
        scanf("%d%lld", &k, &x);
        auto res = go(k, x);
        ans += res.y;
        auto& u = w[last][res.x];
        ans += u.y;
        last = u.x;
    }
    printf("%lld\n", ans-1);
}


Measured memory_bytes: 256
//https://atcoder.jp/contests/abc159/tasks/abc159_b
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin>>s;
	ll n;
	n=s.length();
	bool palin=false;
	vector <char> revs;
	ll i;
	for(i=n-1;i>=0;i--)
	{
		revs.push_back(s[i]);
	}
	for(i=0;i<n;i++)
	{
		if(s[i]==revs[i])
		{
			palin=true;
		}
		else
		{
			palin=false;
			break;
		}
	}
	bool sml1=false;
	bool sml2=false;
	if(palin==true)
	{
		vector <char> rev1;
		for(i=0;i<(n-1)/2;i++)
		{
			rev1.push_back(s[i]);
		}
		ll x;
		x=rev1.size();
		vector <char> rev11;
		for(i=x-1;i>=0;i--)
		{
			rev11.push_back(s[i]);
		}
		for(i=0;i<x;i++)
		{
			if(rev1[i]==rev11[i])
			{
				sml1=true;
			}
			else
			{
				sml1=false;
				break;
			}
		}
		vector <char> rev2;
		for(i=(n+1)/2;i<n;i++)
		{
			rev2.push_back(s[i]);
		}
		ll y;
		y=rev2.size();
		vector <char> rev22;
		for(i=y-1;i>=0;i--)
		{
			rev22.push_back(s[i]);
		}
		for(i=0;i<y;i++)
		{
			if(rev2[i]==rev22[i])
			{
				sml2=true;
			}
			else
			{
				sml2=false;
				break;
			}
		}
		if((sml1==true)&&(sml2==true))
		{
			cout<<"Yes"<<"\n";
		}
		else
		{
			cout<<"No"<<"\n";
		}
	}
	else
	{
		cout<<"No"<<"\n";
	}
	
	return 0;
}

Measured memory_bytes: 3660
def calc(x, y):
    x2 = x
    y2 = y - 1
    x4 = x - 1
    y4 = y
    x5 = x + 1
    y5 = y
    x7 = x
    y7 = y + 1
    return x2, y2, x4, y4, x5, y5, x7, y7

h, w = map(int, input().split())
s = []
for _ in range(h):
    s.append(list(input()))
ans = "Yes"
for i in range(h * w):
    x = i // h
    y = i % h
    c = 0
    if s[y][x] == "#":
        x2, y2, x4, y4, x5, y5, x7, y7 = calc(x, y)
        aaa = [[x2, y2], [x4, y4], [x5, y5], [x7, y7]]
        for (xx, yy) in aaa:
            if ((xx >= 0) & (xx < w) & (yy >= 0) & (yy < h)):
                if s[yy][xx] == "#":
                    c += 1
        if c == 0:
            ans = "No"
            break
print(ans)

Measured memory_bytes: 3064
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    n: usize,
    a: [i64; n],
  }
  let mut xor = a.iter().fold(0, |acc, x| acc ^ x);
  let mut trail: Vec<_> = a.iter().map(|x| x.trailing_zeros()).collect();
  trail.sort();
  let mut ans = 0;
  for &t in trail.iter().rev() {
    if (xor >> t) & 1 == 1 {
      ans += 1;
      xor ^= (1 << t + 1) - 1;
    }
  }
  if xor == 0 {
    puts!("{}\n", ans);
  } else {
    puts!("-1\n");
  }
}


Measured memory_bytes: 8444
#include "bits/stdc++.h"
using namespace std;

int main() {
	string S;
	while (getline(cin, S)) {
		if (S == ".") return 0;
		string T;
		for (int i = 0; i < S.size(); i++) {
			if (S[i] == '(' || S[i] == '[' || S[i] == ')' || S[i] == ']') T = T + S[i];
		}
		stack<char> Q;
		bool check = true;
		for (int i = 0; i < T.size(); i++) {
			if (T[i] == '(' || T[i] == '[') Q.push(T[i]);
			if (T[i] == ')') {
				if (Q.empty()) check = false;
				else {
					if (Q.top() != '(') check = false;
					Q.pop();
				}
			}
			if (T[i] == ']') {
				if (Q.empty()) check = false;
				else {
					if (Q.top() != '[') check = false;
					Q.pop();
				}
			}
		}
		if (!Q.empty()) check = false;
		cout << (check ? "yes" : "no") << endl;
	}
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
#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 SORT(v) sort(v.begin(), v.end())
#define REVERSE(v)  reverse(v.begin(), v.end())
typedef long long ll;
using namespace std;

int main() {
  string S; cin>>S;
  ll K; cin>>K;
  string ans;
  int i;
  for(i=0; i<S.size(); i++) {
    if(S.at(i) == '1')
      ans = '1';
    else {
    ans = S.at(i);
    break;
    }
  }  
  if(K < i+1) cout<<S.at(K-1)<<endl;
  else cout<<ans<<endl;
}

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

int main() {
  int n,q; cin >>n >>q;
  string s; cin >>s;
  bool a = false;
  vector<int> cnts(n);
  int cnt = 0;
  for (int i=0; i<n; i++){
    if (s.at(i)=='A') a = true;
    else if (s.at(i)=='C'){
      if (a){ cnt++; a = false;}
    }else a = false;
    cnts.at(i) = cnt;
  }
  // i文字目までにACが何回出たかを記録する配列cnts
  
  for (int i=0; i<q; i++){
    int ans = 0;
    int l,r; cin >>l >>r;
    ans = cnts.at(r-1)-cnts.at(l-1);
    cout <<ans <<endl;
  }
  //cout <<ans;
  //cout <<endl;
}

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

using namespace std;
int main()
{
    int N;
    while ( !cin.eof() )
    {
        cin >> N;
        vector<int> ans;
        
        for (int a = 0; a < 10; a++)
        {   
            if (N % 2 == 1)
            {
                N = (N - 1) / 2;
                ans.push_back( pow(2,a) );
            }
            else
                N = N / 2;
        }
        
        for (int i = 0; i < ans.size(); i++)
        {
            cout << ans[i] ;
            if (i == ans.size()-1)
                cout << endl;
            else
                cout << " ";
        }
    }
}

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

using namespace std;

inline char getFirstChar(char* string) {
	return string[0];
}
inline char getLastChar(char* string) {
	int c = strlen(string);
	if (c <= 0) { return '\0'; }
	return string[c-1];
}

int main() {
	bool flag = true;
	int N;
	char last = '\0';
	cin >> N;

	char **str = new char*[N];

	for (int i = 0; i < N; i++) {
		str[i] = new char[256];
		scanf("%s", str[i]);

		if (!flag) continue;

		for (int j = 0; j < i; j++) {//かぶりチェック
			if (strcmp(str[i], str[j]) == 0) {
				flag = false;
				break;
			}
		}
		if (i!=0 && getFirstChar(str[i]) != last) {
			flag = false;
		}
		last = getLastChar(str[i]);
	}

	cout << ((flag) ? "Yes" : "No");

	for (int i = 0; i < N; i++) {
		delete[] str[i];
	}
	delete[] str;

	return 0;
}

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

ll pow(ll n){
    if(n == 1) return 1;
    else return n*pow(n-1)%1000000007;
}

int main(){
    ll n,m;
    cin >> n >> m;
    if(abs(n-m)>1){
        cout << "0" << endl;
        return 0;
    }
    if(n==m)cout << 2*pow(n)*pow(m)%1000000007 << endl;
    else cout << pow(n)*pow(m)%1000000007 << endl;

}

Measured memory_bytes: 1792
#include<stdio.h>

int main(){
  int length; //長さ
  int A[100]; //配列
  int i=0,j=0; //ループ
  int flag=0; //交換回数
  int key; // 回避変数
  int min; //最小値

  scanf("%d",&length); //長さ入力
  
  while(i < length){ //数の入力
    scanf("%d",&A[i]);
    i++;
  }
  
  for(i = 0;i <= length-1;i++){ //selectionSort(A, N)
    min = i;
    for(j = i;j <= length-1;j++){
      if(A[j] < A[min]){
	min = j;
      }
    }
    if(min!=i)flag++;//交換回数

    key = A[i];//交換
    A[i] = A[min];
    A[min] = key;
  }

  for(i = 0;i < length-1;i++){   //表示
    printf("%d ",A[i]);
  }
  printf("%d\n",A[i]);
  printf("%d\n",flag);
  return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int N = sc.nextInt();
		int a[] = new int [N];
		int nowX= 0,nowY= 0;
		for (int i=0;i<N;i++) {
			a[i] = sc.nextInt();
		}
		int result[][] = new int[H][W];
		for (int i=0;i<N;i++) {
			for(int j=0;j<a[i];j++) {
				result[nowY][nowX] = i+1;
				if (nowY%2==0) {
					nowX++;
					if (nowX==W) {
						nowX--;
						nowY+=1;
					}
				} else {
					nowX--;
					if (nowX<0) {
						nowY+=1;
						nowX=0;
					}
				}
			}
		}
		for (int i=0;i<H;i++) {
			for (int j=0;j<W;j++) {
				System.out.print(result[i][j]+ " ");
			}
			System.out.println();
		}
	}

}

Measured memory_bytes: 33008
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

h, w = map(int, readline().split())
for i in range(h):
    c = readline().rstrip().decode()
    print(c + '\n' + c)


Measured memory_bytes: 3064
# include <bits/stdc++.h>
# define ll long long int
# define ld long double
# define pb push_back
# define mp make_pair
# define mod 1000000007
# define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#else
// online submission
	#endif
	IOS
	int ans = 0;
  	string s;
  	cin >> s;
  	for(int i = 0; i < 3; i++){
    	if(s[i] == 'R'){
    		int curr = 1;
      		int j = i+1;
      		while(j < 3 && s[j] == 'R'){
        		curr++;
          		j++;
        	}
         	ans = max(ans, curr);
    	}
  }
  cout << ans;
	return 0;
}

Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int main(){
	int W,H,x,y,r;
	cin>>W>>H>>x>>y>>r;
	if(x-r<0||x+r>W||y-r<0||y+r>H){
	cout<<"No"<<endl;
	}
	else if(x-r>=0&&x+r<=W&&y-r>=0&&y+r<=W){
	cout<<"Yes"<<endl;
	}
	

return 0;}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define CFS           \
    cin.tie(nullptr); \
    ios::sync_with_stdio(false);
#define CST(x) cout << fixed << setprecision(x);
using namespace std;
constexpr int IINF = numeric_limits<int>::max();
constexpr long LINF = numeric_limits<long>::max();
constexpr int MOD = (int)1e9 + 7;
// constexpr int MOD = 998244353;

int main()
{
    int k, a, b;
    cin >> k >> a >> b;
    for (int i = a; i <= b; i++) {
        if (i % k == 0) {
            cout << "OK" << "\n";
            return 0;
        }
    }
    cout << "NG" << "\n";
}

Measured memory_bytes: 3624
// cout << "Case #" << test << ": ";
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 2019
using namespace std;
ll modpow(ll a, ll n, ll mod = MOD) {
    ll res = 1;
    while(n > 0) {
        if(n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main() {
    string s;
    cin >> s;
    reverse(all(s));
    int n = s.size();
    vector<ll> a(n, 0), rui(n + 1, 0);
    for(int i = 0; i < n; i++) {
        a[i] = s[i] - '0';
    }
    map<ll, ll> mp;
    mp[rui[0]]++;
    for(int i = 0; i < n; i++) {
        rui[i + 1] = rui[i] + a[i] * modpow(10, i);
        rui[i + 1] %= MOD;
        mp[rui[i + 1]]++;
    }
    ll ans = 0;
    for(auto e : mp) {
        ans += e.second * (e.second - 1) / 2;
    }
    cout << ans << endl;
}


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

int main(int argc, char const *argv[])
{
    int a, b, k;
    cin >> k;
    cin >> a >> b;
    int s = k;
    while (true)
    {
        if (s > b)
        {
            cout << "NG" << endl;
            break;
        }
        if (s >= a && s <= b)
        {
            cout << "OK" << endl;
            break;
        }
        s += k;
    }
    return 0;
}


Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
using namespace std;
int main() {
   string s;
   cin >> s;
   if(s == "SUN"){
      cout << 7 << endl;
   }else if(s == "MON"){
      cout << 6 << endl;
   }else if(s == "TUE"){
      cout << 5 << endl;
   }else if(s == "WED"){
      cout << 4 << endl;
   }else if(s == "THU"){
      cout << 3 << endl;
   }else if(s == "FRI"){
      cout << 2 << endl;
   }else{
      cout << 1 << endl;
   }
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

map<int,int> divisor(int n){
  map<int,int> ret;
  for(int i=1; i*i<=n; i++){
    if(n%i==0){
      ret[i] = 1;
      if(i!=n/i) ret[n/i] = 1;
    }
  }
  return ret;
}

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

  int ret = 0;
  REP(i,1,N+1){
    if(i%2==1 && divisor(i).size() == 8) ret++;
  }

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


Measured memory_bytes: 256
x,y=map(int,input().split(" "))
if x==1:
    a=300000
if x==2:
    a=200000
if x==3:
    a=100000
if y==1:
    b=300000
if y==2:
    b=200000
if y==3:
    b=100000
if x>3:
    a=0
if y>3:
    b=0
if x==1 and y==1:
    print(a+b+400000)
else:
    print(a+b)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define For(i,j,k)	for(int i=j;i<=k;++i)
#define Dow(i,j,k)	for(int i=k;i>=j;--i)
#define ll long long
#define inf 1e8
using namespace std;
inline ll read()
{
	ll t=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')	c=getchar();}
	while(c>='0'&&c<='9')	t=t*10+c-48,c=getchar();
	return t*f;
}
int n,a[200001],mx1,mx2;
int main()
{
	n=read();
	For(i,1,n)	a[i]=read();
	sort(a+1,a+n+1);
	Dow(i,1,n)	if(a[i]==a[i-1])	{mx1=i;break;}
	Dow(i,1,mx1-2)if(a[i]==a[i-1])	{mx2=i;break;}
	printf("%lld",(ll)a[mx1]*a[mx2]);
}

Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <climits>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N, K;
typedef pair<ll, int> P;
vector<P> A;
priority_queue<ll, vector<ll>, greater<ll> > que;
priority_queue<ll> rest;
ll ans;

void init() {
  unordered_map<int, int> U;
  rep(i, N) {
    if (U[A[i].second]==0) {
      U[A[i].second]++;
      if (que.size()<K) {
        ans+=A[i].first;
        que.push(A[i].first);
      } else rest.push(A[i].first);
    } else {
      rest.push(A[i].first);
    }
  }
}

int main() {
  INCANT;
  cin >> N >> K;
  int t;ll d; 
  rep(i, N) {
    cin >> t >> d;
    A.push_back(P(d,t));
  }
  sort(ALL(A), greater<P>());
  init();
  ll x = que.size();
  ans+=x*x;
  while(que.size()<K) {
    ll t = rest.top(); rest.pop();
    ans+=t;
    que.push(t);
  }
  ll prev =ans;
  for (ll i=x-1; i>=1; i--) {
    ll tmp = prev;
    ll r =rest.top(); rest.pop();
    ll q= que.top(); que.pop();
    que.push(r);
    tmp+=r-q;
    tmp+=pow(i,2)-pow(i+1,2);
    ans = max(ans, tmp);
    prev = tmp;
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 6768
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define inf 998244353
#define LINF 1000000000000000007LL
#define ll long long
using namespace std;
int ka[214514],inv[214514];
void setkaijo(int n){
	ka[0]=1;
	for(int i=1;i<=n;i++){
		ka[i] = ka[i-1] * i;
		ka[i] %= inf;
	}
}
int modpow(int x,int k){
	// x ^ k mod inf
	int p2[55],res=1;
	p2[0]=1;p2[1]=x%inf;
	for(int i=2;i<=50;i++){
		p2[i]=p2[i-1]*p2[i-1];
		p2[i] %= inf;
	}
	for(int i=1;i<=50;i++){
		if(k%2==1){
			res *= p2[i];
			res %= inf;
		}
		k /= 2;
	}
	return res;
}
void setinv(int n){
	for(int i=0;i<=n;i++){
		inv[i] = modpow(ka[i],(ll)inf-2);
	}
}
int comb(int n,int k){
	if( k<0 || n<0 || k>n)return 0;
	if(k==0 || k==n)return 1;
	int res = (ka[n] * inv[k]) % inf;
	res = (res*inv[n-k]) % inf;
	return res;
}
int cnt[114514];
signed main(){
	int n;
	cin>>n;
	setkaijo(114514);
	string s;
	cin>>s;
	vector<int> num;
	int r=0,g=0,b=0;
	for(int i=0;i<s.size();i++){
		if( s[i] == 'R'){
			r++;
			cnt[r]++;
			num.pb(cnt[r]);
		}
		if( s[i] == 'G'){
			g++;
			cnt[g]++;
			num.pb(cnt[g]);
		}
		if( s[i] == 'B'){
			b++;
			cnt[b]++;
			num.pb(cnt[b]);
		}
	}
	int c1=0,c2=0,ans = 1;
	for(int i=0;i<num.size();i++){
		if( num[i] == 1){
			c1++;
		}
		else if( num[i] == 2){
			ans *= c1;
			ans %= inf;
			c1--;
			c2++;
		}
		else{
			ans *= c2;
			ans %= inf;
			c2--;
		}
	}
	ans *= ka[n];
	ans %= inf;
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;
ll dp[4444][2222];

int main(){

	ll n,m,k;cin >> n >> m >> k;
	ll ans = 0;

	dp[0][0] = 1;

	REP(i,(n+m)/(k-1)){
		REP(j,m+1)if(dp[i][j]){
			REP(ii,k)if(j + ii <= m){
				dp[i+1][j+ii] += dp[i][j];
				dp[i+1][j+ii] %= MOD;
			}
			for(int ii = 1;ii < k;ii++){
				if(j + ii > m)continue;
				if(i * (k - 1) + k - j - ii > n)continue;
				if((m - j - ii) % (k - 1) != 0)continue;
				if((n - (i * (k - 1) + k - j - ii)) % (k - 1) != 0)continue;
				ans += dp[i][j];
				ans %= MOD;
			}
		}
	}

	cout << ans << endl;

	return 0;
}


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

#define int long long
#define sq(x) (x)*(x)
#define vec vector
using namespace std;

signed main(){
    int n;
    cin >> n;
    vec < int > q(n);
    for(auto &i: q) cin >> i;
    int otv = 1e18;
    for(int ans = 0; ans <= 1000; ++ans){
        int to = 0;
        for(int i = 0; i < n; ++i)
            to += sq(ans-q[i]);
        otv = min(otv, to);
    }
    cout << otv;
	return 0;
}


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

tbl = [[0] * 9 for i in range(9)]

for i in range(1, n + 1):
    if i % 10 != 0:
        tbl[int(str(i)[0]) - 1][int(str(i)[-1]) - 1] += 1

ans = 0
for i in range(9):
    for j in range(9):
        ans += tbl[i][j] * tbl[j][i]

print(ans)

Measured memory_bytes: 3064
n,m,l=map(int,input().split())
A=[list(map(int,input().split())) for i in range(n)]
B=[list(map(int,input().split())) for i in range(m)]
#print(A)
#print(B)

for i in range(n):
  for j in range(l):
    youso=0
    for k in range(m):
      youso+=A[i][k]*B[k][j]
    if j==0:
      print(youso,end="")
    else:
      print("",youso,end="")
  print("")


Measured memory_bytes: 6564
#include <bits/stdc++.h>
#include <cstring>
#include <iostream>
#include <algorithm>
#define foror(i,a,b) for(i=a;i<b;i++)
#define foror2(i,a,b) for(i=a;i>b;i--)
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define MOD 1000000000
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
using ll = long long;
using namespace std;
int main()
{
 //freopen("in.txt", "r", stdin);
 //freopen("out.txt", "w", stdout);
 int x,y;
 scanf("%d%d",&x,&y);
 if(x==2||y==2||x==12)
 {
  cout << "No"<<endl;
  return 0;
 }
 if(x==1||x==3||x==5||x==7||x==8||x==10)
 {
  if(y==3||y==5||y==7||y==8||y==10||y==12)
  cout <<"Yes"<<endl;
  else
  cout <<"No"<<endl;
  return 0;
 }
 if(x==4||x==6||x==9||x==11)
 {
  if(y==6||y==9||y==11)
  cout <<"Yes"<<endl;
  else
  cout<<"No"<<endl;
  return 0;
 }
 //fclose(stdin);
 //fclose(stdout);
 }


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define fi first
#define se second
#define pb push_back
 
#define limit (int) (1000)
#define mod (int) 1000000007

using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
using ld = long double;

vector<int> vr,vc;

int nr[6] = {0},nc[6] = {0},nb=0;
char c[6][6];

void setR(int bm)
{
    vr.clear();

    for (int i = 0; i < 6; ++i)
    {
        if (bm%2 == 1)
            vr.pb(i);        

        bm /= 2;
    }

    return;
}

int findAns(int bm)
{
    vc.clear();

    for (int i = 0; i < 6; ++i)
    {
        if (bm%2 == 1)
            vc.pb(i);

        bm /= 2;
    }

    int ans = 0;

    for (auto e:vr)
    {
        ans += nr[e];
    }

    for (auto e:vc)
    {
        ans += nc[e];
    }

    for (auto i:vr)
    {
        for (auto j:vc)
        {
            if (c[i][j] == '#')
            {
                ans--;
            }
        }
    }

    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);

    int h,w,k;
    cin >> h >> w >> k;
    
    int lr = 1<<h,lc = 1<<w;

    for (int i = 0; i < h; ++i)
    {
        for (int j = 0; j < w; ++j)
        {
            cin >> c[i][j];

            if (c[i][j] == '#')
            {
                nr[i]++;nc[j]++;nb++;
            }
        }
    }

    int temp;
    int ans = 0;
    for (int i = 0; i < lr; ++i)
    {
        setR(i);

        for (int j = 0; j < lc; ++j)
        {
            temp = findAns(j);

            if (nb-temp == k)
            {
                ans++;
            }
        }
    }

    cout << ans;
    return 0;
}












Measured memory_bytes: 3628
#[allow(unused_imports)]
use std::cmp;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    #[allow(unused_mut)]
    let mut s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  input! {
    n: usize,
    ls: [i32; n]
  }
  let mut ls = ls;
  ls.sort();
  let sum: i32 = ls.iter().sum();
  let sum = sum - ls[n-1];
  println!("{}", if ls[n-1] < sum {"Yes"} else {"No"});
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long
#define MAX 500005
using namespace std;

int n, m, a[MAX], s;

int main()
{
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        scanf("%d", &a[i]);
        s += a[i];
    }
    sort(a+1, a+n+1, greater<int>());
    if(a[m]*4*m < s){
        puts("No");
    }
    else puts("Yes");

    return 0;
}


Measured memory_bytes: 256
class Tree
  AND, OR, XOR = (0..2).to_a
  ALL = "1111".to_i(2)

  def initialize(exp, sweet)
    @size = 0
    @root = parse(exp, sweet)
  end

  class Node
    attr_accessor :left, :right, :value
  end

  def parse(exp, sweet)
    node = Node.new
    case exp.chr
      when "("
        @size += 1
        exp.slice!(0) # "("
        node.left = parse(exp, sweet)
        exp.slice!(0) # " "
        node.right = parse(exp, sweet)
        exp.slice!(0) # ")"
      else
        node.value = sweet[exp.slice!(0).to_i - 1]
    end
    node
  end

  def solve(depth = 0, operator = Array.new)
    return (calculate(operator.dup) == ALL ? 1 : 0) if(depth == @size)
    [AND, OR, XOR].map{|op|
      operator[depth] = op
      solve(depth + 1, operator)
    }.inject(&:+)
  end

  def calculate(operator, node = @root)
    return node.value if node.value
    case operator.shift
      when AND
        calculate(operator, node.left) & calculate(operator, node.right)
      when OR
        calculate(operator, node.left) | calculate(operator, node.right)
      when XOR
        calculate(operator, node.left) ^ calculate(operator, node.right)
    end
  end
end

until (exp = gets.chomp) == "END"
  p Tree.new(exp, gets.to_i.times.map{gets.delete(" ").to_i(2)}).solve
end

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

int main(){
  string s,t;
  cin >> s >> t;
  int ans = 0;
  rep(i,int(s.size())-int(t.size())+1){
    int tmp = 0;
    rep(j,int(t.size())){
      if(t[j]==s[i+j]){
        tmp++;
      }
    }
    if(tmp>ans)ans = tmp;
  }
  cout << int(t.size())-ans << endl;
  return 0;
}

Measured memory_bytes: 3612
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <memory.h>
#include <vector>

using namespace std;
typedef long long LL;

const int maxn = 8000005;
const LL inf = 1ll<<50;

int x[maxn],n,Q,A,B;LL tag,ans=inf;
int ABS(int x) {return x>0?x:-x;}
namespace ST {
	LL min1[maxn],min2[maxn],val[maxn];
	#define ls rt<<1
	#define rs rt<<1|1
	void build(int rt,int L,int R) {
		if (L>=R) {
			val[rt]=(L==B)?0:inf;
			min1[rt]=val[rt]-L;
			min2[rt]=val[rt]+L;return ;
		}
		int mid=L+R>>1;
		build(ls,L,mid);
		build(rs,mid+1,R);
		min1[rt]=min(min1[ls],min1[rs]);
		min2[rt]=min(min2[ls],min2[rs]);
	}
	void modify(int rt,int L,int R,int p,LL w) {
		if (L>=R) {
			val[rt]=min(val[rt],w);
			min1[rt]=val[rt]-L;
			min2[rt]=val[rt]+L;
			return ;
		}
		int mid=L+R>>1;
		if (p<=mid) modify(ls,L,mid,p,w);
		else modify(rs,mid+1,R,p,w);
		min1[rt]=min(min1[ls],min1[rs]);
		min2[rt]=min(min2[ls],min2[rs]);
	}
	LL query1(int rt,int L,int R,int l,int r) {
		if (L>=l&&R<=r) return min1[rt];
		int mid=L+R>>1;LL res=inf;
		if (l<=mid) res=min(res,query1(ls,L,mid,l,r));
		if (r>mid) res=min(res,query1(rs,mid+1,R,l,r));
		return res;
	}
	LL query2(int rt,int L,int R,int l,int r) {
		if (L>=l&&R<=r) return min2[rt];
		int mid=L+R>>1;LL res=inf;
		if (l<=mid) res=min(res,query2(ls,L,mid,l,r));
		if (r>mid) res=min(res,query2(rs,mid+1,R,l,r));
		return res;
	}
	void getans(int rt,int L,int R) {
		if (L>=R) {
			ans=min(ans,val[rt]+tag);
			return ;
		}
		int mid=L+R>>1;
		getans(ls,L,mid);
		getans(rs,mid+1,R);
	}
}
using namespace ST;

int main()
{
	#ifdef Amberframe
		freopen("arc073d.in","r",stdin);
		freopen("arc073d.out","w",stdout);
	#endif
	scanf("%d %d %d %d",&n,&Q,&A,&B);
	x[0]=A;build(1,1,n);
	for (int i=1;i<=Q;i++) scanf("%d",&x[i]);
	for (int i=1;i<=Q;i++)
	{
		LL w=min(query1(1,1,n,1,x[i])+x[i],query2(1,1,n,x[i],n)-x[i]);
		LL d=ABS(x[i]-x[i-1]);
		modify(1,1,n,x[i-1],w-d);tag+=d;
	}
	getans(1,1,n);printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 19712
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)
	xs := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&xs[i])
	}
	res := devideIntoTwo(N, xs)
	fmt.Println(res)
}

func devideIntoTwo(N int, xs []int) int {
	sum := 0
	for _, x := range xs {
		sum += x
	}
	half := sum / 2

	tmp := 0
	res1 := 0
	res2 := 0
	for _, x := range xs {
		if tmp+x > half {
			res1 = sum - 2*tmp
			res2 = 2*(tmp+x) - sum
			if res1 < res2 {
				return res1
			}
			return res2
		}
		tmp += x
	}
	return res1
}


Measured memory_bytes: 5376
#include "bits/stdc++.h"
using namespace std;
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define N	    100001
#define rep(i,a,b)  for(int i=a;i<b;i++)
typedef long long ll;
void self_max(ll  &a, ll b) {
	a = max(a, b);
}
int main() {
	int n, w;
	cin>>n>>w;
	vector<ll> weight(n), value(n);
	ll m_val = 0;
	for(int i = 0; i < n; i++) {

		cin>>weight[i]>>value[i];
		m_val += value[i];
	}
	vector<ll> dp(m_val + 1, INT_MAX);
	//This dp[i] is min_weight at value i
	dp[0] = 0;
	for(int i = 0; i < n; i++) {

		for(int j = m_val - value[i]; j >= 0; j--) {
			if(dp[j] != INT_MAX) {
				dp[j + value[i]] = min(dp[j + value[i]], dp[j] + weight[i]);
			}
		}
	}
	ll ans = 0;
	for(int i = 0; i <= m_val; i++) 
		if(dp[i] <= w)
			ans = max(ans, (ll)i);
	cout<<ans<<endl;
}


Measured memory_bytes: 1152
def solve():
    n,a,b = map(int,input().split())
    s = input()
    cnt_a=0
    cnt_b=0
    for i in s:
        if i=='a':
            if cnt_a<a+b:
                print('Yes')
                cnt_a+=1
            else:
                print('No')
        elif i=='b':
            if cnt_a<a+b and cnt_b<b:
                print('Yes')
                cnt_b+=1
                cnt_a+=1
            else:
                print('No')
        else:
            print('No')
if __name__ == "__main__":
    solve()

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

public static class Permi
{
    public static IEnumerable<IEnumerable<T>> Perm<T>(this IEnumerable<T> items, int? k = null)
    {
        if (k == null) k = items.Count();
        if (k == 0) yield return Enumerable.Empty<T>();
        else
        {
            var i = 0;
            foreach (var x in items)
            {
                var xs = items.Where((_, index) => i != index);
                foreach (var c in Perm(xs, k - 1))
                    yield return c.Before(x);
                i++;
            }
        }
    }
    public static IEnumerable<T> Before<T>(this IEnumerable<T> items, T first)
    {
        yield return first;
        foreach (var i in items) yield return i;
    }
}
public class hello
{
    public static void Main()
    {
        var hs = new HashSet<string>();
        var d = Console.ReadLine().Trim();
        var p = "AIZUNYAN";
        var a = "AIDUNYAN";
        var b = a.Perm();
        foreach (var x in b)
        {
            var c2 = new string(x.ToArray());
            if (hs.Add(c2)) d = d.Replace(c2, "@");
        }
        d = d.Replace("@", p);
        Console.WriteLine(d);
    }
}



Measured memory_bytes: 26032
#include<bits/stdc++.h>
using namespace std;
//#include<boost/multiprecision/cpp_int.hpp>
//using boost::multiprecision::cpp_int;

#define int long long
#define cint cpp_int
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) (((a)+(b)-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2
#define PI acos(-1.0)

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

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;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vvout(VVi &v){for(int i=0;i<(v).size();i++) vout(v[i]);}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int mypow(int x, int n, int m){if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int digit(int k,int i){string s = to_string(k);return s[s.size()-i]-'0';}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
Vi accum(Vi v){Vi ret((v).size());ret[0]=v[0];REP(i,1,(v).size()) ret[i]=ret[i-1]+v[i];return ret;}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}



signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
    int n;
    cin>>n;
    Vi a(n);
    REP(i,0,n) cin>>a[i];
    Vi sums=accum(a);
    int s=sums[sums.size()-1];

    int ans=INF;
    REP(i,0,n-1){
        chmin(ans,abs(sums[i]-(s-sums[i])));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4992
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        
        int ans = 0;
        for(int i = 0; i < N; i++) {
            int x = sc.nextInt();
            while( x % 2 == 0 ) {
                x /= 2;
                ans++;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 48032
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    
    if(a < b+c){
      System.out.println((b + c) - a);
    }else if(a >= b+c){
      System.out.println(0);
    }
  }
}

Measured memory_bytes: 23764