akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

void solve()
{
    int w, h, n; cin >> w >> h >> n;
    int xl = 0, xr = w, yt = h, yb = 0;
    for(int i = 0; i < n; ++i){
        int type;
        int x, y;
        cin >> x >> y >> type;
        switch(type){
            case 1:
                if(x > xl)xl = x;
                break;
            case 2:
                if(x < xr)xr = x;
                break;
            case 3:
                if(y > yb)yb = y;
                break;
            case 4:
                if(y < yt)yt = y;
                break;
        }
    }
    // cout << "xr, xl, yt, yb" << xr << " " << xl << " " << yt << " " << yb << endl;
    if(xr <= xl || yt <= yb) cout << 0 << endl;
    else cout << (yt-yb)*(xr-xl) << endl;
}

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

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; 
typedef pair<ll, ll> pii; 
typedef pair<ll, ll> pll; 
typedef pair<string, string> pss; 
typedef vector<ll> vi; 
typedef vector<vi> vvi; 
typedef vector<pii> vii; 
typedef vector<pll> vll; 
typedef vector<ll> vl; 
typedef vector<vl> vvl; 

int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout); 
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ; cout.tie(NULL);
    int tt;
    // cin>>tt;
    tt=1;
    while(tt--){
        ll i,j,k,n,a,b,c,d;
        cin>>a>>b>>c>>d;
        ll ans=a*c;
        ans=max(ans,b*d);
        ans=max(ans,a*d);
        ans=max(ans,b*c);
        cout<<ans<<endl;
    }
    
    return 0;
}

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

int main() {
  int N,K,s,i,l;
  cin >> N >> K;
  s = 0;
  for (i=0;i<N;i++){
    cin >>l;
    if(2*l < K)
      s += 2*l;
    else if(l < K < 2*l)
      s += 2*K - 2*l;
    else
      s += 2*l - 2*K;
  }
  cout << s << endl;
}
    

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

ll dp[50][450][450];  // dp[i+1][j][k] : i番目(iは0-index)の薬品まででタイプAの物質jグラム,タイプBの物質kグラムとなるときの合計価格の最小値
 
int main() {
    ll n, ma, mb;
    cin >> n >> ma >> mb;

    vl a(n), b(n), c(n);
    rep(i, n) {
        cin >> a[i] >> b[i] >> c[i];
    }

    rep(i, 50) {
        rep(j, 450) {
            rep(k, 450) {
                dp[i][j][k] = INF;
            }
        }
    }

    dp[0][0][0] = 0;
    rep(i, n) {
        exrep(j, 0, 400) {
            exrep(k, 0, 400) {
                chmin(dp[i+1][j][k], dp[i][j][k]);
                chmin(dp[i+1][j + a[i]][k + b[i]], dp[i][j][k] + c[i]);
            }
        }
    }

    ll ans = INF;
    exrep(j, 1, 400) {
        exrep(k, 1, 400) {
            if(ma*k == mb*j) {
                chmin(ans, dp[n][j][k]);
            }
        }
    }

    if(ans == INF) {
        out(-1);
    }
    else {
        out(ans);
    }
    
    re0;
}

Measured memory_bytes: 79360
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T> void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T> void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U> bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U> bool isin(T el, U container) { return find(all(container), el) != container.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> bool even(T n) { return ! (n & 1); }
template<class T> bool odd(T n) { return n & 1; }
template<class T> ll rup(T a, T b) { return a % b ? a / b + 1 : a / b; }
template<class T> ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T> ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;
ll intpow(ll a, ll n, ll _mod=numeric_limits<ll>::max()) { ll p=1; while (n) { if (n&1) p=p*a%_mod; a=a*a%_mod; n>>=1; } return p; } 
ll modc(ll a, char op, ll b, ll _mod=mod)
{
        a %= _mod; b %= _mod; ll res = 1;
        switch(op) {
        case '+': res = (a + b) % _mod; break;
        case '-': res = (a - b) % _mod; break;
        case '*': res = a * b % _mod; break;
        case '/': res = modc(a, '*', modc(b, '^', _mod-2, _mod), _mod); break;
        case '^': res = intpow(a, b, _mod); break;
        case 'P': rep(i, a-b+1, a+1) res = modc(res, '*', i, _mod); break;
        case 'C': res = modc(modc(a, 'P', b, _mod), '/', modc(b, 'P', b, _mod)); break;
        } 
        if (res < 0) { res += _mod; } return res;
}



int main()
{
        ll n, a, b;
        cin >> n >> a >> b;
        ll ans = intpow(2, n, mod) - 1;
        ll x = modc(n, 'C', a);
        ll y = modc(n, 'C', b);
        ans = modc(ans, '-', x);
        ans = modc(ans, '-', y);

        cout << ans << endl;
}


Measured memory_bytes: 3676
using System;

namespace AOJ.Volume1
{
    public class ClockShortHandAndLongHand
    {
        public static int Main()
        {
            int n = int.Parse(Console.ReadLine());
            for (int i = 0; i < n; i++)
            {
                var input = Console.ReadLine().Split(':');
                int hour = int.Parse(input[0]);
                int minute = int.Parse(input[1]);

                // 00:00を長針、短針とも0度とする
                // 短針(hour)の角度→1時間に30度、1分に0.5度進む
                double sh = (hour * 30) + (minute * 0.5);
                // 長針(minute)の角度→1分に6度進む
                double lg = minute * 6;

                double dig = Math.Abs(sh - lg);
                // 180度を超えている場合は補正
                if (dig > 180) { dig = 360 - dig; }

                if (dig < 30) { Console.WriteLine("alert"); }
                else if (dig >= 90 && dig <= 180) { Console.WriteLine("safe"); }
                else { Console.WriteLine("warning"); }
            }
            return 0;
        }
    }
}

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

int main(){
	std::string str;
	std::cin>>str;

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

		if (str[i] == 'U' || str[i] == 'D') {
			continue;
		}

		if (i % 2 == 0) {
			if (str[i] != 'R') {
				std::cout << "No" << std::endl;
				exit(0);
			}
		}
		if (i % 2 == 1) {
			if (str[i] != 'L' ) {
				std::cout << "No" << std::endl;
				exit(0);
			}
		}
		
	}

	std::cout<<"Yes"<<std::endl;
	return 0;
}

Measured memory_bytes: 256
from itertools import accumulate
n, q = map(int, input().split())
s = input()
A =[1 if s[i]+s[i+1] == 'AC' else 0 for i in range(n-1)]

S = [0] + list(accumulate(A))

Q = []
Q_append = Q.append
for _ in range(q):
    l, r = map(int, input().split())
    Q_append((l-1, r-1))

for qi in Q:
    print(S[qi[1]]-S[qi[0]])

Measured memory_bytes: 22216
#include <stdio.h>

int main(void)
{
	long a;
	long b;
	long A;
	long B;
	long r;
	long gcd;
	long lcm;
	
	
	
	while (scanf("%ld %ld", &a, &b) != EOF){
		
		r = 1;
		A = a;
		B = b;
		
		if (a < b){
			r = a;
			a = b;
			b = r;
		}
		
		while (r != 0){
			r = a - b;
			if (b < r){
				a = r;
			}
			else{
				a = b;
				b = r;
			}
		}
		
		gcd = a;
		lcm = A * B / gcd;
		
		printf("%ld ", gcd);
		printf("%ld\n", lcm);
	}
	
	return (0);
}

Measured memory_bytes: 596
#include<iostream>
#include<vector>
#include<utility>
#include<queue>
#define INF 1111111
using namespace std;
typedef pair<int,int> P;
int h,w;
char map[55][55];
int passed[55][55];
queue<P> q;
int dy[4] = {0,-1,0,1};
int dx[4] = {1,0,-1,0};
int ans;

void bfs(){
  while(q.size()){
    P yx = q.front();
    q.pop();
    for(int i=0;i<4;i++){
      int ny = yx.first+dy[i];
      int nx = yx.second+dx[i];
      if(ny>=0 && ny<h && nx>=0 && nx<w){
        if(map[ny][nx] == '.' && passed[ny][nx] == INF){
          passed[ny][nx] = passed[yx.first][yx.second]+1;
          q.push(P(ny,nx));
        }
        else if(ny == h-1 && nx == w-1){
          while(q.size())
            q.pop();
          break;
        }
      }
    }
  }
  return;
}


int main(){
  cin >> h >> w;
  ans = h*w;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      passed[i][j] = INF;
  
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> map[i][j];
      if(map[i][j] == '#')
        ans--;
    }
  }
  q.push(P(0,0));
  passed[0][0] = 1;
   
  bfs();
  if(passed[h-1][w-1] != INF)
  cout << (ans-passed[h-1][w-1]) << endl;
  else
  cout << -1 << endl;

}
  
  

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

n,m = l_in()
h = l_in()

edges=[[] for _ in range(n)]
good=[True]*n

for _ in range(m):
    a,b=l_in()
    if h[a-1] > h[b-1]:
        good[a-1] = good[a-1] and True
        good[b-1] = False
    if h[b-1] > h[a-1]:
        good[b-1] = good[b-1] and True
        good[a-1] = False
    if h[b-1] == h[a-1]:
        good[b-1] = False
        good[a-1] = False

print(len(list(filter(lambda a: a, good))))
        


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

using namespace std;
using ll = long long;

template <typename K,typename V>
using umap = unordered_map<K,V>;
template <typename V>
using uset = unordered_set<V>;
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; }
#define REP(i,n) for(int i=0;i<n;i++)
#define REPD(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(v) v.begin(),v.end()

#define INF 1'000'000'000'000 //10^12
#define MOD 1'000'000'007


ll gcd(ll a,ll b){
    if(b == 0){
        return a;
    }else{
        return gcd(b,a%b);
    }
}

int main(){

    int n,W;
    cin >> n >> W;
    int inf = 1000000001;

    int v[n],w[n];
    REP(i,n){
        cin >> w[i] >> v[i];
    }
    vector<vector<ll>> dp(n+1,vector<ll>(100001,inf));



    dp[0][0] = 0;

    for(int i=0;i<n;i++){
        for(int j=0;j<=100000;j++){
            if(j-v[i]>=0){
                dp[i+1][j] = min(dp[i][j] , dp[i][j-v[i]] + w[i]);
            }else{
                dp[i+1][j] = dp[i][j];
            }
        }
    }

    for(int i=100000;i>=0;i--){
        if(dp[n][i] <=W){
            cout << i << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 83256
#include <iostream>
using namespace std;
int main(void){
    char a,b;
  string x;
  cin>>x;
  if(x.size()>=3){
      a = x.at(0);
      b = x.at(x.size() -1);
      cout<<a<<x.size()-2<<b<<endl;
  } else if(x.size()==1){
      cout<<x.at(0)<<endl;
  } else if(x.size() == 2){
      cout<<x.at(0)<<x.at(1)<<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	string t;
	cin>>s>>t;
	bool ok = false;
	for(int i = 0; i < t.size(); ++i){
		string y = ""; y = t[t.size() - 1];
		string x = t.substr(0, t.size() - 1);
		y += x;
		t = y;
		if(t == s){
			ok = true;
			break;
		}
	}
	if(ok){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
import scala.io.Source

object Main{
  def main(args: Array[String]){
    val dices = for{
      in <- Source.stdin.getLines.toList
    } yield in

    val targets = dices.tail.map(_.split(" ").toList.map(_.toInt)).combinations(2)
    val list = for{
      target <- targets
    } yield {
      val dice1 = new Dice(target.head)
      val dice2 = new Dice(target.last)
      dice1.isEqual(dice2)
    }

    println(if(!list.foldLeft(false)((a,b) => a || b)) "Yes" else "No")
  }
}

class Dice(sur: List[Int]){
  private val index: List[Int] = sur

  def findRight(list: List[Int]): Int={
    val dice = new Dice(index)
    val kindOfDices = List[Dice](dice, dice.rotN, dice.rotS, dice.rotW, dice.rotE, dice.rotN.rotN)
    val finddice = for{
      kindOfDice <- kindOfDices
    }yield kindOfDice match{
      case x if(x.getVal(0) == list(0) && x.getVal(1) == list(1)) => x.getVal(2)
      case x if(x.rotR.getVal(0) == list(0) && x.rotR.getVal(1) == list(1)) => x.rotR.getVal(2)
      case x if(x.rotR.rotR.getVal(0) == list(0) && x.rotR.rotR.getVal(1) == list(1)) => x.rotR.rotR.getVal(2)
      case x if(x.rotR.rotR.rotR.getVal(0) == list(0) && x.rotR.rotR.rotR.getVal(1) == list(1)) => x.rotR.rotR.rotR.getVal(2)
      case _ => 0
    }

    finddice.sum
  }

  def isEqual(dice2:Dice): Boolean={
    val dice = new Dice(index)
    val kindOfDices = List[Dice](dice, dice.rotN, dice.rotS, dice.rotW, dice.rotE, dice.rotN.rotN)

    val torf = for{
      kindOfDice <- kindOfDices
    } yield kindOfDice match{
      case x if(x.index == dice2.index) => true
      case x if(x.rotR.index == dice2.index) => true
      case x if(x.rotR.rotR.index == dice2.index) => true
      case x if(x.rotR.rotR.rotR.index == dice2.index) => true
      case _ => false
    }

    def recConfirm(list: List[Boolean]): Boolean={
      if(list == Nil) false
      else list.head || recConfirm(list.tail)
    }

    recConfirm(torf)
  }

  def getVal(i: Int): Int = index(i)

  def rotR(): Dice =
    new Dice(index).rotS.rotW.rotN

  def rotN(): Dice =
    new Dice(List[Int](index(1), index(5), index(2), index(3), index(0), index(4)))

  def rotS(): Dice =
    new Dice(List[Int](index(4), index(0), index(2), index(3), index(5), index(1)))

  def rotW(): Dice =
    new Dice(List[Int](index(2), index(1), index(5), index(0), index(4), index(3)))

  def rotE(): Dice =
    new Dice(List[Int](index(3), index(1), index(0), index(5), index(4), index(2)))
}

Measured memory_bytes: 230824
#include <iostream>
#include <algorithm>
using namespace std;
const int INF = 1 << 29;
int N, MA, MB;
int A[40], B[40], C[40];
int dp[41][401][401];
int ans = INF;
int main(void) {
    cin >> N >> MA >> MB;
    fill((int*)dp, (int*)dp + (N + 1) * 401 * 401, INF);
    for (int n = 0; n < N; ++n) cin >> A[n] >> B[n] >> C[n];
    dp[0][0][0] = 0;
    for (int n = 0; n < N; ++n) for (int a = 0; a <= 400; ++a) for (int b = 0; b <= 400; ++b) {
        if (dp[n][a][b] == INF) continue;
        dp[n + 1][a][b] = min(dp[n + 1][a][b], dp[n][a][b]);
        if (a + A[n] > 400 && b + B[n] > 400) continue;
        dp[n + 1][a + A[n]][b + B[n]] = min(dp[n + 1][a + A[n]][b + B[n]], dp[n][a][b] + C[n]);
    }
    for (int i = 1; MA * i <= 400 && MB * i <= 400; ++i) {
        ans = min(ans, dp[N][MA * i][MB * i]);
    }
    if (ans == INF) ans = -1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 25984
#include <stdio.h>

int main(void)
{
	int a, b, c, d;
	int count = 0;
	int n;
	
	while (scanf("%d", &n) != EOF){
		for (a = 0; a <= 9; a++){
			for (b = 0; b <= 9; b++){
				for (c = 0; c <= 9; c++){
					for (d = 0; d <= 9; d++){
						if (a + b + c + d == n){
						//	printf("%d %d %d %d\n", a, b, c, d);
							count++;
						}
					}
				}
			}
		}
		
		printf("%d\n", count);
		count = 0;
	}
	return (0);
}

Measured memory_bytes: 596
/*************************************************************************
	> File Name: 1.cpp
	> Author: Knowledge_llz
	> Mail: 925538513@qq.com 
	> Blog: https://blog.csdn.net/Pig_cfbsl 
	> Created Time: 2020/9/6 12:33:11
 ************************************************************************/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define LL long long
using namespace std;
LL s;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.in", "r", stdin);
	freopen("output.out", "w", stdout);
#endif
	scanf("%lld",&s);
	LL x=sqrt(s),a,b;
	while(x*x<s) ++x;
	a=x*x-s;
	if(!a) b=0;
	else b=1;
	printf("0 0 %lld %lld %lld %lld\n",x,b,a,x);
	return 0;
}


Measured memory_bytes: 3808
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
using namespace std;

#define REP(i, a, b) for (int i = (int)a; i <= (int)b; i++)
#define fi first
#define sc second
#define pb push_back
#define double long double
#define all(x) x.begin(), x.end()

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pair<int, int>> vpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<int, int> pii;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;

const i64 MOD = 998244353;
const i64 INF = 2e15;

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

	int n;
	cin >> n;

	vector<string> a(n);

	REP(i, 0, n - 1) {
		string s;
		cin >> s;

		sort(all(s));
		a[i] = s;
	}

	sort(all(a));
	i64 ans = 0, d = 0;
	string s;

	REP(i, 0, n - 1) {
		if (i == 0) {
			s = a[i];
			d = 1;
			continue;
		}

		if (a[i] == s) {
			d++;
		}
		else {
			if (d == 2) {
				ans += 1;
			}
			else if (d == 3) {
				ans += 3;
			}
			else if (d == 4) {
				ans += 6;
			}
			else if (d > 4) ans += d * (d - 1) / 2;


			s = a[i];
			d = 1;
		}
	}

	if (d == 2) {
		ans += 1;
	}
	else if (d == 3) {
		ans += 3;
	}
	else if (d == 4) {
		ans += 6;
	}
	else if (d > 4) ans += d * (d - 1) / 2;

	cout << ans << endl;



	return 0;
}

Measured memory_bytes: 5760
fives = []
m = {}

i = 0 
while i**5 <= 10**15:
    m[i**5] = i
    m[-1 * i**5] = -1*i
    i+=1
x = int(input())

def fun():
    for i in m.keys():
        for j in m.keys():
            if i-j == x:
                print(str(m[i]) + " " + str(m[j]))
                return

fun()

Measured memory_bytes: 64684
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import math


S = str(input())

# print(S)
all = list("abcdefghijklmnopqrstuvwxyz")
all.sort()
for i in range(len(S)):
    if S[i] in all:
        all.remove(S[i])

if len(all) > 0:
    print(all[0])
else:
    print("None")


Measured memory_bytes: 4084
#define LOCAL
#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(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;
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; }
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define print(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define print(...)
#endif

ll dp[3000];
int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	string str;  cin >> str;
	memr(dp, 0);
	ll ans = 0;
	rep(i, str.size()){
		ll dp2[3000];
		memr(dp2, 0);
		rep(j, 3000){
			if(dp[j] == 0) continue;
			ll tmp = (j * 10 + (str[i] - '0')) % 2019;
			dp2[tmp] += dp[j];
			if(tmp == 0) {
				ans+=dp[j];
			}
		}
		dp2[str[i] - '0']++;
		rep(i, 3000){
			dp[i] = dp2[i];
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3800
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main(){
    int n,a,b;
    cin>>n>>a>>b;
    map<int,int> hoge;
    
    for(int i=1;i<n;i++) hoge[i]=0;
    
    for(int i=1;i<n;i++){
        for(int j=i+1;j<=n;j++){
            int kyori=j-i;
            kyori=min(kyori,abs(a-i)+abs(b-j)+1);
            
            hoge[kyori]++;
        }
    }
    
    for(int i=1;i<n;i++) cout<<hoge[i]<<endl;
    
    return 0;
}

Measured memory_bytes: 384
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n;
	cin>>n;
	vvi in(n-1,vi(3));
	rep(i,n-1)rep(j,3)cin>>in[i][j];
	rep(i,n-1){
		int t=in[i][1];
		loop(j,i,n-1){
			if(t<in[j][1])t=in[j][1];
			int r=t-in[j][1];
			t=in[j][1];
			if(r)r=((r-1)/in[j][2]+1)*in[j][2];
			t+=r;
			t+=in[j][0];
//			cout<<" "<<t<<endl;
		}
		cout<<t<<endl;
	}
	cout<<0<<endl;
}











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

int main(){
  string s;
  cin >> s;
  
  //sの中にどのアルファベットがあるのかを検出する
  for (char c = 'a'; c <= 'z'; c++) {
    bool found = false;
    for (int i = 0; i < s.size(); i++) {
      if (c == s.at(i)) {
        found = true;
      }
    }
    if (! found) {
      cout << c << endl;
      return 0;
    }
  }
  cout << "None" << endl;
  return 0;
  
  
  
  
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    ll n, k;
    cin >> n >> k;
    vl a(n);
    ll sum = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        sum += a[i];
    }
    sort(a.begin(), a.end());
    auto check = [&](ll mid) {
        if (a[mid] >= k)
            return false;
        bitset<5001> dp = 0;
        dp[0]           = 1;
        for (int i = 0; i < n; ++i) {
            if (i == mid)
                continue;
            if (a[i] <= 5000)
                dp |= dp << a[i];
        }
        bool ok = true;
        for (int i = max(0LL, k - a[mid]); i < k; ++i) {
            if (dp[i] == 1) {
                ok = false;
                break;
            }
        }
        return ok;
    };
    if (!check(0)) {
        cout << 0 << "\n";
        return 0;
    } else if (check(n - 1)) {
        cout << n << "\n";
        return 0;
    }
    ll ok = 0;
    ll ng = n - 1;
    while (abs(ok - ng) != 1) {
        ll mid = (ng + ok) / 2;
        if (check(mid))
            ok = mid;
        else
            ng = mid;
    }
    cout << ok + 1 << "\n";
    return 0;
}

Measured memory_bytes: 256
#pragma comment(linker, "/STACK:640000000")
#include <bits/stdc++.h>

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define ll long long
#define bit __builtin_popcountll
#define sqr(x) (x) * (x)
#define forit(it,S) for(__typeof((S).begin()) it = (S).begin(); it != (S).end(); it++)

using namespace std;

typedef pair<int, int> pii;

const double eps = 1e-9;
const double pi = acos(-1.0);

const int INF = (int)1e9;

int dp[222][222][222];

int main() {
	#ifdef LOCAL
	freopen("a.in", "r", stdin);
	freopen("a.out", "w", stdout);
	#endif

	for (int i = 0; i < 222; i++) {
		for (int j = 0; j < 222; j++) {
			for (int k = 0; k < 222; k++) {
				dp[i][j][k] = INF;
			}
		}
	}

	int a, b, c; cin >> a >> b >> c;

	dp[a][b][c] = 0;

	for (int i = a; i < 220; i++) {
		for (int j = b; j < 220; j++) {
			for (int k = c; k < 220; k++) {
				int val = dp[i][j][k] + 1;
				dp[i + 1][j + 1][k] = min(dp[i + 1][j + 1][k], val);
				dp[i + 1][j][k + 1] = min(dp[i + 1][j][k + 1], val);
				dp[i][j + 1][k + 1] = min(dp[i][j + 1][k + 1], val);
				dp[i + 2][j][k] = min(dp[i + 2][j][k], val);
				dp[i][j + 2][k] = min(dp[i][j + 2][k], val);
				dp[i][j][k + 2] = min(dp[i][j][k + 2], val);
			}
		}
	}

	int res = INF;

	for (int i = 0; i < 222; i++) {
		res = min(res, dp[i][i][i]);
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 43008
// header {{{
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <complex>
#include <utility>
#include <string>
#include <sstream>
#include <queue>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <tuple>
#include <cstdio>
#include <cmath>
using namespace std;

#define ALPHABET    (26)
#define EPS         (1e-10)
#define INF         (1000000005LL)
#define MOD         (1000000007LL)
#define EQ(a, b)    (abs((a)-(b)) < EPS)
// ciling(x/y) = (x+y-1)/y

typedef long long ll;
typedef unsigned long long ull;
// }}}

int main() {
    int n, l;cin >> n >> l;
    vector<string> s(n);
    for(auto &ss : s) cin >> ss;
    sort(s.begin(), s.end());
    for(auto ss : s) cout << ss;
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
n,k = map(int, input().split())
h = [int(input()) for _ in range(n)]
h.sort()
ans = float("INF")
for i in range(n-k+1):
    if ans > h[i+k-1] - h[i]:
        ans = h[i+k-1] - h[i]
print(ans)

Measured memory_bytes: 7384
import java.util.Scanner;

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

		int n = sc.nextInt();

		if (n == 1) {
			System.out.println("Hello World");
		} else {
			int A = sc.nextInt();
			int B = sc.nextInt();
			System.out.println(A + B);
		}
	}
}

Measured memory_bytes: 21844
// B - 105
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N; cin>>N;
	int ans = 0;
	for(int n=1; n<=N; n+=2){
		int c = 0;
		for(int i=1; i<=n; ++i) if(n%i == 0) c++;
		if(c == 8) ans++;
	}
	cout<< ans <<endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.util.*;
public class Main {
	int N;
	long[] dp,ans;
	Scanner cin;
	public void solve(){
		cin = new Scanner(System.in);
		dp = new long[2000 + 1];
		ans = new long[4000 + 1];
		for(int i = 0;i <= 1000;i++){
			for(int j = 0;j <= 1000;j++){
				dp[i + j]++;
			}
		}
		for(int i = 0;i <= 2000;i++){
			for(int j = 0;j <= 2000;j++){
				ans[i + j] += dp[i] * dp[j];
			}
		}
		while(cin.hasNextInt()){
			N = cin.nextInt();
			out.println(ans[N]);
		}
	}
 
	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}
 
	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;
 
	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
			return false;
		}
		if (buflen <= 0)
			return false;
		return true;
	}
 
	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}
 
	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}
 
	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}
 
	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}
 
	public int nextInt() {
		return Integer.parseInt(next());
	}
 
	public long nextLong() {
		return Long.parseLong(next());
	}
 
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 27476
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離

S = input()

ans = 1
tmp = ''
prev = S[0]
for i in range(1, len(S)):
    tmp += S[i]
    if tmp != prev:
        ans += 1
        prev = tmp
        tmp = ''
print(ans)


Measured memory_bytes: 5556
#include <bits/stdc++.h>
using namespace std;
int a[105],n;
bool esta(int k){
    bool b=true;
    for(int i=0;i<n;i++){
        if(k==a[i]) b=false;
    }
    if(b) return true;
    else return false;
}
 
int main() {
    int x;
    cin>>x>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int t1=1e5,t2=1e5;
    for(int i=0;i<=200;i++){
        if(esta(i)){
            if(x>i) t1=min(t1,x-i);
            else t2=min(t2,i-x);
        }
    }
    if(t1>t2) cout<<x+t2<<"\n";
    else cout<<x-t1<<"\n";
    
	return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const ll Mod = 998244353;
const int MAX = 510000;
const double PI = 3.14159265358979;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};

int main() {
  int N;
  cin >> N;
  int res = 0;
  vector<vector<int>> num(10, vector<int>(10, 0));
  for (int n=1; n<=N; n++) {
    vector<int> d;
    int nn = n;
    while (nn) {
      d.push_back(nn%10);
      nn /= 10;
    }
    int a = d[0], b = d.back();
    if (!a||!b) continue;
    num[a][b]++;
  }
  for (int a=1; a<10; a++) {
    for (int b=1; b<10; b++) res += num[a][b]*num[b][a];
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3620
n = int(input())
cnt  = [0 for i in range(10001)]

for x in range(1,101):
    for y in range(1, 105):
        for z in range(1, 105):
            ans = x**2 + y**2 + z**2 + x*y + y*z + z*x 
            if ans <= 10000:    
                cnt[ans] +=1
for i in range(1,n+1):  
    print(cnt[i])

Measured memory_bytes: 9144
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a < 6){
			System.out.print(0);
		}else if(a < 13){
			System.out.print(b/2);
		}else{
			System.out.print(b);
		}
	}
}


Measured memory_bytes: 22996
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
	static void Main()
	{
		var NM = Array.ConvertAll(Console.ReadLine().Split(new[] { ' ' }), number => long.Parse(number));
		var N = NM[0];
		var M = NM[1];

		if (Math.Abs(N - M) <= 1) {
			long num = (long)Math.Pow(10, 9) + (long)7;
			long totalN = 1;
			for (long i = 2; i <= N; ++i) {
				totalN = (totalN * i) % num;
			}

			long totalM = 1;
			for (long i = 2; i <= M; ++i) {
				totalM = (totalM * i) % num;
			}

			if (N == M) {
				Console.WriteLine((totalN * totalM * 2) % num);
			} else {
				Console.WriteLine((totalN * totalM) % num);
			}
		} else {
			Console.WriteLine(0);
		}

		//デバッグ実行での確認用。そのまま提出しても問題なし
		Console.ReadKey();
	}
}


Measured memory_bytes: 13268
#include <stdio.h>
int main()
{
  int n;
  scanf("%d",&n);
  int a,b;
  a = 1;
  int cnt = 0;
  while (a <= n)
  {
    b = 1;
    //printf("%d",a);
    while (b <= n / a)
    {
      if (a*b < n)
      {
        //printf("a:b %d:%d\n",a,b);
        cnt++;
      }
      b++;
    }
    a++;
  }
  printf("%d",cnt);
}

Measured memory_bytes: 1724
# https://atcoder.jp/contests/keyence2020/tasks/keyence2020_b

'''

区間スケジューリング問題：終点でソートして貪欲法

'''


import sys
input = sys.stdin.readline

N = int(input())
schedule = []
for i in range(N):
    x, l = map(int, input().split())
    schedule.append((x - l, l + x))             # schedule = (始点、終点)

schedule = sorted(schedule, key=lambda x: x[1])
ans = 0
end = -10**12                                   # 始点の最小値

for i in range(N):
    if end <= schedule[i][0]:
        end = schedule[i][1]                    # 終点でソートされているので、自動的に可能な中で最速の終点が選ばれている
        ans += 1

print(ans)

Measured memory_bytes: 24624
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;

int main(){
  const double pi =M_PI;
  double err,diff;
  int bunbo,bunsi;

  while (1){
    cin >> err;
    if (err==0) break;
    bunbo=1;
    bunsi=3;
    while (1){
      diff=(pi-((double)bunsi/bunbo));
      //cout << bunsi << "/" << bunbo <<" "<<diff<<" "  << endl;
      if (diff>err)bunsi++;
      else if ((pi-((double)bunsi/bunbo))<-err)bunbo++;
      else break;
    }
    cout << bunsi << "/" << bunbo << endl;
  }
  return 0;
}

Measured memory_bytes: 3168
package main

import (
	"fmt"
	"strconv"
)

func cal(a int, b int, o string)int {
	if o=="+"{
		return a+b
	} 
	return a-b
}

func main() {
	var s string
	var sum int
	var o1,o2,o3 string
	fmt.Scan(&s)
	a,_:= strconv.Atoi(string(s[0]))
	b,_:= strconv.Atoi(string(s[1]))
	c,_:= strconv.Atoi(string(s[2]))
	d,_:= strconv.Atoi(string(s[3]))
	op:=[]string{"+","-"}
	
	for i:=0;i<2;i++{
		for j:=0;j<2;j++{
			for k:=0;k<2;k++{
				sum = cal(a, b, op[i])
				sum = cal(sum, c, op[j])
				sum = cal(sum, d, op[k])
				if sum == 7 {
					o1,o2,o3 = op[i],op[j],op[k]
					break
				}
			}			
		}
	}
	fmt.Printf("%d%s%d%s%d%s%d=7\n",a,o1,b,o2,c,o3,d)
}

Measured memory_bytes: 512
#include <iostream>

#define ll long long
#define LINF 1e18
#define INF 1e9

using namespace std;

int main() {
  ll sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  for (int i = 0; i < abs(tx - sx); i++) {
    cout << "R";
  }
  for (int i = 0; i < abs(ty - sy); i++) {
    cout << "U";
  }
  for (int i = 0; i < abs(tx - sx); i++) {
    cout << "L";
  }
  for (int i = 0; i < abs(ty - sy); i++) {
    cout << "D";
  }
  cout << "D";
  for (int i = 0; i < abs(tx - sx) + 1; i++) {
    cout << "R";
  }
  for (int i = 0; i < abs(ty - sy) + 1; i++) {
    cout << "U";
  }
  cout << "L";
  cout << "U";
  for (int i = 0; i < abs(tx - sx) + 1; i++) {
    cout << "L";
  }
  for (int i = 0; i < abs(ty - sy) + 1; i++) {
    cout << "D";
  }
  cout << "R" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9+1;
int main(){
	int N;cin>>N;
	long cnt[10][10]={};
	rep(i,1,N+1){
		if(i%10==0) continue;
		int temp=i;
		while(temp>=10) temp /= 10;
		cnt[temp][i%10]++;
	}
	long ans=0;
	rep(i,1,10)rep(j,1,10){
		ans+=cnt[i][j]*cnt[j][i];
	}
	cout<<ans<<endl;
}

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

using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    int h;
    int count = 0;
    for (int i = 0; i< N; i++){
        cin >> h;
        if (h >= K){
            count++;
        }
    }
    cout << count << endl;
    
}

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

int64_t gcd(int64_t a, int64_t b){
  int64_t buf;
  while(b > 0){
    buf= a;
    a= b;
    b= buf%b;
  }
  return a;
}

int main(){
  int K;
  cin >> K;

  int ans= 0;
  for(int i=1; i<=K; i++){
    for(int j=1; j<=K; j++){
      int g= gcd(i,j);
      for(int k=1; k<=K; k++){
        ans+= gcd(g, k);
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3636
void main()
{
    long[] nmq = rdRow;
    long n = nmq[0], m = nmq[1], q = nmq[2];

    long[][] lists = new long[][](n+1, n+1);
    foreach (i; 0 .. m)
    {
        long[] tmp = rdRow;
        long l = tmp[0], r = tmp[1];
        ++lists[l][r];
    }

    foreach (i; 1 .. n+1)
    {
        foreach (j; 1 .. n+1)
        {
            lists[i][j] += lists[i-1][j];
        }
    }
    foreach (i; 1 .. n+1)
    {
        foreach (j; 1 .. n+1)
        {
            lists[i][j] += lists[i][j-1];
        }
    }

    foreach (i; 0 .. q)
    {
        long[] tmp = rdRow;
        long a = tmp[0], b = tmp[1];
        writeln(lists[b][b] - lists[b][a-1] - lists[a-1][b] + lists[a-1][a-1]);
    }
}

T rdElem(T = long)()
{
    //import std.stdio : readln;
    //import std.string : chomp;
    //import std.conv : to;

    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;

dchar[] rdDchar()
{
    //import std.conv : to;

    return rdStr.to!(dchar[]);
}

T[] rdRow(T = long)()
{
    //import std.stdio : readln;
    //import std.array : split;
    //import std.conv : to;

    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    //import std.range : iota;
    //import std.algorithm : map;
    //import std.array : array;

    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    //import std.range : iota;
    //import std.algorithm : map;
    //import std.array : array;

    return iota(col).map!(x => rdRow!T).array;
}

void wrMat(T = long)(T[][] mat)
{
    //import std.stdio : write, writeln;

    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 5628
#include <bits/stdc++.h>
#define zeros(x) ((x) & (-x))
#define inf 1e18

using namespace std;

typedef long long ll;
typedef long double ld;

ll a, b;

int main()
{
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>a>>b;
    cout<<6-a-b;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int>a(n);
  for(int i=0;i<n;++i){
    cin >> a[i];
  }
  int ans=0;
  sort(a.begin(),a.end());
  ans=a.at(n/2)-a.at(n/2-1);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3740
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M LLONG_MAX
pair<ll,ll> a[100000];
ll flg[100000][2];
int main(void){
	ll n,m,h,k,i,j,mi,s[1000],sp[1000],ss[1000],sum,p,pp;
	while(1){
		cin>>n>>m>>h>>k;
		if(n==0)break;
		for(i=0;i<n;i++) cin>>s[i],sp[i]=i;
	//	for(i=0;i<n;i++) cout<<s[i][0]<<' '<<s[i][1]<<endl;
		for(i=0;i<m;i++) cin>>a[i].second>>a[i].first;
		sort(a,a+m);
	//	for(i=0;i<m;i++) cout<<a[i].second<<' '<<a[i].first<<endl;
		for(i=0;i<m;i++){
			swap(sp[a[i].second-1],sp[a[i].second]);
			flg[i][0]=sp[a[i].second];
			flg[i][1]=sp[a[i].second-1];
		}
	//	for(i=0;i<m;i++) cout<<flg[i][0]<<' '<<flg[i][1]<<endl;
		for(i=0;i<n;i++) ss[sp[i]]=i;
	//	for(i=0;i<n;i++) cout<<s[i][0]<<endl;
		mi=0;
		for(i=0;i<k;i++) mi+=s[ss[i]];
		for(i=0;i<m;i++){
			p=flg[i][0]; pp=flg[i][1];
			swap(ss[p],ss[pp]);
			sum=0;
			for(j=0;j<k;j++){
				sum+=s[ss[j]];
	//			cout<<i<<' '<<s[ss[j]]<<endl;
			}
			mi=min(mi,sum);
			swap(ss[p],ss[pp]);
		}
		cout<<mi<<endl;
	}
	return 0;
}


Measured memory_bytes: 6180
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;

const unsigned long long BASE = 1e9 + 7;

int main()
{
    int n, k;
    cin >> n >> k;
    int sqrtN = int(sqrt(n));
    vector<unsigned long long> count0(sqrtN, 1);
    for (int i = sqrtN; i >= 1; i--)
    {
        double start = double(n) / (i + 1);
        double end = double(n) / i;
        if (start < sqrtN)
            continue;
        // (start, end]
        count0.push_back(int(end) - int(start));
    }
    int m = count0.size();
    vector<unsigned long long> count(count0.begin(), count0.end());
    for (int iter = 2; iter <= k; iter++)
    {
        vector<unsigned long long> nextCount(m);
        unsigned long long sum = 0;
        for (int i = m - 1; i >= 0; i--)
        {
            sum = (sum + count[m - 1 - i]) % BASE;
            nextCount[i] = sum * count0[i] % BASE;
        }
        count = nextCount;
    }
    unsigned long long result = 0;
    for (int i = 0; i < m; i++)
    {
        result = (result + count[i]) % BASE;
    }
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 4700
#include <iostream>
using namespace std;
int main()
{
    string a,b,u;cin>>a>>b;
    int x,y;cin>>x>>y;
    cin>>u;
    if(u==a){
        x-=1;
    }
    else{
        y-=1;
    }
    cout<<x<<" "<<y;
    return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

const int mod = 1000000007;
//const int mod = 998244353;

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

    //for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) {return mint(*this) /= a;}
};

istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vi dp(3);
    mint ans = 1;
    rep(i, n) {
        int a;
        cin >> a;
        auto pitr = equal_range(all(dp), a);
        ans *= int(pitr.second - pitr.first);
        if(pitr.second != dp.begin()) pitr.second--;
        (*pitr.second)++;
    }

    cout << ans << endl;
}

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

const int M = 60;
int n, m, q;
int a[M], b[M], c[M], d[M];
int A[M], ans;

void dfs(int dep, int pre) {
	if (dep == n) {
		int sum = 0;
		for (int i = 0; i < q; i++)
			if (A[b[i] - 1] - A[a[i] - 1] == c[i])
				sum += d[i];
		ans = max(ans, sum);
	} else {
		for (int i = pre; i <= m; i++) {
			A[dep] = i;
			dfs(dep + 1, i);
		}
	}
}

int main() {
	cin >> n >> m >> q;
	for (int i = 0; i < q; i++)
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	dfs(0, 1);
	cout << ans << "\n";
}

Measured memory_bytes: 3540
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(int i=(ll)(b);i>=(ll)(a);i--)

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,w;cin>>n>>w;
  ll vmax=n*1000+7;
  vector<ll>dp(vmax,1e18);
  dp[0]=0;
  rep(i,n){
    ll tw,tv;cin>>tw>>tv;
    rrep(j,vmax-tv)chmin(dp[j+tv],dp[j]+tw);
  }
  rrep(i,vmax){
    if(dp[i]<=w){
      cout<<i<<endl;
      return 0;
    }
  }


  return 0;

}


Measured memory_bytes: 1152
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define maxn 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second

int n,m;
ll s;

inline int read(){
    int x=0,f=1; char ch=getchar();
    for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
    for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
    return x*f;
}

int main(){
	cin>>s; int y2=1,y3=1e9,pps=y3-y2,x1=s/pps,x3=s%pps;
	if (x1>1e9) --x1,x3+=pps;
	printf("%d %d %d %d %d %d\n",x1,0,0,y2,x3,y3);
    return 0;
}


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

int main(){
    ll n;
    cin>>n;
    ll ans=1;
    ll mod=pow(10,9)+7;
    //ans%=mod;
    ll nine=1;
    ll zn=1;
    for(ll i=0;i<n;i++){
        ans*=10;
        ans%=mod;
        nine*=9;
        nine%=mod;
        zn*=8;
        zn%=mod;
    }
    ans-=nine+nine-zn;
    while(ans<0) ans+=mod;
    ans%=mod;
    cout<<ans<<endl;
    //cout<<mod<<endl;
}

Measured memory_bytes: 3624