akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {

  int a,b,c,d,e;
  cin>>a>>b>>c>>d>>e;
  
  if(a==0){
    cout<<1<<endl;
  }
  else if(b==0){
    cout<<2<<endl;
  }
  else if(c==0){
    cout<<3<<endl;
  }
  else if(d==0){
    cout<<4<<endl;
  }
  else{
    cout<<5<<endl;
  }
}


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

using namespace std;

const int N = 200005;

struct Node {
  int val[2];
  Node() {
    val[0] = val[1] = INT_MAX;
  }
};

int a[N], m[N];

struct S {
  int l, r, val;
  bool operator < (const S &b) const {
    return val > b.val;
  }
};

int n;
Node seg[N << 2];

void add(int id, int l, int r, int loc, int data) {
  if (l == r) {
    seg[id].val[loc & 1] = data;
    seg[id].val[2] = data;
    return ;
  }
  int mid = (l + r) >> 1;
  if (loc <= mid) {
    add(id << 1, l, mid, loc, data);
  }
  else {
    add(id << 1 | 1, mid + 1, r, loc, data);
  }
  seg[id].val[0] = min(seg[id << 1].val[0], seg[id << 1 | 1].val[0]);
  seg[id].val[1] = min(seg[id << 1].val[1], seg[id << 1 | 1].val[1]);
}

int query(int id, int l, int r, int ll, int rr, int flag) {
  if (l == ll && r == rr) {
    return seg[id].val[flag];
  }
  int mid = (l + r) >> 1;
  if (mid >= rr) {
    return query(id << 1, l, mid, ll, rr, flag);
  }
  if (mid < ll) {
    return query(id << 1 | 1, mid + 1, r, ll, rr, flag);
  }
  return min(query(id << 1, l, mid, ll, mid, flag), query(id << 1 | 1, mid + 1, r, mid + 1, rr, flag));
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    m[a[i]] = i;
    add(1, 1, n, i, a[i]);
  }
  a[n + 1] = INT_MAX;
  priority_queue<S> q;
  q.push({1, n, query(1, 1, n, 1, n, 1)});
  vector<int> res;
  while (!q.empty()) {
    S s = q.top();
    q.pop();
    res.push_back(s.val);
    int now = m[s.val];
    int go = query(1, 1, n, now + 1, s.r, (now & 1) ^ 1);
    res.push_back(go);
    go = m[go];
    if (now > s.l) {
      q.push({s.l, now - 1, query(1, 1, n, s.l, now - 1, s.l & 1)});
    }
    if (now + 1 < go) {
      q.push({now + 1, go - 1, query(1, 1, n, now + 1, go - 1, (now + 1) & 1)});
    }
    if (go < s.r) {
      q.push({go + 1, s.r, query(1, 1, n, go + 1, s.r, (go + 1) & 1)});
    }
  }
  for (int i = 0; i < n ; ++i) {
    printf("%d%c", res[i], i < n - 1 ? ' ' : '\n');
  }
  return 0;
}


Measured memory_bytes: 10764
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d) for ( auto blockTime = make_pair(chrono::high_resolution_clock::now(), true);blockTime.second;\
debug("%s: %lld ms\n", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false)
#define li long long int
#define ld long double
#define eb push_back
#define pb pop_back
#define INF 1e18+10
#define MINF -1e18-10
#define rep(i,a,b) for(li i=a;i<b;i++)
#define size(a) a.size()
#define rev(a) reverse(a.begin(),a.end())
#define len(a) a.length()
#define f first
#define s second
#define sort(a) sort(a.begin(),a.end())
#define vli vector<li>
#define vvli vector<vli >
#define pli pair<li,li>
#define vpli vector<pli>
#define inp(t) li t;cin>>t; while(t--)
using namespace std;
const li mod = 1e9+7;
#define MAXN 1000005 

li power(li a, li b) { a%=mod; li ret=1;while(b) {if(b&1) ret*=a;a*=a;if(ret>=mod) ret%=mod;if(a>=mod) a%=mod;b>>=1;}return ret;}
li add(li a,li b) { return (((a%mod)+(b%mod))%mod);}
li sub(li a,li b) { return (((a%mod)-(b%mod))%mod);}
li mul(li a,li b) { return (((a%mod)*(b%mod))%mod);}

bool isprime(li n)
{
  if (n == 1)
    return false;
  int i = 2;
  while (i*i <= n){
      if (n % i == 0)return false;
      i += 1;
  }
  return true;
}

li lcm(li a,li b)
{
    return ((a*b)/__gcd(a,b));
}

void solve()
{
  li x,y;
  cin>>x>>y;

  for(int i=0;i<=x;i++)
  {
    if((2*i+4*(x-i))==y)
    {
      cout<<"Yes\n";
      return;
    }
  }

  cout<<"No\n";
  return;
  
}
int main()
{
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif

    solve();
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std; 
map<string,int> mp;
int n;
string s;
int main() { 
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n;
	int ans=0;
	for(int i=0;i<n;i++){
		cin>>s;
		if(mp[s]==0)ans++;
		mp[s]++;
	}
	cout<<ans<<endl;
    return 0; 
}/*
*/

Measured memory_bytes: 19252
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const ll mod = (ll)1e9 + 7;

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a.at(i);
    ll ans = 0;
    rep(i,60){
        ll x = 0;
        rep(j,n)if(a.at(j)>>i & 1) x++;
        ll y = (ll)n - x;
        ll now =  x * y % mod;
        rep(k,i) now = now * 2 % mod;
        ans += now;
        ans %= mod;
    }
    cout << ans << endl;
    // ll ans = 0;
    // for(int i = 0;i < n -1;i++){
    //     for(int j = i + 1; j < n;j++){
    //         ll t = (a.at(i)) ^ (a.at(j));
    //         t %= MX;
    //         ans = (ans + t) % MX;
    //     }
    // }
    // cout << ans << endl;
}

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

a = list(map(int,input().split()))

a.sort()

query = []

high = a[-1]

low = a[0]

for i in range(1,n-1):
    if a[i] > 0:
        query.append([low, a[i]])
        low -= a[i]
    else:
        query.append([high, a[i]])
        high -= a[i]

query.append([high, low])

print(high-low)

for x,y in query:
    print(x,y)



Measured memory_bytes: 98176
def get_burger_num(n)
  return 1 if n == 0
  return 2*get_burger_num(n-1)+3
end

def get(n, x) # nはバーガーのレベル、xは食べる層数. 食べるパティの層数を吐き出す
  burger_num = get_burger_num(n)
  if n == 0
    return 1
  end

  if x <= 1
    return 0
  elsif x <= get_burger_num(n-1)+1
    return get(n-1, x-1)
  elsif x == get_burger_num(n-1)+2
    return get(n-1, x-1) + 1
  elsif x <= 2*get_burger_num(n-1)+3
    return get(n-1, x-1) + 1 + get(n-1, x-2-get_burger_num(n-1))
  else
    return 2*get(n-1, x-1) + 1
  end
end

n, x = gets.chomp.split(' ').map(&:to_i)
puts get(n, x)

Measured memory_bytes: 1788
#include <stdio.h>

int main()
{
    int list[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int i;
    
    scanf("%d", &i);
    
    printf("%d", list[i-1]);

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
     
    using namespace std;
     
    int inf = 1000000007;
    int n;
    int h[101010];
         
    int dp[101010];
     
    int f(int n) {
      if (n < 1) return inf;
      if (n == 1) return 0;
      
      if (dp[n] != -1) return dp[n];
      dp[n] = min(f(n-1) + abs(h[n] - h[n-1]), f(n-2) + abs(h[n] - h[n-2]));
      return dp[n];
      
    }
         
    int main() {
      	memset(dp, -1, sizeof(dp));
      
      	cin >> n;
      	for(int i = 1; i <= n; i++) cin >> h[i];
      
      	cout << f(n);
      
     	return 0; 
    }

Measured memory_bytes: 2560
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;

int gcd(int a, int b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

void solve() {
    int len = 3;
    vector<vector<int>> c(len, vector<int>(len));
    int max_num = -1;
    for (int i = 0; i < len; ++i) {
        for (int j = 0; j < len; ++j) {
            cin >> c[i][j];
        }
    }
    int max_r0 = *max_element(c[0].begin(), c[0].end());
    int max_r1 = *max_element(c[1].begin(), c[1].end());
    int max_r2 = *max_element(c[2].begin(), c[2].end());
    int a1 = 0, a2 = 0, b0 = 0, b1 = 0, b2 = 0;
    vector<int>a2_candidate(len), a3_candidate(len);
    int a2_can = 0, a3_can = 0, num_a2 = 0, num_a3 = 0;
    for (int a0 = 0; a0 <= max_r0; ++a0) {
        b0 = c[0][0] - a0;
        b1 = c[0][1] - a0;
        b2 = c[0][2] - a0;

        //a2 candidate
        a2_candidate[0] = c[1][0] - b0;
        a2_candidate[1] = c[1][1] - b1;
        a2_candidate[2] = c[1][2] - b2;

        //a3 candidate
        a3_candidate[0] = c[2][0] - b0;
        a3_candidate[1] = c[2][1] - b1;
        a3_candidate[2] = c[2][2] - b2;

        a2_can = a2_candidate[0];
        a3_can = a3_candidate[0];

        num_a2 = 0;
        num_a3 = 0;

        for (int i = 0; i < len; ++i) {
            if (a2_candidate[i] < 0 || a3_candidate[i] < 0) break;
            if (a2_can == a2_candidate[i]) num_a2++;
            if (a3_can == a3_candidate[i]) num_a3++;
        }

        if (num_a2 == 3 && num_a3 == 3) {
            cout << "Yes" << endl;
            return;
        }
    }
    cout << "No" << endl;
    return;
}

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



Measured memory_bytes: 256
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;
typedef pair<ll,ll> P;

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)

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

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

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};
// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};

int main() {
    int N; cin >>N;
    vector<ll>A(N);

    rep(i,N){
        cin >> A[i];
    }
    ll ans=0LL;
    for(int i=0; i<N-1; i++){
        if(A[i]<0){
            A[i]=-A[i];
            A[i+1]=-A[i+1];
        }
    }

    ll minimum=100000000LL;
    for(int i=0; i<N; i++){
        ans+=abs(A[i]);
        minimum = min(minimum, abs(A[i]));
    }
    bool flag=false;
    for(int i=0; i<N; i++) {
        if (A[i] < 0) {
            flag=true;
        }
    }

    if(flag){
        ans-=minimum*2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
n = int(input())
for i in range(1000):
    if n + i == 111 or n + i == 222 or n + i == 333 or n + i == 444 or n + i == 555 or n + i == 666 or n + i == 777 or n + i == 888 or n + i == 999:
        print(n+i)
        exit()
        

Measured memory_bytes: 2940
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        var N = int.Parse(Console.ReadLine());

        var s = new List<char>();
        foreach (var item in Console.ReadLine())
        {
            s.Add(item);
        }
        int operation = 0;
        var right = GetNextRight(s, s.Count - 1);
        for (int left = 0; left < N; left++)
        {
            if (left < right)
            {
                if (s[left] == 'W')
                {
                    var temp = s[left];
                    s[left] = s[right];
                    s[right] = temp;
                    operation++;

                    right = GetNextRight(s, right);
                }
            }
            else
            {
                break;
            }
        }
        Console.WriteLine(operation);
    }

    private static int GetNextRight(List<char> list, int lastRight)
    {
        for (int i = lastRight; i > 0; i--)
        {
            if (list[i] == 'R') return i;
        }

        return 0;
    }
}

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

int main()
{
    int N;
    cin >> N;
    vector<bool> button(N, false);
    button.at(0) = true;
    vector<int> light(N);
    rep(i, N) cin >> light.at(i);
    int bt = 0;
    int ans = 0;
    while (true)
    {
        if (button.at(light.at(bt)-1) == false) button.at(light.at(bt)-1) = true;
        else
        {
            cout << -1 << endl;
            return 0;
        }
        bt = light.at(bt)-1;
        ans++;
        if (bt == 1)
        {
            cout << ans << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
 
int main() {
  ios::sync_with_stdio(0); 
  cin.tie(0); 
  
  int n, m;
  cin >> n >> m;

  char A[n][n];
  char B[m][m];

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) cin >> A[i][j];
  }
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < m; ++j) cin >> B[i][j];
  }

  for (int i = 0; i < n - m + 1; ++i) {
    for (int j = 0; j < n - m + 1; ++j) {
      bool is_found = true;

      for (int x = 0; x < m && is_found; ++x) {
        for (int y = 0; y < m && is_found; ++y) {
          if (A[i + x][j + y] != B[x][y]) {
            is_found = false;
          }
        }
      }

      if (is_found) {
        cout << "Yes" << "\n";
        return 0;
      }
    }
  }

  cout << "No" << "\n";
}


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

using namespace std;

typedef pair<int, int> II;
typedef pair<long long, int> LLI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<II> VII;

#define For(i,a,b) for(int i = a;i <= b; i++)
#define Rep(i,a,b) for(int i = a;i >= b; i--)
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, f) for(auto i : f)
#define fi first
#define se second
#define pb push_back
#define sz(s) int(s.size())
#define reset(f, x) memset(f, x, sizeof(f))
#define all(x) x.begin(), x.end()
#define two(x) (1LL << x)
#define getbit(x, i) ((x >> (i-1)) & 1LL)
#define onbit(x, i) (x | (1LL << (i-1)))
#define offbit(x, i) (x & ~(1 << (i-1)))

const int N = 600+1;
const int p = 37;

int n, res, nn;
char s[2][N][N];
ULL h[2][N][N], pw[N*N], h2[2][N][N];

ULL get_row(int t, int i, int l, int r) {
    return h[t][i][r] - h[t][i][l-1]*pw[r-l+1];
}

ULL get_table(int t, int i, int j) {
    return h2[t][i+n-1][j] - h2[t][i-1][j]*pw[n*n];
}

void init_hash() {
    nn = 2*n;
    pw[0] = 1;
    For(i, 1, n*n) pw[i] = pw[i-1]*p;
    For(t, 0, 1) {
        For(i, 1, nn) {
            For(j, 1, nn) h[t][i][j] = h[t][i][j-1]*p + s[t][i-1][j-1] - 'a';
            For(j, 1, n) {
                h2[t][i][j] = h2[t][i-1][j]*pw[n] + get_row(t, i, j, j+n-1);
            }
        }
    }
}

void solve() {
    For(i, 1, n) For(j, 1, n) {
        ULL r1 = get_table(0, i, j);
        ULL r2 = get_table(1, j, i);
        if (r1 == r2) res++;
    }
    cout << res << "\n";
}

int main() {
    //ios_base::sync_with_stdio(false);
    //freopen("in.txt","r",stdin);
    //freopen("","w",stdout);
    cin >> n;
    REP(i, n) scanf("%s\n", s[0][i]);
    REP(i, n) REP(j, n) s[1][i][j] = s[0][j][i];
    REP(i, n) REP(j, n) {
        s[0][i+n][j+n] = s[0][i][j+n] = s[0][i+n][j] = s[0][i][j];
        s[1][i+n][j+n] = s[1][i][j+n] = s[1][i+n][j] = s[1][i][j];
    }
    //REP(i, 2*n) printf("%s\n", s[1][i]);
    init_hash();
    solve();
}




Measured memory_bytes: 15104
#include<iostream>
#include<iomanip>
#include<string>
#include<queue>
#include<vector>
#include<algorithm>
#include<tuple>
#include<numeric>
#include<map>
#include<cmath>
#define ll long long
#define rep(i,n) for(int i=0;i<(int) (n);i++)
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
using namespace std;
int main(){
  ll x,many=100;
  int cnt=0;
  cin>>x;
  while(many<x){
    many+=(many*0.01);
    cnt++;
  }
  cout<<cnt;

  return 0;
}


Measured memory_bytes: 3636
package main

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

//input
var sc = bufio.NewScanner(os.Stdin)

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

//solve
func printList(list []int) {
	buf := bufio.NewWriter(os.Stdout)
	for _, v := range list {
		buf.Write([]byte(fmt.Sprintf(" %d", v)))
	}
	buf.Write([]byte("\n"))
	buf.Flush()
}

func maxHeapfy(A []int, i int, n int) {
	//fmt.Println(A, i)
	largest := i
	l := 2 * i
	r := 2*i + 1

	//keyが最大のノードを、トップに持ってくる
	if l <= n && A[l] > A[i] {
		largest = l
	}
	if r <= n && A[r] > A[largest] {
		largest = r
	}

	if largest != i {
		tmp := A[i]
		A[i] = A[largest]
		A[largest] = tmp
		maxHeapfy(A, largest, n)
	}

}

func buildHeap(A []int, n int) {
	for i := n / 2; i >= 1; i-- {
		maxHeapfy(A, i, n)
		//fmt.Println(i, A)
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	A := make([]int, n+1)
	for i := 1; i <= n; i++ {
		A[i] = nextInt()
	}

	buildHeap(A, n)
	printList(A[1:])
}



Measured memory_bytes: 10176
#include <stdio.h>
char a[10000][100000];
int main ()
{
	int h,w,i,j;
	scanf ("%d%d",&h,&w);
	for (i=0;i<h;i++)
	{
			scanf ("%s",&a[i]);
	}
	for (i=0;i<w+1;i++)
	{
		printf ("#");
	}
	printf ("#\n");
	for (i=0;i<h;i++)
	{
		printf ("#");
		for (j=0;j<w;j++)
		{
			printf ("%c",a[i][j]);
		}
		printf ("#\n");
	}
	for (i=0;i<w+1;i++)
	{
		printf ("#");
	}
	printf ("#\n");
	return 0;
}
	
	

Measured memory_bytes: 8448
H, W, K = map(int, input().split())
S = [list(map(int, list(input()))) for _ in range(H)]

tab_h = [[0] * (W + 1) for _ in range(H)]
for i in range(H):
    cnt = 0
    for j in range(W):
        cnt += S[i][j]
        tab_h[i][j + 1] = cnt

# tab_v = [[0] * (H + 1) for _ in range(W)]
# for j in range(W):
#     cnt = 0
#     for i in range(H):
#         cnt += S[i][j]
#         tab_v[i + 1][j] = cnt

ans = 1000000007
for case in range(2 ** (H - 1)):
    case_tmp = case
    iscut_v = []
    for i in range(H - 1):
        iscut_v.append(case_tmp % 2)
        case_tmp >>= 1
    #
    parts = []
    vsrc = 0
    for vdst in range(1, H + 1):
        if vdst == H:
            parts.append((vsrc, vdst))
            break
        elif iscut_v[vdst - 1] == 1:
            parts.append((vsrc, vdst))
            vsrc = vdst
        else:
            continue
    #
    possible = False
    hsrc = 0
    iscut_h = [0] * (W - 1)
    for hdst in range(1,  W + 1):
        num_1 = 0
        for vsrc, vdst in parts:
            num_1_tmp = 0
            for i in range(vsrc, vdst):
                num_1_tmp += tab_h[i][hdst] - tab_h[i][hsrc]
            num_1 = max(num_1, num_1_tmp)
            # print("##", hdst, (vsrc, vdst), num_1_tmp)
        #
        if num_1 > K:
            if hdst == 1 or hdst - 1 == hsrc:
                break
            else:
                iscut_h[hdst - 2] = 1
                hsrc = hdst - 1
        else:
            continue
    else:
        possible = True
    #
    if possible:
        ans_tmp = sum(iscut_v) + sum(iscut_h)
        # print("#", iscut_v, iscut_h, ans_tmp)
        ans = min(ans, ans_tmp)

print(ans)

Measured memory_bytes: 48732
x, k, d = map(int, input().split())

x = abs(x)

if x >= k * d:
    print(x - k * d)
else:
    div, mod = divmod(x, d)
    if (k - div) % 2 == 0:
        print(mod)
    else:
        print(abs(mod - d))

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()

int N, M;

int solve() {
    int mn = 0, mx = N;
    REP (m, M) {
        int l, r; cin >> l >> r;
        mn = max(mn, l-1);
        mx = min(mx, r);
    }
    return max(0, mx-mn);
}

int main() {
    cin >> N >> M;
    cout << solve() << endl;
}

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

int main(void)
{
    int N, R;
    cin >> N >> R;

    if (N >= 10)
        cout << R << endl;
    else
        cout << R + 100 * (10 - N) << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int H,W;
        int i,j;
        while(true){
            H=sc.nextInt();
            W=sc.nextInt();
            if(H==0&&W==0) break;
            for(i=0;i<H;i++){
                for(j=0;j<W;j++){
                    if((j!=0&&j!=W-1)&&(i!=0&&i!=H-1)){
                        System.out.print(".");
                    }else{
                        System.out.print("#");
                    }
                }
                System.out.println("");
            }
            System.out.println("");
        }
    }
}


Measured memory_bytes: 33500
n,x=map(int,input().split())
a=list(map(int,input().split()))
ans=0

for i in range(n-1):
    overflow = a[i]+a[i+1]-x
    if overflow >0:
        ans += overflow
        if a[i+1]>= overflow:
            a[i+1] -= overflow
        else:
            a[i] -= overflow -a[i+1]
            a[i+1]=0
 
print(ans)


Measured memory_bytes: 14252
import java.io.*;
import java.util.Arrays;
import java.util.*;

class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] fst = (br.readLine()).split(" ");
		int n = Integer.parseInt(fst[0]);
		int quan = Integer.parseInt(fst[1]);
		int sumtime = 0;
		Deque<Integer> stackint = new ArrayDeque<Integer>();
		Deque<String> stackst = new ArrayDeque<String>();
		for ( int i = 0; i<n ; i++ ) {
			String[] st = (br.readLine()).split(" ");
			stackst.addLast(st[0]);
			stackint.addLast(Integer.parseInt(st[1]));
		}
		int a;
		String b;
		try{
				// System.out.println("a");

			while((a = stackint.pollFirst()) > 0){
				b = stackst.pollFirst();
				if ( a <= quan) {
					sumtime = sumtime + a;
				// System.out.println("b");

					System.out.println(b + " " + sumtime);
				}else{
					sumtime = sumtime + quan;
					a = a - quan;
					stackint.addLast(a);
				// System.out.println("c");

					stackst.addLast(b);
				}
			}
		}catch (NullPointerException e){
				// System.out.println("d");

		}
	}
}

Measured memory_bytes: 63148
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            int iN = int.Parse(sS[0]);
            sS = System.Console.ReadLine().Trim().Split(' ');
            List<int> lstInp = new List<int>();
            for (int i = 0; i < sS.Length; i++) { lstInp.Add(int.Parse(sS[i])); }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            List<int> lstOut = new List<int>();
            for (int i = 0; i < lstInp.Count; i++)
            {
                int i1st = 0;
                int i2nd = 0;
                for (int j = 0; j <= i; j++)               { i1st += lstInp[j]; }
                for (int j = i + 1; j < lstInp.Count; j++) { i2nd += lstInp[j]; }
                lstOut.Add(Math.Abs(i1st - i2nd));
            }
            lstOut.Sort();

            // 出力
            System.Console.WriteLine("{0}", lstOut[0].ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


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

int main(){
    int x,y,a,b,c;
    cin >> x >> y >> a >> b >> c;
    vector<ll> p(a), q(b), r(c);
    rep(i,a) cin >> p[i];
    rep(i,b) cin >> q[i];
    rep(i,c) cin >> r[i];
    sort(p.begin(),p.end(), greater<ll>());
    sort(q.begin(),q.end(), greater<ll>());
    sort(r.begin(),r.end(), greater<ll>());
    ll ans = 0;
    int pc = 0;
    int qc = 0;
    int rc = 0;
    int num = x + y;
    x--; y--; c--;
    rep(i,num){
        //ll now = max3(p[pc],q[qc],r[rc]);
        ll now = -1;
        if(pc<=x) chmax(now,p[pc]);
        if(qc<=y) chmax(now,q[qc]);
        if(rc<=c) chmax(now,r[rc]);
        if(pc<a&&now==p[pc]) pc++;
        else if(qc<b&&now==q[qc]) qc++;
        else {
            rc++;
            if(x<0) y--;
            else if(y<0) x--;
            else if(p[x]<q[y]) {
                x--;
            }else{
                y--;
            }
        }
        ans+= now;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 2560
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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



int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(15);

  ll N; cin>>N;
  vector<ll> v(N); rep(i,N) cin>>v[i];
  
  vector<ll> vec0(100001,0),vec1(100001,0);
  rep(i,N){
    if(i%2==0) vec0[v[i]]++;
    else vec1[v[i]]++;
  }
  vector<pair<ll,ll>> pvec0(100001),pvec1(100001);
  rep(i,100001) {
    pvec0[i]={vec0[i],i};
    pvec1[i]={vec1[i],i};
  }
  sort(pvec0.rbegin(),pvec0.rend());
  sort(pvec1.rbegin(),pvec1.rend());
  if(pvec0[0].second!=pvec1[0].second) cout<<N-pvec0[0].first-pvec1[0].first<<endl;
  else{
    ll ans=INF;
    chmin(ans,N-pvec0[0].first-pvec1[1].first);
    chmin(ans,N-pvec0[1].first-pvec1[0].first);
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 8724
flag=False

def dbg(a,b=None):
  print(a,b) if flag else None
  
def hante(arr,num):
  sum=0
  for i in range(len(arr)):
    sum+=arr[i]
    if sum==num:
      dbg((True,i),arr)
      return (True,i+1)
    if sum>num:
      dbg((False,None),arr)
      return (False,None)
  dbg((False,None),arr)
  return (False,None)


while True:
  n=int(input())
  if n==0:
    break;
  mojisuu=0
  w=["" for i in range(n)]
  for i in range(n):
    x=len(input())
    w[i]=x
    mojisuu+=x
  start=0
  while start<mojisuu:
    
    h1=hante(w[start:],5)
    if not h1[0]:
      start+=1
      continue
    h2=hante(w[start+h1[1]:],7)
    if not h2[0]:
      start+=1
      continue
    h3=hante(w[start+h1[1]+h2[1]:],5)
    if not h3[0]:
      start+=1
      continue
    h4=hante(w[start+h1[1]+h2[1]+h3[1]:],7)
    if not h4[0]:
      start+=1
      continue
    h5=hante(w[start+h1[1]+h2[1]+h3[1]+h4[1]:],7)
    if not h5[0]:
      start+=1
      continue
    break
  print(start+1)
    


Measured memory_bytes: 5624
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

mint pow_kai(mint a, ll n){//aのn乗を計算します。
  mint x = 1;
  while(n > 0){//全てのbitが捨てられるまで。
    if(n&1){//1番右のbitが1のとき。
      x = x*a;
    }
    a = a*a;
    n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
  }
  return x;
}
 
vector<long long> fact_inv, inv, Com;
 
/*  init_nCk :二項係数のための前処理
    計算量:O(n)
*/
void init_nCk(int n, int SIZE) {
    fact_inv.resize(SIZE + 5);
    inv.resize(SIZE + 5);
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < SIZE + 5; i++) {
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD;
    }
    Com.resize(SIZE + 5);
    Com[0] = 1;
    for (int i = 1; i < SIZE + 5; i++) {
        Com[i] = Com[i - 1] * ((n - i + 1) * inv[i] % MOD) % MOD;
    }
}
 
/*  nCk :MODでの二項係数を求める(前処理 int_nCk が必要)
    計算量:O(1)
*/
long long nCk(int k) {
    assert(!(k < 0));
    return Com[k];
}
int main()
{
  ll n,a,b;
  cin >> n >> a >> b;
  mint ans = pow_kai(2,n);
  init_nCk(n,a);
  ll A = nCk(a);
  init_nCk(n,b);
  ll B = nCk(b);
  mint C = A+B;
  cout << ans-C-1 << endl;
}

Measured memory_bytes: 7908
import collections as c
ip = lambda : map(int, input().split())

#################

A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
l = [A,B,C,D,E]
sss = {0,1,2,3,4}
ans = 800
for i1 in range(5):
    s = {i1}
    for i2 in range(5):
        if i2 in s:
            continue
        s.add(i2)
        for i3 in range(5):
            if i3 in s:
                continue
            s.add(i3)
            for i4 in range(5):
                if i4 in s:
                    continue
                s.add(i4)
                for i5 in sss-s:
                    ans = min(ans,(l[i1]+9)//10*10+(l[i2]+9)//10*10+(l[i3]+9)//10*10+(l[i4]+9)//10*10+l[i5])
               
                    s-={i5}
                s-={i4}
            s-={i3}
        s-={i2}
    s-={i1}
print(ans)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
int n;
vector<string>v;
void dfs(int a,int b,string s)
{
	if(!a)
	{
		v.push_back(s);
		return; 
	}
	for(int i=0;i<b;i++)
	{
		string t=s+char('a'+i);
		dfs(a-1,b,t);
	}
	string t=s+char('a'+b);
	dfs(a-1,b+1,t);
}
int main()
{
	cin>>n;
	dfs(n,0,"");
	sort(v.begin(),v.end());
	for(int i=0;i<v.size();i++)
		cout<<v[i]<<endl;

	return 0;
}

Measured memory_bytes: 7796
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
            int N = sc.nextInt();
            int n = N;
            int sum = 0;
            while (N != 0) {
                sum += N % 10;
                N /= 10;
            }
            if(n % sum == 0){
            System.out.println("Yes");
            }else{
                System.out.println("No");
            }
    }
}

Measured memory_bytes: 23124
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <array>
#include <set>
#include <queue>
using namespace std;
typedef long long int lli;
typedef pair<int,int> pii;
typedef array<array<int, 4>, 4> Grid;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
Grid touch(int i, int j, Grid g){
    g[i][j]++;
    vector<pair<pii,int>> wait;
    while(1){
        for(int i=0; i<4; i++){
            for(int j=0; j<4; j++){
                if(g[i][j] > 4){
                    g[i][j] = 0;
                    for(int d=0; d<4; d++){
                        wait.emplace_back(pii(i, j), d);
                    }
                }
            }
        }
        if(wait.empty()) break;
        vector<pair<pii, int>> nwait;
        while(!wait.empty()){
            auto e = wait.back();
            wait.pop_back();
            int i = e.first.first;
            int j = e.first.second;
            int d = e.second;
            int ni=i+dy[d], nj=j+dx[d];
            if(ni<0 or 4<=ni or nj<0 or 4<=nj) continue;
            if(g[i+dy[d]][j+dx[d]] == 0){
                nwait.emplace_back(pii(ni, nj), d);
            }else{
                g[ni][nj]++;
            }
        }
        wait = nwait;
    }
    return g;
}
lli grid_to_ll(const Grid &g){
    lli res = 0;
    for(int i=0; i<4; i++){
        for(int j=0; j<4; j++){
            res |= (lli)g[i][j]<<(3*(4*i+j));
        }
    }
    return res;
}

int solve(Grid g){
    if(grid_to_ll(g) == 0) return 0;
    queue<pair<Grid, int>> wait;
    set<lli> used;
    wait.push(make_pair(g, 0));
    used.insert(grid_to_ll(g));
    while(!wait.empty()){
        Grid g = wait.front().first;
        int cost = wait.front().second;
        wait.pop();
        for(int i=0; i<4; i++){
            for(int j=0; j<4; j++){
                if(g[i][j]==0) continue;
                Grid newg = touch(i, j, g);
                lli gll = grid_to_ll(newg);
                if(used.find(gll) != used.end()) continue;
                used.insert(gll);
                if(gll == 0) return cost+1;
                if(cost < 4){
                    wait.push(make_pair(newg, cost+1));
                }
            }
        }
    }
    return -1;
}

int main(){
    Grid g;
    for(int i=0; i<4; i++){
        for(int j=0; j<4; j++){
            cin >> g[i][j];
        }
    }
    cout << solve(g) << endl;
    return 0;
}



Measured memory_bytes: 4136
#import math
#import itertools
#import numpy as np
from collections import deque


INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))

def do():
    n,k=INTM()
    d=LIST()
    #q=deque(d)
    nkmin=min(n,k)
    stop=10**9
    ans=0
    for i1 in range(1,1+nkmin):
        for i2 in range(i1+1):
            temp=d[0:i2]+d[n-(i1-i2):]
            #print(temp,i1,i2)
            temp=sorted(temp)
            #print(temp,i1,i2)
            for i3 in range(i1):
                if temp[i3]>=0 or i3>=k-i1:
                    stop=i3
                    break
                stop=10**9
            if stop!=10**9:
                #print(temp[i3:],1)
                ans=max(sum(temp[i3:]),ans)
    
    print(ans)



if __name__=='__main__':
    do()

Measured memory_bytes: 9364
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
#define MAX_N 10
vector<string>X[MAX_N][MAX_N];
int main() {
	int a, b, p[MAX_N];
	for (int h = 0; h <= MAX_N; h++) {
		for (int i = 0; i < (1 << h); i++) {
			for (int j = 0; j < h; j++) {
				p[j] = (i / (1 << j)) % 2;
			}
			int A = 0, B = 0, ok = 0;
			for (int j = 0; j < h; j++) {
				if (p[j] == 0) { A++; }
				if (p[j] == 1) { B++; }
				if (j == h - 1) { continue; }
				if (A >= 5 && B <= 3) { ok = 1; }
				if (A <= 3 && B >= 5) { ok = 1; }
			}
			if (ok == 0) {
				string T = ""; int ax = 0, bx = 0;
				for (int j = 0; j < h; j++) {
					if (p[j] == 0) { ax++; T += 'A'; }
					if (p[j] == 1) { bx++; T += 'B'; }
				}
				X[ax][bx].push_back(T);
			}
		}
	}
	for (int i = 0; i < MAX_N; i++) {
		for (int j = 0; j < MAX_N; j++) {
			sort(X[i][j].begin(), X[i][j].end());
		}
	}
	cin >> a >> b;
	for (int i = 0; i < X[a][b].size(); i++) {
		cout << X[a][b][i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1264
import java.util.Scanner;

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

            double result = n % 2 == 0 ? n / 2 : n / 2 + 1;

            System.out.println((long) result);

        }
    }

}

Measured memory_bytes: 21716
//
// Created by Alan on 9/6/2017.
//
#include <bits/stdc++.h>
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    if (a + b >= 10) {
        cout << "error" << endl;
    }
    else {
        cout << a + b << endl;
    }
}


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

int main()
{
    int n ;
    cin>>n;
    int t[n];
    int sum =0;
    for(int i=0;i<n;i++)
    {
        cin>>t[i];
        sum += t[i];
    }
    int m ;
    cin>>m;
    for(int i=0;i<m;i++)
    {
        int p , x;
        cin>>p>>x;
        int temp = sum;
        temp -= t[p-1];
        temp += x;
        cout<<temp<<endl;
    }

}

Measured memory_bytes: 3600
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)

max_1 = 0
len_a = len(A)
for i, a in enumerate(A):
    if len_a - i >= 4:
        if A[i] == A[i+1] and A[i+1] == A[i+2] and A[i+2] == A[i+3]:
            if max_1 == 0:
                print(A[i] ** 2)
                exit()
            else:
                print(A[i] * max_1)
                exit()
    if len_a - i >= 2:
        if A[i] == A[i+1]:
            if max_1 == 0:
                max_1 = A[i]
            else:
                if max_1 != A[i]:
                    print(A[i] * max_1)
                    exit()
print(0)

Measured memory_bytes: 14672
#include <iostream>
#include<vector>
#include<cmath>
#include<iomanip>
#define ll long long
using namespace std;
#define rep(n) for(int i=0;i<n;i++)
#define rep2(a,n) for(int i=a;i<=n;i++)
int main(void){
    // Your code here!
string s;
cin>>s;
int n= s.length();
rep2(1,n){
   if((i&1 && s[i-1]=='L') || !(i&1) && s[i-1]=='R'){
       cout<<"No";
       return 0;
   }
}
cout<<"Yes";

}


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

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

    int N;
    cin >> N;

    map<ll, ll> x;

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

    ll ans = 0;

    for(auto i = begin(x); i != x.end(); i++) {
        ll front = i -> first;
        ll back = i -> second;
        if(front < back) {
            ans += back - front;
        } else if(front > back) {
            ans += back;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 6272
import sys
# sys.setrecursionlimit(100000)


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


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n = input_int()
    dishes = []
    for i in range(n):
        a, b = input_int_list()
        dishes.append((a, b, a + b))
    # a+bの合計値でソートする
    dishes = sorted(dishes, key=lambda x: x[2])
    t_sum = 0
    a_sum = 0
    is_takahashi = True  # True => Tさんのターン
    while dishes:
        a, b, _ = dishes.pop()
        if is_takahashi:
            t_sum += a
        else:
            a_sum += b
        is_takahashi = not is_takahashi
    print(t_sum - a_sum)

    return


if __name__ == "__main__":
    main()


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

int main(){
    int A, B, C, D, E, K;
    cin >> A >> B >> C >> D >> E >> K;

    int a = max(A, B) - min(A, B);
    int b = max(A, C) - min(A, C);
    int c = max(A, D) - min(A, D);
    int d = max(A, E) - min(A, E);
    int e = max(B, C) - min(B, C);
    int f = max(B, D) - min(B, D);
    int g = max(B, E) - min(B, E);
    int h = max(C, D) - min(C, D);
    int i = max(C, E) - min(C, E);
    int j = max(D, E) - min(D, E);

    if(a <= K && b <= K && c <= K && d <= K && e <= K && f <= K && g <= K && h <= K && i <= K && j <= K){
        cout << "Yay!" << endl;
    }

    else{
        cout << ":(" << endl;
    }
}

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

using namespace std;

int main(){
    int count = 0 ;
    string a;
    cin >> a;
    if(a[0] == '1') ++count;
    if(a[1] == '1') ++count;
    if(a[2] == '1') ++count;

    cout<<count<<"\n";
    
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n,k;
    cin >> n >> k;
    vector<int32> h(n);
    REP(i,n)cin >> h[i];
    sort(ALL(h));
    int32 ans = INF;
    REP(i,n-k+1){
        ans = min(ans, h[i+k-1] - h[i]);
    }
    ANS(ans);
    return 0;
}

Measured memory_bytes: 1024
a,v = map(int, input().split())  #鬼
b,w= map(int, input().split())  #逃げる
t=int(input())

ans='NO'
kyo=abs(a-b)
so=abs(v-w)

if w>v:
    ans='NO'
elif w==v:
    ans='NO'
elif w<v:
    if kyo>t*so:
        ans='NO'
    elif kyo<=t*so:
        ans='YES'
        #if kyo%so==0:
            #ans='YES'
        #else:
            #ans='NO'
#print(kyo%so)
print(ans)



Measured memory_bytes: 9220
import math
n, m = map(int,input().split())
def a(n, l):
    return math.factorial(n) // ((math.factorial(n - l) * math.factorial(l)))
if n and m >1:
    print(a(n, 2)+a(m, 2))
elif n > 1:
    print(a(n, 2))
elif m > 1:
    print(a(m, 2))
else:
    print(0)

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

int main() {
  int a, b;
  cin >> a >> b;
  if (a >= 13) {
    cout << b << endl;
  } else if (a >= 6 && a <= 12 )  {
    cout << b / 2 << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}

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

int solve(int cur,vector<int> *gr,vector<int> &dp) {
    if(dp[cur]!=-1) {
        return dp[cur];
    }
    bool isLeaf = true;
    int best = 0;
    for(auto nbr : gr[cur]) {
        isLeaf = false;
        best = max(best,solve(nbr,gr,dp));
    }
    dp[cur] = (isLeaf)?0:1+best;
    return dp[cur];
}

int main() {
	int n,m;
	cin>>n>>m;
	vector<int> gr[n+1];
	for(int i=0;i<m;i++) {
	    int x,y;
	    cin>>x>>y;
	    gr[x].push_back(y);
	}
	vector<int> dp(n+1,-1);
	for(int i=1;i<=n;i++) {
	    if(dp[i]==-1) {
	        dp[i] = solve(i,gr,dp);
	    }
	}
	cout<<*max_element(dp.begin(),dp.end());
	return 0;
}


Measured memory_bytes: 11740
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    ans = 0
    for i in range(1,N+1):
        ans += i
    
    print(ans)
    
if __name__ == "__main__":
	main()


Measured memory_bytes: 38640
#include<stdio.h>

typedef struct{
  char mark;
  int value;
}CARD;

int main() {
  
  int i, j, n, minj, flag = 0;
  CARD a[100], b[100], temp;
  
  scanf("%d", &n);
  for(i = 0; i < n; i++) {
    scanf(" %c%d", &a[i].mark, &a[i].value);
    b[i] = a[i];
  }
  
  //Bubble
  for(i = 0; i < n; i++){
    for(j = n - 1; j != i; j--){
      if(a[j].value < a[j - 1].value){
        temp = a[j];
        a[j] = a[j-1];
        a[j-1] = temp;
      }
    }
  }
  for(i = 0; i < n; i++){
    printf("%c%d", a[i].mark, a[i].value);
    if(i < n-1) printf(" ");
    else printf("\n");
  }
  printf("Stable\n");

  //Select
  for(i = 0; i < n; i++){
    minj = i;
    for(j = i; j < n; j++){
      if(b[j].value < b[minj].value) {
	minj = j;
      }
    }
    temp = b[i];
    b[i] = b[minj];
    b[minj] = temp;
  }
  for(i = 0; i < n; i++){
    if(a[i].mark != b[i].mark) flag = 1;
  }
  for(i = 0; i < n; i++){
    printf("%c%d", b[i].mark, b[i].value);
    if(i < n-1) printf(" ");
    else printf("\n");
  }
  if(flag == 1) printf("Not stable\n");
  else printf("Stable\n");
  
  return 0;
}



Measured memory_bytes: 2144
#include<stdio.h>

int main()
{
	int number1[10000]={0},date1[10000]={0},number2[10000]={0},date2[10000]={0};
	int c1=0,c2=0,num[1000]={0},count[1000]={0},c3=0;
	char in[1000]={};
	int i,j,k;
	
	while(1)
	{
		fgets(in,sizeof(in),stdin);
		if(in[0]=='\n')break;
		number1[c1]=atoi(in);
		c1++;
	}
	while(scanf("%d,%d",&number2[c2],&date2[c2])!=EOF)c2++;
	
	for(i=0;i<c1;i++)
	{
		for(j=0;j<c2;j++)
		{
			if(number1[i]==number2[j])
			{
				if(count[c3]==0)num[c3]=number1[i];
				count[c3]++;
			}
		}
		c3++;
	}
	for(i=0;i<c3;i++)
	{
		for(j=i;j<c3;j++)
		{
			if(num[i]==num[j] && i!=j)
			{
				num[j]=0;
				count[j]=0;
				count[i]++;
			}
		}
	}
	
	for(i=0;i<c3;i++)
	{
		for(j=i;j<c3;j++)
		{
			if(num[i]>num[j])
			{
				k=num[i];
				num[i]=num[j];
				num[j]=k;
				
				k=count[i];
				count[i]=count[j];
				count[j]=k;
			}
		}
	}
	
	for(i=0;i<c3;i++)if(num[i]!=0)printf("%d %d\n",num[i],count[i]+1);
return 0;
}

Measured memory_bytes: 736
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 x = sc.nextInt();

		double s = (double) x / a;

		if (s < a * b / 2) {
			double h = (double) s / b * 2;
			double atan = b / h;
			double ans = Math.atan(atan);


			ans = Math.toDegrees(ans);

			System.out.println(ans);

		} else {
			double remain = a * b - s;
			double h = (double) remain / a * 2;
			double atan = h / a;

			double ans = Math.atan(atan);

			ans = Math.toDegrees(ans);

			System.out.println(ans);

		}

	}

}

Measured memory_bytes: 22996
N, M = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i).sort

top_a = a.last(M)
rest_a = a.first([a.size - M, 0].max) || []

sale_a = []

v = nil
M.times do
  if (top_a.last || 0) > (sale_a.last || 0)
    break if top_a.last.zero?
    v = top_a.pop / 2
  else
    break if sale_a.last.zero?
    v = sale_a.pop / 2
  end
  idx = sale_a.bsearch_index {|x| x >= v }
  if idx.nil?
    sale_a << v
  else
    sale_a.insert(idx, v)
  end
end

puts (top_a + sale_a + rest_a).inject(&:+)


Measured memory_bytes: 15344