akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<vector<int> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

ll comb(ll n){
    return n*(n-1)/2;
}

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> a(m),b(m);
    rep(i,m){
        cin >> a[i] >> b[i];
        a[i]--;b[i]--;
    }
    UnionFind U(n);
    ll cur=comb(n);
    vector<ll>res;
    rep(i,m){
        res.push_back(cur);
        int c=a[m-1-i];
        int d=b[m-1-i];
        if(U.issame(c,d))continue;  
        ll sa=U.size(c);
        ll sb=U.size(d);          
        cur-=U.size(c)*U.size(d);
        U.merge(c,d);    
    }
    reverse(res.begin(),res.end());
    rep(i,res.size()){
        cout<<res[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 3444
import std.stdio;
import std.math;
import std.conv;
import std.string;

void main() {
    const int MAX = 1000000;
    int[MAX] p;
    p[2] = 1;
    for (int i = 3; i < MAX; i++) {
        if (i % 2 == 0) {
            p[i] = p[i-1];
        } else if (isPrime(i)) {
            p[i] = p[i-1] + 1;
        } else {
            p[i] = p[i-1];
        }
    }

    foreach (string line; stdin.lines) {
        int n = line.chomp.to!int;
        p[n].writeln;
    }
}

bool isPrime(double e) {
    bool res = true;
    for (int i = 3; i <= sqrt(e); i += 2) {
        if (e % i == 0) {
            res = false;
            break;
        }
    }
    return res;
}

Measured memory_bytes: 4956
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include<cstdio>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>

using namespace std;

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

int main(){

	double eps = 10e-7;
	double xA,yA,xB,yB,xC,yC,xD,yD;
	while(~scanf("%lf %lf %lf %lf %lf %lf %lf %lf",
		&xA,&yA,&xB,&yB,&xC,&yC,&xD,&yD)){
			if((xB-xA)*(xD-xC)+(yB-yA)*(yD-yC) == 0){
				cout << "YES" << endl;
			}else{
				cout << "NO" << endl;
			}
	}
}

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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define what_is(x) cerr << #x << " is " << x << endl;

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int n;
	scanf("%d", &n);
	vi a(n+1);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		a[i] -= i;
	}

	sort(++a.begin(), a.end());
	vll ps(n+1);
	for (int i = 1; i <= n; i++) ps[i] = ps[i-1] + a[i];
	ll best = 1e18L;
	for (int i = 1; i <= n; i++) {
		ll tmp = (ll)(i - 1) * a[i] - ps[i-1];
		tmp += ps[n] - ps[i] - (ll)(n - i) * a[i];
		best = min(best, tmp);
	}
	printf("%lld\n", best);
}


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

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

    if (k <= a)
        ans = k;
    else if (a + b >= k)
        ans = a;
    else
        ans = a - (k - a - b);

    cout << ans;
}

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

int main(){
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  vector<P> RLE;
  
  int r = 0;
  rep(l,n) {
    int cnt = 0;
    while (s[l] == s[r] && r < n) {
      r++;
      cnt++;
    }
    RLE.push_back({int(s[l] - '0'),cnt});
    l = r-1;
  }
  int m = sz(RLE);
  vector<int> num(m+1,0);

  rep(i,m) {
    num[i+1] = num[i] + RLE[i].second;
  }
  int res = 0;
  if (s[0] == '0') {
    for (int i = 1; i <= m; i++) {
      if (i + k*2 > m) res = max(res, num[m] - num[i-1]);
      else {
        if (i%2 != 0) res = max(res,num[i+k*2-1] - num[i-1]);
        else res = max(res,num[i+2*k] - num[i-1]);
      }
    }
  } else {
    for (int i = 1; i <= m; i++) {  
      if (i + k*2  > m) res = max(res, num[m] - num[i-1]);
      else {
        if (i%2 != 0) res = max(res,num[i+k*2] - num[i-1]);
        else res = max(res,num[i+2*k-1] - num[i-1]);
      }
    }
  }

  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 1652
import sys
N = int(input())
testmonies = [[-1] * N for _ in range(N)]
for i in range(N):
    for _ in range(int(input())):
        tmp = list(map(int, input().split()))
        testmonies[i][tmp[0]-1] = tmp[1]
ans = -1
for i in reversed(range(2 ** N)):
    for n in range(N):
        for j in range(N):
            if testmonies[j][n] == -1 or i >> j & 1 == 0:
                continue
            if testmonies[j][n] == i >> n & 1:
                continue
            else:
                break
        else:
            continue
        break
    else:
        tmp = bin(i).count('1')
        if tmp > ans:
            ans = tmp
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define cool ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int main()
{ 
    cool;
    string s1,s2;
    cin>>s1>>s2;
    int cnt=0;
    for(int i=0;i<3;i++)
    {
    	if(s1[i]==s2[i])
    	cnt++;
	}
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 256
import sys
import heapq

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N = ini()
A = inl()


def solve():
    A.sort(reverse=True)
    hp = [(-A[1], -A[0]), (-A[1], -A[0])]
    score = A[0]
    for i in range(2, N):
        asmall, abig = heapq.heappop(hp)
        score += -asmall
        heapq.heappush(hp, (-A[i], asmall))
        heapq.heappush(hp, (-A[i], abig))
    return score


print(solve())


Measured memory_bytes: 44404
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

int main()
{
	string a, b, c,ans;
	char x, y, z;
	cin >> a >> b >> c;
	x = toupper(a[0]);
	y = toupper(b[0]);
	z = toupper(c[0]);
	/*ans = a.substr(0, 1) + b.substr(0, 1) + c.substr(0, 1);
	transform(ans.begin(), ans.end(),ans.begin(),toupper);*/
	cout << x<<y<<z << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long
struct dat {
    int a, b, c, d;
};

signed main() {
    int n, m, q, res = 0;
    cin >> n >> m >> q;
    vector<dat> req(q);
    for (auto& i : req) cin >> i.a >> i.b >> i.c >> i.d;
    vector<int> a(n, 1);
    while(true) {
        int score = 0;
        for (int j = 0; j < q; ++j) {
            if (a[req[j].b - 1] - a[req[j].a - 1] == req[j].c)
                score += req[j].d;
        }
        res = max(res, score);

        ++a[n - 1];
        if (a[n - 1] > m) {
            int k = 1;
            while (n - 1 >= k && a[n - 1 - k] + 1 > m) ++k;
            if (n - 1 < k) break;
            for (int l = 0; l <= k; ++l) {
                a[n - 1 - l] = a[n - 1 - k] + 1;
            }
        }
    }
    cout << res;
}

Measured memory_bytes: 3544
//https://atcoder.jp/contests/abc090/tasks/arc091_b
//D - Remainder Reminder
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int main(){
#if LOCAL&01
    std::ifstream in("./test/sample-1.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif
    ll N,K; cin>>N>>K;
    dump(N,K);
    ll rev=0;
    if (K==0){ //0は別で...
        cout<<N*N<<endl;
        return 0;
    }

    FOR(b,1,N+1){ //bを固定して,数をもとめる
        auto rest = min<ll>(K-1,b-1);
        auto tmp = (N/b)*(rest+1); //+1は0の分
        auto tmp2 = min(N-(N/b)*b,rest);
        dump(b,rest,tmp,tmp2);
        rev += (tmp+tmp2);
    }
    auto ans = N*N-rev;
    cout<<ans<<endl;
}

int main_() {
#if LOCAL&01
    std::ifstream in("./test/sample-1.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif
    ll N,K; cin>>N>>K;
    ll ans=0;
    FOR(b,K+1,N+1){
//        cerr<<"-"<<b<<endl;
        for(ll k=K;k<b;++k){
            ll add = (k!=0)+(N-k)/b;
            ans += add; //k==0は+1しない
//            cerr<<k<<","<<add<<endl;
        }
//        cout<<ans<<endl;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);
const int maxn = 200010;

int n;
int A[maxn];
map <int,int> mp;

int32_t main() {
	FAST	
	cin >> n;
	for (int i =1;i<=n;i++) {
		cin >> A[i];
	}
	

	int ans = 0;
	for (int i =1;i<=n;i++) {
		ans += (mp[i - A[i]]);
		mp[A[i] + i] += 1;
	}
	cout << ans;
	
}



Measured memory_bytes: 27852
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
  int i;
  int j[8];
  int n,a,b,c;
  int a2;
  int b2;
  int c2;
  int a3;
  int b3;
  int c3;
  int l[8];
  int ans=2997;
  int ans2;
  scanf("%d %d %d %d",&n,&a,&b,&c);
  for(i=0;i<n;i++)
  {
    scanf("%d",&l[i]);
  }
  for(j[0]=0;j[0]<4;j[0]++){
    for(j[1]=0;j[1]<4;j[1]++){
      for(j[2]=0;j[2]<4;j[2]++){
        for(j[3]=0;j[3]<4;j[3]++){
          for(j[4]=0;j[4]<4;j[4]++){
            for(j[5]=0;j[5]<4;j[5]++){
              for(j[6]=0;j[6]<4;j[6]++){
                for(j[7]=0;j[7]<4;j[7]++){
                  a2=0;
                  b2=0;
                  c2=0;
                  a3=0;
                  b3=0;
                  c3=0;
                  ans2=0;
                  for(i=0;i<n;i++){
                    switch(j[i]){
                    case 0:
                      a2+=l[i];
                      a3++;
                      break;
                    case 1:
                      b2+=l[i];
                      b3++;
                      break;
                    case 2:
                      c2+=l[i];
                      c3++;
                      break;
                    case 3:
                      break;
                    }
                  }
                  if(a3!=0 && b3!=0 && c3!=0){
                    ans2=abs(a-a2)+abs(b-b2)+abs(c-c2)+10*(a3+b3+c3-3);
                    if(ans>ans2){
                      ans=ans2;
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 128
require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N = get_int

sixes = 1.step(7).map { |x| 6 ** x }
nines = 1.step(6).map { |x| 9 ** x }

array = [1, *sixes, *nines].sort

ax = [N]
count = 0
set = Set.new
loop do
  ax = ax.reduce([]) do |prev, cur|
    index = array.bsearch_index { |x| x > cur } - 1
    prev + array[0..index].map do |x|
      result = cur - x
      if set.include?(result)
        nil
      else
        set.add(result)
        result
      end
    end.compact
  end
  count += 1
  break if ax.find { |a| a == 0 }
end

puts count


Measured memory_bytes: 180996
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		
		Scanner scan = new Scanner(System.in);

		while(true){
			String x = scan.next();
			if(x.equals ("0")) break;
			
			int sl = x.length();
			int total = 0;
			for(int i=0; i<sl; i++){
				String s = x.substring(i, i+1);
				int X = Integer.parseInt(s);
				total = total + X;
			}
			System.out.println(total);
		}
	
	}

}

Measured memory_bytes: 26540
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}


int main() {
  int n;cin >> n;
  if(n==1)cout << "Hello World" << endl;
  else{int a,b;cin >> a >> b; cout << a+b << endl;}
}

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

int main()
{
	int n, w; cin >> n >> w;

	vector<vector<char>> a(n, vector<char>(w));

	vector<bool> rowBlackExist(n, false);
	vector<bool> columnBlackExist(w, false);

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < w; j++) {
			cin >> a[i][j];
			if (a[i][j] == '#') {
				rowBlackExist[i] = true;
				columnBlackExist[j] = true;
			}
		}
	}

	for (int i = 0; i < n; i++) {
		if (rowBlackExist[i]) {
			for (int j = 0; j < w; j++) {
				if (columnBlackExist[j]) cout << a[i][j];
			}
			cout << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

vl getV(ll x){
  vl t;
  while(sz(t) < 4){
    t.pb(x%2);
    x /= 2;
  }
  return t;
}
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    string s;
    cin >> s;
    rp(i,1<<3){
      vl cur = getV(i);
      string sans = "";
      ll res = s[0]-48;
      sans += string(1,s[0]);
      rp(j,3){
        if(cur[j] == 0){
          res -= (s[j+1]-48);
          sans += "-";
        }
        else {
            res +=(s[j+1]-48);
            sans += "+";
        }
        sans += string(1,s[j+1]);

      }
      if(res == 7) {
        cout << sans << "=7"<< endl;
        return 0;
      }
    }
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int N, lastDigit;

    scanf("%d", &N);


if(N>=100 && N<=999){
    while(N!=0)
{
    lastDigit=N%10;
    N=N/10;

if(lastDigit==7){
    printf("Yes");
    exit(0);

}
        lastDigit = 0;

}

    printf("No");
}

return 0;
}



Measured memory_bytes: 1728
import sys
#from me.io import dup_file_stdin

def print2d(m):
    for r in m:
        print("".join(["{:5d}".format(x) for x in r]))

#@dup_file_stdin
def solve():
    while True:
        n = int(sys.stdin.readline())
        if n == 0 :
            return
        m = []
        for i in range(n):
            m.append([int(x) for x in sys.stdin.readline().split(' ')])
        for r in range(n):
            m[r].append(sum(m[r]))
        lastRow = []
        for c in range(n+1):
            s = 0
            for r in range(n):
                s += m[r][c]
            lastRow.append(s)
        m.append(lastRow)
        print2d(m)
solve()

Measured memory_bytes: 7724
#include <algorithm>
#include <iostream>
#include <vector>

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

    std::vector<long long> v(5);
    for (int i = 0; i < 5; i++) {
        std::cin >> v[i];
    }

    long long smallest = *min_element(v.begin(), v.end());
    long long ans = 5 + (n + (smallest - 1)) / smallest - 1;
    std::cout << ans << std::endl;
}


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

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int s, t, v; cin >> s >> t >> v;
    
    if(s<=t*v) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 3592
x, y = map(int, input().split())
a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
c = [2]
for group in [a, b, c]:
    if x in group and y in group:
        print('Yes')
        exit()
print('No')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll inf= 2e18;
ll ar[100002],n;
ll br[100002],k;

ll dp(ll i,ll val)
{
    if(i==n){
        return abs(ar[n]-val);
    }
    if(i>n){
        return abs(inf-val);
    }
    if(br[i]!=-1){
        return br[i]+abs(ar[i]-val);
    }
    ll v1,v2=inf;
    for(int j=1;j<=k;j++){
        v1=dp(i+j,ar[i]);
        v2=min(v1,v2);
    }
    //v1=dp(i+1,ar[i]);
    //v2=dp(i+2,ar[i]);
    br[i]=v2;//min(v1,v2);
    //cout<<br[i]<<endl;
    return br[i]+abs(ar[i]-val);
}
int main()
{
    ll a,m;
    memset(br,-1,sizeof(br));
    cin>>n>>k;
    for(ll i=1;i<=n;i++){
        scanf("%lld",&ar[i]);
    }
    cout<<dp(1,ar[1])<<endl;

    return 0;
}


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

int main(void){
    int n;
    cin >> n;
    vector<string> vec(n);
    for(int i=0; i<n; i++){
        cin >> vec.at(i);
    }
    bool flag = true;
    for(int i=1; i<n; i++){
        for(int j=0; j<i; j++){
            if(vec.at(i) == vec.at(j)){
                flag = false;
                break;
            }
        }
        if(vec.at(i).front() != vec.at(i-1).back()){
            flag = false;
            break;
        }
    }

	if(flag == true){
    	cout << "Yes" << endl;
	}else{
    	cout << "No" << endl;
	}

    return 0;
}

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

#define int long long

signed main() {
    string n;
    cin >> n;
    string t = n;
    reverse(t.begin(), t.end());
    if(n==t) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 256
/*input
async layered coding
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
int main()
{
	IOS;
	int a,b;
	cin>>a>>b;
	cout<<(a+b+1)/2;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int n,a,b,c;
	while(scanf("%d",&n)!=EOF)
		while(n--)
		{
			{
				scanf("%d%d%d",&a,&b,&c);
				if(a>0&&b>0&&c>0&&(a+b)>c && (a+c)>b && (b+c)>a && abs(a-c)<b &&abs(b-c)<a&&abs(a-b)<c)
				{
					if(a*a+b*b==c*c||a*a+c*c==b*b||b*b+c*c==a*a)
						printf("YES\n");
					else
						printf("NO\n");
				}
				else
				{printf("NO\n");}
			}
		}
	return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

// Mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
//



int main() {
  string s;
  cin >> s;
  int ans = 1;
  int n = s.size();
  string t = "";
  t += s[0];
  string now = "";
  for (int i = 1; i < n; i++) {
    now += s[i];
    if (now == t) {
      continue;
    } else {
      ans++;
      swap(t, now);
      now = "";
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,i,j,ans = 0,s[1000001] = {};scanf("%d",&n);bool ok;
  int a[n];
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);s[a[i]]++;
  }
  for(i=0;i<n;i++){
    ok = true;
    if(s[a[i]]>1) continue;
    else if(a[i]==1){
      ans += s[1]==1;continue;
    }
    for(j=1;j*j<=a[i];j++){
      if(a[i]%j!=0) continue;
      if(s[j]>0){
        ok = false;break;
      }
      if(j>1 && s[a[i]/j]>0){
        ok = false;break;
      }
    }
    ans += ok;
  }
  printf("%d\n",ans);
}

Measured memory_bytes: 8408
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc057/tasks/abc057_b

"""
import sys
from sys import stdin
input = stdin.readline


def calc_dist(s, c):
    return abs(s[0] - c[0]) + abs(s[1] - c[1])


def solve(students, checkpoints):
    ans = []

    for s in students[1:]:
        dist = [float('inf')]
        for c in checkpoints[1:]:
            d = calc_dist(s, c)
            dist.append(d)
        min_dist = min(dist)
        cp_num = dist.index(min_dist )
        ans.append(cp_num)
    return ans


def main(args):
    students = [[0, 0]]
    N, M = map(int, input().split())
    for _ in range(N):
        a, b = map(int, input().split())
        students.append([a, b])
    checkpoints = [[0, 0]]
    for _ in range(M):
        c, d = map(int, input().split())
        checkpoints.append([c, d])
    ans = solve(students, checkpoints)
    print(*ans, sep='\n')


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3064
/*
 * AtCode Beginner Contest 138 : C.Alchemist
 * Author : anaksoleh
 * 18 August 2019
 *
 */

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

int N;
vector<double> v;

int main()
{
	cin>>N;

	double num;
	for(int i = 1 ; i <= N ; i++){
		cin>>num;
		v.push_back(num);
	}	

	sort(v.begin(),v.end());

	double jamu = v[0];
	for(int i = 1 ; i < N ; i++){
		jamu += v[i];
		jamu /= 2;
	}

	cout << jamu << '\n';

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <deque>
#define mp make_pair
using namespace std;
int n,in[100005],dp[100005];
vector <int> ve[100005];
void dfs(int x,int p){
	vector <int> vt;
	for (int i=0;i<ve[x].size();i++){
		if (ve[x][i]!=p){
			dfs(ve[x][i],x);
		}
	}
	for (int i=0;i<ve[x].size();i++){
		if (ve[x][i]!=p) vt.push_back(ve[x][i]);
	}
	int c=0;
	for (int i=0;i<vt.size();i++){
		if (dp[vt[i]]==0) c++;
		dp[x]+=dp[vt[i]];
	}
	dp[x]+=max(c-1,0);
}
int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	for (int i=0;i<n-1;i++){
		int f,t;
		cin>>f>>t;
		ve[f].push_back(t);
		ve[t].push_back(f);
		in[f]++;
		in[t]++;
	} 
	if (n<3){
		cout<<1<<endl;
		return 0;
	}
	int maxi=0;
	for (int i=0;i<n;i++){
		if (in[i]>in[maxi]) maxi=i;
	}
	dfs(maxi,maxi);
	cout<<dp[maxi];
	return 0;
}

Measured memory_bytes: 15744
#include <iostream>
using namespace std;
typedef long long ll;

ll MOD_N = 1e9 + 7;


int main() {
    int N, M;
    cin >> N >> M;
    int S[N];
    int T[M];
    for (int i = 0; i < N; ++i) {
        cin >> S[i];
    }
    for (int i = 0; i < M; ++i) {
        cin >> T[i];
    }
    ll sums[N][M];
    sums[0][0] = (S[0] == T[0]) ? 1 : 0;
    for (int i = 1; i < N; ++i) {
        ll c = (S[i] == T[0]) ? 1 : 0;
        sums[i][0] = sums[i-1][0] + c;
    }
    for (int j = 1; j < M; ++j) {
        ll c = (S[0] == T[j]) ? 1 : 0;
        sums[0][j] = sums[0][j-1] + c;
    }
    for (int i = 1; i < N; ++i) {
        for (int j = 1; j < M; ++j) {
            ll count, sum;
            if (S[i] == T[j]) {
                count = sums[i-1][j-1] + 1;
            } else {
                count = 0;
            }
            sum = sums[i-1][j] + sums[i][j-1] - sums[i-1][j-1] + count;
            sums[i][j] = (sum + MOD_N) % MOD_N;
        }
    }
    ll ans = (sums[N-1][M-1] + 1) % MOD_N;
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 31488
#include <iostream>
#include <vector>
using namespace std;
int main() {
	int N, m;
	cin >> N >> m;
	vector<bool> b(N);
	for (int i = 0; i < m; ++ i) {
		int c, d;
		cin >> c >> d;
		-- c; -- d;
		for (int j = c; j < d; ++ j) {
			b[j] = true;
		}
	}
	int r = N+1;
	for (int i = 0; i < N; ++ i) if (b[i]) r += 2;
	cout << r << endl;
}


Measured memory_bytes: 1200
n = int(input())
arr = list(map(int, input().split()))
res, i = 0, 0
while i < n:
    j = i
    while j < n-1 and arr[j]>=arr[j+1]:
        j += 1
    res = max(res, j-i)
    i = j+1
print(res)


Measured memory_bytes: 63856
#include <stdio.h>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <sstream>

using namespace std;

typedef long long int ll;

ll solve( ll N );

int main(void) {
	
	ll N;
	cin >> N;
	cout << solve(N) << endl;
	return 0;
}

ll solve( const ll N ) {

	set<int> st;
	vector<int> d(N);
	vector<int> f(100,0);

	int ans = -1;

	for( int i = 0; i < N; i++ )
		cin >> d[i];

	for( int i = 0; i < 100000; i++ ) {

		if( st.find(i)!=st.end() ) { continue; }

		stringstream ss;
		ss << i;

		if( !f[ss.str().length()] ) {
			for( int j = 0; j < N; j++ ) {

				int sum = 0;
				for( int k = 0; (k < ss.str().length()) && (j+k<N); k++ ) {
					sum = sum*10+d[j+k];
				}
				st.insert(sum);

			}
			f[ss.str().length()] = 1;
		}
		
		if( st.find(i)==st.end() ) {
			ans = i;
			break;
		}

	}

	return ans;

}

Measured memory_bytes: 3224
import sys
input = sys.stdin.readline

import numpy as np

"""
各辺に対して、Ax,Byの好きな方をとれるとしてよい
全部で半分ずつ → たいてい実現可能

・全部ox
・全部xo
・xx,ooともに存在→ひとつ oo で決め打てば、貪欲に半分とれる
"""

N = int(input())
AB = np.array([[int(x) for x in input().split()] for _ in range(N)],dtype=np.int64)

answer = AB[:,0].sum()
answer = min(answer,AB[:,1].sum())

AB.sort(axis=1)
A,B = AB.T
i = A.argsort()
A = A[i]; B = B[i]

if A.max() > B.min():
    # 全体から貪欲にN個
    C = np.concatenate([A,B])
    C.sort()
    answer = min(answer, C[:N].sum())

# 全体から両取りを1つ
x = A[:-1].sum() + B[:-1].min()
y = A[-1]+B[-1] + A[:-2].sum()
answer = min(answer,x,y)

print(answer)

Measured memory_bytes: 33728
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define REP1(i,n) for(int i=1;i<=(int)(n);i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)


int main(){
  int N,temp=0,aans=0,bans=0;
  vector<int>deck(N);
  vector<int>alice;
  vector<int>bob;
  cin >> N;
  REP(i,N)cin >> deck.at(i);

  REP(i,N){
    if(deck.at(temp)>deck.at(i))continue;
    else temp=i;
  }

  REP(i,N){
    REP(j,N){
      if(deck.at(temp)>deck.at(j))continue;
      else temp=j;
    }
    
    if(i%2==0)alice.push_back(deck.at(temp));
    else bob.push_back(deck.at(temp));
    deck.at(temp)=0;
  }

  REP(i,alice.size())aans+=alice.at(i);
  REP(i,bob.size())bans+=bob.at(i);

  cout << aans-bans << endl;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
		public static void main(String args[]) {
			Scanner sc = new Scanner(System.in);
			String str;
			int chara = 0;
			int flag = 0;
			while(sc.hasNext()) {
				if(flag != 0) {
					System.out.printf(" ");
				} else {
					flag = 1;
				}
				str = sc.next();
				for(int j = 0; j < str.length(); j++) {
					chara = str.charAt(j);
					if(chara >= 'a' && chara <= 'z') {
						chara -= 'a' - 'A';
					} else if(chara >= 'A' && chara <= 'Z') {
						chara -= 'A' - 'a';
					}
					System.out.printf("%c", chara);
				}
			}
			sc.close();
		
			System.out.println();
	}
}


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

int main(){
    int a;
    cin >> a;
    int sum = 0;
    vector<int> A(a);
    rep(i,a){
        cin >> A.at(i);
        sum += A.at(i);
    }
    double ave = (double)sum/(double)a;
    if(fmod(ave,1) > 0.5)
        ave = sum/a + 1;
    else
        ave = sum/a;
    int m = 0;
    rep(i,a){
        m += pow(A.at(i) - (int)ave,2);
    }
    cout << m << endl;
}


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

#define F first
#define S second
#define pii pair<int, int>
#define pb push_back

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 1e5 + 10;

int dp[N], mw[N], pd[N], child[N];
bool path[N];
vector<int> adj[N];

void DFS(int v, int par = -1)
{
	int _child_num = 0, non_path = -1, _child_id = -1, mx = 0, sum1 = 0, sum2 = 0, sum3 = 0, cnt = 0;
	for(auto u : adj[v]){
		if(u == par)continue;
		DFS(u, v);
		_child_num ++;
		_child_id = u;
		sum1 += dp[u];
		sum2 += mw[u];
		sum3 += pd[u];
		if(path[u])mx = max(mx, dp[u]), cnt ++;
		else non_path = u;
	}
	child[v] = _child_num;
	if(_child_num == 0){
		path[v] = true;
		dp[v] = mw[v] = pd[v] = 1;
		return ;
	}
	else if(_child_num == 1){
		path[v] = path[_child_id];
		if(child[_child_id] == 1)dp[v] = dp[_child_id];
		else dp[v] = pd[_child_id];
		mw[v] = mw[_child_id];
		pd[v] = 1 + mw[_child_id];
		return ;
	}

	if(_child_num >= 3)
	{
		if(cnt == 0)
		{
			dp[v] = sum2;
			mw[v] = sum2;
			pd[v] = sum2;
			return ;
		}
		if(cnt >= 1)
		{
			dp[v] = sum2 - 1;
			mw[v] = sum2 - 1;
			pd[v] = sum2;
			return ;
		}
	}
	else if(_child_num == 2)
	{
		if(cnt == 0)
		{
			dp[v] = sum2;
			mw[v] = sum2;
			pd[v] = sum2;
			return ;
		}else if(cnt == 2)
		{
			dp[v] = 1;
			mw[v] = 1;
			pd[v] = 2;
			return ;
		}else
		{
			if(child[non_path] >= 1)dp[v] = pd[non_path];
			else dp[v] = dp[non_path];
			mw[v] = mw[non_path];
			pd[v] = 1 + mw[non_path];
			return ;
		}
	}

	return ;

}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	for(int i=0; i<n-1; i++)
	{
		int u, v; cin >> u >> v;
		adj[u].pb(v);
		adj[v].pb(u);
	}

	DFS(0);

	//for(int i=0; i<n; i++)
	//	cout << i << "," << dp[i] << ':' << mw[i] << ':' << pd[i] << endl;

	cout << dp[0] << endl;

}

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

long long val(string s){
	long long temp = 0;
	for(int i = 0;i < s.size();++i){
		temp *= 10;
		temp += s[i] - '0';
	}
	
	return temp;
}

int val_c(char c){
	return c - '0';
}

long long sub(string val1, string val2){
	long long temp1 = val(val1);
	long long temp2 = val(val2);
	
	return abs(temp1 - temp2);
}

long long checkEqual(string S){
	string mins, maxs;
	long long ans = 8;
	
	for(int k = 1;k < S.size();++k){
		if(S.size() % k != 0) continue;
		
		mins = maxs = S.substr(0, k);
		
		for(int s = 0;s < S.size();s += k){
			maxs = max(maxs, S.substr(s, k));
			mins = min(mins, S.substr(s, k));
		}
		
		ans = min(ans, sub(maxs, mins));
		
	}
	
	return ans;
}

long long check(string S){
	long long maxv = 0;
	long long minv = 10;
	long long p = 0, v;
	
	while(p < S.size()){
		v = val_c(S[p]);
		if(S[p] == '1' && p + 1 < S.size()){
			v = 10 + val_c(S[p + 1]);
			++p;
		}
		
		maxv = max(maxv, v);
		minv = min(minv, v);
		
		++p;
	}
	
	return abs(maxv - minv);
}

int main(){
	string s;
	cin >> s;
	
	long long ans = 8;
	
	ans = min(ans, checkEqual(s));
	ans = min(ans, check(s));
	
	cout << ans << endl;
	
	return 0;
}



Measured memory_bytes: 3288
#https://atcoder.jp/contests/abc165/submissions/12672182
#写経
import itertools
import numpy as np

def resolve():
    N,M,Q = map(int,input().split())
    A = np.array(list(itertools.combinations_with_replacement(range(1,M+1),N)))
    s = np.zeros(len(A), np.int32)
    for i in range(Q):
        a,b,c,d = map(int,input().split()) 
        s += d * (A[:,b-1] - A[:,a-1] == c)
    print(s.max())
resolve()

Measured memory_bytes: 46776
import sys
for line in sys.stdin:
    a,b,c = line.split()
    a,c = int(a), int(c)
    p = '+-*/?'.index(b)
    if p == 0: a += c
    elif p == 1: a -= c
    elif p == 2: a *= c 
    elif p == 3: a /= c
    elif p == 4: break
    print a

Measured memory_bytes: 6436
#include <cstdio>
#include <queue>
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    int a[3*n]; for (int i = 0; i < 3*n; i++) cin >> a[i];
    long long b[n+1], c[n+1];
    long long sum = 0;
    priority_queue<int> temp;
    int i = 0;
    while (i < n) sum += a[i], temp.push(-a[i]), i++;
    b[0] = sum;
    while (i < 2*n) {
        int m = -temp.top();
        if (m < a[i]) {
            temp.push(-a[i]);
            temp.pop();
            sum += a[i] - m;
        }
        b[i-n+1] = sum;
        i++;
    }
    i = 3*n-1;
    temp = priority_queue<int>();
    sum = 0;
    while (i >= 2*n) sum += a[i], temp.push(a[i]), i--;
    c[n] = sum;
    while (i >= n) {
        int m = temp.top();
        if (m > a[i]) {
            temp.push(a[i]);
            temp.pop();
            sum += a[i] - m;
        }
        c[i-n] = sum;
        i--;
    }

    long long ans = -(1LL<<60);
    for (i = 0; i <= n; i++) ans = max(ans, b[i] - c[i]);
    cout << ans << endl;
}


Measured memory_bytes: 3952
// 23.07.2017



# include <iostream>
# include <iomanip>
# include <cstdio>
# include <cstdlib>
# include <cmath>
# include <cstring>
# include <vector>
# include <stack>
# include <queue>
# include <algorithm>


//# define __TRR__

using namespace std;

int n, m, k, gcd, ma;
bool ok;

int GCD (int, int);

int main ()
{
# ifdef __TRR__
   freopen ("A.TXT", "r", stdin);
   freopen ("A.OUT", "w", stdout);
# endif

   cin >> n >> k >> gcd;

   ma = gcd;
   for ( int i=1; i < n; i++ )
   {
      cin >> m;
      gcd = GCD (gcd, m);
      if ( m == k )
         ok = true;
      if ( m > ma )
         ma = m;
   }

# ifdef __TRR__
   cout << n << " " << k << " " << ma << " " << gcd << endl;
# endif

   if ( ok || k % gcd == 0 && k <= ma )
      cout << "POSSIBLE";
   else
      cout << "IMPOSSIBLE";

//system ("pause");
   return 0;
}

int GCD (int a, int b)
{
   while ( a > 0 && b > 0 )
      if ( a > b )
         a %= b;
      else
         b %= a;
   return ( a > 0 ? a : b );
}


Measured memory_bytes: 256
#include <cstdio>

int const N = 1234567;

int p[N], was[N];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", p + i);
    --p[i];
  }
  // long long ans = 0;
  // for (int i = 0; i < n; i++) {
  //   if (was[i]) continue;
  //   int v = i;
  //   while (!was[v]) {
  //     was[v] = i + 1;
  //     v = p[v];
  //   }
  //   if (was[v] == i + 1) {
  //     int u = p[v];
  //     int cc = 1;
  //     while (u != v) {
  //       u = p[u];
  //       ++cc;
  //     }
  //     ans += (long long) cc * (cc - 1) / 2;
  //   }
  // }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (p[p[i]] == i) {
      ++ans;
    }
  }
  printf("%d\n", ans / 2);
}

Measured memory_bytes: 512
# ABC087C - Candies (ARC090C)
def main():
    N, *A = map(int, open(0).read().split())
    ans, x, y = 0, A[:N], A[N:]
    for i in range(N):
        ans = max(ans, sum(x[: i + 1]) + sum(y[i:]))
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
from functools import reduce
from itertools import combinations
from operator import mul


def solve(string):
    n, *s = string.split()
    num = [len([True for _s in s if _s[0] == _i]) for _i in "M A R C H".split()]
    num = [n for n in num if n > 0]
    return str(sum([reduce(mul, n) for n in combinations(num, 3)]))


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))


Measured memory_bytes: 12544
#include <iostream>
#include <cstdio>
using namespace std;
string str[] ={"101","000000",  "000011",  "10010001",  "010001",  "000001",  "100101",  "10011010",  "0101", "0001",
	       "110",  "01001",  "10011011",  "010000",  "0111",  "10011000",  "0110",  "00100",  "10011001",
	       "10011110",  "00101",  "111",  "10011111",  "1000",  "00110",  "00111",  "10011100",  "10011101",
	       "000010","10010010",  "10010011", "10010000"};
string str2[] = {" ","'",",","-",".","?","A","B","C","D","E","F","G","H",
		 "I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
string s3[] = {"11010","11011","11100","11101", "11110","11111",
	       "00000","00001","00010","00011","00100","00101","00110","00111","01000","01001",
	       "01010","01011","01100","01101","01110","01111","10000","10001","10010","10011",
	       "10100","10101","10110","10111","11000","11001"};
int main(){
  string str3 = "";
  while(getline(cin,str3)){

  string s4 = "";


  for(int i = 0 ; i < str3.size() ; i++){

    if(33 <= str3[i] - ' ' && str3[i] - ' ' <=58){
      s4+=str[str3[i] - ' ' - 27];
    }else if(str3[i] - ' ' == 7 ){
      s4+=str[1];
    }else if(12 <= str3[i] - ' '&& str3[i] - ' ' <= 14){
      s4+=str[str3[i] - ' ' - 10];
    }else if(str3[i] - ' ' == 31){
      s4+=str[5];
    }else s4 += str[0];
  }

  while(s4.size()%5 != 0){
    s4 += '0';
  }

  string s5 = "";
  swap(str2[1],str2[4]);
  for(int i = 0 ; i < s4.size() ; i += 5){
    string s = "";
    for(int k = i ; k < i+5 ; k++){
      s+=s4[k];
    }

    for(int j = 0 ; j < 32 ; j++ ){
      if(s == s3[j])s5+=str2[j];
    }
  }
  cout << s5 << endl;
  swap(str2[1],str2[4]);
  cin.clear();
  }
}

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

int main(){
  int n,m;
  cin>>n>>m;
  const int oo= 1e9+9;
  int a,b;
  int al=-oo,br=oo;
  while(m--){
  	cin>>a>>b;
    if(a>al) al=a; 
    if(b<br) br=b;
  }
  if(br<al) cout<<0;
  else cout<<br-(al-1);
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(long long i = 0; i < (long long)(N); i++)
#define repr(i,N) for(long long i = (long long)(N) - 1; i >= 0; i--)
#define rep1(i,N) for(long long i = 1; i <= (long long)(N) ; i++)
#define repr1(i,N) for(long long i = (N) ; (long long)(i) > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; template<class T = ll> using V = vector<T>;
using vi = V<int>; using vl = V<>; using vvi = V< V<int> >;
constexpr int inf = 1001001001; constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif

#define in2(N,s,t) rep(i,N){in(s[i] , t[i]);}
#define in3(N,s,t,u) rep(i,N){in(s[i] , t[i] , u[i]);}
using vd = V<double>; using vs = V<string>; using vvl = V< V<> >;
template<typename T>using heap = priority_queue< T , V<T> , greater<T> >;

using P = pair<int,int>; using vp = V<P>;
constexpr int MOD = /** 1000000007; //*/ 998244353;
//////////////////

void solve(){
  ins(S);
  if(S == "zyxwvutsrqponmlkjihgfedcba") die(-1);
  if(S.size() == 26){
    int idx = 24;
    while(S[idx] > S[idx + 1]) idx--;
    int jdx = 25;
    while(S[idx] > S[jdx]) jdx--;
    swap(S[idx] , S[jdx]);
    S.erase(S.begin() + idx + 1 , S.end());
    die(S);
  }
  int cnt[26] = {};
  rep(i , sz(S)) cnt[S[i] - 'a']++;
  trca(cnt,26);
  rep(i , 26){
    if(cnt[i] == 0){
      S.push_back('a' + i);
      break;
    }
  }
  out(S);

}

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

#define int long long

#define inf 1000000007LL
#define mod 1000000007LL

#define rep(i, n) for(int i = 0; i < (n); i++)
#define trep(i, n) for(int i = 0; i <= (n); i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define mfor(i, s, t) for(int i = (s); i < (t); i++)
#define tfor(i, s, t) for(int i = (s); i <= (t); i++)
#define rfor(i, s, t) for(int i = (t) - 1; i >= (s); i--)

signed main() {
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  rep(i, n) {
    int mi = a + i * c - (n - 1 - i) * d;
    int ma = a + i * d - (n - 1 - i) * c;
    if(mi <= b && b <= ma) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
#define SIZE 200000
const int mod = 1e9+7;

ll inv[SIZE], fac[SIZE], finv[SIZE];

void comInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < SIZE; i++) {
        inv[i] = mod - inv[mod%i] * (mod/i) % mod;
        fac[i] = fac[i-1] * (ll)i % mod;
        finv[i] = finv[i-1] * inv[i] % mod;
    }
}

ll com(int a, int b) {
    if (a < b) return 0;
    return fac[a] * (finv[b] * finv[a-b] % mod) % mod;
}

int main() {
    comInit();
    int H, W, A, B;
    cin >> H >> W >> A >> B;
    ll ans = 0;
    for (int i = B; i < W; i++) {
        // (0,0)から(H-A-1, i)まで
        ll path1 = com(i+H-A-1, i) % mod;
        // (H-A, i)から(H-1, W-1)まで
        ll path2 = com(W-i-1+A-1, A-1) % mod;
        ans += (path1 * path2) % mod;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4992
//
//  main.cpp
//  B - Golden Coins
//
//  Created by Hashizo on 2020/03/28.
//  Copyright © 2020 Hashizo. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <regex>
#include <cmath>

using namespace std;
 
#undef LONG_MAX
#undef LONG_MIN
 
#define LONG_MAX    9223372036854775807
#define LONG_MIN    (-LONG_MAX  -1)
 
#define ll long long
 
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
 
#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())

int main(int argc, const char * argv[]) {
	ll ans = 0;
	
	ll n;
	cin >> n;

	ans += (n / 500) * 1000;
	ans += ((n % 500) / 5) * 5;

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


Measured memory_bytes: 256