akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

vector<int> q;
stack<int> st;


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

    for (int i = 1; i <= n; i++) {
        scanf("%d", &tmp);
        if (i % 2) q.push_back(tmp);
        else st.push(tmp);
    }

    if (n % 2) {
        reverse(q.begin(), q.end());
        for (auto x : q) printf("%d ", x);

        stack<int> out;
        while (!st.empty()) {
            out.push(st.top());
            st.pop();
        }

        while (!out.empty()) {
            printf("%d ", out.top());
            out.pop();
        }
    }
    
    
    else {
        while (!st.empty()) {
            printf("%d ", st.top());
            st.pop();
        }

        for (auto x : q) printf("%d ", x);
    }
}


Measured memory_bytes: 2936
import java.util.*;

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

  Scanner sc;
  long N = 0;
  long K = 0;
  long answer = 0;

  // 標準入力用のコンストラクタ
  public Main(Scanner sc) {
    this.sc = sc;
    N = sc.nextLong();
    K = sc.nextLong();
  }

  // 判定処理
  long solve() {
      //int[] ball = new int[N];  //色の種類数を格納するボールの配列
      answer = K;
      for (int i = 1; i < N; ++i){
        if (N == 1){
            break;
        } else {
            //ball[i] = K;
            answer *= K - 1;
        }
      }
      
      return answer;
  }

  // 回答の表示
  void show(long answer) {
        System.out.println(answer);
  }
    
}

Measured memory_bytes: 35524
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import *

S = input()
N = len(S)

def solvable(k):
  imos = [0] * (N+1)
  ops = [0] * (N+1)
  for i in range(N-k+1):
    ops[i] = ops[i-1] + imos[i]
    if int(S[i] == '1') ^ (ops[i] & 1):
      imos[i] += 1
      imos[i+k] -= 1
      ops[i] += 1
  ops = list(accumulate(imos))[:-1]
  return not any(int(S[i] == '1') ^ (ops[i] & 1) for i in range(k))

l = 1
r = N+1
while r - l > 1:
  m = (l + r) // 2
  if solvable(m):
    l = m
  else:
    r = m
print(l)

Measured memory_bytes: 95096
while (n = gets.to_i) != 0 do
	s = gets.split.map(&:to_f)
	m = s.inject(:+) / s.size

	a = 0
	n.times do |i|
		a += (s[i] - m)**2
	end
	a = a / n

	puts Math::sqrt(a)
end

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

using namespace std;

int sx, sy, tx, ty, dx, dy;
char buf[20005];

void append(char c, int cnt) {
  static int pos = 0;
  for (; cnt; cnt--, pos++) {
    buf[pos] = c;
  }
  buf[pos] = 0;
}

int main() {
  cin >> sx >> sy >> tx >> ty;

  dx = tx - sx;
  dy = ty - sy;

  append('U', dy);
  append('R', dx);
  append('D', dy);
  append('L', dx);
  append('L', 1);
  append('U', dy + 1);
  append('R', dx + 1);
  append('D', 1);
  append('R', 1);
  append('D', dy + 1);
  append('L', dx + 1);
  append('U', 1);

  cout << buf << '\n';
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static int n;
    public static int s;
    public static int c;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            n = sc.nextInt();
            s = sc.nextInt();
            if (n == 0 && s == 0) {
                break;
            }
            c = 0;
            dfs(0, s, s);
            //dfs2(n, s, 0);
            System.out.println(c);

        }
    }

    static void dfs(int k, int rest, int x) {
        if (k == n) {
            if (rest == 0)
                c++;
            return;
        }
        if (rest >= 0) {
            for (int i = Math.min(x, 9); i >= 0; i--) {
                dfs(k + 1, rest - i, i - 1);
            }
        }
    }

    static void dfs2(int k, int rest, int x) {
        if (k == 0) {
            if (rest == 0)
                c++;
        }
        if (rest >= 0) {
            for (int i = x; i <= 9; i++) {
                dfs2(k - 1, rest - i, i + 1);
            }
        }
    }
}


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

using namespace std;

typedef long long lli;

const int N = 200000 + 10;
const int MOD = 1000000007;

map< pair<lli, lli>, int> cnt;
int p[N];

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

int main()
{
	int res, n, s, i;
	lli a, b, d;
	bool neg;
	pair<lli, lli> tmp, tmpr;
	cin>>n;
	p[0] = 1;
	for (i=1; i<=n; i++) p[i] = p[i-1] * 2 % MOD;
	for (i=1; i<=n; i++)
	{
		cin>>a>>b;
		neg = false;
		if (a == 0 && b != 0) b = 1;
		else if (a != 0 && b == 0) a = 1;
		else if (a < 0 && b < 0)
		{
			a = -a;
			b = -b;
		}
		else if (a < 0)
		{
			a = -a;
			neg = true;
		}
		else if (b < 0)
		{
			b = -b;
			neg = true;
		}
		d = gcd(a, b);
		if (d)
		{ 
			a /= d;
			b /= d;
		}
		if (neg)
		{
			tmp = make_pair(-a, b);
			if (cnt.find(tmp) != cnt.end()) cnt[tmp] ++; else cnt[tmp] = 1;
		}
		else
		{
			tmp = make_pair(a, b);
			if (cnt.find(tmp) != cnt.end()) cnt[tmp] ++; else cnt[tmp] = 1;
		}
	}
	res = 1;
	bool zero = false;
	for (map< pair<lli, lli>, int >::iterator itr=cnt.begin(); itr!=cnt.end(); itr++)
	{
		tmp = itr->first;
		if (tmp.first == 0 && tmp.second == 0)
		{
			zero = true;
			continue;
		}
		if (tmp.first == 0 || tmp.second == 0) tmpr = make_pair(tmp.second, tmp.first);
		else if (tmp.first > 0) tmpr = make_pair(-tmp.second, tmp.first);
		else tmpr = make_pair(tmp.second, -tmp.first);
		if (cnt.find(tmpr) != cnt.end()) 
		{
			if (tmpr < tmp) continue;
			s = cnt[tmpr]; 
		}
		else s = 0;
		a = (p[cnt[tmp]] - 1 + MOD) % MOD;
		b = (p[s] - 1 + MOD) % MOD;
		res = 1LL * res * (a + b + 1) % MOD;
//		cout<<tmp.first<<" "<<tmp.second<<" "<<a<<" "<<b<<" "<<res<<endl;
	}
//	while (zero);
	if (!zero) res = (res - 1 + MOD) % MOD;
	else res = (res + cnt[make_pair(0, 0)] - 1) % MOD;
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 16844
#


def main():
    h, w = map(int, input().split(" "))
    m = []
    for i in range(h):
        line = ['']
        line.extend(input())
        line[0] = line[1]
        m.append(line)
        if i == 0:
            m.append(line)
    dp = [[float("inf")] * (w + 1) for _ in range(h + 1)]
    if m[0][0] == "#":
        dp[0][1] = 1
        dp[1][0] = 1
    else:
        dp[0][1] = 0
        dp[1][0] = 0
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            c = m[i][j]
            sh, sw = i - 1, j
            if dp[sh][sw] == dp[i][j -1]:
                if m[sh][sw] != c:
                    sh, sw = i, j - 1
            elif dp[sh][sw] > dp[i][j - 1]:
                sh, sw = i, j -1
            dp[i][j] = dp[sh][sw]
            if m[sh][sw] != c and c != '.':
                dp[i][j] += 1
            # 上のマスのコスト(dp上の位置)
            # sh, sw = i - 1, j
            # # m上の位置へ変換
            # th, tw = sh - 1, sw - 1
            # if dp[sh][sw] > dp[i][j - 1]:
            #     sh, sw = i, j - 1
            #     th, tw = sh - 1, sw - 1
            #     # どちらのコストも同じなら色が同じ方を選ぶ
            # elif m[th][tw] != c:
            #     sh, sw = i, j - 1
            #     th, tw = sh - 1, sw - 1
            # dp[i][j] = dp[sh][sw]
            # ph, pw = i - 1, j - 1
            # if th < 0 or tw < 0:
            #     continue
            # if m[th][tw] != c:
            #     dp[i][j] += 1
    print(dp[h][w])


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
input = sys.stdin.readline
 
# bisect_left(lists, 3)
# bisect_right(lists, 3)

# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

def main():
	N, A, B, C, D = map(int, input().split(" "))
	#N = int(input())
	S = input()
	S = list(S)
	S = S[:-1]

	A -= 1
	B -= 1
	C -= 1
	D -= 1

	if C < D:
		S = S[A:D+1]
	else:
		S = S[A:C+1]

	iwa = []
	kara = []
	nige = []
	for i, val in enumerate(S):
		if val == "#":
			if len(iwa) >= 1 and iwa[-1] == i-1:
				print("No")
				sys.exit()
			iwa.append(i)
		else:
			#print(i)
			#print(len(kara))
			#print(kara)
			
			if len(kara) > 1 and kara[-1] == i-1 and kara[-2] == i-2:
				nige.append(i-2)
			kara.append(i)
	#print(S)
	#print(nige)
	'''
	for i in range(A+1, C):
		if i in iwa:
			tmp = iwa.index(i)
			if len(iwa)-1 > tmp and iwa[tmp+1] == i+1:
				print("No")
				sys.exit()

	for i in range(B+1, D):
		if i in iwa:
			tmp = iwa.index(i)
			if len(iwa)-1 > tmp and iwa[tmp+1] == i+1:
				print("No")
				sys.exit()
	'''
	if A < B and B < C and C < D:
		print("Yes")
		sys.exit()
	elif A < C and C < B and B < D:
		print("Yes")
		sys.exit()
	else:
		for i in nige:
			if B-1 <= i and i+2 <= D+1:
				print("Yes")
				sys.exit()
	'''
	elif A < B and B < D and D < C:
		for i in range(A+1, C):
			if i in kara:
				tmp = kara.index(i)
				if C >= i+2 and len(kara)-2 > tmp :
					if (kara[tmp+1] == i+1) and (kara[tmp+2] == i+2):
						print("Yes")
						sys.exit()
		print("No")
		sys.exit()
	'''
	print("No")
	

if __name__ == "__main__":
	main()

Measured memory_bytes: 14160
#include<iostream>
#include<cstring>
#include<queue>
#include<cstdio>
using namespace std;
#define clr(x,y) memset(x,y,sizeof x)
typedef long long ll;
#define INF 0x3f3f3f3f
#define IINF 0x3f3f3f3f3f3f3f3f
const int maxn = 100 + 10;

ll dist[maxn][maxn];
int main()
{
    int n,m;
    while( ~ scanf("%d%d",&n,&m))
    {
        clr(dist,IINF);
        for(int i = 0;i <= n;i ++)dist[i][i] = 0;
        for(int i = 1; i <= m;i ++)
        {
            int x,y,z;scanf("%d%d%d",&x,&y,&z);
            dist[x][y] = min(dist[x][y],1ll*z);
        }
        for(int k = 0;k < n;k ++)
        {
            for(int i = 0;i < n;i ++)
            {
                for(int j = 0;j < n;j ++)
                {
                    if(dist[i][k] != IINF && dist[k][j] != IINF)
                    dist[i][j] = min(dist[i][j],dist[i][k] + dist[k][j]);
                }
            }
        }
        bool flag = false;
        for(int i = 0;i < n;i ++)
            if(dist[i][i] < 0)
            {
                flag = true;
                puts("NEGATIVE CYCLE");
                break;
            }
        if(flag)continue;
        for(int i = 0;i < n;i ++)
        {
            for(int j = 0;j < n;j ++)
            {
                if(dist[i][j] == IINF)printf("INF");
                else printf("%lld",dist[i][j]);
                printf("%c",j < n - 1 ? ' ' : '\n');
            }

        }
    }
    return 0;
}



Measured memory_bytes: 3324
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e18;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W, x, y, z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

int main() {
    cin >> A >> B >> C >> K;
    ll sum = 0;
    if(A >= K){
        sum += K;
    }else{
        K -= A;
        sum += A;
        if(B < K){
            K -= B;
            sum -= K;
        }
    }
    cout << sum;
}


Measured memory_bytes: 3636
#line 2 "header.hpp"

//%snippet.set('header')%
//%snippet.fold()%
#ifndef HEADER_H
#define HEADER_H

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

// varibable settings
const long long INF = 1e18;
template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (ll i = (ll)((b)-1); i >= (ll)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
template <class T> inline void chmax(T &a, const T &b) { if ((a) < (b)) (a) = (b); }
template <class T> inline void chmin(T &a, const T &b) { if ((a) > (b)) (a) = (b); }
template <typename X, typename T> auto make_table(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto make_table(X x, Y y, Z z, Zs... zs) { auto cont = make_table(y, z, zs...); return vector<decltype(cont)>(x, cont); }

#define cdiv(a, b) (((a) + (b)-1) / (b))
#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x) sort(all(x)); x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)

typedef long long ll;
typedef long double ld;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;

template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
void check_input() { assert(cin.eof() == 0); int tmp; cin >> tmp; assert(cin.eof() == 1); }

#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif

#endif /* HEADER_H */
//%snippet.end()%
#line 2 "solve.cpp"
template<class T=ll> using vec = vector<T>;
struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast;


int solve() {
    string s;cin>>s;
    ll n = sz(s);
    ll m = 0;
    rep(i, n){
        ll v = s[i] - '0';
        m += v;
        m %= 9;
    }
    cout << (m == 0 ? "Yes" : "No") << endl;

    return 0; 
}


int main(){/*{{{*/
    solve();
    check_input();
    return 0;
}/*}}}*/


Measured memory_bytes: 3740
#include <iostream>
#include <bits/stdc++.h>
#include <vector>

using namespace std;
using Int = long long;

signed main(){
    Int n;
    cin >> n;
    vector<Int> w;
    Int sum = 0;
    for (Int i = 0; i < n; i++) {
        Int tmp;
        cin >> tmp;
        sum += tmp;
        w.push_back(tmp);
    }

    Int sum_1 = 0;
    Int sum_2 = sum;
    Int diff = sum;
    for (Int i = 0; i < n; i++){
        sum_1 += w[i];
        sum_2 -= w[i];
        Int tmp_diff = abs(sum_2 - sum_1);
        if (tmp_diff < diff){
            diff = tmp_diff;
        }else{
            cout << diff << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int main() {
  int N; cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  
  sort(A.begin(),A.end());
  bool can = true;
  if (N % 2 == 0) {
    for (int i = 0; i < N; i++) {
      if (A[i] != i / 2 * 2 + 1) can = false;
    }
  } else {
    for (int i = 0; i < N; i++) {
      if (A[i] != (i+1) / 2 * 2) can = false;
    }
  }
  int ans = 1;
  for (int i = 0; i < N / 2; i++) {
    ans *= 2;
    ans %= MOD;
  }

  if (can) cout << ans << endl;
  else cout << 0 << endl;
}

Measured memory_bytes: 640
-- {-# LANGUAGE BangPatterns #-}
-- {-# LANGUAGE ScopedTypeVariables #-}
-- {-# LANGUAGE FlexibleContexts #-}
-- {-# LANGUAGE ViewPatterns #-}
-- {-# LANGUAGE OverloadedStrings #-}

import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
-- import qualified Data.Vector.Algorithms.Merge as VAM
-- import qualified Data.Heap as HP
import qualified Data.ByteString.Char8 as BC
import qualified Data.Map as MP
import qualified Data.Set as ST
import qualified Data.Sequence as SQ
import Data.Array
import Data.Array.Unboxed
import Data.Array.ST
import Data.Array.IO
import Data.Maybe
import Data.Ratio
import Data.Char
import Data.Bits
import Data.List
import Data.Tuple
import Data.Functor
import Data.IORef
import Data.STRef
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Debug.Trace

--------------------------------------------------------------------------
main = do
    [a,b,c,k] <- sLineToIntL
    print $
        if even k
            then a-b
            else negate (a-b)
--------------------------------------------------------------------------

-- Input Util
int :: IO Int
int = readLn 

double :: IO Double
double = readLn 

str :: IO String
str = getLine

strBC :: IO BC.ByteString
strBC = BC.getLine

sLineToIntL :: IO [Int]
sLineToIntL = getLine >>= return . map read . words

sLineToDoubleL :: IO [Double]
sLineToDoubleL = getLine >>= return . map read . words

sLineToIntV :: Int -> IO (VU.Vector Int)
sLineToIntV n = BC.getLine >>= return . VU.unfoldrN n (BC.readInt . BC.dropWhile isSpace)

sLineToDoubleV :: Int -> IO (VU.Vector Double)
sLineToDoubleV n = BC.getLine >>= return . VU.fromList . map (read . BC.unpack) . BC.words

mLinesToIntL :: Int -> IO [Int]
mLinesToIntL n = replicateM n readLn

mLinesToDoubleL :: Int -> IO [Double]
mLinesToDoubleL n = replicateM n readLn

mLinesToIntV :: Int -> IO (VU.Vector Int)
mLinesToIntV n = VU.replicateM n readLn

mLinesToDoubleV :: Int -> IO (VU.Vector Double)
mLinesToDoubleV n = VU.replicateM n (BC.getLine >>= return . read . BC.unpack)

mLinesToTupleL :: Int -> IO [(Int, Int)]
mLinesToTupleL n = replicateM n (getLine >>= return . (\[a,b] -> (a,b)) . map read . words)

mLinesToTupleV :: Int -> IO (VU.Vector (Int, Int))
mLinesToTupleV n = VU.replicateM n $ do
    bs <- strBC
    let
        Just (a, bs') = BC.readInt $ BC.dropWhile isSpace bs
        Just (b, _) = BC.readInt $ BC.dropWhile isSpace bs'
    return (a,b)
    
mLinesToTripleV :: Int -> IO (VU.Vector (Int, Int, Int))
mLinesToTripleV n = VU.replicateM n $ do
    bs <- strBC
    let
        Just (a, bs') = BC.readInt $ BC.dropWhile isSpace bs
        Just (b, bs'') = BC.readInt $ BC.dropWhile isSpace bs'
        Just (c, _) = BC.readInt $ BC.dropWhile isSpace bs''
    return (a,b,c)

-- others
strToChr :: String -> Char
strToChr [x] = x

chrToStr :: Char -> String
chrToStr x = [x]

m1 :: Int -> Int
m1 x = subtract 1 x

toDouble :: Int -> Double
toDouble x = fromIntegral x

toInt :: Double -> Int
toInt x = floor x

Measured memory_bytes: 508
#include <algorithm>
#include <array>
#include <assert.h>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double ld;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<ld>> vvd;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;



int main() {
    cout << setprecision(30);
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    ll n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    vl x(n);
    for (ll i = 0; i < n; ++i) {
        x[i] = s[i] == 'L' ? +1 : -1;
    }
    ll ans = n - 1;
    for (ll i = 0; i < n - 1; ++i) {
        ans -= (x[i] != x[i + 1]);
    }
    cout << min(ans + 2 * k, n - 1);

    return 0;
}


Measured memory_bytes: 1232
#create date: 2020-06-30 14:42

import sys
stdin = sys.stdin
from itertools import combinations_with_replacement

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n, m, q = na()
    matrix = list()
    for i in range(q):
        matrix.append(na())
    l = list(combinations_with_replacement(range(1, m+1), n))
    ans = 0
    for li in l:
        res = 0
        for q in matrix:
            a, b, c, d = q
            if li[b-1] - li[a-1] == c:
                res += d
        ans = max(ans, res)
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 21528
#include<iostream>
#include<vector>
using namespace std;
int main(void){
    int N;
    cin >> N;
    vector<tuple<string,int,int>> a;

    for(int i = 1;i <= N;i++){
        string s;
        int p;
        cin >> s >> p;
        p = -p;
        a.push_back(tie(s,p,i));
    }
    sort(a.begin(),a.end());
    for(int i = 0;i < N;i++){
        cout << get<2>(a[i]) << endl;
    }
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1e9+7;
const int SIZE=2001;

ll powm(ll x,ll k){
    ll res=1;
    while(k){
        if(k&1) res=res*x%MOD;
        x=x*x%MOD;
        k>>=1;
    }
    return res;
}
ll modInv(ll x){
    return powm(x,MOD-2);
}
int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    vector<int> b(n);
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
    }

    vector<vector<ll>> dp(SIZE*2,vector<ll>(SIZE*2));
    for(int i=0;i<n;i++){
        dp[SIZE-a[i]][SIZE-b[i]]++;
    }
    for(int i=1;i<SIZE*2;i++){
        for(int j=1;j<SIZE*2;j++){
            dp[i][j]=(dp[i][j]+dp[i-1][j]+dp[i][j-1])%MOD;
        }
    }
    ll sum=0;
    for(int i=0;i<n;i++){
        sum=(sum+dp[SIZE+a[i]][SIZE+b[i]])%MOD;
    }
    vector<ll> fact(SIZE*4);
    fact[0]=1;
    for(int i=1;i<fact.size();i++) fact[i]=fact[i-1]*i%MOD;
    auto comb=[&fact](ll n,ll k){
        return fact[n]*modInv(fact[k])%MOD*modInv(fact[n-k])%MOD;
    };
    for(int i=0;i<n;i++){
        sum=(sum-comb(a[i]+b[i]+a[i]+b[i],a[i]+a[i]))%MOD;
    }
    
    sum=(sum*modInv(2))%MOD;
    sum=(sum%MOD+MOD)%MOD;
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 127232
n, k = map(int, input().split())
str_abc = input()

if str_abc[k-1] == 'A':
  d = 'a'
elif str_abc[k-1] == 'B':
  d = 'b'
elif str_abc[k-1] == 'C':
  d = 'c'

str_abc = str_abc[:k-1] + d + str_abc[k:]
print(str_abc)

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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  int n,m; cin>>n>>m;
  string s; cin>>s;
  
  vi ans;
  int now=n;
  while(now>=0){
    if(now<=m){
      ans.push_back(now);
      break;
    }
    int tmp=m+1;
    do{
      tmp--;
      if(tmp==0){
        cout<<-1<<endl;
        return 0;
      }
    }while(s[now-tmp]=='1');
    ans.push_back(tmp);
    now-=tmp;
  }
  
  reverse(ans.begin(),ans.end());
  for(auto e: ans){
    cout<<e<<endl;
  }
  
  return 0;
}


Measured memory_bytes: 1096
import java.util.*;

public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        long[] a = new long[n];
        for(int i = 0; i < n; i++) a[i] = scan.nextInt();
        int out = 0;
        for(int i = 0; i < n; i++){
            if(a[i] % 2 == 0){
                out++;
                a[i] /= 2;
                i = -1;
            }
        }
        System.out.println(out);
        scan.close();
    }

    public static void main(String[] args){
        new Main().solve();
    }
}


Measured memory_bytes: 47932
a = Array.new(3)
b = Array.new(3)

counts = Hash.new(0)
3.times do|i|
  a, b = gets.split.map(&:to_i)
  counts[a.to_s] += 1
  counts[b.to_s] += 1
end

puts counts.sort { |(k1, v1), (k2, v2)| v1<=>v2 }.map { |k, v| v } == [1, 1, 2, 2] ? 'YES' : 'NO'


Measured memory_bytes: 1788
#include <cstdio>
#define MAX (2000000)
using namespace std;

bool prime[MAX + 1];

int main()
{
	for (int i = 2; i <= MAX; i++){
		prime[i] = true;
	}
	
	for (int i = 2; i * i <= MAX; i++){
		for (int j = i * i; j <= MAX; j += i){
			prime[j] = false;
		}
	}
	
	int n;
	while (scanf("%d", &n), n){
		bool *p;
		int cnt = 0;
		
		p = &prime[n];
		while (*p == false){
			cnt++;
			p--;
		}
		
		p = &prime[n];
		while (*p == false){
			cnt++;
			p++;
		}
		
		printf("%d\n", cnt);
	}
	
	return 0;
}

Measured memory_bytes: 2980
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#define ll long long
using namespace std;
/*int ghat(int a)
{
    int x = log(a) - log(2.0);
    return x;
}*/
int count(int a)
{
    int c = 0;
    while(a%2==0 && a){
        a = a/2;
        c++;
    }
    return c;
}
int main() {
    ios_base:: sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    int i, x;
    vector<int> p;
    for(i=0; i<n; i++){
        cin >> x;
        p.push_back(x);
    }
    int max_pow = 0;
    for(i=0; i<n; i++){
        x = count(p[i]);
        //cout << x << endl;
        //max_pow = max(x, max_pow);
        max_pow += x;
    }
    //if(max_pow) cout << max_pow + 1 << endl;
    cout << max_pow << endl;
    return 0;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int H,W,N;
int t[500*500];
int u[500*500][50];
int sp[500*500];
 
bool check(ll tm){
  set<int> st;
  for(int i=0;i<N;i++){
    int p=sp[i];
    for(int j=0;j<50;j++)
      if(tm>>j&1)
        p=u[p][j];
    if(st.count(p)>0)return true;
    st.insert(p);
  }
  return false;
}
 
int main(){
  scanf("%d %d %d",&H,&W,&N);
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      int y,x;
      scanf("%d %d",&y,&x);
      t[i*W+j]=y*W+x;
    }
  }
 
  for(int i=0;i<N;i++){
    int y,x;
    scanf("%d %d",&y,&x);
    sp[i]=y*W+x;
  }
     
  for(int i=0;i<H*W;i++){
    u[i][0]=t[i];    
  }
   
  for(int k=1;k<50;k++)
    for(int i=0;i<H*W;i++)
      u[i][k]=u[u[i][k-1]][k-1];
 
  ll left=0,right=(1LL<<45),mid;
 
  if(check(right)==false){
    printf("-1\n");
    return 0;
  }
   
  while(left<right){
    mid=(left+right)/2;
    if(check(mid))right=mid;
    else left=mid+1;
  }
 
  printf("%d\n",left);
  return 0;
}

Measured memory_bytes: 65700
import Data.List
import Data.Char

solve s | sanitary s = toStr (mkTree s)
        | otherwise = "-1\n"

sanitary s =
  head s == '1' && head r == '0'
    && all (\(p,q) -> p == q) (zip s (tail r))
  where r = reverse s

toStr = unlines . map (unwords . map show)

mkTree s = unfoldr f (1, zip [2..] (init s))
  where
    f (_, []) = Nothing
    f (node, (i,e):ps) = Just ([node,i], (if e == '1' then i else node, ps))

main = putStr . solve . takeWhile isAlphaNum =<< getContents


Measured memory_bytes: 9980
#include <bits/stdc++.h>
#define ll long long
#define REV(v) reverse(v.begin(), v.end());
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, start, stop) for (ll i = start; i < stop; i++)
#define FORR(i, start, stop) for (ll i = start; i > stop; i--)
#define SORT(v, n) sort(v, v + n);
#define SORTR(v, n) sort(v, v + n,greater<ll>());
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.begin(), v.end(),greater<ll>());
#define REMOVE(v,n) remove(vector<ll> v,v+v.size(),ll n)
#define ERASE(v,n) v.erase(v.begin()+n);
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
#define V(v,i,j) vector(v.begin() + i, v.begin() + j)
#define INSERT(va,vb) va.insert(va.end(), vb.begin(), vb.end())
using namespace std;
typedef vector<ll> vll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
const int MOD = 1000000007;
void chmin(int &a, int b) { if (a > b) a = b; }

//vector< vector<int> > v (size1, vector<int>(size2) );

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

//累乗 a**n
long long pow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,P;
    cin>>N>>P;
    vector<pair<ll, ll> > pf=prime_factorize(P);
    ll ans=1;
    FOR(i,0,pf.size()){
        //cout<<pf[i].first<<' '<<pf[i].second<<endl;
        if(pf[i].second/N)ans*=pow(pf[i].first,pf[i].second/N);
        //cout<<ans<<endl;
    }

    cout<<ans<<endl;
    
    
}
//678

Measured memory_bytes: 256
import math
a,b=map(int,input().split())
gcd=math.gcd(a,b)

def prime_factorization(n):
  i=2
  prime=[]
  if n%i==0:
    n//=i
    prime.append(2)
    while n%i==0:
      n//=i
  i+=1
  while i*i<=n:
    if n%i:
      i+=2
    else:
      n//=i
      prime.append(i)
      while n%i==0:
        n//=i
  if n>1:
    prime.append(n)
  return prime

print(len(prime_factorization(gcd))+1)

Measured memory_bytes: 9192
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>

using namespace std;

#define INF 999999999

int frac[2];

void dir(string s){
	//cout << s << endl;
	if(s == "north"){
		frac[0] = 0;
		frac[1] = 1;
	}
	else if(s == "west"){
		frac[0] = 90;
		frac[1] = 1;
	}
	else if(s[0] == 'n'){
		dir(s.substr(5));
		frac[0] = frac[0] * 2 - 90;
		frac[1] = frac[1] * 2;
	}
	else if(s[0] == 'w'){
		dir(s.substr(4));
		frac[0] = frac[0] * 2 + 90;
		frac[1] = frac[1] * 2;
	}
}

int main(){
	int i, j;
	string s;
	while(1){
		cin >> s;
		if(s=="#") break;
		dir(s);
		while(!(frac[0]%2)&&!(frac[1]%2)){
			frac[0] /= 2;
			frac[1] /= 2;
		}
		if(frac[1] == 1)cout << frac[0] << endl;
		else cout << frac[0] << "/" << frac[1] << endl;
	}
	return 0;
}

Measured memory_bytes: 1200
import java.util.*;

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

        String[] points = point.split(" ");
        int n = Integer.parseInt(points[0]);
        int d = Integer.parseInt(points[1]);

        int d2 = d * 2 + 1;

        double d3 = (double)n / d2;

        //きりあげ
        double kiriage = Math.ceil(d3);

        System.out.println((int)kiriage);
    }
}

Measured memory_bytes: 23636
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Numerics;

public class Program
{
    public static void Main(string[] args)
    {
        string[] line = Console.ReadLine().Split(' ');

        int n = int.Parse(line[0]);
        int k = int.Parse(line[1]);

        bool r = (k * 2) - 1 <= n;
    
        Console.WriteLine(r ? "YES" : "NO");
        Console.ReadLine();
    }
}


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

int main(){
  int Q; cin >> Q;
  for(int i = 0; i < Q; i++){
    string s, t; cin >> s >> t;
    int N = s.size(), M = t.size();
    vector<vector<int> > dp(N + 1, vector<int> (M + 1, 0));
    for(int i = 0; i < N; i++){
      for(int j = 0; j < M; j++){
        if(s[i] == t[j]){
          dp[i + 1][j + 1] = dp[i][j] + 1;
        }
        else{
          dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
        }
      }
    }
    cout << dp[N][M] << endl;
  }
}


Measured memory_bytes: 6900
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

signed main() {
    int n;
    cin >> n;
    int p[n], q[n];
    rep(i, 0, n) cin >> p[i];
    rep(i, 0, n) cin >> q[i];
    int r[n];
    rep(i, 0, n) r[i] = i + 1;
    int cnt = 0, ans = 0;
    do {
        cnt++;
        bool cp = 1, cq = 1;
        rep(i, 0, n) {
            if (p[i] != r[i]) cp = 0;
            if (q[i] != r[i]) cq = 0;
        }
        if (cp) ans -= cnt;
        if (cq) ans += cnt;
    } while (next_permutation(r, r + n));
    cout << abs(ans) << "\n";
}

Measured memory_bytes: 3608
#include <iostream>
using namespace std;
int main(){
  int N,x,f;
  cin >> N;
  for(x=N;x>0;x=x/10){
    f+=x%10;
  }
  if(N%f==0)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define intt int64_t
#define all(vec) vec.begin(), vec.end()
#define MOD 1000000007

int main() {
    int n;
    scanf("%d", &n);
    vector<pair<int, int> > vec(n);
    rep(i,n) scanf("%d", &vec.at(i).first);
    rep(i,n) scanf("%d", &vec.at(i).second);
    int ans = 0;
    rep(i,n) {
        int MOUKE = vec.at(i).first - vec.at(i).second;
        if (MOUKE > 0) ans += MOUKE;
    }
    printf("%d\n", ans);
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const ll COMBMAX = 210000;
ll fact[COMBMAX];
ll inv[COMBMAX];
ll finv[COMBMAX];

void combinit(){
	fact[0]=finv[0]=1;
	inv[1]=1;
	for(int i=2;i<COMBMAX;i++){
		inv[i]=(MOD-(MOD/i)*inv[MOD%i]%MOD)%MOD;
	}
	for(int i=1;i<COMBMAX;i++){
		fact[i]=fact[i-1]*i%MOD;
		finv[i]=finv[i-1]*inv[i]%MOD;
	}
}
ll comb(int a,int b){
	if(a<b||b<0)return 0;
	return fact[a]*finv[b]%MOD*finv[a-b]%MOD;
}

ll ans = 0;
int main() {
	int n,k;
	cin>>n>>k;
	int blue = k;
	int red = n-k;

	combinit();

	FOR(i,1,blue+1){
		ans = 0;
		ans+=comb(red+1,i)*comb(blue-1,i-1);
		cout << ans%MOD << endl;
	}
	return 0;
}

Measured memory_bytes: 5248
# abc179_c.py
import math
N = int(input())
cnt = 0
for i in range(1,N+1):
    if i*(N//i)==N:
        # print(i,N//i-1)
        cnt += N//i-1
    else:
        cnt += N//i
        # print(i,N//i)
print(cnt)


Measured memory_bytes: 9152
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<limits>
#include<numeric>
#include<bitset>
#include<unordered_map>
#include<functional>
using namespace std;

#define rep(i,s,n) for(int i=s;i<n;i++)
#define dow(i,n,s) for(int i=n-1;i>=s;i--)
#define all(a) a.begin(),a.end()
#define Sort(a) sort(all(a))
#define Qsort(a,size) qsort(a,size,sizeof(*a),compare_int)
//#define DEBUG
typedef pair<int,int> II;
typedef unsigned long ul;
typedef long long ll;
typedef unsigned long long ull;
bool compare_by_second(II a,II b) { return a.second!=b.second?a.second<b.second:a.first<b.first; }
bool compare_int(const void *a,const void *b) { return *(int *)a-*(int *)b; }

const int INF = 1e+9;
const int MAX_N = 50;
const int MAX_M = 2450;
const int MAX_ABC = 1e+2;

int n,m,a,b,c;
vector<int> pattern;
vector< vector<int> > adj;
int turn = 0;

void solve();

int main() {

  cin>>n>>m>>a>>b>>c;
  pattern.push_back(a);
  pattern.push_back(b);
  pattern.push_back(c);

  adj.resize(n+1);
  rep(i,0,m) {
    int tmp1,tmp2;
    cin>>tmp1>>tmp2;
    adj[tmp1].push_back(tmp2);
  }

#ifdef DEBUG
  rep(i,0,n+1) {
    rep(j,0,adj[i].size()) cout<<adj[i][j]<<" ";
    cout<<endl;
  }
#endif

  solve();

  return 0;
}

void solve() {
  unordered_map<int,int> target,add;
  unordered_map<int,int> um1,um2;
  target[n] = 0;
  bool flag;

  while(true) {
    rep(i,1,n) {
      if(target.find(i) == target.end()) {
        rep(j,0,3) {
          um1[i] = 0;
          rep(k,0,pattern[j]) {
            //探索
            for(auto itr = um1.begin();itr!=um1.end();++itr) {
              rep(k,0,adj[itr->first].size()) um2[adj[itr->first][k]] = 0;
            }

            //コピー
            um1.clear();
            um1 = um2;
            um2.clear();
          }

          flag = false;
          for(auto itr=um1.begin();itr!=um1.end();++itr) {
            if(target.find(itr->first)!=target.end()) flag = true;
          }
          um1.clear();
          if(!flag) goto EXIT;

        }

        add[i] = 0;

      }
      EXIT: ;
    }

    turn++;
    if(add.empty()) { cout<<"IMPOSSIBLE"<<endl; return ; }
    if(add.find(1)!=add.end()) { cout<<turn<<endl; return ; }
    for(auto itr = add.begin();itr!=add.end();++itr) target[itr->first] = 0;
    add.clear();
  }

  return ;
}



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

int main()
{
	int D;

	cin >> D;

	if (D == 22) { cout << "Christmas Eve Eve Eve"; }
	else if (D == 23) { cout << "Christmas Eve Eve"; }
	else if (D == 24) { cout << "Christmas Eve"; }
	else if (D == 25) { cout << "Christmas"; }

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
 
//priority_queue<long long, vector<long long>, greater<long long>> pq;

const double TL = 1.5 * CLOCKS_PER_SEC;
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
#define clr(x, y) memset(x, y, sizeof(x))
#define forn(i, n) for (int i = 0; i < n; i++)
#define LL long long
const double pi = acos(-1.0);



int main() {
  //auto start_clock = clock();
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif

  string s;
  cin >> s;
  if (s == "ARC") cout << "ABC" << endl;
  else cout << "ARC" << endl;
  return 0;
}

Measured memory_bytes: 3556
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

class Factorial:
    def __init__(self, n, mod):
        self.f = [1]
        self.mod = mod
        for j in range(1, n + 1):
            self.f.append(self.f[-1] * j % mod)
        self.i = [pow(self.f[-1], mod - 2, mod)]
        for j in range(n, 0, -1):
            self.i.append(self.i[-1] * j % mod)
        self.i.reverse()
    def factorial(self, j):
        return self.f[j]
    def ifactorial(self, j):
        return self.i[j]
    def comb(self, n, k):
        return self.f[n] * self.i[n - k] % self.mod * self.i[k] % self.mod if n >= k else 0

C = Factorial(2 * 10 ** 6 + 5, MOD).comb

r1, c1, r2, c2 = map(int, input().split())

ans = 0
for i in range(c2 - c1 + 1):
    tmp = C(r2 + c2 + 1 - i, r2) - C(r1 + c2 - i, r1 - 1)
    # print (tmp, C(r2 + c2 + 1 - i, r2), C(r1 + c2 - i, r1 - 1))

    ans += tmp
    ans %= MOD

print (ans)


Measured memory_bytes: 135552
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
 
        Scanner sc = new Scanner(System.in);
 
        int a,b;
 
        while(true){
            a = sc.nextInt();
            b = sc.nextInt();
 
            if(a == 0 && b == 0)break;
 
            System.out.printf("%d %d\n", Math.min(a, b),Math.max(a, b));
        }
 
    }
}


Measured memory_bytes: 41544
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(x) x.begin(), x.end()

#define mp make_pair
#define in insert
#define er erase
#define con continue
#define pb push_back
#define sc scanf
#define pr printf
#define ub upper_bound
#define lb lower_bound
#define s second
#define f first
#define int long long

const long long infl = 1e18; 
const int N = 3e5 + 300, N2 = 2e3, inf = 1e9 + 200;

set <int> S;
vector <int> g;
int n, m, k, x, y, a, b, c;

main (){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> x >> y >> a >> b >> c;
	vector <pair <int,int> > v;
	for (int i = 0; i < a; i++){
		int w;
		cin >> w;
		v.pb(mp(w, 1));
	}
	for (int i = 0; i < b; i++){
		int w;
		cin >> w;
		v.pb(mp(w, 2));
	}
	for (int i = 0; i < c; i++){
		int w;
		cin >> w;
		v.pb(mp(w, 3));
	}
	int xx = 0, yy = 0, zz = 0;
	sort(all(v));
	reverse(all(v));
	int ans = 0;
	for (auto i: v){
		if (i.s == 1){
			if (xx < x && xx + yy + zz + 1 <= x + y){
				xx++;
				ans += i.f;
			}
		}
		if (i.s == 2){
			if (yy < y && xx + yy + zz + 1 <= x + y){
				yy++;
				ans += i.f;
			}
		}
		if (i.s == 3){
			if (xx + yy + zz + 1 <= x + y){
				zz++;
				ans += i.f;
			}
		}
	}
	cout << ans;
	return 0;
}












Measured memory_bytes: 10476
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AGC011Airport
{
    class Program
    {
        static void Main(string[] args)
        {
            int N, C, K;
            string[] vals = Console.ReadLine().Split(' ');
            N = int.Parse(vals[0]);
            C = int.Parse(vals[1]);
            K = int.Parse(vals[2]);
            int[] T = new int[N];
            for(int i=0; i < N; i++)
            {
                T[i] = int.Parse(Console.ReadLine());
            }
            Array.Sort(T);

            Queue<int> queue = new Queue<int>();
            int t, u;
            int numBus = 0;
            for(int i=0; i < N; i++)
            {
                queue.Enqueue(T[i]);
                t = queue.Peek();
                if(t+K <= T[i])
                {
                    if(i < N-1)
                    {
                        if (t+K == T[i] && T[i] == T[i + 1] && queue.Count < C)
                            continue;
                    }
                    numBus++;
                    for(int j=0; j < C; j++)
                    {
                        if (queue.Count == 0)
                            break;
                        u = queue.Peek();
                        if(u <= t + K)
                        {
                            queue.Dequeue();
                        }
                        else
                        {
                            break;
                        }                            
                    }
                }
                else
                {
                    if(queue.Count == C)
                    {
                        numBus++;
                        queue.Clear();
                    }
                }
            }
            if (queue.Count > 0)
                numBus++;
            Console.WriteLine(numBus);
        }
    }
}


Measured memory_bytes: 15456
N, M, Q = map(int, input().split())

rules = []
for _ in range(Q):
    a, b, c, d = map(int, input().split())
    a, b = a-1, b-1
    rules.append((a, b, c, d))

def gen():
    seq = [[1]]
    for _ in range(N-1):
        new_seq = []
        for prefix in seq:
            for i in range(prefix[-1], M+1):
                new_seq.append(prefix+[i])
        seq = new_seq
    return seq

ans = 0
for A in gen():
    cand = 0
    for a, b, c, d in rules:
        if A[b]-A[a] == c:
            cand += d
    ans = max(ans, cand)
print(ans)

Measured memory_bytes: 89280
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Tenka1_2017_C solver = new Tenka1_2017_C();
        solver.solve(1, in, out);
        out.close();
    }

    static class Tenka1_2017_C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long N = in.nextLong();

            for (long h = 1; h <= 3500; h++) {
                for (long n = 1; n <= 3500; n++) {
                    try {
                        long child = N * h * n;
                        long mother = (4 * h * n) - (N * n) - (N * h);
                        if (child % mother == 0 && mother > 0) {
                            out.print(h + " " + n + " " + child / mother);
                            return;
                        }


                    } catch (ArithmeticException e) {

                    }

                }
            }

        }

    }
}



Measured memory_bytes: 23636
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;
typedef pair<ll  ,ll > pll;

const ll maxn =2e6;
const ll mod = 1e9+7;
const ld PI = 4 * atan((ld) 1);

#define pb(x) push_back(x);
#define endl '\n'
#define dokme(x) cout << x ;  return(0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
#define ms(x , y) memset(x , y , sizeof x);
ll pw(ll a, ll b) {
    return (!b ? 1 : (b & 1 ? a * pw(a * a % mod, b / 2) % mod : pw(a * a % mod, b / 2) % mod));
}

string s;
int cnt[maxn];

int main(){
    migmig
    cin >> s;
    int cur = 0;
    ms(cnt , 0);
    for (int i = s.size()-1 ; i >=  0 ; i --){
        cnt[cur++] = s[i] - '0';
    }
    pll ans = {0 , 1};
    for(int i = 0 ; i < 1e6+100 ; i ++){
        ll a = min(ans.first + cnt[i] , ans.second+10 - cnt[i]);
        ll b = min(ans.first + cnt[i] +1 , ans.second+10 - (cnt[i] + 1 ) );
        ans = {a , b};
    }

    cout << ans.first;


    return(0);
}


//When we hit our lowest point, we are open to the greatest change.
//If I try, I fail. If I don't try, I'm NEVER GOING TO GET IT.
//Sometimes, life is like this dark tunnel. You can't always see the light at the end of the tunnel. But if you just keep moving... you will come to a better place.
//It is important to draw wisdom from diffrent places. If you take it from only one place it becomes rigid and stale.


Measured memory_bytes: 9116
#include<cstdio>
using namespace std;
int main()
{
    long long int A,B,K,i;

     while(scanf("%lld%lld%lld",&A,&B,&K)!=EOF)
    {
        for(i=A;i<=B;i++)
            if(i<A+K||i>B-K)
                printf("%d\n",i);


    }

   return 0;
}


Measured memory_bytes: 128