akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
const int INF=1e9;
 
int N,M,Q;
char g[2005][2005];
int x[2005][2005],a[2005][2005];
int ex[2005][2005],b[2005][2005];
int ey[2005][2005],c[2005][2005];

int edgey(int i1,int j1,int i2,int j2){
    int cnt=c[i2][j2];
    if(i1==0&&j1>0) cnt-=c[i2][j1-1];
    if(j1==0&&i1>0) cnt-=c[i1][j2];
    if(j1>0&&i1>0){
        int s1=c[i2][j1-1];
        int s2=c[i1][j2]-c[i1][j1-1];
        cnt-=(s1+s2);
    }
    return cnt;
}

int edgex(int i1,int j1,int i2,int j2){
    int cnt=b[i2][j2];
    if(i1==0&&j1>0) cnt-=b[i2][j1];
    if(j1==0&&i1>0) cnt-=b[i1-1][j2];
    if(j1>0&&i1>0){
        int s1=b[i1-1][j2];
        int s2=b[i2][j1]-b[i1-1][j1];
        cnt-=(s1+s2);
    }
    return cnt;
}

int blue(int i1,int j1,int i2,int j2){
    int cnt=a[i2][j2];
    if(i1==0&&j1>0) cnt-=a[i2][j1-1];
    if(j1==0&&i1>0) cnt-=a[i1-1][j2];
    if(j1>0&&i1>0){
        int s1=a[i1-1][j1-1];
        int s2=a[i1-1][j2]-s1;
        int s3=a[i2][j1-1]-s1;
        cnt-=(s1+s2+s3);
    }
    return cnt;
}

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

for(int i=0; i<N; i++) scanf("%s",&g[i]);

for(int i=0; i<N; i++){
    for(int j=0; j<M; j++){
        if(j>0) x[i][j]=x[i][j-1];
        if(g[i][j]-'0') x[i][j]++;
    }
}
for(int j=0; j<M; j++) a[0][j]=x[0][j];
for(int i=0; i<N-1; i++){
    for(int j=0; j<M; j++){
        a[i+1][j]=a[i][j]+x[i+1][j];
    }
}
for(int i=0; i<N; i++){
    for(int j=1; j<M; j++){
        ex[i][j]=ex[i][j-1];
        if(g[i][j]-'0'&&g[i][j-1]-'0') ex[i][j]++;
    }
}
for(int j=0; j<M; j++) b[0][j]=ex[0][j];
for(int i=0; i<N-1; i++){
    for(int j=0; j<M; j++){
        b[i+1][j]=b[i][j]+ex[i+1][j];
    }
}
for(int i=1; i<N; i++){
    for(int j=0; j<M; j++){
        ey[i][j]=ey[i-1][j];
        if(g[i][j]-'0'&&g[i-1][j]-'0') ey[i][j]++;
    }
}
for(int i=0; i<N; i++) c[i][0]=ey[i][0];
for(int i=0; i<N; i++){
    for(int j=0; j<M-1; j++){
        c[i][j+1]=c[i][j]+ey[i][j+1];
    }
}

for(int i=0; i<Q; i++){
    int i1,j1,i2,j2;
    scanf("%d %d %d %d",&i1,&j1,&i2,&j2);
    i1--; j1--; i2--; j2--;
    int ans=blue(i1,j1,i2,j2)-edgex(i1,j1,i2,j2)-edgey(i1,j1,i2,j2);
    printf("%d\n",ans);
}

}

Measured memory_bytes: 99968
class FenwickTree:
    def __init__(self, n, init_list=None):
        self.n = n
        self.data = [0] * n
        if init_list:
            assert n == len(init_list)
            for i in range(n):
                self.add(i, init_list[i])
        
    def add(self, i, val):
        assert 0 <= i < self.n
        i += 1
        while i <= self.n:
            self.data[i - 1] += val
            i += i & -i #LSBを加算して上の層へ
            
    def update(self, i, val):
        self.add(i, val - self.sum(i, i+1))

    def sum(self, l, r):
        assert  0 <= l <= r <= self.n
        if l != 0:
            return self.sum(0, r) - self.sum(0, l)
        ret = 0
        while r > 0:
            ret += self.data[r - 1]
            r -= r & -r #LSB減算して上の層へ
        return ret

n, q = map(int, input().split())
a = list(map(int, input().split()))
ft = FenwickTree(n, a)
ans = []
for _ in range(q):
    i, l, r = map(int, input().split())
    if i == 0:
        ft.add(l, r)
    else:
        ans.append(ft.sum(l, r))

for x in ans:
    print(x)

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

int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    for(int i = 0; i < n; i++){
        cin >> p.at(i);
    }
    int count = 0;
    for(int i = 0; i < n-1; i++){
        if(p.at(i) != i+1){
            count++;
        }
    }
    if(count <= 2){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

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

int main()
{
    //put here bitch 
    int n; cin>>n;
    int a[100001],b[100001],c[100001];
    for(int i=0;i<n;i++) cin>>a[i]>>b[i]>>c[i];
    int dp[100001][5];
    dp[0][1]=a[0],dp[0][2]=b[0],dp[0][3]=c[0];
    
    for(int i=1;i<n;i++)
    {
        dp[i][1]=a[i]+max(dp[i-1][2],dp[i-1][3]);
        dp[i][2]=b[i]+max(dp[i-1][1],dp[i-1][3]);
        dp[i][3]=c[i]+max(dp[i-1][1],dp[i-1][2]);
    }
    cout<<max(dp[n-1][1],max(dp[n-1][2],dp[n-1][3]))<<endl;
}

Measured memory_bytes: 3328
(X, Y, A, B, C), Ps, Qs, Rs = readlines.map{|l| l.split.map(&:to_i)}

class PriorityQueue
  def initialize
    @q = [nil]
  end

  def bubble_up(i)
    pi = i / 2
    return if i <= 1 || @q[pi] <= @q[i]
    @q[i], @q[pi] = @q[pi], @q[i]
    bubble_up(pi)
  end

  def add(e)
    @q << e
    bubble_up(@q.size - 1)
  end

  def bubble_down(i)
    ci = i * 2
    return if ci > @q.size - 1
    ci += 1 if ci != @q.size - 1 && @q[ci] > @q[ci + 1]
    return if @q[i] <= @q[ci]
    @q[i], @q[ci] = @q[ci], @q[i]
    bubble_down(ci)
  end

  def pop
    @q[1], @q[-1] = @q[-1], @q[1]
    ret = @q.pop
    bubble_down(1)
    ret
  end

  def head
    @q[1]
  end

  def sum
    @q.drop(1).inject(:+)
  end
end

pq = PriorityQueue.new
Ps.sort.reverse.take(X).each{|p| pq.add(p)}
Qs.sort.reverse.take(Y).each{|q| pq.add(q)}
rs = Rs.sort
while !rs.empty? && rs.last > pq.head
  pq.pop
  pq.add(rs.pop)
end
puts pq.sum

Measured memory_bytes: 28160
import java.io.FileNotFoundException;
import java.util.Scanner;

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

//    	File file = new File("src/in.txt");
//    	Scanner sc = new Scanner(file);

    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	int K = sc.nextInt();
    	int[] A = new int[N];
    	for(int i=0;i<K;i++) {
    		int d = sc.nextInt();
    		for(int j=0;j<d;j++) {
    			int x = sc.nextInt();
    			A[x-1] ++;
    		}
    	}
    	int ans = 0;
    	for(int i=0;i<N;i++) {
    		if(A[i]==0) {
    			ans++;
    		}
    	}
    	System.out.println(ans);
    }
}

Measured memory_bytes: 37528
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> L(N);
	for (int i = 0; i < N; ++i) { cin >> L[i]; }

	int ans = 0;
	for (int i = 0; i < N; ++i) {
		for (int j = i + 1; j < N; ++j) {
			for (int k = j + 1; k < N; ++k) {
				if (L[i] == L[j]) { continue; }
				if (L[i] == L[k]) { continue; }
				if (L[k] == L[j]) { continue; }
				if (L[i] + L[j] <= L[k]) { continue; }
				if (L[j] + L[k] <= L[i]) { continue; }
				if (L[k] + L[i] <= L[j]) { continue; }
				++ans;
			}
		}
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 3624
//C
#include <cassert>
//#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//ここまで標準include

using namespace std;

long aCb(long a, long b) {
	long out = 1;
	for (long i = 1; i <= b; i++) {
		out = out * (a + 1 - i) / i;
	}
	return out;
}

long long gcd(long long a, long long b) {
	long long r = -1;
	if (a < b) {
		swap(a, b);
	}
	while (r != 0) {
		r = a % b;
		if (r == 0) {
			return b;
		}
		else {
			a = b;
			b = r;
		}
	}
}

long long lcm(long long a, long long b) {
	return a * b / gcd(a, b);
}

int main() {
	int n;
	cin >> n;
	cout << n * (1 + n) / 2 << endl;
}


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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
template <typename T> using vec = vector<T>;
typedef vec<int> vi;
typedef vec<ll> vl;


template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }

int n,k;
string s;

int main()
{
  cin >> n >> k >> s;

  int d = 0;
  for (int i = 1; i < n; i++) {
    if (s[i-1] != s[i]) d++;
  }

  int c = d/2;
  int x = min(c,k);
  d -= 2*x;
  k -= x;

  if (k > 0 && d > 0) d--;

  cout << n-1-d << endl;

  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>
#include <deque>
#define pb push_back
#define make make_pair
#define kaku(a) cout << a << endl
#define isort(a) sort(a.begin(),a.end())

using namespace std;

#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define PI 3.14159265359
long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}
long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}

typedef pair<ll,ll> Pair;
const ll inf =1000000007;

void dsolve(){
    ll x;
    cin >> x;
    ll a,b;
    for(ll i=1;i<=2000;i++){
        for(ll j=-2000;j<2000;j++){
            ll score=pow(i,5)-pow(j,5);
            if(score==x){
                a=i;
                b=j;
                break;
            }
        }
    }
    cout << a <<" "<< b<< endl;
}

void bsolve(){
    ll n,k;
    cin >> n >>k;
    ll w[n];
    rep(i,n) w[i]=0;
    rep(i,k){
        ll d;
        cin>>d;
        rep(j,d){
            ll a;
            cin >>a;
            a--;
            w[a]++;
        }
    }
    ll ans=0;
    rep(i,n){
        if(w[i]==0){
            ans++;
            //kaku(i);
        }
    }
    kaku(ans);
}

void asolve(){
    string s;
    cin >>s;
    if(s=="ABC"){
        cout <<"ARC" << endl;
    }
    else{
        cout <<"ARC" << endl;
    }
}

void csolve(){
    ll n,m;
    cin >> n >>m;
    ll h[n];
    rep(i,n) cin >> h[i];
    vector<ll> g[n];
    Pair ma[n];
    rep(i,n) ma[i]=make(h[i],1);
    rep(i,m){
        ll a,b;
        cin >>a >>b;
        a--;b--;
        g[a].pb(b);
        g[b].pb(a);
        if(ma[a].first<h[b]) ma[a]=make(h[b],1);
        else if(ma[a].first==h[b]) ma[a]=make(h[b],0);
        if(ma[b].first<h[a]) ma[b]=make(h[a],1);
        else if(ma[b].first==h[a]) ma[b]=make(h[a],0);
    }
    ll ans=0;
    for(ll i=0;i<n;i++){
        if(ma[i].first==h[i]&& ma[i].second==1) ans++;
    }
    kaku(ans);
}
int main() {
   csolve();
}






Measured memory_bytes: 11744
import sys
input = sys.stdin.readline
import numpy as np
def print_ans(A, B, K):
    """Test Case
    >>> print_ans(8, 12, 2)
    2
    >>> print_ans(100, 50, 4)
    5
    >>> print_ans(1, 1, 1)
    1
    """
    counter = 0
    for i in range(1, min(A, B) + 1)[::-1]:
        if A % i == 0 and B % i == 0:
            counter += 1
        if counter == K:
            print(i)
            break


if __name__ == '__main__':
    A, B, K = map(int, input().rstrip().split())
    print_ans(A, B, K)


Measured memory_bytes: 12480
using System;
using System.Collections.Generic;

namespace AOJ.Volume0
{
    class Program0005
    {
        static void Main(string[] args)
        {
            string input;
            Queue<int[]> queue = new Queue<int[]>();

            while ((input = Console.ReadLine()) != null)
            {
                string[] splitedInput = input.Split(' ');
                int[] param = new int[2];

                for (int i = 0; i < 2; i++)
                {
                    param[i] = int.Parse(splitedInput[i]);
                }

                int maxKoyaku, minKobai;
                maxKoyaku = GetMaxKoyaku(param[0], param[1]);
                minKobai = GetMinKobai(param[0], param[1], maxKoyaku);

                queue.Enqueue(new[] { maxKoyaku, minKobai });
            }

            foreach (var ans in queue)
            {
                Console.WriteLine("{0} {1}", ans[0], ans[1]);
            }
        }

        static int GetMaxKoyaku(int x, int y)
        {
            int maxKoyaku = 1;

            for (int i = 2; i <= Math.Min(x,y); i++)
            {
                if (x % i == 0 && y % i == 0)
                {
                    maxKoyaku = i;
                }
            }

            return maxKoyaku;
        }

        static int GetMinKobai(int x, int y, int maxKoyaku)
        {
            long kobai = Math.BigMul(x, y);
            return (int)(kobai / maxKoyaku);
        }
    }
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

ll dp[100010][3];
const ll mod = 1e9+7;

int main() {
    string s;
    cin >> s;

    ll all = 1;

    for (int i=1; i<=s.size(); ++i) {
        if (s[i-1] == '?') {
            for (int j=0; j<3; ++j) {
                if (j == 0) dp[i][j] = dp[i-1][j]*3LL+all;
                else dp[i][j] = dp[i-1][j]*3LL + dp[i-1][j-1];
                dp[i][j]%=mod;
            }
            all *= 3;
            all %= mod;
        }
        else {
            int cur = s[i-1]-'A';
            for (int j=0; j<3; ++j) {
                if (cur == j) {
                    if (j == 0) dp[i][j] = dp[i-1][j]+all;
                    else dp[i][j] = dp[i-1][j-1]+dp[i-1][j];
                }
                else {
                    dp[i][j] = dp[i-1][j];
                }
                dp[i][j] %= mod;
            }
        }
    }
    // for (int i=0; i<=s.size(); ++i) {
    //     for (int j=0; j<3; ++j) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    cout << dp[s.size()][2]%mod << endl;
}


Measured memory_bytes: 2816
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <set>
#include <map>
#include <functional>
using namespace std;
#define pb          emplace_back
#define fi          first
#define se          second
#define show(...)   fprintf(stderr, __VA_ARGS__ )
#define outl(x)     cout << (x) << '\n'
#define outl2(x,y)  cout << (x) << ' ' << (y) << '\n'
#define endl        '\n'
#define rep(i,n)    for(int i=0; i<(n); ++i)
#define ALL(x) x.begin(), x.end()
template<class A, class B>inline bool chmax(A &a, B b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, B b){return b<a ? a=b,1 : 0;}
inline bool inside(int x, int y, int W, int H) { return x>=0 && y>=0 && x<W && y<H; }
typedef long long ll;
typedef pair<int,int> pii;
static constexpr int       INF  = 0x3f3f3f3f;
static constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static constexpr int dx[] = {1, 0, -1, 0};
static constexpr int dy[] = {0, 1, 0, -1};


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

    int N;
    bool ok = true;

    set<string> S;

    string s, before;
    cin >> N >> s;

    before = s;
    S.insert(s);

    rep(i, N-1) {

        cin >> s;
        if (S.count(s) != 0 || s.front() != before.back()) {
            ok = false;
        }
        S.insert(s);
        before = s;
    }

    outl(ok? "Yes" : "No");

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define vll vector<ll>
#define pii pair<ll,ll>
#define sz(v) (v).size()
#define srt(v) sort(v.begin(),v.end())
#define ull unsigned long long
#define tell(a) cout<<a<<" "
#define el cout<<endl
#define rev(v) reverse(v.begin(),v.end())
#define rep(i,a,n) for(int i=a;i<n;i++)
#define M 1000000007
ll power(ll x, ll y, ll p){ll res = 1;x = x % p;while (y > 0){   if (y & 1)res = (res*x) % p;y = y>>1;
x = (x*x) % p;}return res;}



int main()
{
	IOS;
	ll n,m,x;
	cin>>n>>m>>x;
	int v[n][m+1];
	for(int i=0;i<n;i++)
	for(int j=0;j<=m;j++)cin>>v[i][j];
	ll ans=INT_MAX;	
	for(int i=0;i<(1LL<<n);i++)
	{
		ll dp[m]={0},pp=0;
		for(int j=0;j<n;j++)
		{
			if((1LL<<j)&i)
			{
				rep(k,1,m+1)dp[k-1]+=v[j][k];
				pp+=v[j][0];
			}
		}
		int c=1;
		rep(k,0,m)
		if(dp[k]<x)
		{
			c=0;break;
		}
		if(c)
		{
			ans=min(ans,pp);
		}
	}
	if(ans==INT_MAX)ans=-1;
	cout<<ans;
}



Measured memory_bytes: 3632
l,r=list(map(int,input().split()))
s=[]
import sys

if r-l>2050:
  print(0)
  sys.exit()
else:
  for i in range(l,r+1):
    s.append(i%2019)

n=len(s)
ans=30000
for i in range(n-1):
  for j in range(i+1,n):
    ans=min(ans,(s[i]*s[j])%2019)


print(ans)

  
  
  

Measured memory_bytes: 9192
#include<iostream>
#include<stdio.h>

int main(){
  int H,W,i,j;
  while(true){
    scanf("%d %d",&H,&W);
    if(H==0 && W==0)break;
    for(i=0;i<H;i++){
      for(j=0;j<W;j++){
        printf("#");
      }
      printf("\n");
    }
    printf("\n");

  }
  return 0;
}


Measured memory_bytes: 3136
#include<iostream>
using namespace std;
long long n,a[200010],b[200010],ans;
int main()
{
	cin>>n;
  
	for(int i=1;i<=n;i++)
		cin>>a[i];
  
	for(int i=n;i>=1;i--)	
	{
		int h=0;
      
		for(int j=2*i;j<=n;j += i)
			if(b[j]==1)
              
				h++;	
      
		if(h%2!=a[i])
		{
			b[i]=1;
			ans++;
		}		
	}
  
	cout<<ans<<endl;
  
	for(int i=1;i<=n;i++)
      
		if(b[i]==1)
			cout<<i<<" ";
  
	cout<<endl;	
  
} 


Measured memory_bytes: 3968
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;


public class Main {
    final static long MOD = 1000000007;

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int n = fs.nextInt();
        int a[] = fs.nextIntArray(n);

        int dp[] = new int[n+1];

        dp[0] = 0;

        for(int i = 1; i < n; i++) {
            dp[i] = Math.min(dp[i-1] + Math.abs(a[i-1] - a[i]), i-2 >= 0 ?  dp[i-2] + Math.abs(a[i-2] - a[i]) : Integer.MAX_VALUE);
        }

        out.println(dp[n-1]);

        out.flush();
        out.close();
    }


    public static String rString(String s) {
        return new StringBuilder(s).reverse().toString();
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                // br = new BufferedReader(new FileReader("chat.txt"));
                st = new StringTokenizer("");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        public String next() {
            if (st.hasMoreTokens())
                return st.nextToken();
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                e.printStackTrace();
            }
            return st.nextToken();
        }

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

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

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

        public String nextLine() {
            String line = "";
            try {
                line = br.readLine();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return line;
        }

        public char nextChar() {
            return next().charAt(0);
        }

        public Integer[] nextIntegerArray(int n) {
            Integer[] a = new Integer[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }

        public char[] nextCharArray() {
            return nextLine().toCharArray();
        }
    }

}





Measured memory_bytes: 31820
A, B, C = map(int,input().split())
ABC = sorted([A,B,C])
counter = 0
for i in range(ABC[1],ABC[2]):
    ABC[0] += 1
    ABC[1] += 1
    counter += 1
while(ABC[0]+2<=ABC[1]):
    ABC[0] += 2
    counter += 1
if ABC[0]!=ABC[1]:
    ABC[1] += 1
    ABC[2] += 1
    counter += 1
    ABC[0] += 2
    counter += 1
print(counter)

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i > b; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define int long long

typedef long long ll;
typedef pair<int, int> Pair;

const int kMaxN = 2*100000;

int N;
int A[kMaxN];
int ans = 1000000000;

signed main() {
  cin >> N;
  REP(i, N) { cin >> A[i]; }
  REP(i, N-1) { A[i+1] += A[i]; }

  int a = 1;
  int c = 3;
  REP(i, N-3) {
    int b = i+2;
    while (a+1 < b) {
      if (ABS(A[a-1] - (A[b-1]-A[a-1])) >= ABS(A[a] - (A[b-1]-A[a]))) {
        ++a;
      } else {
        break;
      }
    }
    while (c+1 < N) {
      // printf("%lld %lld %lld %lld\n", a, b, c, N);
      if (ABS((A[c-1]-A[b-1]) - (A[N-1]-A[c-1]))
        >= ABS((A[c]-A[b-1]) - (A[N-1]-A[c]))) {
          ++c;
      } else {
        break;
      }
    }
    int max = MAX(A[a-1],
      MAX(A[b-1]-A[a-1], MAX(A[c-1]-A[b-1], A[N-1]-A[c-1])));
    int min = MIN(A[a-1],
      MIN(A[b-1]-A[a-1], MIN(A[c-1]-A[b-1], A[N-1]-A[c-1])));
    ans = MIN(ans, max-min);
  }

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


Measured memory_bytes: 1792
import java.util.*;

public class Main {
		public static int N;
		public static long K;
		public static int A[];
		public static Integer F[];
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		K = sc.nextLong();// 修行回数
		A = new int[N];// 消化コスト
		F = new Integer[N];// 食べにくさ
		for (int i = 0; i < N; i++) A[i] = sc.nextInt();
		for (int i = 0; i < N; i++) F[i] = sc.nextInt();
		
		// 消化コストが高い人と、食べにくさが低い食べ物をマッチングする。
		Arrays.sort(A);
		Arrays.sort(F, Collections.reverseOrder());
		for(int i=0;i<N;i++) F[i]=F[i].intValue();
			//降順に並び替えるための手順
		
		//N個の組み合わせについて、それらの最大値がXを下回るようにする。
		//二分探索します。
		//調べたい範囲の一番左以下と、一番右以上の何かをleftとrightで定義する。
		long l = -1; long r = (long)Math.pow(10,12);
		while(l+1<r) {
			long c = l+(r-l)/2;//これがオーバーフローしないための書き方
			if(func(c)==true) r=c; else l=c;//if文を１行で書く	
		}
		System.out.println(r);
	}
	static boolean func(long c) {
		long sum=0;
		for(int i=0;i<N;i++) sum += Math.max(A[i]-c/F[i],0);		
		return sum<=K;
	}
}

Measured memory_bytes: 106916
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define S 10001
#define M 1000000007
#define nl cout<<"\n";
#define error  cout<<"\n***********\n";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define debug(x) cerr << #x << " is " << x << endl;
#define test lli t;  cin>>t; while(t--)
int main()
{
    lli i,j,n;
    cin>>n;
    lli a[n+1];
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    lli dp[n+1];
    dp[1]=0;
    dp[2]=abs(a[2]-a[1]);
    for(i=3;i<=n;i++)
    {
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    }
    cout<<dp[n];
}

Measured memory_bytes: 1792
import sys
input = sys.stdin.readline
n, k = [ int(v) for v in input().split() ]
card_parent = [ i for i in range(n) ]
card_set = [ set([i]) for i in range(n) ]
card_list = [ tuple( int(v)-1 for v in input().split() ) for i in range(k) ]

def parent(x,a):
    if card_parent[x] == x:
        return x, a
    else:
        return parent(card_parent[x],a+1)


for i in card_list:
    p, q = i[0], i[1]
    card_parent[p], rank_p = parent(p,0)
    card_parent[q], rank_q = parent(q,0)
    if card_parent[p] != card_parent[q]:
        if rank_p > rank_q:
            card_parent[card_parent[q]] = card_parent[p]
        else:
            card_parent[card_parent[p]] = card_parent[q]




card_parent = [ parent(i,0)[0] for i in range(n) ]

print(len(set(card_parent)))


Measured memory_bytes: 137120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define cu continue
#define br break
#define pb push_back
#define mod 1000000007
#define inf LLONG_MAX
#define pll pair <ll,ll>
#define min_pq priority_queue <pll> ,vector <pll>, greater <pll> > > 
#define F first
#define S second
#define vll vector <ll>
#define dbg(n) cout<<#n<<' '<<n<<endl;

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


    ll n,m;
    cin>>n>>m;
    ll x,s=0;
    for(ll i=0;i<m;i++)
    {
    	cin>>x;
    	s+=x;
    }
    n-=s;
    if(n<0) n=-1;
    cout<<n<<'\n';
}      

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
#define arrlen(arr) (sizeof(arr)/sizeof(arr[0]))
#define Sort(arr) sort(arr, arr+arrlen(arr))
#define For(i,s,n) for(ll i=s;i<n;i++)
	
int main(){
	ll N,M;
	cin >> N >> M;
	ll a[M+2];
	a[0]=-1;
	a[M+1]=N+1;
	For(i,1,M+1) cin >> a[i];
	
	ll f[N+3];
	f[0]=0;
	f[1]=1;
	For(i,2,N+2){
		f[i]=f[i-1]+f[i-2];
		f[i]%=1000000007;
	}
	
	ll ans=1;
	For(i,1,M+2){
		ans*=f[a[i]-a[i-1]-1];
		//cout << a[i]-a[i-1]-1 << endl;
		ans%=1000000007;
	}
	cout << ans;
}

Measured memory_bytes: 1792
Module Module1

    Sub Main()
        Dim arr() As Integer = Array.ConvertAll(Of String, Integer)(Console.ReadLine.Split(" "), AddressOf Integer.Parse)
        Dim n, y As Integer
        n = arr(0) : y = arr(1)
        Dim a As Integer = -1
        Dim b As Integer = -1
        Dim c As Integer = -1

        For i As Integer = 0 To n
            For j As Integer = 0 To n
                Dim k As Integer = n - i - j
                If k >= 0 AndAlso i * 10000 + j * 5000 + k * 1000 = y Then
                    a = i : b = j : c = k
                End If
            Next
        Next
        Console.WriteLine(a.ToString + " " + b.ToString + " " + c.ToString)
    End Sub

End Module


Measured memory_bytes: 27608
import java.util.HashSet;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int n = sc.nextInt();
		HashSet<Integer> p = new HashSet<Integer>();
		for (int i = 0; i < n; ++i) {
			p.add(sc.nextInt());
		}

		int minAbs = 200;
		int ans = 0;
		for (int possible = 0; possible <= 101; ++possible) {
			if (p.contains(possible)) {
				continue;
			}

			int abs = Math.abs(possible - x);
			if (abs < minAbs) {
				minAbs = abs;
				ans = possible;
			}
		}

		System.out.println(ans);
	}
}


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

int main(){
    ll n, p;
    cin >> n >> p;

    ll ans  = 1;
    double t = 1.0 / n;
    ll now = pow(p , t) + 1;
    while(1){
        ll k = pow(now, n);
        if(p % k == 0){
            ans = now;
            break;
        }
        now--;    
    }

    cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using ll = long long;
// #define int ll
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, int(n) + 1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)
const int MOD = 1000000007;

template <typename T>
void __print__(std::ostream &os, const char *, const char *tail, const T &fst) {
    os << fst << tail;
}
template <typename Fst, typename... Rst>
void __print__(std::ostream &os, const char *del, const char *tail, const Fst &fst,
               const Rst &... rst) {
    os << fst << del;
    __print__(os, del, tail, rst...);
}

#ifdef LOCAL
#define dump(...)                                         \
    do {                                                  \
        std::ostringstream os;                            \
        os << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; \
        __print__(os, ", ", "\n", __VA_ARGS__);           \
        std::cerr << os.str();                            \
    } while (0)
#else
#define dump(...)
#endif

template <typename Fst, typename... Rst>
void println(const Fst &fst, const Rst &... rst) {
    __print__(std::cout, "\n", "\n", fst, rst...);
}
template <typename Fst, typename... Rst>
void print(const Fst &fst, const Rst &... rst) {
    __print__(std::cout, " ", "\n", fst, rst...);
}

template <typename iter>
void println_(iter bgn, iter end) {
    while (bgn != end) println(*bgn++);
}

template <typename iter>
void print_(iter bgn, iter end) {
    while (bgn != end) {
        std::cout << *bgn++;
        std::cout << (bgn == end ? "\n" : " ");
    }
}

int _ = (std::cout.precision(10), std::cout.setf(std::ios::fixed), std::cin.tie(0),
         std::ios::sync_with_stdio(0), 0);

template <typename T>
std::vector<T> ndarray(int n, T v) {
    return std::vector<T>(n, v);
}
template <typename... Args>
auto ndarray(int n, Args... args) {
    auto val = ndarray(args...);
    return std::vector<decltype(val)>(n, move(val));
}

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

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

using namespace std;

string a, b;

vector<int> sub(string S, string s) {
    vector<int> idx;
    int i = 0;
    for (char c : s) {
        while (i < (int)S.size() && S[i] != c) ++i;
        if (i == (int)S.size()) return {};
        idx.push_back(i);
        ++i;
    }
    return idx;
}

bool solve() {
    vector<int> org = sub(a, b);
    if (org.size() == 0) return false;
    reverse(all(a));
    reverse(all(b));
    vector<int> rev = sub(a, b);
    // print_(all(org));
    reverse(all(rev));
    // print_(all(rev));
    rep(i, rev.size()) {
        dump(org[i], rev[i], a.size() - 1);
        if (org[i] + rev[i] != (int)a.size() - 1) return false;
    }
    return true;
}

int main() {
    while (cin >> a >> b) {
        print(solve() ? "yes" : "no");
    }
}

Measured memory_bytes: 9772
n=int(input())
x=list(map(int,input().split()))

def wa(avg):
    max=0
    for i in range(len(x)):
        s=x[i-1]-avg
        max=max+s**2
    return max


maxj=1000000
max=wa(1)
avg=2
while maxj>max:
    maxj=max
    max=wa(avg)
    avg=avg+1
print(maxj)


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

int main()
{
  int n,k,ans = 0;
  cin >> n >> k;
  int sum = 1;
  while(sum < k){
    sum--;
    sum+=n;
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3584
# ABC143D - Triangles
def binary_search(cur: int, upper_bound: int = 1 << 60, lower_bound: int = -1) -> int:
    ok, ng, ret = upper_bound, lower_bound, 0
    while abs(ok - ng) > 0:
        if L[ok] + L[ng] > cur:
            ret += ok - ng
            ok -= 1
        else:
            ng += 1
    return ret


def main():
    # fix the longest edge -> binary search
    global L
    N, *L = map(int, open(0).read().split())
    L.sort()
    ans = sum(binary_search(L[i], i - 1, 0) for i in range(N - 1, 1, -1))
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
#[allow(unused_imports)]
use {
   proconio::{fastout, input, marker::*},
   std::cmp::*,
   std::collections::*,
};

#[fastout]
fn main() {
   input! {
      n: usize,
      k: usize,
      l: usize,
      pk: [(Usize1, Usize1); k],
      rs: [(Usize1, Usize1); l]
   }
   let mut uf1 = (0..n).collect::<Vec<_>>();
   let mut uf2 = (0..n).collect::<Vec<_>>();
   for &(p, k) in pk.iter() {
      uf1.unite(p, k);
   }
   for &(r, s) in rs.iter() {
      uf2.unite(r, s);
   }

   let mut map = BTreeMap::<(usize, usize), Vec<usize>>::new();
   for i in 0..n {
      map.entry((uf1.root(i), uf2.root(i)))
         .and_modify(|v| v.push(i))
         .or_insert(vec![i]);
   }

   let mut ans = vec![0; n];
   for v in map.values() {
      let n = v.len();
      for &i in v.iter() {
         ans[i] = n;
      }
   }

   for &a in ans.iter() {
      print!("{} ", a);
   }
}

trait UnionFind {
   fn unite(&mut self, x: usize, y: usize);
   fn same(&mut self, x: usize, y: usize) -> bool;
   fn root(&mut self, x: usize) -> usize;
}
impl UnionFind for [usize] {
   fn unite(&mut self, x: usize, y: usize) {
      let rx = self.root(x);
      let ry = self.root(y);
      if rx == ry {
         return;
      }
      self[ry] = rx;
   }
   fn same(&mut self, x: usize, y: usize) -> bool { self.root(x) == self.root(y) }
   fn root(&mut self, x: usize) -> usize {
      if self[x] == x {
         x
      } else {
         self[x] = self.root(self[x]);
         self[x]
      }
   }
}


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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 998244353;
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;}


int main() {
  int n, s;
  cin >> n >> s;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  vector<mint> dp(s+1);
  dp[0] = 1;
  rep(i,n) {
    vector<mint> p(s+1);
    swap(dp,p);
    rep(j,s+1) {
      dp[j] += p[j]*2;
      if (j+a[i] <= s) dp[j+a[i]] += p[j];
    }
  }
  cout << dp[s] << endl;
  return 0;
}

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

int main() {
  // abが偶数か奇数か求める。
  //奇数ならOdd、偶数ならEvenと出力する。
  
  int a, b, x;
  cin >> a >> b;
  //a = 1, b = 21;
  
  x = (a * b) % 2;
  	if  (x == 0) {
      cout << "Even" << endl;
  	}
  	else {
      cout << "Odd" << endl;
	}
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int k;
vector<ll> a(100000);
int MOD=1000000007;
vector<ll> memo(100000);
vector<ll> memo_inv(100000);


ll combination(int i,int j);
long long modinv(long long a,long long m);

ll nmod(ll a) {
    return ((a % MOD < 0) ? a % MOD + MOD : a % MOD);
}

int main(){
  cin >> n;
  cin >> k;
  for(int i=0;i<n;i++){
    cin >> a.at(i); 
  }
  memo.at(0)=1;
  for(int i=1;i<n;i++){
    memo.at(i)=nmod(memo.at(i-1)*(i));
  }
  for(int i=0;i<n;i++){
    memo_inv.at(i)=modinv(memo.at(i),MOD);
  }



  sort(a.begin(),a.begin()+n);
  reverse(a.begin(),a.begin()+n);
  ll ans=0;
  for(int i=0;i<n;i++){
    int p = n-i-1;
    if(p>=k-1){
      ll c = combination(p,k-1);
      ans = nmod(ans + nmod(c*a.at(i)));
    }
  }
  reverse(a.begin(),a.begin()+n);
  for(int i=0;i<n;i++){
    int p=n-i-1;
    if(p>=k-1){
      ll c = combination(p,k-1);
      ans = nmod(ans + nmod(-c*a.at(i)));
    }
  }
  cout << ans << endl;
}

ll combination(int i,int j){
  ll n_kai = memo.at(i);
  ll r_kai = memo_inv.at(j);
  ll n_r_kai = memo_inv.at(i-j);
  return nmod((nmod(n_kai*r_kai))*n_r_kai);
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

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

int main(){
	// sengen
	int x;
	// nyuryoku
	cin >> x;
	// keisan
	if(x > 29){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	// syutsuryoku
}

Measured memory_bytes: 3620
from __future__ import annotations

import itertools
import unittest
from dataclasses import dataclass, field, InitVar
from typing import List


def create_order_patterns(n: int):
    return itertools.product(range(2), repeat=n)


@dataclass
class Book:
    id: int
    price: int
    algorithm_points: List[int]


@dataclass
class TakahashiKun:
    border_line: int
    number_of_types_of_algorithms: InitVar[int]
    purchase_amount: int = 0
    algorithm_points: List[int] = field(init=False)

    def __post_init__(self, number_of_types_of_algorithms: int):
        # 何の本も読んでない高橋くんは各種アルゴリズムの理解度が0である！
        self.algorithm_points = [0 for _ in range(number_of_types_of_algorithms)]

    def buy_and_read(self, book: Book) -> None:
        # 高橋くんは本を読むと強くなる！
        self.purchase_amount += book.price

        self.algorithm_points = [p1 + p2 for p1, p2 in zip(self.algorithm_points, book.algorithm_points)]

    def has_read_at_least_one_book(self) -> bool:
        return self.purchase_amount > 0

    def passed_border_line(self) -> bool:
        return all([p >= self.border_line for p in self.algorithm_points])


@dataclass
class TakahashiKunCollection:
    values: List[TakahashiKun] = field(default_factory=list)

    def add(self, single_result: TakahashiKun) -> None:
        self.values.append(single_result)  # メモリ優先

    def min_purchase_amount_required_pass(self) -> int:
        passed_takahashi_list = [takahashi for takahashi in self.values if takahashi.passed_border_line()]

        if not passed_takahashi_list:
            return -1

        return min([takahashi.purchase_amount for takahashi in passed_takahashi_list])

    @staticmethod
    def create(number_of_types_of_algorithms: int,
               border_line: int, 
               book_lineup: List[Book], 
               order_patterns) -> TakahashiKunCollection:
        
        takahashi_kun_collection = TakahashiKunCollection()

        for order in order_patterns:
            single_result = TakahashiKun(border_line, number_of_types_of_algorithms)

            for idx, is_buy in enumerate(order):
                if is_buy == 1:
                    single_result.buy_and_read(book_lineup[idx])

            if single_result.has_read_at_least_one_book():
                takahashi_kun_collection.add(single_result)

        return takahashi_kun_collection


def actual(N, M, X, books_info):
    book_lineup = []

    for idx, book_info in enumerate(books_info, start=1):
        book = Book(id=idx, price=book_info[0], algorithm_points=book_info[1:])
        book_lineup.append(book)

    results = TakahashiKunCollection.create(N, X, book_lineup, order_patterns=create_order_patterns(N))

    return results.min_purchase_amount_required_pass()


N, M, X = [int(x) for x in input().split()]

books_info = []
for _ in range(N):
  book_info = list(map(int, input().split()))
  books_info.append(book_info)

print(actual(N, M, X, books_info))

Measured memory_bytes: 19404
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void pop();
void push(int);
int top=0;
int stack[200];
int main(){

  int i=0;
  char s[4];

  while((scanf("%s",s))!=EOF){

    if(strcmp(s,"+")==0){
      stack[top-1]=(stack[top])+(stack[top-1]);
      pop();
    }
    else if(strcmp(s,"-")==0){
      stack[top-1]=(stack[top-1])-(stack[top]);
      pop();
    }
    else if(strcmp(s,"*")==0){
      stack[top-1]=(stack[top])*(stack[top-1]);
      pop();
    }
    else{
      push(atoi(s));
    }
  }
  printf("%d\n",stack[1]);
  return 0;
}

void push(int a){
  stack[++top]=a;
}


void pop(){
  top--;
}
  


Measured memory_bytes: 2140
#include<stdio.h>
int main(void){
	int a,b,c,i,count=0;
	scanf("%d %d %d",&a,&b,&c);
	for(i=a;i<b+1;i++){
		if(c%i==0){
			count++;
		}
	}
	printf("%d\n",count);
	return 0;
}

Measured memory_bytes: 596
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main(){

    input!{
        s:chars,
    }

    let mut ans = 0;

    for i in s{
        if i=='+' {
            ans += 1;
        } else {
            ans -= 1;
        }
    }

    println!("{}", ans);

}

Measured memory_bytes: 4352
use std::cmp;
use std::collections::VecDeque;
use std::fmt::Debug;
use std::str::FromStr;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where
    T: FromStr,
    <T as FromStr>::Err: Debug,
{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim()
        .split_whitespace()
        .map(|c| T::from_str(c).unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_as_string() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main() {
    let n: usize = read_as_vec()[0];
    let mut a: Vec<usize> = read_as_vec();
    a.sort();
    a.reverse();

    let mut queue: VecDeque<usize> = VecDeque::new();
    let mut ans: usize = 0;
    queue.push_back(a[0]);

    for i in 1..n {
        ans += queue.pop_front().unwrap();
        queue.push_back(a[i]);
        queue.push_back(a[i]);
    }
    println!("{}", ans);
}


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

int main()
{
    int limit=1e9;
    int n,k,s,temp;
    scanf("%d %d %d",&n,&k,&s);
    if(s==limit)
        temp=limit-1;
    else
        temp=limit;
    while(n>0)
    {
        n--;
        if(k>0)
        {
            k--;
            printf("%d ",s);
        }
        else
            printf("%d ",temp);
    }
    return 0;
}


Measured memory_bytes: 1280
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long MOD = 1000000007;
const long long inf = 1ll<<61;
const double eps = 0.000000000001;
typedef pair<int, int> P;
typedef pair<P,int> PP;
struct edge { int to; int to2; int cost; };
int a[114514];
int ans[114514];
signed main() {
	int n; cin >> n;
	rep(i, n)cin >> a[i];
	int osum = 0;
	for (int i = 0; i < n; i += 2)osum += a[i];
	int asum = 0;
	rep(i, n)asum += a[i];
	asum /= 2;
	ans[0] = osum - asum;
	for (int i = 0; i < n-1; i++)ans[i+1] = a[i] - ans[i];
	rep(i, n) {
		if (i)cout << ' '; cout << ans[i] * 2;
	}cout << endl;
}

Measured memory_bytes: 2944
l=list(map(int,input().split()))
N = l[0]
X = l[1]
list_m = [int(input()) for x in range(N)]
list_m.sort()
s = sum(list_m)
r = X - s
for i in range(10**5):
	r -= list_m[0]
	if r < 0:
		lim = i 
		break
print(N + lim)

Measured memory_bytes: 3064
import java.util.*;

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

        long N = sc.nextLong();
        String n = String.valueOf(N);
        int l = n.length();
        long a = 0;
        long x = 0;
        long y = 0;
        long min = N;

        for(int i=1; i<=N*10/Math.pow(10, l/2); i++){
            if(N%i==0){
                a = N / i;
                min = Math.min(min, Math.abs(a-i));
                if(min==Math.abs(a-i)){
                    x = i;
                    y = a;
                }
            }
        }
        System.out.println(x + y - 2);
    }
}

Measured memory_bytes: 23764
#include<cstdio>
#include<algorithm>

using namespace std;

const int N=200+10;
int n,x,a[N];

int main(){
    scanf("%d%d",&n,&x);
    for(int i=1;i<=n;++i)scanf("%d",&a[i]);
    sort(a+1,a+1+n);
    int ans=0;
    for(int i=1;i<n;++i)if(x>=a[i]){
        x-=a[i];
        ++ans;
    }
    if(x==a[n])++ans;
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

const char* answer[4] = {
	"NA", "YYMM", "MMYY", "AMBIGUOUS"
};

int main(void) {
	char S[8];
	int hoge, fuga;
	int yosinagasayuri = 0;
	if (scanf("%s", S) != 1) return 1;
	hoge = (S[0] - '0') * 10 + (S[1] - '0');
	fuga = (S[2] - '0') * 10 + (S[3] - '0');
	if (1 <= fuga && fuga <= 12) yosinagasayuri += 1;
	if (1 <= hoge && hoge <= 12) yosinagasayuri += 2;
	puts(answer[yosinagasayuri]);
;
	return 0;
}


Measured memory_bytes: 128
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include <algorithm>
#include<initializer_list>
#include<map>
#include<set>
using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	int sum = 1;
	for (int i = 0; i < n; i++) {
		if (sum < k) sum*=2;
		else sum += k;
	}
	cout << sum;
	return 0;
}





Measured memory_bytes: 256