akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
A, B, C, D = map(int, input().split())
ans = 0
Am = 0
Bm = 0
df = 0
t = 0

def lcm(x, y):
	return (x * y) // gcd(x, y)

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

t = B - A + 1
Am = (A - 1) // C + (A - 1) // D - (A - 1)//lcm(C, D)
Bm = B // C + B // D - B // lcm(C, D)
ans = t - (Bm - Am)

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  int cnt=1;
  bool f=false;
  for(int i=0;i<n;i++){
    if(a[i]==cnt){
      cnt++;
      f=true;
    }
  }
  if(f){
    cout << n-cnt+1 << endl;
  }
  else{
    cout << -1 << endl;
  }
}

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

int main(){
  int n,a,b;
  cin >> n >> a >> b;
  int x = min(a,b);
  int y = a+b-n;
  if(y<=0){
    y = 0;
  }
  cout << x << endl;
  cout << y << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <set>
#include <map>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll N, ans=0, reg=0, reg2=0;
  std::cin >> N;
  std::vector<ll> a(N);
  for(int i=0;i<N;i++) std::cin >> a[i];
  sort(a.begin(), a.end());
  int itr = lower_bound(a.begin(), a.end(), 0) - a.begin();
  if(itr==0){
    ans = 0;
    for(int i=1;i<N;i++){
      ans += a[i];
    }
    ans -= a[0];
    std::cout << ans << '\n';
    reg = a[0];
    for(int i=1;i<N-1;i++){
      std::cout << reg << " " << a[i] << '\n';
      reg -= a[i];
    }
    std::cout << a[N-1] << " " << reg << '\n';
  }else if(itr==N){
    ans = 0;
    for(int i=0;i<N-1;i++){
      ans -= a[i];
    }
    ans += a[N-1];
    std::cout << ans << '\n';
    reg = a[N-1];
    for(int i=0;i<N-1;i++){
      std::cout << reg << " " << a[i] << '\n';
      reg -= a[i];
    }
  }else{
    ans = 0;
    for(int i=0;i<N;i++){
      ans += abs(a[i]);
    }
    std::cout << ans << '\n';
    reg2 = a[N-1];
    reg = -a[0];
    for(int i=1;i<itr;i++){
      std::cout << reg2 << " " << a[i] << '\n';
      reg2 -= a[i];
    }
    for(int i=itr;i<N-1;i++){
      std::cout << -reg << " " << a[i] << '\n';
      reg += a[i];
    }
    std::cout << reg2 << " " << -reg << '\n';
  }
  return 0;
}


Measured memory_bytes: 2688
### main

loop do
  n, m = gets.split.map(&:to_i)
  break if (n | m) == 0

  sts = n.times.map{gets.to_i}.sort
  shs = m.times.map{gets.to_i}.sort

  tsum = sts.inject(:+)
  hsum = shs.inject(:+)

  dsum = hsum - tsum
  if (dsum & 1) != 0
    puts -1
    next
  end

  sd = dsum / 2

  exc = nil

  for st in sts
    sh = st + sd
    if shs.index(sh)
      exc = [st, sh]
      break
    end
  end

  puts exc.nil? ? -1 : exc.join(' ')
end

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n;
  cin >> n;
  vint a(n), b(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];

  vint pow2(55);
  pow2[0] = 1;
  rep(i, 50) pow2[i+1] = pow2[i]*2;

  vint vec;
  for(int l = 50; l >= 0; --l) {
    int G[55][55];
    fill(G[0], G[55], inf);
    rep(i, 51) G[i][i] = 0;
    rep(i, 51) {
      reps(j, 1, l+1) G[i][i%j] = pow2[j];
      rep(j, vec.size()) G[i][i%vec[j]] = 0;
    }
    rep(k, 51) rep(i, 51) rep(j, 51) chmin(G[i][j], G[i][k]+G[k][j]);
    bool flag = true;
    rep(i, n) {
      if(G[a[i]][b[i]] == inf) flag = false;
    }
    if(!flag) vec.push_back(l+1);
  }

  {
    int G[55][55];
    fill(G[0], G[55], inf);
    rep(i, 51) G[i][i] = 0;
    rep(i, 51) {
      rep(j, vec.size()) G[i][i%vec[j]] = 0;
    }
    rep(k, 51) rep(i, 51) rep(j, 51) chmin(G[i][j], G[i][k]+G[k][j]);
    bool flag = true;
    rep(i, n) {
      if(G[a[i]][b[i]] == inf) flag = false;
    }
    if(!flag) {
      cout << -1 << endl;
      return 0;
    }
  }
  int sum = 0;
  rep(i, vec.size()) sum += pow2[vec[i]];
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,W;
  cin >> H >> W;
  vector<vector<char>> data(H, vector<char>(W));
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      cin >> data.at(i).at(j);
    }
  }
  
  //ドットだけの行があればその行を全部'-'にする
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      if (data.at(i).at(j) == '#'){
        break;
      }
      else if (j == W - 1){
        for (int k = 0; k < W; k++){
          data.at(i).at(k) = '-';
        }
      }
    }
  }
  
  //ドットだけの列があればその列を全部'1'にする
  for (int j = 0; j < W; j++){
    for (int i = 0; i < H; i++){
      if (data.at(i).at(j) == '#'){
        break;
      }
      else if (i == H - 1){
        for (int k = 0; k < H; k++){
          data.at(k).at(j) = '1';
        }
      }
    }
  }
        
  //0以外のものを出力していく
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      if (data.at(i).at(j) == '-'){
        break;
      }
      else if (data.at(i).at(j) != '1'){
        cout << data.at(i).at(j);
      }
      if (j == W - 1){
        cout << " " <<endl;
      }
    }
  }
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

template<typename C> struct Flow {
	int V;
	C INF;
	struct E { int t, r; C c; };
	vector<vector<E>> g;
	vector<bool> used;
	
	Flow() { }
	Flow(int v, C inf) { init(v, inf); }
	void init(int v, C inf) {
		V = v;
		INF = inf;
		g.resize(V);
		used.resize(V);
	}
	
	void add(int f, int t, C c) {
		assert(inID(f, 0, V));
		assert(inID(t, 0, V));
		int gt = g[t].size();
		int gf = g[f].size();
		g[f].PB({ t, gt, c });
		g[t].PB({ f, gf, 0 });
	}
	
	C dfs(int f, int t, C c) {
		if(f == t) { return c; }
		used[f] = true;
		inc(i, g[f].size()) {
			E & e = g[f][i];
			if(used[e.t] || e.c <= 0) { continue; }
			C v = dfs(e.t, t, min(c, e.c));
			if(v > 0) {
				e.c -= v;
				g[e.t][e.r].c += v;
				return v;
			}
		}
		return 0;
	}
	
	C max_flow(int S, int T) {
		assert(inID(S, 0, V));
		assert(inID(T, 0, V));
		C ans = 0;
		while(true) {
			inc(i, V) { used[i] = false; }
			C f = dfs(S, T, INF);
			ans += f;
			if(f == 0) { break; }
		}
		return ans;
	}
};

// ----

LL n, a[101];

int main() {
	cin >> n;
	inc1(i, n) { cin >> a[i]; }
	
	Flow<LL> f(n + 2, 1e12);
	
	int S = 0;
	int T = n + 1;
	inc1(i, n) {
		f.add(S, i, max(a[i], 0LL) - a[i]);
		f.add(i, T, max(a[i], 0LL) -  0LL);
	}
	inc1(i, n) {
		for(int j = i * 2; j <= n; j += i) { f.add(i, j, f.INF); }
	}
	
	LL ans = -f.max_flow(S, T);
	
	inc1(i, n) { ans += max(a[i], 0LL); }
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=605;
int n,m,a[N][N];
ll ans;
char s[N][N];
int getsum(int x,int y)
{
    if(x<1||y<1) return 0;
    return a[x][y];
}
int flag;
void solve(int x,int y)
{
    while(x<=n&&y<=m)
    {
        if(s[x][y]=='#')
        for(int d=1;x+d<=n&&y+d<=m;d++)
            if(s[x+d][y+d]=='#')
        {
            ans+=getsum(x+2*d-flag,y-flag)-getsum(x+d-1+flag,y-d-1+flag);
            ans+=getsum(x-flag,y+2*d-flag)-getsum(x-d-1+flag,y+d-1+flag);
        }
        x++;y++;
    }
}
void solve()
{
    memset(a,0,sizeof(a));
    for(int i=1;i<=n*2;i++)
        for(int j=1;j<=m*2;j++)
        a[i][j]=a[i-1][j-1]+(s[i][j]=='#');
    for(int i=1;i<=n;i++)
        solve(i,1);
    for(int j=2;j<=m;j++)
        solve(1,j);
}
void rev()
{
    for(int i=1;i<=n;i++)
    {
        int l=1,r=m;
        while(l<=r) swap(s[i][l++],s[i][r--]);
    }
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) scanf("%s",s[i]+1);
    solve();
    rev();
    flag=1;
    solve();
    printf("%lld\n",ans);
}


Measured memory_bytes: 1792
# -*- coding: utf-8 -*-

import itertools

S = input()
l = len(S)

cs = itertools.product(['+', ''], repeat=l-1)

ans = 0
for c in cs:
    ex = ''.join([S[i] + c[i] for i in range(l-1)] + [S[-1]])
    exec("ans += {}".format(ex))

print(ans)


Measured memory_bytes: 3060
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back

#define eb emplace_back
#define mod   1000000007
#define PI 2*acos(0.0)
#define all(r)(r).begin(),(r).end()
#define dbg(a) cout<<#a<<" ->->->-> "<<a<<"\n"
#define inf 1000000000000000000
#define N 5000000
int dirx[] = {1, -1,0, 0, 1, 1, -1, -1}, diry[] = {0, 0, 1, -1, 1, -1, 1, -1};



//=============================================ASIFAZAD==============================================//

vi ck(N+7);

void seive()
{
    for(int i = 3; i*i <= N; i+=2)
        if(ck[i] == 0)
            for(int j = i*i; j<= N; j+= 2*i)
                ck[j] = 1;
    ck[1] = 1;
    for(int i = 4; i<= N; i+= 2)
        ck[i]  = 1;
}
int32_t main()
{
    io;
    seive();
//    for(auto x: ck) cout<<x<<"\n";
    int x;
    cin>>x;
    for(; ; x++)
        if(ck[x] == 0)
            break;
    cout<<x;
    return 0;
}



Measured memory_bytes: 22648
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n;
    string s;
    cin >> n >> s;
    int answer = 0;
    FOR(i,1,n){
        int tmp = 0;
        string A,B;
        A = s.substr(0,i);
        B = s.substr(i,s.length()-i);
        
        sort(ALL(A));
        
        REP(j,A.length()){
            if(B.find(A[j]) != std::string::npos)tmp++;
            //else cout << B.find(A[i]) << endl;
            while(j!=A.length()-1 && A[j] == A[j+1]){
                j++;
            }
        }
        answer = max(tmp,answer);
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define sz 100005
#define faster_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;

int main()
{
    faster_io;
    int n;
    cin>>n;

    int a[n+5],b[n+5],sum=0;

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

    for(int i=0;i<n;i++){
        if(a[i]>b[i]){
            sum+=(a[i]-b[i]);
        }
    }

    cout<<sum<<endl;

    return 0;
}




Measured memory_bytes: 256
/*
                     .--.  .--.
                    /    \/    \
                   | .-.  .-.   \
                   |/_  |/_  |   \
                   || `\|| `\|    `----.
                   |\0_/ \0_/    --,    \_
 .--"""""-.       /              (` \     `-.
/          \-----'-.              \          \
\  () ()                         /`\          \
|                         .___.-'   |          \
\                        /` \|      /           ;
 `-.___             ___.' .-.`.---.|             \
    \| ``-..___,.-'`\| / /   /     |              `\
     `      \|      ,`/ /   /   ,  /
             `      |\ /   /    |\/
              ,   .'`-;   '     \/
         ,    |\-'  .'   ,   .-'`
       .-|\--;`` .-'     |\.'
      ( `"'-.|\ (___,.--'`'   
       `-.    `"`          _.--'
          `.          _.-'`-.
            `''---''``       `.
*/

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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int h1, m1, h2, m2, d;
    cin >> h1 >> m1 >> h2 >> m2 >> d;
    int t = h2 - h1 - 1;
    t *= 60;
    t += 60 - m1 + m2;
    if (h1 == h2) {
        t == m2 - m1;
    }
    cout << max(0, t - d) << '\n';
    return 0;
} 

Measured memory_bytes: 3656
N, C = list(map(int, input().split()))
stc = [list(map(int, input().split())) for _ in range(N)]

E = max(stc, key = lambda x: x[1])[1]

R = {}
stc.sort()
L = [0] * (E + 1)
for s, t, c in stc:
  if c not in R:
    R[c] = t
  else:
    if R[c] == s:
      s += 1
    R[c] = t
  L[s - 1] += 1
  L[t] -= 1

ans = L[0]
for i in range(E):
  L[i + 1] += L[i]
  ans = max(ans, L[i + 1])

print(ans)

Measured memory_bytes: 28340
import sys
import bisect
import collections

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    UV = [[int(x) for x in input().split()] for _ in range(N - 1)]

    T = [[] for j in range(N + 1)]

    for u, v in UV:
        T[u].append(v)
        T[v].append(u)

    s = collections.deque()

    lis = []
    s.append([1, lis])

    v = set()

    ans = [0] * (N + 1)
    memo = [[] for j in range(N + 1)]

    while s:
        c = s[-1]
        ci, clis = c[0], c[1]

        # lis処理
        if ci not in v:
            if len(clis) == 0:
                clis.append(A[ci - 1])
                memo[ci].append(-1)
            else:
                if clis[-1] < A[ci - 1]:
                    clis.append(A[ci - 1])
                    memo[ci].append(-1)
                else:
                    i = bisect.bisect_left(clis, A[ci - 1])
                    memo[ci].append(i)
                    memo[ci].append(clis[i])
                    clis[i] = A[ci - 1]

            v.add(ci)
            ans[ci] = len(clis)

        if len(T[ci]) >= 1:
            n = T[ci].pop()
            if n in v:
                continue
            s.append([n, clis])
            continue

        if memo[ci][0] == -1:
            if len(clis) >= 1:
                clis.pop()
        else:
            clis[memo[ci][0]] = memo[ci][1]

        s.pop()

    for i in range(1, N + 1):
        print(ans[i])


if __name__ == '__main__':
    main()


Measured memory_bytes: 207792
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<P,int>
#define vpp vector<PP>
#define fi first
#define se second
#define INF (1<<30)
#define MOD 1000000007
#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 all(x) (x).begin(),(x).end()

const int MAX_V=100000;
int V,E;
vi G[MAX_V];
int color[MAX_V];

bool dfs(int v,int c){
    color[v]=c;
    REP(i,G[v].size()){
        if(color[G[v][i]]==c)return false;
        if(color[G[v][i]]==0&&!dfs(G[v][i],-c))return false;
    }
    return true;
}

signed main(){
    cin>>V>>E;
    REP(i,E){
        int a,b;
        cin>>a>>b;
        a--;b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    if(!dfs(0,1)){
        cerr<<"yes"<<endl;
        cout<<V*(V-1)/2-E<<endl;
    }else{
        cerr<<"no"<<endl;
        int b=0,w=0;
        REP(i,V){
            if(color[i]==1)b++;
            else w++;
        }
        cout<<b*w-E<<endl;
    }
    return 0;
}

Measured memory_bytes: 7424
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,int> pdi;
typedef pair<double,double> pdd;
typedef pair<double,ll> pdl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<pdd> vdd;
typedef vector<pdi> vdi;
typedef vector<pdl> vdl;
typedef vector<string> vs;
#define fi first
#define se second
const ll INFLL=LLONG_MAX;
const int INF=INT_MAX;
const ll MAXLL=0x3f3f3f3f3f3f3f3f;
const int MAX=0x3f3f3f3f;
const ll MOD=1000000007;
const ll mod=998244353;
#define eb emplace_back
#define emp emplace
#define mp(a,b) make_pair(a,b)
template<class T> using min_heap=priority_queue<T,vector<T>,greater<T> >;
template<class T>
void sort(vector<T>& v){
	sort(v.begin(),v.end());
}
template <class T, class U>
void sort(vector<T>& v,U func){
	sort(v.begin(),v.end(),func);
}
template<class T>
void rsort(vector<T>& v){
	sort(v.rbegin(),v.rend());
}
template <class T>
int lb_index(vector<T>& v,T k){
	return lower_bound(v.begin(),v.end(),k)-v.begin();
}
template <class T>
int ub_index(vector<T>& v,T k){
	return upper_bound(v.begin(),v.end(),k)-v.begin();
}
template<class T>
bool is_sorted(vector<T>& v){
	return is_sorted(v.begin(),v.end());
}
template<class T>
bool sorted(vector<T>& v){
	return is_sorted(v);
}
void precompute(){

	return;
}
void solve(){
	int n,m;
	cin>>n>>m;
	vs v(n);
	for(int i=0;i<n;i++)cin>>v[i];
	vi a(m),b(n);
	string s="";
	for(int i=0;i<m;i++)s+=".";
	for(int i=0;i<m;i++){
		for(int j=0;j<n;j++){
			a[i]|=(v[j][i]=='#');
		}
	}
	for(int i=0;i<n;i++)b[i]=(v[i]==s);
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if((a[j])&&(!b[i])){
				cout<<v[i][j];
			}
		}
		if(!b[i])cout<<endl;
	}
}

int main(){
	ios::sync_with_stdio(0);
	int numberofsubtestcases=1;
//	cin>>numberofsubtestcases;
	precompute();
	for(int looping=1;looping<=numberofsubtestcases;looping++){
//		cout<<"Case #"<<looping<<": ";
		solve();
	}
	return 0;
}

Measured memory_bytes: 3592
#include <stdio.h>

int main(void)
{
	int a,i,j,sa[7];
		for(a=0;a<=6;a++){
			scanf("%d %d",&i,&j);
			sa[a]=i-j;
		}
		for(a=0;a<=6;a++){
			printf("%d\n",sa[a]);
		}
	return 0;
}



Measured memory_bytes: 2112
from functools import reduce
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


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


N, K = map(int, input().split())
A = list(map(int, input().split()))

ans = "IMPOSSIBLE"
if max(A) < K:
    print(ans)
    exit()
if K in A:
    ans = "POSSIBLE"
else:
    gcd = reduce(gcd, A)
    if K % gcd == 0:
        ans = "POSSIBLE"
print(ans)


Measured memory_bytes: 14668
s = list(map(int, input().split()))
r = s[0] // s[2] 
t = s[0] % s[2] 
if s[0] > 0 and s[0] - s[1] * s[2] > 0:
    print(s[0] - s[1] * s[2])
elif s[0] < 0 and s[0] + s[1] * s[2] < 0:
    print(-s[0] - s[1] * s[2])
else:
    if s[0] > 0:
        r = s[0] // s[2] 
        t = s[0] % s[2] 
        if (s[1] - r) % 2 == 1:
            print(-t + s[2])
        else:
            print(t)
    elif s[0] < 0:
        v = (-s[0]) // s[2]
        w = -((-s[0]) % s[2])
        if (s[1] - v) % 2 == 1:
            print(w+s[2])
        else:
            print(-w)
    else:
        if s[1] % 2 == 1:
            print(s[2])
        else:
            print(s[0])

Measured memory_bytes: 9272
#include <iostream>
using namespace std;
int main(){
    int n,flag;
    flag = 0;
    string s;
    cin>>n>>s;
    for (int i =0; i<n; i++){
        if(s[i]=='A'){
            for(int j=i; j<i+3; j++){
                if(s[j+1]!='B') break;
                else if (s[j+2]!='C') break;
                else flag ++;
            }
        }
    }
    cout << flag;
}

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

int main() {
  int H, W;
  cin >> H >> W;

  vector<vector<char>> grid(H,vector<char>(W));
  for (int i=0; i<H; i++){
    for (int j=0; j<W; j++){
      cin >> grid.at(i).at(j);
    }
  }
  
  vector<bool> row(H,false);
  vector<bool> col(W,false);

  for (int i=0; i<H; i++){
    for (int j=0; j<W; j++){
      if (grid.at(i).at(j) == '#'){
        row.at(i) = true;
        col.at(j) = true;
    }
  }
  }
  
  for (int i=0; i<H; i++){
    if (row.at(i) == true){
    for (int j=0; j<W; j++){
      if (col.at(j) == true){
       cout << grid.at(i).at(j);
      }
    }
        cout << endl;
    }
  }

}


Measured memory_bytes: 3648
#include <iostream>
#define ll long long
using namespace std;

int main(){
  ll n; cin>>n;
  ll c[3] = {0,0,0};
  
  ll p,count,d; count=1;
  for(int i=0;i<n;i++){
    cin>>p; d=0;
    
    if(p==c[0]){d++;}
    if(p==c[1]){d++;}
    if(p==c[2]){d++;}
    count = count*d%1000000007;
    
    if(p==c[0]){c[0]++;}
    else if(p==c[1]){c[1]++;}
    else if(p==c[2]){c[2]++;}
  }
  
  cout<<count;
  
  return 0;
}

Measured memory_bytes: 256
l = gets.split
ln = l.map{|w| w.length}
lm = {:mx => 0, :wd => ""}
l.each{|w|
  if lm[:mx] < l.count(w)
    lm[:mx] = l.count(w)
    lm[:wd] = w
  end
}
puts "#{lm[:wd]} #{l[ln.index(ln.max)]}"

Measured memory_bytes: 8568
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;

int h,w,x;
char s[1000][1000];
bool visited [1000][1000];
pair<int,int> start,goal;
queue<pair<int,pair<int,int>>> q;
vector<pair<int,int>> ino;

int main(){
  int a,b,c,d;cin>>a>>b>>c>>d;
  cout << (a+b)*c/2;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll                      long long
#define pb                      push_back
#define rep(i,a,b,c)            for(ll i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(ll i=(a);i>=(b);i-=(c))
#define MOD                     1000000007
#define inf                     3e18
#define ld                      long double
#define mp                      make_pair
#define vpll                    vector<pair<ll,ll> >
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define ln                      cout<<"\n";
#define endl                    "\n"
#define test                    ll T;cin>>T;while(T--)
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define show(w,size)            for(ll i=0;i<size;i++) cout<<w[i]<<" ";
#define prll(a)                 cout<<a<<"\n";
#define mset(dp,no)             memset(dp,no,sizeof(dp))
#define input(a,n)              rep(i,0,n-1,1) cin>>a[i];
#define countbit                __builtin_popcount                                           //Number of setbits in decimal notation
#define lb(v,cur)               lower_bound(all(v),cur)-v.begin()
#define ub(v,cur)               upper_bound(all(v),cur)-v.begin()
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
long long pows(long long a, long long b) {
  long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll powm(ll x,ll y,ll m=MOD){x=x%m;ll res=1;while(y){if(y&1)res=res*x;res%=m;y=y>>1;x=x*x;x%=m;}return res;}
ll modInverse(ll a, ll m=MOD){return powm(a,m-2,m);}
int main()
{
fastIO
ll n,m,i,j,k,x,y,z,t,e,f,p,q,g,l,r,o,w,h,count1=0,prod=1,a,b,c,d,index,x1,x2,y1,y2,diff,ans=0,sum=0,sum1=0,sum2=0,flag=0,flag1=0,flag2=0;
string s,s1,s2;
cin>>a>>b>>c;
p=(a+b-1)/b;
cout<<c*p;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string t;
    cin >> t;

    int index;

    for(int i = 0; i < t.size(); i++){
        if(t.at(i) == '?')  t.at(i) = 'D';
        cout << t.at(i);
    }

}

Measured memory_bytes: 3756
# C - Next Prime
import math

def is_prime(n):
    if n == 1: return False
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True

X = int(input())
while True:
    if is_prime(X):
        break
    X += 1
    
print(X)

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

bool so(int n){
  int cnt=0;
  for(int i=2;i*i<=n;i++){
    if(n%i==0){
      cnt++;
      break;
    }
  }
  if(cnt==0)return true;
  else return false;
}

int main(){
  int n;
  while(cin>>n,n){
    int cnt=0;
    if(!so(n)){
      for(int i=n+1;;i++){
        if(so(i))break;
        else cnt++;
      }
      for(int i=n-1;;i--){
        if(so(i))break;
        else cnt++;
      }
      cnt+=2;
    }
    cout<<cnt<<endl;
  }
  return 0;
}

Measured memory_bytes: 3088
#include <stdio.h>

int main(void){

  long n;
  scanf("%ld", &n);
  long k;
  scanf("%ld", &k);
  double p[n];
  for (long i = 0; i < n; i++) {
    scanf("%lf", &p[i]);
  }

  double ex = 0;
  for (long i = 0; i < k; i++) {
    ex += p[i]+1;
  }
  double max = ex;
  for (long i = k; i < n; i++) {
    ex += p[i];
    ex -= p[i-k];
    if (ex > max) {
      max = ex;
    }
  }

  printf("%lf\n", max/2);

  return 0;
}

Measured memory_bytes: 1664
# include <stdio.h>
# define n 200000+10
long int a[n];
int main ()
{
    long int N,T,s,i,k;
    s=0;
    scanf("%ld%ld",&N,&T);
    k=T;
    for(i=0;i<N;i++)
    {
        scanf("%ld",&a[i]);
    }
    for(i=1;i<N;i++)
    {

        if(a[i]-a[i-1]<=T)
        {
            k=k+a[i]-a[i-1];

        }
        else
        {
            k=k+T;
        }
    }
    printf("%ld",k);
    return 0;
}

Measured memory_bytes: 1664
# include<iostream>
# include<cstdio>
using namespace std;
 
int main() {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  if (a == b) {
    if (a != c) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  else if (a == c || b == c) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define printYes() cout << "Yes" << endl;
#define printNo() cout << "No" << endl;
#define printVector(v) rep(i, v.size()) cout << x << endl;

int main()
{
  int x, a, b;
  cin >> x >> a >> b;
  string ans = "A";
  if (abs(x - a) > abs(x - b))
    ans = "B";
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int cnt[5];

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for(int i=0; i<n; i++){
    string s;
    cin >> s;
    switch (s[0]) {
      case 'M' : cnt[0]++; break;
      case 'A' : cnt[1]++; break;
      case 'R' : cnt[2]++; break;
      case 'C' : cnt[3]++; break;
      case 'H' : cnt[4]++; break;
      default : break;
    }
  }
  long long ans = 0;
  for(int i=0; i<5; i++){
    for(int j=i+1; j<5; j++){
      for(int k=j+1; k<5; k++){
        ans += 1ll * cnt[i] * cnt[j] * cnt[k];
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <math.h>
#include <utility>
#include <stack>
#include <string.h>
#include <complex>
using namespace std;
const int INF = 1<<29;
const double EPS = 1e-8;
typedef vector<int> vec;
typedef pair<int,int> P;


int field[10][10];
int ans[10][10];
int kukaku[15];
P start[15];
int X,Y,n;

void copy_field(){
    for(int i=0;i<Y;i++){
        for(int j=0;j<X;j++){
            ans[i][j] = field[i][j];
        }
    }
}

void print_field(){
    for(int i=0;i<Y;i++){
        cout << ans[i][0];
        for(int j=1;j<X;j++){
            printf(" %d",ans[i][j]);
        }
        printf("\n");
    }
}

int  dfs(int n_i){
    if(n_i == n){
        copy_field();
        return 1;
    }
    int p = 0;
    for(int tate=1;tate<=kukaku[n_i];tate++){
        if (kukaku[n_i]%tate)continue;
        int yoko = kukaku[n_i] / tate;
        //printf("tate=%d yoko=%d\n",tate,yoko);
        for(int y=start[n_i].first-tate+1; y<=start[n_i].first; y++){
            for(int x=start[n_i].second-yoko+1; x<=start[n_i].second; x++){
                //printf("n_i=%d x=%d y=%d\n",n_i,x,y);
                if(!(0<=y&&y+tate-1<Y&&0<=x&&x+yoko-1<X)) continue;
                bool can_paint = true;
                for(int i=0;i<tate;i++){
                    for(int j=0;j<yoko;j++){
                        if(field[y+i][x+j]==0||field[y+i][x+j]==n_i+1){
                            field[y+i][x+j] = n_i+1;
                        }else{
                            can_paint = false;
                            break;
                        }
                    }
                }
                //printf("can_paint=%d\n",can_paint);
                if(can_paint){
                    p += dfs(n_i+1);
                    if(p>1) return p;
                }
                for(int i=0;i<tate;i++){
                    for(int j=0;j<yoko;j++){
                        if(field[y+i][x+j]==n_i+1){
                            field[y+i][x+j] = 0;
                        }
                    }
                }
                field[start[n_i].first][start[n_i].second] = n_i+1;
            }
        }
    }
    return p;
}


int main(){
    while(1){
        scanf("%d%d%d",&X,&Y,&n);
        if(!X)break;

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

        for(int i=0;i<Y;i++){
            for(int j=0;j<X;j++){
                scanf("%d",&field[i][j]);
                if(field[i][j]>0){
                    start[field[i][j]-1] = P(i,j);
                }
            }
        }
        if(dfs(0)==1){
            print_field();
        }else{
            printf("NA\n");
        }

        //break;
    }

    return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void warshall_floyd(Graph &graph) {
    int V = graph.size();
    for (int k = 0; k < V; ++k) {
        for (int i = 0; i < V; ++i) {
            for (int j = 0; j < V; ++j) {
                graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]);
            }
        }
    }
}

void Main() {
    int N, M, L;
    cin >> N >> M >> L;
    Graph graph(N, vector<ll>(N, INF));
    rep(i, M) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        if (c > L) continue;
        graph[a][b] = c;
        graph[b][a] = c;
    }
    warshall_floyd(graph);
    Graph graph1(N, vector<ll>(N, INF));
    rep(i, N) {
        rep(j, N) {
            if (i == j) continue;
            if (graph[i][j] <= L) graph1[i][j] = 1;
        }
    }
    warshall_floyd(graph1);
    int Q;
    cin >> Q;
    rep(q, Q) {
        int s, t;
        cin >> s >> t;
        s--;
        t--;
        ll d = graph1[s][t];
        if (d == INF) {
            cout << -1 << '\n';
        } else {
            cout << d - 1<< '\n';
        }
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define stdi(in) freopen(in, "r", stdin)
#define stdo(out) freopen(out, "w", stdout)
#define stdio(in, out) stdi(in); stdo(out)
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define MAX 100007
#define MOD 1000000007
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
#define ordered_set tree<pair<int, int> , null_type, less<pair<int, int> >, rb_tree_tag, tree_order_statistics_node_update>

//const ll modd = 998244353;
const ll inf = 1e18;

int dp[MAX];

int main(){
	/*#ifndef ONLINE_JUDGE
        stdio("in", "out");
    #endif*/
    fast;
    int n,k;
    cin>>n>>k;
    int arr[n];
    for(int i=0;i<n;i++){
    	cin>>arr[i];
    }

    for(int i=1;i<=k;i++){

    	for(int j=0;j<n;j++){
    		if((i-arr[j])>=0 && dp[i-arr[j]]==0){
    			dp[i] = 1;
    			break;
    		}
    	}
    }

    if(dp[k] == 1){
    	cout<<"First\n";
    } else {
    	cout<<"Second\n";
    }

	return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

int main(void) {
    Int k, n;
    cin >> k >> n;
    VI a(n);
    VI d(n);
    for (Int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (Int i = 0; i < n - 1; ++i) {
        d[i] = a[i + 1] - a[i];
    }
    d[n - 1] = a[0] + k - a[n - 1];
    sort(d.begin(), d.end());

    Int result = 0;
    for (Int i = 0; i < n - 1; ++i) {
        result += d[i];
    }
    cout << result << endl;
    return 0;
}



Measured memory_bytes: 6436
def dist(p1,p2):
    return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])

h,w,d = map(int, input().split())

m = [0 for _ in range(h*w + 1)]
acm = [0 for _ in range(h*w + 1)]
ans = []

for i in range(h):
    a = [int(x) for x in input().split()]
    for j,k in enumerate(a):
        m[k] = (i,j)

for i in range(1, d+1):
    count = i
    while count <= h * w:
        if count <= d:
            pass
        else:
            acm[count] = dist(m[count],m[count-d]) + acm[count-d]
        count += d

q = int(input())

for i in range(q):
    l,r = map(int, input().split())
    ans.append(acm[r] - acm[l])

for x in ans:
    print(x)  

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

using namespace std;
typedef long long ll;
const int N=3e5+100;
ll mod=1e9+7;
ll a[N];
int main()
{
    int n;cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    ll ans=0;
    for(int i=0;i<=60;i++){
        int cnt0=0,cnt1=0;
        for(int j=1;j<=n;j++){
            if(1&(a[j]>>i)) cnt1++;
            else cnt0++;
        }
       // cout<<cnt1<<" "<<cnt0<<endl;
        ll bit=1ll*1<<i;
        bit%=mod;
        //cout<<bit<<endl;
        ans=(ans+(bit*1ll*cnt0%mod)*(cnt1%mod))%mod;
    }
    cout<<ans%mod;
    return 0;
}


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

using namespace std;

int n, a, k;
vector<int> cijene;
int dp[100002];

int rek(int x) {
    if (dp[x] != -1) return dp[x];

    int rj = 1e9;
    for (int i=1; i<=k; i++) {
        if (x-i < 0) continue;
        rj = min(rj, rek(x-i) + abs(cijene[x] - cijene[x-i]));
    }

    dp[x] = rj;

    return dp[x];
}

int main() {
    cin >> n >> k;
    for (int i=0; i<n; i++) {
        cin >> a;
        cijene.push_back(a);
    }

    memset(dp, -1, sizeof(dp));
    dp[0] = 0;

    cout << rek(n-1) << endl;

    return 0;
}


Measured memory_bytes: 10304
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    if (A <= C && C <= B) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int n;
    cin >> n;
    rep(i,n) {
        int a;
        cin >> a;
        if (a % 2 == 0 && !(a % 3 == 0 || a % 5 == 0)) {
            cout << "DENIED\n";
            return 0;
        }
    }
    cout << "APPROVED\n";
    return 0;
}

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


int main()
{
    int32_t n;
    std::cin >> n;
	const auto v = n % 10;
    if(v==3){
		std::cout << "bon" << std::endl;

	}
	else {
		if (v == 0||v==1||v==6||v==8) {
			std::cout << "pon" << std::endl;
		}
		else {
			std::cout << "hon" << std::endl;
		}
	}
    return 0;

}



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

using namespace std;

int main () {
    int n = 0, m = 0;
    cin >> n >> m;
    vector<pair<long long, int>> price(n);
    for (int i=0; i<n; i++) {
        cin >> price.at(i).first >> price.at(i).second;
    }
    sort(price.begin(), price.end());
    long long ans = 0;
    int count = 0;
    for (int i=0; i<n; i++) {
        if (price.at(i).second <= m - count) {
            count += price.at(i).second;
            ans += price.at(i).first * price.at(i).second;
        }
        else {
            ans += price.at(i).first * (m - count);
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    ll sum = 0LL;
    ll ans = -1LL;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    sort(A.begin(), A.end());
    rep(i, N - 1) {
        sum += A[i];
        if(2 * sum < A[i + 1]) ans = i;
    }
    if(ans == -1LL) cout << N << endl;
    else cout << N - ans - 1 << endl;
    return 0;
}


Measured memory_bytes: 4008
tbl1strs = ('A'..'Z').map{|s| s} + [" ", ".", ",", "-", "'", "?"]

tbl2 = {
  "101" => " ",
  "000000" => "'",
  "000011" => ",",
  "10010001" => "-",
  "010001" => ".",
  "000001" => "?",
  "100101" => "A",
  "10011010" => "B",
  "0101" => "C",
  "0001" => "D",
  "110" => "E",
  "01001" => "F",
  "10011011" => "G",
  "010000" => "H",
  "0111" => "I",
  "10011000" => "J",
  "0110" => "K",
  "00100" => "L",
  "10011001" => "M",
  "10011110" => "N",
  "00101" => "O",
  "111" => "P",
  "10011111" => "Q",
  "1000" => "R",
  "00110" => "S",
  "00111" => "T",
  "10011100" => "U",
  "10011101" => "V",
  "000010" => "W",
  "10010010" => "X",
  "10010011" => "Y",
  "10010000" => "Z"
}

tbl1 = {}
(0...tbl1strs.length).each{|i| tbl1[tbl1strs[i]] = sprintf("%05b", i)}

keys2 = tbl2.keys.sort{|a, b| a.length <=> b.length}

while (line = gets)
  str = line.chomp

  enc1 = str.split("").map{|s| tbl1[s]}.join("")

  enc2 = ''
  while enc1.length > 0
    failed = true
    for key in keys2
      klen = key.length
      if enc1[0, klen] == key
        enc2 << tbl2[key]
        enc1[0, klen] = ''
        failed = false
      end
    end

    if failed
      enc1 = ''
    end
  end

  puts enc2
end

Measured memory_bytes: 6136
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;

class Test
{

    public static void Main()
    {

        var ss = Console.ReadLine().Split(' ').Select(xx => int.Parse(xx)).ToArray();
        var n = ss[0];
        var x = ss[1];

        var arr = Console.ReadLine().Split(' ').Select(xx => long.Parse(xx)).ToArray();

        long count = 0;

        for (int i = 1; i < arr.Length; i++)
        {
            if (arr[i - 1] > x)
            {
                long dif = arr[i - 1] - x;
                arr[i - 1] = arr[i - 1] - dif;
                count = count + dif;
            }
            if (arr[i] + arr[i - 1] > x)
            {
                long dif = arr[i] + arr[i - 1] - x;
                if (arr[i] - dif >= 0)
                    arr[i] = arr[i] - dif;
                else
                    arr[i - 1] = arr[i - 1] - dif;

                count = count + dif;

            }
        }

        Console.Write(count);

    }

}

















Measured memory_bytes: 34112
/*我是萌新*/
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include <iomanip> 
typedef long long ll;
const int mod = 1e9 + 7;
using namespace std;
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;
}
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    ll n,s;
    while (cin >> n>>s)
    {
        ll* p = new ll[s + 5],ans=0;
        for (ll i = 0; i < s; i++)
        {
            cin >> p[i];
            
        }
        ll  maxn = 0;
        for (ll i = 1; i < s; i++)
        {
            maxn = max(maxn, p[i] - p[i - 1]);
        }
        maxn = max(maxn, n - p[s - 1] + (p[0] - 0));
        cout << n - maxn << '\n';
    }
}



Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// Welcome to my source code!

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; }

int main() {
    int n;
    cin >> n;
    int ans;
    for (int i = 0, a; i < n; i++) {
        cin >> a;
        if (i > 0) ans = gcd(ans, a);
        else ans = a;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    // Your code here!
    int N, d[50];
    long sum = 0;
    scanf("%d", &N);
    
    for(int i = 0; i < N; i++)
    {
        scanf("%d", &d[i]);
    }
    
    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j < N; j++)
        {
            if(i != j)
            {
                sum += d[i]*d[j];
            }
        }
    }
    
    printf("%ld\n", sum/2);
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>

using namespace std;

char S[100];


int main()
{
  cin >> S;
  
  int i,N,x;
  x=0;
  N=strlen(S);
  for(i=0;i<N;i++)
  {
    if(i%2==1 && S[i]=='R')
    {
      x=1;
    }
    else if(i%2==0 && S[i]=='L')
    {
      x=1;
    }
  }
  
  if(x==1)
  {
    cout << "No";
  }
  else
  {
    cout << "Yes";
  }
    
    

 return 0; 
}

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

int main(){
	int N, M;
	cin >> N >> M;
	vector<int> a(M);
	vector<int> b(M);
	vector<int> c(N);
	for(int i=0; i < M; i++){
		cin >> a.at(i) >> b.at(i);
		c.at(a.at(i)-1)++;
		c.at(b.at(i)-1)++;
	}
	for(int i=0; i < N; i++){
		cout << c.at(i) << endl;
	}

}


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

using namespace std;

std::vector<int> n;
int main(){
        int a,b,c,i,o=0;
        cin >> a >> b >> c;
        if(a>b){
                o=a;
                a=b;
                b=o;
        }
        for(i=1;i<=a;i++){
                if(a%i==0 && b%i==0){
                        n.push_back(i);
                }
        }
        sort(n.rbegin(),n.rend());
        cout << n[c-1];
}


Measured memory_bytes: 256
def bubble_sort(n, a)
  arr = a.clone
  (0...n).each do |i|
    (n-1).downto(i+1) do |j|
      arr[j-1],arr[j] = arr[j],arr[j-1] if arr[j-1][1] > arr[j][1]
    end
  end
  return arr
end
  
def selection_sort(n, a)
  arr = a.clone
  (0...n).each do |i|
    min = i
    (i...n).each do |j|
      min = j if arr[j][1] < arr[min][1]
    end
    arr[i], arr[min] = arr[min], arr[i]
  end
  return arr
end
  
n = gets.to_i
a = gets.split.map { |v| [v[0], v[1].to_i] }
b = bubble_sort(n, a)
s = selection_sort(n, a)
  
puts b.map(&:join).join(' ')
puts 'Stable'
puts s.map(&:join).join(' ')
puts b == s ? 'Stable' : 'Not stable'

Measured memory_bytes: 8752
import java.util.Scanner;


public class Main {

    public static void main(String[] args) {

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

        for (int i = 1; i <= 10; i++) {
            if (i * 1000 >= N) {
                System.out.println(i * 1000 - N);
                return;
            }
        }
    }

}


Measured memory_bytes: 35688