akhauriyash/Code-Regression huggingface dataset:
line = readlines.map(&:to_i)

min_rest = 100
time = []
for i in 1..5 do
  rest = line[i-1] % 10
  if rest == 0 then
    time[i-1] = line[i-1]
  else
    time[i-1] = line[i-1] + 10 - rest
    if min_rest > rest then
      min_rest = rest
    end
  end
end
    
ans = 0
for i in 1..5 do
  ans += time[i-1]
end
if min_rest == 100 then
  puts ans
else
  puts ans - 10 + min_rest
end

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

int main() {
  int s;
  int s1;
  int s2;
  int s3;

  cin >> s;

  //100の位
  s1 = s / 100;
  //10の位
  s2 = (s - s1 * 100) / 10;
  //1の位
  s3 = s - (s1 * 100 + s2 * 10);
  cout << s1 + s2 + s3 << endl;
}

Measured memory_bytes: 256
n = int(input())
dif = list(map(int, input().split()))
dif.sort()

divide = 0

medium = int((len(dif)) / 2)


if (len(dif)) %2 != 0:
    print(divide)
else:
    divide = dif[medium] - dif[medium-1]
    print(divide)

Measured memory_bytes: 13992
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iterator>
//#include<math.h>

using namespace std;
#define int long long
/*                      */    //#undef int
#define INF 1000000009
#define INFL 1000000000000000018ll
#define mod 1000000007ll
#define pb push_back
#define fi first
#define se second
#define mk make_pair
typedef pair<int, int> PA;
typedef priority_queue<int> PQ;
typedef priority_queue<PA, vector<PA>, greater<PA> >PQG;

int N, M, ans;
bool flag;

signed main()
{
    scanf("%d%d", &N, &M);
    for(int i = 2; i * i <= M; i++){
        if(M % i == 0ll){
            flag = true;
        }
    }
    if(flag)for(int i = N; i <= M; i++){
        if(M % i == 0){
            printf("%d\n", M / i);
            return 0;
        }
    }
    printf("1\n");



    return 0;
}
/*


*/



Measured memory_bytes: 256
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

constexpr ll INF = 1e16;

#define rep(i, N) for(ll i=0; i<N; ++i)

ll max(ll a, ll b) {return a < b ? b : a; }
ll min(ll a, ll b) {return a > b ? b : a; }

int main() {
  int N;
  ll H;
  cin >> N >> H;
  vector<pair<ll,int>> ab(N*2);
  for(int i=0; i<N; ++i) {
    ll a, b;
    cin >> a >> b;
    ab.push_back(make_pair(a, 1));
    ab.push_back(make_pair(b, 0));
  }
  
  sort(ab.begin(), ab.end(), greater<pair<ll,int>>());
  
  int count = 0;
  int i = 0;
  while(true) {
    auto pr = ab[i];
    if(pr.second == 0) {
      H -= pr.first;
      ++count;
      if(H<=0) {
        break;
      }
    } else {
      //「切る」
      count += (H / pr.first) + (H % pr.first ? 1 : 0);
      break;
    }
    ++i;
  }
  
  cout << count << endl;
  
}

Measured memory_bytes: 8448
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    string a, b;
    cin >> a >> b;
    vector<int> match;
    rep(i, a.size() - b.size()+1)
    {
        int flag = 0;
        rep(j, b.size())
        {
            if (a[i + j] == b[j] || a[i + j] == '?')
            {
                if (flag == 1 || j == 0)
                    flag = 1;
            }
            else
            {
                flag = 0;
                break;
            }
        }
        if (flag == 1)
            match.push_back(i);
    }
    SORT(match);
    if (match.size() > 0)
    {
        rep(j, b.size())
        {
            a[*match.rbegin() + j] = b[j];
        }
        rep(j, a.size())
        {
            if (a[j] == '?')
                a[j] = 'a';
        }
        cout << a << endl;
        return 0;
    }
    cout << "UNRESTORABLE" << endl;
    return 0;
}

Measured memory_bytes: 256
L = []
N, A, B, C = map(int, input().split())
for i in range(N):
    L.append(int(input()))

def base10to(n, b):
    if (int(n/b)):
        return base10to(int(n/b), b) + str(n%b)
    return str(n%b)

maxL = 4 ** N - 1
maxL = base10to(maxL,4)
ans = []
for i in range(1, 4 ** N + 1):
    n = 4 ** N - i
    n = base10to(n,4)
    if len(maxL) - len(n) > 0:
        tmp = ['0'] * (len(maxL) - len(n))
        tmp.extend(list(n))
    else:
        tmp = list(n)
    AA, BB, CC = A, B, C
    aaa = set(tmp)
    anss = 0
    if '1' not in aaa or '2' not in aaa or '3' not in aaa:
        continue
    for j, num in enumerate(tmp):
        if num == '1':
            if AA != A:
                anss += 10
            AA -= L[j]
        elif num == '2':
            if BB != B:
                anss += 10
            BB -= L[j]
        elif num == '3':
            if CC != C:
                anss += 10
            CC -= L[j]
    ans.append(anss + abs(AA) + abs(BB) + abs(CC))
print(min(ans))

Measured memory_bytes: 90072
import sys;
lines = sys.stdin.readlines();

#配列の宣言
stdIn = {};

for i, line in enumerate(lines):
    #値を受け取り格納
    chairSize,humanSize,spaceSize = map(int, line.split());

total = 0;
maxSize = 0;
while total*(humanSize)+(total-1)*(spaceSize)+spaceSize*2 <= chairSize:
    total = total+1;
print (total-1);


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
using namespace std; //std::の省略のため
using ll = long long;

int main()
{
  int a, b, c;
  cin >> a >> b >> c;

  if((a+b) == c || (b+c) == a || (a+c) == b)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;


}


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

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

int main(){
    int N;
    char C[200];
    cin >> N;
    for(int i=0; i<N; i++) cin >> C[i];

    static int64_t dp[201][201] = {0};
    dp[0][0] = 1;
    for(int i=0; i<N; i++) for(int j=0; j<N; j++){
        if(dp[i][j] == 0) continue;
        if(C[i] == 'U'){
            add(dp[i+1][j+1], dp[i][j]);
            add(dp[i+1][j], dp[i][j] * j);
        }else if(C[i] == 'D'){
            add(dp[i+1][j], dp[i][j] * j);
            if(j > 0) add(dp[i+1][j-1], dp[i][j] * j * j);
        }else{
            add(dp[i+1][j], dp[i][j]);
        }
    }
    cout << dp[N][0] << endl;
    return 0;
}



Measured memory_bytes: 3396
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVSORT(v) sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

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

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

  int n,l;cin>>n>>l;

  int sum = 0;
  REP(i,n){
    sum += l + i;
  }

  if(l<=0&&l+n-1>=0){
    cout<<sum<<endl;
  }else if(l<=0){
    cout<<sum - (l+n-1)<<endl;
  }else{
    cout<<sum - l<<endl;
  }

 

  return 0;
}

Measured memory_bytes: 256
a,l=map(int,input().split())
s=0
if l<a or a==0:
	print("No")
elif l/a==2 or l/a==4:
	print("Yes")

else:
	f=a*4
	if f>l:
		for i in range(a):
			f=f-2
			if f==l:
				print("Yes")
				break			
		else:
			print("No")
	else:
		print("No") 

Measured memory_bytes: 9136
use num_integer::lcm;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
use proconio::{fastout, input};
#[fastout]
fn main() {
    input! {
        a: usize,
        b: usize,
    }
    println!("{}", lcm(a, b));
}


Measured memory_bytes: 2152
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

// ref. arihon 3-3
// E: type of data, R: type of query result
template<typename E, typename R>
class SegmentTree {
    public:
        SegmentTree(const int _n, const E inf, R (*f)(E, E)): f(f), inf(inf) {
            n = 1;
            while (n < _n) n *= 2;
            data.resize(2 * n, inf);
        }

        // update data[k] with a
        // 0-index, [0, _n) in other words
        // time complexity: O(n)
        void update(int k, E a) {
            k += n - 1;
            data[k] = a;
            while (k > 0) {
                k = (k - 1) / 2;
                data[k] = (*f)(data[k * 2 + 1], data[k * 2 + 2]);
            }
        }

        // query value from [a, b)
        // 0-index, [0, _n) in other words
        // time complexity: O(n)
        R query(int a, int b) {
            return query(a, b, 0, 0, n);
        }

    private:
        int n;
        R (*f)(E, E);
        const E inf;
        vector<E> data;

        R query(int a, int b, int k, int l, int r) {
            // if [a, b) intersect [l, r) = empty
            if (r <= a || b <= l) {
                return inf;
            }

            // if [a, b) includes [l, r)
            if (a <= l && r <= b) {
                return data[k];
            } else {
                R vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
                R vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
                return (*f)(vl, vr);
            }
        }
};

const int MAX_N = 100000;

int N, M;
vector<int> as;
vector<int> bs;

// {pos, kind} kind = 1 if start, kind = -1 if end
// vector<pair<int, int>> events;

vector<set<int>> ss;
vector<set<int>> es;

SegmentTree<int, int> *st;

int solve(const int N, const int M) {
    for (int i = 0; i < N; i++) {
        for (auto island : es[i]) {
            int a = as[island];
            int b = bs[island];
            if (st->query(a, b) == 0) {
                // printf("add wall to %d\n", b - 1);
                st->update(b - 1, 1);
            }
        }

    }

    return st->query(0, N);
}

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

    as.resize(M);
    bs.resize(M);
    ss.resize(N);
    es.resize(N);
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        as[i] = a;
        bs[i] = b;

        ss[a].insert(i);
        es[b].insert(i);
    }

    auto f = [](int x, int y) {
        return x + y;
    };
    st = new SegmentTree<int, int>(MAX_N, 0, f);

    cout << solve(N, M) << endl;

    delete st;
    return 0;
}


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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n;
  string s,t;cin>>n>>s>>t;

  for(int i=0;i<n;i++){
    cout<<s[i]<<t[i];
  }
  cout<<endl;

  return 0;
}


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

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 5e5 + 10;

vector<int> g[N];
bool viss[N];
int vis[N];

// Normal DFS
void dfs(int curr, int par)
{
  for(auto x: g[curr])
    if(x != par)
      dfs(x, curr);
}

// DFS with visiting status
void dfs1(int curr, int par)
{
  viss[curr] = 1;
  for(auto x: g[curr])
    if(!viss[x])
      dfs1(x, curr);
}

// DFS with strongly connected component
void dfs2(int curr, int par, int num)
{
  vis[curr] = num;
  for(auto x: g[curr])
    if(vis[x] == 0)
      dfs2(x, curr, num);
}

// XOR from 0 to n
ll fxor(ll n)
{
  if(n < 0) return 0;
  if(n % 4 == 3) return 0;
  else if(n % 4 == 0) return n;
  else if(n % 4 == 1) return n^(n-1);
  else if(n%4 == 2) return n^(n-1)^(n-2);
}

// Power in logn with mod 1000000007
llt ppow(llt x, llt y)
{
  llt res = 1;
  while(y > 0){
    if(y&1)
      res = (res * x)%M;
    y = y >> 1;
    x = (x * x)%M;
  }
  return res;
}

// Factorial with dp
llt factdp[N];
llt fact(llt x)
{
  if(x == 0) return 1;
  if(x == 1) return 1;
  if(factdp[x] != -1) return factdp[x];
  return factdp[x] = (x*fact(x-1))%M;
}

// String return to base b
string ansConv ="";
void convert10tob(llt N, int b)
{
     if (N == 0)
        return;
     int x = N % b;
     N /= b;
     if (x < 0)
        N += 1;
     convert10tob(N, b);
     ansConv += to_string(x);
     return;
}

// Convert string to num wiht base b
llt convertstrtob(string a, int b)
{
  llt aa = 0;
  llt mul = 1;
  for(int i=a.length()-1; i>=0; i--)
  {
    int curr = a[i] - '0';
    aa += (curr * mul);
    mul *= b;
  }
  return aa;
}

// Union Find algo with array
// Find()
int findpar(int curr, int arr[])
{
  while(arr[curr] != curr) curr = arr[curr];
  return curr;
}
// Union()
void Union(int b, int spa, int arr[])
{
  while(arr[b] != b)
  {
    int c = arr[b];
    arr[b] = spa;
    b = c;
  }
  arr[b] = spa;
}

// Main Code

int main()
{
  int n;
  cin>>n;
  int arr[n+1];
  rep(i, 0, n) cin>>arr[i];
  arr[n] = 0;
  int cost = 0;
  repn(i, 1, n)
  {
    if(arr[i] < arr[i-1])
      cost += (arr[i-1] - arr[i]);
  }
  cout<<cost<<endl;
  return 0;
}


Measured memory_bytes: 12160
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


# --------------------------------------------

dp = None


def main():
    N = int(input())
    A = li_input()

    ans = 0

    while True:
        A_ = []
        is_end = False

        for a in A:
            if a % 2 != 0:
                is_end = True
                break
            else:
                A_.append(a // 2)

        if is_end:
            break
        else:
            ans += 1
            A = A_[:]

    print(ans)


main()


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

int n, ans;
string s;
int main()
{
    cin >> n >> s;
    for (int i = 0; i + 1 < n; i++)
    {
        if ((s[i] == 'O' && s[i + 1] == 'X') || (s[i] == 'X' && s[i + 1] == 'O'))
            ans++, i++;
    }
    cout << ans << endl;
}



Measured memory_bytes: 3344
import numpy as np
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(N)]
tmp = []
cnt = 0

for i in range(N):
    tmp.append(np.dot(B, A[i]))

for i in range(N):
    if tmp[i]+C>0:
        cnt += 1

print(cnt)

Measured memory_bytes: 14444
#include<bits/stdc++.h>
using namespace std;
map<int, int>mp;
int main()
{
	int n; cin>>n; int ara[n+9]; long long sum=0;
	for(int i=1; i<=n; i++) cin>>ara[i], sum+=ara[i], mp[ara[i]]++;

	int q; cin>>q;
	while(q--){
		int b,c; cin>>b>>c;
		int cur=mp[b];
		mp[c]+=cur;
		if(b<c){
			sum+=(cur * (c-b));
			mp[b]=0;
		}
		else{
			sum-=(cur * (b-c));
			mp[b]=0;
		}

		cout<<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 8304
N = int(input())
s = ["".join(sorted(input())) for i in range(N)]
s.sort()
ss = s[0]
num = 0
ans=0
for i in range(N):
    if ss == s[i]:
        num+=1
    else:
        ans+=num*(num-1)//2
        num=1
        ss=s[i]
ans+=num*(num-1)//2
print(ans)

Measured memory_bytes: 57304
import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8
import sys

R, C, K = map(int, input().split())
rcvs = [list(map(int, input().split())) for _ in range(K)]
rcvs = np.array(rcvs, dtype=np.int64)

@njit(i8(i8[:,:]), cache=True)
def main(rcvs):
    rewards = np.zeros((R, C), dtype=np.int64)
    
    for i in range(len(rcvs)):
        rewards[rcvs[i][0]-1][rcvs[i][1]-1] = rcvs[i][2]
    
    dp = np.zeros((R+1, C+1, 4), dtype=np.int64)
    
    for i in range(R):
        for j in range(C):
            reward = rewards[i][j]
            dp[i+1][j+1][0] = max(dp[i][j+1])
            dp[i+1][j+1][1] = dp[i+1][j+1][0] + reward
            
            for k in range(4): # move downside without selecting
                dp[i+1][j+1][k] = max(dp[i+1][j][k], dp[i+1][j+1][k])
            if reward > 0:
                for k in range(3):
                    dp[i+1][j+1][k+1] = max(dp[i+1][j][k]+reward,dp[i+1][j+1][k+1])
    return max(dp[-1][-1])

print(main(rcvs))

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

int main()
{
  int64_t N, l, r, ans = 0;
  cin >> N;
  vector<int64_t> S(100010, 0);
  for (int i = 0; i < N; i++)
  {
    cin >> l >> r;
    S[l]++;
    S[r + 1]--;
  }
  for (int i = 1; i < 100010; i++)
  {
    S[i] += S[i - 1];
    if (S[i])
      ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4040
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define ll long long
#define eps 1e-7
#define all(x) ((x).begin()),((x).end())
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int n;
vector <int> problem;

int main()
{
	usecppio
	cin >> n;
	problem.resize(n);
	for (int i = 0; i<n; i++)
	{
		cin >> problem[i];
	}
	sort(all(problem));
	int u = n/2-1;
	cout << problem[u+1]-problem[u];
}

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

int main() {
    int32_t n;
    std::cin >> n;

    std::vector< int32_t > l(2 * n);
    for(int32_t i = 0; i < 2 * n; i++) {
        std::cin >> l[i];
    }

    std::sort(l.begin(), l.end());

    int32_t ans = 0;
    for(int32_t i = 0; i < 2 * n; i += 2) {
        ans += l[i];
    }

    std::cout << ans << '\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <algorithm>

using namespace std;
int main() {
    int N;
    cin >> N;
    vector<int> length(N);
    for(int i = 0; i < N; i++)
    {
        cin >> length[i];
    }
    int max = length[0];
    int max_position = 0;
    for(int i = 1; i < N; i++)
    {
        if(max < length[i]) {
            max = length[i];
            max_position = i;
        }
    }
    int length_sum = 0;
    for(int i = 0; i < N; i++)
    {
        if(i != max_position) {
            length_sum += length[i];
        }
    }
    //cout << "sum = " << length_sum << endl;
    //cout << "max = " << max << endl;
    if (length_sum > max) {
        cout << "Yes";
    } else
    {
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 256
x1,y1,x2,y2=map(float,raw_input().split(" "))
for i in xrange(int(raw_input())):
    px,py=map(float,raw_input().split(" "))
    dxa=(x2-x1)
    dya=(y2-y1)
    da=dxa**2+dya**2
    dxb=(px-x1)
    dyb=(py-y1)
    ip=dxb*dxa+dya*dyb
    r=ip/da
    kouten_x=x1+r*dxa
    kouten_y=y1+r*dya
    ref_x=px+2.0*(kouten_x-px)
    ref_y=py+2.0*(kouten_y-py)
    print "{0:.10f} {1:.10f}".format(ref_x,ref_y)

Measured memory_bytes: 4280
#include "bits/stdc++.h"
#include <random>
using namespace std; typedef unsigned long long _ulong; typedef long long int lint; typedef pair<lint, lint> plint; typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define endk '\n'
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
const lint MOD = 1e9 + 7, INF = 1e18;
lint dx[8] = { 0, -1, 1, 0, 1, -1, 1, -1 }, dy[8] = { 1, 0, 0, -1, -1, -1, 1, 1 };

lint N, X, T;
int main() {
	cin >> N >> X >> T;
	cout << ((N - 1) / X + 1) * T << endk;
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <queue>
#define ll long long 
#define pb push_back
using namespace std;
ll n, m, x, y, idx, T, ans;
vector< ll > arr[100010];
priority_queue< ll > pq;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	ll i,  a, b, n, m,ans=0;
	cin >> n >> m;
	for (i = 0; i < n; i++)
	{
		cin >> a >> b;
		if (a > m) continue;
		arr[m - a].pb(b);
	}
	for (i = m-1; i >= 0; i--)
	{
		for (auto val : arr[i]) pq.push(val);
		if (!pq.empty())
		{
			ans += pq.top();
			pq.pop();
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
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;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    map<int,int> m;
    rep(i,n) {
        int a;
        cin >> a;
        m[a]++;
        m[a-1]++;
        m[a+1]++;
    }
    int ans = 0;
    for(auto p : m) chmax(ans,p.second);
    cout << ans << endl;
}


Measured memory_bytes: 4736
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const ll MOD = 1000000007;
using namespace std;

int main(){
    int d, n; cin >> d >> n;
    if(n == 100) ++n;
    int ans = n;
    REP(i, d) ans *= 100;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
while True:
    w,h = map(int,input().split())
    if w == 0:
        break
    around = ''
    for i in range(w + 2):
        around += '#'
    maze = [around]
    cnt = 1
    for i in range(h):
        row = '#' + input() + '#'
        maze.append(row)
        if '@' in row:
            loc = [[i + 1,row.index('@')]]
    maze.append(around)
    visted = loc
    left = True
    while left:
        next_loc = []
        for x,y in loc:
            for i,j in ([1,0],[0,1],[-1,0],[0,-1]):
                if maze[x + i][y + j] == '.' and [x + i,y + j] not in visted:
                    cnt += 1
                    next_loc.append([x + i,y + j])
                    visted.append([x + i,y + j])
            if  next_loc == []:
                print(cnt)
                left = False
                break
        loc = next_loc


Measured memory_bytes: 5676
a, b = list(map(int, input().split()))

def gcd(a, b):
    if a == 0:
        return b
    elif b == 0:
        return a
    else:
        return gcd(b, a%b)

p = gcd(a, b)
factors = {}

while p > 1:
    f = False
    for i in range(2, int(p**0.5)+1):
        if p % i == 0:
            if i in factors:
                factors[i] += 1
            else:
                factors[i] = 1

            p //= i
            f = True
            break

    if not f:
        if p in factors:
            factors[p] += 1
        else:
            factors[p] = 1
        break

print(len(factors)+1)

Measured memory_bytes: 9328
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int main(){
  int a;
  cin >> a;
  cout << a+a*a+a*a*a << endl;
  return 0;
}


Measured memory_bytes: 3616
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

int w,d;

void solve() {
    ll ans=0;
    int a1[50]={};
    int a2[50]={};
    set<int> S;
    rep(i,w) {
        int b;
        cin>>b;
        S.insert(b);
        a1[b]++;
    }
    rep(i,d) {
        int b;
        cin>>b;
        S.insert(b);
        a2[b]++;
    }

    for(auto e : S) {
        ans += max(a1[e],a2[e])*e;
    }
    cout<<ans<<endl;
}

int main() {
    while(cin>>w>>d) {
        if(w+d==0) break;
        solve();
    }
    return 0;
}

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

int h,w;
char grid[50][50];

int main(){
	cin >> h >> w;
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)
			cin >> grid[i][j];
	
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			bool ans=false;
			if(grid[i][j]=='#'){
				int x=1;
				int y=0;
				for(int k=0;k<4;k++){
					if(i+y>=0 && i+y<h && j+x>=0 && j+x<w){
						if(grid[i+y][j+x]=='#') ans=true;
					}
					int prex=x;
					x=y;
					y=-prex;
				}
				if(!ans){
					cout << "No" << endl;
					return 0;
				}
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>
using namespace std;
typedef  long long int lint;
//typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
#define mp make_pair
#define P pair<int,int>

int main() {
	int INF = 1000000;
	int V, X, Y;
	cin >> V >> X >> Y;
	X--;
	Y--;
	vector<vector<int>>G(V);
	for (int i = 0; i < V-1; i++) {
		G[i].push_back(i + 1);
		G[i + 1].push_back(i);
	}
	G[X].push_back(Y);
	G[Y].push_back(X);
	vector<int>ans(10000);
	
	for (int i = 0; i < V; i++) {

		int start = i;//スタート位置

		vector<int>dist(V, INF);//startからの距離を入れる配列。INF(未訪問)で初期化
		queue<int> que;

		dist[start] = 0;
		que.push(start);

		//BFS
		while (!que.empty()) {
			int v = que.front();
			que.pop();

			for (int nv : G[v]) {
				if (dist[nv] != INF)continue;
				dist[nv] = dist[v] + 1;
				que.push(nv);
			}
		}
		rep(j, V) {
			ans[dist[j]]++;
		}

	}
	rep(i, V-1) {
		cout << ans[i + 1]/2 << endl;
	}
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k, t; cin >> k >> t;
    vector<int> a(t); rep (i, t) cin >> a[i];
    sort(all(a), greater<int>());
    cout << max(0, 2 * a[0] - k - 1) << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N,wareru;
map<int,int>m;
int main(){
    cin>>N;
    vector<int>A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
        m[A[i]]++;
    }
    if(m[1]==1){cout<<1<<endl;return 0;}
    if(m[1]>1){cout<<0<<endl;return 0;}
    sort(A.begin(),A.end());
    for(int i=0;i<N;i++){
        for(int n=2;n*n<=A[i];n++){
            if(A[i]%n==0&&(m[n]!=0||m[A[i]/n]!=0)){
                wareru++;
                goto E;
            }
        }
        if(m[A[i]]>1)wareru++;
        E:;
    }
    cout<<N-wareru<<endl;
    return 0;
}

Measured memory_bytes: 33088
n,x,y=map(int,input().split())
wk={}
for i in range(1,n+1):
  for j in range(i+1,n+1):
    k=min(j-i,abs(x-i)+1+abs(y-j))
    if k in wk:
      wk[k]+=1
    else:
      wk[k]=1
for i in range(n-1):
  print(wk[i+1] if i+1 in wk else 0)

Measured memory_bytes: 3572
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <map>

using namespace std;

int main(void) {
  int N;
  cin >> N;
  double X;
  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    X += (double)1 / tmp;
  }
  cout << 1 / X << endl;
  return 0;
}


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

//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

template<class T, class F>
struct SegmentTree {
    F f;
    T ti;
    vector<T> dat;
    int sz;

    SegmentTree(const F &f, const T &ti) : f(f), ti(ti) {}

    void build(const vector<T> &v) {
        assert(v.size());
        sz = 1;
        while (sz < v.size())sz <<= 1;
        dat.resize(sz << 1, ti);
        for (int i = 0; i < v.size(); i++)dat[sz - 1 + i] = v[i];
        for (int i = sz - 2; i >= 0; i--)dat[i] = f(dat[i * 2 + 1], dat[i * 2 + 2]);
    }

    inline void update(int k, T x) {
        k += sz - 1;
        dat[k] = x;
        while (k) {
            k = (k - 1) / 2;
            dat[k] = f(dat[k * 2 + 1], dat[k * 2 + 2]);
        }
    }

    inline void add(int k, int x) {
        k += sz - 1;
        dat[k] = f(dat[k], x);
        while (k) {
            k = (k - 1) / 2;
            dat[k] = f(dat[k * 2 + 1], dat[k * 2 + 2]);
        }
    }

    inline T query(int a, int b) {
        return query(a, b, 0, 0, sz);
    }

    T query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l)return ti;
        if (a <= l && r <= b)return dat[k];
        return f(query(a, b, k * 2 + 1, l, (l + r) / 2), query(a, b, k * 2 + 2, (l + r) / 2, r));
    }
};


int main() {

    int n, q;
    cin >> n >> q;

    vector<ll> v(n);
    rep(i, n) cin >> v[i];

    auto f = [](ll i, ll j) { return i + j; };
    SegmentTree<ll, decltype(f)> segmentTree(f, 0);
    segmentTree.build(v);
    rep(_, q) {
        int m, a, b;
        cin >> m >> a >> b;

        if (m == 0) {
            ll k = segmentTree.query(a, a + 1);
            segmentTree.update(a, k + b);
        } else {
            ll ans = segmentTree.query(a, b);
            cout << ans << endl;
        }
    }

}

Measured memory_bytes: 16440
#include "bits/stdc++.h"
#define double long double
#define int long long
#define mii map<int,int>
#define low lower_bound
#define upp upper_bound
#define inf 1000000007 //10^9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define sort(vec) sort(all(vec));
#define rever(vec) reverse(all(vec));
#define bisea binary_search
#define unsort(vec) sort(vec); rever(vec);
#define cend cout<<endl;
#define F first
#define S second
using namespace std;

signed main() {
  int n,a,b;
  cin>>n>>a>>b;
  if(0<=n-(a+b)) {
    cout<<min(a,b)<<" "<<0<<endl;
  }
  else {
    cout<<min(a,b)<<" "<<a+b-n<<endl;
  }
}

Measured memory_bytes: 256
L=int(input())
L_list=list(str(bin(L)))
del L_list[0:2]
N=len(L_list)
for i in range(N):
  L_list[i]=int(L_list[i])
M=2*N-2
for n in range(1,N):
  if L_list[n]==1:
    M+=1
print(N,M)
for i in range(N):
  L_list[i]=int(L_list[i])
for n in range(N-1):
  print(n+1,n+2,0)
  print(n+1,n+2,2**(N-n-2))
A=2**(N-1)
for n in range(1,N):
  if L_list[n]==1:
    print(1,n+1,A)
    A+=2**(N-n-1)
    
    
  



Measured memory_bytes: 3064
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
int main(void){
  string s;
  int flag1=0,flag2=0,i;
  int res=0;
  cin>>s;

  for(i=0;i<s.size();i++){
    if(s[i]=='C') flag1=1;
    if(s[i]=='F'&&flag1==1) flag2=1;
  }
  if(flag2==1) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<vector>
#include<queue>
#include<math.h>
#include<stdlib.h>
#include<algorithm>
typedef long long int ll;
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[n][3];
	int dp[n][3];
	cin>>a[0][0]>>a[0][1]>>a[0][2];
	dp[0][0]=a[0][0];
	dp[0][1]=a[0][1];
	dp[0][2]=a[0][2];
	for(int i=1;i<n;i++){
		cin>>a[i][0]>>a[i][1]>>a[i][2];
		for(int j=0;j<3;j++){
			dp[i][j]=a[i][j]+max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3]);
		}
	}
	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}

Measured memory_bytes: 2688
#include<map>
#include<queue>
#include<time.h>
#include<limits.h>
#include<cmath>
#include<ostream>
#include<iterator>
#include<set>
#include<stack>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define rep_1(i,m,n) for(int i=m;i<=n;i++)
#define mem(st) memset(st,0,sizeof st)
inline int read()
{
	int num=0, w=0;
	char ch=0;
	while (!isdigit(ch))
	{
		w|=ch=='-';
		ch = getchar();
	}
	while (isdigit(ch))
	{
		num = (num<<3) + (num<<1) + (ch^48);
		ch = getchar();
	}
	return w? -num: num;
}
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef pair<double,double> pdd;
const int inf = 0x3f3f3f3f;
const int N=2e6+10;
int a[N];
void solve()
{
	string s;
	cin>>s;
	int n=s.size();
	if(s[n-1]=='s')
		cout<<s<<"es"<<endl;
	else
		cout<<s<<"s"<<endl;
}
signed main()
{
	int t=1;
	while(t--)
		solve();
	return 0;
}



Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=100005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll x,y,z,a,b,c,N;cin>>x>>y>>z>>a>>b>>c>>N;
    vector<ll> ans(N),cnt(N);
    
    for(ll i=0;i<x;i++){
        cnt[abs(i-a)%N]++;
    }
    
    for(int i=0;i<N;i++){
        ll s=0;
        s+=max(0LL,(b+1-i+N-1)/N);
        s+=max(0LL,(y-b-i+N-1)/N);
        if(i==0) s--;
        
        for(int j=0;j<N;j++){
            ans[(i+j)%N]+=cnt[j]*s;
        }
    }
    
    cnt=ans;
    for(int j=0;j<N;j++) ans[j]=0;
    
    for(int i=0;i<N;i++){
        ll s=0;
        s+=max(0LL,(c+1-i+N-1)/N);
        s+=max(0LL,(z-c-i+N-1)/N);
        if(i==0) s--;
        
        for(int j=0;j<N;j++){
            ans[(i+j)%N]+=cnt[j]*s;
        }
    }
    
    for(int i=0;i<N;i++){
        if(i) cout<<" ";
        cout<<ans[i];
    }
    cout<<endl;
    
}




Measured memory_bytes: 3244
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int d[105];
int a[105][105];
bool s[105];
int ans;
int main(void){
    int n,k; cin>>n>>k;
    for(int i=0;i<k;i++){
        cin>>d[i];
        for(int j=0;j<d[i];j++){
            cin>>a[i][j];
            s[a[i][j]]=true;
        }
    }
    for(int i=1;i<=n;i++){
        if(s[i]==false){
            ans++;
        }
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 3644
# AOJ 1162: Discrete Speed
# Python3 2018.7.15 bal4u

INF = 10e8
import heapq

def dijkstra(V, to, start, goal):
	node = [[[INF for k in range(31)] for j in range(V)] for i in range(V)]
	Q = []
	node[start][0][0] = 0
	heapq.heappush(Q, (0, start, -1, 0))
	while Q:
		t, s, p, v = heapq.heappop(Q)
		if s == goal and v == 1: return t
		for e, d, c in to[s]:
			if e == p: continue    # Uターン禁止
			for i in range(-1, 2):
				nv = v+i
				if nv > c or nv <= 0: continue
				nt = t + d/nv
				if nt < node[e][s][nv]:
					node[e][s][nv] = nt
					heapq.heappush(Q, (nt, e, s, nv))
	return -1
	
while True:
	n, m = map(int, input().split())
	if n == 0: break
	s, g = map(int, input().split())
	s -= 1; g -= 1
	to = [[] for i in range(n)]
	for i in range(m):
		x, y, d, c = map(int, input().split())
		x -= 1; y -= 1
		to[x].append((y, d, c))
		to[y].append((x, d, c))
	ans = dijkstra(n, to, s, g)
	print(ans if ans >= 0 else "unreachable")



Measured memory_bytes: 7548
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define abdelrahman010 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
using namespace std;
const int N = 1e5 + 5;

int main() {
    abdelrahman010
    int n , m;
    cin >> n >> m;
    int a[n + 5] , sum = 0;
    for(int i = 0;i < n;i++)
        cin >> a[i] , sum += a[i];
    int cnt = 0;
    for(int i = 0;i < n;i++)
        cnt += (a[i] >= ((sum + (4 * m) - 1) / (4 * m)));
    cnt >= m ? cout << "Yes" : cout << "No";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#define INF (long)1e9
const int MOD = 1e9 + 7;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
using namespace std;
typedef long long ll;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> vec;
	for(int i = 1; i <= 128; i *= 2)
	{
		vec.push_back(i);
	}
	for(int i = 0; i < vec.size() - 1; i++)
	{
		if(vec[i] <= n && vec[i + 1] > n)
		{
			cout << vec[i] << endl;
			return 0;
		}
	}
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int H[300],W[300],i=0,j,k;

        while(1){
        scanf("%d%d",&H[i],&W[i]);
        if(H[i]==0&&W[i]==0){
            break;
        }
        i++;
    }

    i=0;
    while(H[i]!=0&&W[i]!=0||H[i]!=0&&W[i]==0||H[i]==0&&W[i]!=0){
        for(j=0;j<H[i];j++){
            for(k=0;k<W[i];k++){
                if(0<j&&0<k&&j!=H[i]-1&&k!=W[i]-1){
                    printf(".");
                }else{
                    printf("#");
                }
            }
            printf("\n");
        }
        printf("\n");
        i++;
    }

    return 0;
}

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

#define REP(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define REPS(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define RREP(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define RREPS(i, n) for (int i = ((int)(n)); i > 0; i--)
#define IREP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define IREPS(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVISORT(v) sort(v.begin(), v.end(), greater<int>());
#define ALL(v) v.begin(), v.end()
#define MP(n, m) make_pair(n, m);

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using ll = long long;
using ul = unsigned long;

typedef long long ll;

template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

const int mod=1e9+7;

void printv(VI& v){
  REP(i,v.size()) cout << v[i] << " ";
  cout << endl;
}

int vtotal(VI& v){
  int total=0;
  REP(i,v.size()) total+=v[i];
  return total;
}

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

  // string n;
	// getline(cin,n);

  int n;
  cin>>n;

  VI p(n);
  VI p2(n);
  REP(i,n){
    cin>>p[i];
    p2[i]=p[i];
  }
  VSORT(p);
  int count=0;
  REP(i,n){
    if(p[i]!=p2[i])count++;
  }
  string ans="YES";
  if(count>2)ans="NO";

  cout<<ans<<endl;

  // cout<<std::setprecision(10)<<ans<<endl;

  return 0;
}


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

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

int main() {
  int n; cin >>n;
  string buf1, buf2;
  set<string> s;
  string ans = "Yes";
  for (int i=0; i<n; i++){
    buf1 = buf2;
    cin >>buf2; s.insert(buf2);
    if (i==0){continue;}
    if (buf1.at(buf1.size()-1)!=buf2.at(0)){
      ans = "No"; break;
    }
  }
  if (s.size()!=n){
    ans = "No";
  }

  cout <<ans;
  cout <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define sz(x) (int)(x).size()

const int N = 10010;
int f[N], h[N], n, m;
int g[] = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
vector<int> digits;

void solve() {
  string res = "";
  assert(f[n] != 0);
  for (int k = n; k; k -= g[f[k]])
    res += char('0' + f[k]);
  printf("%s\n", res.data());
}

void process() {
  memset(f, 0, sizeof f);
  memset(h, 0, sizeof h);
  f[0] = -1;
  for (int i = 0; i < n; i++) {
    if (!f[i]) continue;
    for (int d : digits) {
      if (h[i + g[d]] < 1 + h[i] || (h[i + g[d]] == 1 + h[i] && d > f[i + g[d]])) {
        f[i + g[d]] = d;
        h[i + g[d]] = 1 + h[i];
      }
    }
  }
}

int main() {
  scanf("%d%d", &n, &m);
  digits.assign(m, 0);
  for (int i = 0; i < m; i++) {
    scanf("%d", &digits[i]);
  }
  process();
  solve();
}



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

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

int main() {
    int x1, y1, x2, y2; 
    cin >> x1 >> y1 >> x2 >> y2;
    int x3 = x2 - y2 + y1;
    int y3 = y2 + x2 - x1;
    int x4 = x3 - x2 + x1;
    int y4 = y3 - y2 + y1;
    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
    return 0;
}


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

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

    int i, n = S.size();
    int ans[n];

    for (i=0; i<n; i++){
        if (S[i]=='1') ans[i] = 9;
        else ans[i] = 1;
    }
    cout << ans[0] << ans[1] << ans[2] << '\n';




}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ff first
#define pb push_back
#define ss second
#define debug 0
#define ff first
#define mp make_pair
 
using namespace std;
 
const ll MOD = 1000000007LL;
 


 
ll ar[2000056];
ll br[2000056];
ll cr[2000056];


const long double pi=3.1415926535897;

 
vector<int> primes,pec,vec;

vector<pair<ll,ll> > vp;

set<ll> st;

map<ll,ll> has;
map<char,char> hav,first_occr,used;

 
 
 
ll powr (ll a, ll  b)
{
    if (b == 0)
        return 1;
    long long int x = powr(a, b/2);
    if (b % 2 == 0)
        return (x*x)%MOD;
    else
        return ((x*x)%MOD*a%MOD)%MOD;
}
 
inline ll inv(ll x) {
  return powr(x, MOD - 2);
}
 
inline ll mulMod(ll a, ll b) {
  return (a%MOD * b%MOD) % MOD;
 
}
 
/*inline void process() {
  fact[0] = 1;
  power2[0] = 1;
  for(int i = 1; i < 200003; i++) {
    fact[i] = mulMod(fact[i - 1], i);
    power2[i] = mulMod(power2[i - 1], 2);
  }
  ifact[200002] = inv(fact[200002]);
  for(int i = 200002 - 1; i >= 0; i--) {
    ifact[i] = mulMod(ifact[i + 1], i + 1);
  }
}
 
inline ll ncr(ll n, ll r) {
  if(n < r) return 0;
  return mulMod(fact[n], mulMod(ifact[r], ifact[(n - r)]));
}
 
 
 
void sieve()
{
    memset(prime,true,sizeof(prime));
    prime[0]=prime[1]=false;
    
    for(ll i=2;i*i<=1000006;i++)
    {
        if(prime[i])
        {
            for(ll j=i*2;j<=1000006;j+=i)
            {
                prime[j]=false;
            }
        }
    }
    
    for(int i=2;i<=100005;i++)
    {
    	if(prime[i])
    	primes.pb(i);
	}
}





void LeastPrimeFactor(){
	int tot=1000003;
	least_prime[1]=1;
	for (ll i = 2; i <tot; i += 2)	least_prime[i] = 2;
	for (ll i = 3; i < tot; i += 2){
		if (!visit[i]){
			least_prime[i] = i;
			for (ll j = i; (j*i) < tot; j += 2){
				if (!visit[j*i])
				{
					visit[j*i] = true;
					least_prime[j*i] = i;
				}
			}
		}
	}
}*/




string strng[100005];

 

int main() 
{
//	freopen("input4.in","r",stdin);
//	freopen("output4.out","w",stdout);
    ll m,n,t,p,q,s,c,d,e,f,g,h,res=0,u,v,i,j,l=0,k,len,tot=0,rad,w,pos=0,y,r=0,z,x,maxm=-1,mid;
	ll cycle,val,max1=0,max2=0,num=0,zero,ans=0,min1=INT_MAX,min2=INT_MAX,sum=0;
    bool flag=0;
    ll a,b,minm=INT_MAX;
    ll x1,x2;
    
    string str,ptr="",dstr,dptr;
    
    set<ll>::iterator it;
    
    cin>>str;
    cin>>ptr;
    
    reverse(str.begin(),str.end());
    
    if(str==ptr)
    cout<<"YES";
    else
    cout<<"NO";
    
 
	return 0;
    
}    

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

int main(){
	int a,b,c;
	int ans;
	
	string cunning="7767555555555555555555555555555555555555";
	
	for(int i=0;i<104;i++){
		cin>>a>>b;c=a+b;
		//-----test-----
		if(i<cunning.size()){
			cout<<cunning[i]<<endl;
			continue;
		}
		//--------------
		ans=1;
		while(10<=c){
			c/=10;
			ans++;
		}
		cout<<ans<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1208
/*  ex4_1 Golden Apple
    pandacodeb  */

#include <stdio.h>
#include <math.h>

int findLeast(double numApple, double range);

int main(void){
    double numApple, range;
    scanf("%lf %lf", &numApple, &range);
    int numPeople = findLeast(numApple, range);
    printf("%d\n", numPeople);
    return 0;
}

int findLeast(double numApple, double range){
    double realRange = 2*range + 1;
    int numLeast = (int) ceil(numApple/realRange);
    return numLeast;
}

Measured memory_bytes: 128
from collections import Counter
N=int(input())
S = []
S = Counter(input())
for i in range(N-1):
    s = input()
    for k,v in S.items():
        S[k] = min(v, s.count(k))

keys = [k for k in S.keys()]
keys.sort()
print(''.join([k*S[k] for k in keys]))


Measured memory_bytes: 3316